Thu, 19 Sep 2013 09:36:51 -0700
Added tag jdk8-b108 for changeset 85072013aad4
tschatzl@5204 | 1 | /* |
tschatzl@5204 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
tschatzl@5204 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
tschatzl@5204 | 4 | * |
tschatzl@5204 | 5 | * This code is free software; you can redistribute it and/or modify it |
tschatzl@5204 | 6 | * under the terms of the GNU General Public License version 2 only, as |
tschatzl@5204 | 7 | * published by the Free Software Foundation. |
tschatzl@5204 | 8 | * |
tschatzl@5204 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
tschatzl@5204 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
tschatzl@5204 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
tschatzl@5204 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
tschatzl@5204 | 13 | * accompanied this code). |
tschatzl@5204 | 14 | * |
tschatzl@5204 | 15 | * You should have received a copy of the GNU General Public License version |
tschatzl@5204 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
tschatzl@5204 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
tschatzl@5204 | 18 | * |
tschatzl@5204 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
tschatzl@5204 | 20 | * or visit www.oracle.com if you need additional information or have any |
tschatzl@5204 | 21 | * questions. |
tschatzl@5204 | 22 | */ |
tschatzl@5204 | 23 | |
tschatzl@5204 | 24 | /* |
tschatzl@5204 | 25 | * @test TestSummarizeRSetStats.java |
tschatzl@5204 | 26 | * @bug 8013895 |
tschatzl@5204 | 27 | * @library /testlibrary |
tschatzl@5204 | 28 | * @build TestSummarizeRSetStats |
tschatzl@5204 | 29 | * @summary Verify output of -XX:+G1SummarizeRSetStats |
tschatzl@5204 | 30 | * @run main TestSummarizeRSetStats |
tschatzl@5204 | 31 | * |
tschatzl@5204 | 32 | * Test the output of G1SummarizeRSetStats in conjunction with G1SummarizeRSetStatsPeriod. |
tschatzl@5204 | 33 | */ |
tschatzl@5204 | 34 | |
tschatzl@5204 | 35 | import com.oracle.java.testlibrary.*; |
tschatzl@5204 | 36 | import java.lang.Thread; |
tschatzl@5204 | 37 | import java.util.ArrayList; |
tschatzl@5204 | 38 | import java.util.Arrays; |
tschatzl@5204 | 39 | |
tschatzl@5204 | 40 | class RunSystemGCs { |
tschatzl@5204 | 41 | // 4M size, both are directly allocated into the old gen |
tschatzl@5204 | 42 | static Object[] largeObject1 = new Object[1024 * 1024]; |
tschatzl@5204 | 43 | static Object[] largeObject2 = new Object[1024 * 1024]; |
tschatzl@5204 | 44 | |
tschatzl@5204 | 45 | static int[] temp; |
tschatzl@5204 | 46 | |
tschatzl@5204 | 47 | public static void main(String[] args) { |
tschatzl@5204 | 48 | // create some cross-references between these objects |
tschatzl@5204 | 49 | for (int i = 0; i < largeObject1.length; i++) { |
tschatzl@5204 | 50 | largeObject1[i] = largeObject2; |
tschatzl@5204 | 51 | } |
tschatzl@5204 | 52 | |
tschatzl@5204 | 53 | for (int i = 0; i < largeObject2.length; i++) { |
tschatzl@5204 | 54 | largeObject2[i] = largeObject1; |
tschatzl@5204 | 55 | } |
tschatzl@5204 | 56 | |
tschatzl@5204 | 57 | int numGCs = Integer.parseInt(args[0]); |
tschatzl@5204 | 58 | |
tschatzl@5204 | 59 | if (numGCs > 0) { |
tschatzl@5204 | 60 | // try to force a minor collection: the young gen is 4M, the |
tschatzl@5204 | 61 | // amount of data allocated below is roughly that (4*1024*1024 + |
tschatzl@5204 | 62 | // some header data) |
tschatzl@5204 | 63 | for (int i = 0; i < 1024 ; i++) { |
tschatzl@5204 | 64 | temp = new int[1024]; |
tschatzl@5204 | 65 | } |
tschatzl@5204 | 66 | } |
tschatzl@5204 | 67 | |
tschatzl@5204 | 68 | for (int i = 0; i < numGCs - 1; i++) { |
tschatzl@5204 | 69 | System.gc(); |
tschatzl@5204 | 70 | } |
tschatzl@5204 | 71 | } |
tschatzl@5204 | 72 | } |
tschatzl@5204 | 73 | |
tschatzl@5204 | 74 | public class TestSummarizeRSetStats { |
tschatzl@5204 | 75 | |
tschatzl@5204 | 76 | public static String runTest(String[] additionalArgs, int numGCs) throws Exception { |
tschatzl@5204 | 77 | ArrayList<String> finalargs = new ArrayList<String>(); |
tschatzl@5204 | 78 | String[] defaultArgs = new String[] { |
tschatzl@5204 | 79 | "-XX:+UseG1GC", |
tschatzl@5204 | 80 | "-Xmn4m", |
tschatzl@5204 | 81 | "-Xmx20m", |
tschatzl@5204 | 82 | "-XX:InitiatingHeapOccupancyPercent=100", // we don't want the additional GCs due to initial marking |
tschatzl@5204 | 83 | "-XX:+PrintGC", |
tschatzl@5204 | 84 | "-XX:+UnlockDiagnosticVMOptions", |
tschatzl@5204 | 85 | "-XX:G1HeapRegionSize=1M", |
tschatzl@5204 | 86 | }; |
tschatzl@5204 | 87 | |
tschatzl@5204 | 88 | finalargs.addAll(Arrays.asList(defaultArgs)); |
tschatzl@5204 | 89 | |
tschatzl@5204 | 90 | if (additionalArgs != null) { |
tschatzl@5204 | 91 | finalargs.addAll(Arrays.asList(additionalArgs)); |
tschatzl@5204 | 92 | } |
tschatzl@5204 | 93 | |
tschatzl@5204 | 94 | finalargs.add(RunSystemGCs.class.getName()); |
tschatzl@5204 | 95 | finalargs.add(String.valueOf(numGCs)); |
tschatzl@5204 | 96 | |
tschatzl@5204 | 97 | ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
tschatzl@5204 | 98 | finalargs.toArray(new String[0])); |
tschatzl@5204 | 99 | OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
tschatzl@5204 | 100 | |
tschatzl@5204 | 101 | output.shouldHaveExitValue(0); |
tschatzl@5204 | 102 | |
tschatzl@5204 | 103 | String result = output.getStdout(); |
tschatzl@5204 | 104 | return result; |
tschatzl@5204 | 105 | } |
tschatzl@5204 | 106 | |
tschatzl@5204 | 107 | private static void expectStatistics(String result, int expectedCumulative, int expectedPeriodic) throws Exception { |
tschatzl@5204 | 108 | int actualTotal = result.split("Concurrent RS processed").length - 1; |
tschatzl@5204 | 109 | int actualCumulative = result.split("Cumulative RS summary").length - 1; |
tschatzl@5204 | 110 | |
tschatzl@5204 | 111 | if (expectedCumulative != actualCumulative) { |
tschatzl@5204 | 112 | throw new Exception("Incorrect amount of RSet summaries at the end. Expected " + expectedCumulative + ", got " + actualCumulative); |
tschatzl@5204 | 113 | } |
tschatzl@5204 | 114 | |
tschatzl@5204 | 115 | if (expectedPeriodic != (actualTotal - actualCumulative)) { |
tschatzl@5204 | 116 | throw new Exception("Incorrect amount of per-period RSet summaries at the end. Expected " + expectedPeriodic + ", got " + (actualTotal - actualCumulative)); |
tschatzl@5204 | 117 | } |
tschatzl@5204 | 118 | } |
tschatzl@5204 | 119 | |
tschatzl@5204 | 120 | public static void main(String[] args) throws Exception { |
tschatzl@5204 | 121 | String result; |
tschatzl@5204 | 122 | |
tschatzl@5204 | 123 | // no RSet statistics output |
tschatzl@5204 | 124 | result = runTest(null, 0); |
tschatzl@5204 | 125 | expectStatistics(result, 0, 0); |
tschatzl@5204 | 126 | |
tschatzl@5204 | 127 | // no RSet statistics output |
tschatzl@5204 | 128 | result = runTest(null, 2); |
tschatzl@5204 | 129 | expectStatistics(result, 0, 0); |
tschatzl@5204 | 130 | |
tschatzl@5204 | 131 | // no RSet statistics output |
tschatzl@5204 | 132 | result = runTest(new String[] { "-XX:G1SummarizeRSetStatsPeriod=1" }, 3); |
tschatzl@5204 | 133 | expectStatistics(result, 0, 0); |
tschatzl@5204 | 134 | |
tschatzl@5204 | 135 | // single RSet statistics output at the end |
tschatzl@5204 | 136 | result = runTest(new String[] { "-XX:+G1SummarizeRSetStats" }, 0); |
tschatzl@5204 | 137 | expectStatistics(result, 1, 0); |
tschatzl@5204 | 138 | |
tschatzl@5204 | 139 | // single RSet statistics output at the end |
tschatzl@5204 | 140 | result = runTest(new String[] { "-XX:+G1SummarizeRSetStats" }, 2); |
tschatzl@5204 | 141 | expectStatistics(result, 1, 0); |
tschatzl@5204 | 142 | |
tschatzl@5204 | 143 | // single RSet statistics output |
tschatzl@5204 | 144 | result = runTest(new String[] { "-XX:+G1SummarizeRSetStats", "-XX:G1SummarizeRSetStatsPeriod=1" }, 0); |
tschatzl@5204 | 145 | expectStatistics(result, 1, 0); |
tschatzl@5204 | 146 | |
tschatzl@5204 | 147 | // two times RSet statistics output |
tschatzl@5204 | 148 | result = runTest(new String[] { "-XX:+G1SummarizeRSetStats", "-XX:G1SummarizeRSetStatsPeriod=1" }, 1); |
tschatzl@5204 | 149 | expectStatistics(result, 1, 1); |
tschatzl@5204 | 150 | |
tschatzl@5204 | 151 | // four times RSet statistics output |
tschatzl@5204 | 152 | result = runTest(new String[] { "-XX:+G1SummarizeRSetStats", "-XX:G1SummarizeRSetStatsPeriod=1" }, 3); |
tschatzl@5204 | 153 | expectStatistics(result, 1, 3); |
tschatzl@5204 | 154 | |
tschatzl@5204 | 155 | // three times RSet statistics output |
tschatzl@5204 | 156 | result = runTest(new String[] { "-XX:+G1SummarizeRSetStats", "-XX:G1SummarizeRSetStatsPeriod=2" }, 3); |
tschatzl@5204 | 157 | expectStatistics(result, 1, 2); |
tschatzl@5204 | 158 | |
tschatzl@5204 | 159 | // single RSet statistics output |
tschatzl@5204 | 160 | result = runTest(new String[] { "-XX:+G1SummarizeRSetStats", "-XX:G1SummarizeRSetStatsPeriod=100" }, 3); |
tschatzl@5204 | 161 | expectStatistics(result, 1, 1); |
tschatzl@5204 | 162 | } |
tschatzl@5204 | 163 | } |
tschatzl@5204 | 164 |