# HG changeset patch # User Michael Van De Vanter # Date 1442878185 25200 # Node ID 1f19e3cada3d0fffedf925737e954281fa616365 # Parent 526de3af756dc7161213a09482251dc7f506b44b Truffle/Instrumentation: change the installation sequence for instances of Intrumenter.Tool diff -r 526de3af756d -r 1f19e3cada3d truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineBreakpointFactory.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineBreakpointFactory.java Mon Sep 21 12:15:38 2015 -0700 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineBreakpointFactory.java Mon Sep 21 16:29:45 2015 -0700 @@ -139,7 +139,7 @@ final Instrumenter instrumenter = debugger.getInstrumenter(); lineToProbesMap = new LineToProbesMap(); - lineToProbesMap.install(instrumenter); + instrumenter.install(lineToProbesMap); instrumenter.addProbeListener(new DefaultProbeListener() { diff -r 526de3af756d -r 1f19e3cada3d truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java Mon Sep 21 12:15:38 2015 -0700 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java Mon Sep 21 16:29:45 2015 -0700 @@ -132,13 +132,7 @@ protected Tool() { } - /** - * Connect the tool to some part of the Truffle runtime, and enable data collection to - * start. Instrumentation will only be added to subsequently created ASTs. - * - * @throws IllegalStateException if the tool has previously been installed. - */ - public final void install(Instrumenter inst) { + final void install(Instrumenter inst) { checkUninstalled(); this.instrumenter = inst; @@ -547,6 +541,15 @@ return instrument; } + /** + * Connects the tool to some part of the Truffle runtime, and enable data collection to start. + * + * @throws IllegalStateException if the tool has previously been installed or has been disposed. + */ + public void install(Tool tool) { + tool.install(this); + } + @SuppressWarnings("unused") void executionStarted(Source s) { } diff -r 526de3af756d -r 1f19e3cada3d truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/CoverageTrackerTest.java --- a/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/CoverageTrackerTest.java Mon Sep 21 12:15:38 2015 -0700 +++ b/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/CoverageTrackerTest.java Mon Sep 21 16:29:45 2015 -0700 @@ -50,7 +50,7 @@ final Instrumenter instrumenter = (Instrumenter) field.get(vm); final CoverageTracker tool = new CoverageTracker(); assertEquals(tool.getCounts().entrySet().size(), 0); - tool.install(instrumenter); + instrumenter.install(tool); assertEquals(tool.getCounts().entrySet().size(), 0); tool.setEnabled(false); assertEquals(tool.getCounts().entrySet().size(), 0); @@ -80,14 +80,14 @@ final CoverageTracker valueCoverage = new CoverageTracker(ToolTestTag.VALUE_TAG); final CoverageTracker addCoverage = new CoverageTracker(ToolTestTag.ADD_TAG); - valueCoverage.install(instrumenter); + instrumenter.install(valueCoverage); assertTrue(valueCoverage.getCounts().isEmpty()); assertEquals(vm.eval(source).get(), 13); checkCounts(source, valueCoverage, new Long[]{Long.valueOf(1), null, Long.valueOf(1), null}); - addCoverage.install(instrumenter); + instrumenter.install(addCoverage); assertEquals(vm.eval(source).get(), 13); diff -r 526de3af756d -r 1f19e3cada3d truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/LineToProbesMapTest.java --- a/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/LineToProbesMapTest.java Mon Sep 21 12:15:38 2015 -0700 +++ b/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/LineToProbesMapTest.java Mon Sep 21 16:29:45 2015 -0700 @@ -51,7 +51,7 @@ final Instrumenter instrumenter = (Instrumenter) field.get(vm); final Source source = ToolTestUtil.createTestSource("testNoExecution"); final LineToProbesMap probesMap = new LineToProbesMap(); - probesMap.install(instrumenter); + instrumenter.install(probesMap); assertNull(probesMap.findFirstProbe(source.createLineLocation(1))); assertNull(probesMap.findFirstProbe(source.createLineLocation(2))); assertNull(probesMap.findFirstProbe(source.createLineLocation(3))); @@ -72,7 +72,7 @@ assertNull(probesMap.findFirstProbe(source.createLineLocation(3))); // Map installed before AST gets created - probesMap.install(instrumenter); + instrumenter.install(probesMap); assertEquals(vm.eval(source).get(), 13); final Probe probe1 = probesMap.findFirstProbe(source.createLineLocation(1)); @@ -103,7 +103,7 @@ // Map installed after AST gets created assertEquals(vm.eval(source).get(), 13); - probesMap.install(instrumenter); + instrumenter.install(probesMap); final Probe probe1 = probesMap.findFirstProbe(source.createLineLocation(1)); assertNotNull(probe1); diff -r 526de3af756d -r 1f19e3cada3d truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/NodeExecCounterTest.java --- a/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/NodeExecCounterTest.java Mon Sep 21 12:15:38 2015 -0700 +++ b/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/NodeExecCounterTest.java Mon Sep 21 16:29:45 2015 -0700 @@ -48,7 +48,7 @@ final Instrumenter instrumenter = (Instrumenter) field.get(vm); final NodeExecCounter tool = new NodeExecCounter(); assertEquals(tool.getCounts().length, 0); - tool.install(instrumenter); + instrumenter.install(tool); assertEquals(tool.getCounts().length, 0); tool.setEnabled(false); assertEquals(tool.getCounts().length, 0); @@ -82,7 +82,7 @@ final Instrumenter instrumenter = (Instrumenter) field.get(vm); final Source source = ToolTestUtil.createTestSource("testCounting"); final NodeExecCounter execTool = new NodeExecCounter(); - execTool.install(instrumenter); + instrumenter.install(execTool); assertEquals(execTool.getCounts().length, 0); diff -r 526de3af756d -r 1f19e3cada3d truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java --- a/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java Mon Sep 21 12:15:38 2015 -0700 +++ b/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java Mon Sep 21 16:29:45 2015 -0700 @@ -44,7 +44,7 @@ final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); assertFalse(tool.isEnabled()); - tool.install(instrumenter); + instrumenter.install(tool); assertTrue(tool.isEnabled()); tool.reset(); assertTrue(tool.isEnabled()); @@ -82,24 +82,24 @@ public void testAlreadyInstalled() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); - tool.install(instrumenter); - tool.install(instrumenter); + instrumenter.install(tool); + instrumenter.install(tool); } @Test(expected = IllegalStateException.class) public void testAlreadyDisposed1() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); - tool.install(instrumenter); + instrumenter.install(tool); tool.dispose(); - tool.install(instrumenter); + instrumenter.install(tool); } @Test(expected = IllegalStateException.class) public void testAlreadyDisposed2() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); - tool.install(instrumenter); + instrumenter.install(tool); tool.dispose(); tool.reset(); } @@ -108,7 +108,7 @@ public void testAlreadyDisposed3() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); - tool.install(instrumenter); + instrumenter.install(tool); tool.dispose(); tool.setEnabled(true); } @@ -117,7 +117,7 @@ public void testAlreadyDisposed4() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); - tool.install(instrumenter); + instrumenter.install(tool); tool.dispose(); tool.dispose(); }