Class BytecodeRootNodes<T extends RootNode & BytecodeRootNode>
- Type Parameters:
T- the type of the bytecode root node
BytecodeRootNodes instance encapsulates one or more bytecode root nodes produced from a
single parse. To reduce interpreter footprint, it supports on-demand reparsing to compute source
and instrumentation metadata.
This class will be overridden by the Bytecode DSL. Do not override manually.
- Since:
- 24.2
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBytecodeRootNodes(Object token, BytecodeParser<? extends BytecodeBuilder> parser) Default constructor for aBytecodeBuilder. -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters anInstructionTracerfor thisBytecodeRootNodesinstance.final intcount()Returns the number of root nodes produced from the parse.final booleanEnsures that all sources and instrumentation metadata is available, reparsing if necessary.final booleanEnsures that sources are available, reparsing if necessary.final TgetNode(int i) Returns the bytecode root node at indexi.getNodes()Returns the list of bytecode root nodes.protected final BytecodeParser<? extends BytecodeBuilder> Returns the parser used to parse the root nodes.voidUnregisters a previously installedInstructionTracerfrom thisBytecodeRootNodesinstance.voidserialize(DataOutput buffer, BytecodeSerializer callback) Serializes the nodes to a byte buffer.toString()Returns a string representation of aBytecodeRootNodes.final booleanupdate(BytecodeConfig config) Updates the configuration for the given bytecode nodes.protected voidupdateGlobalInstructionTracers(InstructionTracer[] tracers) Internal callback to the generated code to notify when global instruction tracers change.protected abstract booleanupdateImpl(BytecodeConfigEncoder encoder, long encoding) Implementation of reparse.
-
Field Details
-
TOKEN
A singleton object used to ensure certain Bytecode DSL APIs are only used by generated code.- Since:
- 24.2
-
nodes
-
-
Constructor Details
-
BytecodeRootNodes
Default constructor for aBytecodeBuilder.- Since:
- 24.2
-
-
Method Details
-
getNodes
-
getNode
Returns the bytecode root node at indexi. The order of the list corresponds to the order ofbeginRoot(...)calls on the builder.- Since:
- 24.2
-
count
public final int count()Returns the number of root nodes produced from the parse.- Since:
- 24.2
-
getParser
Returns the parser used to parse the root nodes.- Since:
- 24.2
-
update
Updates the configuration for the given bytecode nodes. If the new configuration requires more information (e.g., sources, instrumentation or tags), this method may trigger a reparse to obtain it.Performance considerations: Updating and adding instrumentations or tags is a costly operation and requires reparsing all
root nodesof aBytecodeRootNodesunit. Reparsing and modifying the generated bytecodes will also deoptimize and invalidate all currently optimized code of the reparsed root nodes. It also may or may not reset all profiling feedback gathered so far. Updating and adding just source information is a much less expensive operation and does not require any invalidation, but also requires to reparse all root nodes. Since compiled code is not invalidated when source information is added (and hence theBytecodeNodeis not updated), lazily updated source information should not be accessed in compiled code.Usage in compiled code: This method may be used in compiled code, but the bytecode config must be a
partial evaluation constant. If the bytecode config is changed in compiled code thendeoptimizationwill be triggered. If an update does not require any changes then this operation will be a no-op in compiled code. In the interpreter it is also reasonably fast (a read and comparison of a volatile field), so it should reasonable to call this method on the fast path (e.g., in theprolog).- Since:
- 24.2
-
updateImpl
Implementation of reparse.This method will be generated by the Bytecode DSL. Do not override.
- Since:
- 24.2
-
serialize
Serializes the nodes to a byte buffer. This method will always fail unless serialization isenabled.Unlike the static
serializemethod defined on the generated root node, this method serializes the nodes using their current field values.This method will be overridden by the Bytecode DSL. Do not override.
- Parameters:
buffer- The buffer to write the serialized bytes to.callback- A language-defined method for serializing language constants.- Throws:
IOException- if an I/O error occurs with the buffer.
-
ensureSourceInformation
public final boolean ensureSourceInformation()Ensures that sources are available, reparsing if necessary.- Since:
- 24.2
-
ensureComplete
public final boolean ensureComplete()Ensures that all sources and instrumentation metadata is available, reparsing if necessary.- Since:
- 24.2
-
addInstructionTracer
Registers anInstructionTracerfor thisBytecodeRootNodesinstance.This is a local variant of
BytecodeDescriptor.addInstructionTracer(TruffleLanguage, InstructionTracer): it only affects the root nodes contained in thisBytecodeRootNodesobject, not all bytecode roots for the entire language.Tracer invocation happens on the language execution thread, at instruction granularity, and may run at very high frequency. Implementations should avoid unnecessary allocation or blocking.
The same tracer instance can only be attached once. If the tracer is already installed for this
BytecodeRootNodesinstance, then this method has no effect. The order in which multiple tracers are invoked is unspecified.If this bytecode interpreter was generated without instruction tracing support (for example using
@GenerateBytecode(enableInstructionTracing = false)), this method throwsUnsupportedOperationException.- Parameters:
tracer- the tracer to install- Throws:
IllegalArgumentException- iftraceris exclusive to a differentBytecodeDescriptor(seeInstructionTracer.getExclusiveBytecodeDescriptor())UnsupportedOperationException- if instruction tracing is not enabled for this interpreter- Since:
- 25.1
-
removeInstructionTracer
Unregisters a previously installedInstructionTracerfrom thisBytecodeRootNodesinstance.Note that currently when all instruction tracers were removed, the trace instructions remain in the bytecode. This may be improved in the future.
If this bytecode interpreter was generated without instruction tracing support (for example using
@GenerateBytecode(enableInstructionTracing = false)), this method throwsUnsupportedOperationException.- Parameters:
tracer- the tracer to remove- Throws:
IllegalArgumentException- iftraceris exclusive to a differentBytecodeDescriptor(seeInstructionTracer.getExclusiveBytecodeDescriptor())UnsupportedOperationException- if instruction tracing is not enabled for this interpreter- Since:
- 25.1
-
updateGlobalInstructionTracers
Internal callback to the generated code to notify when global instruction tracers change.- Since:
- 25.1
-
toString
Returns a string representation of aBytecodeRootNodes.
-