author | lkorinth |
Wed, 13 Nov 2019 11:37:29 +0100 | |
changeset 59053 | ba6c248cae19 |
parent 54780 | f8d182aedc92 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
59053
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
54780
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:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
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:
3261
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.memory; |
|
26 |
||
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
27 |
import java.io.PrintStream; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
28 |
import java.util.Observable; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
29 |
import java.util.Observer; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
30 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
31 |
import sun.jvm.hotspot.debugger.Address; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
32 |
import sun.jvm.hotspot.debugger.OopHandle; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
33 |
import sun.jvm.hotspot.gc.epsilon.EpsilonHeap; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
34 |
import sun.jvm.hotspot.gc.g1.G1CollectedHeap; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
35 |
import sun.jvm.hotspot.gc.parallel.ParallelScavengeHeap; |
47819
ee36a8e36561
8183542: Factor out serial GC specific code from GenCollectedHeap into its own subclass
rkennke
parents:
47663
diff
changeset
|
36 |
import sun.jvm.hotspot.gc.serial.SerialHeap; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
37 |
import sun.jvm.hotspot.gc.shared.CollectedHeap; |
52925
9c18c9d839d3
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents:
51554
diff
changeset
|
38 |
import sun.jvm.hotspot.gc.shenandoah.ShenandoahHeap; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
39 |
import sun.jvm.hotspot.gc.z.ZCollectedHeap; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
40 |
import sun.jvm.hotspot.oops.Oop; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
41 |
import sun.jvm.hotspot.runtime.BasicType; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
42 |
import sun.jvm.hotspot.runtime.VM; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
43 |
import sun.jvm.hotspot.runtime.VirtualConstructor; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
44 |
import sun.jvm.hotspot.types.AddressField; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
45 |
import sun.jvm.hotspot.types.CIntegerField; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
46 |
import sun.jvm.hotspot.types.Type; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
47 |
import sun.jvm.hotspot.types.TypeDataBase; |
1 | 48 |
|
49 |
||
50 |
public class Universe { |
|
51 |
private static AddressField collectedHeapField; |
|
52 |
private static VirtualConstructor heapConstructor; |
|
53 |
private static sun.jvm.hotspot.types.OopField mainThreadGroupField; |
|
54 |
private static sun.jvm.hotspot.types.OopField systemThreadGroupField; |
|
55 |
||
56 |
static { |
|
57 |
VM.registerVMInitializedObserver(new Observer() { |
|
58 |
public void update(Observable o, Object data) { |
|
59 |
initialize(VM.getVM().getTypeDataBase()); |
|
60 |
} |
|
61 |
}); |
|
62 |
} |
|
63 |
||
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
64 |
private static boolean typeExists(TypeDataBase db, String type) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
65 |
try { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
66 |
db.lookupType(type); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
67 |
} catch (RuntimeException e) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
68 |
return false; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
69 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
70 |
return true; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
71 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
72 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
73 |
private static void addHeapTypeIfInDB(TypeDataBase db, Class heapClass) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
74 |
String heapName = heapClass.getSimpleName(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
75 |
if (typeExists(db, heapName)) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
76 |
heapConstructor.addMapping(heapName, heapClass); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
77 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
78 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
79 |
|
1 | 80 |
private static synchronized void initialize(TypeDataBase db) { |
81 |
Type type = db.lookupType("Universe"); |
|
82 |
||
83 |
collectedHeapField = type.getAddressField("_collectedHeap"); |
|
84 |
||
85 |
heapConstructor = new VirtualConstructor(db); |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
86 |
addHeapTypeIfInDB(db, SerialHeap.class); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
87 |
addHeapTypeIfInDB(db, ParallelScavengeHeap.class); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
88 |
addHeapTypeIfInDB(db, G1CollectedHeap.class); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
89 |
addHeapTypeIfInDB(db, EpsilonHeap.class); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
90 |
addHeapTypeIfInDB(db, ZCollectedHeap.class); |
52925
9c18c9d839d3
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents:
51554
diff
changeset
|
91 |
addHeapTypeIfInDB(db, ShenandoahHeap.class); |
1 | 92 |
|
93 |
mainThreadGroupField = type.getOopField("_main_thread_group"); |
|
94 |
systemThreadGroupField = type.getOopField("_system_thread_group"); |
|
95 |
||
39227
59ace61f7436
8157243: JMap heap test fail when used with external heap
sjohanss
parents:
35217
diff
changeset
|
96 |
UniverseExt.initialize(heapConstructor); |
1 | 97 |
} |
98 |
||
99 |
public Universe() { |
|
100 |
} |
|
101 |
public CollectedHeap heap() { |
|
30159 | 102 |
return (CollectedHeap) heapConstructor.instantiateWrapperFor(collectedHeapField.getValue()); |
1 | 103 |
} |
104 |
||
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13728
diff
changeset
|
105 |
|
1 | 106 |
/** Returns "TRUE" iff "p" points into the allocated area of the heap. */ |
107 |
public boolean isIn(Address p) { |
|
108 |
return heap().isIn(p); |
|
109 |
} |
|
110 |
||
111 |
/** Returns "TRUE" iff "p" points into the reserved area of the heap. */ |
|
112 |
public boolean isInReserved(Address p) { |
|
113 |
return heap().isInReserved(p); |
|
114 |
} |
|
115 |
||
116 |
private Oop newOop(OopHandle handle) { |
|
117 |
return VM.getVM().getObjectHeap().newOop(handle); |
|
118 |
} |
|
119 |
||
120 |
public Oop mainThreadGroup() { |
|
121 |
return newOop(mainThreadGroupField.getValue()); |
|
122 |
} |
|
123 |
||
124 |
public Oop systemThreadGroup() { |
|
125 |
return newOop(systemThreadGroupField.getValue()); |
|
126 |
} |
|
127 |
||
128 |
||
129 |
public void print() { printOn(System.out); } |
|
130 |
public void printOn(PrintStream tty) { |
|
131 |
heap().printOn(tty); |
|
132 |
} |
|
133 |
||
134 |
// Check whether an element of a typeArrayOop with the given type must be |
|
135 |
// aligned 0 mod 8. The typeArrayOop itself must be aligned at least this |
|
136 |
// strongly. |
|
137 |
public static boolean elementTypeShouldBeAligned(BasicType type) { |
|
138 |
return type == BasicType.T_DOUBLE || type == BasicType.T_LONG; |
|
139 |
} |
|
140 |
||
141 |
// Check whether an object field (static/non-static) of the given type must be |
|
142 |
// aligned 0 mod 8. |
|
143 |
public static boolean fieldTypeShouldBeAligned(BasicType type) { |
|
144 |
return type == BasicType.T_DOUBLE || type == BasicType.T_LONG; |
|
145 |
} |
|
146 |
} |