- System requirements
- Profiler architecture
- Profiler installation
- Uninstall profiler
- Running the profiler
- Profiler activation
- Welcome screen
- Start profiling
- Profiling overhead
- Snapshots
- Solving performance problems
- CPU profiling
- Thread profiling
- Virtual threads support
- Object allocation profiling
- Memory profiling
- Monitor profiling
- Exception profiling
- Telemetry
- Probes: monitor events of various kinds
- Inspections: automatic recognition of typical problems
- Automatically trigger actions on event
- Automatic deobfuscation
- Summary
- Filters
- Profiler command line
- Export of profiling results to external formats
- Profiler Java API
- Profiler HTTP API
- Settings
- Troubleshooting and FAQ
Heap sampling
How heap sampling works
Heap sampling, introduced in Java 11 (JEP 331), is a JVM feature that enables low-overhead, probabilistic tracing of object allocations. It periodically samples allocations on the Java heap, capturing stack traces and metadata (such as object size and type) for a subset of allocated objects. This is achieved using the JVM's memory allocation mechanisms, with a configurable sampling interval that determines how often allocations are recorded.
Advantages
- It provides the same level of detail as classic method (including thread information, full stack traces of object creation, and object size) but with lower overhead.
- Heap sampling is less invasive because it does not require bytecode instrumentation. It does not increase bytecode size or slow down class loading.
- This is especially useful in attach mode, as it prevents the pause that occurs on the first attempt to start object allocation profiling due to instrumenting classes loaded before the agent attaches.
Limitations
Because heap sampling only collects data on a fraction of the total allocations — rather than capturing every object allocation — it may miss objects. This can lead to partial or skewed insights into which code paths are responsible for the bulk of allocations.