changeset 22234:959f658b918d

Truffle/Instrumentation: generify Instrumenter.install(Tool) in the type of the tool.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Mon, 21 Sep 2015 17:03:27 -0700
parents 1f19e3cada3d
children e110ab9f91fe
files truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineBreakpointFactory.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/CoverageTracker.java truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/LineToProbesMap.java truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/NodeExecCounter.java
diffstat 7 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineBreakpointFactory.java	Mon Sep 21 16:29:45 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineBreakpointFactory.java	Mon Sep 21 17:03:27 2015 -0700
@@ -138,8 +138,7 @@
         this.warningLog = warningLog;
 
         final Instrumenter instrumenter = debugger.getInstrumenter();
-        lineToProbesMap = new LineToProbesMap();
-        instrumenter.install(lineToProbesMap);
+        lineToProbesMap = instrumenter.install(new LineToProbesMap());
 
         instrumenter.addProbeListener(new DefaultProbeListener() {
 
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java	Mon Sep 21 16:29:45 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java	Mon Sep 21 17:03:27 2015 -0700
@@ -43,7 +43,7 @@
  * An {@link InstrumentationTool} that builds a map of every {@link Probe} attached to some AST,
  * indexed by {@link Source} and line number.
  */
-final class LineToProbesMap extends Instrumenter.Tool {
+final class LineToProbesMap extends Instrumenter.Tool<LineToProbesMap> {
 
     private static final boolean TRACE = false;
     private static final PrintStream OUT = System.out;
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java	Mon Sep 21 16:29:45 2015 -0700
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java	Mon Sep 21 17:03:27 2015 -0700
@@ -29,6 +29,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -122,7 +123,7 @@
      * language-agnostic management of individual execution environments is added to the platform,
      * installation will be (optionally) specific to a single execution environment.
      */
-    public abstract static class Tool {
+    public abstract static class Tool<T extends Tool<?>> {
         // TODO (mlvdv) still thinking about the most appropriate name for this class of tools
 
         private ToolState toolState = ToolState.UNINSTALLED;
@@ -234,7 +235,7 @@
     private final Object vm;
 
     /** Tools that have been created, but not yet disposed. */
-    private final Set<Tool> tools = Collections.synchronizedSet(new LinkedHashSet<Tool>());
+    Set<Tool<? extends Tool<?>>> tools = new HashSet<>();
 
     private final Set<ASTProber> astProbers = Collections.synchronizedSet(new LinkedHashSet<ASTProber>());
 
@@ -544,10 +545,12 @@
     /**
      * Connects the tool to some part of the Truffle runtime, and enable data collection to start.
      *
+     * @return the tool
      * @throws IllegalStateException if the tool has previously been installed or has been disposed.
      */
-    public void install(Tool tool) {
+    public <T extends Tool<?>> T install(T tool) {
         tool.install(this);
+        return tool;
     }
 
     @SuppressWarnings("unused")
--- a/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java	Mon Sep 21 16:29:45 2015 -0700
+++ b/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java	Mon Sep 21 17:03:27 2015 -0700
@@ -130,7 +130,7 @@
         return instrumenter;
     }
 
-    private static final class DummyTruffleTool extends Instrumenter.Tool {
+    private static final class DummyTruffleTool extends Instrumenter.Tool<DummyTruffleTool> {
 
         @Override
         protected boolean internalInstall() {
--- a/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/CoverageTracker.java	Mon Sep 21 16:29:45 2015 -0700
+++ b/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/CoverageTracker.java	Mon Sep 21 17:03:27 2015 -0700
@@ -82,7 +82,7 @@
  * @see Instrument
  * @see SyntaxTag
  */
-public final class CoverageTracker extends Instrumenter.Tool {
+public final class CoverageTracker extends Instrumenter.Tool<CoverageTracker> {
 
     /** Counting data. */
     private final Map<LineLocation, CoverageRecord> coverageMap = new HashMap<>();
--- a/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/LineToProbesMap.java	Mon Sep 21 16:29:45 2015 -0700
+++ b/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/LineToProbesMap.java	Mon Sep 21 17:03:27 2015 -0700
@@ -43,7 +43,7 @@
  * An {@link InstrumentationTool} that builds a map of every {@link Probe} attached to some AST,
  * indexed by {@link Source} and line number.
  */
-public final class LineToProbesMap extends Instrumenter.Tool {
+public final class LineToProbesMap extends Instrumenter.Tool<LineToProbesMap> {
 
     private static final boolean TRACE = false;
     private static final PrintStream OUT = System.out;
--- a/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/NodeExecCounter.java	Mon Sep 21 16:29:45 2015 -0700
+++ b/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/NodeExecCounter.java	Mon Sep 21 17:03:27 2015 -0700
@@ -96,7 +96,7 @@
  * @see SyntaxTag
  * @see ProbeFailure
  */
-public final class NodeExecCounter extends Instrumenter.Tool {
+public final class NodeExecCounter extends Instrumenter.Tool<NodeExecCounter> {
 
     /**
      * Execution count for AST nodes of a particular type.
@@ -119,7 +119,7 @@
                 /*
                  * Everything up to here is inlined by Truffle compilation. Delegate the next part
                  * to a method behind an inlining boundary.
-                 *
+                 * 
                  * Note that it is not permitted to pass a {@link VirtualFrame} across an inlining
                  * boundary; they are truly virtual in inlined code.
                  */