Skip to content

Commit

Permalink
Do not disable recurring callbacks after an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hofer committed Jan 2, 2018
1 parent d5d8bb1 commit 9fbf62b
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ void onSafepointCheckSlowpath(long timestamp, int value) {
return;
}
assert VMThreads.StatusSupport.isStatusJava();
final long unsignedIntMax = 0xffffffffL;
isExecuting = true;
long now = 0;
try {
final long unsignedIntMax = 0xffffffffL;
long elapsedNanos = timestamp - lastCapture;
long skippedChecks = value & unsignedIntMax; // interpret as unsigned
if (elapsedNanos > 0 && skippedChecks < requestedChecks) { // basic sanity
Expand All @@ -123,28 +124,30 @@ void onSafepointCheckSlowpath(long timestamp, int value) {
ewmaChecksPerNano = EWMA_LAMBDA * checksPerNano + (1 - EWMA_LAMBDA) * ewmaChecksPerNano;
}
}
long now = 0;
boolean expired = (timestamp >= nextDeadline); // avoid one nanoTime() call if true
if (!expired) {
now = System.nanoTime();
expired = (now >= nextDeadline);
}
if (expired) {
invokeCallback();
now = System.nanoTime();
nextDeadline = now + targetIntervalNanos;
try {
invokeCallback();
} finally {
now = System.nanoTime();
nextDeadline = now + targetIntervalNanos;
}
}
} catch (SafepointException se) {
throw se;
} catch (Throwable t) {
Log.log().string("Exception caught in recurring callback (ignored): ").object(t).newline();
} finally {
long remainingNanos = nextDeadline - now;
remainingNanos = (remainingNanos < MINIMUM_INTERVAL_NANOS) ? MINIMUM_INTERVAL_NANOS : remainingNanos;
double checks = ewmaChecksPerNano * remainingNanos;
requestedChecks = (checks > unsignedIntMax) ? unsignedIntMax : ((checks < 1L) ? 1L : (long) checks);
lastCapture = now;
Safepoint.setSafepointRequested((int) requestedChecks);
} catch (SafepointException se) {
throw se;
} catch (Throwable t) {
Log.log().string("Exception caught in recurring callback (ignored): ").object(t).newline();
} finally {
isExecuting = false;
}
}
Expand Down

0 comments on commit 9fbf62b

Please sign in to comment.