Path: blob/master/test/hotspot/jtreg/gc/g1/TestG1TraceEagerReclaimHumongousObjects.java
64478 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 TestG1TraceEagerReclaimHumongousObjects27* @bug 8058801 804817928* @summary Ensure that the output for a G1TraceEagerReclaimHumongousObjects29* includes the expected necessary messages.30* @requires vm.gc.G131* @library /test/lib32* @modules java.base/jdk.internal.misc33* java.management34* @run driver gc.g1.TestG1TraceEagerReclaimHumongousObjects35*/3637import jdk.test.lib.process.OutputAnalyzer;38import jdk.test.lib.process.ProcessTools;39import java.util.LinkedList;4041public class TestG1TraceEagerReclaimHumongousObjects {42public static void main(String[] args) throws Exception {43ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",44"-Xms128M",45"-Xmx128M",46"-Xmn16M",47"-XX:G1HeapRegionSize=1M",48"-Xlog:gc+phases=trace,gc+humongous=trace",49"-XX:+UnlockExperimentalVMOptions",50GCWithHumongousObjectTest.class.getName());5152OutputAnalyzer output = new OutputAnalyzer(pb.start());5354System.out.println(output.getStdout());55// As G1ReclaimDeadHumongousObjectsAtYoungGC is set(default), below logs should be displayed.56output.shouldContain("Humongous Reclaim");57output.shouldContain("Humongous Total");58output.shouldContain("Humongous Candidate");59output.shouldContain("Humongous Reclaimed");6061// As G1TraceReclaimDeadHumongousObjectsAtYoungGC is set and GCWithHumongousObjectTest has humongous objects,62// these logs should be displayed.63output.shouldContain("Humongous region");64output.shouldContain("Reclaimed humongous region");65output.shouldHaveExitValue(0);66}6768static class GCWithHumongousObjectTest {6970public static final int M = 1024*1024;71public static LinkedList<Object> garbageList = new LinkedList<Object>();72// A large object referenced by a static.73static int[] filler = new int[10 * M];7475public static void genGarbage() {76for (int i = 0; i < 32*1024; i++) {77garbageList.add(new int[100]);78}79garbageList.clear();80}8182public static void main(String[] args) {8384int[] large = new int[M];85Object ref = large;8687System.out.println("Creating garbage");88for (int i = 0; i < 100; i++) {89// A large object that will be reclaimed eagerly.90large = new int[6*M];91genGarbage();92// Make sure that the compiler cannot completely remove93// the allocation of the large object until here.94System.out.println(large);95}9697// Keep the reference to the first object alive.98System.out.println(ref);99System.out.println("Done");100}101}102}103104105