Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/g1/TestG1TraceEagerReclaimHumongousObjects.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 TestG1TraceEagerReclaimHumongousObjects25* @bug 8058801 804817926* @summary Ensure that the output for a G1TraceEagerReclaimHumongousObjects27* includes the expected necessary messages.28* @key gc29* @library /testlibrary30*/3132import com.oracle.java.testlibrary.ProcessTools;33import com.oracle.java.testlibrary.OutputAnalyzer;34import java.util.LinkedList;3536public class TestG1TraceEagerReclaimHumongousObjects {37public static void main(String[] args) throws Exception {38testGCLogs();39testHumongousObjectGCLogs();40}4142private static void testGCLogs() throws Exception {4344ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",45"-Xms128M",46"-Xmx128M",47"-Xmn16M",48"-XX:G1HeapRegionSize=1M",49"-XX:+PrintGC",50"-XX:+UnlockExperimentalVMOptions",51"-XX:G1LogLevel=finest",52"-XX:+G1TraceEagerReclaimHumongousObjects",53GCTest.class.getName());5455OutputAnalyzer output = new OutputAnalyzer(pb.start());5657// As G1EagerReclaimHumongousObjects is set(default), below logs should be displayed.58// And GCTest doesn't have humongous objects, so values should be zero.59output.shouldContain("[Humongous Reclaim");60output.shouldContain("[Humongous Total: 0]");61output.shouldContain("[Humongous Candidate: 0]");62output.shouldContain("[Humongous Reclaimed: 0]");6364output.shouldHaveExitValue(0);65}6667private static void testHumongousObjectGCLogs() throws Exception {68ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",69"-Xms128M",70"-Xmx128M",71"-Xmn16M",72"-XX:G1HeapRegionSize=1M",73"-XX:+PrintGC",74"-XX:+UnlockExperimentalVMOptions",75"-XX:G1LogLevel=finest",76"-XX:+G1TraceEagerReclaimHumongousObjects",77GCWithHumongousObjectTest.class.getName());7879OutputAnalyzer output = new OutputAnalyzer(pb.start());8081// As G1ReclaimDeadHumongousObjectsAtYoungGC is set(default), below logs should be displayed.82output.shouldContain("[Humongous Reclaim");83output.shouldContain("[Humongous Total");84output.shouldContain("[Humongous Candidate");85output.shouldContain("[Humongous Reclaimed");8687// As G1TraceReclaimDeadHumongousObjectsAtYoungGC is set and GCWithHumongousObjectTest has humongous objects,88// these logs should be displayed.89output.shouldContain("Live humongous");90output.shouldContain("Dead humongous region");91output.shouldHaveExitValue(0);92}9394static class GCTest {95private static byte[] garbage;9697public static void main(String [] args) {98System.out.println("Creating garbage");99// create 128MB of garbage. This should result in at least one GC100for (int i = 0; i < 1024; i++) {101garbage = new byte[128 * 1024];102}103System.out.println("Done");104}105}106107static class GCWithHumongousObjectTest {108109public static final int M = 1024*1024;110public static LinkedList<Object> garbageList = new LinkedList<Object>();111// A large object referenced by a static.112static int[] filler = new int[10 * M];113114public static void genGarbage() {115for (int i = 0; i < 32*1024; i++) {116garbageList.add(new int[100]);117}118garbageList.clear();119}120121public static void main(String[] args) {122123int[] large = new int[M];124Object ref = large;125126System.out.println("Creating garbage");127for (int i = 0; i < 100; i++) {128// A large object that will be reclaimed eagerly.129large = new int[6*M];130genGarbage();131// Make sure that the compiler cannot completely remove132// the allocation of the large object until here.133System.out.println(large);134}135136// Keep the reference to the first object alive.137System.out.println(ref);138System.out.println("Done");139}140}141}142143144