Skip to content

Commit d1e909f

Browse files
committed
8324933: ConcurrentHashTable::statistics_calculate synchronization is expensive
Reviewed-by: phh Backport-of: 0e2fdc95ae47c11e6a1e47cdc6190268e29a9d9c
1 parent d608778 commit d1e909f

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
@@ -1197,23 +1197,30 @@ template <typename VALUE_SIZE_FUNC>
11971197
inline TableStatistics ConcurrentHashTable<CONFIG, F>::
11981198
statistics_calculate(Thread* thread, VALUE_SIZE_FUNC& vs_f)
11991199
{
1200+
constexpr size_t batch_size = 128;
12001201
NumberSeq summary;
12011202
size_t literal_bytes = 0;
12021203
InternalTable* table = get_table();
1203-
for (size_t bucket_it = 0; bucket_it < table->_size; bucket_it++) {
1204+
size_t num_batches = table->_size / batch_size;
1205+
for (size_t batch_start = 0; batch_start < _table->_size; batch_start += batch_size) {
1206+
// We batch the use of ScopedCS here as it has been found to be quite expensive to
1207+
// invoke it for every single bucket.
1208+
size_t batch_end = MIN2(batch_start + batch_size, _table->_size);
12041209
ScopedCS cs(thread, this);
1205-
size_t count = 0;
1206-
Bucket* bucket = table->get_bucket(bucket_it);
1207-
if (bucket->have_redirect() || bucket->is_locked()) {
1208-
continue;
1209-
}
1210-
Node* current_node = bucket->first();
1211-
while (current_node != NULL) {
1212-
++count;
1213-
literal_bytes += vs_f(current_node->value());
1214-
current_node = current_node->next();
1210+
for (size_t bucket_it = batch_start; bucket_it < batch_end; bucket_it++) {
1211+
size_t count = 0;
1212+
Bucket* bucket = table->get_bucket(bucket_it);
1213+
if (bucket->have_redirect() || bucket->is_locked()) {
1214+
continue;
1215+
}
1216+
Node* current_node = bucket->first();
1217+
while (current_node != nullptr) {
1218+
++count;
1219+
literal_bytes += vs_f(current_node->value());
1220+
current_node = current_node->next();
1221+
}
1222+
summary.add((double)count);
12151223
}
1216-
summary.add((double)count);
12171224
}
12181225

12191226
return TableStatistics(_stats_rate, summary, literal_bytes, sizeof(Bucket), sizeof(Node));

0 commit comments

Comments
 (0)