use of com.oracle.truffle.api.nodes.LanguageInfo in project graal by oracle.
the class DebugALot method logValue.
private void logValue(String prefix, DebugValue v) {
LanguageInfo language = v.getOriginalLanguage();
if (language != null) {
logger.print(prefix);
logger.print("From: ");
logger.println(language.getId());
}
DebugValue metaObject = v.getMetaObject();
if (metaObject != null) {
logger.print(prefix);
logger.print("Type: ");
logger.println(metaObject.as(String.class));
}
SourceSection sourceLocation = v.getSourceLocation();
if (sourceLocation != null) {
logger.print(prefix);
logger.print("SourceSection: ");
logSourceSection(sourceLocation);
}
if (v.isArray()) {
List<DebugValue> array = v.getArray();
int length = array.size();
logger.print(prefix);
logger.print("Array of length: ");
logger.println(Integer.toString(length));
for (int i = 0; i < length && i < 10; i++) {
logger.print(prefix);
logger.print(" element #");
logger.print(Integer.toString(i));
logger.print(" : ");
logger.println(array.get(i).as(String.class));
}
}
Collection<DebugValue> properties = v.getProperties();
logger.print(prefix);
if (properties == null || properties.isEmpty()) {
logger.println("Properties: none");
} else {
logger.print("Properties: ");
logger.println(Integer.toString(properties.size()));
}
logger.print(prefix);
logger.print("Internal: ");
logger.println(v.isInternal());
logger.print(prefix);
logger.print("Readable: ");
logger.println(v.isReadable());
logger.print(prefix);
logger.print("Writable: ");
logger.println(v.isWritable());
}
use of com.oracle.truffle.api.nodes.LanguageInfo in project graal by oracle.
the class InstrumentationTest method testAccessInstrumentFromLanguage.
@Test
public void testAccessInstrumentFromLanguage() {
ReturnLanguageEnv envReturner = new ReturnLanguageEnv();
InstrumentationTestLanguage.envConfig.put(ReturnLanguageEnv.KEY, envReturner);
context.eval(Source.create(InstrumentationTestLanguage.ID, ""));
assertNotNull(envReturner.env);
TruffleLanguage.Env env = envReturner.env;
LanguageInfo langInfo = env.getLanguages().get(InstrumentationTestLanguage.ID);
assertNotNull(langInfo);
assertTrue(langInfo.getMimeTypes().contains(InstrumentationTestLanguage.MIME_TYPE));
assertEquals("InstrumentTestLang", langInfo.getName());
assertEquals("2.0", langInfo.getVersion());
InstrumentInfo instrInfo = env.getInstruments().get("testAccessInstruments");
assertNotNull(instrInfo);
assertEquals("testAccessInstruments", instrInfo.getId());
assertEquals("name", instrInfo.getName());
assertEquals("version", instrInfo.getVersion());
assertNotNull(env.lookup(instrInfo, TestAccessInstruments.class));
assertNull(env.lookup(instrInfo, SpecialService.class));
try {
// cannot load services from current languages to avoid cycles.
env.lookup(langInfo, SpecialService.class);
fail();
} catch (Exception e1) {
// expected
}
}
use of com.oracle.truffle.api.nodes.LanguageInfo in project graal by oracle.
the class InstrumentationTest method testAccessLanguages.
@Test
public void testAccessLanguages() {
Instrument instrument = engine.getInstruments().get("testAccessInstruments");
TestAccessInstruments access = instrument.lookup(TestAccessInstruments.class);
LanguageInfo info = access.env.getLanguages().get(InstrumentationTestLanguage.ID);
assertNotNull(info);
assertTrue(info.getMimeTypes().contains(InstrumentationTestLanguage.MIME_TYPE));
assertEquals("InstrumentTestLang", info.getName());
assertEquals("2.0", info.getVersion());
assertNotNull(access.env.lookup(info, SpecialService.class));
assertEquals(InstrumentationTestLanguage.FILENAME_EXTENSION, access.env.lookup(info, SpecialService.class).fileExtension());
}
use of com.oracle.truffle.api.nodes.LanguageInfo 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.LanguageInfo 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);
}
Aggregations