38 wb.printHeapSizes();
39 }
40 }
41
42 final class MinInitialMaxValues {
43 public long minHeapSize;
44 public long initialHeapSize;
45 public long maxHeapSize;
46
47 public long spaceAlignment;
48 public long heapAlignment;
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);
58 }
59
60 public static void checkMinInitialErgonomics(String gcflag) throws Exception {
61 // heap sizing ergonomics use the value NewSize + OldSize as default values
62 // for ergonomics calculation. Retrieve these values.
63 long[] values = new long[2];
64 getNewOldSize(gcflag, values);
65
66 // we check cases with values smaller and larger than this default value.
67 long newPlusOldSize = values[0] + values[1];
68 long smallValue = newPlusOldSize / 2;
69 long largeValue = newPlusOldSize * 2;
70 long maxHeapSize = largeValue + (2 * 1024 * 1024);
71
72 // -Xms is not set
73 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize }, values, -1, -1);
74 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue);
75 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
76 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=0" }, values, -1, -1);
77
78 // -Xms is set to zero
79 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0" }, values, -1, -1);
80 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue);
81 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
82 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=0" }, values, -1, -1);
83
84 // -Xms is set to small value
85 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue }, values, -1, -1);
86 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
87 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
88 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=0" }, values, smallValue, -1);
89
90 // -Xms is set to large value
91 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue }, values, largeValue, largeValue);
92 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:InitialHeapSize=0" }, values, largeValue, -1);
93 }
94
95 private static long align_up(long value, long alignment) {
96 long alignmentMinusOne = alignment - 1;
97 return (value + alignmentMinusOne) & ~alignmentMinusOne;
98 }
99
100 private static void getNewOldSize(String gcflag, long[] values) throws Exception {
101 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(gcflag,
102 "-XX:+PrintFlagsFinal", "-version");
103 OutputAnalyzer output = new OutputAnalyzer(pb.start());
104 output.shouldHaveExitValue(0);
105
106 String stdout = output.getStdout();
107 values[0] = getFlagValue(" NewSize", stdout);
108 values[1] = getFlagValue(" OldSize", stdout);
109 }
110
111 public static void checkGenMaxHeapErgo(String gcflag) throws Exception {
112 TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 4);
113 TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 5);
114 }
115
116 private static void checkInvalidMinInitialHeapCombinations(String gcflag) throws Exception {
117 expectError(new String[] { gcflag, "-XX:InitialHeapSize=1023K", "-version" });
118 expectError(new String[] { gcflag, "-Xms64M", "-XX:InitialHeapSize=32M", "-version" });
119 }
120
121 private static void checkValidMinInitialHeapCombinations(String gcflag) throws Exception {
122 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=1024K", "-version" });
123 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms4M", "-version" });
124 expectValid(new String[] { gcflag, "-Xms4M", "-XX:InitialHeapSize=8M", "-version" });
125 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms8M", "-version" });
126 // the following is not an error as -Xms sets both minimal and initial heap size
127 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-Xms8M", "-version" });
128 }
129
130 private static void checkInvalidInitialMaxHeapCombinations(String gcflag) throws Exception {
131 expectError(new String[] { gcflag, "-XX:MaxHeapSize=2047K", "-version" });
132 expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=8M", "-version" });
133 expectError(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" });
134 }
135
136 private static void checkValidInitialMaxHeapCombinations(String gcflag) throws Exception {
137 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" });
138 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:InitialHeapSize=4M", "-version" });
139 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=4M", "-version" });
140 // a value of "0" for initial heap size means auto-detect
141 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=0M", "-version" });
142 }
143
144 private static long valueAfter(String source, String match) {
145 int start = source.indexOf(match) + match.length();
146 String tail = source.substring(start).split(" ")[0];
147 return Long.parseLong(tail);
148 }
149
150 /**
151 * Executes a new VM process with the given class and parameters.
152 * @param vmargs Arguments to the VM to run
153 * @param classname Name of the class to run
154 * @param arguments Arguments to the class
155 * @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string
156 * @return The OutputAnalyzer with the results for the invocation.
157 */
158 public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {
159 ArrayList<String> finalargs = new ArrayList<String>();
160
161 String[] whiteboxOpts = new String[] {
162 "-Xbootclasspath/a:.",
163 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
277 output.shouldNotContain(message);
278 }
279 }
280
281 private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception {
282 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags);
283 OutputAnalyzer output = new OutputAnalyzer(pb.start());
284 shouldContainOrNot(output, hasWarning, "Warning");
285 shouldContainOrNot(output, hasError, "Error");
286 output.shouldHaveExitValue(errorcode);
287 }
288
289 private static void expectError(String[] flags) throws Exception {
290 expect(flags, false, true, 1);
291 }
292
293 private static void expectValid(String[] flags) throws Exception {
294 expect(flags, false, false, 0);
295 }
296 }
297
|
38 wb.printHeapSizes();
39 }
40 }
41
42 final class MinInitialMaxValues {
43 public long minHeapSize;
44 public long initialHeapSize;
45 public long maxHeapSize;
46
47 public long spaceAlignment;
48 public long heapAlignment;
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);
58 checkInvalidMinMaxHeapCombinations(gcflag);
59 checkValidMinMaxHeapCombinations(gcflag);
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;
72 long maxHeapSize = largeValue + (2 * 1024 * 1024);
73
74 // -Xms is not set
75 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize }, values, -1, -1);
76 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue }, values, smallValue, -1);
77 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + largeValue }, values, largeValue, -1);
78 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=0" }, values, -1, -1);
79 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue);
80 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
81 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=0" }, values, -1, -1);
82 // Some extra checks when both are set.
83 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
84 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
85 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + largeValue, "-XX:InitialHeapSize=" + largeValue }, values, largeValue, largeValue);
86
87 // -Xms is set to zero
88 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0" }, values, -1, -1);
89 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue }, values, smallValue, -1);
90 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + largeValue }, values, largeValue, -1);
91 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=0" }, values, -1, -1);
92 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue);
93 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
94 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=0" }, values, -1, -1);
95 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
96 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
97 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + largeValue, "-XX:InitialHeapSize=" + largeValue }, values, largeValue, largeValue);
98
99 // -Xms is set to small value
100 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue }, values, -1, -1);
101 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:MinHeapSize=" + smallValue }, values, smallValue, smallValue);
102 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:MinHeapSize=0" }, values, -1, smallValue);
103 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
104 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
105 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=0" }, values, smallValue, -1);
106
107 // -Xms is set to large value
108 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue }, values, largeValue, largeValue);
109 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:InitialHeapSize=0" }, values, largeValue, -1);
110 checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:MinHeapSize=0" }, values, -1, largeValue);
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 {
135 expectError(new String[] { gcflag, "-XX:InitialHeapSize=1023K", "-version" });
136 expectError(new String[] { gcflag, "-Xms64M", "-XX:InitialHeapSize=32M", "-version" });
137 expectError(new String[] { gcflag, "-XX:MinHeapSize=1023K", "-version" });
138 expectError(new String[] { gcflag, "-Xms4M", "-XX:MinHeapSize=8M", "-version" });
139 expectError(new String[] { gcflag, "-XX:MinHeapSize=8M -XX:InitialHeapSize=4m" });
140 }
141
142 private static void checkValidMinInitialHeapCombinations(String gcflag) throws Exception {
143 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=1024K", "-version" });
144 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms4M", "-version" });
145 expectValid(new String[] { gcflag, "-Xms4M", "-XX:InitialHeapSize=8M", "-version" });
146 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms8M", "-version" });
147 expectValid(new String[] { gcflag, "-XX:MinHeapSize=1024K", "-version" });
148 expectValid(new String[] { gcflag, "-XX:MinHeapSize=8M", "-Xms4M", "-version" });
149 expectValid(new String[] { gcflag, "-XX:MinHeapSize=8M", "-Xms8M", "-version" });
150 expectValid(new String[] { gcflag, "-Xms8M", "-XX:MinHeapSize=4M", "-version" });
151 // the following is not an error as -Xms sets both minimal and initial heap size
152 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-Xms8M", "-version" });
153 expectValid(new String[] { gcflag, "-XX:MinHeapSize=4M", "-Xms8M", "-version" });
154 }
155
156 private static void checkInvalidInitialMaxHeapCombinations(String gcflag) throws Exception {
157 expectError(new String[] { gcflag, "-XX:MaxHeapSize=2047K", "-version" });
158 expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=8M", "-version" });
159 expectError(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" });
160 }
161
162 private static void checkInvalidMinMaxHeapCombinations(String gcflag) throws Exception {
163 expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=8M", "-version" });
164 expectError(new String[] { gcflag, "-XX:MinHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" });
165 }
166
167
168 private static void checkValidInitialMaxHeapCombinations(String gcflag) throws Exception {
169 expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" });
170 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:InitialHeapSize=4M", "-version" });
171 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=4M", "-version" });
172 // a value of "0" for initial heap size means auto-detect
173 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=0M", "-version" });
174 }
175
176 private static void checkValidMinMaxHeapCombinations(String gcflag) throws Exception {
177 expectValid(new String[] { gcflag, "-XX:MinHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" });
178 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:MinHeapSize=4M", "-version" });
179 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=4M", "-version" });
180 // a value of "0" for min heap size means auto-detect
181 expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=0M", "-version" });
182 }
183
184 private static long valueAfter(String source, String match) {
185 int start = source.indexOf(match) + match.length();
186 String tail = source.substring(start).split(" ")[0];
187 return Long.parseLong(tail);
188 }
189
190 /**
191 * Executes a new VM process with the given class and parameters.
192 * @param vmargs Arguments to the VM to run
193 * @param classname Name of the class to run
194 * @param arguments Arguments to the class
195 * @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string
196 * @return The OutputAnalyzer with the results for the invocation.
197 */
198 public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {
199 ArrayList<String> finalargs = new ArrayList<String>();
200
201 String[] whiteboxOpts = new String[] {
202 "-Xbootclasspath/a:.",
203 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
317 output.shouldNotContain(message);
318 }
319 }
320
321 private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception {
322 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags);
323 OutputAnalyzer output = new OutputAnalyzer(pb.start());
324 shouldContainOrNot(output, hasWarning, "Warning");
325 shouldContainOrNot(output, hasError, "Error");
326 output.shouldHaveExitValue(errorcode);
327 }
328
329 private static void expectError(String[] flags) throws Exception {
330 expect(flags, false, true, 1);
331 }
332
333 private static void expectValid(String[] flags) throws Exception {
334 expect(flags, false, false, 0);
335 }
336 }
|