Path: blob/master/test/hotspot/jtreg/gc/g1/TestEagerReclaimHumongousRegions.java
40942 views
/*1* Copyright (c) 2014, 2020, 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 TestEagerReclaimHumongousRegions27* @bug 802795928* @summary Test to make sure that eager reclaim of humongous objects work. We simply try to fill29* up the heap with humongous objects that should be eagerly reclaimable to avoid Full GC.30* @requires vm.gc.G131* @library /test/lib32* @modules java.base/jdk.internal.misc33* java.management34* @run driver gc.g1.TestEagerReclaimHumongousRegions35*/3637import java.util.regex.Pattern;38import java.util.regex.Matcher;39import java.util.LinkedList;4041import jdk.test.lib.process.OutputAnalyzer;42import jdk.test.lib.process.ProcessTools;43import jdk.test.lib.Asserts;4445class TestEagerReclaimHumongousRegionsReclaimRegionFast {46public static final int M = 1024*1024;4748public static LinkedList<Object> garbageList = new LinkedList<Object>();4950public static void genGarbage() {51for (int i = 0; i < 32*1024; i++) {52garbageList.add(new int[100]);53}54garbageList.clear();55}5657// A large object referenced by a static.58static int[] filler = new int[10 * M];5960public static void main(String[] args) {6162int[] large = new int[M];6364Object ref_from_stack = large;6566for (int i = 0; i < 100; i++) {67// A large object that will be reclaimed eagerly.68large = new int[6*M];69genGarbage();70// Make sure that the compiler cannot completely remove71// the allocation of the large object until here.72System.out.println(large);73}7475// Keep the reference to the first object alive.76System.out.println(ref_from_stack);77}78}7980public class TestEagerReclaimHumongousRegions {81public static void main(String[] args) throws Exception {82ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(83"-XX:+UseG1GC",84"-Xms128M",85"-Xmx128M",86"-Xmn16M",87"-Xlog:gc",88TestEagerReclaimHumongousRegionsReclaimRegionFast.class.getName());8990Pattern p = Pattern.compile("Full GC");9192OutputAnalyzer output = new OutputAnalyzer(pb.start());9394int found = 0;95Matcher m = p.matcher(output.getStdout());96while (m.find()) { found++; }97System.out.println("Issued " + found + " Full GCs");98Asserts.assertLT(found, 10, "Found that " + found + " Full GCs were issued. This is larger than the bound. Eager reclaim seems to not work at all");99100output.shouldHaveExitValue(0);101}102}103104105