Skip to content

Commit 50358d1

Browse files
committed
8354929: ZGC: Update collection stats while holding page allocator lock
Reviewed-by: stefank, tschatzl, aboldtch
1 parent 367bcc5 commit 50358d1

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

src/hotspot/share/gc/z/zGeneration.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ void ZGeneration::reset_statistics() {
279279
_freed = 0;
280280
_promoted = 0;
281281
_compacted = 0;
282-
_page_allocator->reset_statistics(_id);
283282
}
284283

285284
size_t ZGeneration::freed() const {
@@ -860,7 +859,7 @@ void ZGenerationYoung::mark_start() {
860859
_remembered.flip();
861860

862861
// Update statistics
863-
stat_heap()->at_mark_start(_page_allocator->stats(this));
862+
stat_heap()->at_mark_start(_page_allocator->update_and_stats(this));
864863
}
865864

866865
void ZGenerationYoung::mark_roots() {
@@ -1209,7 +1208,7 @@ void ZGenerationOld::mark_start() {
12091208
_mark.start();
12101209

12111210
// Update statistics
1212-
stat_heap()->at_mark_start(_page_allocator->stats(this));
1211+
stat_heap()->at_mark_start(_page_allocator->update_and_stats(this));
12131212

12141213
// Note that we start a marking cycle.
12151214
// Unlike other GCs, the color switch implicitly changes the nmethods

src/hotspot/share/gc/z/zPageAllocator.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,9 +1373,25 @@ size_t ZPageAllocator::unused() const {
13731373
return unused > 0 ? (size_t)unused : 0;
13741374
}
13751375

1376-
ZPageAllocatorStats ZPageAllocator::stats(ZGeneration* generation) const {
1377-
ZLocker<ZLock> locker(&_lock);
1376+
void ZPageAllocator::update_collection_stats(ZGenerationId id) {
1377+
assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
13781378

1379+
#ifdef ASSERT
1380+
size_t total_used = 0;
1381+
1382+
ZPartitionIterator iter(&_partitions);
1383+
for (ZPartition* partition; iter.next(&partition);) {
1384+
total_used += partition->_used;
1385+
}
1386+
1387+
assert(total_used == _used, "Must be consistent %zu == %zu", total_used, _used);
1388+
#endif
1389+
1390+
_collection_stats[(int)id]._used_high = _used;
1391+
_collection_stats[(int)id]._used_low = _used;
1392+
}
1393+
1394+
ZPageAllocatorStats ZPageAllocator::stats_inner(ZGeneration* generation) const {
13791395
return ZPageAllocatorStats(_min_capacity,
13801396
_max_capacity,
13811397
soft_max_capacity(),
@@ -1390,29 +1406,16 @@ ZPageAllocatorStats ZPageAllocator::stats(ZGeneration* generation) const {
13901406
_stalled.size());
13911407
}
13921408

1393-
void ZPageAllocator::reset_statistics(ZGenerationId id) {
1394-
assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
1395-
#ifdef ASSERT
1396-
{
1397-
// We may free without safepoint synchronization, take the lock to get
1398-
// consistent values.
1399-
ZLocker<ZLock> locker(&_lock);
1400-
size_t total_used = 0;
1401-
1402-
ZPartitionIterator iter(&_partitions);
1403-
for (ZPartition* partition; iter.next(&partition);) {
1404-
total_used += partition->_used;
1405-
}
1406-
1407-
assert(total_used == _used, "Must be consistent at safepoint %zu == %zu", total_used, _used);
1408-
}
1409-
#endif
1409+
ZPageAllocatorStats ZPageAllocator::stats(ZGeneration* generation) const {
1410+
ZLocker<ZLock> locker(&_lock);
1411+
return stats_inner(generation);
1412+
}
14101413

1411-
// Read once, we may have concurrent writers.
1412-
const size_t used = Atomic::load(&_used);
1414+
ZPageAllocatorStats ZPageAllocator::update_and_stats(ZGeneration* generation) {
1415+
ZLocker<ZLock> locker(&_lock);
14131416

1414-
_collection_stats[(int)id]._used_high = used;
1415-
_collection_stats[(int)id]._used_low = used;
1417+
update_collection_stats(generation->id());
1418+
return stats_inner(generation);
14161419
}
14171420

14181421
void ZPageAllocator::increase_used_generation(ZGenerationId id, size_t size) {

src/hotspot/share/gc/z/zPageAllocator.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ class ZPageAllocator {
235235
void notify_out_of_memory();
236236
void restart_gc() const;
237237

238+
void update_collection_stats(ZGenerationId id);
239+
ZPageAllocatorStats stats_inner(ZGeneration* generation) const;
240+
238241
void print_on_inner(outputStream* st) const;
239242

240243
public:
@@ -262,8 +265,7 @@ class ZPageAllocator {
262265
void promote_used(const ZPage* from, const ZPage* to);
263266

264267
ZPageAllocatorStats stats(ZGeneration* generation) const;
265-
266-
void reset_statistics(ZGenerationId id);
268+
ZPageAllocatorStats update_and_stats(ZGeneration* generation);
267269

268270
ZPage* alloc_page(ZPageType type, size_t size, ZAllocationFlags flags, ZPageAge age);
269271
void safe_destroy_page(ZPage* page);

0 commit comments

Comments
 (0)