|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -39,47 +39,33 @@ public class GetTotalSafepointTime { |
39 | 39 | private static HotspotRuntimeMBean mbean = |
40 | 40 | (HotspotRuntimeMBean)ManagementFactoryHelper.getHotspotRuntimeMBean(); |
41 | 41 |
|
42 | | - private static final long NUM_THREAD_DUMPS = 100; |
43 | | - |
44 | 42 | // Careful with these values. |
45 | 43 | private static final long MIN_VALUE_FOR_PASS = 1; |
46 | | - private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE; |
47 | 44 |
|
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 | + } |
49 | 56 |
|
50 | 57 | 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); |
63 | 60 |
|
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) { |
69 | 62 | throw new RuntimeException("Total safepoint time " + |
70 | 63 | "illegal value: " + value + " ms " + |
71 | | - "(MIN = " + MIN_VALUE_FOR_PASS + "; " + |
72 | | - "MAX = " + MAX_VALUE_FOR_PASS + ")"); |
| 64 | + "(MIN = " + MIN_VALUE_FOR_PASS + ")"); |
73 | 65 | } |
74 | 66 |
|
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); |
83 | 69 |
|
84 | 70 | if (value2 <= value) { |
85 | 71 | throw new RuntimeException("Total safepoint time " + |
|
0 commit comments