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. |
LanguageInfo |
findLanguage(Object value)
Find a language that created the value, if any.
|
Iterable<Scope> |
findLocalScopes(Node node,
Frame frame)
Find a list of local scopes enclosing the given
node. |
Object |
findMetaObject(LanguageInfo language,
Object value)
Uses the provided language to find a meta-object of a value, if any.
|
SourceSection |
findSourceLocation(LanguageInfo language,
Object value)
Uses the provided language to find a source location where a value is declared, if any.
|
Iterable<Scope> |
findTopScopes(String languageId)
Find a list of top scopes of a language.
|
Map<String,? extends Object> |
getExportedSymbols()
Returns the polyglot scope - symbols explicitly exported by languages.
|
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. |
Map<String,LanguageInfo> |
getLanguages()
Returns a map
language id to language
info of all languages that are installed in the environment. |
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
TruffleLanguage.getOptionDescriptors(). |
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.
|
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. |
String |
toString(LanguageInfo language,
Object value)
Uses the provided language to print a string representation of this value.
|
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()
TruffleLanguage.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 reasonpublic 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 String toString(LanguageInfo language, Object value)
language - a languagevalue - a known value of that language, must be an interop type (i.e. either
implementing TruffleObject or be a primitive value)TruffleInstrument.Env.findLanguage(java.lang.Object)public Object findMetaObject(LanguageInfo language, Object value)
null is
returned. For the best results, use the value's
language, if any.language - a languagevalue - a value to find the meta-object of, must be an interop type (i.e. either
implementing TruffleObject or be a primitive value)nullTruffleInstrument.Env.findLanguage(java.lang.Object)public SourceSection findSourceLocation(LanguageInfo language, Object value)
value's language,
if any.language - a languagevalue - a value to get the source location for, must be an interop type (i.e. either
implementing TruffleObject or be a primitive value)nullTruffleInstrument.Env.findLanguage(java.lang.Object)public LanguageInfo findLanguage(Object value)
null
for values representing a primitive value, or objects that are not associated with any
language.value - the value to find a language ofnull when there is no language associated with the
value.public Map<String,? extends Object> getExportedSymbols()
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