author | xuelei |
Fri, 14 Sep 2018 20:30:28 -0700 | |
changeset 51755 | 6c394ed56b07 |
parent 47216 | 71c04702a3d5 |
child 53647 | 82c95d4b61f0 |
permissions | -rw-r--r-- |
46384
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
1 |
/* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
4 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
8 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
13 |
* accompanied this code). |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
14 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
18 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
21 |
* questions. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
22 |
*/ |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
23 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
24 |
package gc.concurrent_phase_control; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
25 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
26 |
/* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
27 |
* Utility class that provides verification of expected behavior of |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
28 |
* the Concurrent GC Phase Control WB API when the current GC supports |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
29 |
* phase control. The invoking test must provide WhiteBox access. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
30 |
*/ |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
31 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
32 |
import sun.hotspot.WhiteBox; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
33 |
import java.util.Arrays; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
34 |
import java.util.HashSet; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
35 |
import java.util.List; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
36 |
import java.util.Set; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
37 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
38 |
public class CheckSupported { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
39 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
40 |
private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
41 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
42 |
private static Set<String> toSet(List<String> list, String which) |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
43 |
throws Exception |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
44 |
{ |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
45 |
Set<String> result = new HashSet<String>(list); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
46 |
if (result.size() < list.size()) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
47 |
throw new RuntimeException(which + " phases contains duplicates"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
48 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
49 |
return result; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
50 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
51 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
52 |
private static void checkPhases(String[] expectedPhases) throws Exception { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
53 |
String[] actualPhases = WB.getConcurrentGCPhases(); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
54 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
55 |
List<String> expectedList = Arrays.asList(expectedPhases); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
56 |
List<String> actualList = Arrays.asList(actualPhases); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
57 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
58 |
Set<String> expected = toSet(expectedList, "Expected"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
59 |
Set<String> actual = toSet(actualList, "Actual"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
60 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
61 |
expected.removeAll(actualList); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
62 |
actual.removeAll(expectedList); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
63 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
64 |
boolean match = true; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
65 |
if (!expected.isEmpty()) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
66 |
match = false; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
67 |
System.out.println("Unexpected phases:"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
68 |
for (String s: expected) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
69 |
System.out.println(" " + s); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
70 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
71 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
72 |
if (!actual.isEmpty()) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
73 |
match = false; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
74 |
System.out.println("Expected but missing phases:"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
75 |
for (String s: actual) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
76 |
System.out.println(" " + s); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
77 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
78 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
79 |
if (!match) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
80 |
throw new RuntimeException("Mismatch between expected and actual phases"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
81 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
82 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
83 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
84 |
public static void check(String gcName, String[] phases) throws Exception { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
85 |
// Verify supported. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
86 |
if (!WB.supportsConcurrentGCPhaseControl()) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
87 |
throw new RuntimeException( |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
88 |
gcName + " unexpectedly missing phase control support"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
89 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
90 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
91 |
checkPhases(phases); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
92 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
93 |
// Verify IllegalArgumentException thrown by request attempt |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
94 |
// with unknown phase. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
95 |
boolean illegalArgumentThrown = false; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
96 |
try { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
97 |
WB.requestConcurrentGCPhase("UNKNOWN PHASE"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
98 |
} catch (IllegalArgumentException e) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
99 |
// Expected. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
100 |
illegalArgumentThrown = true; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
101 |
} catch (Exception e) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
102 |
throw new RuntimeException( |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
103 |
gcName + ": Unexpected exception when requesting unknown phase: " + e.toString()); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
104 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
105 |
if (!illegalArgumentThrown) { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
106 |
throw new RuntimeException( |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
107 |
gcName + ": No exception when requesting unknown phase"); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
108 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
109 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
110 |
} |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
111 |