Search in sources :

Example 16 with OptimizedCallTarget

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

the class SimplePartialEvaluationTest method intrinsicHashCode.

@Test
public void intrinsicHashCode() {
    /*
         * The intrinsic for Object.hashCode() is inlined late during Truffle partial evaluation,
         * because we call hashCode() on a value whose exact type Object is only known during
         * partial evaluation.
         */
    FrameDescriptor fd = new FrameDescriptor();
    Object testObject = new Object();
    AbstractTestNode result = new ObjectHashCodeNode(testObject);
    RootNode rootNode = new RootTestNode(fd, "intrinsicHashCode", result);
    OptimizedCallTarget compilable = compileHelper("intrinsicHashCode", rootNode, new Object[0]);
    int actual = (Integer) compilable.call(new Object[0]);
    int expected = testObject.hashCode();
    Assert.assertEquals(expected, actual);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) ObjectHashCodeNode(org.graalvm.compiler.truffle.test.nodes.ObjectHashCodeNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 17 with OptimizedCallTarget

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

the class SimplePartialEvaluationTest method synchronizedExceptionMerge.

@Test
public void synchronizedExceptionMerge() {
    /*
         * Multiple non-inlineable methods with exception edges called from a synchronized method
         * lead to a complicated Graal graph that involves the BytecodeFrame.UNWIND_BCI. This test
         * checks that partial evaluation handles that case correctly.
         */
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new SynchronizedExceptionMergeNode();
    RootNode rootNode = new RootTestNode(fd, "synchronizedExceptionMerge", result);
    OptimizedCallTarget compilable = compileHelper("synchronizedExceptionMerge", rootNode, new Object[0]);
    Assert.assertEquals(42, compilable.call(new Object[0]));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) SynchronizedExceptionMergeNode(org.graalvm.compiler.truffle.test.nodes.SynchronizedExceptionMergeNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 18 with OptimizedCallTarget

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

the class SimplePartialEvaluationTest method intrinsicVirtual.

@Test
public void intrinsicVirtual() {
    /*
         * The intrinsic for String.equals() is inlined late during Truffle partial evaluation,
         * because we call equals() on a value that has the static type Object, but during partial
         * evaluation the more precise type String is known.
         */
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new ObjectEqualsNode("abc", "abf");
    RootNode rootNode = new RootTestNode(fd, "intrinsicVirtual", result);
    OptimizedCallTarget compilable = compileHelper("intrinsicVirtual", rootNode, new Object[0]);
    Assert.assertEquals(42, compilable.call(new Object[0]));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) ObjectEqualsNode(org.graalvm.compiler.truffle.test.nodes.ObjectEqualsNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 19 with OptimizedCallTarget

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

the class SimplePartialEvaluationTest method loopExplosionPhi.

@Test
public void loopExplosionPhi() {
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new LoopExplosionPhiNode();
    RootNode rootNode = new RootTestNode(fd, "loopExplosionPhi", result);
    OptimizedCallTarget compilable = compileHelper("loopExplosionPhi", rootNode, new Object[0]);
    Assert.assertEquals(1, compilable.call(new Object[0]));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) LoopExplosionPhiNode(org.graalvm.compiler.truffle.test.nodes.LoopExplosionPhiNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 20 with OptimizedCallTarget

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

the class TransferToInterpreterTest method test.

@Test
public void test() {
    RootNode rootNode = new TestRootNode();
    GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime();
    OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(rootNode);
    target.call(0);
    Assert.assertFalse(target.isValid());
    OptionValues options = TruffleCompilerOptions.getOptions();
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    final OptimizedCallTarget compilable = target;
    TruffleCompilerImpl compiler = (TruffleCompilerImpl) runtime.newTruffleCompiler();
    CompilationIdentifier compilationId = compiler.getCompilationIdentifier(compilable);
    TruffleInliningPlan inliningPlan = new TruffleInlining(compilable, new DefaultInliningPolicy());
    compiler.compileAST(debug, compilable, inliningPlan, compilationId, null, null);
    Assert.assertTrue(target.isValid());
    target.call(0);
    Assert.assertTrue(target.isValid());
    target.call(1);
    Assert.assertFalse(target.isValid());
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleInliningPlan(org.graalvm.compiler.truffle.common.TruffleInliningPlan) CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) OptionValues(org.graalvm.compiler.options.OptionValues) TruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl) GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) DefaultInliningPolicy(org.graalvm.compiler.truffle.runtime.DefaultInliningPolicy) TruffleInlining(org.graalvm.compiler.truffle.runtime.TruffleInlining) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) DebugContext(org.graalvm.compiler.debug.DebugContext) 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