public class HotSpotConstantReflectionProvider extends Object implements ConstantReflectionProvider, HotSpotProxified
ConstantReflectionProvider
.Modifier and Type | Class and Description |
---|---|
(package private) static class |
HotSpotConstantReflectionProvider.Options |
Modifier and Type | Field and Description |
---|---|
protected HotSpotMemoryAccessProviderImpl |
memoryAccess |
protected HotSpotMethodHandleAccessProvider |
methodHandleAccess |
protected HotSpotJVMCIRuntimeProvider |
runtime |
private static String |
SystemClassName |
Constructor and Description |
---|
HotSpotConstantReflectionProvider(HotSpotJVMCIRuntimeProvider runtime) |
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 . |
private static int |
getArrayDimension(JavaType type) |
MemoryAccessProvider |
getMemoryAccessProvider()
Gets raw memory access.
|
MethodHandleAccessProvider |
getMethodHandleAccess()
Gets access to the internals of
MethodHandle . |
private int |
indexForOffset(JavaConstant array,
long offset)
Try to convert
offset into an an index into array . |
private static boolean |
isBoxCached(JavaConstant source)
Check if the constant is a boxed value that is guaranteed to be cached by the platform.
|
protected boolean |
isFinalInstanceFieldValueConstant(JavaConstant value,
Class<?> receiverClass)
Determines if a value read from a
final instance field is considered constant. |
protected boolean |
isStableInstanceFieldValueConstant(JavaConstant value,
Class<?> receiverClass)
Determines if a value read from a
Stable instance field is considered constant. |
protected boolean |
isStaticFieldConstant(HotSpotResolvedJavaField staticField)
Determines if a static field is constant for the purpose of
readConstantFieldValue(JavaField, JavaConstant) . |
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.
|
private JavaConstant |
readNonStableFieldValue(JavaField field,
JavaConstant receiver) |
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)
|
protected final HotSpotJVMCIRuntimeProvider runtime
protected final HotSpotMethodHandleAccessProvider methodHandleAccess
protected final HotSpotMemoryAccessProviderImpl memoryAccess
private static final String SystemClassName
public HotSpotConstantReflectionProvider(HotSpotJVMCIRuntimeProvider runtime)
public MethodHandleAccessProvider getMethodHandleAccess()
ConstantReflectionProvider
MethodHandle
.getMethodHandleAccess
in interface ConstantReflectionProvider
public MemoryAccessProvider getMemoryAccessProvider()
ConstantReflectionProvider
getMemoryAccessProvider
in interface ConstantReflectionProvider
public Boolean constantEquals(Constant x, Constant y)
ConstantReflectionProvider
true
if the two constants represent the same run time value,
false
if they are different. Returns null
if the constants
cannot be compared at this point.constantEquals
in interface ConstantReflectionProvider
public Integer readArrayLength(JavaConstant array)
ConstantReflectionProvider
null
if the constant is not an
array, or if the array length is not available at this point.readArrayLength
in interface ConstantReflectionProvider
public JavaConstant readConstantArrayElement(JavaConstant array, int index)
ConstantReflectionProvider
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.readConstantArrayElement
in interface ConstantReflectionProvider
private int indexForOffset(JavaConstant array, long offset)
offset
into an an index into array
.public JavaConstant readConstantArrayElementForOffset(JavaConstant array, long offset)
ConstantReflectionProvider
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.readConstantArrayElementForOffset
in interface ConstantReflectionProvider
public JavaConstant readArrayElement(JavaConstant array, int index)
ConstantReflectionProvider
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.readArrayElement
in interface ConstantReflectionProvider
private static boolean isBoxCached(JavaConstant source)
source
- public JavaConstant boxPrimitive(JavaConstant source)
ConstantReflectionProvider
primitive
constant to a boxed
object
constant, according to the Java boxing rules. Returns null
if the source is is not a primitive constant, or the boxed value is not available at this
point.boxPrimitive
in interface ConstantReflectionProvider
public JavaConstant unboxPrimitive(JavaConstant source)
ConstantReflectionProvider
object
constant to a primitive
constant, according to the Java unboxing rules. Returns null
if the source
is is not an object constant that can be unboxed, or the unboxed value is not available at
this point.unboxPrimitive
in interface ConstantReflectionProvider
public JavaConstant forString(String value)
ConstantReflectionProvider
JavaConstant
.forString
in interface ConstantReflectionProvider
public ResolvedJavaType asJavaType(Constant constant)
ConstantReflectionProvider
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.asJavaType
in interface ConstantReflectionProvider
protected boolean isStaticFieldConstant(HotSpotResolvedJavaField staticField)
readConstantFieldValue(JavaField, JavaConstant)
.protected boolean isFinalInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass)
final
instance field is considered constant. The
implementation in HotSpotConstantReflectionProvider
returns true if value
is
not the default value
for its kind or if
HotSpotConstantReflectionProvider.Options.TrustFinalDefaultFields
is true.value
- a value read from a final
instance fieldreceiverClass
- the class
of object from which the
value
was readprotected boolean isStableInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass)
Stable
instance field is considered constant. The
implementation in HotSpotConstantReflectionProvider
returns true if value
is
not the default value
for its kind.public 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)
).
The value
field in OptionValue
is considered constant if the type of
receiver
is (assignable to) StableOptionValue
.
readConstantFieldValue
in interface ConstantReflectionProvider
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 runtimepublic JavaConstant readFieldValue(JavaField field, JavaConstant receiver)
ConstantReflectionProvider
readFieldValue
in interface ConstantReflectionProvider
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).private JavaConstant readNonStableFieldValue(JavaField field, JavaConstant receiver)
public JavaConstant readStableFieldValue(JavaField field, JavaConstant receiver, boolean isDefaultStable)
ConstantReflectionProvider
ConstantReflectionProvider.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.readStableFieldValue
in interface ConstantReflectionProvider
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).private static int getArrayDimension(JavaType type)