com.oracle.truffle.api.instrumentation.EventBinding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truffle-api Show documentation
Show all versions of truffle-api Show documentation
Truffle is a multi-language framework for executing dynamic languages
that achieves high performance when combined with Graal.
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.api.instrumentation;
import java.util.Set;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.instrumentation.InstrumentationHandler.AbstractInstrumenter;
import com.oracle.truffle.api.instrumentation.InstrumentationHandler.LanguageClientInstrumenter;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.SourceSection;
/**
* Represents a binding from a {@link SourceSectionFilter} instance for a particular
* {@link ExecutionEventListener} or {@link ExecutionEventNodeFactory}.
*
* A binding is active until disposed, either:
*
* - by a call to dispose();
* - the instrumenter that created the binding is {@link EventBinding#dispose() disposed}; or
* - the engine running the language is disposed.
*
* If all bindings of a listener or factory are disposed then their methods are not invoked again by
* the instrumentation framework.
*
* @param represents the concrete type of the element bound. Either an implementation of
* {@link ExecutionEventListener} or {@link ExecutionEventNodeFactory}.
* @since 0.12
*/
public final class EventBinding {
private final AbstractInstrumenter instrumenter;
private final SourceSectionFilter filter;
private final T element;
/* language bindings needs special treatment. */
private boolean disposed;
EventBinding(AbstractInstrumenter instrumenter, SourceSectionFilter query, T element) {
this.instrumenter = instrumenter;
this.filter = query;
this.element = element;
}
boolean isLanguageBinding() {
return instrumenter instanceof LanguageClientInstrumenter;
}
AbstractInstrumenter getInstrumenter() {
return instrumenter;
}
/**
* Returns the bound element, either a {@link ExecutionEventNodeFactory factory} or a
* {@link ExecutionEventListener listener} implementation.
*
* @since 0.12
*/
public T getElement() {
return element;
}
/**
* Returns the bound filter for this binding.
*
* @return the filter never null
* @since 0.12
*/
public SourceSectionFilter getFilter() {
return filter;
}
/**
* Returns true
if the binding was already disposed, otherwise false
.
*
* @since 0.12
*/
public boolean isDisposed() {
return disposed;
}
/**
* Disposes this binding. If a binding of a listener or factory is disposed then their methods
* are not invoked again by the instrumentation framework.
*
* @since 0.12
*/
public void dispose() throws IllegalStateException {
CompilerAsserts.neverPartOfCompilation();
if (disposed) {
throw new IllegalStateException("Bindings can only be disposed once");
}
instrumenter.disposeBinding(this);
this.disposed = true;
}
boolean isInstrumentedFull(Set> providedTags, RootNode rootNode, Node node, SourceSection nodeSourceSection) {
if (isInstrumentedLeaf(providedTags, node, nodeSourceSection)) {
if (rootNode == null) {
return false;
}
return isInstrumentedRoot(providedTags, rootNode, rootNode.getSourceSection());
}
return false;
}
boolean isInstrumentedRoot(Set> providedTags, RootNode rootNode, SourceSection rootSourceSection) {
return getInstrumenter().isInstrumentableRoot(rootNode) && getFilter().isInstrumentedRoot(providedTags, rootSourceSection);
}
boolean isInstrumentedLeaf(Set> providedTags, Node instrumentedNode, SourceSection section) {
return getFilter().isInstrumentedNode(providedTags, instrumentedNode, section);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy