use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class InputFilterTest method assertCleanedUp.
private void assertCleanedUp(String code) {
// first we capture all root nodes used by the code.
Set<RootNode> rootNodes = new HashSet<>();
EventBinding<?> binding = instrumenter.attachExecutionEventListener(SourceSectionFilter.ANY, new ExecutionEventListener() {
public void onEnter(EventContext c, VirtualFrame frame) {
addRoot(c);
}
@TruffleBoundary
private void addRoot(EventContext c) {
rootNodes.add(c.getInstrumentedNode().getRootNode());
}
public void onReturnValue(EventContext c, VirtualFrame frame, Object result) {
}
public void onReturnExceptional(EventContext c, VirtualFrame frame, Throwable exception) {
}
});
execute(code);
binding.dispose();
// we execute again to let the instrumentation wrappers be cleaned up
execute(code);
for (RootNode root : rootNodes) {
// all frame slots got removed
assertEquals(new HashSet<>(), root.getFrameDescriptor().getIdentifiers());
// no wrappers left
root.accept(new NodeVisitor() {
public boolean visit(Node node) {
if (node instanceof WrapperNode) {
throw new AssertionError();
}
return true;
}
});
}
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class SLDefineFunctionBuiltin method defineFunction.
@TruffleBoundary
@Specialization
public String defineFunction(String code) {
// @formatter:off
Source source = Source.newBuilder(code).name("[defineFunction]").mimeType(SLLanguage.MIME_TYPE).build();
// @formatter:on
/* The same parsing code as for parsing the initial source. */
getContext().getFunctionRegistry().register(source);
return code;
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class SLHelloEqualsWorldBuiltin method change.
@Specialization
@TruffleBoundary
public String change() {
FrameInstance frameInstance = Truffle.getRuntime().getCallerFrame();
Frame frame = frameInstance.getFrame(FrameAccess.READ_WRITE);
FrameSlot slot = frame.getFrameDescriptor().findOrAddFrameSlot("hello");
frame.setObject(slot, "world");
return "world";
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class SLStatementNode method getSourceSection.
/*
* The creation of source section can be implemented lazily by looking up the root node source
* and then creating the source section object using the indices stored in the node. This avoids
* the eager creation of source section objects during parsing and creates them only when they
* are needed. Alternatively, if the language uses source sections to implement language
* semantics, then it might be more efficient to eagerly create source sections and store it in
* the AST.
*
* For more details see {@link InstrumentableNode}.
*/
@Override
@TruffleBoundary
public final SourceSection getSourceSection() {
if (sourceCharIndex == NO_SOURCE) {
// AST node without source
return null;
}
RootNode rootNode = getRootNode();
if (rootNode == null) {
// not yet adopted yet
return null;
}
SourceSection rootSourceSection = rootNode.getSourceSection();
if (rootSourceSection == null) {
return null;
}
Source source = rootSourceSection.getSource();
if (sourceCharIndex == UNAVAILABLE_SOURCE) {
return source.createUnavailableSection();
} else {
return source.createSection(sourceCharIndex, sourceLength);
}
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class SLDisableSplittingBuiltin method disableSplitting.
@Specialization
@TruffleBoundary
public SLNull disableSplitting(@SuppressWarnings("unused") SLNull argument) {
RootNode parentRoot = Truffle.getRuntime().getCallerFrame().getCallNode().getRootNode();
((SLRootNode) parentRoot).setCloningAllowed(false);
return SLNull.SINGLETON;
}
Aggregations