From d13df23cd93901f7ee9b5fbf5eafae57604a8bc9 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Tue, 8 Jul 2025 06:38:16 +0000 Subject: [PATCH] 8305567: serviceability/tmtools/jstat/GcTest01.java failed utils.JstatGcResults.assertConsistency Reviewed-by: cjplummer, lmesnik --- .../tmtools/jstat/GarbageProducerTest.java | 15 ++--- .../tmtools/jstat/GcNewTest.java | 11 ++-- .../tmtools/jstat/GcTest01.java | 15 ++--- .../tmtools/jstat/GcTest02.java | 4 +- .../jstat/utils/JstatGcCapacityTool.java | 5 +- .../tmtools/jstat/utils/JstatGcCauseTool.java | 5 +- .../tmtools/jstat/utils/JstatGcNewTool.java | 5 +- .../tmtools/jstat/utils/JstatGcTool.java | 5 +- .../tmtools/jstat/utils/JstatResults.java | 6 +- .../tmtools/jstat/utils/JstatTool.java | 59 +++++++++++++++++++ 10 files changed, 89 insertions(+), 41 deletions(-) create mode 100644 test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatTool.java diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/GarbageProducerTest.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/GarbageProducerTest.java index dfe1a8f12dc..933f2b86ff5 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/GarbageProducerTest.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/GarbageProducerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, 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 @@ -25,6 +25,7 @@ import utils.GarbageProducer; import common.TmTool; import utils.JstatResults; +import utils.JstatGcCauseTool; /** * Base class for jstat testing which uses GarbageProducer to allocate garbage. @@ -36,19 +37,19 @@ public class GarbageProducerTest { private final static float TARGET_MEMORY_USAGE = 0.7f; private final static float MEASUREMENT_TOLERANCE = 0.05f; private final GarbageProducer garbageProducer; - private final TmTool jstatTool; + private final JstatGcCauseTool jstatTool; - public GarbageProducerTest(TmTool tool) { + public GarbageProducerTest(JstatGcCauseTool tool) { garbageProducer = new GarbageProducer(TARGET_MEMORY_USAGE); // We will be running jstat tool jstatTool = tool; } public void run() throws Exception { - // Run once and get the results asserting that they are reasonable - JstatResults measurement1 = jstatTool.measure(); - measurement1.assertConsistency(); - // Eat metaspace and heap then run the tool again and get the results asserting that they are reasonable + // Run once and get the results asserting that they are reasonable + JstatResults measurement1 = jstatTool.measureAndAssertConsistency(); + + // Eat metaspace and heap then run the tool again and get the results, asserting that they are reasonable System.gc(); garbageProducer.allocateMetaspaceAndHeap(); // Collect garbage. Also update VM statistics diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/GcNewTest.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/GcNewTest.java index abe80074770..52bc41c3fe3 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/GcNewTest.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/GcNewTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -44,15 +44,13 @@ public static void main(String[] args) throws Exception { JstatGcNewTool jstatGcTool = new JstatGcNewTool(ProcessHandle.current().pid()); // Run once and get the results asserting that they are reasonable - JstatGcNewResults measurement1 = jstatGcTool.measure(); - measurement1.assertConsistency(); + JstatGcNewResults measurement1 = jstatGcTool.measureAndAssertConsistency(); GcProvoker gcProvoker = new GcProvoker(); // Provoke GC and run the tool again gcProvoker.provokeGc(); - JstatGcNewResults measurement2 = jstatGcTool.measure(); - measurement2.assertConsistency(); + JstatGcNewResults measurement2 = jstatGcTool.measureAndAssertConsistency(); // Assert the increase in GC events and time between the measurements assertThat(measurement2.getFloatValue("YGC") > measurement1.getFloatValue("YGC"), "YGC didn't increase between measurements 1 and 2"); @@ -60,8 +58,7 @@ public static void main(String[] args) throws Exception { // Provoke GC and run the tool again gcProvoker.provokeGc(); - JstatGcNewResults measurement3 = jstatGcTool.measure(); - measurement3.assertConsistency(); + JstatGcNewResults measurement3 = jstatGcTool.measureAndAssertConsistency(); // Assert the increase in GC events and time between the measurements assertThat(measurement3.getFloatValue("YGC") > measurement2.getFloatValue("YGC"), "YGC didn't increase between measurements 1 and 2"); diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest01.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest01.java index 74ac7132109..6d062d4fee5 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest01.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest01.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -47,17 +47,15 @@ public static void main(String[] args) throws Exception { // We will be running "jstat -gc" tool JstatGcTool jstatGcTool = new JstatGcTool(ProcessHandle.current().pid()); - // Run once and get the results asserting that they are reasonable - JstatGcResults measurement1 = jstatGcTool.measure(); - measurement1.assertConsistency(); + // Run once and get the results asserting that they are reasonable + JstatGcResults measurement1 = jstatGcTool.measureAndAssertConsistency(); GcProvoker gcProvoker = new GcProvoker(); // Provoke GC then run the tool again and get the results // asserting that they are reasonable gcProvoker.provokeGc(); - JstatGcResults measurement2 = jstatGcTool.measure(); - measurement2.assertConsistency(); + JstatGcResults measurement2 = jstatGcTool.measureAndAssertConsistency(); // Assert the increase in GC events and time between the measurements JstatResults.assertGCEventsIncreased(measurement1, measurement2); @@ -66,13 +64,10 @@ public static void main(String[] args) throws Exception { // Provoke GC again and get the results // asserting that they are reasonable gcProvoker.provokeGc(); - JstatGcResults measurement3 = jstatGcTool.measure(); - measurement3.assertConsistency(); + JstatGcResults measurement3 = jstatGcTool.measureAndAssertConsistency(); // Assert the increase in GC events and time between the measurements JstatResults.assertGCEventsIncreased(measurement2, measurement3); JstatResults.assertGCTimeIncreased(measurement2, measurement3); - } - } diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest02.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest02.java index 0a3102625d6..c223a09ba45 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest02.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest02.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -42,6 +42,6 @@ public class GcTest02 { public static void main(String[] args) throws Exception { - new GarbageProducerTest(new JstatGcTool(ProcessHandle.current().pid())).run(); + new GarbageProducerTest(new JstatGcCauseTool(ProcessHandle.current().pid())).run(); } } diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCapacityTool.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCapacityTool.java index 74cffa150ce..0fb24bbd109 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCapacityTool.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCapacityTool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -28,10 +28,9 @@ * This tool executes "jstat -gccapacity " and returns the results as * JstatGcCapacityoolResults */ -public class JstatGcCapacityTool extends TmTool { +public class JstatGcCapacityTool extends JstatTool { public JstatGcCapacityTool(long pid) { super(JstatGcCapacityResults.class, "jstat", "-gccapacity " + pid); } - } diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCauseTool.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCauseTool.java index c0dd36d8abb..65bea8d36bd 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCauseTool.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCauseTool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -28,10 +28,9 @@ * This tool executes "jstat -gc " and returns the results as * JstatGcToolResults */ -public class JstatGcCauseTool extends TmTool { +public class JstatGcCauseTool extends JstatTool { public JstatGcCauseTool(long pid) { super(JstatGcCauseResults.class, "jstat", "-gc " + pid); } - } diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcNewTool.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcNewTool.java index ed3f20a6c20..7bea437cb28 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcNewTool.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcNewTool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -28,10 +28,9 @@ * This tool executes "jstat -gcnew " and returns the results as * JstatGcNewResults */ -public class JstatGcNewTool extends TmTool { +public class JstatGcNewTool extends JstatTool { public JstatGcNewTool(long pid) { super(JstatGcNewResults.class, "jstat", "-gcnew " + pid); } - } diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcTool.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcTool.java index e046768a46f..f4f86038906 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcTool.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcTool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -28,10 +28,9 @@ * This tool executes "jstat -gc " and returns the results as * JstatGcToolResults */ -public class JstatGcTool extends TmTool { +public class JstatGcTool extends JstatTool { public JstatGcTool(long pid) { super(JstatGcResults.class, "jstat", "-gc " + pid); } - } diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatResults.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatResults.java index 97368d89b3a..01425d4c5b6 100644 --- a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatResults.java +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatResults.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -31,7 +31,7 @@ * Results of running the jstat tool Concrete subclasses will detail the jstat * tool options */ -abstract public class JstatResults extends ToolResults { +public abstract class JstatResults extends ToolResults { private static final float FLOAT_COMPARISON_TOLERANCE = 0.0011f; @@ -181,5 +181,5 @@ public static boolean checkFloatIsSum(float sum, float... floats) { return Math.abs(sum) <= FLOAT_COMPARISON_TOLERANCE; } - abstract public void assertConsistency(); + public abstract void assertConsistency(); } diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatTool.java b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatTool.java new file mode 100644 index 00000000000..404581b1ae7 --- /dev/null +++ b/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatTool.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025, 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. + */ +package utils; + +import common.TmTool; + +/** + * Common base class for Jstat tools. + */ +public class JstatTool extends TmTool { + + private static final int TRIES = 3; + + public JstatTool(Class resultsClz, String toolName, String otherArgs) { + super(resultsClz, toolName, otherArgs); + } + + /** + * Measure, and call assertConsistency() on the results, + * tolerating a set number of failures to account for inconsistencies in PerfData. + */ + public T measureAndAssertConsistency() throws Exception { + T results = null; + for (int i = 1; i <= TRIES; i++) { + try { + results = measure(); + results.assertConsistency(); + } catch (RuntimeException e) { + System.out.println("Attempt " + i + ": " + e); + if (i == TRIES) { + System.out.println("Too many failures."); + throw(e); + } + // Will retry. + } + } + return results; + } +}