Path: blob/master/test/hotspot/jtreg/gc/g1/TestRemsetLoggingTools.java
40942 views
/*1* Copyright (c) 2013, 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* Common helpers for TestRemsetLogging* tests27*/2829import sun.hotspot.WhiteBox;3031import jdk.test.lib.process.ProcessTools;32import jdk.test.lib.process.OutputAnalyzer;33import java.util.ArrayList;34import java.util.Arrays;3536class VerifySummaryOutput {37public static void main(String[] args) {38int numGCs = Integer.parseInt(args[0]);3940// Perform the requested amount of GCs.41WhiteBox wb = WhiteBox.getWhiteBox();42for (int i = 0; i < numGCs - 1; i++) {43wb.youngGC();44}45if (numGCs > 0) {46wb.fullGC();47}48}49}5051public class TestRemsetLoggingTools {5253public static String runTest(String[] additionalArgs, int numGCs) throws Exception {54ArrayList<String> finalargs = new ArrayList<String>();55String[] defaultArgs = new String[] {56"-Xbootclasspath/a:.",57"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",58"-cp", System.getProperty("java.class.path"),59"-XX:+UseG1GC",60"-Xmn4m",61"-Xint", // -Xint makes the test run faster62"-Xms20m",63"-Xmx20m",64"-XX:ParallelGCThreads=1",65"-XX:InitiatingHeapOccupancyPercent=100", // we don't want the additional GCs due to marking66"-XX:+UnlockDiagnosticVMOptions",67"-XX:G1HeapRegionSize=1M",68};6970finalargs.addAll(Arrays.asList(defaultArgs));7172if (additionalArgs != null) {73finalargs.addAll(Arrays.asList(additionalArgs));74}7576finalargs.add(VerifySummaryOutput.class.getName());77finalargs.add(String.valueOf(numGCs));7879ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs);80OutputAnalyzer output = new OutputAnalyzer(pb.start());8182output.shouldHaveExitValue(0);8384String result = output.getStdout();85return result;86}8788private static void checkCounts(int expected, int actual, String which) throws Exception {89if (expected != actual) {90throw new Exception("RSet summaries mention " + which + " regions an incorrect number of times. Expected " + expected + ", got " + actual);91}92}9394public static void expectPerRegionRSetSummaries(String result, int expectedCumulative, int expectedPeriodic) throws Exception {95expectRSetSummaries(result, expectedCumulative, expectedPeriodic);96int actualYoung = result.split("Young regions").length - 1;97int actualHumongous = result.split("Humongous regions").length - 1;98int actualFree = result.split("Free regions").length - 1;99int actualOther = result.split("Old regions").length - 1;100101// the strings we check for above are printed four times per summary102int expectedPerRegionTypeInfo = (expectedCumulative + expectedPeriodic) * 4;103104checkCounts(expectedPerRegionTypeInfo, actualYoung, "Young");105checkCounts(expectedPerRegionTypeInfo, actualHumongous, "Humongous");106checkCounts(expectedPerRegionTypeInfo, actualFree, "Free");107checkCounts(expectedPerRegionTypeInfo, actualOther, "Old");108}109110public static void expectRSetSummaries(String result, int expectedCumulative, int expectedPeriodic) throws Exception {111int actualTotal = result.split("Concurrent refinement threads times").length - 1;112int actualCumulative = result.split("Cumulative RS summary").length - 1;113114if (expectedCumulative != actualCumulative) {115throw new Exception("Incorrect amount of RSet summaries at the end. Expected " + expectedCumulative + ", got " + actualCumulative);116}117118if (expectedPeriodic != (actualTotal - actualCumulative)) {119throw new Exception("Incorrect amount of per-period RSet summaries at the end. Expected " + expectedPeriodic + ", got " + (actualTotal - actualCumulative));120}121}122}123124125