Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/g1/TestSummarizeRSetStatsTools.java
32284 views
/*1* Copyright (c) 2013, 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* Common helpers for TestSummarizeRSetStats* tests25*/2627import sun.management.ManagementFactoryHelper;28import com.sun.management.HotSpotDiagnosticMXBean;29import com.sun.management.VMOption;3031import com.oracle.java.testlibrary.*;32import java.util.regex.Matcher;33import java.util.regex.Pattern;34import java.lang.Thread;35import java.util.ArrayList;36import java.util.Arrays;3738class VerifySummaryOutput {39// 4M size, both are directly allocated into the old gen40static Object[] largeObject1 = new Object[1024 * 1024];41static Object[] largeObject2 = new Object[1024 * 1024];4243static int[] temp;4445public static void main(String[] args) {46// create some cross-references between these objects47for (int i = 0; i < largeObject1.length; i++) {48largeObject1[i] = largeObject2;49}5051for (int i = 0; i < largeObject2.length; i++) {52largeObject2[i] = largeObject1;53}5455int numGCs = Integer.parseInt(args[0]);5657if (numGCs > 0) {58// try to force a minor collection: the young gen is 4M, the59// amount of data allocated below is roughly that (4*1024*1024 +60// some header data)61for (int i = 0; i < 1024 ; i++) {62temp = new int[1024];63}64}6566for (int i = 0; i < numGCs - 1; i++) {67System.gc();68}69}70}7172public class TestSummarizeRSetStatsTools {7374// the VM is currently run using G1GC, i.e. trying to test G1 functionality.75public static boolean testingG1GC() {76HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();7778VMOption option = diagnostic.getVMOption("UseG1GC");79if (option.getValue().equals("false")) {80System.out.println("Skipping this test. It is only a G1 test.");81return false;82}83return true;84}8586public static String runTest(String[] additionalArgs, int numGCs) throws Exception {87ArrayList<String> finalargs = new ArrayList<String>();88String[] defaultArgs = new String[] {89"-XX:+UseG1GC",90"-Xmn4m",91"-Xmx20m",92"-XX:InitiatingHeapOccupancyPercent=100", // we don't want the additional GCs due to initial marking93"-XX:+PrintGC",94"-XX:+UnlockDiagnosticVMOptions",95"-XX:G1HeapRegionSize=1M",96};9798finalargs.addAll(Arrays.asList(defaultArgs));99100if (additionalArgs != null) {101finalargs.addAll(Arrays.asList(additionalArgs));102}103104finalargs.add(VerifySummaryOutput.class.getName());105finalargs.add(String.valueOf(numGCs));106107ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(108finalargs.toArray(new String[0]));109OutputAnalyzer output = new OutputAnalyzer(pb.start());110111output.shouldHaveExitValue(0);112113String result = output.getStdout();114return result;115}116117private static void checkCounts(int expected, int actual, String which) throws Exception {118if (expected != actual) {119throw new Exception("RSet summaries mention " + which + " regions an incorrect number of times. Expected " + expected + ", got " + actual);120}121}122123public static void expectPerRegionRSetSummaries(String result, int expectedCumulative, int expectedPeriodic) throws Exception {124expectRSetSummaries(result, expectedCumulative, expectedPeriodic);125int actualYoung = result.split("Young regions").length - 1;126int actualHumonguous = result.split("Humonguous regions").length - 1;127int actualFree = result.split("Free regions").length - 1;128int actualOther = result.split("Old regions").length - 1;129130// the strings we check for above are printed four times per summary131int expectedPerRegionTypeInfo = (expectedCumulative + expectedPeriodic) * 4;132133checkCounts(expectedPerRegionTypeInfo, actualYoung, "Young");134checkCounts(expectedPerRegionTypeInfo, actualHumonguous, "Humonguous");135checkCounts(expectedPerRegionTypeInfo, actualFree, "Free");136checkCounts(expectedPerRegionTypeInfo, actualOther, "Old");137}138139public static void expectRSetSummaries(String result, int expectedCumulative, int expectedPeriodic) throws Exception {140int actualTotal = result.split("concurrent refinement").length - 1;141int actualCumulative = result.split("Cumulative RS summary").length - 1;142143if (expectedCumulative != actualCumulative) {144throw new Exception("Incorrect amount of RSet summaries at the end. Expected " + expectedCumulative + ", got " + actualCumulative);145}146147if (expectedPeriodic != (actualTotal - actualCumulative)) {148throw new Exception("Incorrect amount of per-period RSet summaries at the end. Expected " + expectedPeriodic + ", got " + (actualTotal - actualCumulative));149}150}151}152153154155