use of com.oracle.truffle.api.InstrumentInfo in project graal by oracle.
the class TruffleExecutionContext method releaseScriptsHandler.
public void releaseScriptsHandler() {
if (schCounter.decrementAndGet() == 0) {
InstrumentInfo instrumentInfo = getEnv().getInstruments().get(SourceLoadInstrument.ID);
getEnv().lookup(instrumentInfo, Enabler.class).disable();
sch = null;
schCounter = null;
}
}
use of com.oracle.truffle.api.InstrumentInfo in project graal by oracle.
the class InstrumentationTest method testAccessInstruments.
@Test
public void testAccessInstruments() {
Instrument instrument = engine.getInstruments().get("testAccessInstruments");
TestAccessInstruments access = instrument.lookup(TestAccessInstruments.class);
InstrumentInfo info = access.env.getInstruments().get("testAccessInstruments");
assertNotNull(info);
assertEquals("testAccessInstruments", info.getId());
assertEquals("name", info.getName());
assertEquals("version", info.getVersion());
try {
access.env.lookup(info, TestAccessInstruments.class);
fail();
} catch (IllegalArgumentException e) {
// expected
}
TestAccessInstrumentsOther.initializedCount = 0;
InstrumentInfo other = access.env.getInstruments().get("testAccessInstrumentsOther");
assertNotNull(other);
assertEquals("testAccessInstrumentsOther", other.getId());
assertEquals("otherName", other.getName());
assertEquals("otherVersion", other.getVersion());
assertEquals(0, TestAccessInstrumentsOther.initializedCount);
// invalid service, should not trigger onCreate
assertNull(access.env.lookup(other, Object.class));
assertEquals(0, TestAccessInstrumentsOther.initializedCount);
// valide service, should trigger onCreate
assertNotNull(access.env.lookup(other, TestAccessInstrumentsOther.class));
assertEquals(1, TestAccessInstrumentsOther.initializedCount);
}
use of com.oracle.truffle.api.InstrumentInfo 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.InstrumentInfo in project graal by oracle.
the class TruffleExecutionContext method getScriptsHandler.
public ScriptsHandler getScriptsHandler() {
if (sch == null) {
InstrumentInfo instrumentInfo = getEnv().getInstruments().get(SourceLoadInstrument.ID);
getEnv().lookup(instrumentInfo, Enabler.class).enable();
sch = getEnv().lookup(instrumentInfo, ScriptsHandler.Provider.class).getScriptsHandler();
schCounter = new AtomicInteger(0);
}
schCounter.incrementAndGet();
return sch;
}
use of com.oracle.truffle.api.InstrumentInfo in project graal by oracle.
the class TruffleProfiler method doEnable.
private void doEnable() {
slh = context.getScriptsHandler();
sampler = context.getEnv().lookup(context.getEnv().getInstruments().get(CPUSamplerInstrument.ID), CPUSampler.class);
tracer = context.getEnv().lookup(context.getEnv().getInstruments().get(CPUTracerInstrument.ID), CPUTracer.class);
InstrumentInfo instrumentInfo = context.getEnv().getInstruments().get(TypeProfileInstrument.ID);
context.getEnv().lookup(instrumentInfo, Enabler.class).enable();
typeHandler = context.getEnv().lookup(instrumentInfo, TypeHandler.Provider.class).getTypeHandler();
}
Aggregations