annotate agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java @ 196:d1605aabd0a1 jdk7-b30

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