Skip to content

Commit c47a0e0

Browse files
Xiaolong PengY. Srinivas Ramakrishna
authored andcommitted
8334147: Shenandoah: Avoid taking lock for disabled free set logging
Reviewed-by: shade, ysr
1 parent 308a812 commit c47a0e0

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ bool ShenandoahConcurrentGC::collect(GCCause::Cause cause) {
153153
// the space. This would be the last action if there is nothing to evacuate.
154154
entry_cleanup_early();
155155

156-
{
157-
ShenandoahHeapLocker locker(heap->lock());
158-
heap->free_set()->log_status();
159-
}
156+
heap->free_set()->log_status_under_lock();
160157

161158
// Perform concurrent class unloading
162159
if (heap->unload_classes() &&

src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ void ShenandoahControlThread::run_service() {
147147
heap->set_forced_counters_update(true);
148148

149149
// If GC was requested, we better dump freeset data for performance debugging
150-
{
151-
ShenandoahHeapLocker locker(heap->lock());
152-
heap->free_set()->log_status();
153-
}
150+
heap->free_set()->log_status_under_lock();
154151

155152
switch (mode) {
156153
case concurrent_normal:
@@ -178,18 +175,15 @@ void ShenandoahControlThread::run_service() {
178175

179176
// Report current free set state at the end of cycle, whether
180177
// it is a normal completion, or the abort.
181-
{
182-
ShenandoahHeapLocker locker(heap->lock());
183-
heap->free_set()->log_status();
178+
heap->free_set()->log_status_under_lock();
184179

185-
// Notify Universe about new heap usage. This has implications for
186-
// global soft refs policy, and we better report it every time heap
187-
// usage goes down.
188-
heap->update_capacity_and_used_at_gc();
180+
// Notify Universe about new heap usage. This has implications for
181+
// global soft refs policy, and we better report it every time heap
182+
// usage goes down.
183+
heap->update_capacity_and_used_at_gc();
189184

190-
// Signal that we have completed a visit to all live objects.
191-
heap->record_whole_heap_examined_timestamp();
192-
}
185+
// Signal that we have completed a visit to all live objects.
186+
heap->record_whole_heap_examined_timestamp();
193187

194188
// Disable forced counters update, and update counters one more time
195189
// to capture the state at the end of GC session.

src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,16 @@ void ShenandoahFreeSet::reserve_regions(size_t to_reserve) {
11301130
}
11311131
}
11321132

1133+
void ShenandoahFreeSet::log_status_under_lock() {
1134+
// Must not be heap locked, it acquires heap lock only when log is enabled
1135+
shenandoah_assert_not_heaplocked();
1136+
if (LogTarget(Info, gc, free)::is_enabled()
1137+
DEBUG_ONLY(|| LogTarget(Debug, gc, free)::is_enabled())) {
1138+
ShenandoahHeapLocker locker(_heap->lock());
1139+
log_status();
1140+
}
1141+
}
1142+
11331143
void ShenandoahFreeSet::log_status() {
11341144
shenandoah_assert_heaplocked();
11351145

src/hotspot/share/gc/shenandoah/shenandoahFreeSet.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ class ShenandoahFreeSet : public CHeapObj<mtGC> {
318318

319319
void finish_rebuild(size_t cset_regions);
320320

321+
// log status, assuming lock has already been acquired by the caller.
322+
void log_status();
323+
321324
public:
322325
ShenandoahFreeSet(ShenandoahHeap* heap, size_t max_regions);
323326

@@ -340,7 +343,8 @@ class ShenandoahFreeSet : public CHeapObj<mtGC> {
340343
void move_regions_from_collector_to_mutator(size_t cset_regions);
341344

342345
void recycle_trash();
343-
void log_status();
346+
// Acquire heap lock and log status, assuming heap lock is not acquired by the caller.
347+
void log_status_under_lock();
344348

345349
inline size_t capacity() const { return _partitions.capacity_of(ShenandoahFreeSetPartitionId::Mutator); }
346350
inline size_t used() const { return _partitions.used_by(ShenandoahFreeSetPartitionId::Mutator); }

0 commit comments

Comments
 (0)