changeset 56431:152cd40a1d36

8228658: test GetTotalSafepointTime.java fails on fast Linux machines with Total safepoint time 0 ms Reviewed-by: dholmes, jcbeyler
author mbaesken
date Thu, 01 Aug 2019 08:59:31 +0200
parents 446dcfc2a925
children 26f71e24dd24
files test/jdk/sun/management/HotspotRuntimeMBean/GetTotalSafepointTime.java
diffstat 1 files changed, 21 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/sun/management/HotspotRuntimeMBean/GetTotalSafepointTime.java	Fri Aug 02 10:43:30 2019 +0200
+++ b/test/jdk/sun/management/HotspotRuntimeMBean/GetTotalSafepointTime.java	Thu Aug 01 08:59:31 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, 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
@@ -40,47 +40,33 @@
     private static HotspotRuntimeMBean mbean =
         (HotspotRuntimeMBean)ManagementFactoryHelper.getHotspotRuntimeMBean();
 
-    private static final long NUM_THREAD_DUMPS = 100;
-
     // Careful with these values.
     private static final long MIN_VALUE_FOR_PASS = 1;
-    private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE;
 
-    private static boolean trace = false;
+    // Thread.getAllStackTraces() should cause safepoints.
+    // If this test is failing because it doesn't,
+    // MIN_VALUE_FOR_PASS should be reset to 0
+    public static long executeThreadDumps(long initial_value) {
+        long value;
+        do {
+            Thread.getAllStackTraces();
+            value = mbean.getTotalSafepointTime();
+        } while (value == initial_value);
+        return value;
+    }
 
     public static void main(String args[]) throws Exception {
-        if (args.length > 0 && args[0].equals("trace")) {
-            trace = true;
+        long value = executeThreadDumps(0);
+        System.out.println("Total safepoint time (ms): " + value);
+
+        if (value < MIN_VALUE_FOR_PASS) {
+            throw new RuntimeException("Total safepoint time " +
+                                       "illegal value: " + value + " ms " +
+                                       "(MIN = " + MIN_VALUE_FOR_PASS + ")");
         }
 
-        // Thread.getAllStackTraces() should cause safepoints.
-        // If this test is failing because it doesn't,
-        // MIN_VALUE_FOR_PASS should be reset to 0
-        for (int i = 0; i < NUM_THREAD_DUMPS; i++) {
-             Thread.getAllStackTraces();
-        }
-
-        long value = mbean.getTotalSafepointTime();
-
-        if (trace) {
-            System.out.println("Total safepoint time (ms): " + value);
-        }
-
-        if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) {
-            throw new RuntimeException("Total safepoint time " +
-                                       "illegal value: " + value + " ms " +
-                                       "(MIN = " + MIN_VALUE_FOR_PASS + "; " +
-                                       "MAX = " + MAX_VALUE_FOR_PASS + ")");
-        }
-
-        for (int i = 0; i < 2 * NUM_THREAD_DUMPS; i++) {
-             Thread.getAllStackTraces();
-        }
-        long value2 = mbean.getTotalSafepointTime();
-
-        if (trace) {
-            System.out.println("Total safepoint time2 (ms): " + value2);
-        }
+        long value2 = executeThreadDumps(value);
+        System.out.println("Total safepoint time (ms): " + value2);
 
         if (value2 <= value) {
             throw new RuntimeException("Total safepoint time " +