Search in sources :

Example 6 with EventContext

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

the class DebuggerExampleTest method testStepOver.

@Test
@SuppressWarnings("hiding")
public void testStepOver() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "DEFINE(foo,STATEMENT),", // 3
    "DEFINE(bar", // 4
    ",STATEMENT", // 5
    ",STATEMENT(CALL(foo))", // 6
    ",STATEMENT),", /**/
    "STATEMENT(CALL(bar)))");
    // 7
    final AtomicBoolean allStepped = new AtomicBoolean();
    debugger.installBreakpoint(4, new Callback() {

        public void halted(DebuggerController debugger, EventContext haltedAt) {
            assertLineAt(haltedAt, 4);
            debugger.stepOver(new Callback() {

                public void halted(DebuggerController debugger, EventContext haltedAt) {
                    assertLineAt(haltedAt, 5);
                    debugger.stepOver(new Callback() {

                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                            assertLineAt(haltedAt, 6);
                            allStepped.set(true);
                            debugger.stepOver(new Callback() {

                                public void halted(DebuggerController debugger, EventContext haltedAt) {
                                    throw new AssertionError();
                                }
                            });
                        }
                    });
                }
            });
        }
    });
    run(source);
    Assert.assertTrue(allStepped.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 7 with EventContext

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

the class SLInstrumentTest method testLexicalScopes.

@Test
public void testLexicalScopes() throws Exception {
    String code = "function test(n) {\n" + // 2
    "  a = 1;\n" + "  if (a > 0) {\n" + "    b = 10;\n" + // 5
    "    println(b);\n" + "  }\n" + "  if (a == 1) {\n" + "    b = 20;\n" + "    a = 0;\n" + // 10
    "    c = 1;\n" + "    if (b > 0) {\n" + "      a = 4;\n" + "      b = 5;\n" + "      c = 6;\n" + // 15
    "      d = 7;\n" + "      println(d);\n" + "    }\n" + "  }\n" + "  println(b);\n" + // 20
    "  println(a);\n" + "}\n" + "function main() {\n" + "  test(\"n_n\");\n" + "}";
    Source source = Source.newBuilder("sl", code, "testing").build();
    List<Throwable> throwables;
    try (Engine engine = Engine.newBuilder().out(new java.io.OutputStream() {

        // null output stream
        @Override
        public void write(int b) throws IOException {
        }
    }).build()) {
        Instrument envInstr = engine.getInstruments().get("testEnvironmentHandlerInstrument");
        TruffleInstrument.Env env = envInstr.lookup(Environment.class).env;
        throwables = new ArrayList<>();
        env.getInstrumenter().attachExecutionEventListener(SourceSectionFilter.newBuilder().lineIn(1, source.getLineCount()).build(), new ExecutionEventListener() {

            @Override
            public void onEnter(EventContext context, VirtualFrame frame) {
                Node node = context.getInstrumentedNode();
                Iterable<Scope> lexicalScopes = env.findLocalScopes(node, null);
                Iterable<Scope> dynamicScopes = env.findLocalScopes(node, frame);
                try {
                    verifyLexicalScopes(lexicalScopes, dynamicScopes, context.getInstrumentedSourceSection().getStartLine(), frame.materialize());
                } catch (ThreadDeath t) {
                    throw t;
                } catch (Throwable t) {
                    CompilerDirectives.transferToInterpreter();
                    PrintStream lsErr = System.err;
                    lsErr.println("Line = " + context.getInstrumentedSourceSection().getStartLine());
                    lsErr.println("Node = " + node + ", class = " + node.getClass().getName());
                    t.printStackTrace(lsErr);
                    throwables.add(t);
                }
            }

            @Override
            public void onReturnValue(EventContext context, VirtualFrame frame, Object result) {
            }

            @Override
            public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) {
            }
        });
        Context.newBuilder().engine(engine).build().eval(source);
    }
    assertTrue(throwables.toString(), throwables.isEmpty());
}
Also used : TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RootNode(com.oracle.truffle.api.nodes.RootNode) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) Node(com.oracle.truffle.api.nodes.Node) Source(org.graalvm.polyglot.Source) ExecutionEventListener(com.oracle.truffle.api.instrumentation.ExecutionEventListener) EventContext(com.oracle.truffle.api.instrumentation.EventContext) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Example 8 with EventContext

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

the class Profiler method reset.

// Reconfigure what's being collected; does not affect collected data
private void reset() {
    if (binding != null) {
        binding.dispose();
        binding = null;
    }
    if (isCollecting) {
        final Builder filterBuilder = SourceSectionFilter.newBuilder();
        if (mimeTypes != null) {
            filterBuilder.mimeTypeIs(mimeTypes);
        }
        final SourceSectionFilter filter = filterBuilder.tagIs(StandardTags.RootTag.class).sourceIs(notInternal).build();
        binding = instrumenter.attachExecutionEventFactory(filter, new ExecutionEventNodeFactory() {

            public ExecutionEventNode create(EventContext context) {
                return createCountingNode(context);
            }
        });
    }
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) ExecutionEventNodeFactory(com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory) Builder(com.oracle.truffle.api.instrumentation.SourceSectionFilter.Builder) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags)

Example 9 with EventContext

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

the class InstrumentationEventTest method setUp.

@Before
public final void setUp() {
    this.context = Context.create();
    this.instrument = context.getEngine().getInstruments().get(InputFilterTestInstrument.ID).lookup(InputFilterTestInstrument.class);
    this.instrumenter = instrument.environment.getInstrumenter();
    this.events = new ArrayList<>();
    this.factory = new ExecutionEventNodeFactory() {

        public ExecutionEventNode create(EventContext c) {
            return new ExecutionEventNode() {

                {
                    for (int i = 0; i < getInputCount(); i++) {
                        Assert.assertNotNull(getInputContext(i));
                    }
                }

                @Override
                protected void onInputValue(VirtualFrame frame, EventContext inputContext, int inputIndex, Object inputValue) {
                    saveInputValue(frame, inputIndex, inputValue);
                    assertTrue(inputIndex < getInputCount());
                    assertSame(inputContext, getInputContext(inputIndex));
                    events.add(new Event(EventKind.INPUT_VALUE, c, frame, null, null, inputIndex, inputValue, createInputContexts()));
                }

                @Override
                public void onEnter(VirtualFrame frame) {
                    events.add(new Event(EventKind.ENTER, c, frame, null, null, -1, null, createInputContexts()));
                }

                @Override
                protected void onReturnValue(VirtualFrame frame, Object result) {
                    events.add(new Event(EventKind.RETURN_VALUE, c, frame, getSavedInputValues(frame), result, -1, null, createInputContexts()));
                }

                private EventContext[] createInputContexts() {
                    EventContext[] inputContexts = new EventContext[getInputCount()];
                    for (int i = 0; i < getInputCount(); i++) {
                        Assert.assertNotNull(getInputContext(i));
                        inputContexts[i] = getInputContext(i);
                    }
                    return inputContexts;
                }
            };
        }
    };
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) ExecutionEventNodeFactory(com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode) Before(org.junit.Before)

Example 10 with EventContext

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

the class InstrumentationMultiThreadingTest method createDummyBindings.

private static EventBinding<?>[] createDummyBindings(Instrumenter instrumenter) {
    EventBinding<?>[] bindings = new EventBinding<?>[5];
    int bi = 0;
    ExecutionEventListener dummyListener = new ExecutionEventListener() {

        public void onReturnValue(EventContext context, VirtualFrame frame, Object result) {
        }

        public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) {
        }

        public void onEnter(EventContext context, VirtualFrame frame) {
        }
    };
    bindings[bi++] = instrumenter.attachExecutionEventListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build(), dummyListener);
    bindings[bi++] = instrumenter.attachExecutionEventListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(), dummyListener);
    bindings[bi++] = instrumenter.attachLoadSourceListener(SourceFilter.ANY, new LoadSourceListener() {

        public void onLoad(LoadSourceEvent event) {
        }
    }, true);
    bindings[bi++] = instrumenter.attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build(), new LoadSourceSectionListener() {

        public void onLoad(LoadSourceSectionEvent event) {
        }
    }, true);
    bindings[bi++] = instrumenter.attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(), new LoadSourceSectionListener() {

        public void onLoad(LoadSourceSectionEvent event) {
        }
    }, true);
    return bindings;
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) EventBinding(com.oracle.truffle.api.instrumentation.EventBinding) LoadSourceEvent(com.oracle.truffle.api.instrumentation.LoadSourceEvent) LoadSourceSectionEvent(com.oracle.truffle.api.instrumentation.LoadSourceSectionEvent) LoadSourceListener(com.oracle.truffle.api.instrumentation.LoadSourceListener) LoadSourceSectionListener(com.oracle.truffle.api.instrumentation.LoadSourceSectionListener) ExecutionEventListener(com.oracle.truffle.api.instrumentation.ExecutionEventListener)

Aggregations

EventContext (com.oracle.truffle.api.instrumentation.EventContext)13 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)5 Test (org.junit.Test)5 ExecutionEventListener (com.oracle.truffle.api.instrumentation.ExecutionEventListener)4 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)4 Callback (com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Source (org.graalvm.polyglot.Source)4 ExecutionEventNodeFactory (com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory)3 Node (com.oracle.truffle.api.nodes.Node)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 ExecutionEventNode (com.oracle.truffle.api.instrumentation.ExecutionEventNode)2 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)2 LoadSourceSectionEvent (com.oracle.truffle.api.instrumentation.LoadSourceSectionEvent)2 LoadSourceSectionListener (com.oracle.truffle.api.instrumentation.LoadSourceSectionListener)2 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)2 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 EventBinding (com.oracle.truffle.api.instrumentation.EventBinding)1 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)1