Path: blob/master/test/hotspot/jtreg/gc/g1/TestEagerReclaimHumongousRegionsWithRefs.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 TestEagerReclaimHumongousRegionsWithRefs27* @bug 804817928* @summary Test to make sure that eager reclaim of humongous objects that have previously29* been referenced by other old gen regions work. We simply try to fill30* up the heap with humongous objects and create a remembered set entry from an object by31* referencing that we know is in the old gen. After changing this reference, the object32* should still be eagerly reclaimable to avoid Full GC.33* @requires vm.gc.G134* @library /test/lib35* @modules java.base/jdk.internal.misc36* java.management37* @run driver gc.g1.TestEagerReclaimHumongousRegionsWithRefs38*/3940import java.util.regex.Pattern;41import java.util.regex.Matcher;42import java.util.LinkedList;4344import jdk.test.lib.process.OutputAnalyzer;45import jdk.test.lib.process.ProcessTools;46import static jdk.test.lib.Asserts.*;4748class RefHolder {49Object ref;50}5152class TestEagerReclaimHumongousRegionsWithRefsReclaimRegionFast {5354public static final int M = 1024*1024;5556public static LinkedList<Object> garbageList = new LinkedList<Object>();5758public static void genGarbage() {59for (int i = 0; i < 32*1024; i++) {60garbageList.add(new int[100]);61}62garbageList.clear();63}646566// A large object referenced by a static.67static int[] filler = new int[10 * M];6869// Old gen object referencing the large object, generating remembered70// set entries.71static RefHolder fromOld = new RefHolder();7273public static void main(String[] args) {7475int[] large = new int[M];7677Object ref_from_stack = large;7879for (int i = 0; i < 100; i++) {80// A large object that will be reclaimed eagerly.81large = new int[6*M];82fromOld.ref = large;83genGarbage();84}8586// Keep the reference to the first object alive.87System.out.println(ref_from_stack);88}89}9091public class TestEagerReclaimHumongousRegionsWithRefs {9293public static void main(String[] args) throws Exception {94ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(95"-XX:+UseG1GC",96"-Xms128M",97"-Xmx128M",98"-Xmn16M",99"-Xlog:gc",100TestEagerReclaimHumongousRegionsWithRefsReclaimRegionFast.class.getName());101102Pattern p = Pattern.compile("Full GC");103104OutputAnalyzer output = new OutputAnalyzer(pb.start());105106int found = 0;107Matcher m = p.matcher(output.getStdout());108while (m.find()) {109found++;110}111System.out.println("Issued " + found + " Full GCs");112113assertLessThan(found, 10, "Found that " + found + " Full GCs were issued. This is larger than the bound. Eager reclaim of objects once referenced from old gen seems to not work at all");114output.shouldHaveExitValue(0);115}116}117118119120