77 Type type = db.lookupType("InstanceKlass");
78 annotations = type.getAddressField("_annotations");
79 arrayKlasses = new MetadataField(type.getAddressField("_array_klasses"), 0);
80 methods = type.getAddressField("_methods");
81 defaultMethods = type.getAddressField("_default_methods");
82 methodOrdering = type.getAddressField("_method_ordering");
83 localInterfaces = type.getAddressField("_local_interfaces");
84 transitiveInterfaces = type.getAddressField("_transitive_interfaces");
85 fieldinfoStream = type.getAddressField("_fieldinfo_stream");
86 constants = new MetadataField(type.getAddressField("_constants"), 0);
87 sourceDebugExtension = type.getAddressField("_source_debug_extension");
88 innerClasses = type.getAddressField("_inner_classes");
89 nestMembers = type.getAddressField("_nest_members");
90 nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
91 staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0);
92 staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
93 nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
94 initState = new CIntField(type.getCIntegerField("_init_state"), 0);
95 itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0);
96 nestHostIndex = new CIntField(type.getCIntegerField("_nest_host_index"), 0);
97 if (VM.getVM().isJvmtiSupported()) {
98 breakpoints = type.getAddressField("_breakpoints");
99 }
100 headerSize = type.getSize();
101 accessFlags = new CIntField(type.getCIntegerField("_access_flags"), 0);
102
103 // read internal field flags constants
104 FIELD_FLAG_IS_INITIALIZED = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_initialized");
105 FIELD_FLAG_IS_INJECTED = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_injected");
106 FIELD_FLAG_IS_GENERIC = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_generic");
107 FIELD_FLAG_IS_STABLE = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_stable");
108 FIELD_FLAG_IS_CONTENDED = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_contended");
109
110
111 // read ClassState constants
112 CLASS_STATE_ALLOCATED = db.lookupIntConstant("InstanceKlass::allocated").intValue();
113 CLASS_STATE_LOADED = db.lookupIntConstant("InstanceKlass::loaded").intValue();
114 CLASS_STATE_LINKED = db.lookupIntConstant("InstanceKlass::linked").intValue();
115 CLASS_STATE_BEING_INITIALIZED = db.lookupIntConstant("InstanceKlass::being_initialized").intValue();
116 CLASS_STATE_FULLY_INITIALIZED = db.lookupIntConstant("InstanceKlass::fully_initialized").intValue();
145 private static AddressField annotations;
146 private static MetadataField arrayKlasses;
147 private static AddressField methods;
148 private static AddressField defaultMethods;
149 private static AddressField methodOrdering;
150 private static AddressField localInterfaces;
151 private static AddressField transitiveInterfaces;
152 private static AddressField fieldinfoStream;
153 private static MetadataField constants;
154 private static AddressField sourceDebugExtension;
155 private static AddressField innerClasses;
156 private static AddressField nestMembers;
157 private static CIntField nonstaticFieldSize;
158 private static CIntField staticFieldSize;
159 private static CIntField staticOopFieldCount;
160 private static CIntField nonstaticOopMapSize;
161 private static CIntField initState;
162 private static CIntField itableLen;
163 private static CIntField nestHostIndex;
164 private static CIntField accessFlags;
165 private static AddressField breakpoints;
166
167 // type safe enum for ClassState from instanceKlass.hpp
168 public static class ClassState {
169 public static final ClassState ALLOCATED = new ClassState("allocated");
170 public static final ClassState LOADED = new ClassState("loaded");
171 public static final ClassState LINKED = new ClassState("linked");
172 public static final ClassState BEING_INITIALIZED = new ClassState("beingInitialized");
173 public static final ClassState FULLY_INITIALIZED = new ClassState("fullyInitialized");
174 public static final ClassState INITIALIZATION_ERROR = new ClassState("initializationError");
175
176 private ClassState(String value) {
177 this.value = value;
178 }
179
180 public String toString() {
181 return value;
182 }
183
184 private String value;
235 result |= JVMDIClassStatus.VERIFIED | JVMDIClassStatus.PREPARED;
236 }
237
238 if (isInitialized()) {
239 if (Assert.ASSERTS_ENABLED) {
240 Assert.that(isLinked(), "Class status is not consistent");
241 }
242 result |= JVMDIClassStatus.INITIALIZED;
243 }
244
245 if (isInErrorState()) {
246 result |= JVMDIClassStatus.ERROR;
247 }
248 return result;
249 }
250
251 // Byteside of the header
252 private static long headerSize;
253
254 public long getObjectSize(Oop object) {
255 return getSizeHelper() * VM.getVM().getAddressSize();
256 }
257
258 public long getSize() { // in number of bytes
259 long wordLength = VM.getVM().getBytesPerWord();
260 long size = getHeaderSize() +
261 (getVtableLen() +
262 getItableLen() +
263 getNonstaticOopMapSize()) * wordLength;
264 if (isInterface()) {
265 size += wordLength;
266 }
267 return alignSize(size);
268 }
269
270 public static long getHeaderSize() { return headerSize; }
271
272 // Each InstanceKlass mirror instance will cache the Field[] array after it is decoded,
273 // but since there can be multiple InstanceKlass mirror instances per hotspot InstanceKlass,
274 // we also have a global cache that uses the Address of the hotspot InstanceKlass as the key.
275 private Field[] fields;
369 return javaFieldsCount;
370 }
371
372 public int getAllFieldsCount() {
373 if (allFieldsCount == -1) {
374 initFieldCounts();
375 }
376 return allFieldsCount;
377 }
378
379 public KlassArray getLocalInterfaces() { return new KlassArray(localInterfaces.getValue(getAddress())); }
380 public KlassArray getTransitiveInterfaces() { return new KlassArray(transitiveInterfaces.getValue(getAddress())); }
381 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
382 public Symbol getSourceFileName() { return getConstants().getSourceFileName(); }
383 public String getSourceDebugExtension(){ return CStringUtilities.getString(sourceDebugExtension.getValue(getAddress())); }
384 public long getNonstaticFieldSize() { return nonstaticFieldSize.getValue(this); }
385 public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
386 public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); }
387 public long getItableLen() { return itableLen.getValue(this); }
388 public short getNestHostIndex() { return (short) nestHostIndex.getValue(this); }
389 public long majorVersion() { return getConstants().majorVersion(); }
390 public long minorVersion() { return getConstants().minorVersion(); }
391 public Symbol getGenericSignature() { return getConstants().getGenericSignature(); }
392 // "size helper" == instance size in words
393 public long getSizeHelper() {
394 int lh = getLayoutHelper();
395 if (Assert.ASSERTS_ENABLED) {
396 Assert.that(lh > 0, "layout helper initialized for instance class");
397 }
398 return lh / VM.getVM().getAddressSize();
399 }
400 public Annotations getAnnotations() {
401 Address addr = annotations.getValue(getAddress());
402 return VMObjectFactory.newObject(Annotations.class, addr);
403 }
404
405 // same as enum InnerClassAttributeOffset in VM code.
406 private static class InnerClassAttributeOffset {
407 // from JVM spec. "InnerClasses" attribute
408 public static int innerClassInnerClassInfoOffset;
|
77 Type type = db.lookupType("InstanceKlass");
78 annotations = type.getAddressField("_annotations");
79 arrayKlasses = new MetadataField(type.getAddressField("_array_klasses"), 0);
80 methods = type.getAddressField("_methods");
81 defaultMethods = type.getAddressField("_default_methods");
82 methodOrdering = type.getAddressField("_method_ordering");
83 localInterfaces = type.getAddressField("_local_interfaces");
84 transitiveInterfaces = type.getAddressField("_transitive_interfaces");
85 fieldinfoStream = type.getAddressField("_fieldinfo_stream");
86 constants = new MetadataField(type.getAddressField("_constants"), 0);
87 sourceDebugExtension = type.getAddressField("_source_debug_extension");
88 innerClasses = type.getAddressField("_inner_classes");
89 nestMembers = type.getAddressField("_nest_members");
90 nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
91 staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0);
92 staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
93 nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
94 initState = new CIntField(type.getCIntegerField("_init_state"), 0);
95 itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0);
96 nestHostIndex = new CIntField(type.getCIntegerField("_nest_host_index"), 0);
97 hashOffset = new CIntField(type.getCIntegerField("_hash_offset"), 0);
98 if (VM.getVM().isJvmtiSupported()) {
99 breakpoints = type.getAddressField("_breakpoints");
100 }
101 headerSize = type.getSize();
102 accessFlags = new CIntField(type.getCIntegerField("_access_flags"), 0);
103
104 // read internal field flags constants
105 FIELD_FLAG_IS_INITIALIZED = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_initialized");
106 FIELD_FLAG_IS_INJECTED = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_injected");
107 FIELD_FLAG_IS_GENERIC = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_generic");
108 FIELD_FLAG_IS_STABLE = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_stable");
109 FIELD_FLAG_IS_CONTENDED = db.lookupIntConstant("FieldInfo::FieldFlags::_ff_contended");
110
111
112 // read ClassState constants
113 CLASS_STATE_ALLOCATED = db.lookupIntConstant("InstanceKlass::allocated").intValue();
114 CLASS_STATE_LOADED = db.lookupIntConstant("InstanceKlass::loaded").intValue();
115 CLASS_STATE_LINKED = db.lookupIntConstant("InstanceKlass::linked").intValue();
116 CLASS_STATE_BEING_INITIALIZED = db.lookupIntConstant("InstanceKlass::being_initialized").intValue();
117 CLASS_STATE_FULLY_INITIALIZED = db.lookupIntConstant("InstanceKlass::fully_initialized").intValue();
146 private static AddressField annotations;
147 private static MetadataField arrayKlasses;
148 private static AddressField methods;
149 private static AddressField defaultMethods;
150 private static AddressField methodOrdering;
151 private static AddressField localInterfaces;
152 private static AddressField transitiveInterfaces;
153 private static AddressField fieldinfoStream;
154 private static MetadataField constants;
155 private static AddressField sourceDebugExtension;
156 private static AddressField innerClasses;
157 private static AddressField nestMembers;
158 private static CIntField nonstaticFieldSize;
159 private static CIntField staticFieldSize;
160 private static CIntField staticOopFieldCount;
161 private static CIntField nonstaticOopMapSize;
162 private static CIntField initState;
163 private static CIntField itableLen;
164 private static CIntField nestHostIndex;
165 private static CIntField accessFlags;
166 private static CIntField hashOffset;
167 private static AddressField breakpoints;
168
169 // type safe enum for ClassState from instanceKlass.hpp
170 public static class ClassState {
171 public static final ClassState ALLOCATED = new ClassState("allocated");
172 public static final ClassState LOADED = new ClassState("loaded");
173 public static final ClassState LINKED = new ClassState("linked");
174 public static final ClassState BEING_INITIALIZED = new ClassState("beingInitialized");
175 public static final ClassState FULLY_INITIALIZED = new ClassState("fullyInitialized");
176 public static final ClassState INITIALIZATION_ERROR = new ClassState("initializationError");
177
178 private ClassState(String value) {
179 this.value = value;
180 }
181
182 public String toString() {
183 return value;
184 }
185
186 private String value;
237 result |= JVMDIClassStatus.VERIFIED | JVMDIClassStatus.PREPARED;
238 }
239
240 if (isInitialized()) {
241 if (Assert.ASSERTS_ENABLED) {
242 Assert.that(isLinked(), "Class status is not consistent");
243 }
244 result |= JVMDIClassStatus.INITIALIZED;
245 }
246
247 if (isInErrorState()) {
248 result |= JVMDIClassStatus.ERROR;
249 }
250 return result;
251 }
252
253 // Byteside of the header
254 private static long headerSize;
255
256 public long getObjectSize(Oop object) {
257 long baseSize = getSizeHelper() * VM.getVM().getAddressSize();
258 if (VM.getVM().isCompactObjectHeadersEnabled()) {
259 Mark mark = object.getMark();
260 if (mark.isExpanded() && (getHashOffset() + 4 /* size of hash field */) > baseSize) {
261 // Needs extra word for identity hash-code.
262 return baseSize + VM.getVM().getBytesPerWord();
263 }
264 }
265 return baseSize;
266 }
267
268 public long getSize() { // in number of bytes
269 long wordLength = VM.getVM().getBytesPerWord();
270 long size = getHeaderSize() +
271 (getVtableLen() +
272 getItableLen() +
273 getNonstaticOopMapSize()) * wordLength;
274 if (isInterface()) {
275 size += wordLength;
276 }
277 return alignSize(size);
278 }
279
280 public static long getHeaderSize() { return headerSize; }
281
282 // Each InstanceKlass mirror instance will cache the Field[] array after it is decoded,
283 // but since there can be multiple InstanceKlass mirror instances per hotspot InstanceKlass,
284 // we also have a global cache that uses the Address of the hotspot InstanceKlass as the key.
285 private Field[] fields;
379 return javaFieldsCount;
380 }
381
382 public int getAllFieldsCount() {
383 if (allFieldsCount == -1) {
384 initFieldCounts();
385 }
386 return allFieldsCount;
387 }
388
389 public KlassArray getLocalInterfaces() { return new KlassArray(localInterfaces.getValue(getAddress())); }
390 public KlassArray getTransitiveInterfaces() { return new KlassArray(transitiveInterfaces.getValue(getAddress())); }
391 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
392 public Symbol getSourceFileName() { return getConstants().getSourceFileName(); }
393 public String getSourceDebugExtension(){ return CStringUtilities.getString(sourceDebugExtension.getValue(getAddress())); }
394 public long getNonstaticFieldSize() { return nonstaticFieldSize.getValue(this); }
395 public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
396 public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); }
397 public long getItableLen() { return itableLen.getValue(this); }
398 public short getNestHostIndex() { return (short) nestHostIndex.getValue(this); }
399 public long getHashOffset() { return hashOffset.getValue(this); }
400 public long majorVersion() { return getConstants().majorVersion(); }
401 public long minorVersion() { return getConstants().minorVersion(); }
402 public Symbol getGenericSignature() { return getConstants().getGenericSignature(); }
403 // "size helper" == instance size in words
404 public long getSizeHelper() {
405 int lh = getLayoutHelper();
406 if (Assert.ASSERTS_ENABLED) {
407 Assert.that(lh > 0, "layout helper initialized for instance class");
408 }
409 return lh / VM.getVM().getAddressSize();
410 }
411 public Annotations getAnnotations() {
412 Address addr = annotations.getValue(getAddress());
413 return VMObjectFactory.newObject(Annotations.class, addr);
414 }
415
416 // same as enum InnerClassAttributeOffset in VM code.
417 private static class InnerClassAttributeOffset {
418 // from JVM spec. "InnerClasses" attribute
419 public static int innerClassInnerClassInfoOffset;
|