All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.oracle.truffle.api.instrumentation.EventBinding Maven / Gradle / Ivy

Go to download

Truffle is a multi-language framework for executing dynamic languages that achieves high performance when combined with Graal.

There is a newer version: 1.0.0-rc7
Show newest version
/*
 * 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.Source;
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; private final boolean isExecutionEvent; /* language bindings needs special treatment. */ private volatile boolean disposed; EventBinding(AbstractInstrumenter instrumenter, SourceSectionFilter query, T element, boolean isExecutionEvent) { this.instrumenter = instrumenter; this.filter = query; this.element = element; this.isExecutionEvent = isExecutionEvent; } /** * 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 synchronized void dispose() throws IllegalStateException { CompilerAsserts.neverPartOfCompilation(); if (!disposed) { instrumenter.disposeBinding(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); } boolean isInstrumentedSource(Source source) { return getFilter().isInstrumentedSource(source); } boolean isExecutionEvent() { return isExecutionEvent; } boolean isLanguageBinding() { return instrumenter instanceof LanguageClientInstrumenter; } AbstractInstrumenter getInstrumenter() { return instrumenter; } synchronized void disposeBulk() { disposed = true; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy