Path: blob/master/test/hotspot/jtreg/gc/g1/TestG1TraceEagerReclaimHumongousObjects.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 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());5354// As G1ReclaimDeadHumongousObjectsAtYoungGC is set(default), below logs should be displayed.55output.shouldContain("Humongous Reclaim");56output.shouldContain("Humongous Total");57output.shouldContain("Humongous Candidate");58output.shouldContain("Humongous Reclaimed");5960// As G1TraceReclaimDeadHumongousObjectsAtYoungGC is set and GCWithHumongousObjectTest has humongous objects,61// these logs should be displayed.62output.shouldContain("Live humongous");63output.shouldContain("Dead humongous region");64output.shouldHaveExitValue(0);65}6667static class GCWithHumongousObjectTest {6869public static final int M = 1024*1024;70public static LinkedList<Object> garbageList = new LinkedList<Object>();71// A large object referenced by a static.72static int[] filler = new int[10 * M];7374public static void genGarbage() {75for (int i = 0; i < 32*1024; i++) {76garbageList.add(new int[100]);77}78garbageList.clear();79}8081public static void main(String[] args) {8283int[] large = new int[M];84Object ref = large;8586System.out.println("Creating garbage");87for (int i = 0; i < 100; i++) {88// A large object that will be reclaimed eagerly.89large = new int[6*M];90genGarbage();91// Make sure that the compiler cannot completely remove92// the allocation of the large object until here.93System.out.println(large);94}9596// Keep the reference to the first object alive.97System.out.println(ref);98System.out.println("Done");99}100}101}102103104