Search in sources :

Example 46 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget 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 47 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class OptimizedCallTargetTest method testCompileOnly4.

@Test
public void testCompileOnly4() {
    // OSR should not trigger for compile-only includes
    try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "foobar")) {
        final OSRRepeatingNode repeating = new OSRRepeatingNode(TruffleCompilerOptions.getValue(TruffleOSRCompilationThreshold));
        final LoopNode loop = runtime.createLoopNode(repeating);
        OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar") {

            @Child
            LoopNode loopChild = loop;

            @Override
            public Object execute(VirtualFrame frame) {
                loopChild.executeLoop(frame);
                return super.execute(frame);
            }
        });
        target.call();
        OptimizedCallTarget osrTarget = findOSRTarget(loop);
        if (osrTarget != null) {
            assertNotCompiled(osrTarget);
        }
    }
}
Also used : LoopNode(com.oracle.truffle.api.nodes.LoopNode) OptimizedOSRLoopNode(org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 48 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class OptimizedCallTargetTest method testCompileOnly1.

@Test
public void testCompileOnly1() {
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "foobar")) {
        OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar"));
        for (int i = 0; i < compilationThreshold; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
        target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("baz"));
        for (int i = 0; i < compilationThreshold; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertNotCompiled(target);
    }
}
Also used : TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 49 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class OptimizedOSRLoopNodeTest method testOSRMinInvocationThresholdPropagateLoopCounts.

/*
     * Test that loop counts of osr loops propagate loop counts the parent call target.
     */
@Theory
public void testOSRMinInvocationThresholdPropagateLoopCounts(OSRLoopFactory factory) {
    TestRootNode rootNode = new TestRootNode(factory, new TestRepeatingNode());
    OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(rootNode);
    int osrThreshold = OSR_THRESHOLD;
    int truffleMinInvokes = TruffleCompilerOptions.getValue(TruffleMinInvokeThreshold);
    int i;
    int invokesleft = osrThreshold;
    for (i = 0; i < truffleMinInvokes - 1; i++) {
        int invokes = osrThreshold / truffleMinInvokes;
        invokesleft -= invokes;
        target.call(invokes);
        assertNotCompiled(rootNode.getOSRTarget());
    }
    assertNotCompiled(target);
    /*
         * This should trigger OSR, but since the parent is compiling/compiled already we won't do
         * OSR.
         */
    target.call(invokesleft + 1);
    assertNotCompiled(rootNode.getOSRTarget());
    assertCompiled(target);
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) DataPoint(org.junit.experimental.theories.DataPoint) Theory(org.junit.experimental.theories.Theory)

Example 50 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget 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)

Aggregations

OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)57 Test (org.junit.Test)42 RootNode (com.oracle.truffle.api.nodes.RootNode)18 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)14 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)14 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)13 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)11 TruffleOptionsOverrideScope (org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope)8 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)6 TruffleCompilerOptions (org.graalvm.compiler.truffle.common.TruffleCompilerOptions)6 Specialization (com.oracle.truffle.api.dsl.Specialization)4 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)4 GraalTruffleRuntime (org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime)4 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)4 Theory (org.junit.experimental.theories.Theory)4 Assumption (com.oracle.truffle.api.Assumption)3 LoopNode (com.oracle.truffle.api.nodes.LoopNode)3 Ignore (org.junit.Ignore)3 Node (com.oracle.truffle.api.nodes.Node)2 WeakReference (java.lang.ref.WeakReference)2