Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit ccb1a3e

Browse files
committed
8324933: ConcurrentHashTable::statistics_calculate synchronization is expensive
Backport-of: 0e2fdc95ae47c11e6a1e47cdc6190268e29a9d9c
1 parent ac9ca97 commit ccb1a3e

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/hotspot/share/utilities/concurrentHashTable.inline.hpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,23 +1223,30 @@ template <typename VALUE_SIZE_FUNC>
12231223
inline TableStatistics ConcurrentHashTable<CONFIG, F>::
12241224
statistics_calculate(Thread* thread, VALUE_SIZE_FUNC& vs_f)
12251225
{
1226+
constexpr size_t batch_size = 128;
12261227
NumberSeq summary;
12271228
size_t literal_bytes = 0;
12281229
InternalTable* table = get_table();
1229-
for (size_t bucket_it = 0; bucket_it < table->_size; bucket_it++) {
1230+
size_t num_batches = table->_size / batch_size;
1231+
for (size_t batch_start = 0; batch_start < _table->_size; batch_start += batch_size) {
1232+
// We batch the use of ScopedCS here as it has been found to be quite expensive to
1233+
// invoke it for every single bucket.
1234+
size_t batch_end = MIN2(batch_start + batch_size, _table->_size);
12301235
ScopedCS cs(thread, this);
1231-
size_t count = 0;
1232-
Bucket* bucket = table->get_bucket(bucket_it);
1233-
if (bucket->have_redirect() || bucket->is_locked()) {
1234-
continue;
1235-
}
1236-
Node* current_node = bucket->first();
1237-
while (current_node != nullptr) {
1238-
++count;
1239-
literal_bytes += vs_f(current_node->value());
1240-
current_node = current_node->next();
1236+
for (size_t bucket_it = batch_start; bucket_it < batch_end; bucket_it++) {
1237+
size_t count = 0;
1238+
Bucket* bucket = table->get_bucket(bucket_it);
1239+
if (bucket->have_redirect() || bucket->is_locked()) {
1240+
continue;
1241+
}
1242+
Node* current_node = bucket->first();
1243+
while (current_node != nullptr) {
1244+
++count;
1245+
literal_bytes += vs_f(current_node->value());
1246+
current_node = current_node->next();
1247+
}
1248+
summary.add((double)count);
12411249
}
1242-
summary.add((double)count);
12431250
}
12441251

12451252
if (_stats_rate == nullptr) {

0 commit comments

Comments
 (0)