# HG changeset patch # User Michael Van De Vanter # Date 1443676252 25200 # Node ID 339272c9d5196609104a2d76184d40e58e8b24ee # Parent bcfb44655eb90f1a1bd382cba559edf3a5c5a9d0 Test updates for revised Polyglot/Instrumentation APIs diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -22,7 +22,9 @@ */ package com.oracle.graal.truffle.test; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.truffle.OptimizedCallTarget; @@ -40,6 +42,18 @@ return 42; } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void constantValue() { Assumption assumption = Truffle.getRuntime().createAssumption(); diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/BytecodeInterpreterPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/BytecodeInterpreterPartialEvaluationTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/BytecodeInterpreterPartialEvaluationTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -24,7 +24,9 @@ import java.util.Random; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -43,6 +45,18 @@ public class BytecodeInterpreterPartialEvaluationTest extends PartialEvaluationTest { + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + public static class Bytecode { public static final byte CONST = 0; public static final byte RETURN = 1; diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/CompilerAssertsTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/CompilerAssertsTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/CompilerAssertsTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -24,7 +24,9 @@ import jdk.internal.jvmci.code.BailoutException; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.truffle.test.nodes.AbstractTestNode; @@ -47,6 +49,18 @@ } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + public static class CompilationConstantTestNode extends AbstractTestNode { @Child private AbstractTestNode child; diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ControlFlowExceptionPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ControlFlowExceptionPartialEvaluationTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ControlFlowExceptionPartialEvaluationTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -22,7 +22,9 @@ */ package com.oracle.graal.truffle.test; +import org.junit.After; import org.junit.Assume; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.truffle.TruffleCompilerOptions; @@ -42,6 +44,18 @@ return 42; } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void catchControlFlowException() { FrameDescriptor fd = new FrameDescriptor(); diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -22,26 +22,6 @@ */ package com.oracle.graal.truffle.test; -import org.junit.Assert; -import org.junit.Test; - -import com.oracle.graal.truffle.test.nodes.AbstractTestNode; -import com.oracle.graal.truffle.test.nodes.ConstantTestNode; -import com.oracle.graal.truffle.test.nodes.RootTestNode; -import com.oracle.truffle.api.RootCallTarget; -import com.oracle.truffle.api.Truffle; -import com.oracle.truffle.api.frame.FrameDescriptor; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrument.ASTProber; -import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot; -import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory; -import com.oracle.truffle.api.instrument.Instrument; -import com.oracle.truffle.api.instrument.Probe; -import com.oracle.truffle.api.instrument.impl.DefaultSimpleInstrumentListener; -import com.oracle.truffle.api.instrument.impl.DefaultStandardInstrumentListener; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.nodes.NodeVisitor; - /** * Tests for a single simple PE test with various combinations of instrumentation attached. None of * the instrumentation ultimate does anything, so should compile away. @@ -52,332 +32,352 @@ return 42; } - @Test - public void constantValueUninstrumented() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNoInstruments() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - result.probe(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNullInstrument1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument"); - probe.attach(instrument); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNullInstrument2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument"); - probe.attach(instrument); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNullInstrumentDisposed1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument"); - probe.attach(instrument); - instrument.dispose(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNullInstrumentDisposed2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument"); - probe.attach(instrument); - instrument.dispose(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedTwoNullInstruments1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedTwoNullInstruments2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedThreeNullInstruments1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - Instrument instrument3 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 3"); - probe.attach(instrument3); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedThreeNullInstruments2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - Instrument instrument3 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 3"); - probe.attach(instrument3); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedThreeNullInstrumentsOneDisposed1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - Instrument instrument3 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 3"); - probe.attach(instrument3); - instrument2.dispose(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedThreeNullInstrumentsOneDisposed2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - Instrument instrument3 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 3"); - probe.attach(instrument3); - instrument2.dispose(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueInertAdvancedInstrumentRootFactory() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe testProbe = result.probe(); - // A factory that could insert a AdvancedInstrumentRoot into the AST, but which never does. - Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { - - public AdvancedInstrumentRoot createInstrumentRoot(Probe probe, Node node) { - return null; - } - }, null, "test AdvancedInstrument"); - testProbe.attach(instrument); - - // It all gets compiled away - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueInertAdvancedInstrumentRoot() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode resultTestNode = new ConstantTestNode(42); - RootTestNode rootTestNode = new RootTestNode(fd, "constantValue", resultTestNode); - rootTestNode.adoptChildren(); - Probe testProbe = resultTestNode.probe(); - // Factory inserts a AdvancedInstrumentRoot with empty methods into instrumentation . - Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { - - @Override - public AdvancedInstrumentRoot createInstrumentRoot(Probe probe, Node node) { - return new AdvancedInstrumentRoot() { - - public String instrumentationInfo() { - return null; - } - - @Override - public Object executeRoot(Node n, VirtualFrame frame) { - return null; - } - }; - } - }, null, "test AdvancedInstrument"); - testProbe.attach(instrument); - - // It all gets compiled away. - assertPartialEvalEquals("constant42", rootTestNode); - } - - @Test - public void instrumentDeopt() { - final FrameDescriptor fd = new FrameDescriptor(); - final AbstractTestNode result = new ConstantTestNode(42); - final RootTestNode root = new RootTestNode(fd, "constantValue", result); - final Probe[] probe = new Probe[1]; - final int[] count = {1}; - count[0] = 0; - // Register a "prober" that will get applied when CallTarget gets created. - final ASTProber prober = new ASTProber() { - - @Override - public void probeAST(Node node) { - node.accept(new NodeVisitor() { - - @Override - public boolean visit(Node visitedNode) { - if (visitedNode instanceof ConstantTestNode) { - probe[0] = visitedNode.probe(); - } - return true; - } - - }); - } - }; - Probe.registerASTProber(prober); - try { - final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(root); - - // The CallTarget has one Probe, attached to the ConstantTestNode, ready to run - Assert.assertEquals(42, callTarget.call()); // Correct result - Assert.assertEquals(0, count[0]); // Didn't count anything - - // Add a counting instrument; this changes the "Probe state" and should cause a deopt - final Instrument countingInstrument = Instrument.create(new DefaultSimpleInstrumentListener() { - - @Override - public void enter(Probe p) { - count[0] = count[0] + 1; - } - }, null); - probe[0].attach(countingInstrument); - - Assert.assertEquals(42, callTarget.call()); // Correct result - Assert.assertEquals(1, count[0]); // Counted the first call - - // Remove the counting instrument; this changes the "Probe state" and should cause a - // deopt - countingInstrument.dispose(); - - Assert.assertEquals(42, callTarget.call()); // Correct result - Assert.assertEquals(1, count[0]); // Didn't count this time - } finally { - Probe.unregisterASTProber(prober); - } - - } - - /** - * Experimental feature; not yet validated. - */ - @Test - public void specialOptInstrument() { - final FrameDescriptor fd = new FrameDescriptor(); - final AbstractTestNode result = new ConstantTestNode(42); - final RootTestNode root = new RootTestNode(fd, "constantValue", result); - final Probe[] probe = new Probe[1]; - final int[] count = {1}; - count[0] = 0; - // Register a "prober" that will get applied when CallTarget gets created. - final ASTProber prober = new ASTProber() { - - @Override - public void probeAST(Node node) { - node.accept(new NodeVisitor() { - - @Override - public boolean visit(Node visitedNode) { - if (visitedNode instanceof ConstantTestNode) { - probe[0] = visitedNode.probe(); - } - return true; - } - }); - } - }; - Probe.registerASTProber(prober); - try { - final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(root); - - // The CallTarget has one Probe, attached to the ConstantTestNode, ready to run - Assert.assertEquals(42, callTarget.call()); // Correct result - - final boolean[] isCurrentlyCompiled = {false}; - final Instrument optInstrument = Instrument.create(new Instrument.TruffleOptListener() { - - @Override - public void notifyIsCompiled(boolean isCompiled) { - isCurrentlyCompiled[0] = isCompiled; - } - }); - probe[0].attach(optInstrument); - - Assert.assertEquals(42, callTarget.call()); // Correct result - Assert.assertFalse(isCurrentlyCompiled[0]); - - // TODO (mlvdv) compile, call again, and assert that isCurrentlyCompiled == true - - } finally { - Probe.unregisterASTProber(prober); - } - - } +// @Test +// public void constantValueUninstrumented() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedNoInstruments() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// result.probe(); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedNullInstrument1() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument"); +// probe.attach(instrument); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedNullInstrument2() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument"); +// probe.attach(instrument); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedNullInstrumentDisposed1() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument"); +// probe.attach(instrument); +// instrument.dispose(); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedNullInstrumentDisposed2() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument"); +// probe.attach(instrument); +// instrument.dispose(); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedTwoNullInstruments1() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument 1"); +// probe.attach(instrument1); +// Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument 2"); +// probe.attach(instrument2); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedTwoNullInstruments2() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument 1"); +// probe.attach(instrument1); +// Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument 2"); +// probe.attach(instrument2); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedThreeNullInstruments1() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument 1"); +// probe.attach(instrument1); +// Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument 2"); +// probe.attach(instrument2); +// Instrument instrument3 = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument 3"); +// probe.attach(instrument3); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedThreeNullInstruments2() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument 1"); +// probe.attach(instrument1); +// Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument 2"); +// probe.attach(instrument2); +// Instrument instrument3 = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument 3"); +// probe.attach(instrument3); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedThreeNullInstrumentsOneDisposed1() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument 1"); +// probe.attach(instrument1); +// Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument 2"); +// probe.attach(instrument2); +// Instrument instrument3 = Instrument.create(new DefaultSimpleInstrumentListener(), +// "Null test Instrument 3"); +// probe.attach(instrument3); +// instrument2.dispose(); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueProbedThreeNullInstrumentsOneDisposed2() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe probe = result.probe(); +// Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument 1"); +// probe.attach(instrument1); +// Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument 2"); +// probe.attach(instrument2); +// Instrument instrument3 = Instrument.create(new DefaultStandardInstrumentListener(), +// "Null test Instrument 3"); +// probe.attach(instrument3); +// instrument2.dispose(); +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueInertAdvancedInstrumentRootFactory() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode result = new ConstantTestNode(42); +// RootTestNode root = new RootTestNode(fd, "constantValue", result); +// root.adoptChildren(); +// Probe testProbe = result.probe(); +// // A factory that could insert a AdvancedInstrumentRoot into the AST, but which never does. +// Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { +// +// public AdvancedInstrumentRoot createInstrumentRoot(Probe probe, Node node) { +// return null; +// } +// }, null, "test AdvancedInstrument"); +// testProbe.attach(instrument); +// +// // It all gets compiled away +// assertPartialEvalEquals("constant42", root); +// } +// +// @Test +// public void constantValueInertAdvancedInstrumentRoot() { +// FrameDescriptor fd = new FrameDescriptor(); +// AbstractTestNode resultTestNode = new ConstantTestNode(42); +// RootTestNode rootTestNode = new RootTestNode(fd, "constantValue", resultTestNode); +// rootTestNode.adoptChildren(); +// Probe testProbe = resultTestNode.probe(); +// // Factory inserts a AdvancedInstrumentRoot with empty methods into instrumentation . +// Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { +// +// @Override +// public AdvancedInstrumentRoot createInstrumentRoot(Probe probe, Node node) { +// return new AdvancedInstrumentRoot() { +// +// public String instrumentationInfo() { +// return null; +// } +// +// @Override +// public Object executeRoot(Node n, VirtualFrame frame) { +// return null; +// } +// }; +// } +// }, null, "test AdvancedInstrument"); +// testProbe.attach(instrument); +// +// // It all gets compiled away. +// assertPartialEvalEquals("constant42", rootTestNode); +// } +// +// @Test +// public void instrumentDeopt() { +// final FrameDescriptor fd = new FrameDescriptor(); +// final AbstractTestNode result = new ConstantTestNode(42); +// final RootTestNode root = new RootTestNode(fd, "constantValue", result); +// final Probe[] probe = new Probe[1]; +// final int[] count = {1}; +// count[0] = 0; +// // Register a "prober" that will get applied when CallTarget gets created. +// final ASTProber prober = new ASTProber() { +// +// @Override +// public void probeAST(Node node) { +// node.accept(new NodeVisitor() { +// +// @Override +// public boolean visit(Node visitedNode) { +// if (visitedNode instanceof ConstantTestNode) { +// probe[0] = visitedNode.probe(); +// } +// return true; +// } +// +// }); +// } +// }; +// Probe.registerASTProber(prober); +// try { +// final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(root); +// +// // The CallTarget has one Probe, attached to the ConstantTestNode, ready to run +// Assert.assertEquals(42, callTarget.call()); // Correct result +// Assert.assertEquals(0, count[0]); // Didn't count anything +// +// // Add a counting instrument; this changes the "Probe state" and should cause a deopt +// final Instrument countingInstrument = Instrument.create(new DefaultSimpleInstrumentListener() { +// +// @Override +// public void enter(Probe p) { +// count[0] = count[0] + 1; +// } +// }, null); +// probe[0].attach(countingInstrument); +// +// Assert.assertEquals(42, callTarget.call()); // Correct result +// Assert.assertEquals(1, count[0]); // Counted the first call +// +// // Remove the counting instrument; this changes the "Probe state" and should cause a +// // deopt +// countingInstrument.dispose(); +// +// Assert.assertEquals(42, callTarget.call()); // Correct result +// Assert.assertEquals(1, count[0]); // Didn't count this time +// } finally { +// Probe.unregisterASTProber(prober); +// } +// +// } +// +// /** +// * Experimental feature; not yet validated. +// */ +// @Test +// public void specialOptInstrument() { +// final FrameDescriptor fd = new FrameDescriptor(); +// final AbstractTestNode result = new ConstantTestNode(42); +// final RootTestNode root = new RootTestNode(fd, "constantValue", result); +// final Probe[] probe = new Probe[1]; +// final int[] count = {1}; +// count[0] = 0; +// // Register a "prober" that will get applied when CallTarget gets created. +// final ASTProber prober = new ASTProber() { +// +// @Override +// public void probeAST(Node node) { +// node.accept(new NodeVisitor() { +// +// @Override +// public boolean visit(Node visitedNode) { +// if (visitedNode instanceof ConstantTestNode) { +// probe[0] = visitedNode.probe(); +// } +// return true; +// } +// }); +// } +// }; +// Probe.registerASTProber(prober); +// try { +// final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(root); +// +// // The CallTarget has one Probe, attached to the ConstantTestNode, ready to run +// Assert.assertEquals(42, callTarget.call()); // Correct result +// +// final boolean[] isCurrentlyCompiled = {false}; +// final Instrument optInstrument = Instrument.create(new Instrument.TruffleOptListener() { +// +// @Override +// public void notifyIsCompiled(boolean isCompiled) { +// isCurrentlyCompiled[0] = isCompiled; +// } +// }); +// probe[0].attach(optInstrument); +// +// Assert.assertEquals(42, callTarget.call()); // Correct result +// Assert.assertFalse(isCurrentlyCompiled[0]); +// +// // TODO (mlvdv) compile, call again, and assert that isCurrentlyCompiled == true +// +// } finally { +// Probe.unregisterASTProber(prober); +// } +// +// } } diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationTestMode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationTestMode.java Wed Sep 30 22:10:52 2015 -0700 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test; + +import static org.junit.Assert.fail; + +import java.lang.reflect.Field; + +import com.oracle.truffle.api.instrument.Instrumenter; +import com.oracle.truffle.api.vm.PolyglotEngine; + +public class InstrumentationTestMode { + + public static void set(boolean enable) { + + try { + final PolyglotEngine vm = PolyglotEngine.buildNew().build(); + final Field instrumenterField = vm.getClass().getDeclaredField("instrumenter"); + instrumenterField.setAccessible(true); + final Object instrumenter = instrumenterField.get(vm); + final java.lang.reflect.Field testVMField = Instrumenter.class.getDeclaredField("testVM"); + testVMField.setAccessible(true); + if (enable) { + testVMField.set(instrumenter, vm); + } else { + testVMField.set(instrumenter, null); + } + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { + fail("Reflective access to Instrumenter for testing"); + } + + } +} diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ReadOnlyArrayListPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ReadOnlyArrayListPartialEvaluationTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ReadOnlyArrayListPartialEvaluationTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -22,6 +22,8 @@ */ package com.oracle.graal.truffle.test; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.truffle.test.nodes.AbstractTestNode; @@ -35,6 +37,18 @@ return 42; } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void constantValue() { FrameDescriptor fd = new FrameDescriptor(); diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -25,7 +25,9 @@ import jdk.internal.jvmci.code.BailoutException; import jdk.internal.jvmci.code.SourceStackTrace; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.replacements.PEGraphDecoder; @@ -54,6 +56,18 @@ return 42; } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void constantValue() { FrameDescriptor fd = new FrameDescriptor(); diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleDirectCallNodeTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleDirectCallNodeTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleDirectCallNodeTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import com.oracle.truffle.api.CallTarget; @@ -34,6 +36,16 @@ public class TruffleDirectCallNodeTest { + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @After + public void after() { + InstrumentationTestMode.set(false); + } + @Test public void testCanBeClonedWithoutParent() { final RootNode rootNode = new RootNode(MockLanguage.class, null, null) { diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleEnsureVirtualizedTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleEnsureVirtualizedTest.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleEnsureVirtualizedTest.java Wed Sep 30 22:10:52 2015 -0700 @@ -24,7 +24,9 @@ import jdk.internal.jvmci.code.BailoutException; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.api.directives.GraalDirectives; @@ -63,6 +65,18 @@ public static boolean booleanField; public static Object field; + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void test1() { testEnsureVirtualized(false, new TestNode() { diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/AbstractTestNode.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/AbstractTestNode.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/AbstractTestNode.java Wed Sep 30 22:10:52 2015 -0700 @@ -23,7 +23,6 @@ package com.oracle.graal.truffle.test.nodes; import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; import com.oracle.truffle.api.nodes.Node; public abstract class AbstractTestNode extends Node { @@ -32,15 +31,5 @@ super(null); } - @Override - public boolean isInstrumentable() { - return true; - } - - @Override - public WrapperNode createWrapperNode() { - return new WrapperTestNode(this); - } - public abstract int execute(VirtualFrame frame); } diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java Wed Sep 30 22:10:52 2015 -0700 @@ -25,7 +25,6 @@ import com.oracle.graal.truffle.test.MockLanguage; import com.oracle.truffle.api.frame.FrameDescriptor; import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrument.Probe; import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.nodes.RootNode; @@ -47,11 +46,6 @@ } @Override - public void applyInstrumentation() { - Probe.applyASTProbers(node); - } - - @Override public String toString() { return name; } diff -r bcfb44655eb9 -r 339272c9d519 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/WrapperTestNode.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/WrapperTestNode.java Wed Sep 30 17:59:48 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/WrapperTestNode.java Wed Sep 30 22:10:52 2015 -0700 @@ -23,10 +23,10 @@ package com.oracle.graal.truffle.test.nodes; import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.instrument.EventHandlerNode; import com.oracle.truffle.api.instrument.KillException; import com.oracle.truffle.api.instrument.Probe; -import com.oracle.truffle.api.instrument.ProbeNode; -import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; +import com.oracle.truffle.api.instrument.WrapperNode; import com.oracle.truffle.api.nodes.Node; /** @@ -35,7 +35,7 @@ public final class WrapperTestNode extends AbstractTestNode implements WrapperNode { @Child private AbstractTestNode child; - @Child private ProbeNode probeNode; + @Child private EventHandlerNode eventHandlerNode; public WrapperTestNode(AbstractTestNode child) { this.child = child; @@ -46,16 +46,12 @@ } @Override - public boolean isInstrumentable() { - return false; - } - - public void insertProbe(ProbeNode newProbeNode) { - this.probeNode = newProbeNode; + public void insertEventHandlerNode(EventHandlerNode eventHandler) { + this.eventHandlerNode = eventHandler; } public Probe getProbe() { - return probeNode.getProbe(); + return eventHandlerNode.getProbe(); } @Override @@ -65,15 +61,15 @@ @Override public int execute(VirtualFrame frame) { - probeNode.enter(child, frame); + eventHandlerNode.enter(child, frame); try { final int result = child.execute(frame); - probeNode.returnValue(child, frame, result); + eventHandlerNode.returnValue(child, frame, result); return result; } catch (KillException e) { throw (e); } catch (Exception e) { - probeNode.returnExceptional(child, frame, e); + eventHandlerNode.returnExceptional(child, frame, e); throw (e); } diff -r bcfb44655eb9 -r 339272c9d519 mx.graal/suite.py --- a/mx.graal/suite.py Wed Sep 30 17:59:48 2015 -0700 +++ b/mx.graal/suite.py Wed Sep 30 22:10:52 2015 -0700 @@ -14,7 +14,7 @@ }, { "name" : "truffle", - "version" : "71ec6de11cea65ab4ef7dca73aae10637dd6ceb8", + "version" : "1e4021a273b1e2e4767be88308642fdb9dffb8dd", "urls" : [ {"url" : "http://lafo.ssw.uni-linz.ac.at/hg/truffle", "kind" : "hg"}, {"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},