Path: blob/master/test/hotspot/jtreg/gc/g1/TestEagerReclaimHumongousRegionsLog.java
40942 views
/*1* Copyright (c) 2017, 2021, 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 TestEagerReclaimHumongousRegionsLog27* @summary Check that G1 reports humongous eager reclaim statistics correctly.28* @requires vm.gc.G129* @library /test/lib30* @modules java.base/jdk.internal.misc31* java.management32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run driver gc.g1.TestEagerReclaimHumongousRegionsLog35*/3637import sun.hotspot.WhiteBox;3839import java.util.Arrays;40import jdk.test.lib.Asserts;4142import jdk.test.lib.process.OutputAnalyzer;43import jdk.test.lib.process.ProcessTools;4445public class TestEagerReclaimHumongousRegionsLog {4647private static final String LogSeparator = ": ";4849static final String SumSeparator = "Sum: ";5051private static String getSumValue(String s) {52return s.substring(s.indexOf(SumSeparator) + SumSeparator.length(), s.indexOf(", Workers"));53}5455public static void runTest() throws Exception {56ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(57"-Xbootclasspath/a:.",58"-XX:+UnlockExperimentalVMOptions",59"-XX:+UnlockDiagnosticVMOptions",60"-XX:+WhiteBoxAPI",61"-XX:+UseG1GC",62"-XX:G1HeapRegionSize=1M",63"-Xms128M",64"-Xmx128M",65"-Xlog:gc+phases=trace,gc+heap=info",66GCTest.class.getName());67OutputAnalyzer output = new OutputAnalyzer(pb.start());6869output.shouldHaveExitValue(0);7071System.out.println(output.getStdout());7273// This gives an array of lines containing eager reclaim of humongous regions74// log messages contents after the ":" in the following order for every GC:75// Region Register: a.ams76// Eagerly Reclaim Humonguous Objects b.cms77// Humongous Total: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: c, Workers: 178// Humongous Candidate: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: d, Workers: 179// Humongous Reclaimed: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: e, Workers: 180// Humongous Regions: f->g8182String[] lines = Arrays.stream(output.getStdout().split("\\R"))83.filter(s -> (s.contains("Humongous") || s.contains("Region Register"))).map(s -> s.substring(s.indexOf(LogSeparator) + LogSeparator.length()))84.toArray(String[]::new);8586Asserts.assertTrue(lines.length % 6 == 0, "There seems to be an unexpected amount of log messages (total: " + lines.length + ") per GC");8788for (int i = 0; i < lines.length; i += 6) {89int total = Integer.parseInt(getSumValue(lines[i + 2]));90int candidate = Integer.parseInt(getSumValue(lines[i + 3]));91int reclaimed = Integer.parseInt(getSumValue(lines[i + 4]));9293int before = Integer.parseInt(lines[i + 5].substring(0, 1));94int after = Integer.parseInt(lines[i + 5].substring(3, 4));95System.out.println("total " + total + " candidate " + candidate + " reclaimed " + reclaimed + " before " + before + " after " + after);9697Asserts.assertEQ(total, candidate, "Not all humonguous objects are candidates");98Asserts.assertLTE(reclaimed, candidate, "The number of reclaimed objects must be less or equal than the number of candidates");99100if (reclaimed > 0) {101Asserts.assertLT(after, before, "Number of regions after must be smaller than before.");102Asserts.assertEQ(reclaimed, candidate, "Must have reclaimed all candidates.");103Asserts.assertGT((before - after), reclaimed, "Number of regions reclaimed (" + (before - after) +104") must be larger than number of objects reclaimed (" + reclaimed + ")");105}106}107}108109public static void main(String[] args) throws Exception {110runTest();111}112113static class GCTest {114private static final WhiteBox WB = WhiteBox.getWhiteBox();115116public static Object holder;117118public static void main(String [] args) {119// Create a humongous objects spanning multiple regions so that the difference120// between number of humongous objects reclaimed and number of regions reclaimed121// is apparent.122holder = new byte[4 * 1024 * 1024];123WB.youngGC();124System.out.println(holder);125holder = null;126WB.youngGC();127}128}129}130131132133