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