Skip to content

Commit 714b345

Browse files
committedJun 10, 2020
8247310: Shenandoah: pacer should not affect interrupt status
Reviewed-by: zgu
1 parent 191fe75 commit 714b345

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
 

‎src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
2929
#include "gc/shenandoah/shenandoahPacer.hpp"
3030
#include "runtime/atomic.hpp"
31+
#include "runtime/mutexLocker.hpp"
3132

3233
/*
3334
* In normal concurrent cycle, we have to pace the application to let GC finish.
@@ -239,7 +240,7 @@ void ShenandoahPacer::pace_for_alloc(size_t words) {
239240
}
240241

241242
// Threads that are attaching should not block at all: they are not
242-
// fully initialized yet. Calling sleep() on them would be awkward.
243+
// fully initialized yet. Blocking them would be awkward.
243244
// This is probably the path that allocates the thread oop itself.
244245
// Forcefully claim without waiting.
245246
if (JavaThread::current()->is_attaching_via_jni()) {
@@ -264,7 +265,7 @@ void ShenandoahPacer::pace_for_alloc(size_t words) {
264265
}
265266
cur = MAX2<size_t>(1, cur);
266267

267-
JavaThread::current()->sleep(cur);
268+
wait(cur);
268269

269270
double end = os::elapsedTime();
270271
total = (size_t)((end - start) * 1000);
@@ -289,6 +290,19 @@ void ShenandoahPacer::pace_for_alloc(size_t words) {
289290
}
290291
}
291292

293+
void ShenandoahPacer::wait(long time_ms) {
294+
// Perform timed wait. It works like like sleep(), except without modifying
295+
// the thread interruptible status. MonitorLocker also checks for safepoints.
296+
assert(time_ms > 0, "Should not call this with zero argument, as it would stall until notify");
297+
MonitorLocker locker(_wait_monitor);
298+
_wait_monitor->wait(time_ms);
299+
}
300+
301+
void ShenandoahPacer::notify_waiters() {
302+
MonitorLocker locker(_wait_monitor);
303+
_wait_monitor->notify_all();
304+
}
305+
292306
void ShenandoahPacer::print_on(outputStream* out) const {
293307
out->print_cr("ALLOCATION PACING:");
294308
out->cr();

‎src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ShenandoahPacer : public CHeapObj<mtGC> {
4545
ShenandoahHeap* _heap;
4646
BinaryMagnitudeSeq _delays;
4747
TruncatedSeq* _progress_history;
48+
Monitor* _wait_monitor;
4849

4950
// Set once per phase
5051
volatile intptr_t _epoch;
@@ -64,6 +65,7 @@ class ShenandoahPacer : public CHeapObj<mtGC> {
6465
ShenandoahPacer(ShenandoahHeap* heap) :
6566
_heap(heap),
6667
_progress_history(new TruncatedSeq(5)),
68+
_wait_monitor(new Monitor(Mutex::leaf, "_wait_monitor", true, Monitor::_safepoint_check_always)),
6769
_epoch(0),
6870
_tax_rate(1),
6971
_budget(0),
@@ -98,6 +100,9 @@ class ShenandoahPacer : public CHeapObj<mtGC> {
98100
void restart_with(size_t non_taxable_bytes, double tax_rate);
99101

100102
size_t update_and_get_progress_history();
103+
104+
void wait(long time_ms);
105+
void notify_waiters();
101106
};
102107

103108
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHPACER_HPP

0 commit comments

Comments
 (0)
Please sign in to comment.