28 * the Concurrent GC Phase Control WB API when the current GC supports |
28 * the Concurrent GC Phase Control WB API when the current GC supports |
29 * phase control. The invoking test must provide WhiteBox access. |
29 * phase control. The invoking test must provide WhiteBox access. |
30 */ |
30 */ |
31 |
31 |
32 import sun.hotspot.WhiteBox; |
32 import sun.hotspot.WhiteBox; |
33 import java.util.Arrays; |
|
34 import java.util.HashSet; |
|
35 import java.util.List; |
|
36 import java.util.Set; |
|
37 |
33 |
38 public class CheckSupported { |
34 public class CheckSupported { |
39 |
35 |
40 private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
36 private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
41 |
37 |
42 private static Set<String> toSet(List<String> list, String which) |
38 public static void check(String gcName) throws Exception { |
43 throws Exception |
|
44 { |
|
45 Set<String> result = new HashSet<String>(list); |
|
46 if (result.size() < list.size()) { |
|
47 throw new RuntimeException(which + " phases contains duplicates"); |
|
48 } |
|
49 return result; |
|
50 } |
|
51 |
|
52 private static void checkPhases(String[] expectedPhases) throws Exception { |
|
53 String[] actualPhases = WB.getConcurrentGCPhases(); |
|
54 |
|
55 List<String> expectedList = Arrays.asList(expectedPhases); |
|
56 List<String> actualList = Arrays.asList(actualPhases); |
|
57 |
|
58 Set<String> expected = toSet(expectedList, "Expected"); |
|
59 Set<String> actual = toSet(actualList, "Actual"); |
|
60 |
|
61 expected.removeAll(actualList); |
|
62 actual.removeAll(expectedList); |
|
63 |
|
64 boolean match = true; |
|
65 if (!expected.isEmpty()) { |
|
66 match = false; |
|
67 System.out.println("Unexpected phases:"); |
|
68 for (String s: expected) { |
|
69 System.out.println(" " + s); |
|
70 } |
|
71 } |
|
72 if (!actual.isEmpty()) { |
|
73 match = false; |
|
74 System.out.println("Expected but missing phases:"); |
|
75 for (String s: actual) { |
|
76 System.out.println(" " + s); |
|
77 } |
|
78 } |
|
79 if (!match) { |
|
80 throw new RuntimeException("Mismatch between expected and actual phases"); |
|
81 } |
|
82 } |
|
83 |
|
84 public static void check(String gcName, String[] phases) throws Exception { |
|
85 // Verify supported. |
39 // Verify supported. |
86 if (!WB.supportsConcurrentGCPhaseControl()) { |
40 if (!WB.supportsConcurrentGCPhaseControl()) { |
87 throw new RuntimeException( |
41 throw new RuntimeException( |
88 gcName + " unexpectedly missing phase control support"); |
42 gcName + " unexpectedly missing phase control support"); |
89 } |
43 } |
90 |
|
91 checkPhases(phases); |
|
92 |
44 |
93 // Verify IllegalArgumentException thrown by request attempt |
45 // Verify IllegalArgumentException thrown by request attempt |
94 // with unknown phase. |
46 // with unknown phase. |
95 boolean illegalArgumentThrown = false; |
47 boolean illegalArgumentThrown = false; |
96 try { |
48 try { |