EventBinding<?> install(Instrumenter instrumenter, SourceSectionFilter filter, boolean compiledOnly) { return instrumenter.attachExecutionEventFactory(filter, new ExecutionEventNodeFactory() { public ExecutionEventNode create(EventContext context) { Node instrumentedNode = context.getInstrumentedNode(); if (instrumentedNode.getSourceSection() == null) { logger.warning("Instrumented node " + instrumentedNode + " has null SourceSection."); return null; } return new StackPushPopNode(ShadowStack.this, instrumenter, context, compiledOnly); } }); }
synchronized void setContextsListener(DebugContextsListener listener, boolean includeExistingContexts) { if (contextsBinding != null) { contextsBinding.dispose(); } contextsListener = listener; if (listener != null) { contextsBinding = lifecycleInstrumenter.attachContextsListener(this, includeExistingContexts); } else { contextsBinding = null; if (threadsBinding == null) { contextMap.clear(); } } }
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++; }
SourceFilter filter = locationKey.createSourceFilter(); final boolean[] sourceResolved = new boolean[]{false}; sourceBinding = debugger.getInstrumenter().attachExecuteSourceListener(filter, new ExecuteSourceListener() { @Override public void onExecute(ExecuteSourceEvent event) { breakpointBinding = debugger.getInstrumenter().attachExecutionEventFactory(locationFilter, new BreakpointNodeFactory());
synchronized void setThreadsListener(DebugThreadsListener listener, boolean includeExistingThreads) { if (threadsBinding != null) { threadsBinding.dispose(); } this.threadsListener = listener; if (listener != null) { threadsBinding = lifecycleInstrumenter.attachThreadsListener(this, includeExistingThreads); } else { threadsBinding = null; if (contextsBinding == null) { contextMap.clear(); } } }
if (sourceBinding == null && (filter = locationKey.createSourceFilter()) != null) { final boolean[] sourceResolved = new boolean[]{false}; sourceBinding = debugger.getInstrumenter().attachExecuteSourceListener(filter, new ExecuteSourceListener() { @Override public void onExecute(ExecuteSourceEvent event) {
this.activeBinding = env.getInstrumenter().attachAllocationListener(AllocationEventFilter.ANY, new Listener());
/** * Returns a list of all loaded sources. The sources are returned in the order as they have been * loaded by the languages. * * @return an unmodifiable list of sources * @since 0.17 * @deprecated not very flexible, polls all sources without any notification about changes. */ @Deprecated public List<Source> getLoadedSources() { final List<Source> sources = new ArrayList<>(); EventBinding<?> binding = env.getInstrumenter().attachLoadSourceListener(SourceFilter.ANY, new LoadSourceListener() { public void onLoad(LoadSourceEvent event) { sources.add(event.getSource()); } }, true); binding.dispose(); return Collections.unmodifiableList(sources); }
synchronized void setThreadsListener(DebugThreadsListener listener, boolean includeExistingThreads) { if (threadsBinding != null) { threadsBinding.dispose(); } this.threadsListener = listener; if (listener != null) { threadsBinding = lifecycleInstrumenter.attachThreadsListener(this, includeExistingThreads); } else { threadsBinding = null; if (contextsBinding == null) { contextMap.clear(); } } }
void resetTracer() { assert Thread.holdsLock(this); if (activeBinding != null) { activeBinding.dispose(); activeBinding = null; } if (!collecting || closed) { return; } SourceSectionFilter f = this.filter; if (f == null) { f = DEFAULT_FILTER; } this.shadowStack = new ShadowStack(stackLimit, f, env.getInstrumenter(), TruffleLogger.getLogger(CPUTracerInstrument.ID)); this.stacksBinding = this.shadowStack.install(env.getInstrumenter(), f, false); this.activeBinding = env.getInstrumenter().attachAllocationListener(AllocationEventFilter.ANY, new Listener()); }
/** * Starts execution event notification for a given {@link SourceSectionFilter event filter} and * {@link ExecutionEventNodeFactory factory}. Events are delivered to the * {@link ExecutionEventNode} instances created by the factory. * <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 created execution event nodes. To deliver inputs * events use * {@link #attachExecutionEventFactory(SourceSectionFilter, SourceSectionFilter, ExecutionEventNodeFactory)} * instead. * * @param eventFilter filters the events that are reported to the {@link ExecutionEventNode * execution event nodes} created by the factory. * @param factory the factory that creates {@link ExecutionEventNode execution event nodes}. * @see ExecutionEventNodeFactory * @see #attachExecutionEventFactory(SourceSectionFilter, SourceSectionFilter, * ExecutionEventNodeFactory) * @since 0.33 */ public final <T extends ExecutionEventNodeFactory> EventBinding<T> attachExecutionEventFactory(SourceSectionFilter eventFilter, T factory) { return attachExecutionEventFactory(eventFilter, null, factory); }
synchronized void setContextsListener(DebugContextsListener listener, boolean includeExistingContexts) { if (contextsBinding != null) { contextsBinding.dispose(); } contextsListener = listener; if (listener != null) { contextsBinding = lifecycleInstrumenter.attachContextsListener(this, includeExistingContexts); } else { contextsBinding = null; if (threadsBinding == null) { contextMap.clear(); } } }
/** * @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 ExecutionEventNodeFactory> EventBinding<T> attachFactory(SourceSectionFilter eventFilter, T factory) { return attachExecutionEventFactory(eventFilter, null, factory); }
private HeapMonitor(TruffleInstrument.Env env) { this.env = env; env.getInstrumenter().attachContextsListener(new ContextsListener() { @Override public void onContextCreated(TruffleContext context) { } @Override public void onLanguageContextCreated(TruffleContext context, LanguageInfo language) { } @Override public void onLanguageContextInitialized(TruffleContext context, LanguageInfo language) { initializedLanguages.put(language, language); } @Override public void onLanguageContextFinalized(TruffleContext context, LanguageInfo language) { initializedLanguages.remove(language); } @Override public void onLanguageContextDisposed(TruffleContext context, LanguageInfo language) { } @Override public void onContextClosed(TruffleContext context) { } }, true); }
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 ExecutionEventNodeFactory> EventBinding<T> attachFactory(SourceSectionFilter eventFilter, T factory) { return attachExecutionEventFactory(eventFilter, null, factory); }
CPUSampler(Env env) { this.env = env; env.getInstrumenter().attachContextsListener(new ContextsListener() { @Override public void onContextCreated(TruffleContext context) { } @Override public void onLanguageContextCreated(TruffleContext context, LanguageInfo language) { } @Override public void onLanguageContextInitialized(TruffleContext context, LanguageInfo language) { if (!language.isInternal()) { nonInternalLanguageContextInitialized = true; } } @Override public void onLanguageContextFinalized(TruffleContext context, LanguageInfo language) { } @Override public void onLanguageContextDisposed(TruffleContext context, LanguageInfo language) { } @Override public void onContextClosed(TruffleContext context) { } }, true); }
/** * 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); }
/** * Starts execution event notification for a given {@link SourceSectionFilter event filter} and * {@link ExecutionEventNodeFactory factory}. Events are delivered to the * {@link ExecutionEventNode} instances created by the factory. * <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 created execution event nodes. To deliver inputs * events use * {@link #attachExecutionEventFactory(SourceSectionFilter, SourceSectionFilter, ExecutionEventNodeFactory)} * instead. * * @param eventFilter filters the events that are reported to the {@link ExecutionEventNode * execution event nodes} created by the factory. * @param factory the factory that creates {@link ExecutionEventNode execution event nodes}. * @see ExecutionEventNodeFactory * @see #attachExecutionEventFactory(SourceSectionFilter, SourceSectionFilter, * ExecutionEventNodeFactory) * @since 0.33 */ public final <T extends ExecutionEventNodeFactory> EventBinding<T> attachExecutionEventFactory(SourceSectionFilter eventFilter, T factory) { return attachExecutionEventFactory(eventFilter, null, factory); }