/** * Handles exceptions from non-language instrumentation code that must not be allowed to alter * guest language execution semantics. Normal response is to log and continue. */ @TruffleBoundary static void exceptionEventForClientInstrument(EventBinding.Source<?> b, String eventName, Throwable t) { assert !b.isLanguageBinding(); if (t instanceof ThreadDeath) { // Terminates guest language execution immediately throw (ThreadDeath) t; } // Exception is a failure in (non-language) instrumentation code; log and continue InstrumentClientInstrumenter instrumenter = (InstrumentClientInstrumenter) b.getInstrumenter(); Class<?> instrumentClass = instrumenter.getInstrumentClass(); String message = String.format("Event %s failed for instrument class %s and listener/factory %s.", // eventName, instrumentClass.getName(), b.getElement()); Exception exception = new Exception(message, t); PrintStream stream = new PrintStream(instrumenter.getEnv().err()); exception.printStackTrace(stream); }
/** * Handles exceptions from non-language instrumentation code that must not be allowed to alter * guest language execution semantics. Normal response is to log and continue. */ @TruffleBoundary static void exceptionEventForClientInstrument(EventBinding.Source<?> b, String eventName, Throwable t) { assert !b.isLanguageBinding(); if (t instanceof ThreadDeath) { // Terminates guest language execution immediately throw (ThreadDeath) t; } final Object currentVm = AccessorInstrumentHandler.engineAccess().getCurrentVM(); if (b.getInstrumenter() instanceof EngineInstrumenter || (currentVm != null && AccessorInstrumentHandler.engineAccess().isInstrumentExceptionsAreThrown(currentVm))) { throw sthrow(RuntimeException.class, t); } // Exception is a failure in (non-language) instrumentation code; log and continue InstrumentClientInstrumenter instrumenter = (InstrumentClientInstrumenter) b.getInstrumenter(); Class<?> instrumentClass = instrumenter.getInstrumentClass(); String message = String.format("Event %s failed for instrument class %s and listener/factory %s.", // eventName, instrumentClass.getName(), b.getElement()); Exception exception = new Exception(message, t); PrintStream stream = new PrintStream(instrumenter.getEnv().err()); exception.printStackTrace(stream); }
<T> EventBinding<T> addExecutionBinding(EventBinding.Source<T> binding) { if (TRACE) { trace("BEGIN: Adding execution binding %s, %s%n", binding.getFilter(), binding.getElement()); } this.executionBindings.add(binding); if (!executedRoots.isEmpty()) { visitRoots(executedRoots, new InsertWrappersWithBindingVisitor(binding)); } if (TRACE) { trace("END: Added execution binding %s, %s%n", binding.getFilter(), binding.getElement()); } return binding; }
ProbeNode.EventChainNode createEventChainCallback(VirtualFrame frame, EventBinding.Source<?> binding, RootNode rootNode, Set<Class<?>> providedTags, Node instrumentedNode, SourceSection instrumentedNodeSourceSection) { ProbeNode.EventChainNode next; Object element = binding.getElement(); if (element instanceof ExecutionEventListener) { next = new EventFilterChainNode(binding, (ExecutionEventListener) element);
private void initializeSlots(VirtualFrame frame) { Lock lock = getLock(); lock.lock(); try { if (this.inputSlots == null) { if (InstrumentationHandler.TRACE) { InstrumentationHandler.trace("SLOTS: Adding %s save slots for binding %s%n", inputCount, getBinding().getElement()); } FrameDescriptor frameDescriptor = frame.getFrameDescriptor(); FrameSlot[] slots = new FrameSlot[inputCount]; for (int i = 0; i < inputCount; i++) { int slotIndex = inputBaseIndex + i; slots[i] = frameDescriptor.findOrAddFrameSlot(new SavedInputValueID(getBinding(), slotIndex)); } this.sourceFrameDescriptor = frameDescriptor; this.inputSlots = slots; } } finally { lock.unlock(); } }
private void initializeSlots(VirtualFrame frame) { Lock lock = getLock(); lock.lock(); try { if (this.inputSlots == null) { if (InstrumentationHandler.TRACE) { InstrumentationHandler.trace("SLOTS: Adding %s save slots for binding %s%n", inputCount, getBinding().getElement()); } FrameDescriptor frameDescriptor = frame.getFrameDescriptor(); FrameSlot[] slots = new FrameSlot[inputCount]; for (int i = 0; i < inputCount; i++) { int slotIndex = inputBaseIndex + i; slots[i] = frameDescriptor.findOrAddFrameSlot(new SavedInputValueID(getBinding(), slotIndex)); } this.sourceFrameDescriptor = frameDescriptor; this.inputSlots = slots; } } finally { lock.unlock(); } }
<T> EventBinding<T> addSourceExecutionBinding(EventBinding.Source<T> binding, boolean notifyLoaded) { if (TRACE) { trace("BEGIN: Adding source execution binding %s, %s%n", binding.getFilter(), binding.getElement()); } this.sourceExecutedBindings.add(binding); this.hasSourceExecutedBindings = true; if (notifyLoaded) { synchronized (sourcesExecuted) { lazyInitializeSourcesExecutedList(); } for (Source source : sourcesExecutedListRef.get()) { notifySourceExecutedBinding(binding, source); } } if (TRACE) { trace("END: Added source execution binding %s, %s%n", binding.getFilter(), binding.getElement()); } return binding; }
<T> EventBinding<T> addSourceBinding(EventBinding.Source<T> binding, boolean notifyLoaded) { if (TRACE) { trace("BEGIN: Adding source binding %s, %s%n", binding.getFilter(), binding.getElement()); } this.sourceBindings.add(binding); this.hasSourceBindings = true; if (notifyLoaded) { synchronized (sources) { lazyInitializeSourcesList(); } for (Source source : sourcesListRef.get()) { notifySourceBindingLoaded(binding, source); } } if (TRACE) { trace("END: Added source binding %s, %s%n", binding.getFilter(), binding.getElement()); } return binding; }
<T> EventBinding<T> addSourceBinding(EventBinding.Source<T> binding, boolean notifyLoaded) { if (TRACE) { trace("BEGIN: Adding source binding %s, %s%n", binding.getFilter(), binding.getElement()); } this.sourceBindings.add(binding); this.hasSourceBindings = true; if (notifyLoaded) { synchronized (sources) { lazyInitializeSourcesList(); } for (Source source : sourcesListRef.get()) { notifySourceBindingLoaded(binding, source); } } if (TRACE) { trace("END: Added source binding %s, %s%n", binding.getFilter(), binding.getElement()); } return binding; }
<T> EventBinding<T> addSourceExecutionBinding(EventBinding.Source<T> binding, boolean notifyLoaded) { if (TRACE) { trace("BEGIN: Adding source execution binding %s, %s%n", binding.getFilter(), binding.getElement()); } this.sourceExecutedBindings.add(binding); this.hasSourceExecutedBindings = true; if (notifyLoaded) { synchronized (sourcesExecuted) { lazyInitializeSourcesExecutedList(); } for (Source source : sourcesExecutedListRef.get()) { notifySourceExecutedBinding(binding, source); } } if (TRACE) { trace("END: Added source execution binding %s, %s%n", binding.getFilter(), binding.getElement()); } return binding; }
static void notifySourceSectionLoaded(EventBinding.Source<?> binding, Node node, SourceSection section) { if (section == null) { // Do not report null source sections to keep compatibility with the past behavior. return; } LoadSourceSectionListener listener = (LoadSourceSectionListener) binding.getElement(); try { listener.onLoad(new LoadSourceSectionEvent(section, node)); } catch (Throwable t) { if (binding.isLanguageBinding()) { throw t; } else { ProbeNode.exceptionEventForClientInstrument(binding, "onLoad", t); } } }
static void notifySourceSectionLoaded(EventBinding.Source<?> binding, Node node, SourceSection section) { if (section == null) { // Do not report null source sections to keep compatibility with the past behavior. return; } LoadSourceSectionListener listener = (LoadSourceSectionListener) binding.getElement(); try { listener.onLoad(new LoadSourceSectionEvent(section, node)); } catch (Throwable t) { if (binding.isLanguageBinding()) { throw t; } else { ProbeNode.exceptionEventForClientInstrument(binding, "onLoad", t); } } }
<T> EventBinding<T> addSourceSectionBinding(EventBinding.Source<T> binding, boolean notifyLoaded) { if (TRACE) { trace("BEGIN: Adding binding %s, %s%n", binding.getFilter(), binding.getElement()); } this.sourceSectionBindings.add(binding); if (notifyLoaded) { if (!loadedRoots.isEmpty()) { visitRoots(loadedRoots, new NotifyLoadedWithBindingVisitor(binding)); } } if (TRACE) { trace("END: Added binding %s, %s%n", binding.getFilter(), binding.getElement()); } return binding; }
<T> EventBinding<T> addSourceSectionBinding(EventBinding.Source<T> binding, boolean notifyLoaded) { if (TRACE) { trace("BEGIN: Adding binding %s, %s%n", binding.getFilter(), binding.getElement()); } this.sourceSectionBindings.add(binding); if (notifyLoaded) { if (!loadedRoots.isEmpty()) { visitRoots(loadedRoots, new NotifyLoadedWithBindingVisitor(binding)); } } if (TRACE) { trace("END: Added binding %s, %s%n", binding.getFilter(), binding.getElement()); } return binding; }
private void visitLoadedSourceSections(EventBinding.Source<?> binding) { if (TRACE) { trace("BEGIN: Visiting loaded source sections %s, %s%n", binding.getFilter(), binding.getElement()); } if (!loadedRoots.isEmpty()) { visitRoots(loadedRoots, new NotifyLoadedWithBindingVisitor(binding)); } if (TRACE) { trace("END: Visited loaded source sections %s, %s%n", binding.getFilter(), binding.getElement()); } }
private static void notifySourceBindingLoaded(EventBinding.Source<?> binding, Source source) { if (!binding.isDisposed() && binding.isInstrumentedSource(source)) { try { ((LoadSourceListener) binding.getElement()).onLoad(new LoadSourceEvent(source)); } catch (Throwable t) { if (binding.isLanguageBinding()) { throw t; } else { ProbeNode.exceptionEventForClientInstrument(binding, "onLoad", t); } } } }
private static void notifySourceExecutedBinding(EventBinding.Source<?> binding, Source source) { if (!binding.isDisposed() && binding.isInstrumentedSource(source)) { try { ((ExecuteSourceListener) binding.getElement()).onExecute(new ExecuteSourceEvent(source)); } catch (Throwable t) { if (binding.isLanguageBinding()) { throw t; } else { ProbeNode.exceptionEventForClientInstrument(binding, "onExecute", t); } } } }
private static void notifySourceExecutedBinding(EventBinding.Source<?> binding, Source source) { if (!binding.isDisposed() && binding.isInstrumentedSource(source)) { try { ((ExecuteSourceListener) binding.getElement()).onExecute(new ExecuteSourceEvent(source)); } catch (Throwable t) { if (binding.isLanguageBinding()) { throw t; } else { ProbeNode.exceptionEventForClientInstrument(binding, "onExecute", t); } } } }
<T> EventBinding<T> addExecutionBinding(EventBinding.Source<T> binding) { if (TRACE) { trace("BEGIN: Adding execution binding %s, %s%n", binding.getFilter(), binding.getElement()); } this.executionBindings.add(binding); if (!executedRoots.isEmpty()) { visitRoots(executedRoots, new InsertWrappersWithBindingVisitor(binding)); } if (TRACE) { trace("END: Added execution binding %s, %s%n", binding.getFilter(), binding.getElement()); } return binding; }
private static void notifySourceBindingLoaded(EventBinding.Source<?> binding, Source source) { if (!binding.isDisposed() && binding.isInstrumentedSource(source)) { try { ((LoadSourceListener) binding.getElement()).onLoad(new LoadSourceEvent(source)); } catch (Throwable t) { if (binding.isLanguageBinding()) { throw t; } else { ProbeNode.exceptionEventForClientInstrument(binding, "onLoad", t); } } } }