8334147: Shenandoah: Avoid taking lock for disabled free set logging

8341554: Shenandoah: Missing heap lock when updating usage for soft ref policy

Reviewed-by: kdnilsen, ysr
Backport-of: c47a0e005e54551e42ee1ae33d7169417a5f86d4
This commit is contained in:
William Kemper 2024-10-09 08:15:31 +00:00 committed by Aleksey Shipilev
parent 1c812b5d8a
commit e2f4c7a110
4 changed files with 23 additions and 15 deletions

View File

@ -153,10 +153,7 @@ bool ShenandoahConcurrentGC::collect(GCCause::Cause cause) {
// the space. This would be the last action if there is nothing to evacuate.
entry_cleanup_early();
{
ShenandoahHeapLocker locker(heap->lock());
heap->free_set()->log_status();
}
heap->free_set()->log_status_under_lock();
// Perform concurrent class unloading
if (heap->unload_classes() &&

View File

@ -147,10 +147,7 @@ void ShenandoahControlThread::run_service() {
heap->set_forced_counters_update(true);
// If GC was requested, we better dump freeset data for performance debugging
{
ShenandoahHeapLocker locker(heap->lock());
heap->free_set()->log_status();
}
heap->free_set()->log_status_under_lock();
switch (mode) {
case concurrent_normal:
@ -178,19 +175,19 @@ void ShenandoahControlThread::run_service() {
// Report current free set state at the end of cycle, whether
// it is a normal completion, or the abort.
{
ShenandoahHeapLocker locker(heap->lock());
heap->free_set()->log_status();
heap->free_set()->log_status_under_lock();
{
// Notify Universe about new heap usage. This has implications for
// global soft refs policy, and we better report it every time heap
// usage goes down.
ShenandoahHeapLocker locker(heap->lock());
heap->update_capacity_and_used_at_gc();
// Signal that we have completed a visit to all live objects.
heap->record_whole_heap_examined_timestamp();
}
// Signal that we have completed a visit to all live objects.
heap->record_whole_heap_examined_timestamp();
// Disable forced counters update, and update counters one more time
// to capture the state at the end of GC session.
heap->handle_force_counters_update();

View File

@ -1130,6 +1130,16 @@ void ShenandoahFreeSet::reserve_regions(size_t to_reserve) {
}
}
void ShenandoahFreeSet::log_status_under_lock() {
// Must not be heap locked, it acquires heap lock only when log is enabled
shenandoah_assert_not_heaplocked();
if (LogTarget(Info, gc, free)::is_enabled()
DEBUG_ONLY(|| LogTarget(Debug, gc, free)::is_enabled())) {
ShenandoahHeapLocker locker(_heap->lock());
log_status();
}
}
void ShenandoahFreeSet::log_status() {
shenandoah_assert_heaplocked();

View File

@ -318,6 +318,9 @@ private:
void finish_rebuild(size_t cset_regions);
// log status, assuming lock has already been acquired by the caller.
void log_status();
public:
ShenandoahFreeSet(ShenandoahHeap* heap, size_t max_regions);
@ -340,7 +343,8 @@ public:
void move_regions_from_collector_to_mutator(size_t cset_regions);
void recycle_trash();
void log_status();
// Acquire heap lock and log status, assuming heap lock is not acquired by the caller.
void log_status_under_lock();
inline size_t capacity() const { return _partitions.capacity_of(ShenandoahFreeSetPartitionId::Mutator); }
inline size_t used() const { return _partitions.used_by(ShenandoahFreeSetPartitionId::Mutator); }