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 * @library /testlibrary 29 */ 30 31 import com.oracle.java.testlibrary.*; 32 33 public class HumongousAlloc { 34 private static final int g1HeapSize = 200; // MB 35 private static final int g1HeapRegionSize = 1; // MB 36 private static final int g1InitiatingHeapOccupancyPercent = 50; // % 37 38 public static void main(String[] args) throws Exception { 39 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 40 "-XX:+UseG1GC", 41 "-Xms" + g1HeapSize + "m", 42 "-Xmx" + g1HeapSize + "m", 43 "-XX:G1HeapRegionSize=" + g1HeapRegionSize + "m", 44 "-XX:InitiatingHeapOccupancyPercent=" + g1InitiatingHeapOccupancyPercent, 45 "-XX:+PrintGC", 46 "-XX:+PrintGCDetails", 47 HumongousAllocRunner.class.getName()); 48 49 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 50 output.shouldContain("GC pause (G1 Humongous Allocation) (young) (initial-mark)"); 51 output.shouldNotContain("Full GC"); 52 output.shouldHaveExitValue(0); 53 } 54 55 static class HumongousAllocRunner { 56 public static void main(String [] args) throws Exception { 57 // Object size is 75% of a region 58 final int g1HumongousObjectSize = 59 (int)(g1HeapRegionSize * 1024 * 1024 * 0.75); 60 61 // Number of objects to allocate to go above IHOP 62 final int g1HumongousObjectAllocations = 63 (int)((g1HeapSize * g1InitiatingHeapOccupancyPercent / 100.0) / g1HeapRegionSize) + 1; 64 65 // Allocate 66 for (int i = 1; i <= g1HumongousObjectAllocations; i++) { 67 System.err.println("Allocating humongous object " + i + "/" + g1HumongousObjectAllocations + 68 " of size " + g1HumongousObjectSize + " bytes"); 69 byte[] dummy = new byte[g1HumongousObjectSize]; 70 } 71 } 72 } 73 } 74