Search in sources :

Example 11 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class DebugStackFrame method findCurrentRoot.

RootNode findCurrentRoot() {
    SuspendedContext context = getContext();
    if (currentFrame == null) {
        return context.getInstrumentedNode().getRootNode();
    } else {
        Node callNode = currentFrame.getCallNode();
        if (callNode != null) {
            return callNode.getRootNode();
        }
        CallTarget target = currentFrame.getCallTarget();
        if (target instanceof RootCallTarget) {
            return ((RootCallTarget) target).getRootNode();
        }
        return null;
    }
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 12 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class DebugStackFrame method getScope.

/**
 * Get the current inner-most scope. The scope remain valid as long as the current stack frame
 * remains valid.
 * <p>
 * Use {@link DebuggerSession#getTopScope(java.lang.String)} to get scopes with global validity.
 * <p>
 * This method is not thread-safe and will throw an {@link IllegalStateException} if called on
 * another thread than it was created with.
 *
 * @return the scope, or <code>null</code> when no language is associated with this frame
 *         location, or when no local scope exists.
 * @since 0.26
 */
public DebugScope getScope() {
    verifyValidState(false);
    SuspendedContext context = getContext();
    RootNode root = findCurrentRoot();
    if (root == null) {
        return null;
    }
    Node node;
    if (currentFrame == null) {
        node = context.getInstrumentedNode();
    } else {
        node = currentFrame.getCallNode();
    }
    if (node.getRootNode().getLanguageInfo() == null) {
        // no language, no scopes
        return null;
    }
    Debugger debugger = event.getSession().getDebugger();
    MaterializedFrame frame = findTruffleFrame();
    Iterable<Scope> scopes = debugger.getEnv().findLocalScopes(node, frame);
    Iterator<Scope> it = scopes.iterator();
    if (!it.hasNext()) {
        return null;
    }
    return new DebugScope(it.next(), it, debugger, event, frame, root);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Scope(com.oracle.truffle.api.Scope) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame)

Example 13 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class DebugStackFrame method isInternal.

/**
 * Returns whether this stack frame is a language implementation artifact that should be hidden
 * during normal guest language debugging, for example in stack traces.
 * <p>
 * Language implementations sometimes create method calls internally that do not correspond to
 * anything explicitly written by a programmer, for example when the body of a looping construct
 * is implemented as callable block. Language implementors mark these methods as
 * <em>internal</em>.
 * </p>
 * <p>
 * Clients of the debugging API should assume that displaying <em>internal</em> frames is
 * unlikely to help programmers debug guest language programs and might possibly create
 * confusion. However, clients may choose to display all frames, for example in a special mode
 * to support development of programming language implementations.
 * </p>
 * <p>
 * The decision to mark a method as <em>internal</em> is language-specific, reflects judgments
 * about tool usability, and is subject to change.
 * <p>
 * This method is thread-safe.
 *
 * @since 0.17
 */
public boolean isInternal() {
    verifyValidState(true);
    RootNode root = findCurrentRoot();
    if (root == null) {
        return true;
    }
    return root.isInternal();
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode)

Example 14 with RootNode

use of com.oracle.truffle.api.nodes.RootNode 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 15 with RootNode

use of com.oracle.truffle.api.nodes.RootNode 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)

Aggregations

RootNode (com.oracle.truffle.api.nodes.RootNode)86 Test (org.junit.Test)36 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)24 Node (com.oracle.truffle.api.nodes.Node)23 CallTarget (com.oracle.truffle.api.CallTarget)16 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)16 RootCallTarget (com.oracle.truffle.api.RootCallTarget)12 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)12 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)9 Source (com.oracle.truffle.api.source.Source)8 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)8 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 ArrayList (java.util.ArrayList)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)3