Search in sources :

Example 41 with RootTestNode

use of org.graalvm.compiler.truffle.test.nodes.RootTestNode in project graal by oracle.

the class InstrumentBranchesPhaseTest method simpleIfTest.

@Test
public void simpleIfTest() {
    InstrumentPhase.Instrumentation instrumentation = truffleCompiler.getInstrumentation();
    FrameDescriptor descriptor = new FrameDescriptor();
    SimpleIfTestNode result = new SimpleIfTestNode(5);
    RootTestNode rootNode = new RootTestNode(descriptor, "simpleIfRoot", result);
    OptimizedCallTarget target = compileHelper("simpleIfRoot", rootNode, new Object[0]);
    Assert.assertTrue(target.isValid());
    target.call();
    String stackOutput = instrumentation.accessTableToList(getOptions()).get(0);
    Assert.assertTrue(stackOutput, stackOutput.contains("org.graalvm.compiler.truffle.test.InstrumentBranchesPhaseTest$SimpleIfTestNode.execute(InstrumentBranchesPhaseTest.java"));
    Assert.assertTrue(stackOutput, stackOutput.contains("[bci: 4]\n[0] state = ELSE(if=0#, else=1#)"));
    String histogramOutput = instrumentation.accessTableToHistogram().get(0);
    Assert.assertEquals("  0: ********************************************************************************", histogramOutput);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) InstrumentPhase(org.graalvm.compiler.truffle.compiler.phases.InstrumentPhase) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 42 with RootTestNode

use of org.graalvm.compiler.truffle.test.nodes.RootTestNode in project graal by oracle.

the class InstrumentBranchesPhaseTest method twoIfsTest.

@Test
public void twoIfsTest() {
    InstrumentPhase.Instrumentation instrumentation = truffleCompiler.getInstrumentation();
    FrameDescriptor descriptor = new FrameDescriptor();
    TwoIfsTestNode result = new TwoIfsTestNode(5, -1);
    RootTestNode rootNode = new RootTestNode(descriptor, "twoIfsRoot", result);
    OptimizedCallTarget target = compileHelper("twoIfsRoot", rootNode, new Object[0]);
    Assert.assertTrue(target.isValid());
    // We run this twice to make sure that it comes first in the sorted access list.
    target.call();
    target.call();
    String stackOutput1 = instrumentation.accessTableToList(getOptions()).get(0);
    Assert.assertTrue(stackOutput1, stackOutput1.contains("org.graalvm.compiler.truffle.test.InstrumentBranchesPhaseTest$TwoIfsTestNode.execute(InstrumentBranchesPhaseTest.java"));
    Assert.assertTrue(stackOutput1, stackOutput1.contains("[bci: 4]\n[0] state = ELSE(if=0#, else=2#)"));
    String stackOutput2 = instrumentation.accessTableToList(getOptions()).get(1);
    Assert.assertTrue(stackOutput2, stackOutput2.contains("org.graalvm.compiler.truffle.test.InstrumentBranchesPhaseTest$TwoIfsTestNode.execute(InstrumentBranchesPhaseTest.java"));
    Assert.assertTrue(stackOutput2, stackOutput2.contains("[bci: 18]\n[1] state = IF(if=2#, else=0#)"));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) InstrumentPhase(org.graalvm.compiler.truffle.compiler.phases.InstrumentPhase) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 43 with RootTestNode

use of org.graalvm.compiler.truffle.test.nodes.RootTestNode in project graal by oracle.

the class BailoutPartialEvaluationTest method partialEvaluationConstantBailout2.

@Test(expected = BailoutException.class)
public void partialEvaluationConstantBailout2() {
    FrameDescriptor fd = new FrameDescriptor();
    RootTestNode rootNode = new RootTestNode(fd, "partialEvaluationConstantBailout2", new AbstractTestNode() {

        @Override
        public int execute(VirtualFrame frame) {
            CompilerAsserts.partialEvaluationConstant(notConstantInt);
            return 0;
        }
    });
    compileHelper("partialEvaluationConstantBailout2", rootNode, new Object[] {});
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 44 with RootTestNode

use of org.graalvm.compiler.truffle.test.nodes.RootTestNode in project graal by oracle.

the class CompilationFinalWeakReferencePartialEvaluationTest method compilationFinalWeakReferenceTest.

/**
 * {@link WeakReference} constant-folded but not embedded in compiled code.
 */
@Test
public void compilationFinalWeakReferenceTest() {
    String name = "compilationFinalWeakReferenceTest";
    FrameDescriptor fd = new FrameDescriptor();
    IntSupplier data = generateTestData();
    AbstractTestNode result = new CompilationFinalWeakReferenceTestNode(data);
    RootTestNode rootNode = new RootTestNode(fd, name, result);
    assertPartialEvalEquals("constant42", rootNode);
    OptimizedCallTarget callTarget = compileHelper(name, rootNode, new Object[0]);
    Assert.assertEquals(42, (int) callTarget.call(new Object[0]));
    assert data != null;
    WeakReference<IntSupplier> witness = new WeakReference<>(data);
    data = null;
    boolean cleared = false;
    for (int i = 1; i <= 5 && !cleared; i++) {
        System.gc();
        cleared = witness.get() == null;
    }
    // Reference not embedded in compiled code
    Assert.assertEquals(42, (int) callTarget.call(new Object[0]));
    assertTrue(callTarget.isValid());
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) IntSupplier(java.util.function.IntSupplier) WeakReference(java.lang.ref.WeakReference) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 45 with RootTestNode

use of org.graalvm.compiler.truffle.test.nodes.RootTestNode in project graal by oracle.

the class CompilationFinalWeakReferencePartialEvaluationTest method compilationFinalWeakReferenceTestGC.

/**
 * {@link WeakReference} constant-folded and embedded in compiled code.
 */
@Test
public void compilationFinalWeakReferenceTestGC() {
    String name = "compilationFinalWeakReferenceTestGC";
    FrameDescriptor fd = new FrameDescriptor();
    IntSupplier data = generateTestData();
    AbstractTestNode result = new CompilationFinalWeakReferenceTestGCNode(data);
    RootTestNode rootNode = new RootTestNode(fd, name, result);
    OptimizedCallTarget callTarget = compileHelper(name, rootNode, new Object[] { data });
    Assert.assertEquals(42, (int) callTarget.call(new Object[] { data }));
    Assert.assertEquals(-1, (int) callTarget.call(new Object[] { null }));
    callTarget = compileHelper(name, rootNode, new Object[] { data });
    assertTrue(callTarget.isValid());
    assert data != null;
    clearDebugScopeTL();
    WeakReference<IntSupplier> witness = new WeakReference<>(data);
    data = null;
    boolean cleared = false;
    for (int i = 1; i <= 5 && !cleared; i++) {
        System.gc();
        cleared = witness.get() == null;
    }
    assertTrue("Test data should have been garbage collected at this point", cleared);
    // Compiled code had the collected reference embedded so it had to be invalidated
    assertFalse(callTarget.isValid());
    Assert.assertEquals(0xdead, (int) callTarget.call(new Object[] { null }));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) IntSupplier(java.util.function.IntSupplier) WeakReference(java.lang.ref.WeakReference) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Aggregations

FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)50 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)50 Test (org.junit.Test)48 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)43 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)14 ConstantTestNode (org.graalvm.compiler.truffle.test.nodes.ConstantTestNode)14 RootNode (com.oracle.truffle.api.nodes.RootNode)10 AddTestNode (org.graalvm.compiler.truffle.test.nodes.AddTestNode)7 BlockTestNode (org.graalvm.compiler.truffle.test.nodes.BlockTestNode)6 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)5 Assumption (com.oracle.truffle.api.Assumption)3 LoadLocalTestNode (org.graalvm.compiler.truffle.test.nodes.LoadLocalTestNode)3 NestedExplodedLoopTestNode (org.graalvm.compiler.truffle.test.nodes.NestedExplodedLoopTestNode)3 StoreLocalTestNode (org.graalvm.compiler.truffle.test.nodes.StoreLocalTestNode)3 CallTarget (com.oracle.truffle.api.CallTarget)2 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 WeakReference (java.lang.ref.WeakReference)2 IntSupplier (java.util.function.IntSupplier)2 BailoutException (jdk.vm.ci.code.BailoutException)2 InstrumentPhase (org.graalvm.compiler.truffle.compiler.phases.InstrumentPhase)2