Skip to content

Commit 2bb8af6

Browse files
committed
refactor(jmh-fork): thread isWarmup flag into runBenchmark
Replace the inline isWarmupFork() check inside runBenchmark's measurement loop with an explicit isWarmup flag computed in doSingle from `!mode.doMeasurement() || isWarmupFork()`. Groundwork for COD-2548 (warmup leaking into flamegraphs for <100ns benchmarks): centralises the warmup-vs-measurement decision so the outer startBenchmark/stopBenchmark scope can be tightened next.
1 parent a0f178f commit 2bb8af6

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

jmh-fork/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,17 @@ public void acceptMeta(BenchmarkResultMetaData md) {
148148
}
149149

150150
private void doSingle(BenchmarkParams params, ActionMode mode, IterationResultAcceptor acceptor) {
151+
boolean isWarmup = !mode.doMeasurement() || isWarmupFork();
151152
try {
152153
switch (mode) {
153154
case WARMUP: {
154-
runBenchmark(params, null);
155+
runBenchmark(params, null, isWarmup);
155156
out.println("");
156157
break;
157158
}
158159
case WARMUP_MEASUREMENT:
159160
case MEASUREMENT: {
160-
runBenchmark(params, acceptor);
161+
runBenchmark(params, acceptor, isWarmup);
161162
break;
162163
}
163164
default:
@@ -248,11 +249,11 @@ private String formatDuration(long nanos) {
248249
return String.format("%s%02d:%02d:%02d", (days > 0) ? days + " days, " : "", hrs, mins, secs);
249250
}
250251

251-
void runBenchmark(BenchmarkParams benchParams, IterationResultAcceptor acceptor) {
252+
void runBenchmark(BenchmarkParams benchParams, IterationResultAcceptor acceptor, boolean isWarmup) {
252253
BenchmarkHandler handler = null;
253254
try {
254255
handler = new BenchmarkHandler(out, options, benchParams);
255-
runBenchmark(benchParams, handler, acceptor);
256+
runBenchmark(benchParams, handler, acceptor, isWarmup);
256257
} catch (BenchmarkException be) {
257258
throw be;
258259
} catch (Throwable ex) {
@@ -264,7 +265,7 @@ void runBenchmark(BenchmarkParams benchParams, IterationResultAcceptor acceptor)
264265
}
265266
}
266267

267-
protected void runBenchmark(BenchmarkParams benchParams, BenchmarkHandler handler, IterationResultAcceptor acceptor) {
268+
protected void runBenchmark(BenchmarkParams benchParams, BenchmarkHandler handler, IterationResultAcceptor acceptor, boolean isWarmup) {
268269
long warmupTime = System.currentTimeMillis();
269270

270271
long allWarmup = 0;
@@ -307,7 +308,7 @@ protected void runBenchmark(BenchmarkParams benchParams, BenchmarkHandler handle
307308
IterationResult ir = handler.runIteration(benchParams, mp, isFirstIteration, isLastIteration);
308309
long endTs = InstrumentHooks.currentTimestamp();
309310

310-
if (!isWarmupFork()) {
311+
if (!isWarmup) {
311312
InstrumentHooks hooks = InstrumentHooks.getInstance();
312313
int pid = (int) ProcessHandle.current().pid();
313314
hooks.addMarker(pid, InstrumentHooks.MARKER_TYPE_BENCHMARK_START, startTs);

0 commit comments

Comments
 (0)