Search in sources :

Example 1 with ExecutionEventNode

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

the class DebuggerSessionSnippets method collectDebuggerNodes.

private List<DebuggerNode> collectDebuggerNodes(DebuggerNode source, SuspendAnchor suspendAnchor) {
    EventContext context = source.getContext();
    List<DebuggerNode> nodes = new ArrayList<>();
    nodes.add(source);
    Iterator<ExecutionEventNode> nodesIterator = context.lookupExecutionEventNodes(allBindings);
    if (SuspendAnchor.BEFORE.equals(suspendAnchor)) {
        // We collect nodes following the source (these nodes remain to be executed)
        boolean after = false;
        while (nodesIterator.hasNext()) {
            DebuggerNode node = (DebuggerNode) nodesIterator.next();
            if (after) {
                if (node.isActiveAt(suspendAnchor)) {
                    nodes.add(node);
                }
            } else {
                after = node == source;
            }
        }
    } else {
        // We collect nodes preceding the source (these nodes remain to be executed)
        while (nodesIterator.hasNext()) {
            DebuggerNode node = (DebuggerNode) nodesIterator.next();
            if (node == source) {
                break;
            }
            if (node.isActiveAt(suspendAnchor)) {
                nodes.add(node);
            }
        }
    }
    return nodes;
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) ArrayList(java.util.ArrayList) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode)

Example 2 with ExecutionEventNode

use of com.oracle.truffle.api.instrumentation.ExecutionEventNode 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)

Aggregations

EventContext (com.oracle.truffle.api.instrumentation.EventContext)2 ExecutionEventNode (com.oracle.truffle.api.instrumentation.ExecutionEventNode)2 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 ExecutionEventNodeFactory (com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1