annotate agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java @ 2177:3582bf76420e

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