Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java @ 4737:75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
Summary: Reduce class runtime memory usage by packing 4 instanceKlass boolean fields into single u1 field. Save 4-byte for each loaded class.
Reviewed-by: dholmes, bobv, phh, twisti, never, coleenp
Contributed-by: Jiangli Zhou <jiangli.zhou@oracle.com>
author | coleenp |
---|---|
date | Thu, 17 Nov 2011 12:53:59 -0500 |
parents | cb315dc80374 |
children | 8f8b94305aff |
rev | line source |
---|---|
0 | 1 /* |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.oops; | |
26 | |
27 import java.io.*; | |
28 import java.util.*; | |
29 import sun.jvm.hotspot.debugger.*; | |
30 import sun.jvm.hotspot.memory.*; | |
31 import sun.jvm.hotspot.runtime.*; | |
32 import sun.jvm.hotspot.types.*; | |
33 import sun.jvm.hotspot.utilities.*; | |
34 | |
35 // An InstanceKlass is the VM level representation of a Java class. | |
36 | |
37 public class InstanceKlass extends Klass { | |
38 static { | |
39 VM.registerVMInitializedObserver(new Observer() { | |
40 public void update(Observable o, Object data) { | |
41 initialize(VM.getVM().getTypeDataBase()); | |
42 } | |
43 }); | |
44 } | |
45 | |
46 // field offset constants | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
47 private static int ACCESS_FLAGS_OFFSET; |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
48 private static int NAME_INDEX_OFFSET; |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
49 private static int SIGNATURE_INDEX_OFFSET; |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
50 private static int INITVAL_INDEX_OFFSET; |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
51 private static int LOW_OFFSET; |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
52 private static int HIGH_OFFSET; |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
53 private static int GENERIC_SIGNATURE_INDEX_OFFSET; |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
54 private static int FIELD_SLOTS; |
0 | 55 public static int IMPLEMENTORS_LIMIT; |
56 | |
57 // ClassState constants | |
58 private static int CLASS_STATE_UNPARSABLE_BY_GC; | |
59 private static int CLASS_STATE_ALLOCATED; | |
60 private static int CLASS_STATE_LOADED; | |
61 private static int CLASS_STATE_LINKED; | |
62 private static int CLASS_STATE_BEING_INITIALIZED; | |
63 private static int CLASS_STATE_FULLY_INITIALIZED; | |
64 private static int CLASS_STATE_INITIALIZATION_ERROR; | |
65 | |
4737
75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
coleenp
parents:
3962
diff
changeset
|
66 private static int IS_MARKED_DEPENDENT_MASK; |
75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
coleenp
parents:
3962
diff
changeset
|
67 |
0 | 68 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { |
69 Type type = db.lookupType("instanceKlass"); | |
70 arrayKlasses = new OopField(type.getOopField("_array_klasses"), Oop.getHeaderSize()); | |
71 methods = new OopField(type.getOopField("_methods"), Oop.getHeaderSize()); | |
72 methodOrdering = new OopField(type.getOopField("_method_ordering"), Oop.getHeaderSize()); | |
73 localInterfaces = new OopField(type.getOopField("_local_interfaces"), Oop.getHeaderSize()); | |
74 transitiveInterfaces = new OopField(type.getOopField("_transitive_interfaces"), Oop.getHeaderSize()); | |
75 nofImplementors = new CIntField(type.getCIntegerField("_nof_implementors"), Oop.getHeaderSize()); | |
76 IMPLEMENTORS_LIMIT = db.lookupIntConstant("instanceKlass::implementors_limit").intValue(); | |
77 implementors = new OopField[IMPLEMENTORS_LIMIT]; | |
78 for (int i = 0; i < IMPLEMENTORS_LIMIT; i++) { | |
79 long arrayOffset = Oop.getHeaderSize() + (i * db.getAddressSize()); | |
80 implementors[i] = new OopField(type.getOopField("_implementors[0]"), arrayOffset); | |
81 } | |
82 fields = new OopField(type.getOopField("_fields"), Oop.getHeaderSize()); | |
3938 | 83 javaFieldsCount = new CIntField(type.getCIntegerField("_java_fields_count"), Oop.getHeaderSize()); |
0 | 84 constants = new OopField(type.getOopField("_constants"), Oop.getHeaderSize()); |
85 classLoader = new OopField(type.getOopField("_class_loader"), Oop.getHeaderSize()); | |
86 protectionDomain = new OopField(type.getOopField("_protection_domain"), Oop.getHeaderSize()); | |
87 signers = new OopField(type.getOopField("_signers"), Oop.getHeaderSize()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
88 sourceFileName = type.getAddressField("_source_file_name"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
89 sourceDebugExtension = type.getAddressField("_source_debug_extension"); |
0 | 90 innerClasses = new OopField(type.getOopField("_inner_classes"), Oop.getHeaderSize()); |
91 nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), Oop.getHeaderSize()); | |
92 staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), Oop.getHeaderSize()); | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
93 staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), Oop.getHeaderSize()); |
0 | 94 nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), Oop.getHeaderSize()); |
4737
75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
coleenp
parents:
3962
diff
changeset
|
95 miscFlags = new CIntField(type.getCIntegerField("_misc_flags"), Oop.getHeaderSize()); |
0 | 96 initState = new CIntField(type.getCIntegerField("_init_state"), Oop.getHeaderSize()); |
97 vtableLen = new CIntField(type.getCIntegerField("_vtable_len"), Oop.getHeaderSize()); | |
98 itableLen = new CIntField(type.getCIntegerField("_itable_len"), Oop.getHeaderSize()); | |
99 breakpoints = type.getAddressField("_breakpoints"); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
100 genericSignature = type.getAddressField("_generic_signature"); |
0 | 101 majorVersion = new CIntField(type.getCIntegerField("_major_version"), Oop.getHeaderSize()); |
102 minorVersion = new CIntField(type.getCIntegerField("_minor_version"), Oop.getHeaderSize()); | |
103 headerSize = alignObjectOffset(Oop.getHeaderSize() + type.getSize()); | |
104 | |
105 // read field offset constants | |
3938 | 106 ACCESS_FLAGS_OFFSET = db.lookupIntConstant("FieldInfo::access_flags_offset").intValue(); |
107 NAME_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::name_index_offset").intValue(); | |
108 SIGNATURE_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::signature_index_offset").intValue(); | |
109 INITVAL_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::initval_index_offset").intValue(); | |
110 LOW_OFFSET = db.lookupIntConstant("FieldInfo::low_offset").intValue(); | |
111 HIGH_OFFSET = db.lookupIntConstant("FieldInfo::high_offset").intValue(); | |
112 GENERIC_SIGNATURE_INDEX_OFFSET = db.lookupIntConstant("FieldInfo::generic_signature_offset").intValue(); | |
113 FIELD_SLOTS = db.lookupIntConstant("FieldInfo::field_slots").intValue(); | |
0 | 114 // read ClassState constants |
115 CLASS_STATE_UNPARSABLE_BY_GC = db.lookupIntConstant("instanceKlass::unparsable_by_gc").intValue(); | |
116 CLASS_STATE_ALLOCATED = db.lookupIntConstant("instanceKlass::allocated").intValue(); | |
117 CLASS_STATE_LOADED = db.lookupIntConstant("instanceKlass::loaded").intValue(); | |
118 CLASS_STATE_LINKED = db.lookupIntConstant("instanceKlass::linked").intValue(); | |
119 CLASS_STATE_BEING_INITIALIZED = db.lookupIntConstant("instanceKlass::being_initialized").intValue(); | |
120 CLASS_STATE_FULLY_INITIALIZED = db.lookupIntConstant("instanceKlass::fully_initialized").intValue(); | |
121 CLASS_STATE_INITIALIZATION_ERROR = db.lookupIntConstant("instanceKlass::initialization_error").intValue(); | |
122 | |
4737
75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
coleenp
parents:
3962
diff
changeset
|
123 IS_MARKED_DEPENDENT_MASK = db.lookupIntConstant("instanceKlass::IS_MARKED_DEPENDENT").intValue(); |
75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
coleenp
parents:
3962
diff
changeset
|
124 |
0 | 125 } |
126 | |
127 InstanceKlass(OopHandle handle, ObjectHeap heap) { | |
128 super(handle, heap); | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
129 if (getJavaFieldsCount() != getAllFieldsCount()) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
130 // Exercise the injected field logic |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
131 for (int i = getJavaFieldsCount(); i < getAllFieldsCount(); i++) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
132 getFieldName(i); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
133 getFieldSignature(i); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
134 } |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
135 } |
0 | 136 } |
137 | |
138 private static OopField arrayKlasses; | |
139 private static OopField methods; | |
140 private static OopField methodOrdering; | |
141 private static OopField localInterfaces; | |
142 private static OopField transitiveInterfaces; | |
143 private static CIntField nofImplementors; | |
144 private static OopField[] implementors; | |
145 private static OopField fields; | |
3938 | 146 private static CIntField javaFieldsCount; |
0 | 147 private static OopField constants; |
148 private static OopField classLoader; | |
149 private static OopField protectionDomain; | |
150 private static OopField signers; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
151 private static AddressField sourceFileName; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
152 private static AddressField sourceDebugExtension; |
0 | 153 private static OopField innerClasses; |
154 private static CIntField nonstaticFieldSize; | |
155 private static CIntField staticFieldSize; | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
156 private static CIntField staticOopFieldCount; |
0 | 157 private static CIntField nonstaticOopMapSize; |
4737
75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
coleenp
parents:
3962
diff
changeset
|
158 private static CIntField miscFlags; |
0 | 159 private static CIntField initState; |
160 private static CIntField vtableLen; | |
161 private static CIntField itableLen; | |
162 private static AddressField breakpoints; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
163 private static AddressField genericSignature; |
0 | 164 private static CIntField majorVersion; |
165 private static CIntField minorVersion; | |
166 | |
167 // type safe enum for ClassState from instanceKlass.hpp | |
168 public static class ClassState { | |
169 public static final ClassState UNPARSABLE_BY_GC = new ClassState("unparsable_by_gc"); | |
170 public static final ClassState ALLOCATED = new ClassState("allocated"); | |
171 public static final ClassState LOADED = new ClassState("loaded"); | |
172 public static final ClassState LINKED = new ClassState("linked"); | |
173 public static final ClassState BEING_INITIALIZED = new ClassState("beingInitialized"); | |
174 public static final ClassState FULLY_INITIALIZED = new ClassState("fullyInitialized"); | |
175 public static final ClassState INITIALIZATION_ERROR = new ClassState("initializationError"); | |
176 | |
177 private ClassState(String value) { | |
178 this.value = value; | |
179 } | |
180 | |
181 public String toString() { | |
182 return value; | |
183 } | |
184 | |
185 private String value; | |
186 } | |
187 | |
3939 | 188 public int getInitStateAsInt() { return (int) initState.getValue(this); } |
0 | 189 public ClassState getInitState() { |
190 int state = getInitStateAsInt(); | |
191 if (state == CLASS_STATE_UNPARSABLE_BY_GC) { | |
192 return ClassState.UNPARSABLE_BY_GC; | |
193 } else if (state == CLASS_STATE_ALLOCATED) { | |
194 return ClassState.ALLOCATED; | |
195 } else if (state == CLASS_STATE_LOADED) { | |
196 return ClassState.LOADED; | |
197 } else if (state == CLASS_STATE_LINKED) { | |
198 return ClassState.LINKED; | |
199 } else if (state == CLASS_STATE_BEING_INITIALIZED) { | |
200 return ClassState.BEING_INITIALIZED; | |
201 } else if (state == CLASS_STATE_FULLY_INITIALIZED) { | |
202 return ClassState.FULLY_INITIALIZED; | |
203 } else if (state == CLASS_STATE_INITIALIZATION_ERROR) { | |
204 return ClassState.INITIALIZATION_ERROR; | |
205 } else { | |
206 throw new RuntimeException("should not reach here"); | |
207 } | |
208 } | |
209 | |
210 // initialization state quaries | |
211 public boolean isLoaded() { | |
212 return getInitStateAsInt() >= CLASS_STATE_LOADED; | |
213 } | |
214 | |
215 public boolean isLinked() { | |
216 return getInitStateAsInt() >= CLASS_STATE_LINKED; | |
217 } | |
218 | |
219 public boolean isInitialized() { | |
220 return getInitStateAsInt() == CLASS_STATE_FULLY_INITIALIZED; | |
221 } | |
222 | |
223 public boolean isNotInitialized() { | |
224 return getInitStateAsInt() < CLASS_STATE_BEING_INITIALIZED; | |
225 } | |
226 | |
227 public boolean isBeingInitialized() { | |
228 return getInitStateAsInt() == CLASS_STATE_BEING_INITIALIZED; | |
229 } | |
230 | |
231 public boolean isInErrorState() { | |
232 return getInitStateAsInt() == CLASS_STATE_INITIALIZATION_ERROR; | |
233 } | |
234 | |
235 public int getClassStatus() { | |
236 int result = 0; | |
237 if (isLinked()) { | |
238 result |= JVMDIClassStatus.VERIFIED | JVMDIClassStatus.PREPARED; | |
239 } | |
240 | |
241 if (isInitialized()) { | |
242 if (Assert.ASSERTS_ENABLED) { | |
243 Assert.that(isLinked(), "Class status is not consistent"); | |
244 } | |
245 result |= JVMDIClassStatus.INITIALIZED; | |
246 } | |
247 | |
248 if (isInErrorState()) { | |
249 result |= JVMDIClassStatus.ERROR; | |
250 } | |
251 return result; | |
252 } | |
253 | |
254 // Byteside of the header | |
255 private static long headerSize; | |
256 | |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
257 public long getObjectSize(Oop object) { |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
258 return getSizeHelper() * VM.getVM().getAddressSize(); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
259 } |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
260 |
0 | 261 public static long getHeaderSize() { return headerSize; } |
262 | |
3938 | 263 public short getFieldAccessFlags(int index) { |
264 return getFields().getShortAt(index * FIELD_SLOTS + ACCESS_FLAGS_OFFSET); | |
265 } | |
266 | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
267 public short getFieldNameIndex(int index) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
268 if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;"); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
269 return getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
270 } |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
271 |
3938 | 272 public Symbol getFieldName(int index) { |
273 int nameIndex = getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET); | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
274 if (index < getJavaFieldsCount()) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
275 return getConstants().getSymbolAt(nameIndex); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
276 } else { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
277 return vmSymbols.symbolAt(nameIndex); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
278 } |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
279 } |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
280 |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
281 public short getFieldSignatureIndex(int index) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
282 if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;"); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
283 return getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET); |
3938 | 284 } |
285 | |
286 public Symbol getFieldSignature(int index) { | |
287 int signatureIndex = getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET); | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
288 if (index < getJavaFieldsCount()) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
289 return getConstants().getSymbolAt(signatureIndex); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
290 } else { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
291 return vmSymbols.symbolAt(signatureIndex); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
292 } |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
293 } |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
294 |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
295 public short getFieldGenericSignatureIndex(int index) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
296 return getFields().getShortAt(index * FIELD_SLOTS + GENERIC_SIGNATURE_INDEX_OFFSET); |
3938 | 297 } |
298 | |
299 public Symbol getFieldGenericSignature(int index) { | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
300 short genericSignatureIndex = getFieldGenericSignatureIndex(index); |
3938 | 301 if (genericSignatureIndex != 0) { |
302 return getConstants().getSymbolAt(genericSignatureIndex); | |
303 } | |
304 return null; | |
305 } | |
306 | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
307 public short getFieldInitialValueIndex(int index) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
308 if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;"); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
309 return getFields().getShortAt(index * FIELD_SLOTS + INITVAL_INDEX_OFFSET); |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
310 } |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
311 |
3938 | 312 public int getFieldOffset(int index) { |
313 TypeArray fields = getFields(); | |
314 return VM.getVM().buildIntFromShorts(fields.getShortAt(index * FIELD_SLOTS + LOW_OFFSET), | |
315 fields.getShortAt(index * FIELD_SLOTS + HIGH_OFFSET)); | |
316 } | |
317 | |
0 | 318 // Accessors for declared fields |
319 public Klass getArrayKlasses() { return (Klass) arrayKlasses.getValue(this); } | |
320 public ObjArray getMethods() { return (ObjArray) methods.getValue(this); } | |
321 public TypeArray getMethodOrdering() { return (TypeArray) methodOrdering.getValue(this); } | |
322 public ObjArray getLocalInterfaces() { return (ObjArray) localInterfaces.getValue(this); } | |
323 public ObjArray getTransitiveInterfaces() { return (ObjArray) transitiveInterfaces.getValue(this); } | |
324 public long nofImplementors() { return nofImplementors.getValue(this); } | |
325 public Klass getImplementor() { return (Klass) implementors[0].getValue(this); } | |
326 public Klass getImplementor(int i) { return (Klass) implementors[i].getValue(this); } | |
327 public TypeArray getFields() { return (TypeArray) fields.getValue(this); } | |
3938 | 328 public int getJavaFieldsCount() { return (int) javaFieldsCount.getValue(this); } |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
329 public int getAllFieldsCount() { return (int)getFields().getLength() / FIELD_SLOTS; } |
0 | 330 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); } |
331 public Oop getClassLoader() { return classLoader.getValue(this); } | |
332 public Oop getProtectionDomain() { return protectionDomain.getValue(this); } | |
333 public ObjArray getSigners() { return (ObjArray) signers.getValue(this); } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
334 public Symbol getSourceFileName() { return getSymbol(sourceFileName); } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
335 public Symbol getSourceDebugExtension(){ return getSymbol(sourceDebugExtension); } |
0 | 336 public TypeArray getInnerClasses() { return (TypeArray) innerClasses.getValue(this); } |
337 public long getNonstaticFieldSize() { return nonstaticFieldSize.getValue(this); } | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
338 public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); } |
0 | 339 public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); } |
4737
75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
coleenp
parents:
3962
diff
changeset
|
340 public boolean getIsMarkedDependent() { return (miscFlags.getValue(this) & IS_MARKED_DEPENDENT_MASK) != 0; } |
0 | 341 public long getVtableLen() { return vtableLen.getValue(this); } |
342 public long getItableLen() { return itableLen.getValue(this); } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
343 public Symbol getGenericSignature() { return getSymbol(genericSignature); } |
0 | 344 public long majorVersion() { return majorVersion.getValue(this); } |
345 public long minorVersion() { return minorVersion.getValue(this); } | |
346 | |
347 // "size helper" == instance size in words | |
348 public long getSizeHelper() { | |
349 int lh = getLayoutHelper(); | |
350 if (Assert.ASSERTS_ENABLED) { | |
351 Assert.that(lh > 0, "layout helper initialized for instance class"); | |
352 } | |
353 return lh / VM.getVM().getAddressSize(); | |
354 } | |
355 | |
356 // same as enum InnerClassAttributeOffset in VM code. | |
357 public static interface InnerClassAttributeOffset { | |
358 // from JVM spec. "InnerClasses" attribute | |
359 public static final int innerClassInnerClassInfoOffset = 0; | |
360 public static final int innerClassOuterClassInfoOffset = 1; | |
361 public static final int innerClassInnerNameOffset = 2; | |
362 public static final int innerClassAccessFlagsOffset = 3; | |
363 public static final int innerClassNextOffset = 4; | |
364 }; | |
365 | |
366 // refer to compute_modifier_flags in VM code. | |
367 public long computeModifierFlags() { | |
368 long access = getAccessFlags(); | |
369 // But check if it happens to be member class. | |
370 TypeArray innerClassList = getInnerClasses(); | |
371 int length = ( innerClassList == null)? 0 : (int) innerClassList.getLength(); | |
372 if (length > 0) { | |
373 if (Assert.ASSERTS_ENABLED) { | |
374 Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0, "just checking"); | |
375 } | |
376 for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) { | |
377 int ioff = innerClassList.getShortAt(i + | |
378 InnerClassAttributeOffset.innerClassInnerClassInfoOffset); | |
379 // 'ioff' can be zero. | |
380 // refer to JVM spec. section 4.7.5. | |
381 if (ioff != 0) { | |
382 // only look at classes that are already loaded | |
383 // since we are looking for the flags for our self. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
384 ConstantPool.CPSlot classInfo = getConstants().getSlotAt(ioff); |
0 | 385 Symbol name = null; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
386 if (classInfo.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
387 name = ((Klass) classInfo.getOop()).getName(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
388 } else if (classInfo.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
389 name = classInfo.getSymbol(); |
0 | 390 } else { |
391 throw new RuntimeException("should not reach here"); | |
392 } | |
393 | |
394 if (name.equals(getName())) { | |
395 // This is really a member class | |
396 access = innerClassList.getShortAt(i + | |
397 InnerClassAttributeOffset.innerClassAccessFlagsOffset); | |
398 break; | |
399 } | |
400 } | |
401 } // for inner classes | |
402 } | |
403 | |
404 // Remember to strip ACC_SUPER bit | |
405 return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS; | |
406 } | |
407 | |
408 | |
409 // whether given Symbol is name of an inner/nested Klass of this Klass? | |
410 // anonymous and local classes are excluded. | |
411 public boolean isInnerClassName(Symbol sym) { | |
412 return isInInnerClasses(sym, false); | |
413 } | |
414 | |
415 // whether given Symbol is name of an inner/nested Klass of this Klass? | |
416 // anonymous classes excluded, but local classes are included. | |
417 public boolean isInnerOrLocalClassName(Symbol sym) { | |
418 return isInInnerClasses(sym, true); | |
419 } | |
420 | |
421 private boolean isInInnerClasses(Symbol sym, boolean includeLocals) { | |
422 TypeArray innerClassList = getInnerClasses(); | |
423 int length = ( innerClassList == null)? 0 : (int) innerClassList.getLength(); | |
424 if (length > 0) { | |
425 if (Assert.ASSERTS_ENABLED) { | |
426 Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0, "just checking"); | |
427 } | |
428 for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) { | |
429 int ioff = innerClassList.getShortAt(i + | |
430 InnerClassAttributeOffset.innerClassInnerClassInfoOffset); | |
431 // 'ioff' can be zero. | |
432 // refer to JVM spec. section 4.7.5. | |
433 if (ioff != 0) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
434 ConstantPool.CPSlot iclassInfo = getConstants().getSlotAt(ioff); |
0 | 435 Symbol innerName = null; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
436 if (iclassInfo.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
437 innerName = ((Klass) iclassInfo.getOop()).getName(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
438 } else if (iclassInfo.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
439 innerName = iclassInfo.getSymbol(); |
0 | 440 } else { |
441 throw new RuntimeException("should not reach here"); | |
442 } | |
443 | |
444 Symbol myname = getName(); | |
445 int ooff = innerClassList.getShortAt(i + | |
446 InnerClassAttributeOffset.innerClassOuterClassInfoOffset); | |
447 // for anonymous classes inner_name_index of InnerClasses | |
448 // attribute is zero. | |
449 int innerNameIndex = innerClassList.getShortAt(i + | |
450 InnerClassAttributeOffset.innerClassInnerNameOffset); | |
451 // if this is not a member (anonymous, local etc.), 'ooff' will be zero | |
452 // refer to JVM spec. section 4.7.5. | |
453 if (ooff == 0) { | |
454 if (includeLocals) { | |
455 // does it looks like my local class? | |
456 if (innerName.equals(sym) && | |
457 innerName.asString().startsWith(myname.asString())) { | |
458 // exclude anonymous classes. | |
459 return (innerNameIndex != 0); | |
460 } | |
461 } | |
462 } else { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
463 ConstantPool.CPSlot oclassInfo = getConstants().getSlotAt(ooff); |
0 | 464 Symbol outerName = null; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
465 if (oclassInfo.isOop()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
466 outerName = ((Klass) oclassInfo.getOop()).getName(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
467 } else if (oclassInfo.isMetaData()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1552
diff
changeset
|
468 outerName = oclassInfo.getSymbol(); |
0 | 469 } else { |
470 throw new RuntimeException("should not reach here"); | |
471 } | |
472 | |
473 // include only if current class is outer class. | |
474 if (outerName.equals(myname) && innerName.equals(sym)) { | |
475 return true; | |
476 } | |
477 } | |
478 } | |
479 } // for inner classes | |
480 return false; | |
481 } else { | |
482 return false; | |
483 } | |
484 } | |
485 | |
486 public boolean implementsInterface(Klass k) { | |
487 if (Assert.ASSERTS_ENABLED) { | |
488 Assert.that(k.isInterface(), "should not reach here"); | |
489 } | |
490 ObjArray interfaces = getTransitiveInterfaces(); | |
491 final int len = (int) interfaces.getLength(); | |
492 for (int i = 0; i < len; i++) { | |
493 if (interfaces.getObjAt(i).equals(k)) return true; | |
494 } | |
495 return false; | |
496 } | |
497 | |
498 boolean computeSubtypeOf(Klass k) { | |
499 if (k.isInterface()) { | |
500 return implementsInterface(k); | |
501 } else { | |
502 return super.computeSubtypeOf(k); | |
503 } | |
504 } | |
505 | |
506 public void printValueOn(PrintStream tty) { | |
507 tty.print("InstanceKlass for " + getName().asString()); | |
508 } | |
509 | |
510 public void iterateFields(OopVisitor visitor, boolean doVMFields) { | |
511 super.iterateFields(visitor, doVMFields); | |
512 if (doVMFields) { | |
513 visitor.doOop(arrayKlasses, true); | |
514 visitor.doOop(methods, true); | |
515 visitor.doOop(methodOrdering, true); | |
516 visitor.doOop(localInterfaces, true); | |
517 visitor.doOop(transitiveInterfaces, true); | |
518 visitor.doCInt(nofImplementors, true); | |
519 for (int i = 0; i < IMPLEMENTORS_LIMIT; i++) | |
520 visitor.doOop(implementors[i], true); | |
521 visitor.doOop(fields, true); | |
522 visitor.doOop(constants, true); | |
523 visitor.doOop(classLoader, true); | |
524 visitor.doOop(protectionDomain, true); | |
525 visitor.doOop(signers, true); | |
526 visitor.doOop(innerClasses, true); | |
527 visitor.doCInt(nonstaticFieldSize, true); | |
528 visitor.doCInt(staticFieldSize, true); | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
529 visitor.doCInt(staticOopFieldCount, true); |
0 | 530 visitor.doCInt(nonstaticOopMapSize, true); |
4737
75c0a73eee98
7102776: Pack instanceKlass boolean fields into single u1 field
coleenp
parents:
3962
diff
changeset
|
531 visitor.doCInt(miscFlags, true); |
0 | 532 visitor.doCInt(initState, true); |
533 visitor.doCInt(vtableLen, true); | |
534 visitor.doCInt(itableLen, true); | |
535 } | |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
536 } |
0 | 537 |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
538 /* |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
539 * Visit the static fields of this InstanceKlass with the obj of |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
540 * the visitor set to the oop holding the fields, which is |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
541 * currently the java mirror. |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
542 */ |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
543 public void iterateStaticFields(OopVisitor visitor) { |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
544 visitor.setObj(getJavaMirror()); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
545 visitor.prologue(); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
546 iterateStaticFieldsInternal(visitor); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
547 visitor.epilogue(); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
548 |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
549 } |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
550 |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
551 void iterateStaticFieldsInternal(OopVisitor visitor) { |
3938 | 552 int length = getJavaFieldsCount(); |
3944 | 553 for (int index = 0; index < length; index++) { |
554 short accessFlags = getFieldAccessFlags(index); | |
555 FieldType type = new FieldType(getFieldSignature(index)); | |
0 | 556 AccessFlags access = new AccessFlags(accessFlags); |
557 if (access.isStatic()) { | |
558 visitField(visitor, type, index); | |
559 } | |
560 } | |
561 } | |
562 | |
563 public Klass getJavaSuper() { | |
564 return getSuper(); | |
565 } | |
566 | |
3939 | 567 public static class StaticField { |
568 public AccessFlags flags; | |
569 public Field field; | |
570 | |
571 StaticField(Field field, AccessFlags flags) { | |
572 this.field = field; | |
573 this.flags = flags; | |
574 } | |
575 } | |
576 | |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
577 public void iterateNonStaticFields(OopVisitor visitor, Oop obj) { |
0 | 578 if (getSuper() != null) { |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2376
diff
changeset
|
579 ((InstanceKlass) getSuper()).iterateNonStaticFields(visitor, obj); |
0 | 580 } |
3938 | 581 int length = getJavaFieldsCount(); |
3944 | 582 for (int index = 0; index < length; index++) { |
583 short accessFlags = getFieldAccessFlags(index); | |
584 FieldType type = new FieldType(getFieldSignature(index)); | |
0 | 585 AccessFlags access = new AccessFlags(accessFlags); |
586 if (!access.isStatic()) { | |
587 visitField(visitor, type, index); | |
588 } | |
589 } | |
590 } | |
591 | |
592 /** Field access by name. */ | |
593 public Field findLocalField(Symbol name, Symbol sig) { | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3944
diff
changeset
|
594 int length = getJavaFieldsCount(); |
3944 | 595 for (int i = 0; i < length; i++) { |
596 Symbol f_name = getFieldName(i); | |
597 Symbol f_sig = getFieldSignature(i); | |
0 | 598 if (name.equals(f_name) && sig.equals(f_sig)) { |
599 return newField(i); | |
600 } | |
601 } | |
602 | |
603 return null; | |
604 } | |
605 | |
606 /** Find field in direct superinterfaces. */ | |
607 public Field findInterfaceField(Symbol name, Symbol sig) { | |
608 ObjArray interfaces = getLocalInterfaces(); | |
609 int n = (int) interfaces.getLength(); | |
610 for (int i = 0; i < n; i++) { | |
611 InstanceKlass intf1 = (InstanceKlass) interfaces.getObjAt(i); | |
612 if (Assert.ASSERTS_ENABLED) { | |
613 Assert.that(intf1.isInterface(), "just checking type"); | |
614 } | |
615 // search for field in current interface | |
616 Field f = intf1.findLocalField(name, sig); | |
617 if (f != null) { | |
618 if (Assert.ASSERTS_ENABLED) { | |
619 Assert.that(f.getAccessFlagsObj().isStatic(), "interface field must be static"); | |
620 } | |
621 return f; | |
622 } | |
623 // search for field in direct superinterfaces | |
624 f = intf1.findInterfaceField(name, sig); | |
625 if (f != null) return f; | |
626 } | |
627 // otherwise field lookup fails | |
628 return null; | |
629 } | |
630 | |
631 /** Find field according to JVM spec 5.4.3.2, returns the klass in | |
632 which the field is defined. */ | |
633 public Field findField(Symbol name, Symbol sig) { | |
634 // search order according to newest JVM spec (5.4.3.2, p.167). | |
635 // 1) search for field in current klass | |
636 Field f = findLocalField(name, sig); | |
637 if (f != null) return f; | |
638 | |
639 // 2) search for field recursively in direct superinterfaces | |
640 f = findInterfaceField(name, sig); | |
641 if (f != null) return f; | |
642 | |
643 // 3) apply field lookup recursively if superclass exists | |
644 InstanceKlass supr = (InstanceKlass) getSuper(); | |
645 if (supr != null) return supr.findField(name, sig); | |
646 | |
647 // 4) otherwise field lookup fails | |
648 return null; | |
649 } | |
650 | |
651 /** Find field according to JVM spec 5.4.3.2, returns the klass in | |
652 which the field is defined (convenience routine) */ | |
653 public Field findField(String name, String sig) { | |
654 SymbolTable symbols = VM.getVM().getSymbolTable(); | |
655 Symbol nameSym = symbols.probe(name); | |
656 Symbol sigSym = symbols.probe(sig); | |
657 if (nameSym == null || sigSym == null) { | |
658 return null; | |
659 } | |
660 return findField(nameSym, sigSym); | |
661 } | |
662 | |
663 /** Find field according to JVM spec 5.4.3.2, returns the klass in | |
664 which the field is defined (retained only for backward | |
665 compatibility with jdbx) */ | |
666 public Field findFieldDbg(String name, String sig) { | |
667 return findField(name, sig); | |
668 } | |
669 | |
670 /** Get field by its index in the fields array. Only designed for | |
671 use in a debugging system. */ | |
3944 | 672 public Field getFieldByIndex(int fieldIndex) { |
673 return newField(fieldIndex); | |
0 | 674 } |
675 | |
676 | |
677 /** Return a List of SA Fields for the fields declared in this class. | |
678 Inherited fields are not included. | |
679 Return an empty list if there are no fields declared in this class. | |
680 Only designed for use in a debugging system. */ | |
681 public List getImmediateFields() { | |
682 // A list of Fields for each field declared in this class/interface, | |
683 // not including inherited fields. | |
3938 | 684 int length = getJavaFieldsCount(); |
685 List immediateFields = new ArrayList(length); | |
3944 | 686 for (int index = 0; index < length; index++) { |
0 | 687 immediateFields.add(getFieldByIndex(index)); |
688 } | |
689 | |
690 return immediateFields; | |
691 } | |
692 | |
693 /** Return a List of SA Fields for all the java fields in this class, | |
694 including all inherited fields. This includes hidden | |
695 fields. Thus the returned list can contain fields with | |
696 the same name. | |
697 Return an empty list if there are no fields. | |
698 Only designed for use in a debugging system. */ | |
699 public List getAllFields() { | |
700 // Contains a Field for each field in this class, including immediate | |
701 // fields and inherited fields. | |
702 List allFields = getImmediateFields(); | |
703 | |
704 // transitiveInterfaces contains all interfaces implemented | |
705 // by this class and its superclass chain with no duplicates. | |
706 | |
707 ObjArray interfaces = getTransitiveInterfaces(); | |
708 int n = (int) interfaces.getLength(); | |
709 for (int i = 0; i < n; i++) { | |
710 InstanceKlass intf1 = (InstanceKlass) interfaces.getObjAt(i); | |
711 if (Assert.ASSERTS_ENABLED) { | |
712 Assert.that(intf1.isInterface(), "just checking type"); | |
713 } | |
714 allFields.addAll(intf1.getImmediateFields()); | |
715 } | |
716 | |
717 // Get all fields in the superclass, recursively. But, don't | |
718 // include fields in interfaces implemented by superclasses; | |
719 // we already have all those. | |
720 if (!isInterface()) { | |
721 InstanceKlass supr; | |
722 if ( (supr = (InstanceKlass) getSuper()) != null) { | |
723 allFields.addAll(supr.getImmediateFields()); | |
724 } | |
725 } | |
726 | |
727 return allFields; | |
728 } | |
729 | |
730 | |
731 /** Return a List of SA Methods declared directly in this class/interface. | |
732 Return an empty list if there are none, or if this isn't a class/ | |
733 interface. | |
734 */ | |
735 public List getImmediateMethods() { | |
736 // Contains a Method for each method declared in this class/interface | |
737 // not including inherited methods. | |
738 | |
739 ObjArray methods = getMethods(); | |
740 int length = (int)methods.getLength(); | |
741 Object[] tmp = new Object[length]; | |
742 | |
743 TypeArray methodOrdering = getMethodOrdering(); | |
744 if (methodOrdering.getLength() != length) { | |
745 // no ordering info present | |
746 for (int index = 0; index < length; index++) { | |
747 tmp[index] = methods.getObjAt(index); | |
748 } | |
749 } else { | |
750 for (int index = 0; index < length; index++) { | |
751 int originalIndex = getMethodOrdering().getIntAt(index); | |
752 tmp[originalIndex] = methods.getObjAt(index); | |
753 } | |
754 } | |
755 | |
756 return Arrays.asList(tmp); | |
757 } | |
758 | |
759 /** Return a List containing an SA InstanceKlass for each | |
760 interface named in this class's 'implements' clause. | |
761 */ | |
762 public List getDirectImplementedInterfaces() { | |
763 // Contains an InstanceKlass for each interface in this classes | |
764 // 'implements' clause. | |
765 | |
766 ObjArray interfaces = getLocalInterfaces(); | |
767 int length = (int) interfaces.getLength(); | |
768 List directImplementedInterfaces = new ArrayList(length); | |
769 | |
770 for (int index = 0; index < length; index ++) { | |
771 directImplementedInterfaces.add(interfaces.getObjAt(index)); | |
772 } | |
773 | |
774 return directImplementedInterfaces; | |
775 } | |
776 | |
777 | |
778 public long getObjectSize() { | |
779 long bodySize = alignObjectOffset(getVtableLen() * getHeap().getOopSize()) | |
780 + alignObjectOffset(getItableLen() * getHeap().getOopSize()) | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
781 + (getNonstaticOopMapSize()) * getHeap().getOopSize(); |
0 | 782 return alignObjectSize(headerSize + bodySize); |
783 } | |
784 | |
785 public Klass arrayKlassImpl(boolean orNull, int n) { | |
786 // FIXME: in reflective system this would need to change to | |
787 // actually allocate | |
788 if (getArrayKlasses() == null) { return null; } | |
789 ObjArrayKlass oak = (ObjArrayKlass) getArrayKlasses(); | |
790 if (orNull) { | |
791 return oak.arrayKlassOrNull(n); | |
792 } | |
793 return oak.arrayKlass(n); | |
794 } | |
795 | |
796 public Klass arrayKlassImpl(boolean orNull) { | |
797 return arrayKlassImpl(orNull, 1); | |
798 } | |
799 | |
800 public String signature() { | |
801 return "L" + super.signature() + ";"; | |
802 } | |
803 | |
804 /** Convenience routine taking Strings; lookup is done in | |
805 SymbolTable. */ | |
806 public Method findMethod(String name, String sig) { | |
807 SymbolTable syms = VM.getVM().getSymbolTable(); | |
808 Symbol nameSym = syms.probe(name); | |
809 Symbol sigSym = syms.probe(sig); | |
810 if (nameSym == null || sigSym == null) { | |
811 return null; | |
812 } | |
813 return findMethod(nameSym, sigSym); | |
814 } | |
815 | |
816 /** Find method in vtable. */ | |
817 public Method findMethod(Symbol name, Symbol sig) { | |
818 return findMethod(getMethods(), name, sig); | |
819 } | |
820 | |
821 /** Breakpoint support (see methods on methodOop for details) */ | |
822 public BreakpointInfo getBreakpoints() { | |
823 Address addr = getHandle().getAddressAt(Oop.getHeaderSize() + breakpoints.getOffset()); | |
824 return (BreakpointInfo) VMObjectFactory.newObject(BreakpointInfo.class, addr); | |
825 } | |
826 | |
827 //---------------------------------------------------------------------- | |
828 // Internals only below this point | |
829 // | |
830 | |
831 private void visitField(OopVisitor visitor, FieldType type, int index) { | |
832 Field f = newField(index); | |
833 if (type.isOop()) { | |
834 visitor.doOop((OopField) f, false); | |
835 return; | |
836 } | |
837 if (type.isByte()) { | |
838 visitor.doByte((ByteField) f, false); | |
839 return; | |
840 } | |
841 if (type.isChar()) { | |
842 visitor.doChar((CharField) f, false); | |
843 return; | |
844 } | |
845 if (type.isDouble()) { | |
846 visitor.doDouble((DoubleField) f, false); | |
847 return; | |
848 } | |
849 if (type.isFloat()) { | |
850 visitor.doFloat((FloatField) f, false); | |
851 return; | |
852 } | |
853 if (type.isInt()) { | |
854 visitor.doInt((IntField) f, false); | |
855 return; | |
856 } | |
857 if (type.isLong()) { | |
858 visitor.doLong((LongField) f, false); | |
859 return; | |
860 } | |
861 if (type.isShort()) { | |
862 visitor.doShort((ShortField) f, false); | |
863 return; | |
864 } | |
865 if (type.isBoolean()) { | |
866 visitor.doBoolean((BooleanField) f, false); | |
867 return; | |
868 } | |
869 } | |
870 | |
871 // Creates new field from index in fields TypeArray | |
872 private Field newField(int index) { | |
3944 | 873 FieldType type = new FieldType(getFieldSignature(index)); |
0 | 874 if (type.isOop()) { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
875 if (VM.getVM().isCompressedOopsEnabled()) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
876 return new NarrowOopField(this, index); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
877 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
878 return new OopField(this, index); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
879 } |
0 | 880 } |
881 if (type.isByte()) { | |
882 return new ByteField(this, index); | |
883 } | |
884 if (type.isChar()) { | |
885 return new CharField(this, index); | |
886 } | |
887 if (type.isDouble()) { | |
888 return new DoubleField(this, index); | |
889 } | |
890 if (type.isFloat()) { | |
891 return new FloatField(this, index); | |
892 } | |
893 if (type.isInt()) { | |
894 return new IntField(this, index); | |
895 } | |
896 if (type.isLong()) { | |
897 return new LongField(this, index); | |
898 } | |
899 if (type.isShort()) { | |
900 return new ShortField(this, index); | |
901 } | |
902 if (type.isBoolean()) { | |
903 return new BooleanField(this, index); | |
904 } | |
905 throw new RuntimeException("Illegal field type at index " + index); | |
906 } | |
907 | |
908 private static Method findMethod(ObjArray methods, Symbol name, Symbol signature) { | |
909 int len = (int) methods.getLength(); | |
910 // methods are sorted, so do binary search | |
911 int l = 0; | |
912 int h = len - 1; | |
913 while (l <= h) { | |
914 int mid = (l + h) >> 1; | |
915 Method m = (Method) methods.getObjAt(mid); | |
916 int res = m.getName().fastCompare(name); | |
917 if (res == 0) { | |
918 // found matching name; do linear search to find matching signature | |
919 // first, quick check for common case | |
920 if (m.getSignature().equals(signature)) return m; | |
921 // search downwards through overloaded methods | |
922 int i; | |
923 for (i = mid - 1; i >= l; i--) { | |
924 Method m1 = (Method) methods.getObjAt(i); | |
925 if (!m1.getName().equals(name)) break; | |
926 if (m1.getSignature().equals(signature)) return m1; | |
927 } | |
928 // search upwards | |
929 for (i = mid + 1; i <= h; i++) { | |
930 Method m1 = (Method) methods.getObjAt(i); | |
931 if (!m1.getName().equals(name)) break; | |
932 if (m1.getSignature().equals(signature)) return m1; | |
933 } | |
934 // not found | |
935 if (Assert.ASSERTS_ENABLED) { | |
936 int index = linearSearch(methods, name, signature); | |
937 if (index != -1) { | |
938 throw new DebuggerException("binary search bug: should have found entry " + index); | |
939 } | |
940 } | |
941 return null; | |
942 } else if (res < 0) { | |
943 l = mid + 1; | |
944 } else { | |
945 h = mid - 1; | |
946 } | |
947 } | |
948 if (Assert.ASSERTS_ENABLED) { | |
949 int index = linearSearch(methods, name, signature); | |
950 if (index != -1) { | |
951 throw new DebuggerException("binary search bug: should have found entry " + index); | |
952 } | |
953 } | |
954 return null; | |
955 } | |
956 | |
957 private static int linearSearch(ObjArray methods, Symbol name, Symbol signature) { | |
958 int len = (int) methods.getLength(); | |
959 for (int index = 0; index < len; index++) { | |
960 Method m = (Method) methods.getObjAt(index); | |
961 if (m.getSignature().equals(signature) && m.getName().equals(name)) { | |
962 return index; | |
963 } | |
964 } | |
965 return -1; | |
966 } | |
967 } |