@SuppressWarnings("deprecation") private EventChainNode findParentChain(VirtualFrame frame, EventBinding<?> binding) { Node node = getParent().getParent(); while (node != null) { // TODO we should avoid materializing the source section here if (node instanceof com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode) { ProbeNode probe = ((com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode) node).getProbeNode(); EventChainNode c = probe.lazyUpdate(frame); if (c != null) { c = c.find(binding); } if (c != null) { return c; } } else if (node instanceof RootNode) { break; } node = node.getParent(); } if (node == null) { throw new IllegalStateException("The AST node is not yet adopted. "); } return null; }
final void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) { UnwindException unwind = null; if (exception instanceof UnwindException) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); next.onReturnExceptional(context, frame, exception); } catch (UnwindException ex) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); innerOnReturnExceptional(context, frame, exception); } catch (UnwindException ex) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException();
final void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) { UnwindException unwind = null; if (exception instanceof UnwindException) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); next.onReturnExceptional(context, frame, exception); } catch (UnwindException ex) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); unwind = mergeUnwind(unwind, ex); innerOnReturnExceptional(context, frame, exception); } catch (UnwindException ex) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); unwind = mergeUnwind(unwind, ex); } catch (Throwable t) { if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException();
final void onEnter(EventContext context, VirtualFrame frame) { UnwindException unwind = null; try { innerOnEnter(context, frame); } catch (UnwindException ex) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException(); next.onEnter(context, frame); } catch (UnwindException ex) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind();
final void onEnter(EventContext context, VirtualFrame frame) { UnwindException unwind = null; try { innerOnEnter(context, frame); } catch (UnwindException ex) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException(); next.onEnter(context, frame); } catch (UnwindException ex) { if (!isSeenUnwind()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwind(); if (!isSeenHasNext()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenHasNext();
if (next != null) { try { next.onInputValue(context, frame, inputBinding, inputContext, inputIndex, inputValue); } catch (UnwindException ex) { if (!isSeenUnwindOnInputValue()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwindOnInputValue(); innerOnInputValue(context, frame, binding, inputContext, inputIndex, inputValue); if (!isSeenUnwindOnInputValue()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenUnwindOnInputValue(); unwind = mergeUnwind(unwind, ex); } catch (Throwable t) { if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException();
final Object onUnwind(EventContext context, VirtualFrame frame, UnwindException unwind) { Object ret = null; if (containsBinding(unwind)) { try { ret = innerOnUnwind(context, frame, getInfo(unwind)); } catch (Throwable t) { if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException(); } if (binding.isLanguageBinding()) { throw t; } else { CompilerDirectives.transferToInterpreter(); exceptionEventForClientInstrument(binding, "onUnwind", t); } } if (ret != null) { assert checkInteropType(ret, binding); reset(unwind); } } else { ret = UNWIND_ACTION_IGNORED; } if (next != null) { Object nextRet = next.onUnwind(context, frame, unwind); ret = mergePostUnwindReturns(ret, nextRet); } return ret; }
final Object onUnwind(EventContext context, VirtualFrame frame, UnwindException unwind) { Object ret = null; if (containsBinding(unwind)) { try { ret = innerOnUnwind(context, frame, getInfo(unwind)); } catch (Throwable t) { if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException(); } if (binding.isLanguageBinding()) { throw t; } else { CompilerDirectives.transferToInterpreter(); exceptionEventForClientInstrument(binding, "onUnwind", t); } } if (ret != null) { assert checkInteropType(ret, binding); reset(unwind); } } else { ret = UNWIND_ACTION_IGNORED; } if (next != null) { Object nextRet = next.onUnwind(context, frame, unwind); ret = mergePostUnwindReturns(ret, nextRet); } return ret; }
final void onInputValue(EventContext context, VirtualFrame frame, EventBinding<?> inputBinding, EventContext inputContext, int inputIndex, Object inputValue) { if (next != null) { next.onInputValue(context, frame, inputBinding, inputContext, inputIndex, inputValue); } try { if (binding == inputBinding) { innerOnInputValue(context, frame, binding, inputContext, inputIndex, inputValue); } } catch (Throwable t) { if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException(); } if (binding.isLanguageBinding()) { throw t; } else { CompilerDirectives.transferToInterpreter(); exceptionEventForClientInstrument(binding, "onInputValue", t); } } }
@SuppressWarnings("deprecation") private EventChainNode findParentChain(VirtualFrame frame, EventBinding<?> binding) { Node node = getParent().getParent(); while (node != null) { // TODO we should avoid materializing the source section here if (node instanceof com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode) { ProbeNode probe = ((com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode) node).getProbeNode(); EventChainNode c = probe.lazyUpdate(frame); if (c != null) { c = c.find(binding); } if (c != null) { return c; } } else if (node instanceof RootNode) { break; } node = node.getParent(); } if (node == null) { throw new IllegalStateException("The AST node is not yet adopted. "); } return null; }
final void onDispose(EventContext context, VirtualFrame frame) { try { innerOnDispose(context, frame); } catch (Throwable t) { if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException(); } if (binding.isLanguageBinding()) { throw t; } else { exceptionEventForClientInstrument(binding, "onEnter", t); } } if (next != null) { next.onDispose(context, frame); } }
EventChainNode createParentEventChainCallback(VirtualFrame frame, EventBinding.Source<?> binding, RootNode rootNode, Set<Class<?>> providedTags) { EventChainNode parent = findParentChain(frame, binding); if (!(parent instanceof EventProviderWithInputChainNode)) { // this event is unreachable because nobody is listening to it. return null; } EventContext parentContext = parent.findProbe().getContext(); EventProviderWithInputChainNode parentChain = (EventProviderWithInputChainNode) parent; int index = indexOfChild(binding, rootNode, providedTags, parentContext.getInstrumentedNode(), parentContext.getInstrumentedSourceSection(), context.getInstrumentedNode()); if (index < 0 || index >= parentChain.inputCount) { // not found. a child got replaced? // TODO what to do if child was not found? // we should not continue with an out of bounds child index. assert false; return null; } ProbeNode probe = parent.findProbe(); return new InputValueChainNode(binding, probe, context, index); }
EventChainNode createParentEventChainCallback(VirtualFrame frame, EventBinding.Source<?> binding, RootNode rootNode, Set<Class<?>> providedTags) { EventChainNode parent = findParentChain(frame, binding); if (!(parent instanceof EventProviderWithInputChainNode)) { // this event is unreachable because nobody is listening to it. return null; } EventContext parentContext = parent.findProbe().getContext(); EventProviderWithInputChainNode parentChain = (EventProviderWithInputChainNode) parent; int index = indexOfChild(binding, rootNode, providedTags, parentContext.getInstrumentedNode(), parentContext.getInstrumentedSourceSection(), context.getInstrumentedNode()); if (index < 0 || index >= parentChain.inputCount) { // not found. a child got replaced? // probe should have been notified about this with notifyInserted assert throwIllegalASTAssertion(parentChain, parentContext, binding, rootNode, providedTags, index); return null; } ProbeNode probe = parent.findProbe(); return new InputValueChainNode(binding, probe, context, index); }
private boolean containsBinding(UnwindException unwind) { if (unwind.getBinding() == binding) { return true; } else { UnwindException nextUnwind = unwind.getNext(); if (nextUnwind != null) { if (!isSeenHasNext()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenHasNext(); } return containsBindingBoundary(nextUnwind); } else { return false; } } }
private Object getInfo(UnwindException unwind) { if (unwind.getBinding() == binding) { return unwind.getInfo(); } else { UnwindException nextUnwind = unwind.getNext(); if (nextUnwind != null) { if (!isSeenHasNext()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenHasNext(); } return getInfoBoundary(nextUnwind); } else { return false; } } }
final void onDispose(EventContext context, VirtualFrame frame) { try { innerOnDispose(context, frame); } catch (Throwable t) { if (!isSeenException()) { CompilerDirectives.transferToInterpreterAndInvalidate(); setSeenException(); } if (binding.isLanguageBinding()) { throw t; } else { exceptionEventForClientInstrument(binding, "onEnter", t); } } if (next != null) { next.onDispose(context, frame); } }
@TruffleBoundary private boolean containsBindingBoundary(UnwindException unwind) { return containsBinding(unwind); }
@TruffleBoundary private boolean containsBindingBoundary(UnwindException unwind) { return containsBinding(unwind); }
@TruffleBoundary private Object getInfoBoundary(UnwindException unwind) { return getInfo(unwind); }
@TruffleBoundary private Object getInfoBoundary(UnwindException unwind) { return getInfo(unwind); }