Skip to content

Commit 47f651b

Browse files
authored
7903498: JMH: Reset worker interrupt status after iteration
1 parent 482561a commit 47f651b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkHandler.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,6 @@ private WorkerData getWorkerData(Thread worker) throws Exception {
451451
// Wait for all threads to roll to this synchronization point.
452452
// If there is any thread without assignment, the barrier action
453453
// would dump the unused worker data for claiming.
454-
//
455-
// In face of interruptions, the barrier can either throw the interrupted
456-
// exception if this thread caughts it and breaks the barrier,
457-
// or broken barrier exception if other threads were waiting on this
458-
// barrier. Bubble up both exceptions, and let the caller handle.
459454
workerDataBarrier.await();
460455

461456
if (wd == null) {
@@ -520,6 +515,12 @@ public BenchmarkTaskResult call() throws Exception {
520515
// bind the executor thread
521516
runner = Thread.currentThread();
522517

518+
// Clear the interruption status for the thread before going into the infra.
519+
// Normally, the interrupts would be cleared at the end of benchmark, but
520+
// there is a tiny window when harness could deliver another interrupt after
521+
// we left.
522+
boolean unused = Thread.interrupted();
523+
523524
// poll the current data, or instantiate in this thread, if needed
524525
WorkerData wd = control.firstIteration ? newWorkerData(runner) : getWorkerData(runner);
525526

@@ -552,6 +553,11 @@ public BenchmarkTaskResult call() throws Exception {
552553
} finally {
553554
// unbind the executor thread
554555
runner = null;
556+
557+
// Clear the interruption status for the thread after leaving the benchmark method.
558+
// If any InterruptedExceptions happened, they should have been handled by now.
559+
// This prepares the runner thread for another iteration.
560+
boolean unused = Thread.interrupted();
555561
}
556562
}
557563

0 commit comments

Comments
 (0)