src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java

Print this page

        

@@ -28,32 +28,28 @@
 import java.lang.reflect.Array;
 
 import jdk.vm.ci.meta.Constant;
 import jdk.vm.ci.meta.ConstantReflectionProvider;
 import jdk.vm.ci.meta.JavaConstant;
-import jdk.vm.ci.meta.JavaField;
 import jdk.vm.ci.meta.JavaKind;
 import jdk.vm.ci.meta.JavaType;
 import jdk.vm.ci.meta.MemoryAccessProvider;
 import jdk.vm.ci.meta.MethodHandleAccessProvider;
+import jdk.vm.ci.meta.ResolvedJavaField;
 import jdk.vm.ci.meta.ResolvedJavaType;
-import jdk.vm.ci.options.Option;
-import jdk.vm.ci.options.OptionType;
-import jdk.vm.ci.options.OptionValue;
-import jdk.vm.ci.options.StableOptionValue;
 
 /**
  * HotSpot implementation of {@link ConstantReflectionProvider}.
  */
 public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, HotSpotProxified {
 
-    static class Options {
-        //@formatter:off
-        @Option(help = "Constant fold final fields with default values.", type = OptionType.Debug)
-        public static final OptionValue<Boolean> TrustFinalDefaultFields = new OptionValue<>(true);
-        //@formatter:on
-    }
+    private static final String TrustFinalDefaultFieldsProperty = "jvmci.TrustFinalDefaultFields";
+
+    /**
+     * Determines whether to treat {@code final} fields with default values as constant.
+     */
+    private static final boolean TrustFinalDefaultFields = HotSpotJVMCIRuntime.getBooleanProperty(TrustFinalDefaultFieldsProperty, true);
 
     protected final HotSpotJVMCIRuntimeProvider runtime;
     protected final HotSpotMethodHandleAccessProvider methodHandleAccess;
     protected final HotSpotMemoryAccessProviderImpl memoryAccess;
 

@@ -237,11 +233,11 @@
 
     private static final String SystemClassName = "Ljava/lang/System;";
 
     /**
      * Determines if a static field is constant for the purpose of
-     * {@link #readConstantFieldValue(JavaField, JavaConstant)}.
+     * {@link #readConstantFieldValue(ResolvedJavaField, JavaConstant)}.
      */
     protected boolean isStaticFieldConstant(HotSpotResolvedJavaField staticField) {
         if (staticField.isFinal() || staticField.isStable()) {
             ResolvedJavaType holder = staticField.getDeclaringClass();
             if (holder.isInitialized() && !holder.getName().equals(SystemClassName)) {

@@ -253,18 +249,18 @@
 
     /**
      * Determines if a value read from a {@code final} instance field is considered constant. The
      * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is
      * not the {@link JavaConstant#isDefaultForKind default value} for its kind or if
-     * {@link Options#TrustFinalDefaultFields} is true.
+     * {@link #TrustFinalDefaultFields} is true.
      *
      * @param value a value read from a {@code final} instance field
      * @param receiverClass the {@link Object#getClass() class} of object from which the
      *            {@code value} was read
      */
     protected boolean isFinalInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass) {
-        return !value.isDefaultForKind() || Options.TrustFinalDefaultFields.getValue();
+        return !value.isDefaultForKind() || TrustFinalDefaultFields;
     }
 
     /**
      * Determines if a value read from a {@link Stable} instance field is considered constant. The
      * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is

@@ -276,17 +272,11 @@
      */
     protected boolean isStableInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass) {
         return !value.isDefaultForKind();
     }
 
-    /**
-     * {@inheritDoc}
-     * <p>
-     * The {@code value} field in {@link OptionValue} is considered constant if the type of
-     * {@code receiver} is (assignable to) {@link StableOptionValue}.
-     */
-    public JavaConstant readConstantFieldValue(JavaField field, JavaConstant receiver) {
+    public JavaConstant readConstantFieldValue(ResolvedJavaField field, JavaConstant receiver) {
         HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field;
 
         if (hotspotField.isStatic()) {
             if (isStaticFieldConstant(hotspotField)) {
                 JavaConstant value = readFieldValue(field, receiver);

@@ -317,34 +307,26 @@
                         JavaConstant value = readFieldValue(field, receiver);
                         if (isStableInstanceFieldValueConstant(value, object.getClass())) {
                             return value;
                         }
                     }
-                } else {
-                    Class<?> clazz = object.getClass();
-                    if (StableOptionValue.class.isAssignableFrom(clazz)) {
-                        if (hotspotField.isInObject(object) && hotspotField.getName().equals("value")) {
-                            StableOptionValue<?> option = (StableOptionValue<?>) object;
-                            return HotSpotObjectConstantImpl.forObject(option.getValue());
-                        }
-                    }
                 }
             }
         }
         return null;
     }
 
-    public JavaConstant readFieldValue(JavaField field, JavaConstant receiver) {
+    public JavaConstant readFieldValue(ResolvedJavaField field, JavaConstant receiver) {
         HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field;
         if (!hotspotField.isStable()) {
             return readNonStableFieldValue(field, receiver);
         } else {
             return readStableFieldValue(field, receiver, hotspotField.isDefaultStable());
         }
     }
 
-    private JavaConstant readNonStableFieldValue(JavaField field, JavaConstant receiver) {
+    private JavaConstant readNonStableFieldValue(ResolvedJavaField field, JavaConstant receiver) {
         HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field;
         if (hotspotField.isStatic()) {
             HotSpotResolvedJavaType holder = (HotSpotResolvedJavaType) hotspotField.getDeclaringClass();
             if (holder.isInitialized()) {
                 return memoryAccess.readUnsafeConstant(hotspotField.getJavaKind(), HotSpotObjectConstantImpl.forObject(holder.mirror()), hotspotField.offset());

@@ -355,11 +337,11 @@
             }
         }
         return null;
     }
 
-    public JavaConstant readStableFieldValue(JavaField field, JavaConstant receiver, boolean isDefaultStable) {
+    public JavaConstant readStableFieldValue(ResolvedJavaField field, JavaConstant receiver, boolean isDefaultStable) {
         JavaConstant fieldValue = readNonStableFieldValue(field, receiver);
         if (fieldValue.isNonNull()) {
             JavaType declaredType = field.getType();
             if (declaredType.getComponentType() != null) {
                 int stableDimension = getArrayDimension(declaredType);