Mercurial > hg > graal-jvmci-8
comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java @ 22758:a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 21 Dec 2015 15:53:56 +0100 |
parents | f4c4cc22a31c |
children | 4cf1946f59fc |
comparison
equal
deleted
inserted
replaced
22757:f4c4cc22a31c | 22758:a130b51efb07 |
---|---|
28 import java.lang.reflect.Array; | 28 import java.lang.reflect.Array; |
29 | 29 |
30 import jdk.vm.ci.meta.Constant; | 30 import jdk.vm.ci.meta.Constant; |
31 import jdk.vm.ci.meta.ConstantReflectionProvider; | 31 import jdk.vm.ci.meta.ConstantReflectionProvider; |
32 import jdk.vm.ci.meta.JavaConstant; | 32 import jdk.vm.ci.meta.JavaConstant; |
33 import jdk.vm.ci.meta.JavaField; | |
34 import jdk.vm.ci.meta.JavaKind; | 33 import jdk.vm.ci.meta.JavaKind; |
35 import jdk.vm.ci.meta.JavaType; | 34 import jdk.vm.ci.meta.JavaType; |
36 import jdk.vm.ci.meta.MemoryAccessProvider; | 35 import jdk.vm.ci.meta.MemoryAccessProvider; |
37 import jdk.vm.ci.meta.MethodHandleAccessProvider; | 36 import jdk.vm.ci.meta.MethodHandleAccessProvider; |
38 import jdk.vm.ci.meta.ResolvedJavaField; | 37 import jdk.vm.ci.meta.ResolvedJavaField; |
39 import jdk.vm.ci.meta.ResolvedJavaType; | 38 import jdk.vm.ci.meta.ResolvedJavaType; |
40 import jdk.vm.ci.options.Option; | |
41 import jdk.vm.ci.options.OptionType; | |
42 import jdk.vm.ci.options.OptionValue; | |
43 import jdk.vm.ci.options.StableOptionValue; | |
44 | 39 |
45 /** | 40 /** |
46 * HotSpot implementation of {@link ConstantReflectionProvider}. | 41 * HotSpot implementation of {@link ConstantReflectionProvider}. |
47 */ | 42 */ |
48 public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, HotSpotProxified { | 43 public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, HotSpotProxified { |
49 | 44 |
50 static class Options { | 45 private static final String TrustFinalDefaultFieldsProperty = "jvmci.TrustFinalDefaultFields"; |
51 //@formatter:off | 46 |
52 @Option(help = "Constant fold final fields with default values.", type = OptionType.Debug) | 47 /** |
53 public static final OptionValue<Boolean> TrustFinalDefaultFields = new OptionValue<>(true); | 48 * Determines whether to treat {@code final} fields with default values as constant. |
54 //@formatter:on | 49 */ |
55 } | 50 private static final boolean TrustFinalDefaultFields = HotSpotJVMCIRuntime.getBooleanOption(TrustFinalDefaultFieldsProperty, true); |
56 | 51 |
57 protected final HotSpotJVMCIRuntimeProvider runtime; | 52 protected final HotSpotJVMCIRuntimeProvider runtime; |
58 protected final HotSpotMethodHandleAccessProvider methodHandleAccess; | 53 protected final HotSpotMethodHandleAccessProvider methodHandleAccess; |
59 protected final HotSpotMemoryAccessProviderImpl memoryAccess; | 54 protected final HotSpotMemoryAccessProviderImpl memoryAccess; |
60 | 55 |
254 | 249 |
255 /** | 250 /** |
256 * Determines if a value read from a {@code final} instance field is considered constant. The | 251 * Determines if a value read from a {@code final} instance field is considered constant. The |
257 * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is | 252 * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is |
258 * not the {@link JavaConstant#isDefaultForKind default value} for its kind or if | 253 * not the {@link JavaConstant#isDefaultForKind default value} for its kind or if |
259 * {@link Options#TrustFinalDefaultFields} is true. | 254 * {@link #TrustFinalDefaultFields} is true. |
260 * | 255 * |
261 * @param value a value read from a {@code final} instance field | 256 * @param value a value read from a {@code final} instance field |
262 * @param receiverClass the {@link Object#getClass() class} of object from which the | 257 * @param receiverClass the {@link Object#getClass() class} of object from which the |
263 * {@code value} was read | 258 * {@code value} was read |
264 */ | 259 */ |
265 protected boolean isFinalInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass) { | 260 protected boolean isFinalInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass) { |
266 return !value.isDefaultForKind() || Options.TrustFinalDefaultFields.getValue(); | 261 return !value.isDefaultForKind() || TrustFinalDefaultFields; |
267 } | 262 } |
268 | 263 |
269 /** | 264 /** |
270 * Determines if a value read from a {@link Stable} instance field is considered constant. The | 265 * Determines if a value read from a {@link Stable} instance field is considered constant. The |
271 * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is | 266 * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is |
277 */ | 272 */ |
278 protected boolean isStableInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass) { | 273 protected boolean isStableInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass) { |
279 return !value.isDefaultForKind(); | 274 return !value.isDefaultForKind(); |
280 } | 275 } |
281 | 276 |
282 /** | |
283 * {@inheritDoc} | |
284 * <p> | |
285 * The {@code value} field in {@link OptionValue} is considered constant if the type of | |
286 * {@code receiver} is (assignable to) {@link StableOptionValue}. | |
287 */ | |
288 public JavaConstant readConstantFieldValue(ResolvedJavaField field, JavaConstant receiver) { | 277 public JavaConstant readConstantFieldValue(ResolvedJavaField field, JavaConstant receiver) { |
289 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; | 278 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; |
290 | 279 |
291 if (hotspotField.isStatic()) { | 280 if (hotspotField.isStatic()) { |
292 if (isStaticFieldConstant(hotspotField)) { | 281 if (isStaticFieldConstant(hotspotField)) { |
318 JavaConstant value = readFieldValue(field, receiver); | 307 JavaConstant value = readFieldValue(field, receiver); |
319 if (isStableInstanceFieldValueConstant(value, object.getClass())) { | 308 if (isStableInstanceFieldValueConstant(value, object.getClass())) { |
320 return value; | 309 return value; |
321 } | 310 } |
322 } | 311 } |
323 } else { | |
324 Class<?> clazz = object.getClass(); | |
325 if (StableOptionValue.class.isAssignableFrom(clazz)) { | |
326 if (hotspotField.isInObject(object) && hotspotField.getName().equals("value")) { | |
327 StableOptionValue<?> option = (StableOptionValue<?>) object; | |
328 return HotSpotObjectConstantImpl.forObject(option.getValue()); | |
329 } | |
330 } | |
331 } | 312 } |
332 } | 313 } |
333 } | 314 } |
334 return null; | 315 return null; |
335 } | 316 } |
341 } else { | 322 } else { |
342 return readStableFieldValue(field, receiver, hotspotField.isDefaultStable()); | 323 return readStableFieldValue(field, receiver, hotspotField.isDefaultStable()); |
343 } | 324 } |
344 } | 325 } |
345 | 326 |
346 private JavaConstant readNonStableFieldValue(JavaField field, JavaConstant receiver) { | 327 private JavaConstant readNonStableFieldValue(ResolvedJavaField field, JavaConstant receiver) { |
347 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; | 328 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; |
348 if (hotspotField.isStatic()) { | 329 if (hotspotField.isStatic()) { |
349 HotSpotResolvedJavaType holder = (HotSpotResolvedJavaType) hotspotField.getDeclaringClass(); | 330 HotSpotResolvedJavaType holder = (HotSpotResolvedJavaType) hotspotField.getDeclaringClass(); |
350 if (holder.isInitialized()) { | 331 if (holder.isInitialized()) { |
351 return memoryAccess.readUnsafeConstant(hotspotField.getJavaKind(), HotSpotObjectConstantImpl.forObject(holder.mirror()), hotspotField.offset()); | 332 return memoryAccess.readUnsafeConstant(hotspotField.getJavaKind(), HotSpotObjectConstantImpl.forObject(holder.mirror()), hotspotField.offset()); |