comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java @ 23391:dd9f3badc978

Remove implicit stable field handling (JDK-8156552).
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 12 May 2016 14:24:15 +0200
parents c8cdf8d81475
children b3a816d3b844
comparison
equal deleted inserted replaced
23390:19855d029fc0 23391:dd9f3badc978
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package jdk.vm.ci.hotspot; 23 package jdk.vm.ci.hotspot;
24 24
25 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
26 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; 25 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config;
27 26
28 import java.lang.annotation.Annotation; 27 import java.lang.annotation.Annotation;
29 import java.lang.reflect.Field; 28 import java.lang.reflect.Field;
30 29
31 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
32 import jdk.vm.ci.meta.JavaType; 30 import jdk.vm.ci.meta.JavaType;
33 import jdk.vm.ci.meta.MetaAccessProvider;
34 import jdk.vm.ci.meta.ModifiersProvider; 31 import jdk.vm.ci.meta.ModifiersProvider;
35 import jdk.vm.ci.meta.ResolvedJavaField;
36 import jdk.vm.ci.meta.ResolvedJavaType; 32 import jdk.vm.ci.meta.ResolvedJavaType;
37 33
38 /** 34 /**
39 * Represents a field in a HotSpot type. 35 * Represents a field in a HotSpot type.
40 */ 36 */
149 * Checks if this field has the {@link Stable} annotation. 145 * Checks if this field has the {@link Stable} annotation.
150 * 146 *
151 * @return true if field has {@link Stable} annotation, false otherwise 147 * @return true if field has {@link Stable} annotation, false otherwise
152 */ 148 */
153 public boolean isStable() { 149 public boolean isStable() {
154 if ((config().jvmAccFieldStable & modifiers) != 0) { 150 return (config().jvmAccFieldStable & modifiers) != 0;
155 return true;
156 }
157 assert getAnnotation(Stable.class) == null;
158 if (Option.ImplicitStableValues.getBoolean() && isImplicitStableField()) {
159 return true;
160 }
161 return false;
162 } 151 }
163 152
164 @Override 153 @Override
165 public Annotation[] getAnnotations() { 154 public Annotation[] getAnnotations() {
166 Field javaField = toJava(); 155 Field javaField = toJava();
202 return toJavaCache = holder.mirror().getDeclaredField(name); 191 return toJavaCache = holder.mirror().getDeclaredField(name);
203 } catch (NoSuchFieldException | NoClassDefFoundError e) { 192 } catch (NoSuchFieldException | NoClassDefFoundError e) {
204 return null; 193 return null;
205 } 194 }
206 } 195 }
207
208 private boolean isArray() {
209 JavaType fieldType = getType();
210 return fieldType instanceof ResolvedJavaType && ((ResolvedJavaType) fieldType).isArray();
211 }
212
213 private boolean isImplicitStableField() {
214 if (isSyntheticEnumSwitchMap()) {
215 return true;
216 }
217 if (isWellKnownImplicitStableField()) {
218 return true;
219 }
220 return false;
221 }
222
223 public boolean isDefaultStable() {
224 assert this.isStable();
225 if (isSyntheticEnumSwitchMap()) {
226 return true;
227 }
228 return false;
229 }
230
231 private boolean isSyntheticEnumSwitchMap() {
232 if (isSynthetic() && isStatic() && isArray()) {
233 if (isFinal() && name.equals("$VALUES") || name.equals("ENUM$VALUES")) {
234 // generated int[] field for EnumClass::values()
235 return true;
236 } else if (name.startsWith("$SwitchMap$") || name.startsWith("$SWITCH_TABLE$")) {
237 // javac and ecj generate a static field in an inner class for a switch on an enum
238 // named $SwitchMap$p$k$g$EnumClass and $SWITCH_TABLE$p$k$g$EnumClass, respectively
239 return true;
240 }
241 }
242 return false;
243 }
244
245 private boolean isWellKnownImplicitStableField() {
246 return WellKnownImplicitStableField.test(this);
247 }
248
249 static class WellKnownImplicitStableField {
250 /**
251 * @return {@code true} if the field is a well-known stable field.
252 */
253 public static boolean test(HotSpotResolvedJavaField field) {
254 return field.equals(STRING_VALUE_FIELD);
255 }
256
257 private static final ResolvedJavaField STRING_VALUE_FIELD;
258
259 static {
260 try {
261 MetaAccessProvider metaAccess = runtime().getHostJVMCIBackend().getMetaAccess();
262 STRING_VALUE_FIELD = metaAccess.lookupJavaField(String.class.getDeclaredField("value"));
263 } catch (SecurityException | NoSuchFieldException e) {
264 throw new InternalError(e);
265 }
266 }
267 }
268 } 196 }