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