author | ksrini |
Wed, 21 Jun 2017 19:39:51 -0700 | |
changeset 45742 | 36bf0f2436ad |
parent 41533 | 64e1caddf380 |
child 49630 | 2f1b308b4469 |
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 |
/* |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
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 java.util.ArrayList; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
27 |
import java.util.List; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
28 |
import sun.hotspot.WhiteBox; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
29 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
30 |
/** |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
31 |
* 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
|
32 |
* 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
|
33 |
*/ |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
34 |
public enum GC { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
35 |
Serial(1), |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
36 |
Parallel(2), |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
37 |
ConcMarkSweep(4), |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
38 |
G1(8); |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
39 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
40 |
private static final GC CURRENT_GC; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
41 |
private static final int ALL_GC_CODES; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
42 |
private static final boolean IS_BY_ERGO; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
43 |
static { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
44 |
WhiteBox WB = WhiteBox.getWhiteBox(); |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
45 |
ALL_GC_CODES = WB.allSupportedGC(); |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
46 |
IS_BY_ERGO = WB.gcSelectedByErgo(); |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
47 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
48 |
int currentCode = WB.currentGC(); |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
49 |
GC tmp = null; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
50 |
for (GC gc: GC.values()) { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
51 |
if (gc.code == currentCode) { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
52 |
tmp = gc; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
53 |
break; |
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 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
56 |
if (tmp == null) { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
57 |
throw new Error("Unknown current GC code " + currentCode); |
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 |
CURRENT_GC = tmp; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
60 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
61 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
62 |
private final int code; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
63 |
private GC(int code) { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
64 |
this.code = code; |
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 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
67 |
/** |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
68 |
* @return true if the collector is supported by the VM, false otherwise. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
69 |
*/ |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
70 |
public boolean isSupported() { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
71 |
return (ALL_GC_CODES & code) != 0; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
72 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
73 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
74 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
75 |
/** |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
76 |
* @return the current collector used by VM. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
77 |
*/ |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
78 |
public static GC current() { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
79 |
return CURRENT_GC; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
80 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
81 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
82 |
/** |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
83 |
* @return true if GC was selected by ergonomic, false if specified |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
84 |
* explicitly by the command line flag. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
85 |
*/ |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
86 |
public static boolean currentSetByErgo() { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
87 |
return IS_BY_ERGO; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
88 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
89 |
|
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
90 |
/** |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
91 |
* @return List of collectors supported by the VM. |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
92 |
*/ |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
93 |
public static List<GC> allSupported() { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
94 |
List<GC> list = new ArrayList<>(); |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
95 |
for (GC gc: GC.values()) { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
96 |
if (gc.isSupported()) { |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
97 |
list.add(gc); |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
98 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
99 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
100 |
return list; |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
101 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
102 |
} |
0602da3f94c9
8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff
changeset
|
103 |