Search in sources :

Example 6 with OptimizedCallTarget

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

the class IndirectCallSiteTest method testIndirectCallNodeDoesNotDeoptOnTypeChangeWithInlining1.

/**
 * Tests that a {@link CallTarget} will not deoptimize if it calls (using an
 * {@link IndirectCallNode}) a target previously compiled with a different argument assumption
 * and also inlined into another compiled target.
 */
@Test
public void testIndirectCallNodeDoesNotDeoptOnTypeChangeWithInlining1() {
    try (TruffleCompilerOptions.TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleFunctionInlining, true)) {
        final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
        final OptimizedCallTarget saveArgumentToGlobalState = (OptimizedCallTarget) runtime.createCallTarget(new WritesToGlobalState());
        final OptimizedCallTarget targetWithDirectCall = (OptimizedCallTarget) runtime.createCallTarget(new DirectlyCallsTargetWithArguments(saveArgumentToGlobalState, new Object[] { 1 }));
        final OptimizedCallTarget dummyInnerTarget = (OptimizedCallTarget) runtime.createCallTarget(new DummyTarget());
        final OptimizedCallTarget targetWithIndirectCall = (OptimizedCallTarget) runtime.createCallTarget(new IndirectCallTargetFromArgument());
        for (int i = 0; i < compilationThreshold; i++) {
            targetWithDirectCall.call(new Object[0]);
        }
        assertCompiled(targetWithDirectCall);
        assertNotDeoptimized(targetWithDirectCall);
        assertCompiled(saveArgumentToGlobalState);
        assertNotDeoptimized(saveArgumentToGlobalState);
        for (int i = 0; i < compilationThreshold; i++) {
            targetWithIndirectCall.call(new Object[] { dummyInnerTarget });
        }
        assertCompiled(targetWithIndirectCall);
        assertNotDeoptimized(targetWithIndirectCall);
        globalState[0] = 0;
        targetWithIndirectCall.call(new Object[] { saveArgumentToGlobalState });
        Assert.assertEquals("Global state not updated!", LOREM_IPSUM, globalState[0]);
        assertCompiled(targetWithIndirectCall);
        // targetWithDirectCall is unaffected by inlining
        assertCompiled(targetWithDirectCall);
        assertNotDeoptimized(targetWithDirectCall);
        // saveArgumentToGlobalState compilation is delayed by the invalidation
        assertNotCompiled(saveArgumentToGlobalState);
        assertNotDeoptimized(saveArgumentToGlobalState);
        Assert.assertEquals("saveArgumentToGlobalState was not invalidated!", 1, saveArgumentToGlobalState.getCompilationProfile().getInvalidationCount());
    }
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) TruffleCompilerOptions(org.graalvm.compiler.truffle.common.TruffleCompilerOptions) Test(org.junit.Test)

Example 7 with OptimizedCallTarget

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

the class OptimizedCallTargetTest method testCompileOnly2.

@Test
public void testCompileOnly2() {
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    // test single exclude
    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();
        }
        assertNotCompiled(target);
        target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("baz"));
        for (int i = 0; i < compilationThreshold; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
    }
}
Also used : TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 8 with OptimizedCallTarget

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

the class OptimizedCallTargetTest method testCompileOnly3.

@Test
public void testCompileOnly3() {
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    // test two includes/excludes
    try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "foo,baz")) {
        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();
        }
        assertCompiled(target);
    }
}
Also used : TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 9 with OptimizedCallTarget

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

the class OptimizedCallTargetTest method testCompilationHeuristics.

/*
     * GR-1328
     */
@Test
@Ignore("Fails non deterministically")
public void testCompilationHeuristics() {
    testInvalidationCounterCompiled = 0;
    testInvalidationCounterInterpreted = 0;
    doInvalidate = false;
    OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            if (CompilerDirectives.inInterpreter()) {
                testInvalidationCounterInterpreted++;
            } else {
                testInvalidationCounterCompiled++;
            }
            // doInvalidate needs to be volatile otherwise it floats up.
            if (doInvalidate) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
            }
            return null;
        }
    });
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    final int reprofileCount = TruffleCompilerOptions.getValue(TruffleReplaceReprofileCount);
    assertTrue(compilationThreshold >= 2);
    int expectedCompiledCount = 0;
    int expectedInterpreterCount = 0;
    for (int i = 0; i < compilationThreshold; i++) {
        assertNotCompiled(target);
        target.call();
    }
    assertCompiled(target);
    expectedInterpreterCount += compilationThreshold;
    assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
    assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
    for (int j = 1; j < 100; j++) {
        target.invalidate(this, "test");
        for (int i = 0; i < reprofileCount; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedInterpreterCount += reprofileCount;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        doInvalidate = true;
        expectedCompiledCount++;
        target.call();
        assertNotCompiled(target);
        doInvalidate = false;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        for (int i = 0; i < reprofileCount; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedInterpreterCount += reprofileCount;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        for (int i = 0; i < compilationThreshold; i++) {
            assertCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedCompiledCount += compilationThreshold;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
    }
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with OptimizedCallTarget

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

the class OptimizedCallTargetTest method testCompileOnly5.

@Test
public void testCompileOnly5() {
    // OSR should trigger if compile-only with excludes
    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);
        assertCompiled(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)

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