Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.graalvm.options.OptionDescriptor;
import org.graalvm.options.OptionDescriptors;
import org.graalvm.options.OptionValues;
import org.graalvm.polyglot.Engine;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.InstrumentInfo;
import com.oracle.truffle.api.Option;
import com.oracle.truffle.api.Scope;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleRuntime;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.InstrumentationHandler.AccessorInstrumentHandler;
import com.oracle.truffle.api.instrumentation.InstrumentationHandler.InstrumentClientInstrumenter;
import com.oracle.truffle.api.nodes.ExecutableNode;
import com.oracle.truffle.api.nodes.LanguageInfo;
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;
/**
* The service provider interface (SPI) for Truffle instruments: clients of Truffle instrumentation
* that may observe and inject behavior into interpreters written using the Truffle framework.
*
* Instrument implementation classes must use the {@link Registration} annotation to provide
* required metadata and to enable automatic discovery of the implementation.
*
* An instrument is {@link #onCreate(Env) created } if at least one instrument
* {@link TruffleInstrument.Env#getOptions() option} was specified or if a
* {@link TruffleInstrument.Env#registerService(Object) service} was looked up. The
* {@link Instrumenter} available in the provided {@linkplain Env environment} allows the instrument
* instance to bind listeners for {@linkplain ExecutionEventListener execution} and
* {@linkplain LoadSourceListener source} events, as well as {@linkplain ExecutionEventNodeFactory
* node factories} for code injection at guest language code locations.
*
* An instrument is disposed when the associated polyglot {@linkplain Engine engine} is disposed.
* All active bindings created by a disposed instrument become disposed automatically. The
* {@link Instrumenter} instance available in the provided {@linkplain Env environment} may not be
* used after disposal.
*
*
Example for a simple expression coverage instrument:
* {@codesnippet com.oracle.truffle.api.instrumentation.test.examples.CoverageExample}
*
* @since 0.12
*/
public abstract class TruffleInstrument {
/**
* Constructor for subclasses.
*
* @since 0.12
*/
protected TruffleInstrument() {
}
/**
* Invoked once on each newly allocated {@link TruffleInstrument} instance.
*
* The method may {@link Env#registerService(java.lang.Object) register} additional
* {@link Registration#services() services} - e.g. objects to be exposed via
* {@link org.graalvm.polyglot.Instrument#lookup lookup query}. For example to expose a debugger
* one could define an abstract debugger controller:
*
*
* {@codesnippet DebuggerController}
*
* and declare it as a {@link Registration#services() service} associated with the instrument,
* implement it, instantiate and {@link Env#registerService(java.lang.Object) register} in own's
* instrument {@link #onCreate(com.oracle.truffle.api.instrumentation.TruffleInstrument.Env)
* onCreate} method:
*
* {@codesnippet DebuggerExample}
*
* @param env environment information for the instrument
*
* @see Env#getInstrumenter()
* @since 0.12
*/
protected abstract void onCreate(Env env);
/**
* Invoked once on an {@linkplain TruffleInstrument instance} just before all instruments and
* languages are going to be disposed, possibly because the underlying
* {@linkplain org.graalvm.polyglot.Engine engine} is going to be closed. This method is called
* before {@link #onDispose(Env)} and the instrument must remain usable after finalization. The
* instrument can prepare for disposal while still having other instruments not disposed yet.
*
* @param env environment information for the instrument
* @since 1.0
*/
protected void onFinalize(Env env) {
// default implementation does nothing
}
/**
* Invoked once on an {@linkplain TruffleInstrument instance} when it becomes disabled, possibly
* because the underlying {@linkplain org.graalvm.polyglot.Engine engine} has been closed. A
* disposed instance is no longer usable. If the instrument is re-enabled, the engine will
* create a new instance.
*
* @param env environment information for the instrument
* @since 0.12
*/
protected void onDispose(Env env) {
// default implementation does nothing
}
/**
* Returns a set of option descriptors that are supported by this instrument. Option values are
* accessible using the {@link Env#getOptions() environment} when the instrument is
* {@link #onCreate(Env) created}. By default no options are available for an instrument.
* Options returned by this method must specify the {@link Registration#id() instrument id} as
* {@link OptionDescriptor#getName() name} prefix for each option. For example if the id of the
* instrument is "debugger" then a valid option name would be "debugger.Enabled". The instrument
* will automatically be {@link #onCreate(Env) created} if one of the specified options was
* provided by the engine. To construct option descriptors from a list then
* {@link OptionDescriptors#create(List)} can be used.
*
* @see Option For an example of declaring the option descriptor using an annotation.
* @since 0.27
*/
protected OptionDescriptors getOptionDescriptors() {
return OptionDescriptors.EMPTY;
}
/**
* Access to instrumentation services as well as input, output, and error streams.
*
* @since 0.12
*/
@SuppressWarnings("static-method")
public static final class Env {
private final Object vmObject; // PolyglotInstrument
private final InputStream in;
private final OutputStream err;
private final OutputStream out;
OptionValues options;
InstrumentClientInstrumenter instrumenter;
private List