Path: blob/master/test/hotspot/jtreg/gc/g1/TestHumongousConcurrentStartUndo.java
40942 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.g1;2425/*26* @test TestHumongousConcurrentStartUndo27* @summary Tests an alternating sequence of Concurrent Mark and Concurrent Undo28* cycles.29* reclaim heap occupancy falls below the IHOP value.30* @requires vm.gc.G131* @library /test/lib /testlibrary /32* @modules java.base/jdk.internal.misc33* java.management34* @build sun.hotspot.WhiteBox35* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox36* sun.hotspot.WhiteBox$WhiteBoxPermission37* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.38* gc.g1.TestHumongousConcurrentStartUndo39*/4041import gc.testlibrary.Helpers;4243import sun.hotspot.WhiteBox;44import jdk.test.lib.process.OutputAnalyzer;45import jdk.test.lib.process.ProcessTools;4647import java.lang.ref.Reference;4849public class TestHumongousConcurrentStartUndo {50// Heap sizes < 224 MB are increased to 224 MB if vm_page_size == 64K to51// fulfill alignment constraints.52private static final int HeapSize = 224; // MB53private static final int HeapRegionSize = 1; // MB54private static final int InitiatingHeapOccupancyPercent = 50; // %55private static final int YoungSize = HeapSize / 8;5657public static void main(String[] args) throws Exception {58ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(59"-Xbootclasspath/a:.",60"-XX:+UseG1GC",61"-Xms" + HeapSize + "m",62"-Xmx" + HeapSize + "m",63"-Xmn" + YoungSize + "m",64"-XX:G1HeapRegionSize=" + HeapRegionSize + "m",65"-XX:InitiatingHeapOccupancyPercent=" + InitiatingHeapOccupancyPercent,66"-XX:-G1UseAdaptiveIHOP",67"-XX:+UnlockDiagnosticVMOptions",68"-XX:+WhiteBoxAPI",69"-Xlog:gc*",70EdenObjectAllocatorWithHumongousAllocation.class.getName());7172OutputAnalyzer output = new OutputAnalyzer(pb.start());73output.shouldContain("Pause Young (Concurrent Start) (G1 Humongous Allocation)");74output.shouldContain("Concurrent Undo Cycle");75output.shouldContain("Concurrent Mark Cycle");76output.shouldHaveExitValue(0);77System.out.println(output.getStdout());78}7980static class EdenObjectAllocatorWithHumongousAllocation {81private static final WhiteBox WB = WhiteBox.getWhiteBox();8283private static final int M = 1024 * 1024;84// Make humongous object size 75% of region size85private static final int HumongousObjectSize =86(int)(HeapRegionSize * M * 0.75);87// Number of objects to allocate to go above IHOP88private static final int NumHumongousObjectAllocations =89(int)(((HeapSize - YoungSize) * 80 / 100.0) / HeapRegionSize);909192private static void allocateHumongous(int num, Object[] holder) {93for (int i = 0; i < num; i++) {94if (i % 10 == 0) {95System.out.println("Allocating humongous object " + i + "/" + num +96" of size " + HumongousObjectSize + " bytes");97}98holder[i % holder.length] = new byte[HumongousObjectSize];99}100}101102private static void runConcurrentUndoCycle() {103// Start from an "empty" heap.104WB.fullGC();105// The queue only holds one element, so only one humongous object106// will be reachable and the concurrent operation should be undone.107allocateHumongous(NumHumongousObjectAllocations, new Object[1]);108Helpers.waitTillCMCFinished(WB, 1);109}110111private static void runConcurrentMarkCycle() {112Object[] a = new Object[NumHumongousObjectAllocations];113// Start from an "empty" heap.114WB.fullGC();115// Try to trigger a concurrent mark cycle. Block concurrent operation116// while we are allocating more humongous objects than the IHOP threshold.117// After releasing control, trigger the full cycle.118try {119System.out.println("Acquire CM control");120WB.concurrentGCAcquireControl();121allocateHumongous(NumHumongousObjectAllocations, a);122} finally {123System.out.println("Release CM control");124WB.concurrentGCReleaseControl();125}126// At this point we kept NumHumongousObjectAllocations humongous objects live127// in "a" which is larger than the IHOP threshold. Another dummy humongous128// allocation must trigger a concurrent cycle that is not an Undo Cycle.129allocateHumongous(1, new Object[1]);130Helpers.waitTillCMCFinished(WB, 1);131132Reference.reachabilityFence(a);133}134135public static void main(String [] args) throws Exception {136for (int iterate = 0; iterate < 3; iterate++) {137runConcurrentUndoCycle();138runConcurrentMarkCycle();139}140}141}142}143144145146