private synchronized void enableCancel() { if (cancellationBinding == null) { cancellationBinding = instrumenter.attachExecutionEventListener(SourceSectionFilter.ANY, new ExecutionEventListener() { public void onReturnValue(EventContext context, VirtualFrame frame, Object result) { cancelExecution(context); } public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) { cancelExecution(context); } public void onEnter(EventContext context, VirtualFrame frame) { cancelExecution(context); } @TruffleBoundary private void cancelExecution(EventContext eventContext) { PolyglotContextImpl context = PolyglotContextImpl.requireContext(); if (context.cancelling) { throw new CancelExecution(eventContext); } } }); } cancellationUsers++; }
/** * @since 0.12 * @deprecated in 0.32 use * {@link #attachExecutionEventFactory(SourceSectionFilter, ExecutionEventNodeFactory)} * instead (rename only) */ @Deprecated public final <T extends ExecutionEventListener> EventBinding<T> attachListener(SourceSectionFilter eventFilter, T listener) { return attachExecutionEventListener(eventFilter, null, listener); }
/** * @since 0.12 * @deprecated in 0.32 use * {@link #attachExecutionEventFactory(SourceSectionFilter, ExecutionEventNodeFactory)} * instead (rename only) */ @Deprecated public final <T extends ExecutionEventListener> EventBinding<T> attachListener(SourceSectionFilter eventFilter, T listener) { return attachExecutionEventListener(eventFilter, null, listener); }
/** * Starts execution event notification for a given {@link SourceSectionFilter event filter} and * {@link ExecutionEventListener listener}. The execution events are delivered to the * {@link ExecutionEventListener}. * <p> * Returns a {@link EventBinding binding} which allows to dispose the attached execution event * binding. Disposing the binding removes all probes and wrappers from the AST that were created * for this instrument. The removal of probes and wrappers is performed lazily on the next * execution of the AST. * <p> * By default no * {@link ExecutionEventNode#onInputValue(com.oracle.truffle.api.frame.VirtualFrame, EventContext, int, Object) * input value events} are delivered to the listener. To deliver inputs events use * {@link #attachExecutionEventListener(SourceSectionFilter, SourceSectionFilter, ExecutionEventListener)} * instead. * * @param eventFilter filters the events that are reported to the given * {@link ExecutionEventListener listener} * @param listener that listens to execution events. * @see ExecutionEventListener * @since 0.33 */ public final <T extends ExecutionEventListener> EventBinding<T> attachExecutionEventListener(SourceSectionFilter eventFilter, T listener) { return attachExecutionEventListener(eventFilter, null, listener); }
private synchronized void enableCancel() { if (cancellationBinding == null) { cancellationBinding = instrumenter.attachExecutionEventListener(SourceSectionFilter.ANY, new ExecutionEventListener() { public void onReturnValue(EventContext context, VirtualFrame frame, Object result) { cancelExecution(context); } public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) { cancelExecution(context); } public void onEnter(EventContext context, VirtualFrame frame) { cancelExecution(context); } @TruffleBoundary private void cancelExecution(EventContext eventContext) { PolyglotContextImpl context = PolyglotContextImpl.requireContext(); if (context.cancelling) { throw new CancelExecution(eventContext); } } }); } cancellationUsers++; }
/** * Starts execution event notification for a given {@link SourceSectionFilter event filter} and * {@link ExecutionEventListener listener}. The execution events are delivered to the * {@link ExecutionEventListener}. * <p> * Returns a {@link EventBinding binding} which allows to dispose the attached execution event * binding. Disposing the binding removes all probes and wrappers from the AST that were created * for this instrument. The removal of probes and wrappers is performed lazily on the next * execution of the AST. * <p> * By default no * {@link ExecutionEventNode#onInputValue(com.oracle.truffle.api.frame.VirtualFrame, EventContext, int, Object) * input value events} are delivered to the listener. To deliver inputs events use * {@link #attachExecutionEventListener(SourceSectionFilter, SourceSectionFilter, ExecutionEventListener)} * instead. * * @param eventFilter filters the events that are reported to the given * {@link ExecutionEventListener listener} * @param listener that listens to execution events. * @see ExecutionEventListener * @since 0.33 */ public final <T extends ExecutionEventListener> EventBinding<T> attachExecutionEventListener(SourceSectionFilter eventFilter, T listener) { return attachExecutionEventListener(eventFilter, null, listener); }