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