Skip to content

Commit af4a59a

Browse files
committed
bench(gradle): add JVM flags for heap/GC stability
Fixed heap size (-Xms2g -Xmx2g), pre-touch pages, serial GC, and disabled adaptive size policy to reduce measurement noise from heap resizes, page faults, and concurrent GC threads.
1 parent 1d8ea65 commit af4a59a

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

examples/example-gradle/build.gradle.kts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ jmh {
1111

1212
// Force a System.gc() between iterations so heap state is reset before each
1313
// measurement starts. Without this, a GC pause can land inside the measurement
14-
// window and show up as a spurious regression in CI. Safe under G1 (JDK 21
15-
// default) — avoid combining with -XX:+DisableExplicitGC, which would make this
16-
// a silent no-op.
14+
// window and show up as a spurious regression in CI.
1715
forceGC = true
1816

1917
// -Xbatch forces JIT compilation to run synchronously on the benchmark thread
2018
// instead of on a background compiler thread. With background compilation, the
2119
// C2 thread can kick in mid-measurement and steal CPU cycles, producing jitter
2220
// that shows up as a regression on unchanged code. Synchronous compilation
2321
// front-loads the cost into warmup where it belongs.
24-
jvmArgs.set(listOf("-Xbatch"))
22+
//
23+
// -Xms/-Xmx: Fixed heap size eliminates resize pauses and adaptive sizing noise.
24+
// -XX:+AlwaysPreTouch: Pre-touches all heap pages at startup so lazy page faults
25+
// don't land inside measurement windows.
26+
// -XX:+UseSerialGC: Single-threaded GC is the most predictable — no concurrent
27+
// GC threads, no G1 refinement jitter.
28+
// -XX:-UseAdaptiveSizePolicy: Prevents the GC from dynamically resizing
29+
// young/old generations between runs.
30+
jvmArgs.set(listOf(
31+
"-Xbatch",
32+
"-Xms2g", "-Xmx2g",
33+
"-XX:+AlwaysPreTouch",
34+
"-XX:+UseSerialGC",
35+
"-XX:-UseAdaptiveSizePolicy",
36+
))
2537
}
2638

2739
sourceSets {

0 commit comments

Comments
 (0)