Search in sources :

Example 1 with InstrumentInfo

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;
    }
}
Also used : InstrumentInfo(com.oracle.truffle.api.InstrumentInfo) Enabler(com.oracle.truffle.tools.chromeinspector.instrument.Enabler)

Example 2 with InstrumentInfo

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);
}
Also used : InstrumentInfo(com.oracle.truffle.api.InstrumentInfo) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Test(org.junit.Test)

Example 3 with InstrumentInfo

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
    }
}
Also used : LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) InstrumentInfo(com.oracle.truffle.api.InstrumentInfo) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) PolyglotException(org.graalvm.polyglot.PolyglotException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with InstrumentInfo

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;
}
Also used : InstrumentInfo(com.oracle.truffle.api.InstrumentInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Enabler(com.oracle.truffle.tools.chromeinspector.instrument.Enabler)

Example 5 with InstrumentInfo

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();
}
Also used : InstrumentInfo(com.oracle.truffle.api.InstrumentInfo) CPUTracer(com.oracle.truffle.tools.profiler.CPUTracer) Enabler(com.oracle.truffle.tools.chromeinspector.instrument.Enabler) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler)

Aggregations

InstrumentInfo (com.oracle.truffle.api.InstrumentInfo)7 Enabler (com.oracle.truffle.tools.chromeinspector.instrument.Enabler)5 Test (org.junit.Test)2 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)1 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)1 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)1 CPUSampler (com.oracle.truffle.tools.profiler.CPUSampler)1 CPUTracer (com.oracle.truffle.tools.profiler.CPUTracer)1 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Instrument (org.graalvm.polyglot.Instrument)1 PolyglotException (org.graalvm.polyglot.PolyglotException)1