Search in sources :

Example 11 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class ArrayTest method testNode1.

@Test
public void testNode1() {
    final TestNode1 node = TestNode1NodeGen.create(null);
    RootNode root = new RootNode(null) {

        @Child
        TestNode1 test = node;

        @Override
        public Object execute(VirtualFrame frame) {
            return test.executeWith(frame, frame.getArguments()[0]);
        }
    };
    CallTarget target = Truffle.getRuntime().createCallTarget(root);
    Assert.assertEquals(1, (int) target.call(1));
    Assert.assertArrayEquals(new double[0], (double[]) target.call(new int[0]), 0.0d);
    Assert.assertArrayEquals(new double[0], (double[]) target.call(new double[0]), 0.0d);
    Assert.assertArrayEquals(new String[0], (String[]) target.call((Object) new String[0]));
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 12 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class FrameTest method testFrameDescriptorAccess1.

@Test
public void testFrameDescriptorAccess1() {
    FrameDescriptorAccess1Node node = FrameDescriptorAccess1NodeGen.create();
    FrameDescriptor descriptor = new FrameDescriptor();
    VirtualFrame frame = Truffle.getRuntime().createVirtualFrame(null, descriptor);
    Assert.assertSame(frame.getFrameDescriptor(), node.execute(frame, 2));
    Assert.assertSame(frame.getFrameDescriptor(), node.execute(frame, 3));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Test(org.junit.Test)

Example 13 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class FrameTest method testFrameDescriptorAccess2.

@Test
public void testFrameDescriptorAccess2() {
    FrameDescriptorAccess2Node node = FrameDescriptorAccess2NodeGen.create();
    FrameDescriptor descriptor = new FrameDescriptor();
    VirtualFrame frame = Truffle.getRuntime().createVirtualFrame(null, descriptor);
    Assert.assertSame(frame.getFrameDescriptor(), node.execute(frame, 2));
    Assert.assertSame(frame.getFrameDescriptor(), node.execute(frame, 3));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Test(org.junit.Test)

Example 14 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class LanguageSPITest method testPolyglotBindingsMultiThreaded.

@Test
public void testPolyglotBindingsMultiThreaded() throws InterruptedException, ExecutionException, TimeoutException {
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
            return true;
        }

        @Override
        protected CallTarget parse(ParsingRequest request) throws Exception {
            return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {

                @Override
                public Object execute(VirtualFrame frame) {
                    return getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
                }
            });
        }
    });
    Context c = Context.create();
    ExecutorService service = Executors.newFixedThreadPool(20);
    Value languageBindings = c.eval(ProxyLanguage.ID, "");
    Value polyglotBindings = c.getPolyglotBindings();
    List<Future<?>> futures = new ArrayList<>();
    for (int i = 0; i < 2000; i++) {
        futures.add(service.submit(() -> {
            polyglotBindings.putMember("foo", "bar");
            assertEquals("bar", polyglotBindings.getMember("foo").asString());
            assertEquals("bar", languageBindings.getMember("foo").asString());
            languageBindings.putMember("baz", "42");
            assertEquals("42", polyglotBindings.getMember("baz").asString());
            assertEquals("42", languageBindings.getMember("baz").asString());
        }));
    }
    for (Future<?> future : futures) {
        future.get(100000, TimeUnit.MILLISECONDS);
    }
    service.shutdown();
    service.awaitTermination(100000, TimeUnit.MILLISECONDS);
    c.close();
}
Also used : Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleException(com.oracle.truffle.api.TruffleException) PolyglotException(org.graalvm.polyglot.PolyglotException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) ExecutionException(java.util.concurrent.ExecutionException) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) ExecutorService(java.util.concurrent.ExecutorService) Value(org.graalvm.polyglot.Value) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 15 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class LanguageSPITest method testPolyglotBindingsPreserveLanguage.

@Test
public void testPolyglotBindingsPreserveLanguage() {
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected CallTarget parse(ParsingRequest request) throws Exception {
            return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {

                @Override
                public Object execute(VirtualFrame frame) {
                    Object bindings = getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
                    try {
                        ForeignAccess.sendWrite(Message.WRITE.createNode(), (TruffleObject) bindings, "exportedValue", "convertOnToString");
                    } catch (UnknownIdentifierException | UnsupportedTypeException | UnsupportedMessageException e) {
                        throw new AssertionError(e);
                    }
                    return bindings;
                }
            });
        }

        @Override
        protected String toString(LanguageContext context, Object value) {
            if (value.equals("convertOnToString")) {
                return "myStringToString";
            }
            return super.toString(context, value);
        }
    });
    Context c = Context.create();
    c.eval(ProxyLanguage.ID, "");
    assertEquals("Make sure language specific toString was invoked.", "myStringToString", c.getPolyglotBindings().getMember("exportedValue").toString());
}
Also used : Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TimeoutException(java.util.concurrent.TimeoutException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleException(com.oracle.truffle.api.TruffleException) PolyglotException(org.graalvm.polyglot.PolyglotException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) ExecutionException(java.util.concurrent.ExecutionException) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Aggregations

VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)48 Test (org.junit.Test)34 RootNode (com.oracle.truffle.api.nodes.RootNode)27 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)14 CallTarget (com.oracle.truffle.api.CallTarget)11 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)9 RootCallTarget (com.oracle.truffle.api.RootCallTarget)6 EventContext (com.oracle.truffle.api.instrumentation.EventContext)5 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)5 ExecutionEventListener (com.oracle.truffle.api.instrumentation.ExecutionEventListener)4 Node (com.oracle.truffle.api.nodes.Node)4 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)4 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)4 Ignore (org.junit.Ignore)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3