Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/g1/TestEagerReclaimHumongousRegionsWithRefs.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 TestEagerReclaimHumongousRegionsWithRefs25* @bug 804817926* @summary Test to make sure that eager reclaim of humongous objects that have previously27* been referenced by other old gen regions work. We simply try to fill28* up the heap with humongous objects and create a remembered set entry from an object by29* referencing that we know is in the old gen. After changing this reference, the object30* should still be eagerly reclaimable to avoid Full GC.31* @key gc32* @library /testlibrary33*/3435import java.util.regex.Pattern;36import java.util.regex.Matcher;37import java.util.LinkedList;3839import com.oracle.java.testlibrary.OutputAnalyzer;40import com.oracle.java.testlibrary.ProcessTools;41import static com.oracle.java.testlibrary.Asserts.*;4243class RefHolder {44Object ref;45}4647class ReclaimRegionFast {4849public static final int M = 1024*1024;5051public static LinkedList<Object> garbageList = new LinkedList<Object>();5253public static void genGarbage() {54for (int i = 0; i < 32*1024; i++) {55garbageList.add(new int[100]);56}57garbageList.clear();58}596061// A large object referenced by a static.62static int[] filler = new int[10 * M];6364// Old gen object referencing the large object, generating remembered65// set entries.66static RefHolder fromOld = new RefHolder();6768public static void main(String[] args) {6970int[] large = new int[M];7172Object ref_from_stack = large;7374for (int i = 0; i < 100; i++) {75// A large object that will be reclaimed eagerly.76large = new int[6*M];77fromOld.ref = large;78genGarbage();79}8081// Keep the reference to the first object alive.82System.out.println(ref_from_stack);83}84}8586public class TestEagerReclaimHumongousRegionsWithRefs {8788public static void main(String[] args) throws Exception {89ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(90"-XX:+UseG1GC",91"-Xms128M",92"-Xmx128M",93"-Xmn16M",94"-XX:+PrintGC",95ReclaimRegionFast.class.getName());9697Pattern p = Pattern.compile("Full GC");9899OutputAnalyzer output = new OutputAnalyzer(pb.start());100101int found = 0;102Matcher m = p.matcher(output.getStdout());103while (m.find()) {104found++;105}106System.out.println("Issued " + found + " Full GCs");107108assertLessThan(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");109output.shouldHaveExitValue(0);110}111}112113114115