Search in sources :

Example 41 with AbstractTestNode

use of org.graalvm.compiler.truffle.test.nodes.AbstractTestNode 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 42 with AbstractTestNode

use of org.graalvm.compiler.truffle.test.nodes.AbstractTestNode 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)

Example 43 with AbstractTestNode

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

the class ControlFlowExceptionPartialEvaluationTest method catchControlFlowExceptionWithLoopExplosion.

@Test
public void catchControlFlowExceptionWithLoopExplosion() {
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new CatchControlFlowExceptionTestNode(new BlockTestNode(new ThrowControlFlowExceptionTestNode()));
    assertPartialEvalEquals("constant42", new RootTestNode(fd, "catchControlFlowExceptionWithLoopExplosion", result));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 44 with AbstractTestNode

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

the class ControlFlowExceptionPartialEvaluationTest method catchControlFlowException.

@Test
public void catchControlFlowException() {
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new CatchControlFlowExceptionTestNode(new ThrowControlFlowExceptionTestNode());
    assertPartialEvalEquals("constant42", new RootTestNode(fd, "catchControlFlowException", result));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 45 with AbstractTestNode

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

the class ControlFlowExceptionPartialEvaluationTest method catchSlowPathAndControlFlowException.

@Test
public void catchSlowPathAndControlFlowException() {
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new CatchSlowPathAndControlFlowExceptionTestNode(new ThrowControlFlowExceptionTestNode());
    assertPartialEvalEquals("constant42", new RootTestNode(fd, "catchSlowPathAndControlFlowException", result));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Aggregations

AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)46 Test (org.junit.Test)45 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)43 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)43 ConstantTestNode (org.graalvm.compiler.truffle.test.nodes.ConstantTestNode)13 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)11 RootNode (com.oracle.truffle.api.nodes.RootNode)9 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 LoadLocalTestNode (org.graalvm.compiler.truffle.test.nodes.LoadLocalTestNode)4 NestedExplodedLoopTestNode (org.graalvm.compiler.truffle.test.nodes.NestedExplodedLoopTestNode)3 StoreLocalTestNode (org.graalvm.compiler.truffle.test.nodes.StoreLocalTestNode)3 Assumption (com.oracle.truffle.api.Assumption)2 CallTarget (com.oracle.truffle.api.CallTarget)2 WeakReference (java.lang.ref.WeakReference)2 IntSupplier (java.util.function.IntSupplier)2 LoopTestNode (org.graalvm.compiler.truffle.test.nodes.LoopTestNode)2 TwoMergesExplodedLoopTestNode (org.graalvm.compiler.truffle.test.nodes.TwoMergesExplodedLoopTestNode)2 Ignore (org.junit.Ignore)2