8146157: JVMCI must not fold accesses to @Stable fields if -XX:-FoldStableValues
Reviewed-by: twisti
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java Mon Dec 28 10:32:20 2015 +0100
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java Sat Dec 26 16:59:26 2015 +0100
@@ -242,7 +242,7 @@
* {@link #readConstantFieldValue(JavaField, JavaConstant)}.
*/
protected boolean isStaticFieldConstant(HotSpotResolvedJavaField staticField) {
- if (staticField.isFinal() || staticField.isStable()) {
+ if (staticField.isFinal() || (staticField.isStable() && runtime.getConfig().foldStableValues)) {
ResolvedJavaType holder = staticField.getDeclaringClass();
if (holder.isInitialized() && !holder.getName().equals(SystemClassName)) {
return true;
@@ -312,7 +312,7 @@
return value;
}
}
- } else if (hotspotField.isStable()) {
+ } else if (hotspotField.isStable() && runtime.getConfig().foldStableValues) {
if (hotspotField.isInObject(object)) {
JavaConstant value = readFieldValue(field, receiver);
if (isStableInstanceFieldValueConstant(value, object.getClass())) {
@@ -337,8 +337,10 @@
HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field;
if (!hotspotField.isStable()) {
return readNonStableFieldValue(field, receiver);
+ } else if (runtime.getConfig().foldStableValues) {
+ return readStableFieldValue(field, receiver, hotspotField.isDefaultStable());
} else {
- return readStableFieldValue(field, receiver, hotspotField.isDefaultStable());
+ return null;
}
}
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaField.java Mon Dec 28 10:32:20 2015 +0100
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaField.java Sat Dec 26 16:59:26 2015 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,17 +40,14 @@
int offset();
/**
- * Checks if this field has the {@link Stable} annotation.
- *
- * @return true if field has {@link Stable} annotation, false otherwise
+ * Determines if this field should be treated as a constant.
*/
boolean isStable();
/**
- * If this field is stable, checks if default values (0, null, etc.) should be considered stable
- * as well.
- *
- * @return true if default values should be considered stable, false otherwise
+ * Determines if this field should be considered constant if it has the default value for its
+ * type (e.g, 0, null, etc.). The result of this method is undefined if this field is not
+ * {@linkplain #isStable() stable}.
*/
boolean isDefaultStable();
}
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java Mon Dec 28 10:32:20 2015 +0100
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java Sat Dec 26 16:59:26 2015 +0100
@@ -853,6 +853,7 @@
@HotSpotVMFlag(name = "JVMCIUseFastLocking") @Stable public boolean useFastLocking;
@HotSpotVMFlag(name = "ForceUnreachable") @Stable public boolean forceUnreachable;
@HotSpotVMFlag(name = "CodeCacheSegmentSize") @Stable public int codeSegmentSize;
+ @HotSpotVMFlag(name = "FoldStableValues") @Stable public boolean foldStableValues;
@HotSpotVMFlag(name = "UseTLAB") @Stable public boolean useTLAB;
@HotSpotVMFlag(name = "UseBiasedLocking") @Stable public boolean useBiasedLocking;
@@ -1683,6 +1684,7 @@
@HotSpotVMConstant(name = "ArrayData::array_len_off_set") @Stable public int arrayDataArrayLenOffset;
@HotSpotVMConstant(name = "ArrayData::array_start_off_set") @Stable public int arrayDataArrayStartOffset;
@HotSpotVMConstant(name = "MultiBranchData::per_case_cell_count") @Stable public int multiBranchDataPerCaseCellCount;
+
// Checkstyle: resume
private boolean check() {