author | mdoerr |
Mon, 08 Jul 2019 10:56:05 +0200 | |
changeset 55618 | 978b2201984c |
parent 55308 | 871bc449ce06 |
child 55621 | ea3b1a8fd4bb |
permissions | -rw-r--r-- |
17389 | 1 |
/* |
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
41705
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
4 |
* |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
7 |
* published by the Free Software Foundation. |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
8 |
* |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
13 |
* accompanied this code). |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
14 |
* |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
18 |
* |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
21 |
* questions. |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
22 |
*/ |
17389 | 23 |
|
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
47216
diff
changeset
|
24 |
package gc.arguments; |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
47216
diff
changeset
|
25 |
|
17389 | 26 |
import java.util.regex.Matcher; |
27 |
import java.util.regex.Pattern; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Arrays; |
|
30 |
||
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
39993
diff
changeset
|
31 |
import jdk.test.lib.process.ProcessTools; |
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
39993
diff
changeset
|
32 |
import jdk.test.lib.process.OutputAnalyzer; |
17389 | 33 |
import sun.hotspot.WhiteBox; |
34 |
||
35 |
class ErgoArgsPrinter { |
|
36 |
public static void main(String[] args) throws Exception { |
|
37 |
WhiteBox wb = WhiteBox.getWhiteBox(); |
|
38 |
wb.printHeapSizes(); |
|
39 |
} |
|
40 |
} |
|
41 |
||
42 |
final class MinInitialMaxValues { |
|
43 |
public long minHeapSize; |
|
44 |
public long initialHeapSize; |
|
45 |
public long maxHeapSize; |
|
46 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
47 |
public long spaceAlignment; |
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
48 |
public long heapAlignment; |
17389 | 49 |
} |
50 |
||
51 |
class TestMaxHeapSizeTools { |
|
52 |
||
53 |
public static void checkMinInitialMaxHeapFlags(String gcflag) throws Exception { |
|
54 |
checkInvalidMinInitialHeapCombinations(gcflag); |
|
55 |
checkValidMinInitialHeapCombinations(gcflag); |
|
56 |
checkInvalidInitialMaxHeapCombinations(gcflag); |
|
57 |
checkValidInitialMaxHeapCombinations(gcflag); |
|
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
58 |
checkInvalidMinMaxHeapCombinations(gcflag); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
59 |
checkValidMinMaxHeapCombinations(gcflag); |
17389 | 60 |
} |
61 |
||
62 |
public static void checkMinInitialErgonomics(String gcflag) throws Exception { |
|
63 |
// heap sizing ergonomics use the value NewSize + OldSize as default values |
|
64 |
// for ergonomics calculation. Retrieve these values. |
|
65 |
long[] values = new long[2]; |
|
66 |
getNewOldSize(gcflag, values); |
|
67 |
||
68 |
// we check cases with values smaller and larger than this default value. |
|
69 |
long newPlusOldSize = values[0] + values[1]; |
|
70 |
long smallValue = newPlusOldSize / 2; |
|
71 |
long largeValue = newPlusOldSize * 2; |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
72 |
long maxHeapSize = largeValue + (2 * 1024 * 1024); |
17389 | 73 |
|
74 |
// -Xms is not set |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
75 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize }, values, -1, -1); |
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
76 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue }, values, smallValue, -1); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
77 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + largeValue }, values, largeValue, -1); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
78 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=0" }, values, -1, -1); |
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
79 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
80 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
81 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=0" }, values, -1, -1); |
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
82 |
// Some extra checks when both are set. |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
83 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
84 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
85 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + largeValue, "-XX:InitialHeapSize=" + largeValue }, values, largeValue, largeValue); |
17389 | 86 |
|
87 |
// -Xms is set to zero |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
88 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0" }, values, -1, -1); |
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
89 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue }, values, smallValue, -1); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
90 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + largeValue }, values, largeValue, -1); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
91 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=0" }, values, -1, -1); |
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
92 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
93 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
94 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=0" }, values, -1, -1); |
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
95 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
96 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
97 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + largeValue, "-XX:InitialHeapSize=" + largeValue }, values, largeValue, largeValue); |
17389 | 98 |
|
99 |
// -Xms is set to small value |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
100 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue }, values, -1, -1); |
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
101 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:MinHeapSize=" + smallValue }, values, smallValue, smallValue); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
102 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:MinHeapSize=0" }, values, -1, smallValue); |
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
103 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
104 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
105 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=0" }, values, smallValue, -1); |
17389 | 106 |
|
107 |
// -Xms is set to large value |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
108 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue }, values, largeValue, largeValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
109 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:InitialHeapSize=0" }, values, largeValue, -1); |
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
110 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:MinHeapSize=0" }, values, -1, largeValue); |
17389 | 111 |
} |
112 |
||
113 |
private static long align_up(long value, long alignment) { |
|
114 |
long alignmentMinusOne = alignment - 1; |
|
115 |
return (value + alignmentMinusOne) & ~alignmentMinusOne; |
|
116 |
} |
|
117 |
||
118 |
private static void getNewOldSize(String gcflag, long[] values) throws Exception { |
|
119 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(gcflag, |
|
120 |
"-XX:+PrintFlagsFinal", "-version"); |
|
121 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
122 |
output.shouldHaveExitValue(0); |
|
123 |
||
124 |
String stdout = output.getStdout(); |
|
125 |
values[0] = getFlagValue(" NewSize", stdout); |
|
126 |
values[1] = getFlagValue(" OldSize", stdout); |
|
127 |
} |
|
128 |
||
129 |
public static void checkGenMaxHeapErgo(String gcflag) throws Exception { |
|
130 |
TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 4); |
|
131 |
TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 5); |
|
132 |
} |
|
133 |
||
134 |
private static void checkInvalidMinInitialHeapCombinations(String gcflag) throws Exception { |
|
37088 | 135 |
expectError(new String[] { gcflag, "-XX:InitialHeapSize=1023K", "-version" }); |
28497
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
22765
diff
changeset
|
136 |
expectError(new String[] { gcflag, "-Xms64M", "-XX:InitialHeapSize=32M", "-version" }); |
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
137 |
expectError(new String[] { gcflag, "-XX:MinHeapSize=1023K", "-version" }); |
55618
978b2201984c
8226302: Test failures on IBM platforms (power and s/390) after JDK-8223837
mdoerr
parents:
55308
diff
changeset
|
138 |
// Note: MinHeapSize values get aligned up by HeapAlignment which is 32M with 64k pages. |
978b2201984c
8226302: Test failures on IBM platforms (power and s/390) after JDK-8223837
mdoerr
parents:
55308
diff
changeset
|
139 |
expectError(new String[] { gcflag, "-Xms4M", "-XX:MinHeapSize=64M", "-version" }); |
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
140 |
expectError(new String[] { gcflag, "-XX:MinHeapSize=8M -XX:InitialHeapSize=4m" }); |
17389 | 141 |
} |
142 |
||
143 |
private static void checkValidMinInitialHeapCombinations(String gcflag) throws Exception { |
|
37088 | 144 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=1024K", "-version" }); |
17389 | 145 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms4M", "-version" }); |
146 |
expectValid(new String[] { gcflag, "-Xms4M", "-XX:InitialHeapSize=8M", "-version" }); |
|
147 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms8M", "-version" }); |
|
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
148 |
expectValid(new String[] { gcflag, "-XX:MinHeapSize=1024K", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
149 |
expectValid(new String[] { gcflag, "-XX:MinHeapSize=8M", "-Xms4M", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
150 |
expectValid(new String[] { gcflag, "-XX:MinHeapSize=8M", "-Xms8M", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
151 |
expectValid(new String[] { gcflag, "-Xms8M", "-XX:MinHeapSize=4M", "-version" }); |
17389 | 152 |
// the following is not an error as -Xms sets both minimal and initial heap size |
153 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-Xms8M", "-version" }); |
|
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
154 |
expectValid(new String[] { gcflag, "-XX:MinHeapSize=4M", "-Xms8M", "-version" }); |
17389 | 155 |
} |
156 |
||
157 |
private static void checkInvalidInitialMaxHeapCombinations(String gcflag) throws Exception { |
|
37088 | 158 |
expectError(new String[] { gcflag, "-XX:MaxHeapSize=2047K", "-version" }); |
17389 | 159 |
expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=8M", "-version" }); |
160 |
expectError(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" }); |
|
161 |
} |
|
162 |
||
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
163 |
private static void checkInvalidMinMaxHeapCombinations(String gcflag) throws Exception { |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
164 |
expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=8M", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
165 |
expectError(new String[] { gcflag, "-XX:MinHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
166 |
} |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
167 |
|
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
168 |
|
17389 | 169 |
private static void checkValidInitialMaxHeapCombinations(String gcflag) throws Exception { |
170 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" }); |
|
171 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:InitialHeapSize=4M", "-version" }); |
|
172 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=4M", "-version" }); |
|
173 |
// a value of "0" for initial heap size means auto-detect |
|
174 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=0M", "-version" }); |
|
175 |
} |
|
176 |
||
55308
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
177 |
private static void checkValidMinMaxHeapCombinations(String gcflag) throws Exception { |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
178 |
expectValid(new String[] { gcflag, "-XX:MinHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
179 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:MinHeapSize=4M", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
180 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=4M", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
181 |
// a value of "0" for min heap size means auto-detect |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
182 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=0M", "-version" }); |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
183 |
} |
871bc449ce06
8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents:
53523
diff
changeset
|
184 |
|
17389 | 185 |
private static long valueAfter(String source, String match) { |
186 |
int start = source.indexOf(match) + match.length(); |
|
187 |
String tail = source.substring(start).split(" ")[0]; |
|
188 |
return Long.parseLong(tail); |
|
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
* Executes a new VM process with the given class and parameters. |
|
193 |
* @param vmargs Arguments to the VM to run |
|
194 |
* @param classname Name of the class to run |
|
195 |
* @param arguments Arguments to the class |
|
196 |
* @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string |
|
197 |
* @return The OutputAnalyzer with the results for the invocation. |
|
198 |
*/ |
|
199 |
public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception { |
|
200 |
ArrayList<String> finalargs = new ArrayList<String>(); |
|
201 |
||
202 |
String[] whiteboxOpts = new String[] { |
|
203 |
"-Xbootclasspath/a:.", |
|
204 |
"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", |
|
205 |
"-cp", System.getProperty("java.class.path"), |
|
206 |
}; |
|
207 |
||
208 |
if (useTestDotJavaDotOpts) { |
|
209 |
// System.getProperty("test.java.opts") is '' if no options is set, |
|
210 |
// we need to skip such a result |
|
211 |
String[] externalVMOpts = new String[0]; |
|
212 |
if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) { |
|
213 |
externalVMOpts = System.getProperty("test.java.opts").split(" "); |
|
214 |
} |
|
215 |
finalargs.addAll(Arrays.asList(externalVMOpts)); |
|
216 |
} |
|
217 |
||
218 |
finalargs.addAll(Arrays.asList(vmargs)); |
|
219 |
finalargs.addAll(Arrays.asList(whiteboxOpts)); |
|
220 |
finalargs.add(classname); |
|
221 |
finalargs.addAll(Arrays.asList(arguments)); |
|
222 |
||
223 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0])); |
|
224 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
225 |
output.shouldHaveExitValue(0); |
|
226 |
||
227 |
return output; |
|
228 |
} |
|
229 |
||
230 |
private static void getMinInitialMaxHeap(String[] args, MinInitialMaxValues val) throws Exception { |
|
231 |
OutputAnalyzer output = runWhiteBoxTest(args, ErgoArgsPrinter.class.getName(), new String[] {}, false); |
|
232 |
||
233 |
// the output we watch for has the following format: |
|
234 |
// |
|
235 |
// "Minimum heap X Initial heap Y Maximum heap Z Min alignment A Max Alignment B" |
|
236 |
// |
|
237 |
// where A, B, X, Y and Z are sizes in bytes. |
|
238 |
// Unfortunately there is no other way to retrieve the minimum heap size and |
|
239 |
// the alignments. |
|
240 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
241 |
Matcher m = Pattern.compile("Minimum heap \\d+ Initial heap \\d+ Maximum heap \\d+ Space alignment \\d+ Heap alignment \\d+"). |
17389 | 242 |
matcher(output.getStdout()); |
243 |
if (!m.find()) { |
|
244 |
throw new RuntimeException("Could not find heap size string."); |
|
245 |
} |
|
246 |
||
247 |
String match = m.group(); |
|
248 |
||
249 |
// actual values |
|
250 |
val.minHeapSize = valueAfter(match, "Minimum heap "); |
|
251 |
val.initialHeapSize = valueAfter(match, "Initial heap "); |
|
252 |
val.maxHeapSize = valueAfter(match, "Maximum heap "); |
|
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
253 |
val.spaceAlignment = valueAfter(match, "Space alignment "); |
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
254 |
val.heapAlignment = valueAfter(match, "Heap alignment "); |
17389 | 255 |
} |
256 |
||
257 |
/** |
|
258 |
* Verify whether the VM automatically synchronizes minimum and initial heap size if only |
|
259 |
* one is given for the GC specified. |
|
260 |
*/ |
|
261 |
public static void checkErgonomics(String[] args, long[] newoldsize, |
|
262 |
long expectedMin, long expectedInitial) throws Exception { |
|
263 |
||
264 |
MinInitialMaxValues v = new MinInitialMaxValues(); |
|
265 |
getMinInitialMaxHeap(args, v); |
|
266 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
267 |
if ((expectedMin != -1) && (align_up(expectedMin, v.heapAlignment) != v.minHeapSize)) { |
17389 | 268 |
throw new RuntimeException("Actual minimum heap size of " + v.minHeapSize + |
269 |
" differs from expected minimum heap size of " + expectedMin); |
|
270 |
} |
|
271 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
272 |
if ((expectedInitial != -1) && (align_up(expectedInitial, v.heapAlignment) != v.initialHeapSize)) { |
17389 | 273 |
throw new RuntimeException("Actual initial heap size of " + v.initialHeapSize + |
274 |
" differs from expected initial heap size of " + expectedInitial); |
|
275 |
} |
|
276 |
||
277 |
// always check the invariant min <= initial <= max heap size |
|
278 |
if (!(v.minHeapSize <= v.initialHeapSize && v.initialHeapSize <= v.maxHeapSize)) { |
|
279 |
throw new RuntimeException("Inconsistent min/initial/max heap sizes, they are " + |
|
280 |
v.minHeapSize + "/" + v.initialHeapSize + "/" + v.maxHeapSize); |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
/** |
|
285 |
* Verify whether the VM respects the given maximum heap size in MB for the |
|
286 |
* GC specified. |
|
287 |
* @param gcflag The garbage collector to test as command line flag. E.g. -XX:+UseG1GC |
|
288 |
* @param maxHeapSize the maximum heap size to verify, in MB. |
|
289 |
*/ |
|
290 |
public static void checkGenMaxHeapSize(String gcflag, long maxHeapsize) throws Exception { |
|
291 |
final long K = 1024; |
|
292 |
||
293 |
MinInitialMaxValues v = new MinInitialMaxValues(); |
|
294 |
getMinInitialMaxHeap(new String[] { gcflag, "-XX:MaxHeapSize=" + maxHeapsize + "M" }, v); |
|
295 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
296 |
long expectedHeapSize = align_up(maxHeapsize * K * K, v.heapAlignment); |
17389 | 297 |
long actualHeapSize = v.maxHeapSize; |
298 |
||
299 |
if (actualHeapSize > expectedHeapSize) { |
|
300 |
throw new RuntimeException("Heap has " + actualHeapSize + |
|
301 |
" bytes, expected to be less than " + expectedHeapSize); |
|
302 |
} |
|
303 |
} |
|
304 |
||
305 |
private static long getFlagValue(String flag, String where) { |
|
306 |
Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where); |
|
307 |
if (!m.find()) { |
|
308 |
throw new RuntimeException("Could not find value for flag " + flag + " in output string"); |
|
309 |
} |
|
310 |
String match = m.group(); |
|
311 |
return Long.parseLong(match.substring(match.lastIndexOf(" ") + 1, match.length())); |
|
312 |
} |
|
313 |
||
314 |
private static void shouldContainOrNot(OutputAnalyzer output, boolean contains, String message) throws Exception { |
|
315 |
if (contains) { |
|
316 |
output.shouldContain(message); |
|
317 |
} else { |
|
318 |
output.shouldNotContain(message); |
|
319 |
} |
|
320 |
} |
|
321 |
||
322 |
private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception { |
|
323 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags); |
|
324 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
325 |
shouldContainOrNot(output, hasWarning, "Warning"); |
|
326 |
shouldContainOrNot(output, hasError, "Error"); |
|
327 |
output.shouldHaveExitValue(errorcode); |
|
328 |
} |
|
329 |
||
330 |
private static void expectError(String[] flags) throws Exception { |
|
331 |
expect(flags, false, true, 1); |
|
332 |
} |
|
333 |
||
334 |
private static void expectValid(String[] flags) throws Exception { |
|
335 |
expect(flags, false, false, 0); |
|
336 |
} |
|
337 |
} |