# HG changeset patch # User zgu # Date 1579117923 18000 # Wed Jan 15 14:52:03 2020 -0500 # Node ID 9db827b6d99ac5e1b9cc2286882b86795d691f2d # Parent 6d8a39322e5115893681fbe317af95837ba0087a 8236878: Use atomic instruction to update StringDedupTable's entries and entries_removed counters diff --git a/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp b/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp --- a/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp +++ b/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp @@ -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; @@ -479,9 +479,9 @@ // Delayed update to avoid contention on the table 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); } } diff --git a/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.hpp b/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.hpp --- a/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.hpp +++ b/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.hpp @@ -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;