1 /*
 2  * Copyright (c) 2012, 2019, 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 package gc.g1;
25 
26 /*
27  * @test TestHumongousAllocNearlyFullRegion
28  * @bug 8143587
29  * @summary G1: humongous object allocations should work even when there is
30  *              not enough space in the heapRegion to fit a filler object.
31  * @requires vm.gc.G1
32  * @modules java.base/jdk.internal.misc
33  * @library /test/lib
34  * @run driver gc.g1.TestHumongousAllocNearlyFullRegion
35  */
36 
37 import jdk.test.lib.process.OutputAnalyzer;
38 import jdk.test.lib.process.ProcessTools;
39 
40 public class TestHumongousAllocNearlyFullRegion {
41     // Heap sizes < 224 MB are increased to 224 MB if vm_page_size == 64K to
42     // fulfill alignment constraints.
43     private static final int heapSize                       = 224; // MB
44     private static final int heapRegionSize                 = 1;   // MB
45 
46     public static void main(String[] args) throws Exception {
47         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
48             "-XX:+UseG1GC",
49             "-Xms" + heapSize + "m",
50             "-Xmx" + heapSize + "m",
51             "-XX:G1HeapRegionSize=" + heapRegionSize + "m",
52             "-Xlog:gc",
53             HumongousObjectAllocator.class.getName());
54 
55         OutputAnalyzer output = new OutputAnalyzer(pb.start());
56         output.shouldContain("Pause Young (Concurrent Start) (G1 Humongous Allocation)");
57         output.shouldHaveExitValue(0);
58     }
59 
60     static class HumongousObjectAllocator {
61         public static void main(String [] args) {
62             for (int i = 0; i < heapSize; i++) {
63                 // 131069 is the number of longs it takes to fill a heapRegion except
64                 // for 8 bytes on 64 bit.
65                 long[] largeObect = new long[131069];
66             }
67         }
68     }
69 }
70