Class BytecodeSupport.ConstantsBuffer
java.lang.Object
com.oracle.truffle.api.bytecode.BytecodeSupport.ConstantsBuffer
- Enclosing class:
BytecodeSupport
Specialized reusable and allocation-free buffer for constants.
The first 8 literals are stored linearly in
constants[]. Once
that threshold is crossed, all literals are also entered into an open-address hash table
(keys[]/values[]) so that subsequent look-ups run in amortised O(1) without
allocating any Map.Entry objects.
After the client has finished emitting a method it must call materialize() to obtain
an immutable snapshot of the constant pool for that method. The buffer can then be filled
again without further allocations. Call clear() at the end of using this buffer if
you want to release the object references or down-size the backing arrays.
Not thread-safe.
Intended for use in generated code. Do not use directly.- Since:
- 25.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintInsertsconstant(non-null) and returns its pool index.intaddNull()Inserts a constant without value and returns its index.voidclear()Clears all object references held in this buffer.Object[]create()Object[]Copies the internalconstants[]array and returns it.
-
Constructor Details
-
ConstantsBuffer
public ConstantsBuffer()
-
-
Method Details
-
add
Insertsconstant(non-null) and returns its pool index. If an equal constant is already present, its existing index is returned.- Throws:
NullPointerException- ifconstantisnull- Since:
- 25.0
-
addNull
public int addNull()Inserts a constant without value and returns its index. The added null values are intended to be later patched aftermaterialization. The client must ensure that the reserved null slots do not contain duplicates already contained in the materialized constants array.- Since:
- 25.0
-
materialize
Copies the internalconstants[]array and returns it. All auxiliary data structures are reset so that the buffer is ready for the next use. Note that this implementation deliberately does not clear all references contained in the buffer. If all references should be cleared, thenclear()should be called after materialization.- Returns:
- a freshly allocated array of exactly
size()elements, nevernull. - Since:
- 25.0
-
create
-
clear
public void clear()Clears all object references held in this buffer. If the pool had grown beyond 512 constants its internal arrays are replaced by new arrays of that bounded size; otherwise the existing arrays are reused.The buffer must be materialised before it can be cleared.
- Throws:
IllegalStateException- ifmaterialize()has not been called since the last insertion- Since:
- 25.0
-