public static final class TruffleInstrument.Env extends Object
| Modifier and Type | Method and Description |
|---|---|
OutputStream |
err()
Standard error writer for
Engine this
instrument is being executed in. |
Iterable<Scope> |
findLocalScopes(Node node,
Frame frame)
Find a list of local scopes enclosing the given
node. |
Iterable<Scope> |
findTopScopes(String languageId)
Find a list of top scopes of a language.
|
Instrumenter |
getInstrumenter()
Returns the instrumenter which lets you instrument guest language ASTs.
|
Map<String,InstrumentInfo> |
getInstruments()
Returns a map
instrument id to instrument info of all instruments that are installed in the environment. |
LanguageInfo |
getLanguageInfo(Class<? extends TruffleLanguage<?>> languageClass)
Returns the
language info for a given language class if available. |
Map<String,LanguageInfo> |
getLanguages()
Returns a map
language id to language
info of all languages that are installed in the environment. |
Object |
getLanguageView(LanguageInfo language,
Object value)
Wraps the provided value to provide language specific information for primitive and
foreign values.
|
TruffleLogger |
getLogger(Class<?> forClass)
Find or create an engine bound logger for an instrument.
|
TruffleLogger |
getLogger(String loggerName)
Find or create an engine bound logger for an instrument.
|
org.graalvm.options.OptionValues |
getOptions()
Returns option values for the options described in
TruffleInstrument.getOptionDescriptors(). |
Object |
getPolyglotBindings()
Returns the polyglot scope - symbols explicitly exported by languages.
|
Object |
getScopedView(LanguageInfo language,
Node location,
Frame frame,
Object value)
Returns the scoped view of a value for a location in the AST.
|
TruffleFile |
getTruffleFile(String path)
Returns a
TruffleFile for given path. |
TruffleFile |
getTruffleFile(URI uri)
Returns a
TruffleFile for given URI. |
InputStream |
in()
Input associated with
Engine this instrument is being executed in. |
boolean |
isEngineRoot(RootNode root)
Returns
true if the given root node is considered an engine evaluation root
for the current execution context. |
<S> S |
lookup(InstrumentInfo instrument,
Class<S> type)
Returns an additional service provided by this instrument, specified by type.
|
<S> S |
lookup(LanguageInfo language,
Class<S> type)
Queries a
language implementation for a special service. |
OutputStream |
out()
Standard output writer for
Engine this
instrument is being executed in. |
CallTarget |
parse(Source source,
String... argumentNames)
Evaluates source of (potentially different) language using the current context.The names
of arguments are parameters for the resulting {#link CallTarget} that allow the
source to reference the actual parameters passed to
CallTarget.call(java.lang.Object...). |
ExecutableNode |
parseInline(Source source,
Node node,
MaterializedFrame frame)
Parses source snippet of the node's language at the provided node location.
|
void |
registerService(Object service)
Registers additional service.
|
void |
setAsynchronousStackDepth(int depth)
Request for languages to provide stack frames of scheduled asynchronous execution.
|
org.graalvm.polyglot.io.MessageEndpoint |
startServer(URI uri,
org.graalvm.polyglot.io.MessageEndpoint server)
Start a server at the provided URI via the
MessageTransport service. |
public Instrumenter getInstrumenter()
Instrumenterpublic InputStream in()
Engine this instrument is being executed in.nullpublic OutputStream out()
Engine this
instrument is being executed in.nullpublic OutputStream err()
Engine this
instrument is being executed in.nullpublic org.graalvm.polyglot.io.MessageEndpoint startServer(URI uri, org.graalvm.polyglot.io.MessageEndpoint server) throws IOException, org.graalvm.polyglot.io.MessageTransport.VetoException
MessageTransport service. Before an
instrument creates a server endpoint for a message protocol, it needs to check the result
of this method. When a virtual message transport is available, it blocks until a client
connects and MessageEndpoint representing the peer endpoint is returned. Those
endpoints need to be used instead of a direct creation of a server socket. If no virtual
message transport is available at that URI, null is returned and the
instrument needs to set up the server itself.
When MessageTransport.VetoException is thrown, the server
creation needs to be abandoned.
This method can be called concurrently from multiple threads. However, the
MessageEndpoint ought to be called on one thread at a time, unless you're sure
that the particular implementation can handle concurrent calls. The same holds true for
the returned endpoint, it's called synchronously.
uri - the URI of the server endpointserver - the handler of messages at the server sideMessageEndpoint call back representing the client
side, or null when no virtual transport is availableMessageTransport.VetoException - if creation of a server at that URI is not allowedIOExceptionpublic void registerService(Object service)
initialization of the instrument. These services are made available to users via
Instrument.lookup(java.lang.Class<T>) query method.
This method can only be called from
TruffleInstrument.onCreate(com.oracle.truffle.api.instrumentation.TruffleInstrument.Env) method -
then the services are collected and cannot be changed anymore.service - a service to be returned from associated
Instrument.lookup(java.lang.Class<T>)IllegalStateException - if the method is called later than from
TruffleInstrument.onCreate(com.oracle.truffle.api.instrumentation.TruffleInstrument.Env)
methodpublic <S> S lookup(LanguageInfo language, Class<S> type)
language implementation for a special service. The
services can be provided by the language by directly implementing them when subclassing
TruffleLanguage. The truffle language needs to be entered on the current Thread
otherwise an AssertionError is thrown.S - the requested typelanguage - identification of the language to querytype - the class of the requested typenull if none is foundpublic <S> S lookup(InstrumentInfo instrument, Class<S> type)
IllegalArgumentException is thrown if a service is
looked up from the current instrument.S - the requested typeinstrument - identification of the instrument to querytype - the class of the requested typenull if none is foundpublic Map<String,LanguageInfo> getLanguages()
language id to language
info of all languages that are installed in the environment.public Map<String,InstrumentInfo> getInstruments()
instrument id to instrument info of all instruments that are installed in the environment.public org.graalvm.options.OptionValues getOptions()
TruffleInstrument.getOptionDescriptors(). The returned options are never
null.public CallTarget parse(Source source, String... argumentNames) throws IOException
source to reference the actual parameters passed to
CallTarget.call(java.lang.Object...).source - the source to evaluateargumentNames - the names of CallTarget.call(java.lang.Object...) arguments
that can be referenced from the sourceIOException - if the parsing or evaluation fails for some reasonSecurityExceptionpublic ExecutableNode parseInline(Source source, Node node, MaterializedFrame frame)
ExecutableNode that accepts frames valid at the
provided node location, or null when inline parsing is not supported by the
language.source - a source snippet to parse at the provided node locationnode - a context location where the source is parsed at, must not be
nullframe - a frame location where the source is parsed at, can be nullnullpublic TruffleFile getTruffleFile(String path)
TruffleFile for given path. This must be called on a context thread
only.path - the absolute or relative path to create TruffleFile forTruffleFilepublic TruffleFile getTruffleFile(URI uri)
TruffleFile for given URI. This must be called on a context
thread only.uri - the URI to create TruffleFile forTruffleFilepublic boolean isEngineRoot(RootNode root)
true if the given root node is considered an engine evaluation root
for the current execution context. Multiple such root nodes can appear on stack frames
returned by
TruffleRuntime.iterateFrames(com.oracle.truffle.api.frame.FrameInstanceVisitor).
A debugger implementation might use this information to hide stack frames of other
engines.root - the root node to checktrue if engine root else falsepublic void setAsynchronousStackDepth(int depth)
depth asynchronous stack frames are asked for. When multiple
instruments call this method, the languages get a maximum depth of these calls and may
therefore provide longer asynchronous stacks than requested. Also, languages may provide
asynchronous stacks if it's of no performance penalty, or if requested by other options.
Asynchronous stacks can then be accessed via
TruffleStackTrace.getAsynchronousStackTrace(CallTarget, Frame).depth - the requested stack depth, 0 means no asynchronous stack frames are
required.TruffleStackTrace.getAsynchronousStackTrace(CallTarget, Frame)public LanguageInfo getLanguageInfo(Class<? extends TruffleLanguage<?>> languageClass)
language info for a given language class if available.
Language classes are typically obtained by invoking the
InteropLibrary.getLanguage(Object) message. Throws an
IllegalArgumentException if the provided language is not registered. Note that
languages may be returned that are not contained in TruffleInstrument.Env.getLanguages(). For example,
values originating from the embedder like Java classes or polyglot proxies.languageClass - the language class to convertIllegalArgumentException - if the language class is not valid.public Object getLanguageView(LanguageInfo language, Object value)
language.
display
string for primitive and foreign values.
metaobject
primitive or foreign values.
language - the language to provide the view forvalue - the value to language specific information for.TruffleLanguage.getLanguageView(Object, Object)public Object getScopedView(LanguageInfo language, Node location, Frame frame, Object value)
The provided language must match the language of the root node
of the location provided. The frame must have the same FrameDescriptor associated
as the RootNode of the provided location. The provided location must be
instrumentable. If any of these
pre-conditions are violated then an IllegalArgumentException is thrown.
If a value is not yet associated with the provided language, then a
language view will be requested
implicitly. Only interop messages should be used on the result of
this method.
language - the language must match the languagelocation - the location to provide scope for. Never null and returns
true for InstrumentableNode.isInstrumentable(). E.g. any
location observed using EventContext.getInstrumentedNode().frame - the frame of the current activation of the parent RootNode.value - the value to provide scope information for.TruffleLanguage.getScopedView(Object, Node, Frame, Object)public Object getPolyglotBindings()
public Iterable<Scope> findLocalScopes(Node node, Frame frame)
node. The scopes contain
variables that are valid at the provided node and that have a relation to it. Unless the
node is in a global scope, it is expected that there is at least one scope provided, that
corresponds to the enclosing function. Global top scopes are provided by
TruffleInstrument.Env.findTopScopes(java.lang.String). The iteration order corresponds with the scope
nesting, from the inner-most to the outer-most.
Scopes may depend on the information provided by the frame.
Lexical scopes are returned when frame argument is null.
node - a node to get the enclosing scopes for. The node needs to be inside a
RootNode associated with a language.frame - The current frame the node is in, or null for lexical access
when the program is not running, or is not suspended at the node's location.Iterable providing list of scopes from the inner-most to the
outer-most.TruffleLanguage.findLocalScopes(java.lang.Object, com.oracle.truffle.api.nodes.Node,
com.oracle.truffle.api.frame.Frame)public Iterable<Scope> findTopScopes(String languageId)
languageId - a language id.TruffleLanguage.findTopScopes(java.lang.Object)public TruffleLogger getLogger(String loggerName)
If a logger with given name already exists it's returned, otherwise a new logger is created.
Unlike loggers created by
TruffleLogger.getLogger loggers created by this method are bound to engine, there may be
more logger instances having the same name but each bound to different engine instance.
Instruments should never store the returned logger into a static fields. A new logger
must be always created in
onCreate method.
loggerName - the the name of a TruffleLogger, if a loggerName is
null or empty a root logger for language or instrument is returnedTruffleLoggerpublic TruffleLogger getLogger(Class<?> forClass)
If a logger for the class already exists it's returned, otherwise a new logger is created.
Unlike loggers created by
TruffleLogger.getLogger loggers created by this method are bound to engine, there may be
more logger instances having the same name but each bound to different engine instance.
Instruments should never store the returned logger into a static fields. A new logger
must be always created in
onCreate method.
forClass - the Class to create a logger forTruffleLoggerNullPointerException - if forClass is null