use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class TckLanguage method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
Source code = request.getSource();
final RootNode root;
final String txt = code.getCharacters().toString();
if (txt.startsWith("TCK42:")) {
int nextColon = txt.indexOf(":", 6);
String mimeType = txt.substring(6, nextColon);
Source toParse = Source.newBuilder(txt.substring(nextColon + 1)).mimeType(mimeType).name("src.tck").build();
root = new MultiplyNode(this, toParse);
} else {
final double value = Double.parseDouble(txt);
root = RootNode.createConstantNode(value);
}
return Truffle.getRuntime().createCallTarget(root);
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SourceSectionFilterTest method testIgnoreInternal.
@Test
public void testIgnoreInternal() throws Exception {
SourceSectionFilter internalFilter = SourceSectionFilter.newBuilder().includeInternal(false).build();
SourceSectionFilter defaultFilter = SourceSectionFilter.newBuilder().build();
Assert.assertTrue(isInstrumented(internalFilter, null, source()));
Source nonInternalSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
// Default non-internal RootNode
RootNode root = createRootNode(nonInternalSource.createSection(0, 23), null);
Assert.assertTrue(isInstrumented(internalFilter, root, createNode(nonInternalSource.createSection(1))));
// Internal RootNode
root = createRootNode(nonInternalSource.createSection(0, 23), true);
Assert.assertFalse(isInstrumented(internalFilter, root, createNode(nonInternalSource.createSection(1))));
Assert.assertTrue(isInstrumented(defaultFilter, root, createNode(nonInternalSource.createSection(1))));
Source internalSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).internal().build();
// Default internal RootNode
root = createRootNode(internalSource.createSection(0, 23), null);
Assert.assertFalse(isInstrumented(internalFilter, root, createNode(internalSource.createSection(1))));
// Non-internal RootNode
root = createRootNode(nonInternalSource.createSection(0, 23), false);
Assert.assertTrue(isInstrumented(internalFilter, root, createNode(internalSource.createSection(1))));
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SourceSectionFilterTest method createRootNode.
static RootNode createRootNode(Engine engine, final SourceSection section, final Boolean internal, Node... children) throws Exception {
Language language = engine.getLanguages().get(InstrumentationTestLanguage.ID);
Field impl = Language.class.getDeclaredField("impl");
ReflectionUtils.setAccessible(impl, true);
Object polyglotLanguage = impl.get(language);
Method ensureInitialized = polyglotLanguage.getClass().getDeclaredMethod("ensureInitialized");
ReflectionUtils.setAccessible(ensureInitialized, true);
ensureInitialized.invoke(polyglotLanguage);
Field info = polyglotLanguage.getClass().getDeclaredField("info");
ReflectionUtils.setAccessible(info, true);
LanguageInfo languageInfo = (LanguageInfo) info.get(polyglotLanguage);
Field spi = LanguageInfo.class.getDeclaredField("spi");
ReflectionUtils.setAccessible(spi, true);
TruffleLanguage<?> truffleLanguage = (TruffleLanguage<?>) spi.get(languageInfo);
return new RootNode(truffleLanguage) {
@Node.Children
Node[] rootChildren = children;
@Override
protected boolean isInstrumentable() {
return true;
}
@Override
public SourceSection getSourceSection() {
return section;
}
@Override
public boolean isInternal() {
if (internal == null) {
return super.isInternal();
} else {
return internal;
}
}
@Override
public Object execute(VirtualFrame frame) {
return null;
}
};
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class UnwindInstrumentationReturnSnippets method isLanguageContextInitialized.
/**
* Test if language context of the source of the event is initialized.
*
* @since 0.26
*/
public boolean isLanguageContextInitialized() {
CompilerAsserts.neverPartOfCompilation();
Node node = getInstrumentedNode();
if (node == null) {
return true;
}
RootNode root = node.getRootNode();
if (root == null) {
return true;
}
LanguageInfo languageInfo = root.getLanguageInfo();
Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo);
return AccessorInstrumentHandler.langAccess().isContextInitialized(env);
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class UnwindInstrumentationReturnSnippets method validEventContext.
@SuppressWarnings("unchecked")
boolean validEventContext() {
Node node = getInstrumentedNode();
if (node instanceof RootNode) {
throw new IllegalStateException("Instrumentable node must not be a root node.");
}
Object object = null;
if (node instanceof InstrumentableNode) {
object = ((InstrumentableNode) node).getNodeObject();
} else {
// legacy support
return true;
}
if (object != null) {
assert AccessorInstrumentHandler.interopAccess().isValidNodeObject(object);
}
boolean foundStandardTag = false;
for (Class<?> clazz : StandardTags.ALL_TAGS) {
if (hasTag((Class<? extends Tag>) clazz)) {
foundStandardTag = true;
}
}
if (foundStandardTag) {
RootNode root = probeNode.getRootNode();
if (root != null && root.getSourceSection() != null) {
assert sourceSection != null : "All nodes tagged with a standard tag and with a root node that has a source section must also have a source section.";
}
}
return true;
}
Aggregations