--- /dev/null 2013-08-19 14:35:29.062603190 +0200 +++ new/test/gc/g1/TestHumongousAllocInitialMark.java 2013-09-23 17:49:30.778585697 +0200 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test Humongous.java + * @bug 7168848 + * @summary G1: humongous object allocations should initiate marking cycles when necessary + * @library /testlibrary + */ + +import com.oracle.java.testlibrary.*; + +public class HumongousAlloc { + private static final int g1HeapSize = 200; // MB + private static final int g1HeapRegionSize = 1; // MB + private static final int g1InitiatingHeapOccupancyPercent = 50; // % + + public static void main(String[] args) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UseG1GC", + "-Xms" + g1HeapSize + "m", + "-Xmx" + g1HeapSize + "m", + "-XX:G1HeapRegionSize=" + g1HeapRegionSize + "m", + "-XX:InitiatingHeapOccupancyPercent=" + g1InitiatingHeapOccupancyPercent, + "-XX:+PrintGC", + "-XX:+PrintGCDetails", + HumongousAllocRunner.class.getName()); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldContain("GC pause (G1 Humongous Allocation) (young) (initial-mark)"); + output.shouldNotContain("Full GC"); + output.shouldHaveExitValue(0); + } + + static class HumongousAllocRunner { + public static void main(String [] args) throws Exception { + // Object size is 75% of a region + final int g1HumongousObjectSize = + (int)(g1HeapRegionSize * 1024 * 1024 * 0.75); + + // Number of objects to allocate to go above IHOP + final int g1HumongousObjectAllocations = + (int)((g1HeapSize * g1InitiatingHeapOccupancyPercent / 100.0) / g1HeapRegionSize) + 1; + + // Allocate + for (int i = 1; i <= g1HumongousObjectAllocations; i++) { + System.err.println("Allocating humongous object " + i + "/" + g1HumongousObjectAllocations + + " of size " + g1HumongousObjectSize + " bytes"); + byte[] dummy = new byte[g1HumongousObjectSize]; + } + } + } +} +