Mercurial > hg > graal-compiler
comparison test/gc/g1/TestSummarizeRSetStatsTools.java @ 12339:c319b188c7b2
8014078: G1: improve remembered set summary information by providing per region type information
Summary: Add memory consumption breakdown on a per region type in the G1 remembered set summary statistics. This simplifies remembered set memory consumption analysis.
Reviewed-by: brutisso
author | tschatzl |
---|---|
date | Thu, 26 Sep 2013 12:49:45 +0200 |
parents | |
children | 0abcece2ee27 |
comparison
equal
deleted
inserted
replaced
12306:03f493ce3a71 | 12339:c319b188c7b2 |
---|---|
1 /* | |
2 * Copyright (c) 2013, 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 TestSummarizeRSetStats* tests | |
26 */ | |
27 | |
28 import sun.management.ManagementFactoryHelper; | |
29 import com.sun.management.HotSpotDiagnosticMXBean; | |
30 import com.sun.management.VMOption; | |
31 | |
32 import com.oracle.java.testlibrary.*; | |
33 import java.util.regex.Matcher; | |
34 import java.util.regex.Pattern; | |
35 import java.lang.Thread; | |
36 import java.util.ArrayList; | |
37 import java.util.Arrays; | |
38 | |
39 class VerifySummaryOutput { | |
40 // 4M size, both are directly allocated into the old gen | |
41 static Object[] largeObject1 = new Object[1024 * 1024]; | |
42 static Object[] largeObject2 = new Object[1024 * 1024]; | |
43 | |
44 static int[] temp; | |
45 | |
46 public static void main(String[] args) { | |
47 // create some cross-references between these objects | |
48 for (int i = 0; i < largeObject1.length; i++) { | |
49 largeObject1[i] = largeObject2; | |
50 } | |
51 | |
52 for (int i = 0; i < largeObject2.length; i++) { | |
53 largeObject2[i] = largeObject1; | |
54 } | |
55 | |
56 int numGCs = Integer.parseInt(args[0]); | |
57 | |
58 if (numGCs > 0) { | |
59 // try to force a minor collection: the young gen is 4M, the | |
60 // amount of data allocated below is roughly that (4*1024*1024 + | |
61 // some header data) | |
62 for (int i = 0; i < 1024 ; i++) { | |
63 temp = new int[1024]; | |
64 } | |
65 } | |
66 | |
67 for (int i = 0; i < numGCs - 1; i++) { | |
68 System.gc(); | |
69 } | |
70 } | |
71 } | |
72 | |
73 public class TestSummarizeRSetStatsTools { | |
74 | |
75 // the VM is currently run using G1GC, i.e. trying to test G1 functionality. | |
76 public static boolean testingG1GC() { | |
77 HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); | |
78 | |
79 VMOption option = diagnostic.getVMOption("UseG1GC"); | |
80 if (option.getValue().equals("false")) { | |
81 System.out.println("Skipping this test. It is only a G1 test."); | |
82 return false; | |
83 } | |
84 return true; | |
85 } | |
86 | |
87 public static String runTest(String[] additionalArgs, int numGCs) throws Exception { | |
88 ArrayList<String> finalargs = new ArrayList<String>(); | |
89 String[] defaultArgs = new String[] { | |
90 "-XX:+UseG1GC", | |
91 "-XX:+UseCompressedOops", | |
92 "-Xmn4m", | |
93 "-Xmx20m", | |
94 "-XX:InitiatingHeapOccupancyPercent=100", // we don't want the additional GCs due to initial marking | |
95 "-XX:+PrintGC", | |
96 "-XX:+UnlockDiagnosticVMOptions", | |
97 "-XX:G1HeapRegionSize=1M", | |
98 }; | |
99 | |
100 finalargs.addAll(Arrays.asList(defaultArgs)); | |
101 | |
102 if (additionalArgs != null) { | |
103 finalargs.addAll(Arrays.asList(additionalArgs)); | |
104 } | |
105 | |
106 finalargs.add(VerifySummaryOutput.class.getName()); | |
107 finalargs.add(String.valueOf(numGCs)); | |
108 | |
109 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( | |
110 finalargs.toArray(new String[0])); | |
111 OutputAnalyzer output = new OutputAnalyzer(pb.start()); | |
112 | |
113 output.shouldHaveExitValue(0); | |
114 | |
115 String result = output.getStdout(); | |
116 return result; | |
117 } | |
118 | |
119 private static void checkCounts(int expected, int actual, String which) throws Exception { | |
120 if (expected != actual) { | |
121 throw new Exception("RSet summaries mention " + which + " regions an incorrect number of times. Expected " + expected + ", got " + actual); | |
122 } | |
123 } | |
124 | |
125 public static void expectPerRegionRSetSummaries(String result, int expectedCumulative, int expectedPeriodic) throws Exception { | |
126 expectRSetSummaries(result, expectedCumulative, expectedPeriodic); | |
127 int actualYoung = result.split("Young regions").length - 1; | |
128 int actualHumonguous = result.split("Humonguous regions").length - 1; | |
129 int actualFree = result.split("Free regions").length - 1; | |
130 int actualOther = result.split("Old regions").length - 1; | |
131 | |
132 // the strings we check for above are printed four times per summary | |
133 int expectedPerRegionTypeInfo = (expectedCumulative + expectedPeriodic) * 4; | |
134 | |
135 checkCounts(expectedPerRegionTypeInfo, actualYoung, "Young"); | |
136 checkCounts(expectedPerRegionTypeInfo, actualHumonguous, "Humonguous"); | |
137 checkCounts(expectedPerRegionTypeInfo, actualFree, "Free"); | |
138 checkCounts(expectedPerRegionTypeInfo, actualOther, "Old"); | |
139 } | |
140 | |
141 public static void expectRSetSummaries(String result, int expectedCumulative, int expectedPeriodic) throws Exception { | |
142 int actualTotal = result.split("concurrent refinement").length - 1; | |
143 int actualCumulative = result.split("Cumulative RS summary").length - 1; | |
144 | |
145 if (expectedCumulative != actualCumulative) { | |
146 throw new Exception("Incorrect amount of RSet summaries at the end. Expected " + expectedCumulative + ", got " + actualCumulative); | |
147 } | |
148 | |
149 if (expectedPeriodic != (actualTotal - actualCumulative)) { | |
150 throw new Exception("Incorrect amount of per-period RSet summaries at the end. Expected " + expectedPeriodic + ", got " + (actualTotal - actualCumulative)); | |
151 } | |
152 } | |
153 } | |
154 |