Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/g1/TestEagerReclaimHumongousRegions.java
32284 views
/*1* Copyright (c) 2014, 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*/2223/*24* @test TestEagerReclaimHumongousRegions25* @bug 802795926* @summary Test to make sure that eager reclaim of humongous objects work. We simply try to fill27* up the heap with humongous objects that should be eagerly reclaimable to avoid Full GC.28* @key gc29* @library /testlibrary30*/3132import java.util.regex.Pattern;33import java.util.regex.Matcher;34import java.util.LinkedList;3536import com.oracle.java.testlibrary.OutputAnalyzer;37import com.oracle.java.testlibrary.ProcessTools;38import com.oracle.java.testlibrary.Asserts;3940class ReclaimRegionFast {41public static final int M = 1024*1024;4243public static LinkedList<Object> garbageList = new LinkedList<Object>();4445public static void genGarbage() {46for (int i = 0; i < 32*1024; i++) {47garbageList.add(new int[100]);48}49garbageList.clear();50}5152// A large object referenced by a static.53static int[] filler = new int[10 * M];5455public static void main(String[] args) {5657int[] large = new int[M];5859Object ref_from_stack = large;6061for (int i = 0; i < 100; i++) {62// A large object that will be reclaimed eagerly.63large = new int[6*M];64genGarbage();65// Make sure that the compiler cannot completely remove66// the allocation of the large object until here.67System.out.println(large);68}6970// Keep the reference to the first object alive.71System.out.println(ref_from_stack);72}73}7475public class TestEagerReclaimHumongousRegions {76public static void main(String[] args) throws Exception {77ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(78"-XX:+UseG1GC",79"-Xms128M",80"-Xmx128M",81"-Xmn16M",82"-XX:+PrintGC",83ReclaimRegionFast.class.getName());8485Pattern p = Pattern.compile("Full GC");8687OutputAnalyzer output = new OutputAnalyzer(pb.start());8889int found = 0;90Matcher m = p.matcher(output.getStdout());91while (m.find()) { found++; }92System.out.println("Issued " + found + " Full GCs");93Asserts.assertLT(found, 10, "Found that " + found + " Full GCs were issued. This is larger than the bound. Eager reclaim seems to not work at all");9495output.shouldHaveExitValue(0);96}97}9899100