Search in sources :

Example 1 with Instrumenter

use of com.oracle.truffle.api.instrumentation.Instrumenter in project graal by oracle.

the class TypeHandler method start.

public boolean start() {
    if (currentBinding.get() == null) {
        final SourceSectionFilter filter = SourceSectionFilter.newBuilder().tagIs(StandardTags.RootTag.class).includeInternal(false).build();
        final Instrumenter instrumenter = env.getInstrumenter();
        final EventBinding<TypeProfileEventFactory> binding = instrumenter.attachExecutionEventFactory(filter, new TypeProfileEventFactory());
        if (currentBinding.compareAndSet(null, binding)) {
            return true;
        } else {
            binding.dispose();
        }
    }
    return false;
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Instrumenter(com.oracle.truffle.api.instrumentation.Instrumenter) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags)

Example 2 with Instrumenter

use of com.oracle.truffle.api.instrumentation.Instrumenter in project graal by oracle.

the class InstrumentationTest method testQueryTags2.

/*
     * Test behavior of queryTags when used with languages
     */
@Test
public void testQueryTags2() throws IOException {
    Instrument instrument = engine.getInstruments().get("testIsNodeTaggedWith1");
    assureEnabled(instrument);
    TestIsNodeTaggedWith1.expressionNode = null;
    TestIsNodeTaggedWith1.statementNode = null;
    TestIsNodeTaggedWith1Language.instrumenter = null;
    Source otherLanguageSource = Source.create("testIsNodeTaggedWith1-lang", "STATEMENT(EXPRESSION)");
    run(otherLanguageSource);
    Instrumenter instrumenter = TestIsNodeTaggedWith1Language.instrumenter;
    Node languageExpression = TestIsNodeTaggedWith1.expressionNode;
    Node languageStatement = TestIsNodeTaggedWith1.statementNode;
    assertTags(instrumenter.queryTags(languageExpression), InstrumentationTestLanguage.EXPRESSION);
    assertTags(instrumenter.queryTags(languageStatement), InstrumentationTestLanguage.STATEMENT);
    TestIsNodeTaggedWith1.expressionNode = null;
    TestIsNodeTaggedWith1.statementNode = null;
    run("EXPRESSION");
    // fail if called with nodes from a different language
    Node otherLanguageExpression = TestIsNodeTaggedWith1.expressionNode;
    try {
        instrumenter.queryTags(otherLanguageExpression);
        Assert.fail();
    } catch (IllegalArgumentException e) {
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) Node(com.oracle.truffle.api.nodes.Node) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Instrumenter(com.oracle.truffle.api.instrumentation.Instrumenter) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 3 with Instrumenter

use of com.oracle.truffle.api.instrumentation.Instrumenter in project graal by oracle.

the class CoverageExample method onCreate.

@Override
protected void onCreate(final Env env) {
    SourceSectionFilter.Builder builder = SourceSectionFilter.newBuilder();
    SourceSectionFilter filter = builder.tagIs(EXPRESSION).build();
    Instrumenter instrumenter = env.getInstrumenter();
    instrumenter.attachExecutionEventFactory(filter, new CoverageEventFactory(env));
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Instrumenter(com.oracle.truffle.api.instrumentation.Instrumenter)

Example 4 with Instrumenter

use of com.oracle.truffle.api.instrumentation.Instrumenter in project graal by oracle.

the class InstrumentationTest method testQueryTags1.

/*
     * Test behavior of queryTags when used with instruments
     */
@Test
public void testQueryTags1() throws IOException {
    Instrument instrument = engine.getInstruments().get("testIsNodeTaggedWith1");
    Instrumenter instrumenter = instrument.lookup(Instrumenter.class);
    TestIsNodeTaggedWith1.expressionNode = null;
    TestIsNodeTaggedWith1.statementNode = null;
    Assert.assertTrue(instrumenter.queryTags(new Node() {
    }).isEmpty());
    run("STATEMENT(EXPRESSION)");
    assertTags(instrumenter.queryTags(TestIsNodeTaggedWith1.expressionNode), InstrumentationTestLanguage.EXPRESSION);
    assertTags(instrumenter.queryTags(TestIsNodeTaggedWith1.statementNode), InstrumentationTestLanguage.STATEMENT);
    try {
        instrumenter.queryTags(null);
        Assert.fail();
    } catch (NullPointerException e) {
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) Node(com.oracle.truffle.api.nodes.Node) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Instrumenter(com.oracle.truffle.api.instrumentation.Instrumenter) Test(org.junit.Test)

Aggregations

Instrumenter (com.oracle.truffle.api.instrumentation.Instrumenter)4 ExecutionEventNode (com.oracle.truffle.api.instrumentation.ExecutionEventNode)2 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)2 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)2 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)2 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)2 ExecutableNode (com.oracle.truffle.api.nodes.ExecutableNode)2 Node (com.oracle.truffle.api.nodes.Node)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 Instrument (org.graalvm.polyglot.Instrument)2 Test (org.junit.Test)2 StandardTags (com.oracle.truffle.api.instrumentation.StandardTags)1 Source (org.graalvm.polyglot.Source)1