annotate agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java @ 17467:55fb97c4c58d hs25-b65

8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013 Summary: Copyright year updated for files modified during 2013 Reviewed-by: twisti, iveresov
author mikael
date Tue, 24 Dec 2013 11:48:39 -0800
parents a4f036ef52e8
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 13431
diff changeset
2 * Copyright (c) 2000, 2013, 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.*;
3972
4f93f0d00802 7059019: G1: add G1 support to the SA
tonyp
parents: 2411
diff changeset
36 import sun.jvm.hotspot.gc_implementation.g1.*;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 public class ObjectHeap {
a61af66fc99e Initial load
duke
parents:
diff changeset
44
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
45 private static final boolean DEBUG;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
46
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
47 static {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
48 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
49 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
50
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
51 private Address boolArrayKlassHandle;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
52 private Address byteArrayKlassHandle;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
53 private Address charArrayKlassHandle;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
54 private Address intArrayKlassHandle;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
55 private Address shortArrayKlassHandle;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
56 private Address longArrayKlassHandle;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
57 private Address singleArrayKlassHandle;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
58 private Address doubleArrayKlassHandle;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private TypeArrayKlass boolArrayKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private TypeArrayKlass byteArrayKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private TypeArrayKlass charArrayKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private TypeArrayKlass intArrayKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private TypeArrayKlass shortArrayKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private TypeArrayKlass longArrayKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private TypeArrayKlass singleArrayKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private TypeArrayKlass doubleArrayKlassObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public void initialize(TypeDataBase db) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Lookup the roots in the object hierarchy.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 Type universeType = db.lookupType("Universe");
a61af66fc99e Initial load
duke
parents:
diff changeset
72
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
73 boolArrayKlassHandle = universeType.getAddressField("_boolArrayKlassObj").getValue();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
74 boolArrayKlassObj = new TypeArrayKlass(boolArrayKlassHandle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
75
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
76 byteArrayKlassHandle = universeType.getAddressField("_byteArrayKlassObj").getValue();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
77 byteArrayKlassObj = new TypeArrayKlass(byteArrayKlassHandle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
78
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
79 charArrayKlassHandle = universeType.getAddressField("_charArrayKlassObj").getValue();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
80 charArrayKlassObj = new TypeArrayKlass(charArrayKlassHandle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
81
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
82 intArrayKlassHandle = universeType.getAddressField("_intArrayKlassObj").getValue();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
83 intArrayKlassObj = new TypeArrayKlass(intArrayKlassHandle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
84
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
85 shortArrayKlassHandle = universeType.getAddressField("_shortArrayKlassObj").getValue();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
86 shortArrayKlassObj = new TypeArrayKlass(shortArrayKlassHandle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
87
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
88 longArrayKlassHandle = universeType.getAddressField("_longArrayKlassObj").getValue();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
89 longArrayKlassObj = new TypeArrayKlass(longArrayKlassHandle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
90
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
91 singleArrayKlassHandle = universeType.getAddressField("_singleArrayKlassObj").getValue();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
92 singleArrayKlassObj = new TypeArrayKlass(singleArrayKlassHandle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
93
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
94 doubleArrayKlassHandle = universeType.getAddressField("_doubleArrayKlassObj").getValue();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
95 doubleArrayKlassObj = new TypeArrayKlass(doubleArrayKlassHandle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 public ObjectHeap(TypeDataBase db) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // 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
100 oopSize = VM.getVM().getOopSize();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101 byteSize = db.getJByteType().getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 charSize = db.getJCharType().getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 booleanSize = db.getJBooleanType().getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 intSize = db.getJIntType().getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 shortSize = db.getJShortType().getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 longSize = db.getJLongType().getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 floatSize = db.getJFloatType().getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 doubleSize = db.getJDoubleType().getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 initialize(db);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 /** Comparison operation for oops, either or both of which may be null */
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public boolean equal(Oop o1, Oop o2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 if (o1 != null) return o1.equals(o2);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return (o2 == null);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Cached sizes of basic types
a61af66fc99e Initial load
duke
parents:
diff changeset
120 private long oopSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 private long byteSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 private long charSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 private long booleanSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 private long intSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 private long shortSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 private long longSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 private long floatSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 private long doubleSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public long getOopSize() { return oopSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public long getByteSize() { return byteSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public long getCharSize() { return charSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public long getBooleanSize() { return booleanSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 public long getIntSize() { return intSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 public long getShortSize() { return shortSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public long getLongSize() { return longSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public long getFloatSize() { return floatSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public long getDoubleSize() { return doubleSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // Accessors for well-known system classes (from Universe)
a61af66fc99e Initial load
duke
parents:
diff changeset
141 public TypeArrayKlass getBoolArrayKlassObj() { return boolArrayKlassObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 public TypeArrayKlass getByteArrayKlassObj() { return byteArrayKlassObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public TypeArrayKlass getCharArrayKlassObj() { return charArrayKlassObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 public TypeArrayKlass getIntArrayKlassObj() { return intArrayKlassObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 public TypeArrayKlass getShortArrayKlassObj() { return shortArrayKlassObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 public TypeArrayKlass getLongArrayKlassObj() { return longArrayKlassObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 public TypeArrayKlass getSingleArrayKlassObj() { return singleArrayKlassObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 public TypeArrayKlass getDoubleArrayKlassObj() { return doubleArrayKlassObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 /** Takes a BasicType and returns the corresponding primitive array
a61af66fc99e Initial load
duke
parents:
diff changeset
151 klass */
a61af66fc99e Initial load
duke
parents:
diff changeset
152 public Klass typeArrayKlassObj(int t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (t == BasicType.getTBoolean()) return getBoolArrayKlassObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (t == BasicType.getTChar()) return getCharArrayKlassObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
155 if (t == BasicType.getTFloat()) return getSingleArrayKlassObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (t == BasicType.getTDouble()) return getDoubleArrayKlassObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if (t == BasicType.getTByte()) return getByteArrayKlassObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
158 if (t == BasicType.getTShort()) return getShortArrayKlassObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (t == BasicType.getTInt()) return getIntArrayKlassObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (t == BasicType.getTLong()) return getLongArrayKlassObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 throw new RuntimeException("Illegal basic type " + t);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 /** an interface to filter objects while walking heap */
a61af66fc99e Initial load
duke
parents:
diff changeset
165 public static interface ObjectFilter {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 public boolean canInclude(Oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 /** The base heap iteration mechanism */
a61af66fc99e Initial load
duke
parents:
diff changeset
170 public void iterate(HeapVisitor visitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 iterateLiveRegions(collectLiveRegions(), visitor, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 /** iterate objects satisfying a specified ObjectFilter */
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public void iterate(HeapVisitor visitor, ObjectFilter of) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 iterateLiveRegions(collectLiveRegions(), visitor, of);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 /** iterate objects of given Klass. param 'includeSubtypes' tells whether to
a61af66fc99e Initial load
duke
parents:
diff changeset
180 * include objects of subtypes or not */
a61af66fc99e Initial load
duke
parents:
diff changeset
181 public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k, boolean includeSubtypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 if (includeSubtypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (k.isFinal()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // do the simpler "exact" klass loop
a61af66fc99e Initial load
duke
parents:
diff changeset
185 iterateExact(visitor, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 iterateSubtypes(visitor, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // there can no object of abstract classes and interfaces
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (!k.isAbstract() && !k.isInterface()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 iterateExact(visitor, k);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 /** iterate objects of given Klass (objects of subtypes included) */
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 iterateObjectsOfKlass(visitor, k, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 /** This routine can be used to iterate through the heap at an
a61af66fc99e Initial load
duke
parents:
diff changeset
203 extremely low level (stepping word-by-word) to provide the
a61af66fc99e Initial load
duke
parents:
diff changeset
204 ability to do very low-level debugging */
a61af66fc99e Initial load
duke
parents:
diff changeset
205 public void iterateRaw(RawHeapVisitor visitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 List liveRegions = collectLiveRegions();
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // Summarize size
a61af66fc99e Initial load
duke
parents:
diff changeset
209 long totalSize = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 for (int i = 0; i < liveRegions.size(); i += 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 Address bottom = (Address) liveRegions.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 Address top = (Address) liveRegions.get(i+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 totalSize += top.minus(bottom);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 visitor.prologue(totalSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 for (int i = 0; i < liveRegions.size(); i += 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 Address bottom = (Address) liveRegions.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 Address top = (Address) liveRegions.get(i+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Traverses the space from bottom to top
a61af66fc99e Initial load
duke
parents:
diff changeset
222 while (bottom.lessThan(top)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 visitor.visitAddress(bottom);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 bottom = bottom.addOffsetTo(VM.getVM().getAddressSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 visitor.epilogue();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
231 public boolean isValidMethod(Address handle) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
232 try {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
233 Method m = (Method)Metadata.instantiateWrapperFor(handle);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
234 return true;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
235 } catch (Exception e) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
236 return false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
218
a5838065ab24 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 113
diff changeset
238 }
a5838065ab24 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 113
diff changeset
239
0
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // Creates an instance from the Oop hierarchy based based on the handle
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public Oop newOop(OopHandle handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // The only known way to detect the right type of an oop is
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // traversing the class chain until a well-known klass is recognized.
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // A more direct solution would require the klasses to expose
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // the C++ vtbl structure.
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // Handle the null reference
a61af66fc99e Initial load
duke
parents:
diff changeset
248 if (handle == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // Then check if obj.klass() is one of the root objects
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
251 Klass klass = Oop.getKlassForOopHandle(handle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if (klass != null) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
253 if (klass instanceof TypeArrayKlass) return new TypeArray(handle, this);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
254 if (klass instanceof ObjArrayKlass) return new ObjArray(handle, this);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
255 if (klass instanceof InstanceKlass) return new Instance(handle, this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257
218
a5838065ab24 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 113
diff changeset
258 if (DEBUG) {
a5838065ab24 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 113
diff changeset
259 System.err.println("Unknown oop at " + handle);
a5838065ab24 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 113
diff changeset
260 System.err.println("Oop's klass is " + klass);
a5838065ab24 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 113
diff changeset
261 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 throw new UnknownOopException();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // Print all objects in the object heap
a61af66fc99e Initial load
duke
parents:
diff changeset
267 public void print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 HeapPrinter printer = new HeapPrinter(System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 iterate(printer);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 //---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
274 //
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 private void iterateExact(HeapVisitor visitor, final Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 public boolean canInclude(Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 Klass tk = obj.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // null Klass is seen sometimes!
a61af66fc99e Initial load
duke
parents:
diff changeset
281 return (tk != null && tk.equals(k));
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283 });
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 private void iterateSubtypes(HeapVisitor visitor, final Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 public boolean canInclude(Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 Klass tk = obj.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // null Klass is seen sometimes!
a61af66fc99e Initial load
duke
parents:
diff changeset
291 return (tk != null && tk.isSubtypeOf(k));
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 });
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 private void iterateLiveRegions(List liveRegions, HeapVisitor visitor, ObjectFilter of) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // Summarize size
a61af66fc99e Initial load
duke
parents:
diff changeset
298 long totalSize = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 for (int i = 0; i < liveRegions.size(); i += 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 Address bottom = (Address) liveRegions.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 Address top = (Address) liveRegions.get(i+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
302 totalSize += top.minus(bottom);
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 visitor.prologue(totalSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 CompactibleFreeListSpace cmsSpaceOld = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 CollectedHeap heap = VM.getVM().getUniverse().heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (heap instanceof GenCollectedHeap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 GenCollectedHeap genHeap = (GenCollectedHeap) heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 Generation genOld = genHeap.getGen(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 if (genOld instanceof ConcurrentMarkSweepGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genOld;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 cmsSpaceOld = concGen.cmsSpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 for (int i = 0; i < liveRegions.size(); i += 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 Address bottom = (Address) liveRegions.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 Address top = (Address) liveRegions.get(i+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // Traverses the space from bottom to top
a61af66fc99e Initial load
duke
parents:
diff changeset
324 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
325
0
a61af66fc99e Initial load
duke
parents:
diff changeset
326 while (handle.lessThan(top)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 Oop obj = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 obj = newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 } catch (UnknownOopException exp) {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
332 if (DEBUG) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
333 throw new RuntimeException(" UnknownOopException " + exp);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
334 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 //Find the object size using Printezis bits and skip over
a61af66fc99e Initial load
duke
parents:
diff changeset
338 long size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle) ){
a61af66fc99e Initial load
duke
parents:
diff changeset
341 size = cmsSpaceOld.collector().blockSizeUsingPrintezisBits(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (size <= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 //Either Printezis bits not set or handle is not in cms space.
a61af66fc99e Initial load
duke
parents:
diff changeset
346 throw new UnknownOopException();
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(size));
a61af66fc99e Initial load
duke
parents:
diff changeset
350 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 if (of == null || of.canInclude(obj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 if (visitor.doObj(obj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 // doObj() returns true to abort this loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
355 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3972
diff changeset
358 if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
359 handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(obj.getObjectSize()) );
a61af66fc99e Initial load
duke
parents:
diff changeset
360 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 handle = handle.addOffsetToAsOopHandle(obj.getObjectSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 // This is okay at the top of these regions
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
367 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
368 catch (UnknownOopException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // This is okay at the top of these regions
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 visitor.epilogue();
a61af66fc99e Initial load
duke
parents:
diff changeset
374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
375
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
376 private void addLiveRegions(String name, List input, List output) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
377 for (Iterator itr = input.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 MemRegion reg = (MemRegion) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
379 Address top = reg.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
380 Address bottom = reg.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
381 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 Assert.that(top != null, "top address in a live region should not be null");
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 Assert.that(bottom != null, "bottom address in a live region should not be null");
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387 output.add(top);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 output.add(bottom);
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
389 if (DEBUG) {
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
390 System.err.println("Live region: " + name + ": " + bottom + ", " + top);
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
391 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 private class LiveRegionsCollector implements SpaceClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 LiveRegionsCollector(List l) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 liveRegions = l;
a61af66fc99e Initial load
duke
parents:
diff changeset
398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
399
a61af66fc99e Initial load
duke
parents:
diff changeset
400 public void doSpace(Space s) {
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
401 addLiveRegions(s.toString(), s.getLiveRegions(), liveRegions);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 private List liveRegions;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 // Returns a List<Address> where the addresses come in pairs. These
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // designate the live regions of the heap.
a61af66fc99e Initial load
duke
parents:
diff changeset
408 private List collectLiveRegions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // We want to iterate through all live portions of the heap, but
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // do not want to abort the heap traversal prematurely if we find
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // a problem (like an allocated but uninitialized object at the
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // top of a generation). To do this we enumerate all generations'
a61af66fc99e Initial load
duke
parents:
diff changeset
413 // bottom and top regions, and factor in TLABs if necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // List<Address>. Addresses come in pairs.
a61af66fc99e Initial load
duke
parents:
diff changeset
416 List liveRegions = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
417 LiveRegionsCollector lrc = new LiveRegionsCollector(liveRegions);
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 CollectedHeap heap = VM.getVM().getUniverse().heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 if (heap instanceof GenCollectedHeap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 GenCollectedHeap genHeap = (GenCollectedHeap) heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // Run through all generations, obtaining bottom-top pairs.
a61af66fc99e Initial load
duke
parents:
diff changeset
424 for (int i = 0; i < genHeap.nGens(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 Generation gen = genHeap.getGen(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 gen.spaceIterate(lrc, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428 } else if (heap instanceof ParallelScavengeHeap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
429 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
430 PSYoungGen youngGen = psh.youngGen();
a61af66fc99e Initial load
duke
parents:
diff changeset
431 // Add eden space
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
432 addLiveRegions("eden", youngGen.edenSpace().getLiveRegions(), liveRegions);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
433 // Add from-space but not to-space
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
434 addLiveRegions("from", youngGen.fromSpace().getLiveRegions(), liveRegions);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
435 PSOldGen oldGen = psh.oldGen();
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
436 addLiveRegions("old ", oldGen.objectSpace().getLiveRegions(), liveRegions);
3972
4f93f0d00802 7059019: G1: add G1 support to the SA
tonyp
parents: 2411
diff changeset
437 } else if (heap instanceof G1CollectedHeap) {
4f93f0d00802 7059019: G1: add G1 support to the SA
tonyp
parents: 2411
diff changeset
438 G1CollectedHeap g1h = (G1CollectedHeap) heap;
4f93f0d00802 7059019: G1: add G1 support to the SA
tonyp
parents: 2411
diff changeset
439 g1h.heapRegionIterate(lrc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
440 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 if (Assert.ASSERTS_ENABLED) {
3972
4f93f0d00802 7059019: G1: add G1 support to the SA
tonyp
parents: 2411
diff changeset
442 Assert.that(false, "Expecting GenCollectedHeap, G1CollectedHeap, " +
4f93f0d00802 7059019: G1: add G1 support to the SA
tonyp
parents: 2411
diff changeset
443 "or ParallelScavengeHeap, but got " +
4f93f0d00802 7059019: G1: add G1 support to the SA
tonyp
parents: 2411
diff changeset
444 heap.getClass().getName());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 // If UseTLAB is enabled, snip out regions associated with TLABs'
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // dead regions. Note that TLABs can be present in any generation.
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // FIXME: consider adding fewer boundaries to live region list.
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // Theoretically only need to stop at TLAB's top and resume at its
a61af66fc99e Initial load
duke
parents:
diff changeset
453 // end.
a61af66fc99e Initial load
duke
parents:
diff changeset
454
a61af66fc99e Initial load
duke
parents:
diff changeset
455 if (VM.getVM().getUseTLAB()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
456 for (JavaThread thread = VM.getVM().getThreads().first(); thread != null; thread = thread.next()) {
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
457 ThreadLocalAllocBuffer tlab = thread.tlab();
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
458 if (tlab.start() != null) {
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
459 if ((tlab.top() == null) || (tlab.end() == null)) {
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
460 System.err.print("Warning: skipping invalid TLAB for thread ");
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
461 thread.printThreadIDOn(System.err);
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
462 System.err.println();
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
463 } else {
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
464 if (DEBUG) {
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
465 System.err.print("TLAB for " + thread.getThreadName() + ", #");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
466 thread.printThreadIDOn(System.err);
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
467 System.err.print(": ");
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
468 tlab.printOn(System.err);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
470 // Go from:
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
471 // - below start() to start()
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
472 // - start() to top()
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
473 // - end() and above
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
474 liveRegions.add(tlab.start());
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
475 liveRegions.add(tlab.start());
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
476 liveRegions.add(tlab.top());
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
477 liveRegions.add(tlab.hardEnd());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // Now sort live regions
a61af66fc99e Initial load
duke
parents:
diff changeset
484 sortLiveRegions(liveRegions);
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 Assert.that(liveRegions.size() % 2 == 0, "Must have even number of region boundaries");
a61af66fc99e Initial load
duke
parents:
diff changeset
488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
489
13431
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
490 if (DEBUG) {
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
491 System.err.println("liveRegions:");
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
492 for (int i = 0; i < liveRegions.size(); i += 2) {
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
493 Address bottom = (Address) liveRegions.get(i);
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
494 Address top = (Address) liveRegions.get(i+1);
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
495 System.err.println(" " + bottom + " - " + top);
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
496 }
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
497 }
a4f036ef52e8 8029395: SA: jstack throws WrongTypeException
sla
parents: 8059
diff changeset
498
0
a61af66fc99e Initial load
duke
parents:
diff changeset
499 return liveRegions;
a61af66fc99e Initial load
duke
parents:
diff changeset
500 }
a61af66fc99e Initial load
duke
parents:
diff changeset
501
a61af66fc99e Initial load
duke
parents:
diff changeset
502 private void sortLiveRegions(List liveRegions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 Collections.sort(liveRegions, new Comparator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
504 public int compare(Object o1, Object o2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 Address a1 = (Address) o1;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 Address a2 = (Address) o2;
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (AddressOps.lt(a1, a2)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
509 } else if (AddressOps.gt(a1, a2)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
510 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 }
a61af66fc99e Initial load
duke
parents:
diff changeset
512 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 });
a61af66fc99e Initial load
duke
parents:
diff changeset
515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }