< prev index next >

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

Print this page




  36 import jdk.vm.ci.meta.ResolvedJavaType;
  37 
  38 /**
  39  * Represents a constant non-{@code null} object reference, within the compiler and across the
  40  * compiler/runtime interface.
  41  */
  42 final class HotSpotObjectConstantImpl implements HotSpotObjectConstant, HotSpotProxified {
  43 
  44     static JavaConstant forObject(Object object) {
  45         return forObject(object, false);
  46     }
  47 
  48     static JavaConstant forObject(Object object, boolean compressed) {
  49         if (object == null) {
  50             return compressed ? HotSpotCompressedNullConstant.COMPRESSED_NULL : JavaConstant.NULL_POINTER;
  51         } else {
  52             return new HotSpotObjectConstantImpl(object, compressed);
  53         }
  54     }
  55 
  56     static JavaConstant forStableArray(Object object, int stableDimension, boolean isDefaultStable) {
  57         if (object == null) {
  58             return JavaConstant.NULL_POINTER;
  59         } else {
  60             assert object.getClass().isArray();
  61             return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable);
  62         }
  63     }
  64 
  65     public static JavaConstant forBoxedValue(JavaKind kind, Object value) {
  66         if (kind == JavaKind.Object) {
  67             return HotSpotObjectConstantImpl.forObject(value);
  68         } else {
  69             return JavaConstant.forBoxedPrimitive(value);
  70         }
  71     }
  72 
  73     static Object asBoxedValue(Constant constant) {
  74         if (JavaConstant.isNull(constant)) {
  75             return null;
  76         } else if (constant instanceof HotSpotObjectConstantImpl) {
  77             return ((HotSpotObjectConstantImpl) constant).object;
  78         } else {
  79             return ((JavaConstant) constant).asBoxedPrimitive();
  80         }
  81     }
  82 
  83     private final Object object;
  84     private final boolean compressed;
  85     private final byte stableDimension;
  86     private final boolean isDefaultStable;
  87 
  88     private HotSpotObjectConstantImpl(Object object, boolean compressed, int stableDimension, boolean isDefaultStable) {
  89         this.object = object;
  90         this.compressed = compressed;
  91         this.stableDimension = (byte) stableDimension;
  92         this.isDefaultStable = isDefaultStable;
  93         assert object != null;
  94         assert stableDimension == 0 || (object != null && object.getClass().isArray());
  95         assert stableDimension >= 0 && stableDimension <= 255;
  96         assert !isDefaultStable || stableDimension > 0;
  97     }
  98 
  99     private HotSpotObjectConstantImpl(Object object, boolean compressed) {
 100         this(object, compressed, 0, false);
 101     }
 102 
 103     @Override
 104     public JavaKind getJavaKind() {
 105         return JavaKind.Object;
 106     }
 107 
 108     /**
 109      * Package-private accessor for the object represented by this constant.
 110      */
 111     Object object() {
 112         return object;
 113     }
 114 
 115     public boolean isCompressed() {
 116         return compressed;
 117     }
 118 
 119     public JavaConstant compress() {
 120         assert !compressed;
 121         return new HotSpotObjectConstantImpl(object, true, stableDimension, isDefaultStable);
 122     }
 123 
 124     public JavaConstant uncompress() {
 125         assert compressed;
 126         return new HotSpotObjectConstantImpl(object, false, stableDimension, isDefaultStable);
 127     }
 128 
 129     public HotSpotResolvedObjectType getType() {
 130         return fromObjectClass(object.getClass());
 131     }
 132 
 133     public JavaConstant getClassLoader() {
 134         if (object instanceof Class) {
 135             /*
 136              * This is an intrinsic for getClassLoader0, which occurs after any security checks. We
 137              * can't call that directly so just call getClassLoader.
 138              */
 139             return HotSpotObjectConstantImpl.forObject(((Class<?>) object).getClassLoader());
 140         }
 141         return null;
 142     }
 143 
 144     public int getIdentityHashCode() {
 145         return System.identityHashCode(object);
 146     }


 231     public float asFloat() {
 232         throw new IllegalArgumentException();
 233     }
 234 
 235     @Override
 236     public double asDouble() {
 237         throw new IllegalArgumentException();
 238     }
 239 
 240     @Override
 241     public int hashCode() {
 242         return System.identityHashCode(object);
 243     }
 244 
 245     @Override
 246     public boolean equals(Object o) {
 247         if (o == this) {
 248             return true;
 249         } else if (o instanceof HotSpotObjectConstantImpl) {
 250             HotSpotObjectConstantImpl other = (HotSpotObjectConstantImpl) o;
 251             return object == other.object && compressed == other.compressed && stableDimension == other.stableDimension && isDefaultStable == other.isDefaultStable;
 252         }
 253         return false;
 254     }
 255 
 256     @Override
 257     public String toValueString() {
 258         if (object instanceof String) {
 259             return "\"" + (String) object + "\"";
 260         } else {
 261             return JavaKind.Object.format(object);
 262         }
 263     }
 264 
 265     @Override
 266     public String toString() {
 267         return (compressed ? "NarrowOop" : getJavaKind().getJavaName()) + "[" + JavaKind.Object.format(object) + "]";
 268     }
 269 
 270     /**
 271      * Number of stable dimensions if this constant is a stable array.
 272      */
 273     public int getStableDimension() {
 274         return stableDimension & 0xff;
 275     }
 276 
 277     /**
 278      * Returns {@code true} if this is a stable array constant and its elements should be considered
 279      * as stable regardless of whether they are default values.
 280      */
 281     public boolean isDefaultStable() {
 282         return isDefaultStable;
 283     }
 284 }


  36 import jdk.vm.ci.meta.ResolvedJavaType;
  37 
  38 /**
  39  * Represents a constant non-{@code null} object reference, within the compiler and across the
  40  * compiler/runtime interface.
  41  */
  42 final class HotSpotObjectConstantImpl implements HotSpotObjectConstant, HotSpotProxified {
  43 
  44     static JavaConstant forObject(Object object) {
  45         return forObject(object, false);
  46     }
  47 
  48     static JavaConstant forObject(Object object, boolean compressed) {
  49         if (object == null) {
  50             return compressed ? HotSpotCompressedNullConstant.COMPRESSED_NULL : JavaConstant.NULL_POINTER;
  51         } else {
  52             return new HotSpotObjectConstantImpl(object, compressed);
  53         }
  54     }
  55 









  56     public static JavaConstant forBoxedValue(JavaKind kind, Object value) {
  57         if (kind == JavaKind.Object) {
  58             return HotSpotObjectConstantImpl.forObject(value);
  59         } else {
  60             return JavaConstant.forBoxedPrimitive(value);
  61         }
  62     }
  63 
  64     static Object asBoxedValue(Constant constant) {
  65         if (JavaConstant.isNull(constant)) {
  66             return null;
  67         } else if (constant instanceof HotSpotObjectConstantImpl) {
  68             return ((HotSpotObjectConstantImpl) constant).object;
  69         } else {
  70             return ((JavaConstant) constant).asBoxedPrimitive();
  71         }
  72     }
  73 
  74     private final Object object;
  75     private final boolean compressed;


  76 
  77     private HotSpotObjectConstantImpl(Object object, boolean compressed) {
  78         this.object = object;
  79         this.compressed = compressed;


  80         assert object != null;







  81     }
  82 
  83     @Override
  84     public JavaKind getJavaKind() {
  85         return JavaKind.Object;
  86     }
  87 
  88     /**
  89      * Package-private accessor for the object represented by this constant.
  90      */
  91     Object object() {
  92         return object;
  93     }
  94 
  95     public boolean isCompressed() {
  96         return compressed;
  97     }
  98 
  99     public JavaConstant compress() {
 100         assert !compressed;
 101         return new HotSpotObjectConstantImpl(object, true);
 102     }
 103 
 104     public JavaConstant uncompress() {
 105         assert compressed;
 106         return new HotSpotObjectConstantImpl(object, false);
 107     }
 108 
 109     public HotSpotResolvedObjectType getType() {
 110         return fromObjectClass(object.getClass());
 111     }
 112 
 113     public JavaConstant getClassLoader() {
 114         if (object instanceof Class) {
 115             /*
 116              * This is an intrinsic for getClassLoader0, which occurs after any security checks. We
 117              * can't call that directly so just call getClassLoader.
 118              */
 119             return HotSpotObjectConstantImpl.forObject(((Class<?>) object).getClassLoader());
 120         }
 121         return null;
 122     }
 123 
 124     public int getIdentityHashCode() {
 125         return System.identityHashCode(object);
 126     }


 211     public float asFloat() {
 212         throw new IllegalArgumentException();
 213     }
 214 
 215     @Override
 216     public double asDouble() {
 217         throw new IllegalArgumentException();
 218     }
 219 
 220     @Override
 221     public int hashCode() {
 222         return System.identityHashCode(object);
 223     }
 224 
 225     @Override
 226     public boolean equals(Object o) {
 227         if (o == this) {
 228             return true;
 229         } else if (o instanceof HotSpotObjectConstantImpl) {
 230             HotSpotObjectConstantImpl other = (HotSpotObjectConstantImpl) o;
 231             return object == other.object && compressed == other.compressed;
 232         }
 233         return false;
 234     }
 235 
 236     @Override
 237     public String toValueString() {
 238         if (object instanceof String) {
 239             return "\"" + (String) object + "\"";
 240         } else {
 241             return JavaKind.Object.format(object);
 242         }
 243     }
 244 
 245     @Override
 246     public String toString() {
 247         return (compressed ? "NarrowOop" : getJavaKind().getJavaName()) + "[" + JavaKind.Object.format(object) + "]";















 248     }
 249 }
< prev index next >