← Recipes

Better Linux Profiling Stacks

Preserve frame pointers so native profilers can produce more reliable stack traces.

Flags

-XX:+PreserveFramePointer

-XX:+PreserveFramePointer keeps the frame pointer available instead of using that register for general-purpose work. This helps tools such as Linux perf, async-profiler, and eBPF profilers unwind stacks more accurately.

Flag details

-XX:+PreserveFramePointer
Keeps the native frame pointer chain intact for JIT-compiled Java frames. This can make profiler stack unwinding more reliable, especially for mixed Java/native CPU profiles.

When to use it

Use this for production services where CPU profiling matters, especially when you need complete mixed Java/native flame graphs during incidents or load tests.

Java version support

-XX:+PreserveFramePointer is a HotSpot profiling option for platforms where frame pointers matter for native stack walking. Use it when your production profiling stack depends on frame-pointer based unwinding.

Related JEPs

Examples

java -XX:+PreserveFramePointer \
  -jar app.jar

Use this as a default for services where production CPU profiling is part of normal operations.

java -XX:+PreserveFramePointer -XX:+UseZGC -Xmx8g \
  -jar latency-api.jar

Combine it with collector and heap choices; it does not select or tune GC.

Verify

Run your profiler before and after enabling the flag and compare how many stack frames are unresolved.