15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package jdk.vm.ci.hotspot; 24 25 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; 26 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; 27 28 import java.lang.annotation.Annotation; 29 import java.lang.reflect.Field; 30 31 import jdk.internal.vm.annotation.Stable; 32 import jdk.vm.ci.common.JVMCIError; 33 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; 34 import jdk.vm.ci.meta.JavaType; 35 import jdk.vm.ci.meta.LocationIdentity; 36 import jdk.vm.ci.meta.MetaAccessProvider; 37 import jdk.vm.ci.meta.ModifiersProvider; 38 import jdk.vm.ci.meta.ResolvedJavaField; 39 import jdk.vm.ci.meta.ResolvedJavaType; 40 41 /** 42 * Represents a field in a HotSpot type. 43 */ 44 class HotSpotResolvedJavaFieldImpl implements HotSpotResolvedJavaField, HotSpotProxified { 45 46 private final HotSpotResolvedObjectTypeImpl holder; 47 private final String name; 48 private JavaType type; 49 private final int offset; 50 51 /** 52 * This value contains all flags as stored in the VM including internal ones. 53 */ 54 private final int modifiers; 55 private final LocationIdentity locationIdentity = new FieldLocationIdentity(this); 56 57 public static class FieldLocationIdentity extends LocationIdentity { 58 HotSpotResolvedJavaField inner; 59 60 FieldLocationIdentity(HotSpotResolvedJavaFieldImpl inner) { 61 this.inner = inner; 62 } 63 64 @Override 65 public boolean isImmutable() { 66 return false; 67 } 68 69 @Override 70 public boolean equals(Object obj) { 71 if (this == obj) { 72 return true; 73 } 74 if (obj instanceof FieldLocationIdentity) { 75 FieldLocationIdentity fieldLocationIdentity = (FieldLocationIdentity) obj; 76 return inner.equals(fieldLocationIdentity.inner); 77 78 } 79 return false; 80 } 81 82 @Override 83 public int hashCode() { 84 return inner.hashCode(); 85 } 86 87 @Override 88 public String toString() { 89 return inner.getName(); 90 } 91 } 92 93 HotSpotResolvedJavaFieldImpl(HotSpotResolvedObjectTypeImpl holder, String name, JavaType type, long offset, int modifiers) { 94 this.holder = holder; 95 this.name = name; 96 this.type = type; 97 assert offset != -1; 98 assert offset == (int) offset : "offset larger than int"; 99 this.offset = (int) offset; 100 this.modifiers = modifiers; 101 } 102 103 @Override 104 public boolean equals(Object obj) { 105 if (this == obj) { 106 return true; 107 } 108 if (obj instanceof HotSpotResolvedJavaField) { 109 HotSpotResolvedJavaFieldImpl that = (HotSpotResolvedJavaFieldImpl) obj; 110 if (that.offset != this.offset || that.isStatic() != this.isStatic()) { 111 return false; 287 } 288 289 static class WellKnownImplicitStableField { 290 /** 291 * @return {@code true} if the field is a well-known stable field. 292 */ 293 public static boolean test(HotSpotResolvedJavaField field) { 294 return field.equals(STRING_VALUE_FIELD); 295 } 296 297 private static final ResolvedJavaField STRING_VALUE_FIELD; 298 299 static { 300 try { 301 MetaAccessProvider metaAccess = runtime().getHostJVMCIBackend().getMetaAccess(); 302 STRING_VALUE_FIELD = metaAccess.lookupJavaField(String.class.getDeclaredField("value")); 303 } catch (SecurityException | NoSuchFieldException e) { 304 throw new JVMCIError(e); 305 } 306 } 307 } 308 309 public LocationIdentity getLocationIdentity() { 310 return locationIdentity; 311 } 312 } | 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package jdk.vm.ci.hotspot; 24 25 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; 26 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; 27 28 import java.lang.annotation.Annotation; 29 import java.lang.reflect.Field; 30 31 import jdk.internal.vm.annotation.Stable; 32 import jdk.vm.ci.common.JVMCIError; 33 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; 34 import jdk.vm.ci.meta.JavaType; 35 import jdk.vm.ci.meta.MetaAccessProvider; 36 import jdk.vm.ci.meta.ModifiersProvider; 37 import jdk.vm.ci.meta.ResolvedJavaField; 38 import jdk.vm.ci.meta.ResolvedJavaType; 39 40 /** 41 * Represents a field in a HotSpot type. 42 */ 43 class HotSpotResolvedJavaFieldImpl implements HotSpotResolvedJavaField, HotSpotProxified { 44 45 private final HotSpotResolvedObjectTypeImpl holder; 46 private final String name; 47 private JavaType type; 48 private final int offset; 49 50 /** 51 * This value contains all flags as stored in the VM including internal ones. 52 */ 53 private final int modifiers; 54 55 HotSpotResolvedJavaFieldImpl(HotSpotResolvedObjectTypeImpl holder, String name, JavaType type, long offset, int modifiers) { 56 this.holder = holder; 57 this.name = name; 58 this.type = type; 59 assert offset != -1; 60 assert offset == (int) offset : "offset larger than int"; 61 this.offset = (int) offset; 62 this.modifiers = modifiers; 63 } 64 65 @Override 66 public boolean equals(Object obj) { 67 if (this == obj) { 68 return true; 69 } 70 if (obj instanceof HotSpotResolvedJavaField) { 71 HotSpotResolvedJavaFieldImpl that = (HotSpotResolvedJavaFieldImpl) obj; 72 if (that.offset != this.offset || that.isStatic() != this.isStatic()) { 73 return false; 249 } 250 251 static class WellKnownImplicitStableField { 252 /** 253 * @return {@code true} if the field is a well-known stable field. 254 */ 255 public static boolean test(HotSpotResolvedJavaField field) { 256 return field.equals(STRING_VALUE_FIELD); 257 } 258 259 private static final ResolvedJavaField STRING_VALUE_FIELD; 260 261 static { 262 try { 263 MetaAccessProvider metaAccess = runtime().getHostJVMCIBackend().getMetaAccess(); 264 STRING_VALUE_FIELD = metaAccess.lookupJavaField(String.class.getDeclaredField("value")); 265 } catch (SecurityException | NoSuchFieldException e) { 266 throw new JVMCIError(e); 267 } 268 } 269 } 270 } |