Skip to content

Commit 5a6e681

Browse files
SendaoYanPaul Hohensee
authored andcommitted
8228658: test GetTotalSafepointTime.java fails on fast Linux machines with Total safepoint time 0 ms
Reviewed-by: phh Backport-of: c4e0c2656caaba67128f75d733b4452def9a7afc
1 parent f08dd7f commit 5a6e681

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

jdk/test/sun/management/HotspotRuntimeMBean/GetTotalSafepointTime.java

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2019, 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
@@ -39,47 +39,33 @@ public class GetTotalSafepointTime {
3939
private static HotspotRuntimeMBean mbean =
4040
(HotspotRuntimeMBean)ManagementFactoryHelper.getHotspotRuntimeMBean();
4141

42-
private static final long NUM_THREAD_DUMPS = 100;
43-
4442
// Careful with these values.
4543
private static final long MIN_VALUE_FOR_PASS = 1;
46-
private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE;
4744

48-
private static boolean trace = false;
45+
// Thread.getAllStackTraces() should cause safepoints.
46+
// If this test is failing because it doesn't,
47+
// MIN_VALUE_FOR_PASS should be reset to 0
48+
public static long executeThreadDumps(long initial_value) {
49+
long value;
50+
do {
51+
Thread.getAllStackTraces();
52+
value = mbean.getTotalSafepointTime();
53+
} while (value == initial_value);
54+
return value;
55+
}
4956

5057
public static void main(String args[]) throws Exception {
51-
if (args.length > 0 && args[0].equals("trace")) {
52-
trace = true;
53-
}
54-
55-
// Thread.getAllStackTraces() should cause safepoints.
56-
// If this test is failing because it doesn't,
57-
// MIN_VALUE_FOR_PASS should be reset to 0
58-
for (int i = 0; i < NUM_THREAD_DUMPS; i++) {
59-
Thread.getAllStackTraces();
60-
}
61-
62-
long value = mbean.getTotalSafepointTime();
58+
long value = executeThreadDumps(0);
59+
System.out.println("Total safepoint time (ms): " + value);
6360

64-
if (trace) {
65-
System.out.println("Total safepoint time (ms): " + value);
66-
}
67-
68-
if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) {
61+
if (value < MIN_VALUE_FOR_PASS) {
6962
throw new RuntimeException("Total safepoint time " +
7063
"illegal value: " + value + " ms " +
71-
"(MIN = " + MIN_VALUE_FOR_PASS + "; " +
72-
"MAX = " + MAX_VALUE_FOR_PASS + ")");
64+
"(MIN = " + MIN_VALUE_FOR_PASS + ")");
7365
}
7466

75-
for (int i = 0; i < 2 * NUM_THREAD_DUMPS; i++) {
76-
Thread.getAllStackTraces();
77-
}
78-
long value2 = mbean.getTotalSafepointTime();
79-
80-
if (trace) {
81-
System.out.println("Total safepoint time2 (ms): " + value2);
82-
}
67+
long value2 = executeThreadDumps(value);
68+
System.out.println("Total safepoint time (ms): " + value2);
8369

8470
if (value2 <= value) {
8571
throw new RuntimeException("Total safepoint time " +

0 commit comments

Comments
 (0)