1 /*
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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 *
67 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
68 Type type = db.lookupType("InstanceKlass");
69 arrayKlasses = new MetadataField(type.getAddressField("_array_klasses"), 0);
70 methods = type.getAddressField("_methods");
71 methodOrdering = type.getAddressField("_method_ordering");
72 localInterfaces = type.getAddressField("_local_interfaces");
73 transitiveInterfaces = type.getAddressField("_transitive_interfaces");
74 fields = type.getAddressField("_fields");
75 javaFieldsCount = new CIntField(type.getCIntegerField("_java_fields_count"), 0);
76 constants = new MetadataField(type.getAddressField("_constants"), 0);
77 classLoaderData = type.getAddressField("_class_loader_data");
78 sourceDebugExtension = type.getAddressField("_source_debug_extension");
79 innerClasses = type.getAddressField("_inner_classes");
80 sourceFileNameIndex = new CIntField(type.getCIntegerField("_source_file_name_index"), 0);
81 nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
82 staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0);
83 staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
84 nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
85 isMarkedDependent = new CIntField(type.getCIntegerField("_is_marked_dependent"), 0);
86 initState = new CIntField(type.getCIntegerField("_init_state"), 0);
87 vtableLen = new CIntField(type.getCIntegerField("_vtable_len"), 0);
88 itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0);
89 breakpoints = type.getAddressField("_breakpoints");
90 genericSignatureIndex = new CIntField(type.getCIntegerField("_generic_signature_index"), 0);
91 majorVersion = new CIntField(type.getCIntegerField("_major_version"), 0);
92 minorVersion = new CIntField(type.getCIntegerField("_minor_version"), 0);
93 headerSize = Oop.alignObjectOffset(type.getSize());
94
95 // read field offset constants
96 ACCESS_FLAGS_OFFSET = db.lookupIntConstant("FieldInfo::access_flags_offset").intValue();
97 NAME_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::name_index_offset").intValue();
98 SIGNATURE_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::signature_index_offset").intValue();
99 INITVAL_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::initval_index_offset").intValue();
100 LOW_OFFSET = db.lookupIntConstant("FieldInfo::low_packed_offset").intValue();
101 HIGH_OFFSET = db.lookupIntConstant("FieldInfo::high_packed_offset").intValue();
102 FIELD_SLOTS = db.lookupIntConstant("FieldInfo::field_slots").intValue();
103 FIELDINFO_TAG_SIZE = db.lookupIntConstant("FIELDINFO_TAG_SIZE").shortValue();
104 FIELDINFO_TAG_MASK = db.lookupIntConstant("FIELDINFO_TAG_MASK").shortValue();
105 FIELDINFO_TAG_OFFSET = db.lookupIntConstant("FIELDINFO_TAG_OFFSET").shortValue();
106
107 // read ClassState constants
126 }
127
128 private static MetadataField arrayKlasses;
129 private static AddressField methods;
130 private static AddressField methodOrdering;
131 private static AddressField localInterfaces;
132 private static AddressField transitiveInterfaces;
133 private static AddressField fields;
134 private static CIntField javaFieldsCount;
135 private static MetadataField constants;
136 private static AddressField classLoaderData;
137 private static AddressField sourceDebugExtension;
138 private static AddressField innerClasses;
139 private static CIntField sourceFileNameIndex;
140 private static CIntField nonstaticFieldSize;
141 private static CIntField staticFieldSize;
142 private static CIntField staticOopFieldCount;
143 private static CIntField nonstaticOopMapSize;
144 private static CIntField isMarkedDependent;
145 private static CIntField initState;
146 private static CIntField vtableLen;
147 private static CIntField itableLen;
148 private static AddressField breakpoints;
149 private static CIntField genericSignatureIndex;
150 private static CIntField majorVersion;
151 private static CIntField minorVersion;
152
153 // type safe enum for ClassState from instanceKlass.hpp
154 public static class ClassState {
155 public static final ClassState ALLOCATED = new ClassState("allocated");
156 public static final ClassState LOADED = new ClassState("loaded");
157 public static final ClassState LINKED = new ClassState("linked");
158 public static final ClassState BEING_INITIALIZED = new ClassState("beingInitialized");
159 public static final ClassState FULLY_INITIALIZED = new ClassState("fullyInitialized");
160 public static final ClassState INITIALIZATION_ERROR = new ClassState("initializationError");
161
162 private ClassState(String value) {
163 this.value = value;
164 }
165
166 public String toString() {
335 int len = getFields().length();
336 int allFieldsCount = 0;
337 for (; allFieldsCount*FIELD_SLOTS < len; allFieldsCount++) {
338 short flags = getFieldAccessFlags(allFieldsCount);
339 AccessFlags access = new AccessFlags(flags);
340 if (access.fieldHasGenericSignature()) {
341 len --;
342 }
343 }
344 return allFieldsCount;
345 }
346 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
347 public ClassLoaderData getClassLoaderData() { return ClassLoaderData.instantiateWrapperFor(classLoaderData.getValue(getAddress())); }
348 public Oop getClassLoader() { return getClassLoaderData().getClassLoader(); }
349 public Symbol getSourceFileName() { return getConstants().getSymbolAt(sourceFileNameIndex.getValue(this)); }
350 public String getSourceDebugExtension(){ return CStringUtilities.getString(sourceDebugExtension.getValue(getAddress())); }
351 public long getNonstaticFieldSize() { return nonstaticFieldSize.getValue(this); }
352 public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
353 public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); }
354 public boolean getIsMarkedDependent() { return isMarkedDependent.getValue(this) != 0; }
355 public long getVtableLen() { return vtableLen.getValue(this); }
356 public long getItableLen() { return itableLen.getValue(this); }
357 public long majorVersion() { return majorVersion.getValue(this); }
358 public long minorVersion() { return minorVersion.getValue(this); }
359 public Symbol getGenericSignature() {
360 long index = genericSignatureIndex.getValue(this);
361 if (index != 0) {
362 return getConstants().getSymbolAt(index);
363 } else {
364 return null;
365 }
366 }
367
368 // "size helper" == instance size in words
369 public long getSizeHelper() {
370 int lh = getLayoutHelper();
371 if (Assert.ASSERTS_ENABLED) {
372 Assert.that(lh > 0, "layout helper initialized for instance class");
373 }
374 return lh / VM.getVM().getAddressSize();
375 }
531 return super.computeSubtypeOf(k);
532 }
533 }
534
535 public void printValueOn(PrintStream tty) {
536 tty.print("InstanceKlass for " + getName().asString());
537 }
538
539 public void iterateFields(MetadataVisitor visitor) {
540 super.iterateFields(visitor);
541 visitor.doMetadata(arrayKlasses, true);
542 // visitor.doOop(methods, true);
543 // visitor.doOop(localInterfaces, true);
544 // visitor.doOop(transitiveInterfaces, true);
545 visitor.doCInt(nonstaticFieldSize, true);
546 visitor.doCInt(staticFieldSize, true);
547 visitor.doCInt(staticOopFieldCount, true);
548 visitor.doCInt(nonstaticOopMapSize, true);
549 visitor.doCInt(isMarkedDependent, true);
550 visitor.doCInt(initState, true);
551 visitor.doCInt(vtableLen, true);
552 visitor.doCInt(itableLen, true);
553 }
554
555 /*
556 * Visit the static fields of this InstanceKlass with the obj of
557 * the visitor set to the oop holding the fields, which is
558 * currently the java mirror.
559 */
560 public void iterateStaticFields(OopVisitor visitor) {
561 visitor.setObj(getJavaMirror());
562 visitor.prologue();
563 iterateStaticFieldsInternal(visitor);
564 visitor.epilogue();
565
566 }
567
568 void iterateStaticFieldsInternal(OopVisitor visitor) {
569 int length = getJavaFieldsCount();
570 for (int index = 0; index < length; index++) {
571 short accessFlags = getFieldAccessFlags(index);
|
1 /*
2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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 *
67 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
68 Type type = db.lookupType("InstanceKlass");
69 arrayKlasses = new MetadataField(type.getAddressField("_array_klasses"), 0);
70 methods = type.getAddressField("_methods");
71 methodOrdering = type.getAddressField("_method_ordering");
72 localInterfaces = type.getAddressField("_local_interfaces");
73 transitiveInterfaces = type.getAddressField("_transitive_interfaces");
74 fields = type.getAddressField("_fields");
75 javaFieldsCount = new CIntField(type.getCIntegerField("_java_fields_count"), 0);
76 constants = new MetadataField(type.getAddressField("_constants"), 0);
77 classLoaderData = type.getAddressField("_class_loader_data");
78 sourceDebugExtension = type.getAddressField("_source_debug_extension");
79 innerClasses = type.getAddressField("_inner_classes");
80 sourceFileNameIndex = new CIntField(type.getCIntegerField("_source_file_name_index"), 0);
81 nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
82 staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0);
83 staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
84 nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
85 isMarkedDependent = new CIntField(type.getCIntegerField("_is_marked_dependent"), 0);
86 initState = new CIntField(type.getCIntegerField("_init_state"), 0);
87 itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0);
88 breakpoints = type.getAddressField("_breakpoints");
89 genericSignatureIndex = new CIntField(type.getCIntegerField("_generic_signature_index"), 0);
90 majorVersion = new CIntField(type.getCIntegerField("_major_version"), 0);
91 minorVersion = new CIntField(type.getCIntegerField("_minor_version"), 0);
92 headerSize = Oop.alignObjectOffset(type.getSize());
93
94 // read field offset constants
95 ACCESS_FLAGS_OFFSET = db.lookupIntConstant("FieldInfo::access_flags_offset").intValue();
96 NAME_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::name_index_offset").intValue();
97 SIGNATURE_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::signature_index_offset").intValue();
98 INITVAL_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::initval_index_offset").intValue();
99 LOW_OFFSET = db.lookupIntConstant("FieldInfo::low_packed_offset").intValue();
100 HIGH_OFFSET = db.lookupIntConstant("FieldInfo::high_packed_offset").intValue();
101 FIELD_SLOTS = db.lookupIntConstant("FieldInfo::field_slots").intValue();
102 FIELDINFO_TAG_SIZE = db.lookupIntConstant("FIELDINFO_TAG_SIZE").shortValue();
103 FIELDINFO_TAG_MASK = db.lookupIntConstant("FIELDINFO_TAG_MASK").shortValue();
104 FIELDINFO_TAG_OFFSET = db.lookupIntConstant("FIELDINFO_TAG_OFFSET").shortValue();
105
106 // read ClassState constants
125 }
126
127 private static MetadataField arrayKlasses;
128 private static AddressField methods;
129 private static AddressField methodOrdering;
130 private static AddressField localInterfaces;
131 private static AddressField transitiveInterfaces;
132 private static AddressField fields;
133 private static CIntField javaFieldsCount;
134 private static MetadataField constants;
135 private static AddressField classLoaderData;
136 private static AddressField sourceDebugExtension;
137 private static AddressField innerClasses;
138 private static CIntField sourceFileNameIndex;
139 private static CIntField nonstaticFieldSize;
140 private static CIntField staticFieldSize;
141 private static CIntField staticOopFieldCount;
142 private static CIntField nonstaticOopMapSize;
143 private static CIntField isMarkedDependent;
144 private static CIntField initState;
145 private static CIntField itableLen;
146 private static AddressField breakpoints;
147 private static CIntField genericSignatureIndex;
148 private static CIntField majorVersion;
149 private static CIntField minorVersion;
150
151 // type safe enum for ClassState from instanceKlass.hpp
152 public static class ClassState {
153 public static final ClassState ALLOCATED = new ClassState("allocated");
154 public static final ClassState LOADED = new ClassState("loaded");
155 public static final ClassState LINKED = new ClassState("linked");
156 public static final ClassState BEING_INITIALIZED = new ClassState("beingInitialized");
157 public static final ClassState FULLY_INITIALIZED = new ClassState("fullyInitialized");
158 public static final ClassState INITIALIZATION_ERROR = new ClassState("initializationError");
159
160 private ClassState(String value) {
161 this.value = value;
162 }
163
164 public String toString() {
333 int len = getFields().length();
334 int allFieldsCount = 0;
335 for (; allFieldsCount*FIELD_SLOTS < len; allFieldsCount++) {
336 short flags = getFieldAccessFlags(allFieldsCount);
337 AccessFlags access = new AccessFlags(flags);
338 if (access.fieldHasGenericSignature()) {
339 len --;
340 }
341 }
342 return allFieldsCount;
343 }
344 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
345 public ClassLoaderData getClassLoaderData() { return ClassLoaderData.instantiateWrapperFor(classLoaderData.getValue(getAddress())); }
346 public Oop getClassLoader() { return getClassLoaderData().getClassLoader(); }
347 public Symbol getSourceFileName() { return getConstants().getSymbolAt(sourceFileNameIndex.getValue(this)); }
348 public String getSourceDebugExtension(){ return CStringUtilities.getString(sourceDebugExtension.getValue(getAddress())); }
349 public long getNonstaticFieldSize() { return nonstaticFieldSize.getValue(this); }
350 public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
351 public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); }
352 public boolean getIsMarkedDependent() { return isMarkedDependent.getValue(this) != 0; }
353 public long getItableLen() { return itableLen.getValue(this); }
354 public long majorVersion() { return majorVersion.getValue(this); }
355 public long minorVersion() { return minorVersion.getValue(this); }
356 public Symbol getGenericSignature() {
357 long index = genericSignatureIndex.getValue(this);
358 if (index != 0) {
359 return getConstants().getSymbolAt(index);
360 } else {
361 return null;
362 }
363 }
364
365 // "size helper" == instance size in words
366 public long getSizeHelper() {
367 int lh = getLayoutHelper();
368 if (Assert.ASSERTS_ENABLED) {
369 Assert.that(lh > 0, "layout helper initialized for instance class");
370 }
371 return lh / VM.getVM().getAddressSize();
372 }
528 return super.computeSubtypeOf(k);
529 }
530 }
531
532 public void printValueOn(PrintStream tty) {
533 tty.print("InstanceKlass for " + getName().asString());
534 }
535
536 public void iterateFields(MetadataVisitor visitor) {
537 super.iterateFields(visitor);
538 visitor.doMetadata(arrayKlasses, true);
539 // visitor.doOop(methods, true);
540 // visitor.doOop(localInterfaces, true);
541 // visitor.doOop(transitiveInterfaces, true);
542 visitor.doCInt(nonstaticFieldSize, true);
543 visitor.doCInt(staticFieldSize, true);
544 visitor.doCInt(staticOopFieldCount, true);
545 visitor.doCInt(nonstaticOopMapSize, true);
546 visitor.doCInt(isMarkedDependent, true);
547 visitor.doCInt(initState, true);
548 visitor.doCInt(itableLen, true);
549 }
550
551 /*
552 * Visit the static fields of this InstanceKlass with the obj of
553 * the visitor set to the oop holding the fields, which is
554 * currently the java mirror.
555 */
556 public void iterateStaticFields(OopVisitor visitor) {
557 visitor.setObj(getJavaMirror());
558 visitor.prologue();
559 iterateStaticFieldsInternal(visitor);
560 visitor.epilogue();
561
562 }
563
564 void iterateStaticFieldsInternal(OopVisitor visitor) {
565 int length = getJavaFieldsCount();
566 for (int index = 0; index < length; index++) {
567 short accessFlags = getFieldAccessFlags(index);
|