From 47f651b72d05c2c335f8ced5ed33f2fb0dd26720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksey=20Shipil=C3=ABv?= Date: Tue, 20 Jun 2023 10:23:12 +0200 Subject: [PATCH] 7903498: JMH: Reset worker interrupt status after iteration --- .../org/openjdk/jmh/runner/BenchmarkHandler.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkHandler.java b/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkHandler.java index e5a147d20..a418d1903 100644 --- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkHandler.java +++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkHandler.java @@ -451,11 +451,6 @@ private WorkerData getWorkerData(Thread worker) throws Exception { // Wait for all threads to roll to this synchronization point. // If there is any thread without assignment, the barrier action // would dump the unused worker data for claiming. - // - // In face of interruptions, the barrier can either throw the interrupted - // exception if this thread caughts it and breaks the barrier, - // or broken barrier exception if other threads were waiting on this - // barrier. Bubble up both exceptions, and let the caller handle. workerDataBarrier.await(); if (wd == null) { @@ -520,6 +515,12 @@ public BenchmarkTaskResult call() throws Exception { // bind the executor thread runner = Thread.currentThread(); + // Clear the interruption status for the thread before going into the infra. + // Normally, the interrupts would be cleared at the end of benchmark, but + // there is a tiny window when harness could deliver another interrupt after + // we left. + boolean unused = Thread.interrupted(); + // poll the current data, or instantiate in this thread, if needed WorkerData wd = control.firstIteration ? newWorkerData(runner) : getWorkerData(runner); @@ -552,6 +553,11 @@ public BenchmarkTaskResult call() throws Exception { } finally { // unbind the executor thread runner = null; + + // Clear the interruption status for the thread after leaving the benchmark method. + // If any InterruptedExceptions happened, they should have been handled by now. + // This prepares the runner thread for another iteration. + boolean unused = Thread.interrupted(); } }