Skip to content
Permalink
Browse files
8247310: Shenandoah: pacer should not affect interrupt status
Reviewed-by: zgu
  • Loading branch information
shipilev committed Jun 10, 2020
1 parent 191fe75 commit 714b345bf556da63b1bb7d0f53b879115dfe85fc
Showing 2 changed files with 21 additions and 2 deletions.
@@ -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 @@ void ShenandoahPacer::pace_for_alloc(size_t words) {
}

// 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 @@ void ShenandoahPacer::pace_for_alloc(size_t words) {
}
cur = MAX2<size_t>(1, cur);

JavaThread::current()->sleep(cur);
wait(cur);

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

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();
@@ -45,6 +45,7 @@ class ShenandoahPacer : public CHeapObj<mtGC> {
ShenandoahHeap* _heap;
BinaryMagnitudeSeq _delays;
TruncatedSeq* _progress_history;
Monitor* _wait_monitor;

// Set once per phase
volatile intptr_t _epoch;
@@ -64,6 +65,7 @@ class ShenandoahPacer : public CHeapObj<mtGC> {
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 @@ class ShenandoahPacer : public CHeapObj<mtGC> {
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

0 comments on commit 714b345

Please sign in to comment.