public interface ConstantReflectionProvider
object
constants. This access is not always possible, depending on kind of VM and the state that
the VM is in. Therefore, all methods can return null
at any time, to indicate that the
result is not available at this point. The caller is responsible to check for null
results and handle them properly, e.g., not perform an optimization.Modifier and Type | Method and Description |
---|---|
ResolvedJavaType |
asJavaType(Constant constant)
Returns the
ResolvedJavaType for a Class object (or any other object regarded
as a class by the VM) encapsulated in the given constant. |
JavaConstant |
boxPrimitive(JavaConstant source)
|
Boolean |
constantEquals(Constant x,
Constant y)
Compares two constants for equality.
|
JavaConstant |
forString(String value)
Gets a string as a
JavaConstant . |
MemoryAccessProvider |
getMemoryAccessProvider()
Gets raw memory access.
|
MethodHandleAccessProvider |
getMethodHandleAccess()
Gets access to the internals of
MethodHandle . |
JavaConstant |
readArrayElement(JavaConstant array,
int index)
Reads a value from the given array at the given index.
|
Integer |
readArrayLength(JavaConstant array)
Returns the length of the array constant.
|
JavaConstant |
readConstantArrayElement(JavaConstant array,
int index)
Reads a value from the given array at the given index if it is a stable array.
|
JavaConstant |
readConstantArrayElementForOffset(JavaConstant array,
long offset)
Reads a value from the given array at the given offset if it is a stable array.
|
JavaConstant |
readConstantFieldValue(JavaField field,
JavaConstant receiver)
Gets the constant value of this field.
|
JavaConstant |
readFieldValue(JavaField field,
JavaConstant receiver)
Gets the current value of this field for a given object, if available.
|
JavaConstant |
readStableFieldValue(JavaField field,
JavaConstant receiver,
boolean isDefaultStable)
Gets the current value of this field for a given object, if available.
|
JavaConstant |
unboxPrimitive(JavaConstant source)
|
Boolean constantEquals(Constant x, Constant y)
Integer readArrayLength(JavaConstant array)
null
if the constant is not an
array, or if the array length is not available at this point.JavaConstant readArrayElement(JavaConstant array, int index)
null
if the constant
is not an array, if the index is out of bounds, or if the value is not available at this
point.JavaConstant readConstantArrayElement(JavaConstant array, int index)
null
if the constant is not a stable array, if it is a default value, if the index is
out of bounds, or if the value is not available at this point.JavaConstant readConstantArrayElementForOffset(JavaConstant array, long offset)
null
if the constant is not a stable array, if it is a default value, if the offset
is out of bounds, or if the value is not available at this point.JavaConstant readConstantFieldValue(JavaField field, JavaConstant receiver)
static final
field may not be
considered constant if its declaring class is not yet initialized or if it is a well known
field that can be updated via other means (e.g., System.setOut(java.io.PrintStream)
).receiver
- object from which this field's value is to be read. This value is ignored if
this field is static.null
if this field is not considered
constant by the runtimeJavaConstant readFieldValue(JavaField field, JavaConstant receiver)
receiver
- object from which this field's value is to be read. This value is ignored if
this field is static.null
if the value is not available (e.g., because
the field holder is not yet initialized).JavaConstant readStableFieldValue(JavaField field, JavaConstant receiver, boolean isDefaultStable)
readFieldValue(JavaField, JavaConstant)
but treats array fields as stable.
There is no guarantee that the same value will be returned by this method for a field unless
the field is considered to be constant by the runtime.receiver
- object from which this field's value is to be read. This value is ignored if
this field is static.isDefaultStable
- if true
, default values are considered stablenull
if the value is not available (e.g., because
the field holder is not yet initialized).JavaConstant boxPrimitive(JavaConstant source)
JavaConstant unboxPrimitive(JavaConstant source)
JavaConstant forString(String value)
JavaConstant
.ResolvedJavaType asJavaType(Constant constant)
ResolvedJavaType
for a Class
object (or any other object regarded
as a class by the VM) encapsulated in the given constant. Returns null
if the
constant does not encapsulate a class, or if the type is not available at this point.MethodHandleAccessProvider getMethodHandleAccess()
MethodHandle
.MemoryAccessProvider getMemoryAccessProvider()