@@ -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
14181421void ZPageAllocator::increase_used_generation (ZGenerationId id, size_t size) {
0 commit comments