Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/TestAllocHumongousFragment.java
32284 views
/*1* Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223/*24* @test TestAllocHumongousFragment25* @summary Make sure Shenandoah can recover from humongous allocation fragmentation26* @key gc27*28* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204829* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive30* -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify31* TestAllocHumongousFragment32*33* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204834* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive35* -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify36* TestAllocHumongousFragment37*38* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204839* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive40* -XX:-ShenandoahDegeneratedGC41* TestAllocHumongousFragment42*43* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204844* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive45* -XX:+ShenandoahDegeneratedGC46* TestAllocHumongousFragment47*/4849/*50* @test TestAllocHumongousFragment51* @summary Make sure Shenandoah can recover from humongous allocation fragmentation52* @key gc53*54* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204855* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive56* -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify57* TestAllocHumongousFragment58*59* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204860* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive61* -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify62* TestAllocHumongousFragment63*64* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204865* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive66* -XX:+ShenandoahOOMDuringEvacALot67* TestAllocHumongousFragment68*69* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204870* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive71* -XX:+ShenandoahAllocFailureALot72* TestAllocHumongousFragment73*74* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204875* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive76* -XX:+ShenandoahVerify77* TestAllocHumongousFragment78*/7980/*81* @test TestAllocHumongousFragment82* @summary Make sure Shenandoah can recover from humongous allocation fragmentation83* @key gc84*85* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204886* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive87* TestAllocHumongousFragment88*/8990/*91* @test TestAllocHumongousFragment92* @summary Make sure Shenandoah can recover from humongous allocation fragmentation93* @key gc94*95* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=204896* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static97* TestAllocHumongousFragment98*/99100/*101* @test TestAllocHumongousFragment102* @summary Make sure Shenandoah can recover from humongous allocation fragmentation103* @key gc104*105* @run main/othervm -Xmx1g -Xms1g -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048106* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact107* TestAllocHumongousFragment108*/109110/*111* @test TestAllocHumongousFragment112* @summary Make sure Shenandoah can recover from humongous allocation fragmentation113* @key gc114*115* @run main/othervm -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048116* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive117* -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify118* TestAllocHumongousFragment119*120* @run main/othervm -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048121* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive122* -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify123* TestAllocHumongousFragment124*125* @run main/othervm -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048126* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive127* -XX:+ShenandoahOOMDuringEvacALot128* TestAllocHumongousFragment129*130* @run main/othervm -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048131* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive132* -XX:+ShenandoahAllocFailureALot133* TestAllocHumongousFragment134*135* @run main/othervm -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048136* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu137* -XX:+ShenandoahVerify138* TestAllocHumongousFragment139*/140141/*142* @test TestAllocHumongousFragment143* @summary Make sure Shenandoah can recover from humongous allocation fragmentation144* @key gc145*146* @run main/othervm -verbose:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048147* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu148* TestAllocHumongousFragment149*/150151import java.util.*;152import java.util.concurrent.*;153154public class TestAllocHumongousFragment {155156static final long TARGET_MB = Long.getLong("target", 30_000); // 30 Gb allocations157static final long LIVE_MB = Long.getLong("occupancy", 700); // 700 Mb alive158159static volatile Object sink;160161static List<int[]> objects;162163public static void main(String[] args) throws Exception {164final int min = 128 * 1024;165final int max = 16 * 1024 * 1024;166final long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));167168objects = new ArrayList<>();169long current = 0;170171Random r = new Random();172for (long c = 0; c < count; c++) {173while (current > LIVE_MB * 1024 * 1024) {174int idx = ThreadLocalRandom.current().nextInt(objects.size());175int[] remove = objects.remove(idx);176current -= remove.length * 4 + 16;177}178179int[] newObj = new int[min + r.nextInt(max - min)];180current += newObj.length * 4 + 16;181objects.add(newObj);182sink = new Object();183184System.out.println("Allocated: " + (current / 1024 / 1024) + " Mb");185}186}187188}189190191