1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * Common helpers for TestRemsetLogging* tests 26 */ 27 28 import com.sun.management.HotSpotDiagnosticMXBean; 29 import com.sun.management.VMOption; 30 import sun.hotspot.WhiteBox; 31 32 import jdk.test.lib.*; 33 import java.lang.management.ManagementFactory; 34 import java.util.ArrayList; 35 import java.util.Arrays; 36 37 class VerifySummaryOutput { 38 public static void main(String[] args) { 39 int numGCs = Integer.parseInt(args[0]); 40 41 // Perform the requested amount of GCs. 42 WhiteBox wb = WhiteBox.getWhiteBox(); 43 for (int i = 0; i < numGCs - 1; i++) { 44 wb.youngGC(); 45 } 46 if (numGCs > 0) { 47 wb.fullGC(); 48 } 49 } 50 } 51 52 public class TestRemsetLoggingTools { 53 54 public static String runTest(String[] additionalArgs, int numGCs) throws Exception { 55 ArrayList<String> finalargs = new ArrayList<String>(); 56 String[] defaultArgs = new String[] { 57 "-Xbootclasspath/a:.", 58 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", 59 "-cp", System.getProperty("java.class.path"), 60 "-XX:+UseG1GC", 61 "-Xmn4m", 62 "-Xint", // -Xint makes the test run faster 63 "-Xms20m", 64 "-Xmx20m", 65 "-XX:ParallelGCThreads=1", 66 "-XX:InitiatingHeapOccupancyPercent=100", // we don't want the additional GCs due to initial marking 67 "-XX:+UnlockDiagnosticVMOptions", 68 "-XX:G1HeapRegionSize=1M", 69 }; 70 71 finalargs.addAll(Arrays.asList(defaultArgs)); 72 73 if (additionalArgs != null) { 74 finalargs.addAll(Arrays.asList(additionalArgs)); 75 } 76 77 finalargs.add(VerifySummaryOutput.class.getName()); 78 finalargs.add(String.valueOf(numGCs)); 79 80 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 81 finalargs.toArray(new String[0])); 82 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 83 84 output.shouldHaveExitValue(0); 85 86 String result = output.getStdout(); 87 return result; 88 } 89 90 private static void checkCounts(int expected, int actual, String which) throws Exception { 91 if (expected != actual) { 92 throw new Exception("RSet summaries mention " + which + " regions an incorrect number of times. Expected " + expected + ", got " + actual); 93 } 94 } 95 96 public static void expectPerRegionRSetSummaries(String result, int expectedCumulative, int expectedPeriodic) throws Exception { 97 expectRSetSummaries(result, expectedCumulative, expectedPeriodic); 98 int actualYoung = result.split("Young regions").length - 1; 99 int actualHumonguous = result.split("Humonguous regions").length - 1; 100 int actualFree = result.split("Free regions").length - 1; 101 int actualOther = result.split("Old regions").length - 1; 102 103 // the strings we check for above are printed four times per summary 104 int expectedPerRegionTypeInfo = (expectedCumulative + expectedPeriodic) * 4; 105 106 checkCounts(expectedPerRegionTypeInfo, actualYoung, "Young"); 107 checkCounts(expectedPerRegionTypeInfo, actualHumonguous, "Humonguous"); 108 checkCounts(expectedPerRegionTypeInfo, actualFree, "Free"); 109 checkCounts(expectedPerRegionTypeInfo, actualOther, "Old"); 110 } 111 112 public static void expectRSetSummaries(String result, int expectedCumulative, int expectedPeriodic) throws Exception { 113 int actualTotal = result.split("concurrent refinement").length - 1; 114 int actualCumulative = result.split("Cumulative RS summary").length - 1; 115 116 if (expectedCumulative != actualCumulative) { 117 throw new Exception("Incorrect amount of RSet summaries at the end. Expected " + expectedCumulative + ", got " + actualCumulative); 118 } 119 120 if (expectedPeriodic != (actualTotal - actualCumulative)) { 121 throw new Exception("Incorrect amount of per-period RSet summaries at the end. Expected " + expectedPeriodic + ", got " + (actualTotal - actualCumulative)); 122 } 123 } 124 }