author | robm |
Tue, 25 Aug 2015 14:07:08 +0100 | |
changeset 32271 | d6cb1602f271 |
parent 30604 | b8d532cb6420 |
child 36576 | 8bd19bf60177 |
permissions | -rw-r--r-- |
26932
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
1 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
26932
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
26932
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
4 |
* |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
8 |
* |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
14 |
* |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
18 |
* |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
21 |
* questions. |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
22 |
*/ |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
23 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
24 |
/* |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
25 |
* @test TestG1ConcRefinementThreads |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
26 |
* @key gc |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
27 |
* @bug 8047976 |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
28 |
* @summary Tests argument processing for G1ConcRefinementThreads |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
29 |
* @library /testlibrary |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
26932
diff
changeset
|
30 |
* @modules java.base/sun.misc |
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
26932
diff
changeset
|
31 |
* java.management |
26932
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
32 |
*/ |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
33 |
|
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
34 |
import jdk.test.lib.*; |
26932
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
35 |
import java.util.*; |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
36 |
import java.util.regex.*; |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
37 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
38 |
public class TestG1ConcRefinementThreads { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
39 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
40 |
static final int AUTO_SELECT_THREADS_COUNT = 0; |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
41 |
static final int PASSED_THREADS_COUNT = 11; |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
42 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
43 |
public static void main(String args[]) throws Exception { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
44 |
// default case |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
45 |
runG1ConcRefinementThreadsTest( |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
46 |
new String[]{}, // automatically selected |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
47 |
AUTO_SELECT_THREADS_COUNT /* use default setting */); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
48 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
49 |
// zero setting case |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
50 |
runG1ConcRefinementThreadsTest( |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
51 |
new String[]{"-XX:G1ConcRefinementThreads=0"}, // automatically selected |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
52 |
AUTO_SELECT_THREADS_COUNT /* set to zero */); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
53 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
54 |
// non-zero sestting case |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
55 |
runG1ConcRefinementThreadsTest( |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
56 |
new String[]{"-XX:G1ConcRefinementThreads="+Integer.toString(PASSED_THREADS_COUNT)}, |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
57 |
PASSED_THREADS_COUNT); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
58 |
} |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
59 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
60 |
private static void runG1ConcRefinementThreadsTest(String[] passedOpts, |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
61 |
int expectedValue) throws Exception { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
62 |
List<String> vmOpts = new ArrayList<>(); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
63 |
if (passedOpts.length > 0) { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
64 |
Collections.addAll(vmOpts, passedOpts); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
65 |
} |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
66 |
Collections.addAll(vmOpts, "-XX:+UseG1GC", "-XX:+PrintFlagsFinal", "-version"); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
67 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
68 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()])); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
69 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
70 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
71 |
output.shouldHaveExitValue(0); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
72 |
String stdout = output.getStdout(); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
73 |
checkG1ConcRefinementThreadsConsistency(stdout, expectedValue); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
74 |
} |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
75 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
76 |
private static void checkG1ConcRefinementThreadsConsistency(String output, int expectedValue) { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
77 |
int actualValue = getIntValue("G1ConcRefinementThreads", output); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
78 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
79 |
if (expectedValue == 0) { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
80 |
// If expectedValue is automatically selected, set it same as ParallelGCThreads. |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
81 |
expectedValue = getIntValue("ParallelGCThreads", output); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
82 |
} |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
83 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
84 |
if (expectedValue != actualValue) { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
85 |
throw new RuntimeException( |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
86 |
"Actual G1ConcRefinementThreads(" + Integer.toString(actualValue) |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
87 |
+ ") is not equal to expected value(" + Integer.toString(expectedValue) + ")"); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
88 |
} |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
89 |
} |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
90 |
|
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
91 |
public static int getIntValue(String flag, String where) { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
92 |
Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
93 |
if (!m.find()) { |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
94 |
throw new RuntimeException("Could not find value for flag " + flag + " in output string"); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
95 |
} |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
96 |
String match = m.group(); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
97 |
return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length())); |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
98 |
} |
33d6fa41d290
8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents:
diff
changeset
|
99 |
} |