changeset 51690:b83571bbc147

8210511: TestSingleWriterSynchronizer can deadlock Summary: Check for safepoints in test loops. Reviewed-by: coleenp, eosterlund
author kbarrett
date Mon, 10 Sep 2018 19:18:04 -0400
parents 9d89c0835ac1
children f036f767708e
files test/hotspot/gtest/utilities/test_singleWriterSynchronizer.cpp
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/gtest/utilities/test_singleWriterSynchronizer.cpp	Mon Sep 10 18:57:44 2018 -0400
+++ b/test/hotspot/gtest/utilities/test_singleWriterSynchronizer.cpp	Mon Sep 10 19:18:04 2018 -0400
@@ -54,13 +54,16 @@
   {}
 
   virtual void main_run() {
-    uintx iterations = 0;
+    size_t iterations = 0;
+    size_t values_changed = 0;
     while (OrderAccess::load_acquire(_continue_running) != 0) {
+      { ThreadBlockInVM tbiv(this); } // Safepoint check outside critical section.
       ++iterations;
       SingleWriterSynchronizer::CriticalSection cs(_synchronizer);
       uintx value = OrderAccess::load_acquire(_synchronized_value);
+      uintx new_value = value;
       for (uint i = 0; i < reader_iterations; ++i) {
-        uintx new_value = OrderAccess::load_acquire(_synchronized_value);
+        new_value = OrderAccess::load_acquire(_synchronized_value);
         // A reader can see either the value it first read after
         // entering the critical section, or that value + 1.  No other
         // values are possible.
@@ -68,8 +71,12 @@
           ASSERT_EQ((value + 1), new_value);
         }
       }
+      if (value != new_value) {
+        ++values_changed;
+      }
     }
-    tty->print_cr("reader iterations: " UINTX_FORMAT, iterations);
+    tty->print_cr("reader iterations: " SIZE_FORMAT ", changes: " SIZE_FORMAT,
+                  iterations, values_changed);
   }
 };
 
@@ -93,13 +100,14 @@
     while (OrderAccess::load_acquire(_continue_running) != 0) {
       ++*_synchronized_value;
       _synchronizer->synchronize();
+      { ThreadBlockInVM tbiv(this); } // Safepoint check.
     }
     tty->print_cr("writer iterations: " UINTX_FORMAT, *_synchronized_value);
   }
 };
 
 const uint nreaders = 5;
-const uint milliseconds_to_run = 3000;
+const uint milliseconds_to_run = 1000;
 
 TEST_VM(TestSingleWriterSynchronizer, stress) {
   Semaphore post;