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