author | rehn |
Tue, 21 May 2019 10:34:57 +0200 | |
changeset 54955 | 46409371a691 |
parent 54388 | a1acc800c87a |
child 55404 | 8259c22be42c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
781
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
781
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
781
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
// |
|
26 |
// The ObjectHeap is an abstraction over all generations in the VM |
|
27 |
// It gives access to all present objects and classes. |
|
28 |
// |
|
29 |
||
30 |
package sun.jvm.hotspot.oops; |
|
31 |
||
32 |
import java.util.*; |
|
33 |
||
34 |
import sun.jvm.hotspot.debugger.*; |
|
30769 | 35 |
import sun.jvm.hotspot.gc.cms.*; |
30764 | 36 |
import sun.jvm.hotspot.gc.shared.*; |
50523
7b7c75d87f9b
8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
47216
diff
changeset
|
37 |
import sun.jvm.hotspot.gc.epsilon.*; |
30764 | 38 |
import sun.jvm.hotspot.gc.g1.*; |
52925
9c18c9d839d3
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents:
51741
diff
changeset
|
39 |
import sun.jvm.hotspot.gc.shenandoah.*; |
30764 | 40 |
import sun.jvm.hotspot.gc.parallel.*; |
51741
ed9b1200dd81
8209163: SA: Show Object Histogram asserts with ZGC
pliden
parents:
51554
diff
changeset
|
41 |
import sun.jvm.hotspot.gc.z.*; |
1 | 42 |
import sun.jvm.hotspot.memory.*; |
43 |
import sun.jvm.hotspot.runtime.*; |
|
44 |
import sun.jvm.hotspot.types.*; |
|
45 |
import sun.jvm.hotspot.utilities.*; |
|
46 |
||
47 |
public class ObjectHeap { |
|
48 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
49 |
private static final boolean DEBUG; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
50 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
51 |
static { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
52 |
DEBUG = System.getProperty("sun.jvm.hotspot.oops.ObjectHeap.DEBUG") != null; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
53 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
54 |
|
1 | 55 |
public ObjectHeap(TypeDataBase db) throws WrongTypeException { |
56 |
// Get commonly used sizes of basic types |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
57 |
oopSize = VM.getVM().getOopSize(); |
1 | 58 |
byteSize = db.getJByteType().getSize(); |
59 |
charSize = db.getJCharType().getSize(); |
|
60 |
booleanSize = db.getJBooleanType().getSize(); |
|
61 |
intSize = db.getJIntType().getSize(); |
|
62 |
shortSize = db.getJShortType().getSize(); |
|
63 |
longSize = db.getJLongType().getSize(); |
|
64 |
floatSize = db.getJFloatType().getSize(); |
|
65 |
doubleSize = db.getJDoubleType().getSize(); |
|
66 |
} |
|
67 |
||
68 |
/** Comparison operation for oops, either or both of which may be null */ |
|
69 |
public boolean equal(Oop o1, Oop o2) { |
|
70 |
if (o1 != null) return o1.equals(o2); |
|
71 |
return (o2 == null); |
|
72 |
} |
|
73 |
||
74 |
// Cached sizes of basic types |
|
75 |
private long oopSize; |
|
76 |
private long byteSize; |
|
77 |
private long charSize; |
|
78 |
private long booleanSize; |
|
79 |
private long intSize; |
|
80 |
private long shortSize; |
|
81 |
private long longSize; |
|
82 |
private long floatSize; |
|
83 |
private long doubleSize; |
|
84 |
||
85 |
public long getOopSize() { return oopSize; } |
|
86 |
public long getByteSize() { return byteSize; } |
|
87 |
public long getCharSize() { return charSize; } |
|
88 |
public long getBooleanSize() { return booleanSize; } |
|
89 |
public long getIntSize() { return intSize; } |
|
90 |
public long getShortSize() { return shortSize; } |
|
91 |
public long getLongSize() { return longSize; } |
|
92 |
public long getFloatSize() { return floatSize; } |
|
93 |
public long getDoubleSize() { return doubleSize; } |
|
94 |
||
95 |
/** an interface to filter objects while walking heap */ |
|
96 |
public static interface ObjectFilter { |
|
97 |
public boolean canInclude(Oop obj); |
|
98 |
} |
|
99 |
||
100 |
/** The base heap iteration mechanism */ |
|
101 |
public void iterate(HeapVisitor visitor) { |
|
102 |
iterateLiveRegions(collectLiveRegions(), visitor, null); |
|
103 |
} |
|
104 |
||
105 |
/** iterate objects satisfying a specified ObjectFilter */ |
|
106 |
public void iterate(HeapVisitor visitor, ObjectFilter of) { |
|
107 |
iterateLiveRegions(collectLiveRegions(), visitor, of); |
|
108 |
} |
|
109 |
||
110 |
/** iterate objects of given Klass. param 'includeSubtypes' tells whether to |
|
111 |
* include objects of subtypes or not */ |
|
112 |
public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k, boolean includeSubtypes) { |
|
113 |
if (includeSubtypes) { |
|
114 |
if (k.isFinal()) { |
|
115 |
// do the simpler "exact" klass loop |
|
116 |
iterateExact(visitor, k); |
|
117 |
} else { |
|
118 |
iterateSubtypes(visitor, k); |
|
119 |
} |
|
120 |
} else { |
|
121 |
// there can no object of abstract classes and interfaces |
|
122 |
if (!k.isAbstract() && !k.isInterface()) { |
|
123 |
iterateExact(visitor, k); |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
/** iterate objects of given Klass (objects of subtypes included) */ |
|
129 |
public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k) { |
|
130 |
iterateObjectsOfKlass(visitor, k, true); |
|
131 |
} |
|
132 |
||
133 |
/** This routine can be used to iterate through the heap at an |
|
134 |
extremely low level (stepping word-by-word) to provide the |
|
135 |
ability to do very low-level debugging */ |
|
136 |
public void iterateRaw(RawHeapVisitor visitor) { |
|
137 |
List liveRegions = collectLiveRegions(); |
|
138 |
||
139 |
// Summarize size |
|
140 |
long totalSize = 0; |
|
141 |
for (int i = 0; i < liveRegions.size(); i += 2) { |
|
142 |
Address bottom = (Address) liveRegions.get(i); |
|
143 |
Address top = (Address) liveRegions.get(i+1); |
|
144 |
totalSize += top.minus(bottom); |
|
145 |
} |
|
146 |
visitor.prologue(totalSize); |
|
147 |
||
148 |
for (int i = 0; i < liveRegions.size(); i += 2) { |
|
149 |
Address bottom = (Address) liveRegions.get(i); |
|
150 |
Address top = (Address) liveRegions.get(i+1); |
|
151 |
||
152 |
// Traverses the space from bottom to top |
|
153 |
while (bottom.lessThan(top)) { |
|
154 |
visitor.visitAddress(bottom); |
|
155 |
bottom = bottom.addOffsetTo(VM.getVM().getAddressSize()); |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
visitor.epilogue(); |
|
160 |
} |
|
161 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
162 |
public boolean isValidMethod(Address handle) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
163 |
try { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
164 |
Method m = (Method)Metadata.instantiateWrapperFor(handle); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
165 |
return true; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
166 |
} catch (Exception e) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
167 |
return false; |
1 | 168 |
} |
764
67578bc37423
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
360
diff
changeset
|
169 |
} |
67578bc37423
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
360
diff
changeset
|
170 |
|
1 | 171 |
// Creates an instance from the Oop hierarchy based based on the handle |
172 |
public Oop newOop(OopHandle handle) { |
|
173 |
// The only known way to detect the right type of an oop is |
|
174 |
// traversing the class chain until a well-known klass is recognized. |
|
175 |
// A more direct solution would require the klasses to expose |
|
176 |
// the C++ vtbl structure. |
|
177 |
||
178 |
// Handle the null reference |
|
179 |
if (handle == null) return null; |
|
180 |
||
181 |
// Then check if obj.klass() is one of the root objects |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
182 |
Klass klass = Oop.getKlassForOopHandle(handle); |
1 | 183 |
if (klass != null) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
184 |
if (klass instanceof TypeArrayKlass) return new TypeArray(handle, this); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
185 |
if (klass instanceof ObjArrayKlass) return new ObjArray(handle, this); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
186 |
if (klass instanceof InstanceKlass) return new Instance(handle, this); |
1 | 187 |
} |
188 |
||
764
67578bc37423
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
360
diff
changeset
|
189 |
if (DEBUG) { |
67578bc37423
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
360
diff
changeset
|
190 |
System.err.println("Unknown oop at " + handle); |
67578bc37423
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
360
diff
changeset
|
191 |
System.err.println("Oop's klass is " + klass); |
67578bc37423
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
360
diff
changeset
|
192 |
} |
1 | 193 |
|
194 |
throw new UnknownOopException(); |
|
195 |
} |
|
196 |
||
197 |
// Print all objects in the object heap |
|
198 |
public void print() { |
|
199 |
HeapPrinter printer = new HeapPrinter(System.out); |
|
200 |
iterate(printer); |
|
201 |
} |
|
202 |
||
203 |
//--------------------------------------------------------------------------- |
|
204 |
// Internals only below this point |
|
205 |
// |
|
206 |
||
207 |
private void iterateExact(HeapVisitor visitor, final Klass k) { |
|
208 |
iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() { |
|
209 |
public boolean canInclude(Oop obj) { |
|
210 |
Klass tk = obj.getKlass(); |
|
211 |
// null Klass is seen sometimes! |
|
212 |
return (tk != null && tk.equals(k)); |
|
213 |
} |
|
214 |
}); |
|
215 |
} |
|
216 |
||
217 |
private void iterateSubtypes(HeapVisitor visitor, final Klass k) { |
|
218 |
iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() { |
|
219 |
public boolean canInclude(Oop obj) { |
|
220 |
Klass tk = obj.getKlass(); |
|
221 |
// null Klass is seen sometimes! |
|
222 |
return (tk != null && tk.isSubtypeOf(k)); |
|
223 |
} |
|
224 |
}); |
|
225 |
} |
|
226 |
||
227 |
private void iterateLiveRegions(List liveRegions, HeapVisitor visitor, ObjectFilter of) { |
|
228 |
// Summarize size |
|
229 |
long totalSize = 0; |
|
230 |
for (int i = 0; i < liveRegions.size(); i += 2) { |
|
231 |
Address bottom = (Address) liveRegions.get(i); |
|
232 |
Address top = (Address) liveRegions.get(i+1); |
|
233 |
totalSize += top.minus(bottom); |
|
234 |
} |
|
235 |
visitor.prologue(totalSize); |
|
236 |
||
237 |
CompactibleFreeListSpace cmsSpaceOld = null; |
|
238 |
CollectedHeap heap = VM.getVM().getUniverse().heap(); |
|
239 |
||
240 |
if (heap instanceof GenCollectedHeap) { |
|
241 |
GenCollectedHeap genHeap = (GenCollectedHeap) heap; |
|
242 |
Generation genOld = genHeap.getGen(1); |
|
243 |
if (genOld instanceof ConcurrentMarkSweepGeneration) { |
|
244 |
ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genOld; |
|
245 |
cmsSpaceOld = concGen.cmsSpace(); |
|
246 |
} |
|
247 |
} |
|
248 |
||
249 |
for (int i = 0; i < liveRegions.size(); i += 2) { |
|
250 |
Address bottom = (Address) liveRegions.get(i); |
|
251 |
Address top = (Address) liveRegions.get(i+1); |
|
252 |
||
253 |
try { |
|
254 |
// Traverses the space from bottom to top |
|
255 |
OopHandle handle = bottom.addOffsetToAsOopHandle(0); |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
256 |
|
1 | 257 |
while (handle.lessThan(top)) { |
54388
a1acc800c87a
8220602: Shenandoah-SA: Enable best-effort implementation of heap walk
zgu
parents:
53814
diff
changeset
|
258 |
Oop obj = null; |
a1acc800c87a
8220602: Shenandoah-SA: Enable best-effort implementation of heap walk
zgu
parents:
53814
diff
changeset
|
259 |
// Raw pointer walk |
a1acc800c87a
8220602: Shenandoah-SA: Enable best-effort implementation of heap walk
zgu
parents:
53814
diff
changeset
|
260 |
handle = handle.addOffsetToAsOopHandle(heap.oopOffset()); |
1 | 261 |
|
262 |
try { |
|
263 |
obj = newOop(handle); |
|
264 |
} catch (UnknownOopException exp) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
265 |
if (DEBUG) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
266 |
throw new RuntimeException(" UnknownOopException " + exp); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
267 |
} |
1 | 268 |
} |
269 |
if (obj == null) { |
|
270 |
//Find the object size using Printezis bits and skip over |
|
271 |
long size = 0; |
|
272 |
||
273 |
if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle) ){ |
|
274 |
size = cmsSpaceOld.collector().blockSizeUsingPrintezisBits(handle); |
|
275 |
} |
|
276 |
||
277 |
if (size <= 0) { |
|
278 |
//Either Printezis bits not set or handle is not in cms space. |
|
279 |
throw new UnknownOopException(); |
|
280 |
} |
|
281 |
||
282 |
handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(size)); |
|
283 |
continue; |
|
284 |
} |
|
285 |
if (of == null || of.canInclude(obj)) { |
|
286 |
if (visitor.doObj(obj)) { |
|
287 |
// doObj() returns true to abort this loop. |
|
288 |
break; |
|
289 |
} |
|
290 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10663
diff
changeset
|
291 |
if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle)) { |
1 | 292 |
handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(obj.getObjectSize()) ); |
293 |
} else { |
|
294 |
handle = handle.addOffsetToAsOopHandle(obj.getObjectSize()); |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
catch (AddressException e) { |
|
299 |
// This is okay at the top of these regions |
|
22216 | 300 |
} |
1 | 301 |
catch (UnknownOopException e) { |
302 |
// This is okay at the top of these regions |
|
303 |
} |
|
304 |
} |
|
305 |
||
306 |
visitor.epilogue(); |
|
307 |
} |
|
308 |
||
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
309 |
private static class LiveRegionsCollector implements LiveRegionsClosure { |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
310 |
LiveRegionsCollector(List<Address> l) { |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
311 |
liveRegions = l; |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
312 |
} |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
313 |
|
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
314 |
@Override |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
315 |
public void doLiveRegions(LiveRegionsProvider lrp) { |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
316 |
for (MemRegion reg : lrp.getLiveRegions()) { |
1 | 317 |
Address top = reg.end(); |
318 |
Address bottom = reg.start(); |
|
319 |
if (Assert.ASSERTS_ENABLED) { |
|
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
320 |
Assert.that(top != null, "top address in a live region should not be null"); |
1 | 321 |
} |
322 |
if (Assert.ASSERTS_ENABLED) { |
|
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
323 |
Assert.that(bottom != null, "bottom address in a live region should not be null"); |
1 | 324 |
} |
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
325 |
liveRegions.add(top); |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
326 |
liveRegions.add(bottom); |
22216 | 327 |
if (DEBUG) { |
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
328 |
System.err.println("Live region: " + lrp + ": " + bottom + ", " + top); |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
329 |
} |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
330 |
} |
1 | 331 |
} |
332 |
||
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
333 |
private List<Address> liveRegions; |
1 | 334 |
} |
335 |
||
336 |
// Returns a List<Address> where the addresses come in pairs. These |
|
337 |
// designate the live regions of the heap. |
|
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
338 |
private List<Address> collectLiveRegions() { |
1 | 339 |
// We want to iterate through all live portions of the heap, but |
340 |
// do not want to abort the heap traversal prematurely if we find |
|
341 |
// a problem (like an allocated but uninitialized object at the |
|
342 |
// top of a generation). To do this we enumerate all generations' |
|
343 |
// bottom and top regions, and factor in TLABs if necessary. |
|
344 |
||
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
345 |
// Addresses come in pairs. |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
346 |
List<Address> liveRegions = new ArrayList<>(); |
1 | 347 |
LiveRegionsCollector lrc = new LiveRegionsCollector(liveRegions); |
348 |
||
349 |
CollectedHeap heap = VM.getVM().getUniverse().heap(); |
|
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
350 |
heap.liveRegionsIterate(lrc); |
1 | 351 |
|
352 |
// If UseTLAB is enabled, snip out regions associated with TLABs' |
|
353 |
// dead regions. Note that TLABs can be present in any generation. |
|
354 |
||
355 |
// FIXME: consider adding fewer boundaries to live region list. |
|
356 |
// Theoretically only need to stop at TLAB's top and resume at its |
|
357 |
// end. |
|
358 |
||
359 |
if (VM.getVM().getUseTLAB()) { |
|
54955
46409371a691
8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents:
54388
diff
changeset
|
360 |
Threads threads = VM.getVM().getThreads(); |
46409371a691
8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents:
54388
diff
changeset
|
361 |
for (int i = 0; i < threads.getNumberOfThreads(); i++) { |
46409371a691
8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents:
54388
diff
changeset
|
362 |
JavaThread thread = threads.getJavaThreadAt(i); |
22216 | 363 |
ThreadLocalAllocBuffer tlab = thread.tlab(); |
364 |
if (tlab.start() != null) { |
|
365 |
if ((tlab.top() == null) || (tlab.end() == null)) { |
|
366 |
System.err.print("Warning: skipping invalid TLAB for thread "); |
|
367 |
thread.printThreadIDOn(System.err); |
|
368 |
System.err.println(); |
|
369 |
} else { |
|
370 |
if (DEBUG) { |
|
371 |
System.err.print("TLAB for " + thread.getThreadName() + ", #"); |
|
1 | 372 |
thread.printThreadIDOn(System.err); |
22216 | 373 |
System.err.print(": "); |
374 |
tlab.printOn(System.err); |
|
1 | 375 |
} |
22216 | 376 |
// Go from: |
377 |
// - below start() to start() |
|
378 |
// - start() to top() |
|
379 |
// - end() and above |
|
380 |
liveRegions.add(tlab.start()); |
|
381 |
liveRegions.add(tlab.start()); |
|
382 |
liveRegions.add(tlab.top()); |
|
383 |
liveRegions.add(tlab.hardEnd()); |
|
1 | 384 |
} |
385 |
} |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
// Now sort live regions |
|
390 |
sortLiveRegions(liveRegions); |
|
391 |
||
392 |
if (Assert.ASSERTS_ENABLED) { |
|
393 |
Assert.that(liveRegions.size() % 2 == 0, "Must have even number of region boundaries"); |
|
394 |
} |
|
395 |
||
22216 | 396 |
if (DEBUG) { |
397 |
System.err.println("liveRegions:"); |
|
398 |
for (int i = 0; i < liveRegions.size(); i += 2) { |
|
399 |
Address bottom = (Address) liveRegions.get(i); |
|
400 |
Address top = (Address) liveRegions.get(i+1); |
|
401 |
System.err.println(" " + bottom + " - " + top); |
|
402 |
} |
|
403 |
} |
|
404 |
||
1 | 405 |
return liveRegions; |
406 |
} |
|
407 |
||
53814
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
408 |
private void sortLiveRegions(List<Address> liveRegions) { |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
409 |
Collections.sort(liveRegions, new Comparator<Address>() { |
eff915f3d3f2
8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
stefank
parents:
52925
diff
changeset
|
410 |
public int compare(Address a1, Address a2) { |
1 | 411 |
if (AddressOps.lt(a1, a2)) { |
412 |
return -1; |
|
413 |
} else if (AddressOps.gt(a1, a2)) { |
|
414 |
return 1; |
|
415 |
} |
|
416 |
return 0; |
|
417 |
} |
|
418 |
}); |
|
419 |
} |
|
420 |
} |