Mercurial > hg > graal-jvmci-8
annotate agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java @ 235:9c2ecc2ffb12 jdk7-b31
Merge
author | trims |
---|---|
date | Fri, 11 Jul 2008 01:14:44 -0700 |
parents | d1605aabd0a1 a5838065ab24 |
children | c18cbe5936b8 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 2000-2008 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // | |
26 // The ObjectHeap is an abstraction over all generations in the VM | |
27 // It gives access to all present objects and classes. | |
28 // | |
29 | |
30 package sun.jvm.hotspot.oops; | |
31 | |
32 import java.util.*; | |
33 | |
34 import sun.jvm.hotspot.debugger.*; | |
35 import sun.jvm.hotspot.gc_interface.*; | |
36 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*; | |
37 import sun.jvm.hotspot.memory.*; | |
38 import sun.jvm.hotspot.runtime.*; | |
39 import sun.jvm.hotspot.types.*; | |
40 import sun.jvm.hotspot.utilities.*; | |
41 | |
42 public class ObjectHeap { | |
43 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
44 private static final boolean DEBUG; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
45 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
46 static { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
47 DEBUG = System.getProperty("sun.jvm.hotspot.oops.ObjectHeap.DEBUG") != null; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
48 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
49 |
0 | 50 private OopHandle symbolKlassHandle; |
51 private OopHandle methodKlassHandle; | |
52 private OopHandle constMethodKlassHandle; | |
53 private OopHandle methodDataKlassHandle; | |
54 private OopHandle constantPoolKlassHandle; | |
55 private OopHandle constantPoolCacheKlassHandle; | |
56 private OopHandle klassKlassHandle; | |
57 private OopHandle instanceKlassKlassHandle; | |
58 private OopHandle typeArrayKlassKlassHandle; | |
59 private OopHandle objArrayKlassKlassHandle; | |
60 private OopHandle boolArrayKlassHandle; | |
61 private OopHandle byteArrayKlassHandle; | |
62 private OopHandle charArrayKlassHandle; | |
63 private OopHandle intArrayKlassHandle; | |
64 private OopHandle shortArrayKlassHandle; | |
65 private OopHandle longArrayKlassHandle; | |
66 private OopHandle singleArrayKlassHandle; | |
67 private OopHandle doubleArrayKlassHandle; | |
68 private OopHandle arrayKlassKlassHandle; | |
69 private OopHandle compiledICHolderKlassHandle; | |
70 | |
71 private SymbolKlass symbolKlassObj; | |
72 private MethodKlass methodKlassObj; | |
73 private ConstMethodKlass constMethodKlassObj; | |
74 private MethodDataKlass methodDataKlassObj; | |
75 private ConstantPoolKlass constantPoolKlassObj; | |
76 private ConstantPoolCacheKlass constantPoolCacheKlassObj; | |
77 private KlassKlass klassKlassObj; | |
78 private InstanceKlassKlass instanceKlassKlassObj; | |
79 private TypeArrayKlassKlass typeArrayKlassKlassObj; | |
80 private ObjArrayKlassKlass objArrayKlassKlassObj; | |
81 private TypeArrayKlass boolArrayKlassObj; | |
82 private TypeArrayKlass byteArrayKlassObj; | |
83 private TypeArrayKlass charArrayKlassObj; | |
84 private TypeArrayKlass intArrayKlassObj; | |
85 private TypeArrayKlass shortArrayKlassObj; | |
86 private TypeArrayKlass longArrayKlassObj; | |
87 private TypeArrayKlass singleArrayKlassObj; | |
88 private TypeArrayKlass doubleArrayKlassObj; | |
89 private ArrayKlassKlass arrayKlassKlassObj; | |
90 private CompiledICHolderKlass compiledICHolderKlassObj; | |
91 | |
92 public void initialize(TypeDataBase db) throws WrongTypeException { | |
93 // Lookup the roots in the object hierarchy. | |
94 Type universeType = db.lookupType("Universe"); | |
95 | |
96 symbolKlassHandle = universeType.getOopField("_symbolKlassObj").getValue(); | |
97 symbolKlassObj = new SymbolKlass(symbolKlassHandle, this); | |
98 | |
99 methodKlassHandle = universeType.getOopField("_methodKlassObj").getValue(); | |
100 methodKlassObj = new MethodKlass(methodKlassHandle, this); | |
101 | |
102 constMethodKlassHandle = universeType.getOopField("_constMethodKlassObj").getValue(); | |
103 constMethodKlassObj = new ConstMethodKlass(constMethodKlassHandle, this); | |
104 | |
105 constantPoolKlassHandle = universeType.getOopField("_constantPoolKlassObj").getValue(); | |
106 constantPoolKlassObj = new ConstantPoolKlass(constantPoolKlassHandle, this); | |
107 | |
108 constantPoolCacheKlassHandle = universeType.getOopField("_constantPoolCacheKlassObj").getValue(); | |
109 constantPoolCacheKlassObj = new ConstantPoolCacheKlass(constantPoolCacheKlassHandle, this); | |
110 | |
111 klassKlassHandle = universeType.getOopField("_klassKlassObj").getValue(); | |
112 klassKlassObj = new KlassKlass(klassKlassHandle, this); | |
113 | |
114 arrayKlassKlassHandle = universeType.getOopField("_arrayKlassKlassObj").getValue(); | |
115 arrayKlassKlassObj = new ArrayKlassKlass(arrayKlassKlassHandle, this); | |
116 | |
117 instanceKlassKlassHandle = universeType.getOopField("_instanceKlassKlassObj").getValue(); | |
118 instanceKlassKlassObj = new InstanceKlassKlass(instanceKlassKlassHandle, this); | |
119 | |
120 typeArrayKlassKlassHandle = universeType.getOopField("_typeArrayKlassKlassObj").getValue(); | |
121 typeArrayKlassKlassObj = new TypeArrayKlassKlass(typeArrayKlassKlassHandle, this); | |
122 | |
123 objArrayKlassKlassHandle = universeType.getOopField("_objArrayKlassKlassObj").getValue(); | |
124 objArrayKlassKlassObj = new ObjArrayKlassKlass(objArrayKlassKlassHandle, this); | |
125 | |
126 boolArrayKlassHandle = universeType.getOopField("_boolArrayKlassObj").getValue(); | |
127 boolArrayKlassObj = new TypeArrayKlass(boolArrayKlassHandle, this); | |
128 | |
129 byteArrayKlassHandle = universeType.getOopField("_byteArrayKlassObj").getValue(); | |
130 byteArrayKlassObj = new TypeArrayKlass(byteArrayKlassHandle, this); | |
131 | |
132 charArrayKlassHandle = universeType.getOopField("_charArrayKlassObj").getValue(); | |
133 charArrayKlassObj = new TypeArrayKlass(charArrayKlassHandle, this); | |
134 | |
135 intArrayKlassHandle = universeType.getOopField("_intArrayKlassObj").getValue(); | |
136 intArrayKlassObj = new TypeArrayKlass(intArrayKlassHandle, this); | |
137 | |
138 shortArrayKlassHandle = universeType.getOopField("_shortArrayKlassObj").getValue(); | |
139 shortArrayKlassObj = new TypeArrayKlass(shortArrayKlassHandle, this); | |
140 | |
141 longArrayKlassHandle = universeType.getOopField("_longArrayKlassObj").getValue(); | |
142 longArrayKlassObj = new TypeArrayKlass(longArrayKlassHandle, this); | |
143 | |
144 singleArrayKlassHandle = universeType.getOopField("_singleArrayKlassObj").getValue(); | |
145 singleArrayKlassObj = new TypeArrayKlass(singleArrayKlassHandle, this); | |
146 | |
147 doubleArrayKlassHandle = universeType.getOopField("_doubleArrayKlassObj").getValue(); | |
148 doubleArrayKlassObj = new TypeArrayKlass(doubleArrayKlassHandle, this); | |
149 | |
150 if (!VM.getVM().isCore()) { | |
151 methodDataKlassHandle = universeType.getOopField("_methodDataKlassObj").getValue(); | |
152 methodDataKlassObj = new MethodDataKlass(methodDataKlassHandle, this); | |
153 | |
154 compiledICHolderKlassHandle = universeType.getOopField("_compiledICHolderKlassObj").getValue(); | |
155 compiledICHolderKlassObj= new CompiledICHolderKlass(compiledICHolderKlassHandle ,this); | |
156 } | |
157 } | |
158 | |
159 public ObjectHeap(TypeDataBase db) throws WrongTypeException { | |
160 // Get commonly used sizes of basic types | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
161 oopSize = VM.getVM().getOopSize(); |
0 | 162 byteSize = db.getJByteType().getSize(); |
163 charSize = db.getJCharType().getSize(); | |
164 booleanSize = db.getJBooleanType().getSize(); | |
165 intSize = db.getJIntType().getSize(); | |
166 shortSize = db.getJShortType().getSize(); | |
167 longSize = db.getJLongType().getSize(); | |
168 floatSize = db.getJFloatType().getSize(); | |
169 doubleSize = db.getJDoubleType().getSize(); | |
170 | |
171 initialize(db); | |
172 } | |
173 | |
174 /** Comparison operation for oops, either or both of which may be null */ | |
175 public boolean equal(Oop o1, Oop o2) { | |
176 if (o1 != null) return o1.equals(o2); | |
177 return (o2 == null); | |
178 } | |
179 | |
180 // Cached sizes of basic types | |
181 private long oopSize; | |
182 private long byteSize; | |
183 private long charSize; | |
184 private long booleanSize; | |
185 private long intSize; | |
186 private long shortSize; | |
187 private long longSize; | |
188 private long floatSize; | |
189 private long doubleSize; | |
190 | |
191 public long getOopSize() { return oopSize; } | |
192 public long getByteSize() { return byteSize; } | |
193 public long getCharSize() { return charSize; } | |
194 public long getBooleanSize() { return booleanSize; } | |
195 public long getIntSize() { return intSize; } | |
196 public long getShortSize() { return shortSize; } | |
197 public long getLongSize() { return longSize; } | |
198 public long getFloatSize() { return floatSize; } | |
199 public long getDoubleSize() { return doubleSize; } | |
200 | |
201 // Accessors for well-known system classes (from Universe) | |
202 public SymbolKlass getSymbolKlassObj() { return symbolKlassObj; } | |
203 public MethodKlass getMethodKlassObj() { return methodKlassObj; } | |
204 public ConstMethodKlass getConstMethodKlassObj() { return constMethodKlassObj; } | |
205 public MethodDataKlass getMethodDataKlassObj() { return methodDataKlassObj; } | |
206 public ConstantPoolKlass getConstantPoolKlassObj() { return constantPoolKlassObj; } | |
207 public ConstantPoolCacheKlass getConstantPoolCacheKlassObj() { return constantPoolCacheKlassObj; } | |
208 public KlassKlass getKlassKlassObj() { return klassKlassObj; } | |
209 public ArrayKlassKlass getArrayKlassKlassObj() { return arrayKlassKlassObj; } | |
210 public InstanceKlassKlass getInstanceKlassKlassObj() { return instanceKlassKlassObj; } | |
211 public ObjArrayKlassKlass getObjArrayKlassKlassObj() { return objArrayKlassKlassObj; } | |
212 public TypeArrayKlassKlass getTypeArrayKlassKlassObj() { return typeArrayKlassKlassObj; } | |
213 public TypeArrayKlass getBoolArrayKlassObj() { return boolArrayKlassObj; } | |
214 public TypeArrayKlass getByteArrayKlassObj() { return byteArrayKlassObj; } | |
215 public TypeArrayKlass getCharArrayKlassObj() { return charArrayKlassObj; } | |
216 public TypeArrayKlass getIntArrayKlassObj() { return intArrayKlassObj; } | |
217 public TypeArrayKlass getShortArrayKlassObj() { return shortArrayKlassObj; } | |
218 public TypeArrayKlass getLongArrayKlassObj() { return longArrayKlassObj; } | |
219 public TypeArrayKlass getSingleArrayKlassObj() { return singleArrayKlassObj; } | |
220 public TypeArrayKlass getDoubleArrayKlassObj() { return doubleArrayKlassObj; } | |
221 public CompiledICHolderKlass getCompiledICHolderKlassObj() { | |
222 if (Assert.ASSERTS_ENABLED) { | |
223 Assert.that(!VM.getVM().isCore(), "must not be called for core build"); | |
224 } | |
225 return compiledICHolderKlassObj; | |
226 } | |
227 | |
228 /** Takes a BasicType and returns the corresponding primitive array | |
229 klass */ | |
230 public Klass typeArrayKlassObj(int t) { | |
231 if (t == BasicType.getTBoolean()) return getBoolArrayKlassObj(); | |
232 if (t == BasicType.getTChar()) return getCharArrayKlassObj(); | |
233 if (t == BasicType.getTFloat()) return getSingleArrayKlassObj(); | |
234 if (t == BasicType.getTDouble()) return getDoubleArrayKlassObj(); | |
235 if (t == BasicType.getTByte()) return getByteArrayKlassObj(); | |
236 if (t == BasicType.getTShort()) return getShortArrayKlassObj(); | |
237 if (t == BasicType.getTInt()) return getIntArrayKlassObj(); | |
238 if (t == BasicType.getTLong()) return getLongArrayKlassObj(); | |
239 throw new RuntimeException("Illegal basic type " + t); | |
240 } | |
241 | |
242 /** an interface to filter objects while walking heap */ | |
243 public static interface ObjectFilter { | |
244 public boolean canInclude(Oop obj); | |
245 } | |
246 | |
247 /** The base heap iteration mechanism */ | |
248 public void iterate(HeapVisitor visitor) { | |
249 iterateLiveRegions(collectLiveRegions(), visitor, null); | |
250 } | |
251 | |
252 /** iterate objects satisfying a specified ObjectFilter */ | |
253 public void iterate(HeapVisitor visitor, ObjectFilter of) { | |
254 iterateLiveRegions(collectLiveRegions(), visitor, of); | |
255 } | |
256 | |
257 /** iterate objects of given Klass. param 'includeSubtypes' tells whether to | |
258 * include objects of subtypes or not */ | |
259 public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k, boolean includeSubtypes) { | |
260 if (includeSubtypes) { | |
261 if (k.isFinal()) { | |
262 // do the simpler "exact" klass loop | |
263 iterateExact(visitor, k); | |
264 } else { | |
265 iterateSubtypes(visitor, k); | |
266 } | |
267 } else { | |
268 // there can no object of abstract classes and interfaces | |
269 if (!k.isAbstract() && !k.isInterface()) { | |
270 iterateExact(visitor, k); | |
271 } | |
272 } | |
273 } | |
274 | |
275 /** iterate objects of given Klass (objects of subtypes included) */ | |
276 public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k) { | |
277 iterateObjectsOfKlass(visitor, k, true); | |
278 } | |
279 | |
280 /** This routine can be used to iterate through the heap at an | |
281 extremely low level (stepping word-by-word) to provide the | |
282 ability to do very low-level debugging */ | |
283 public void iterateRaw(RawHeapVisitor visitor) { | |
284 List liveRegions = collectLiveRegions(); | |
285 | |
286 // Summarize size | |
287 long totalSize = 0; | |
288 for (int i = 0; i < liveRegions.size(); i += 2) { | |
289 Address bottom = (Address) liveRegions.get(i); | |
290 Address top = (Address) liveRegions.get(i+1); | |
291 totalSize += top.minus(bottom); | |
292 } | |
293 visitor.prologue(totalSize); | |
294 | |
295 for (int i = 0; i < liveRegions.size(); i += 2) { | |
296 Address bottom = (Address) liveRegions.get(i); | |
297 Address top = (Address) liveRegions.get(i+1); | |
298 | |
299 // Traverses the space from bottom to top | |
300 while (bottom.lessThan(top)) { | |
301 visitor.visitAddress(bottom); | |
302 bottom = bottom.addOffsetTo(VM.getVM().getAddressSize()); | |
303 } | |
304 } | |
305 | |
306 visitor.epilogue(); | |
307 } | |
308 | |
309 // Iterates through only the perm generation for the purpose of | |
310 // finding static fields for liveness analysis | |
311 public void iteratePerm(HeapVisitor visitor) { | |
312 CollectedHeap heap = VM.getVM().getUniverse().heap(); | |
313 List liveRegions = new ArrayList(); | |
314 addPermGenLiveRegions(liveRegions, heap); | |
315 sortLiveRegions(liveRegions); | |
316 iterateLiveRegions(liveRegions, visitor, null); | |
317 } | |
318 | |
218
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
319 public boolean isValidMethod(OopHandle handle) { |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
320 OopHandle klass = Oop.getKlassForOopHandle(handle); |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
321 if (klass != null && klass.equals(methodKlassHandle)) { |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
322 return true; |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
323 } |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
324 return false; |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
325 } |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
326 |
0 | 327 // Creates an instance from the Oop hierarchy based based on the handle |
328 public Oop newOop(OopHandle handle) { | |
329 // The only known way to detect the right type of an oop is | |
330 // traversing the class chain until a well-known klass is recognized. | |
331 // A more direct solution would require the klasses to expose | |
332 // the C++ vtbl structure. | |
333 | |
334 // Handle the null reference | |
335 if (handle == null) return null; | |
336 | |
337 // First check if handle is one of the root objects | |
338 if (handle.equals(methodKlassHandle)) return getMethodKlassObj(); | |
339 if (handle.equals(constMethodKlassHandle)) return getConstMethodKlassObj(); | |
340 if (handle.equals(symbolKlassHandle)) return getSymbolKlassObj(); | |
341 if (handle.equals(constantPoolKlassHandle)) return getConstantPoolKlassObj(); | |
342 if (handle.equals(constantPoolCacheKlassHandle)) return getConstantPoolCacheKlassObj(); | |
343 if (handle.equals(instanceKlassKlassHandle)) return getInstanceKlassKlassObj(); | |
344 if (handle.equals(objArrayKlassKlassHandle)) return getObjArrayKlassKlassObj(); | |
345 if (handle.equals(klassKlassHandle)) return getKlassKlassObj(); | |
346 if (handle.equals(arrayKlassKlassHandle)) return getArrayKlassKlassObj(); | |
347 if (handle.equals(typeArrayKlassKlassHandle)) return getTypeArrayKlassKlassObj(); | |
348 if (handle.equals(boolArrayKlassHandle)) return getBoolArrayKlassObj(); | |
349 if (handle.equals(byteArrayKlassHandle)) return getByteArrayKlassObj(); | |
350 if (handle.equals(charArrayKlassHandle)) return getCharArrayKlassObj(); | |
351 if (handle.equals(intArrayKlassHandle)) return getIntArrayKlassObj(); | |
352 if (handle.equals(shortArrayKlassHandle)) return getShortArrayKlassObj(); | |
353 if (handle.equals(longArrayKlassHandle)) return getLongArrayKlassObj(); | |
354 if (handle.equals(singleArrayKlassHandle)) return getSingleArrayKlassObj(); | |
355 if (handle.equals(doubleArrayKlassHandle)) return getDoubleArrayKlassObj(); | |
356 if (!VM.getVM().isCore()) { | |
357 if (handle.equals(compiledICHolderKlassHandle)) return getCompiledICHolderKlassObj(); | |
358 if (handle.equals(methodDataKlassHandle)) return getMethodDataKlassObj(); | |
359 } | |
360 | |
361 // Then check if obj.klass() is one of the root objects | |
362 OopHandle klass = Oop.getKlassForOopHandle(handle); | |
363 if (klass != null) { | |
364 if (klass.equals(methodKlassHandle)) return new Method(handle, this); | |
365 if (klass.equals(constMethodKlassHandle)) return new ConstMethod(handle, this); | |
366 if (klass.equals(symbolKlassHandle)) return new Symbol(handle, this); | |
367 if (klass.equals(constantPoolKlassHandle)) return new ConstantPool(handle, this); | |
368 if (klass.equals(constantPoolCacheKlassHandle)) return new ConstantPoolCache(handle, this); | |
369 if (!VM.getVM().isCore()) { | |
370 if (klass.equals(compiledICHolderKlassHandle)) return new CompiledICHolder(handle, this); | |
371 if (klass.equals(methodDataKlassHandle)) return new MethodData(handle, this); | |
372 } | |
373 if (klass.equals(instanceKlassKlassHandle)) return new InstanceKlass(handle, this); | |
374 if (klass.equals(objArrayKlassKlassHandle)) return new ObjArrayKlass(handle, this); | |
375 if (klass.equals(typeArrayKlassKlassHandle)) return new TypeArrayKlass(handle, this); | |
376 | |
377 // Lastly check if obj.klass().klass() is on of the root objects | |
378 OopHandle klassKlass = Oop.getKlassForOopHandle(klass); | |
379 if (klassKlass != null) { | |
380 if (klassKlass.equals(instanceKlassKlassHandle)) return new Instance(handle, this); | |
381 if (klassKlass.equals(objArrayKlassKlassHandle)) return new ObjArray(handle, this); | |
382 if (klassKlass.equals(typeArrayKlassKlassHandle)) return new TypeArray(handle, this); | |
383 } | |
384 } | |
385 | |
218
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
386 if (DEBUG) { |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
387 System.err.println("Unknown oop at " + handle); |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
388 System.err.println("Oop's klass is " + klass); |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
113
diff
changeset
|
389 } |
0 | 390 |
391 throw new UnknownOopException(); | |
392 } | |
393 | |
394 // Print all objects in the object heap | |
395 public void print() { | |
396 HeapPrinter printer = new HeapPrinter(System.out); | |
397 iterate(printer); | |
398 } | |
399 | |
400 //--------------------------------------------------------------------------- | |
401 // Internals only below this point | |
402 // | |
403 | |
404 private void iterateExact(HeapVisitor visitor, final Klass k) { | |
405 iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() { | |
406 public boolean canInclude(Oop obj) { | |
407 Klass tk = obj.getKlass(); | |
408 // null Klass is seen sometimes! | |
409 return (tk != null && tk.equals(k)); | |
410 } | |
411 }); | |
412 } | |
413 | |
414 private void iterateSubtypes(HeapVisitor visitor, final Klass k) { | |
415 iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() { | |
416 public boolean canInclude(Oop obj) { | |
417 Klass tk = obj.getKlass(); | |
418 // null Klass is seen sometimes! | |
419 return (tk != null && tk.isSubtypeOf(k)); | |
420 } | |
421 }); | |
422 } | |
423 | |
424 private void iterateLiveRegions(List liveRegions, HeapVisitor visitor, ObjectFilter of) { | |
425 // Summarize size | |
426 long totalSize = 0; | |
427 for (int i = 0; i < liveRegions.size(); i += 2) { | |
428 Address bottom = (Address) liveRegions.get(i); | |
429 Address top = (Address) liveRegions.get(i+1); | |
430 totalSize += top.minus(bottom); | |
431 } | |
432 visitor.prologue(totalSize); | |
433 | |
434 CompactibleFreeListSpace cmsSpaceOld = null; | |
435 CompactibleFreeListSpace cmsSpacePerm = null; | |
436 CollectedHeap heap = VM.getVM().getUniverse().heap(); | |
437 | |
438 if (heap instanceof GenCollectedHeap) { | |
439 GenCollectedHeap genHeap = (GenCollectedHeap) heap; | |
440 Generation genOld = genHeap.getGen(1); | |
441 Generation genPerm = genHeap.permGen(); | |
442 if (genOld instanceof ConcurrentMarkSweepGeneration) { | |
443 ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genOld; | |
444 cmsSpaceOld = concGen.cmsSpace(); | |
445 } | |
446 if (genPerm instanceof ConcurrentMarkSweepGeneration) { | |
447 ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genPerm; | |
448 cmsSpacePerm = concGen.cmsSpace(); | |
449 } | |
450 } | |
451 | |
452 for (int i = 0; i < liveRegions.size(); i += 2) { | |
453 Address bottom = (Address) liveRegions.get(i); | |
454 Address top = (Address) liveRegions.get(i+1); | |
455 | |
456 try { | |
457 // Traverses the space from bottom to top | |
458 OopHandle handle = bottom.addOffsetToAsOopHandle(0); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
459 |
0 | 460 while (handle.lessThan(top)) { |
461 Oop obj = null; | |
462 | |
463 try { | |
464 obj = newOop(handle); | |
465 } catch (UnknownOopException exp) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
466 if (DEBUG) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
467 throw new RuntimeException(" UnknownOopException " + exp); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
468 } |
0 | 469 } |
470 if (obj == null) { | |
471 //Find the object size using Printezis bits and skip over | |
472 System.err.println("Finding object size using Printezis bits and skipping over..."); | |
473 long size = 0; | |
474 | |
475 if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle) ){ | |
476 size = cmsSpaceOld.collector().blockSizeUsingPrintezisBits(handle); | |
477 } else if ((cmsSpacePerm != null) && cmsSpacePerm.contains(handle) ){ | |
478 size = cmsSpacePerm.collector().blockSizeUsingPrintezisBits(handle); | |
479 } | |
480 | |
481 if (size <= 0) { | |
482 //Either Printezis bits not set or handle is not in cms space. | |
483 throw new UnknownOopException(); | |
484 } | |
485 | |
486 handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(size)); | |
487 continue; | |
488 } | |
489 if (of == null || of.canInclude(obj)) { | |
490 if (visitor.doObj(obj)) { | |
491 // doObj() returns true to abort this loop. | |
492 break; | |
493 } | |
494 } | |
495 if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle) || | |
496 (cmsSpacePerm != null) && cmsSpacePerm.contains(handle) ) { | |
497 handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(obj.getObjectSize()) ); | |
498 } else { | |
499 handle = handle.addOffsetToAsOopHandle(obj.getObjectSize()); | |
500 } | |
501 } | |
502 } | |
503 catch (AddressException e) { | |
504 // This is okay at the top of these regions | |
505 } | |
506 catch (UnknownOopException e) { | |
507 // This is okay at the top of these regions | |
508 } | |
509 } | |
510 | |
511 visitor.epilogue(); | |
512 } | |
513 | |
514 private void addPermGenLiveRegions(List output, CollectedHeap heap) { | |
515 LiveRegionsCollector lrc = new LiveRegionsCollector(output); | |
516 if (heap instanceof GenCollectedHeap) { | |
517 GenCollectedHeap genHeap = (GenCollectedHeap) heap; | |
518 Generation gen = genHeap.permGen(); | |
519 gen.spaceIterate(lrc, true); | |
520 } else if (heap instanceof ParallelScavengeHeap) { | |
521 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; | |
522 PSPermGen permGen = psh.permGen(); | |
523 addLiveRegions(permGen.objectSpace().getLiveRegions(), output); | |
524 } else { | |
525 if (Assert.ASSERTS_ENABLED) { | |
526 Assert.that(false, "Expecting GenCollectedHeap or ParallelScavengeHeap, but got " + | |
527 heap.getClass().getName()); | |
528 } | |
529 } | |
530 } | |
531 | |
532 private void addLiveRegions(List input, List output) { | |
533 for (Iterator itr = input.iterator(); itr.hasNext();) { | |
534 MemRegion reg = (MemRegion) itr.next(); | |
535 Address top = reg.end(); | |
536 Address bottom = reg.start(); | |
537 if (Assert.ASSERTS_ENABLED) { | |
538 Assert.that(top != null, "top address in a live region should not be null"); | |
539 } | |
540 if (Assert.ASSERTS_ENABLED) { | |
541 Assert.that(bottom != null, "bottom address in a live region should not be null"); | |
542 } | |
543 output.add(top); | |
544 output.add(bottom); | |
545 } | |
546 } | |
547 | |
548 private class LiveRegionsCollector implements SpaceClosure { | |
549 LiveRegionsCollector(List l) { | |
550 liveRegions = l; | |
551 } | |
552 | |
553 public void doSpace(Space s) { | |
554 addLiveRegions(s.getLiveRegions(), liveRegions); | |
555 } | |
556 private List liveRegions; | |
557 } | |
558 | |
559 // Returns a List<Address> where the addresses come in pairs. These | |
560 // designate the live regions of the heap. | |
561 private List collectLiveRegions() { | |
562 // We want to iterate through all live portions of the heap, but | |
563 // do not want to abort the heap traversal prematurely if we find | |
564 // a problem (like an allocated but uninitialized object at the | |
565 // top of a generation). To do this we enumerate all generations' | |
566 // bottom and top regions, and factor in TLABs if necessary. | |
567 | |
568 // List<Address>. Addresses come in pairs. | |
569 List liveRegions = new ArrayList(); | |
570 LiveRegionsCollector lrc = new LiveRegionsCollector(liveRegions); | |
571 | |
572 CollectedHeap heap = VM.getVM().getUniverse().heap(); | |
573 | |
574 if (heap instanceof GenCollectedHeap) { | |
575 GenCollectedHeap genHeap = (GenCollectedHeap) heap; | |
576 // Run through all generations, obtaining bottom-top pairs. | |
577 for (int i = 0; i < genHeap.nGens(); i++) { | |
578 Generation gen = genHeap.getGen(i); | |
579 gen.spaceIterate(lrc, true); | |
580 } | |
581 } else if (heap instanceof ParallelScavengeHeap) { | |
582 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; | |
583 PSYoungGen youngGen = psh.youngGen(); | |
584 // Add eden space | |
585 addLiveRegions(youngGen.edenSpace().getLiveRegions(), liveRegions); | |
586 // Add from-space but not to-space | |
587 addLiveRegions(youngGen.fromSpace().getLiveRegions(), liveRegions); | |
588 PSOldGen oldGen = psh.oldGen(); | |
589 addLiveRegions(oldGen.objectSpace().getLiveRegions(), liveRegions); | |
590 } else { | |
591 if (Assert.ASSERTS_ENABLED) { | |
592 Assert.that(false, "Expecting GenCollectedHeap or ParallelScavengeHeap, but got " + | |
593 heap.getClass().getName()); | |
594 } | |
595 } | |
596 | |
597 // handle perm generation | |
598 addPermGenLiveRegions(liveRegions, heap); | |
599 | |
600 // If UseTLAB is enabled, snip out regions associated with TLABs' | |
601 // dead regions. Note that TLABs can be present in any generation. | |
602 | |
603 // FIXME: consider adding fewer boundaries to live region list. | |
604 // Theoretically only need to stop at TLAB's top and resume at its | |
605 // end. | |
606 | |
607 if (VM.getVM().getUseTLAB()) { | |
608 for (JavaThread thread = VM.getVM().getThreads().first(); thread != null; thread = thread.next()) { | |
609 if (thread.isJavaThread()) { | |
610 ThreadLocalAllocBuffer tlab = thread.tlab(); | |
611 if (tlab.start() != null) { | |
612 if ((tlab.top() == null) || (tlab.end() == null)) { | |
613 System.err.print("Warning: skipping invalid TLAB for thread "); | |
614 thread.printThreadIDOn(System.err); | |
615 System.err.println(); | |
616 } else { | |
617 // Go from: | |
618 // - below start() to start() | |
619 // - start() to top() | |
620 // - end() and above | |
621 liveRegions.add(tlab.start()); | |
622 liveRegions.add(tlab.start()); | |
623 liveRegions.add(tlab.top()); | |
624 liveRegions.add(tlab.end()); | |
625 } | |
626 } | |
627 } | |
628 } | |
629 } | |
630 | |
631 // Now sort live regions | |
632 sortLiveRegions(liveRegions); | |
633 | |
634 if (Assert.ASSERTS_ENABLED) { | |
635 Assert.that(liveRegions.size() % 2 == 0, "Must have even number of region boundaries"); | |
636 } | |
637 | |
638 return liveRegions; | |
639 } | |
640 | |
641 private void sortLiveRegions(List liveRegions) { | |
642 Collections.sort(liveRegions, new Comparator() { | |
643 public int compare(Object o1, Object o2) { | |
644 Address a1 = (Address) o1; | |
645 Address a2 = (Address) o2; | |
646 if (AddressOps.lt(a1, a2)) { | |
647 return -1; | |
648 } else if (AddressOps.gt(a1, a2)) { | |
649 return 1; | |
650 } | |
651 return 0; | |
652 } | |
653 }); | |
654 } | |
655 } |