author | stefank |
Wed, 10 Apr 2019 15:41:03 +0200 | |
changeset 54510 | c97a91097f9f |
parent 52925 | 9c18c9d839d3 |
child 59053 | ba6c248cae19 |
permissions | -rw-r--r-- |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
1 |
/* |
49630 | 2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
4 |
* |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
8 |
* |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
13 |
* accompanied this code). |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
14 |
* |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
18 |
* |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
21 |
* questions. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
22 |
*/ |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
23 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
24 |
package sun.hotspot.gc; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
25 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
26 |
import sun.hotspot.WhiteBox; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
27 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
28 |
/** |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
29 |
* API to obtain information about selected and supported Garbage Collectors |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
30 |
* retrieved from the VM with the WhiteBox API. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
31 |
*/ |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
32 |
public enum GC { |
49630 | 33 |
/* |
51616
b071f4fff1f1
8210259: [testbug] IncompatibleOptions.java fails if VM configured without ZGC
goetz
parents:
50525
diff
changeset
|
34 |
* Enum values must match CollectedHeap::Name |
49630 | 35 |
*/ |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
36 |
Serial(1), |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
37 |
Parallel(2), |
49630 | 38 |
ConcMarkSweep(3), |
50523
7b7c75d87f9b
8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents:
49630
diff
changeset
|
39 |
G1(4), |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
50523
diff
changeset
|
40 |
Epsilon(5), |
52925
9c18c9d839d3
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents:
51616
diff
changeset
|
41 |
Z(6), |
9c18c9d839d3
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents:
51616
diff
changeset
|
42 |
Shenandoah(7); |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
43 |
|
49630 | 44 |
private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
45 |
|
49630 | 46 |
private final int name; |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
47 |
|
49630 | 48 |
private GC(int name) { |
49 |
this.name = name; |
|
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
50 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
51 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
52 |
/** |
51616
b071f4fff1f1
8210259: [testbug] IncompatibleOptions.java fails if VM configured without ZGC
goetz
parents:
50525
diff
changeset
|
53 |
* @return true if this GC is supported by the VM, i.e., it is built into the VM. |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
54 |
*/ |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
55 |
public boolean isSupported() { |
49630 | 56 |
return WB.isGCSupported(name); |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
57 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
58 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
59 |
/** |
49630 | 60 |
* @return true if this GC is currently selected/used |
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
61 |
*/ |
49630 | 62 |
public boolean isSelected() { |
63 |
return WB.isGCSelected(name); |
|
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
64 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
65 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
66 |
/** |
49630 | 67 |
* @return true if GC was selected ergonomically, as opposed |
68 |
* to being explicitly specified on the command line |
|
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
69 |
*/ |
49630 | 70 |
public static boolean isSelectedErgonomically() { |
71 |
return WB.isGCSelectedErgonomically(); |
|
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
72 |
} |
54510 | 73 |
|
74 |
/** |
|
75 |
* @return the selected GC. |
|
76 |
*/ |
|
77 |
public static GC selected() { |
|
78 |
for (GC gc : values()) { |
|
79 |
if (gc.isSelected()) { |
|
80 |
return gc; |
|
81 |
} |
|
82 |
} |
|
83 |
throw new IllegalStateException("No selected GC found"); |
|
84 |
} |
|
38629
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
85 |
} |