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()
ConstantReflectionProviderMethodHandle.getMethodHandleAccess in interface ConstantReflectionProviderpublic MemoryAccessProvider getMemoryAccessProvider()
ConstantReflectionProvidergetMemoryAccessProvider in interface ConstantReflectionProviderpublic Boolean constantEquals(Constant x, Constant y)
ConstantReflectionProvidertrue 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 ConstantReflectionProviderpublic Integer readArrayLength(JavaConstant array)
ConstantReflectionProvidernull if the constant is not an
array, or if the array length is not available at this point.readArrayLength in interface ConstantReflectionProviderpublic JavaConstant readConstantArrayElement(JavaConstant array, int index)
ConstantReflectionProvidernull 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 ConstantReflectionProviderprivate int indexForOffset(JavaConstant array, long offset)
offset into an an index into array.public JavaConstant readConstantArrayElementForOffset(JavaConstant array, long offset)
ConstantReflectionProvidernull 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 ConstantReflectionProviderpublic JavaConstant readArrayElement(JavaConstant array, int index)
ConstantReflectionProvidernull 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 ConstantReflectionProviderprivate static boolean isBoxCached(JavaConstant source)
source - public JavaConstant boxPrimitive(JavaConstant source)
ConstantReflectionProviderprimitive 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 ConstantReflectionProviderpublic JavaConstant unboxPrimitive(JavaConstant source)
ConstantReflectionProviderobject 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 ConstantReflectionProviderpublic JavaConstant forString(String value)
ConstantReflectionProviderJavaConstant.forString in interface ConstantReflectionProviderpublic ResolvedJavaType asJavaType(Constant constant)
ConstantReflectionProviderResolvedJavaType 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 ConstantReflectionProviderprotected 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 ConstantReflectionProviderreceiver - 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)
ConstantReflectionProviderreadFieldValue in interface ConstantReflectionProviderreceiver - 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)
ConstantReflectionProviderConstantReflectionProvider.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 ConstantReflectionProviderreceiver - 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)