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 com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.InstrumentInfo;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleRuntime;
import com.oracle.truffle.api.instrumentation.InstrumentationHandler.AccessorInstrumentHandler;
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
* {@linkplain com.oracle.truffle.api.vm.PolyglotEngine.Instrument Instruments}: clients of Truffle
* instrumentation that may observe and inject behavior into interpreters written using the Truffle
* framework.
*
* Each registered instrument can be
* {@linkplain com.oracle.truffle.api.vm.PolyglotEngine.Instrument#setEnabled(boolean)
* enabled/disabled} multiple times during the lifetime of a
* {@link com.oracle.truffle.api.vm.PolyglotEngine PolyglotEngine}, but there is never more than one
* instance per engine. A new {@link TruffleInstrument} instance is created each time the instrument
* is enabled, and the currently enabled instance is disposed when the instrument is disabled.
*
*
Registration
*
* Instrument implementation classes must use the {@link Registration} annotation to provide
* required metadata and to enable automatic discovery of the implementation.
*
*
Instrument Creation
*
*
When an instrument becomes
* {@linkplain com.oracle.truffle.api.vm.PolyglotEngine.Instrument#setEnabled(boolean) enabled}, a
* new instance is created and notified once via {@link #onCreate(Env)}.
*
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.
*
*
Instrument Disposal
*
*
When an instrument becomes
* {@linkplain com.oracle.truffle.api.vm.PolyglotEngine.Instrument#setEnabled(boolean) disabled},
* the current instance is notified once via {@link #onDispose(Env)}.
*
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.
*
All enabled instruments in an engine become disabled automatically when the engine is
* disposed.
*
*
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 com.oracle.truffle.api.vm.PolyglotRuntime.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} when it becomes
* {@linkplain com.oracle.truffle.api.vm.PolyglotEngine.Instrument#setEnabled(boolean) disabled}
* , possibly because the underlying {@linkplain com.oracle.truffle.api.vm.PolyglotEngine
* engine} has been disposed. 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
}
/**
* 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; // PolyglotRuntime.Instrument
private final Instrumenter instrumenter;
private final InputStream in;
private final OutputStream err;
private final OutputStream out;
private List