# HG changeset patch # User jmasa # Date 1453938886 28800 # Wed Jan 27 15:54:46 2016 -0800 # Node ID 65b33b2257838cb47be60234ec01134911584958 # Parent 63a57b9b3ea4e05a6df8eefc003c1dba92f6f084 [mq]: 8076140 diff --git a/test/gc/g1/TestDynamicGCThreadsStats.java b/test/gc/g1/TestDynamicGCThreadsStats.java new file mode 100644 --- /dev/null +++ b/test/gc/g1/TestDynamicGCThreadsStats.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test TestDynamicGCThreadsStats + * @bug 8140585 + * @summary Check that G1 does reports per thread statistics. + * @requires vm.gc=="G1" | vm.gc=="null" + * @key gc + * @library /testlibrary /test/lib + * @build sun.hotspot.WhiteBox + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run driver TestDynamicGCThreadsStats + */ + +import sun.hotspot.WhiteBox; + +import java.text.DecimalFormatSymbols; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import jdk.test.lib.OutputAnalyzer; +import jdk.test.lib.Platform; +import jdk.test.lib.ProcessTools; + +import static jdk.test.lib.Asserts.*; + +public class TestDynamicGCThreadsStats { + + public static void runTest() throws Exception { + final String[] arguments = { + "-Xbootclasspath/a:.", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UseDynamicNumberOfGCThreads", + "-XX:+WhiteBoxAPI", + "-XX:+UseG1GC", + "-Xlog:gc*=trace", + "-Xmx10M", + GCTest.class.getName() + }; + + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + + output.shouldHaveExitValue(0); + + // Looking for: + // [0.234s][debug ][gc,phases ] GC(0) Evacuate Collection Set: 3.7 ms + String parallel_phase_leader = "Evacuate Collection Set: \\d+\\.\\d+ms"; + String std_out = output.getStdout(); + Matcher m = Pattern.compile(parallel_phase_leader, Pattern.MULTILINE).matcher(std_out); + + if (!m.find()) { + throw new Exception("Could not find correct output for Evacuate Collection Set: in stdout," + + " should match the pattern \"" + parallel_phase_leader + "\", but stdout is \n" + output.getStdout()); + } else { + // Find data with per thread times. + // Any of the metrics with per thread times can be used. + // Chose: + // [0.234s][debug ][gc,phases ] GC(0) Ext Root Scanning: Min: 0.6, Avg: 1.1, Max: 1.6, Diff: 1.0, Sum: 2.2 + String stats = "Ext Root Scanning \\(ms\\):"; +// String stats = "GC Worker End:"; + Pattern stats_pattern = Pattern.compile(stats); + m.usePattern(stats_pattern); + if (!m.find()) { + throw new Exception("Could not find correct output for chosen statistics in stdout," + + " should match the pattern \"" + stats + "\", but stdout is \n" + output.getStdout()); + } else { + // Find the printed average from the log. + Pattern avg_pattern = Pattern.compile("(Avg: +)(\\d+\\.\\d+)(,)"); + m.usePattern(avg_pattern); + if (!m.find()) { + throw new Exception("Could not find Avg: dd.d in stdout\n," + output.getStdout()); + } else { + String value_string = m.group(2); + // Count the decimal places in the printed average. The + // number of decimal places will be used to calculate the + // rounding error when the per thread values are summed in + // this test. + DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); + char decimal_symbol = symbols.getDecimalSeparator(); + String decimal_places_string = value_string.substring(value_string.indexOf(decimal_symbol) + 1); + int decimal_points = decimal_places_string.length(); +System.out.println("Decimal places in Avg: " + decimal_points); + double avg_value = 0.0; + try { + avg_value = Double.parseDouble(value_string); +System.err.println("Avg: " + avg_value + " from String " + value_string); + } catch (java.lang.NumberFormatException e) { + System.out.println("Non Number Format - " + value_string); + } + // Go to the next line which will have a "GC" in it. For + // example: + // [0.234s][trace ][gc,phases ] GC(0) 1.58 0.58 + Pattern GC_pattern = Pattern.compile("GC"); + m.usePattern(GC_pattern); + if (m.find()) { + String[] per_thread_values = std_out.substring(m.end()).split(System.lineSeparator(), 2); +System.err.println("String of values: " + per_thread_values[0]); + String value_regex = " +\\d+\\.\\d+"; + Matcher value_m = Pattern.compile(value_regex, Pattern.MULTILINE).matcher(per_thread_values[0]); + int workers = 0; + Double sum = 0.0; + // Count and sum the values. Note that each parsed value has rounding error in it. + while (value_m.find()) { + try { + Double value = Double.parseDouble(value_m.group()); + sum += value; + workers++; +System.err.println("Double value " + value + " from String " + value_m.group()); + } catch (java.lang.NumberFormatException e) { + System.out.println("Non Number Format - " + m.group()); + } + } + if (workers > 0) { + Double calculated_avg = sum / workers; +System.err.println("Calculated average " + calculated_avg); + // Rounding error in per thread data + Double rounding_error = workers * 0.5 * Math.pow(10.0, -decimal_points); + if (Math.abs(calculated_avg - avg_value) > rounding_error) { + throw new Exception("Average from log " + avg_value + " and average calculated by test " + + calculated_avg + " can differ by rounding error " + rounding_error); + } else { + + System.err.println("PASSED: Average from log " + avg_value + " and average calculated by test " + + calculated_avg + " can differ by rounding error " + rounding_error); + } + } + } + System.out.println(output.getStdout()); + } + } + } + } + + public static void main(String[] args) throws Exception { + runTest(); + } + + static class GCTest { + public static void main(String [] args) { + int numGCs = 4; + + // Perform the requested amount of GCs. + WhiteBox wb = WhiteBox.getWhiteBox(); + for (int i = 0; i < numGCs - 1; i++) { + wb.youngGC(); + } + if (numGCs > 0) { + wb.fullGC(); + } + System.out.println("Done"); + } + } +} + # HG changeset patch # User jmasa # Date 1458600667 25200 # Mon Mar 21 15:51:07 2016 -0700 # Node ID 0d6fe324619ff0fe220ccf8951310cd7afccc25f # Parent 65b33b2257838cb47be60234ec01134911584958 8152208: Summary for phase times are incorrect with and without UseDynamicNumberOfGCThreads Reviewed-by: tamao, brutisso diff --git a/src/share/vm/gc/g1/workerDataArray.inline.hpp b/src/share/vm/gc/g1/workerDataArray.inline.hpp --- a/src/share/vm/gc/g1/workerDataArray.inline.hpp +++ b/src/share/vm/gc/g1/workerDataArray.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -85,7 +85,7 @@ template T WorkerDataArray::sum(uint active_threads) const { T s = get(0); - for (uint i = 1; i < active_threads; ++i) { + for (uint i = 0; i < active_threads; ++i) { s += get(i); } return s; @@ -108,7 +108,7 @@ T max = get(0); T min = max; T sum = 0; - for (uint i = 1; i < active_threads; ++i) { + for (uint i = 0; i < active_threads; ++i) { T value = get(i); max = MAX2(max, value); min = MIN2(min, value); diff --git a/test/gc/g1/TestDynamicGCThreadsStats.java b/test/gc/g1/TestDynamicGCThreadsStats.java --- a/test/gc/g1/TestDynamicGCThreadsStats.java +++ b/test/gc/g1/TestDynamicGCThreadsStats.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,8 +23,8 @@ /* * @test TestDynamicGCThreadsStats - * @bug 8140585 - * @summary Check that G1 does reports per thread statistics. + * @bug 8176140 + * @summary Check that G1 reports per thread statistics. * @requires vm.gc=="G1" | vm.gc=="null" * @key gc * @library /testlibrary /test/lib @@ -80,7 +80,6 @@ // Chose: // [0.234s][debug ][gc,phases ] GC(0) Ext Root Scanning: Min: 0.6, Avg: 1.1, Max: 1.6, Diff: 1.0, Sum: 2.2 String stats = "Ext Root Scanning \\(ms\\):"; -// String stats = "GC Worker End:"; Pattern stats_pattern = Pattern.compile(stats); m.usePattern(stats_pattern); if (!m.find()) { @@ -102,11 +101,9 @@ char decimal_symbol = symbols.getDecimalSeparator(); String decimal_places_string = value_string.substring(value_string.indexOf(decimal_symbol) + 1); int decimal_points = decimal_places_string.length(); -System.out.println("Decimal places in Avg: " + decimal_points); double avg_value = 0.0; try { avg_value = Double.parseDouble(value_string); -System.err.println("Avg: " + avg_value + " from String " + value_string); } catch (java.lang.NumberFormatException e) { System.out.println("Non Number Format - " + value_string); } @@ -117,7 +114,6 @@ m.usePattern(GC_pattern); if (m.find()) { String[] per_thread_values = std_out.substring(m.end()).split(System.lineSeparator(), 2); -System.err.println("String of values: " + per_thread_values[0]); String value_regex = " +\\d+\\.\\d+"; Matcher value_m = Pattern.compile(value_regex, Pattern.MULTILINE).matcher(per_thread_values[0]); int workers = 0; @@ -128,14 +124,12 @@ Double value = Double.parseDouble(value_m.group()); sum += value; workers++; -System.err.println("Double value " + value + " from String " + value_m.group()); } catch (java.lang.NumberFormatException e) { System.out.println("Non Number Format - " + m.group()); } } if (workers > 0) { Double calculated_avg = sum / workers; -System.err.println("Calculated average " + calculated_avg); // Rounding error in per thread data Double rounding_error = workers * 0.5 * Math.pow(10.0, -decimal_points); if (Math.abs(calculated_avg - avg_value) > rounding_error) {