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;
}
}
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);
}
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();
}
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]));
}
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();
}
Aggregations