public final class Engine extends Object implements AutoCloseable
guest languages
, instruments
and
their available options.
By default every context creates its own engine
instance implicitly when
instantiated
. Multiple contexts can use an
explicit engine
when using a context builder. If contexts
share the same engine instance then they share instruments and their configuration.
It can be useful to create
an engine instance without a context to only
access meta-data for installed languages, instruments and their available options.
Modifier and Type | Class and Description |
---|---|
class |
Engine.Builder |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this engine and frees up allocated native resources.
|
void |
close(boolean cancelIfExecuting)
Closes this engine and frees up allocated native resources.
|
static Engine |
create()
Creates a new engine instance with default configuration.
|
static Engine |
create(String... permittedLanguages)
Creates a new engine instance with default configuration with a set of permitted languages.
|
static Path |
findHome()
Finds the GraalVM home folder.
|
Set<Source> |
getCachedSources()
Returns the sources previously cached by this engine.
|
String |
getImplementationName()
Gets a human-readable name of the polyglot implementation (for example, "Default Truffle
Engine" or "Graal Truffle Engine").
|
Map<String,Instrument> |
getInstruments()
Gets all installed instruments of this engine.
|
Map<String,Language> |
getLanguages()
Gets a map of all installed languages with the language id as key and the language object as
value.
|
OptionDescriptors |
getOptions()
Returns all options available for the engine.
|
String |
getVersion()
Gets the version string of the engine in an unspecified format.
|
static Engine.Builder |
newBuilder()
Creates a new engine builder that allows to configure an engine instance.
|
static Engine.Builder |
newBuilder(String... permittedLanguages)
Creates a new engine builder that allows to configure an engine instance.
|
public Map<String,Language> getLanguages()
public Map<String,Instrument> getInstruments()
options
passed to the engine
when the engine or
context is constructed.public OptionDescriptors getOptions()
groups
:
Instrument.getOptions()
or Language.getOptions()
.public String getVersion()
public void close(boolean cancelIfExecuting)
PolyglotException
. The exception indicates that it was
cancelled
.cancelIfExecuting
- if true
then currently executing contexts will be
cancelled, else an IllegalStateException
is thrown.public void close()
close
in interface AutoCloseable
IllegalStateException
- if there currently executing open context instances.Engine.close(boolean)
,
Engine.close()
public String getImplementationName()
null
.public static Engine create()
newBuilder().build()
.to create a new execution context.
public static Engine create(String... permittedLanguages)
newBuilder(permittedLanuages).build()
.to create a new execution context.
public static Engine.Builder newBuilder()
Engine.newBuilder(String...)
with an empty set of permitted
languages.public static Engine.Builder newBuilder(String... permittedLanguages)
permittedLanguages
- names of languages permitted in the engine. If no languages are
provided, then all installed languages will be permitted. All contexts created
with this engine will inherit the set of permitted languages.public static Path findHome()
HomeFinder.getHomeFolder()
which should be preferred.null
if it cannot be foundpublic Set<Source> getCachedSources()
caching
(default on). The source cache of the engine
is using weak references to refer to the source objects. Calling this method will result in a
strong reference to all cached sources of this engine until the returned set is no longer
referenced. This method is useful to find out which sources very already evaluated by this
engine. This method only returns sources that were evaluated using
Context.eval(Source)
. Sources evaluated by the guest application will not be
returned. The return set is never null
and not modifiable.