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