changeset 57721:adcb848a9ecc

8236878: Use atomic instruction to update StringDedupTable's entries and entries_removed counters Reviewed-by: rkennke, shade
author zgu
date Thu, 16 Jan 2020 18:36:24 -0500
parents 9aba9109a25e
children 5c660d2d97ff
files src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp src/hotspot/share/gc/shared/stringdedup/stringDedupTable.hpp
diffstat 2 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp	Thu Jan 16 08:28:21 2020 -0500
+++ b/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp	Thu Jan 16 18:36:24 2020 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2020, 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
@@ -215,7 +215,7 @@
 const uintx              StringDedupTable::_rehash_threshold = (uintx)(_rehash_multiple * _grow_load_factor);
 
 uintx                    StringDedupTable::_entries_added = 0;
-uintx                    StringDedupTable::_entries_removed = 0;
+volatile uintx           StringDedupTable::_entries_removed = 0;
 uintx                    StringDedupTable::_resize_count = 0;
 uintx                    StringDedupTable::_rehash_count = 0;
 
@@ -477,11 +477,13 @@
     removed += unlink_or_oops_do(cl, table_half + partition_begin, table_half + partition_end, worker_id);
   }
 
-  // Delayed update to avoid contention on the table lock
+  // Do atomic update here instead of taking StringDedupTable_lock. This allows concurrent
+  // cleanup when multiple workers are cleaning up the table, while the mutators are blocked
+  // on StringDedupTable_lock.
   if (removed > 0) {
-    MutexLocker ml(StringDedupTable_lock, Mutex::_no_safepoint_check_flag);
-    _table->_entries -= removed;
-    _entries_removed += removed;
+    assert_locked_or_safepoint_weak(StringDedupTable_lock);
+    Atomic::sub(&_table->_entries, removed);
+    Atomic::add(&_entries_removed, removed);
   }
 }
 
--- a/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.hpp	Thu Jan 16 08:28:21 2020 -0500
+++ b/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.hpp	Thu Jan 16 18:36:24 2020 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2020, 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
@@ -122,7 +122,7 @@
 
   StringDedupEntry**              _buckets;
   size_t                          _size;
-  uintx                           _entries;
+  volatile uintx                  _entries;
   uintx                           _shrink_threshold;
   uintx                           _grow_threshold;
   bool                            _rehash_needed;
@@ -144,7 +144,7 @@
 
   // Table statistics, only used for logging.
   static uintx                    _entries_added;
-  static uintx                    _entries_removed;
+  static volatile uintx           _entries_removed;
   static uintx                    _resize_count;
   static uintx                    _rehash_count;