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
ConstructorsModifierConstructorDescriptionprotected
BytecodeRootNodes
(Object token, BytecodeParser<? extends BytecodeBuilder> parser) Default constructor for aBytecodeBuilder
. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
count()
Returns the number of root nodes produced from the parse.final boolean
Ensures that all sources and instrumentation metadata is available, reparsing if necessary.final boolean
Ensures that sources are available, reparsing if necessary.final T
getNode
(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.void
serialize
(DataOutput buffer, BytecodeSerializer callback) Serializes the nodes to a byte buffer.toString()
Returns a string representation of aBytecodeRootNodes
.final boolean
update
(BytecodeConfig config) Updates the configuration for the given bytecode nodes.protected abstract boolean
updateImpl
(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 nodes
of aBytecodeRootNodes
unit. 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 theBytecodeNode
is 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 thendeoptimization
will 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
serialize
method 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
-
toString
Returns a string representation of aBytecodeRootNodes
.
-