Search in sources :

Example 51 with OptimizedCallTarget

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

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

the class SLCallUntilOptimizedBuiltin method callUntilCompiled.

@Specialization
public SLFunction callUntilCompiled(SLFunction function, boolean checkTarget) {
    OptimizedCallTarget target = ((OptimizedCallTarget) function.getCallTarget());
    for (int i = 0; i < MAX_CALLS; i++) {
        if (isCompiling(target)) {
            break;
        } else {
            indirectCall.call(target, EMPTY_ARGS);
        }
    }
    // call one more in compiled
    indirectCall.call(target, EMPTY_ARGS);
    if (checkTarget) {
        checkTarget(target);
    }
    return function;
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 53 with OptimizedCallTarget

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

the class SLCallWithOptionOverrideBuiltin method callWithOptionOverride.

@Specialization
public SLFunction callWithOptionOverride(SLFunction function, String name, Object value) {
    TruffleOptionsOverrideScope scope = override(name, value);
    OptimizedCallTarget target = ((OptimizedCallTarget) function.getCallTarget());
    indirectCall.call(target, EMPTY_ARGS);
    close(scope);
    return function;
}
Also used : TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 54 with OptimizedCallTarget

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

the class SLWaitForOptimizationBuiltin method waitForOptimization.

@Specialization
public SLFunction waitForOptimization(SLFunction function, long timeout) {
    OptimizedCallTarget target = (OptimizedCallTarget) function.getCallTarget();
    GraalTruffleRuntime runtime = ((GraalTruffleRuntime) Truffle.getRuntime());
    try {
        runtime.waitForCompilation(target, timeout);
    } catch (ExecutionException | TimeoutException e) {
        throw new RuntimeException(e);
    }
    return function;
}
Also used : GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 55 with OptimizedCallTarget

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

the class TraceSplittingListener method onCompilationSplit.

@Override
public void onCompilationSplit(OptimizedDirectCallNode callNode) {
    OptimizedCallTarget callTarget = callNode.getCallTarget();
    String label = String.format("split %3s-%-4s-%-4s ", splitCount++, Integer.toHexString(callNode.getCurrentCallTarget().hashCode()), callNode.getCallCount());
    final Map<String, Object> debugProperties = callTarget.getDebugProperties(null);
    debugProperties.put("SourceSection", extractSourceSection(callNode));
    TruffleCompilerRuntime.getRuntime().logEvent(0, label, callTarget.toString(), debugProperties);
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)

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