# HG changeset patch # User shade # Date 1591779268 -7200 # Wed Jun 10 10:54:28 2020 +0200 # Node ID c53cc504fc2cd240df858b024aa8420235d3180c # Parent fb88a17c572cf5159d40d4d48e11e126227022ae 8247310: Shenandoah: pacer should not affect interrupt status Reviewed-by: XXX diff --git a/src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp b/src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp --- a/src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp @@ -28,6 +28,7 @@ #include "gc/shenandoah/shenandoahHeap.inline.hpp" #include "gc/shenandoah/shenandoahPacer.hpp" #include "runtime/atomic.hpp" +#include "runtime/mutexLocker.hpp" /* * In normal concurrent cycle, we have to pace the application to let GC finish. @@ -239,7 +240,7 @@ } // Threads that are attaching should not block at all: they are not - // fully initialized yet. Calling sleep() on them would be awkward. + // fully initialized yet. Blocking them would be awkward. // This is probably the path that allocates the thread oop itself. // Forcefully claim without waiting. if (JavaThread::current()->is_attaching_via_jni()) { @@ -264,7 +265,7 @@ } cur = MAX2(1, cur); - JavaThread::current()->sleep(cur); + wait(cur); double end = os::elapsedTime(); total = (size_t)((end - start) * 1000); @@ -289,6 +290,19 @@ } } +void ShenandoahPacer::wait(long time_ms) { + // Perform timed wait. It works like like sleep(), except without modifying + // the thread interruptible status. MonitorLocker also checks for safepoints. + assert(time_ms > 0, "Should not call this with zero argument, as it would stall until notify"); + MonitorLocker locker(_wait_monitor); + _wait_monitor->wait(time_ms); +} + +void ShenandoahPacer::notify_waiters() { + MonitorLocker locker(_wait_monitor); + _wait_monitor->notify_all(); +} + void ShenandoahPacer::print_on(outputStream* out) const { out->print_cr("ALLOCATION PACING:"); out->cr(); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp b/src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp --- a/src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp @@ -45,6 +45,7 @@ ShenandoahHeap* _heap; BinaryMagnitudeSeq _delays; TruncatedSeq* _progress_history; + Monitor* _wait_monitor; // Set once per phase volatile intptr_t _epoch; @@ -64,6 +65,7 @@ ShenandoahPacer(ShenandoahHeap* heap) : _heap(heap), _progress_history(new TruncatedSeq(5)), + _wait_monitor(new Monitor(Mutex::leaf, "_wait_monitor", true, Monitor::_safepoint_check_always)), _epoch(0), _tax_rate(1), _budget(0), @@ -98,6 +100,9 @@ void restart_with(size_t non_taxable_bytes, double tax_rate); size_t update_and_get_progress_history(); + + void wait(long time_ms); + void notify_waiters(); }; #endif // SHARE_GC_SHENANDOAH_SHENANDOAHPACER_HPP