58 + "(Ratio))=[^ ]+)")) |
58 + "(Ratio))=[^ ]+)")) |
59 ); |
59 ); |
60 |
60 |
61 // Test NewSize and MaxNewSize |
61 // Test NewSize and MaxNewSize |
62 testNewSizeFlags(20 * M, 10 * M, 30 * M, 40 * M, options, false); |
62 testNewSizeFlags(20 * M, 10 * M, 30 * M, 40 * M, options, false); |
63 testNewSizeFlags(10 * M, 20 * M, 30 * M, 40 * M, options, false); |
63 testNewSizeFlags(10 * M, 20 * M, 30 * M, 80 * M, options, false); |
64 testNewSizeFlags(-1, 20 * M, 30 * M, 40 * M, options, false); |
64 testNewSizeFlags(-1, 20 * M, 30 * M, 40 * M, options, false); |
65 testNewSizeFlags(10 * M, -1, 30 * M, 40 * M, options, false); |
65 testNewSizeFlags(10 * M, -1, 30 * M, 40 * M, options, false); |
66 testNewSizeFlags(20 * M, 20 * M, 30 * M, 40 * M, options, false); |
66 testNewSizeFlags(20 * M, 20 * M, 30 * M, 40 * M, options, false); |
67 testNewSizeFlags(20 * M, 30 * M, 40 * M, 50 * M, options, false); |
67 testNewSizeFlags(20 * M, 30 * M, 40 * M, 50 * M, options, false); |
68 testNewSizeFlags(30 * M, 100 * M, 150 * M, 200 * M, options, false); |
68 testNewSizeFlags(30 * M, 100 * M, 150 * M, 200 * M, options, false); |
69 testNewSizeFlags(0, -1, 30 * M, 40 * M, options, false); |
69 testNewSizeFlags(20 * M, 30 * M, 128 * M, 128 * M, options, false); |
70 |
70 |
71 // Test -Xmn |
71 // Test -Xmn |
72 testXmnFlags(0, 30 * M, 40 * M, options, true); |
72 testXmnFlags(0, 30 * M, 40 * M, options, true); |
73 testXmnFlags(20 * M, 30 * M, 40 * M, options, false); |
73 testXmnFlags(20 * M, 30 * M, 40 * M, options, false); |
74 testXmnFlags(50 * M, 70 * M, 100 * M, options, false); |
74 testXmnFlags(50 * M, 70 * M, 100 * M, options, false); |
86 */ |
86 */ |
87 public static void testNewSizeFlags(long newSize, long maxNewSize, |
87 public static void testNewSizeFlags(long newSize, long maxNewSize, |
88 long heapSize, long maxHeapSize, |
88 long heapSize, long maxHeapSize, |
89 LinkedList<String> options, |
89 LinkedList<String> options, |
90 boolean failureExpected) throws Exception { |
90 boolean failureExpected) throws Exception { |
|
91 long expectedNewSize = newSize; |
|
92 long expectedMaxNewSize = (maxNewSize >= 0 ? Math.max(maxNewSize, newSize) : maxNewSize); |
91 testVMOptions(newSize, maxNewSize, |
93 testVMOptions(newSize, maxNewSize, |
92 heapSize, maxHeapSize, |
94 heapSize, maxHeapSize, |
93 newSize, (maxNewSize >= 0 ? Math.max(maxNewSize, newSize) : maxNewSize), |
95 expectedNewSize, expectedMaxNewSize, |
94 options, failureExpected); |
96 options, failureExpected); |
95 } |
97 } |
96 |
98 |
97 /** |
99 /** |
98 * Verify that -Xmn flag affect young gen size. |
100 * Verify that -Xmn flag affect young gen size. |
175 * max size, NewSizeVerifier do some object allocation to force garbage |
179 * max size, NewSizeVerifier do some object allocation to force garbage |
176 * collection and heap expansion. |
180 * collection and heap expansion. |
177 */ |
181 */ |
178 public static class NewSizeVerifier { |
182 public static class NewSizeVerifier { |
179 |
183 |
180 static WhiteBox wb = WhiteBox.getWhiteBox(); |
184 private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
|
185 private static final GCTypes.YoungGCType YOUNG_GC_TYPE = GCTypes.YoungGCType.getYoungGCType(); |
|
186 private static final long HEAP_SPACE_ALIGNMENT = WB.getHeapSpaceAlignment(); |
|
187 private static final long HEAP_ALIGNMENT = WB.getHeapAlignment(); |
|
188 private static final long PS_VIRTUAL_SPACE_ALIGNMENT = |
|
189 (YOUNG_GC_TYPE == GCTypes.YoungGCType.PSNew) ? WB.psVirtualSpaceAlignment() : 0; |
181 |
190 |
182 public static final int ARRAY_LENGTH = 100; |
191 public static final int ARRAY_LENGTH = 100; |
183 public static final int CHUNK_SIZE = 1024; |
192 public static final int CHUNK_SIZE = 1024; |
184 public static final int MAX_ITERATIONS = 10; |
193 public static final int MAX_ITERATIONS = 10; |
185 public static byte garbage[][] = new byte[ARRAY_LENGTH][]; |
194 public static byte garbage[][] = new byte[ARRAY_LENGTH][]; |
186 |
195 |
187 public static void main(String args[]) throws Exception { |
196 public static void main(String args[]) throws Exception { |
188 if (args.length != 2) { |
197 if (args.length != 4) { |
189 throw new IllegalArgumentException("Expected 2 args: <expectedNewSize> <expectedMaxNewSize>"); |
198 throw new IllegalArgumentException("Expected 4 args: <expectedNewSize> <expectedMaxNewSize> <initialHeapSize> <maxHeapSize>"); |
190 } |
199 } |
191 final long newSize = Long.valueOf(args[0]); |
200 final long newSize = Long.valueOf(args[0]); |
192 final long maxNewSize = Long.valueOf(args[1]); |
201 final long maxNewSize = Long.valueOf(args[1]); |
|
202 final long initialHeapSize = Long.valueOf(args[2]); |
|
203 final long maxHeapSize = Long.valueOf(args[3]); |
193 |
204 |
194 // verify initial size |
205 // verify initial size |
195 verifyNewSize(newSize, maxNewSize); |
206 verifyNewSize(newSize, maxNewSize, initialHeapSize, maxHeapSize); |
196 |
207 |
197 // force GC and verify that size is still correct |
208 // force GC and verify that size is still correct |
198 AllocationHelper allocator = new AllocationHelper(MAX_ITERATIONS, ARRAY_LENGTH, CHUNK_SIZE, () -> (verifyNewSize(newSize, maxNewSize))); |
209 AllocationHelper allocator = new AllocationHelper(MAX_ITERATIONS, ARRAY_LENGTH, CHUNK_SIZE, () -> (verifyNewSize(newSize, maxNewSize, initialHeapSize, maxHeapSize))); |
199 allocator.allocateMemoryAndVerifyNoOOME(); |
210 allocator.allocateMemoryAndVerifyNoOOME(); |
200 } |
211 } |
201 |
212 |
202 /** |
213 /** |
203 * Verify that actual young gen size conforms NewSize and MaxNewSize values. |
214 * Verify that actual young gen size conforms NewSize and MaxNewSize values. |
204 */ |
215 */ |
205 public static Void verifyNewSize(long newSize, long maxNewSize) { |
216 public static Void verifyNewSize(long newSize, long maxNewSize, |
206 long alignedNewSize = alignNewSize(newSize); |
217 long initialHeapSize, long maxHeapSize) { |
207 long alignedMaxNewSize = alignNewSize(maxNewSize); |
218 long alignedNewSize = alignGenSize(newSize); |
|
219 long alignedMaxNewSize = alignGenSize(maxNewSize); |
|
220 long alignedXms = alignHeapSize(initialHeapSize); |
|
221 long alignedXmx = alignHeapSize(maxHeapSize); |
208 |
222 |
209 MemoryUsage youngGenUsage = getYoungGenUsage(); |
223 MemoryUsage youngGenUsage = getYoungGenUsage(); |
|
224 long initSize = youngGenUsage.getInit(); |
|
225 long commitedSize = youngGenUsage.getCommitted(); |
|
226 long maxSize = youngGenUsage.getMax(); |
210 |
227 |
211 if (newSize != -1) { |
228 if (newSize != -1) { |
212 if (youngGenUsage.getInit() < alignedNewSize) { |
229 if (initSize < alignedNewSize) { |
213 throw new RuntimeException("initial new size < NewSize value: " |
230 throw new RuntimeException("initial new size < NewSize value: " |
214 + youngGenUsage.getInit() + " < " + alignedNewSize); |
231 + initSize + " < " + alignedNewSize); |
215 } |
232 } |
216 |
233 |
217 if (youngGenUsage.getCommitted() < alignedNewSize) { |
234 if (commitedSize < alignedNewSize) { |
218 throw new RuntimeException("actual new size < NewSize value: " |
235 throw new RuntimeException("actual new size < NewSize value: " |
219 + youngGenUsage.getCommitted() + " < " + alignedNewSize); |
236 + commitedSize + " < " + alignedNewSize); |
220 } |
237 } |
221 |
238 |
222 // for G1 max new size == committed new size |
239 // for G1 max new size == committed new size |
223 if (GCTypes.YoungGCType.getYoungGCType() != GCTypes.YoungGCType.G1 |
240 if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1 |
224 && youngGenUsage.getMax() < alignedNewSize) { |
241 && maxSize < alignedNewSize) { |
225 throw new RuntimeException("max new size < NewSize value: " |
242 throw new RuntimeException("max new size < NewSize value: " |
226 + youngGenUsage.getMax() + " < " + alignedNewSize); |
243 + maxSize + " < " + alignedNewSize); |
227 } |
244 } |
228 } |
245 } |
229 |
246 |
230 if (maxNewSize != -1) { |
247 if (maxNewSize != -1) { |
231 if (youngGenUsage.getInit() > alignedMaxNewSize) { |
248 if (initSize > alignedMaxNewSize) { |
232 throw new RuntimeException("initial new size > MaxNewSize value: " |
249 throw new RuntimeException("initial new size > MaxNewSize value: " |
233 + youngGenUsage.getInit() + " > " + alignedMaxNewSize); |
250 + initSize + " > " + alignedMaxNewSize); |
234 } |
251 } |
235 |
252 |
236 if (youngGenUsage.getCommitted() > alignedMaxNewSize) { |
253 if (commitedSize > alignedMaxNewSize) { |
237 throw new RuntimeException("actual new size > MaxNewSize value: " |
254 throw new RuntimeException("actual new size > MaxNewSize value: " |
238 + youngGenUsage.getCommitted() + " > " + alignedMaxNewSize); |
255 + commitedSize + " > " + alignedMaxNewSize); |
239 } |
256 } |
240 |
257 |
241 if (GCTypes.YoungGCType.getYoungGCType() != GCTypes.YoungGCType.G1 |
258 if (alignedXms != alignedXmx) { |
242 && youngGenUsage.getMax() != alignedMaxNewSize) { |
259 if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1 |
243 throw new RuntimeException("max new size != MaxNewSize value: " |
260 && maxSize != alignedMaxNewSize) { |
244 + youngGenUsage.getMax() + " != " + alignedMaxNewSize); |
261 throw new RuntimeException("max new size != MaxNewSize value: " |
|
262 + maxSize + " != " + alignedMaxNewSize); |
|
263 } |
|
264 } else { |
|
265 if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1 |
|
266 && maxSize != alignedNewSize) { |
|
267 throw new RuntimeException("max new size != NewSize for case InitialHeapSize == MaxHeapSize value: " |
|
268 + maxSize + " != " + alignedNewSize + " HeapSize == " + alignedXms); |
|
269 } |
245 } |
270 } |
246 } |
271 } |
247 return null; |
272 return null; |
248 } |
273 } |
249 |
274 |
254 * for other GCs it is EdenUsage + 2 * SurvivorUsage. |
279 * for other GCs it is EdenUsage + 2 * SurvivorUsage. |
255 * For G1 max value is just LONG_MAX. |
280 * For G1 max value is just LONG_MAX. |
256 * For all GCs used value is 0. |
281 * For all GCs used value is 0. |
257 */ |
282 */ |
258 private static MemoryUsage getYoungGenUsage() { |
283 private static MemoryUsage getYoungGenUsage() { |
259 if (GCTypes.YoungGCType.getYoungGCType() == GCTypes.YoungGCType.G1) { |
284 MemoryUsage edenUsage = HeapRegionUsageTool.getEdenUsage(); |
260 return new MemoryUsage(HeapRegionUsageTool.getEdenUsage().getInit() |
285 MemoryUsage survivorUsage = HeapRegionUsageTool.getSurvivorUsage(); |
261 + HeapRegionUsageTool.getSurvivorUsage().getInit(), |
286 long edenUsageInit = edenUsage.getInit(); |
262 0, |
287 long edenUsageCommited = edenUsage.getCommitted(); |
263 HeapRegionUsageTool.getEdenUsage().getCommitted() |
288 long survivorUsageInit = survivorUsage.getInit(); |
264 + HeapRegionUsageTool.getSurvivorUsage().getCommitted(), |
289 long survivorUsageCommited = survivorUsage.getCommitted(); |
265 Long.MAX_VALUE); |
290 |
|
291 if (YOUNG_GC_TYPE == GCTypes.YoungGCType.G1) { |
|
292 return new MemoryUsage(edenUsageInit + survivorUsageInit, 0, |
|
293 edenUsageCommited + survivorUsageCommited, Long.MAX_VALUE); |
266 } else { |
294 } else { |
267 return new MemoryUsage(HeapRegionUsageTool.getEdenUsage().getInit() |
295 return new MemoryUsage(edenUsageInit + survivorUsageInit * 2, 0, |
268 + HeapRegionUsageTool.getSurvivorUsage().getInit() * 2, |
296 edenUsageCommited + survivorUsageCommited * 2, |
269 0, |
297 edenUsage.getMax() + survivorUsage.getMax() * 2); |
270 HeapRegionUsageTool.getEdenUsage().getCommitted() |
|
271 + HeapRegionUsageTool.getSurvivorUsage().getCommitted() * 2, |
|
272 HeapRegionUsageTool.getEdenUsage().getMax() |
|
273 + HeapRegionUsageTool.getSurvivorUsage().getMax() * 2); |
|
274 } |
298 } |
275 } |
299 } |
276 |
300 |
277 /** |
301 /** |
278 * Align value regardful to used young GC. |
302 * Align generation size regardful to used young GC. |
279 */ |
303 */ |
280 public static long alignNewSize(long value) { |
304 public static long alignGenSize(long value) { |
281 switch (GCTypes.YoungGCType.getYoungGCType()) { |
305 switch (YOUNG_GC_TYPE) { |
282 case DefNew: |
306 case DefNew: |
283 case ParNew: |
307 case ParNew: |
284 return HeapRegionUsageTool.alignDown(value, wb.getHeapSpaceAlignment()); |
308 return HeapRegionUsageTool.alignDown(value, HEAP_SPACE_ALIGNMENT); |
285 case PSNew: |
309 case PSNew: |
286 return HeapRegionUsageTool.alignUp(HeapRegionUsageTool.alignDown(value, |
310 return HeapRegionUsageTool.alignUp(HeapRegionUsageTool.alignDown(value, |
287 wb.getHeapSpaceAlignment()), |
311 HEAP_SPACE_ALIGNMENT), |
288 wb.psVirtualSpaceAlignment()); |
312 PS_VIRTUAL_SPACE_ALIGNMENT); |
289 case G1: |
313 case G1: |
290 return HeapRegionUsageTool.alignUp(value, wb.g1RegionSize()); |
314 return HeapRegionUsageTool.alignUp(value, WB.g1RegionSize()); |
291 default: |
315 default: |
292 throw new RuntimeException("Unexpected young GC type"); |
316 throw new RuntimeException("Unexpected young GC type"); |
293 } |
317 } |
294 } |
318 } |
|
319 |
|
320 /** |
|
321 * Align heap size. |
|
322 */ |
|
323 public static long alignHeapSize(long value){ |
|
324 return HeapRegionUsageTool.alignUp(value,HEAP_ALIGNMENT); |
|
325 } |
295 } |
326 } |
296 } |
327 } |