Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java @ 113:ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
author | coleenp |
---|---|
date | Sun, 13 Apr 2008 17:43:42 -0400 |
parents | a61af66fc99e |
children | d1605aabd0a1 a5838065ab24 |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact 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 | |
319 // Creates an instance from the Oop hierarchy based based on the handle | |
320 public Oop newOop(OopHandle handle) { | |
321 // The only known way to detect the right type of an oop is | |
322 // traversing the class chain until a well-known klass is recognized. | |
323 // A more direct solution would require the klasses to expose | |
324 // the C++ vtbl structure. | |
325 | |
326 // Handle the null reference | |
327 if (handle == null) return null; | |
328 | |
329 // First check if handle is one of the root objects | |
330 if (handle.equals(methodKlassHandle)) return getMethodKlassObj(); | |
331 if (handle.equals(constMethodKlassHandle)) return getConstMethodKlassObj(); | |
332 if (handle.equals(symbolKlassHandle)) return getSymbolKlassObj(); | |
333 if (handle.equals(constantPoolKlassHandle)) return getConstantPoolKlassObj(); | |
334 if (handle.equals(constantPoolCacheKlassHandle)) return getConstantPoolCacheKlassObj(); | |
335 if (handle.equals(instanceKlassKlassHandle)) return getInstanceKlassKlassObj(); | |
336 if (handle.equals(objArrayKlassKlassHandle)) return getObjArrayKlassKlassObj(); | |
337 if (handle.equals(klassKlassHandle)) return getKlassKlassObj(); | |
338 if (handle.equals(arrayKlassKlassHandle)) return getArrayKlassKlassObj(); | |
339 if (handle.equals(typeArrayKlassKlassHandle)) return getTypeArrayKlassKlassObj(); | |
340 if (handle.equals(boolArrayKlassHandle)) return getBoolArrayKlassObj(); | |
341 if (handle.equals(byteArrayKlassHandle)) return getByteArrayKlassObj(); | |
342 if (handle.equals(charArrayKlassHandle)) return getCharArrayKlassObj(); | |
343 if (handle.equals(intArrayKlassHandle)) return getIntArrayKlassObj(); | |
344 if (handle.equals(shortArrayKlassHandle)) return getShortArrayKlassObj(); | |
345 if (handle.equals(longArrayKlassHandle)) return getLongArrayKlassObj(); | |
346 if (handle.equals(singleArrayKlassHandle)) return getSingleArrayKlassObj(); | |
347 if (handle.equals(doubleArrayKlassHandle)) return getDoubleArrayKlassObj(); | |
348 if (!VM.getVM().isCore()) { | |
349 if (handle.equals(compiledICHolderKlassHandle)) return getCompiledICHolderKlassObj(); | |
350 if (handle.equals(methodDataKlassHandle)) return getMethodDataKlassObj(); | |
351 } | |
352 | |
353 // Then check if obj.klass() is one of the root objects | |
354 OopHandle klass = Oop.getKlassForOopHandle(handle); | |
355 if (klass != null) { | |
356 if (klass.equals(methodKlassHandle)) return new Method(handle, this); | |
357 if (klass.equals(constMethodKlassHandle)) return new ConstMethod(handle, this); | |
358 if (klass.equals(symbolKlassHandle)) return new Symbol(handle, this); | |
359 if (klass.equals(constantPoolKlassHandle)) return new ConstantPool(handle, this); | |
360 if (klass.equals(constantPoolCacheKlassHandle)) return new ConstantPoolCache(handle, this); | |
361 if (!VM.getVM().isCore()) { | |
362 if (klass.equals(compiledICHolderKlassHandle)) return new CompiledICHolder(handle, this); | |
363 if (klass.equals(methodDataKlassHandle)) return new MethodData(handle, this); | |
364 } | |
365 if (klass.equals(instanceKlassKlassHandle)) return new InstanceKlass(handle, this); | |
366 if (klass.equals(objArrayKlassKlassHandle)) return new ObjArrayKlass(handle, this); | |
367 if (klass.equals(typeArrayKlassKlassHandle)) return new TypeArrayKlass(handle, this); | |
368 | |
369 // Lastly check if obj.klass().klass() is on of the root objects | |
370 OopHandle klassKlass = Oop.getKlassForOopHandle(klass); | |
371 if (klassKlass != null) { | |
372 if (klassKlass.equals(instanceKlassKlassHandle)) return new Instance(handle, this); | |
373 if (klassKlass.equals(objArrayKlassKlassHandle)) return new ObjArray(handle, this); | |
374 if (klassKlass.equals(typeArrayKlassKlassHandle)) return new TypeArray(handle, this); | |
375 } | |
376 } | |
377 | |
378 System.err.println("Unknown oop at " + handle); | |
379 System.err.println("Oop's klass is " + klass); | |
380 | |
381 throw new UnknownOopException(); | |
382 } | |
383 | |
384 // Print all objects in the object heap | |
385 public void print() { | |
386 HeapPrinter printer = new HeapPrinter(System.out); | |
387 iterate(printer); | |
388 } | |
389 | |
390 //--------------------------------------------------------------------------- | |
391 // Internals only below this point | |
392 // | |
393 | |
394 private void iterateExact(HeapVisitor visitor, final Klass k) { | |
395 iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() { | |
396 public boolean canInclude(Oop obj) { | |
397 Klass tk = obj.getKlass(); | |
398 // null Klass is seen sometimes! | |
399 return (tk != null && tk.equals(k)); | |
400 } | |
401 }); | |
402 } | |
403 | |
404 private void iterateSubtypes(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.isSubtypeOf(k)); | |
410 } | |
411 }); | |
412 } | |
413 | |
414 private void iterateLiveRegions(List liveRegions, HeapVisitor visitor, ObjectFilter of) { | |
415 // Summarize size | |
416 long totalSize = 0; | |
417 for (int i = 0; i < liveRegions.size(); i += 2) { | |
418 Address bottom = (Address) liveRegions.get(i); | |
419 Address top = (Address) liveRegions.get(i+1); | |
420 totalSize += top.minus(bottom); | |
421 } | |
422 visitor.prologue(totalSize); | |
423 | |
424 CompactibleFreeListSpace cmsSpaceOld = null; | |
425 CompactibleFreeListSpace cmsSpacePerm = null; | |
426 CollectedHeap heap = VM.getVM().getUniverse().heap(); | |
427 | |
428 if (heap instanceof GenCollectedHeap) { | |
429 GenCollectedHeap genHeap = (GenCollectedHeap) heap; | |
430 Generation genOld = genHeap.getGen(1); | |
431 Generation genPerm = genHeap.permGen(); | |
432 if (genOld instanceof ConcurrentMarkSweepGeneration) { | |
433 ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genOld; | |
434 cmsSpaceOld = concGen.cmsSpace(); | |
435 } | |
436 if (genPerm instanceof ConcurrentMarkSweepGeneration) { | |
437 ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genPerm; | |
438 cmsSpacePerm = concGen.cmsSpace(); | |
439 } | |
440 } | |
441 | |
442 for (int i = 0; i < liveRegions.size(); i += 2) { | |
443 Address bottom = (Address) liveRegions.get(i); | |
444 Address top = (Address) liveRegions.get(i+1); | |
445 | |
446 try { | |
447 // Traverses the space from bottom to top | |
448 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
|
449 |
0 | 450 while (handle.lessThan(top)) { |
451 Oop obj = null; | |
452 | |
453 try { | |
454 obj = newOop(handle); | |
455 } catch (UnknownOopException exp) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
456 if (DEBUG) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
457 throw new RuntimeException(" UnknownOopException " + exp); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
458 } |
0 | 459 } |
460 if (obj == null) { | |
461 //Find the object size using Printezis bits and skip over | |
462 System.err.println("Finding object size using Printezis bits and skipping over..."); | |
463 long size = 0; | |
464 | |
465 if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle) ){ | |
466 size = cmsSpaceOld.collector().blockSizeUsingPrintezisBits(handle); | |
467 } else if ((cmsSpacePerm != null) && cmsSpacePerm.contains(handle) ){ | |
468 size = cmsSpacePerm.collector().blockSizeUsingPrintezisBits(handle); | |
469 } | |
470 | |
471 if (size <= 0) { | |
472 //Either Printezis bits not set or handle is not in cms space. | |
473 throw new UnknownOopException(); | |
474 } | |
475 | |
476 handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(size)); | |
477 continue; | |
478 } | |
479 if (of == null || of.canInclude(obj)) { | |
480 if (visitor.doObj(obj)) { | |
481 // doObj() returns true to abort this loop. | |
482 break; | |
483 } | |
484 } | |
485 if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle) || | |
486 (cmsSpacePerm != null) && cmsSpacePerm.contains(handle) ) { | |
487 handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(obj.getObjectSize()) ); | |
488 } else { | |
489 handle = handle.addOffsetToAsOopHandle(obj.getObjectSize()); | |
490 } | |
491 } | |
492 } | |
493 catch (AddressException e) { | |
494 // This is okay at the top of these regions | |
495 } | |
496 catch (UnknownOopException e) { | |
497 // This is okay at the top of these regions | |
498 } | |
499 } | |
500 | |
501 visitor.epilogue(); | |
502 } | |
503 | |
504 private void addPermGenLiveRegions(List output, CollectedHeap heap) { | |
505 LiveRegionsCollector lrc = new LiveRegionsCollector(output); | |
506 if (heap instanceof GenCollectedHeap) { | |
507 GenCollectedHeap genHeap = (GenCollectedHeap) heap; | |
508 Generation gen = genHeap.permGen(); | |
509 gen.spaceIterate(lrc, true); | |
510 } else if (heap instanceof ParallelScavengeHeap) { | |
511 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; | |
512 PSPermGen permGen = psh.permGen(); | |
513 addLiveRegions(permGen.objectSpace().getLiveRegions(), output); | |
514 } else { | |
515 if (Assert.ASSERTS_ENABLED) { | |
516 Assert.that(false, "Expecting GenCollectedHeap or ParallelScavengeHeap, but got " + | |
517 heap.getClass().getName()); | |
518 } | |
519 } | |
520 } | |
521 | |
522 private void addLiveRegions(List input, List output) { | |
523 for (Iterator itr = input.iterator(); itr.hasNext();) { | |
524 MemRegion reg = (MemRegion) itr.next(); | |
525 Address top = reg.end(); | |
526 Address bottom = reg.start(); | |
527 if (Assert.ASSERTS_ENABLED) { | |
528 Assert.that(top != null, "top address in a live region should not be null"); | |
529 } | |
530 if (Assert.ASSERTS_ENABLED) { | |
531 Assert.that(bottom != null, "bottom address in a live region should not be null"); | |
532 } | |
533 output.add(top); | |
534 output.add(bottom); | |
535 } | |
536 } | |
537 | |
538 private class LiveRegionsCollector implements SpaceClosure { | |
539 LiveRegionsCollector(List l) { | |
540 liveRegions = l; | |
541 } | |
542 | |
543 public void doSpace(Space s) { | |
544 addLiveRegions(s.getLiveRegions(), liveRegions); | |
545 } | |
546 private List liveRegions; | |
547 } | |
548 | |
549 // Returns a List<Address> where the addresses come in pairs. These | |
550 // designate the live regions of the heap. | |
551 private List collectLiveRegions() { | |
552 // We want to iterate through all live portions of the heap, but | |
553 // do not want to abort the heap traversal prematurely if we find | |
554 // a problem (like an allocated but uninitialized object at the | |
555 // top of a generation). To do this we enumerate all generations' | |
556 // bottom and top regions, and factor in TLABs if necessary. | |
557 | |
558 // List<Address>. Addresses come in pairs. | |
559 List liveRegions = new ArrayList(); | |
560 LiveRegionsCollector lrc = new LiveRegionsCollector(liveRegions); | |
561 | |
562 CollectedHeap heap = VM.getVM().getUniverse().heap(); | |
563 | |
564 if (heap instanceof GenCollectedHeap) { | |
565 GenCollectedHeap genHeap = (GenCollectedHeap) heap; | |
566 // Run through all generations, obtaining bottom-top pairs. | |
567 for (int i = 0; i < genHeap.nGens(); i++) { | |
568 Generation gen = genHeap.getGen(i); | |
569 gen.spaceIterate(lrc, true); | |
570 } | |
571 } else if (heap instanceof ParallelScavengeHeap) { | |
572 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; | |
573 PSYoungGen youngGen = psh.youngGen(); | |
574 // Add eden space | |
575 addLiveRegions(youngGen.edenSpace().getLiveRegions(), liveRegions); | |
576 // Add from-space but not to-space | |
577 addLiveRegions(youngGen.fromSpace().getLiveRegions(), liveRegions); | |
578 PSOldGen oldGen = psh.oldGen(); | |
579 addLiveRegions(oldGen.objectSpace().getLiveRegions(), liveRegions); | |
580 } else { | |
581 if (Assert.ASSERTS_ENABLED) { | |
582 Assert.that(false, "Expecting GenCollectedHeap or ParallelScavengeHeap, but got " + | |
583 heap.getClass().getName()); | |
584 } | |
585 } | |
586 | |
587 // handle perm generation | |
588 addPermGenLiveRegions(liveRegions, heap); | |
589 | |
590 // If UseTLAB is enabled, snip out regions associated with TLABs' | |
591 // dead regions. Note that TLABs can be present in any generation. | |
592 | |
593 // FIXME: consider adding fewer boundaries to live region list. | |
594 // Theoretically only need to stop at TLAB's top and resume at its | |
595 // end. | |
596 | |
597 if (VM.getVM().getUseTLAB()) { | |
598 for (JavaThread thread = VM.getVM().getThreads().first(); thread != null; thread = thread.next()) { | |
599 if (thread.isJavaThread()) { | |
600 ThreadLocalAllocBuffer tlab = thread.tlab(); | |
601 if (tlab.start() != null) { | |
602 if ((tlab.top() == null) || (tlab.end() == null)) { | |
603 System.err.print("Warning: skipping invalid TLAB for thread "); | |
604 thread.printThreadIDOn(System.err); | |
605 System.err.println(); | |
606 } else { | |
607 // Go from: | |
608 // - below start() to start() | |
609 // - start() to top() | |
610 // - end() and above | |
611 liveRegions.add(tlab.start()); | |
612 liveRegions.add(tlab.start()); | |
613 liveRegions.add(tlab.top()); | |
614 liveRegions.add(tlab.end()); | |
615 } | |
616 } | |
617 } | |
618 } | |
619 } | |
620 | |
621 // Now sort live regions | |
622 sortLiveRegions(liveRegions); | |
623 | |
624 if (Assert.ASSERTS_ENABLED) { | |
625 Assert.that(liveRegions.size() % 2 == 0, "Must have even number of region boundaries"); | |
626 } | |
627 | |
628 return liveRegions; | |
629 } | |
630 | |
631 private void sortLiveRegions(List liveRegions) { | |
632 Collections.sort(liveRegions, new Comparator() { | |
633 public int compare(Object o1, Object o2) { | |
634 Address a1 = (Address) o1; | |
635 Address a2 = (Address) o2; | |
636 if (AddressOps.lt(a1, a2)) { | |
637 return -1; | |
638 } else if (AddressOps.gt(a1, a2)) { | |
639 return 1; | |
640 } | |
641 return 0; | |
642 } | |
643 }); | |
644 } | |
645 } |