comparison test/gc/7168848/HumongousAlloc.java @ 6105:9a344d88dc22

7168848: Add test to check that humongous object allocation path also checks the heap occupancy. Summary: Added test that checks humongous object allocation path also check the heap occupancy and initiate a marking cycle when / if needed. Reviewed-by: brutisso, jwilhelm
author mnunez
date Mon, 21 May 2012 14:59:59 +0200
parents
children
comparison
equal deleted inserted replaced
6104:c92a79900986 6105:9a344d88dc22
1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test Humongous.java
26 * @bug 7168848
27 * @summary G1: humongous object allocations should initiate marking cycles when necessary
28 * @run main/othervm -Xms100m -Xmx100m -XX:+PrintGC -XX:G1HeapRegionSize=1m -XX:+UseG1GC HumongousAlloc
29 *
30 */
31 import java.lang.management.GarbageCollectorMXBean;
32 import java.lang.management.ManagementFactory;
33 import java.util.List;
34
35 public class HumongousAlloc {
36
37 public static byte[] dummy;
38 private static int sleepFreq = 40;
39 private static int sleepTime = 1000;
40 private static double size = 0.75;
41 private static int iterations = 50;
42 private static int MB = 1024 * 1024;
43
44 public static void allocate(int size, int sleepTime, int sleepFreq) throws InterruptedException {
45 System.out.println("Will allocate objects of size: " + size
46 + " bytes and sleep for " + sleepTime
47 + " ms after every " + sleepFreq + "th allocation.");
48 int count = 0;
49 while (count < iterations) {
50 for (int i = 0; i < sleepFreq; i++) {
51 dummy = new byte[size - 16];
52 }
53 Thread.sleep(sleepTime);
54 count++;
55 }
56 }
57
58 public static void main(String[] args) throws InterruptedException {
59 allocate((int) (size * MB), sleepTime, sleepFreq);
60 List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans();
61 for (GarbageCollectorMXBean collector : collectors) {
62 if (collector.getName().contains("G1 Old")) {
63 long count = collector.getCollectionCount();
64 if (count > 0) {
65 throw new RuntimeException("Failed: FullGCs should not have happened. The number of FullGC run is " + count);
66 }
67 else {
68 System.out.println("Passed.");
69 }
70 }
71 }
72 }
73 }
74