Skip to content

Commit 310ef85

Browse files
committed
8305567: serviceability/tmtools/jstat/GcTest01.java failed utils.JstatGcResults.assertConsistency
Reviewed-by: cjplummer, lmesnik
1 parent 5205eae commit 310ef85

File tree

10 files changed

+89
-41
lines changed

10 files changed

+89
-41
lines changed

test/hotspot/jtreg/serviceability/tmtools/jstat/GarbageProducerTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
import utils.GarbageProducer;
2626
import common.TmTool;
2727
import utils.JstatResults;
28+
import utils.JstatGcCauseTool;
2829

2930
/**
3031
* Base class for jstat testing which uses GarbageProducer to allocate garbage.
@@ -36,19 +37,19 @@ public class GarbageProducerTest {
3637
private final static float TARGET_MEMORY_USAGE = 0.7f;
3738
private final static float MEASUREMENT_TOLERANCE = 0.05f;
3839
private final GarbageProducer garbageProducer;
39-
private final TmTool<? extends JstatResults> jstatTool;
40+
private final JstatGcCauseTool jstatTool;
4041

41-
public GarbageProducerTest(TmTool<? extends JstatResults> tool) {
42+
public GarbageProducerTest(JstatGcCauseTool tool) {
4243
garbageProducer = new GarbageProducer(TARGET_MEMORY_USAGE);
4344
// We will be running jstat tool
4445
jstatTool = tool;
4546
}
4647

4748
public void run() throws Exception {
48-
// Run once and get the results asserting that they are reasonable
49-
JstatResults measurement1 = jstatTool.measure();
50-
measurement1.assertConsistency();
51-
// Eat metaspace and heap then run the tool again and get the results asserting that they are reasonable
49+
// Run once and get the results asserting that they are reasonable
50+
JstatResults measurement1 = jstatTool.measureAndAssertConsistency();
51+
52+
// Eat metaspace and heap then run the tool again and get the results, asserting that they are reasonable
5253
System.gc();
5354
garbageProducer.allocateMetaspaceAndHeap();
5455
// Collect garbage. Also update VM statistics

test/hotspot/jtreg/serviceability/tmtools/jstat/GcNewTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,24 +44,21 @@ public static void main(String[] args) throws Exception {
4444
JstatGcNewTool jstatGcTool = new JstatGcNewTool(ProcessHandle.current().pid());
4545

4646
// Run once and get the results asserting that they are reasonable
47-
JstatGcNewResults measurement1 = jstatGcTool.measure();
48-
measurement1.assertConsistency();
47+
JstatGcNewResults measurement1 = jstatGcTool.measureAndAssertConsistency();
4948

5049
GcProvoker gcProvoker = new GcProvoker();
5150

5251
// Provoke GC and run the tool again
5352
gcProvoker.provokeGc();
54-
JstatGcNewResults measurement2 = jstatGcTool.measure();
55-
measurement2.assertConsistency();
53+
JstatGcNewResults measurement2 = jstatGcTool.measureAndAssertConsistency();
5654

5755
// Assert the increase in GC events and time between the measurements
5856
assertThat(measurement2.getFloatValue("YGC") > measurement1.getFloatValue("YGC"), "YGC didn't increase between measurements 1 and 2");
5957
assertThat(measurement2.getFloatValue("YGCT") > measurement1.getFloatValue("YGCT"), "YGCT time didn't increase between measurements 1 and 2");
6058

6159
// Provoke GC and run the tool again
6260
gcProvoker.provokeGc();
63-
JstatGcNewResults measurement3 = jstatGcTool.measure();
64-
measurement3.assertConsistency();
61+
JstatGcNewResults measurement3 = jstatGcTool.measureAndAssertConsistency();
6562

6663
// Assert the increase in GC events and time between the measurements
6764
assertThat(measurement3.getFloatValue("YGC") > measurement2.getFloatValue("YGC"), "YGC didn't increase between measurements 1 and 2");

test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest01.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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 {
4747
// We will be running "jstat -gc" tool
4848
JstatGcTool jstatGcTool = new JstatGcTool(ProcessHandle.current().pid());
4949

50-
// Run once and get the results asserting that they are reasonable
51-
JstatGcResults measurement1 = jstatGcTool.measure();
52-
measurement1.assertConsistency();
50+
// Run once and get the results asserting that they are reasonable
51+
JstatGcResults measurement1 = jstatGcTool.measureAndAssertConsistency();
5352

5453
GcProvoker gcProvoker = new GcProvoker();
5554

5655
// Provoke GC then run the tool again and get the results
5756
// asserting that they are reasonable
5857
gcProvoker.provokeGc();
59-
JstatGcResults measurement2 = jstatGcTool.measure();
60-
measurement2.assertConsistency();
58+
JstatGcResults measurement2 = jstatGcTool.measureAndAssertConsistency();
6159

6260
// Assert the increase in GC events and time between the measurements
6361
JstatResults.assertGCEventsIncreased(measurement1, measurement2);
@@ -66,13 +64,10 @@ public static void main(String[] args) throws Exception {
6664
// Provoke GC again and get the results
6765
// asserting that they are reasonable
6866
gcProvoker.provokeGc();
69-
JstatGcResults measurement3 = jstatGcTool.measure();
70-
measurement3.assertConsistency();
67+
JstatGcResults measurement3 = jstatGcTool.measureAndAssertConsistency();
7168

7269
// Assert the increase in GC events and time between the measurements
7370
JstatResults.assertGCEventsIncreased(measurement2, measurement3);
7471
JstatResults.assertGCTimeIncreased(measurement2, measurement3);
75-
7672
}
77-
7873
}

test/hotspot/jtreg/serviceability/tmtools/jstat/GcTest02.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,6 +42,6 @@
4242
public class GcTest02 {
4343

4444
public static void main(String[] args) throws Exception {
45-
new GarbageProducerTest(new JstatGcTool(ProcessHandle.current().pid())).run();
45+
new GarbageProducerTest(new JstatGcCauseTool(ProcessHandle.current().pid())).run();
4646
}
4747
}

test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCapacityTool.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,10 +28,9 @@
2828
* This tool executes "jstat -gccapacity <pid>" and returns the results as
2929
* JstatGcCapacityoolResults
3030
*/
31-
public class JstatGcCapacityTool extends TmTool<JstatGcCapacityResults> {
31+
public class JstatGcCapacityTool extends JstatTool<JstatGcCapacityResults> {
3232

3333
public JstatGcCapacityTool(long pid) {
3434
super(JstatGcCapacityResults.class, "jstat", "-gccapacity " + pid);
3535
}
36-
3736
}

test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCauseTool.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,10 +28,9 @@
2828
* This tool executes "jstat -gc <pid>" and returns the results as
2929
* JstatGcToolResults
3030
*/
31-
public class JstatGcCauseTool extends TmTool<JstatGcCauseResults> {
31+
public class JstatGcCauseTool extends JstatTool<JstatGcCauseResults> {
3232

3333
public JstatGcCauseTool(long pid) {
3434
super(JstatGcCauseResults.class, "jstat", "-gc " + pid);
3535
}
36-
3736
}

test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcNewTool.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,10 +28,9 @@
2828
* This tool executes "jstat -gcnew <pid>" and returns the results as
2929
* JstatGcNewResults
3030
*/
31-
public class JstatGcNewTool extends TmTool<JstatGcNewResults> {
31+
public class JstatGcNewTool extends JstatTool<JstatGcNewResults> {
3232

3333
public JstatGcNewTool(long pid) {
3434
super(JstatGcNewResults.class, "jstat", "-gcnew " + pid);
3535
}
36-
3736
}

test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcTool.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,10 +28,9 @@
2828
* This tool executes "jstat -gc <pid>" and returns the results as
2929
* JstatGcToolResults
3030
*/
31-
public class JstatGcTool extends TmTool<JstatGcResults> {
31+
public class JstatGcTool extends JstatTool<JstatGcResults> {
3232

3333
public JstatGcTool(long pid) {
3434
super(JstatGcResults.class, "jstat", "-gc " + pid);
3535
}
36-
3736
}

test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatResults.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,7 @@
3131
* Results of running the jstat tool Concrete subclasses will detail the jstat
3232
* tool options
3333
*/
34-
abstract public class JstatResults extends ToolResults {
34+
public abstract class JstatResults extends ToolResults {
3535

3636
private static final float FLOAT_COMPARISON_TOLERANCE = 0.0011f;
3737

@@ -181,5 +181,5 @@ public static boolean checkFloatIsSum(float sum, float... floats) {
181181
return Math.abs(sum) <= FLOAT_COMPARISON_TOLERANCE;
182182
}
183183

184-
abstract public void assertConsistency();
184+
public abstract void assertConsistency();
185185
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025, 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+
package utils;
24+
25+
import common.TmTool;
26+
27+
/**
28+
* Common base class for Jstat tools.
29+
*/
30+
public class JstatTool<T extends JstatResults> extends TmTool<T> {
31+
32+
private static final int TRIES = 3;
33+
34+
public JstatTool(Class<T> resultsClz, String toolName, String otherArgs) {
35+
super(resultsClz, toolName, otherArgs);
36+
}
37+
38+
/**
39+
* Measure, and call assertConsistency() on the results,
40+
* tolerating a set number of failures to account for inconsistencies in PerfData.
41+
*/
42+
public T measureAndAssertConsistency() throws Exception {
43+
T results = null;
44+
for (int i = 1; i <= TRIES; i++) {
45+
try {
46+
results = measure();
47+
results.assertConsistency();
48+
} catch (RuntimeException e) {
49+
System.out.println("Attempt " + i + ": " + e);
50+
if (i == TRIES) {
51+
System.out.println("Too many failures.");
52+
throw(e);
53+
}
54+
// Will retry.
55+
}
56+
}
57+
return results;
58+
}
59+
}

0 commit comments

Comments
 (0)