RFR: JMC-8477: Add opt-in memory-mapped file support for event storage
Jaroslav Bachorik
jbachorik at openjdk.org
Fri Dec 5 12:07:37 UTC 2025
## Summary
Implements [JMC-8477](https://bugs.openjdk.org/browse/JMC-8477): Add opt-in memory-mapped file support to JFR Writer API for off-heap event storage.
## Problem
The current JFR Writer API stores all event data in on-heap byte arrays during recording creation, causing:
- **Heap pressure** from large byte array allocations
- **GC overhead** from frequent allocation/deallocation
- **Unbounded memory growth** with recording size
- **Scalability issues** for long-running or high-throughput scenarios
## Solution
This PR adds opt-in memory-mapped file support, allowing event data to be stored off-heap.
### API
Users opt in via the builder pattern:
Recording recording = Recordings.newRecording(outputStream,
settings -> settings.withMmap(4 * 1024 * 1024) // 4MB per thread
.withJdkTypeInitialization());
### Benefits
- **Reduced Heap Pressure**: Event data stored off-heap eliminates large on-heap allocations
- **Predictable Memory Usage**: Fixed memory footprint per thread regardless of recording size
- **Improved Performance**: JMH benchmarks show 8-12% throughput improvement
- **Better Scalability**: Multiple recordings can coexist without competing for heap space
- **Fully Backward Compatible**: Heap mode remains the default; opt-in only
### Performance Results
JMH benchmarks show consistent improvements across event types:
- writeSimpleEvent: +8.3% (909K → 985K ops/s)
- writeMultiFieldEvent: +11.9% (787K → 881K ops/s)
- writeRepeatedStringsEvent: +11.9% (793K → 887K ops/s)
- writeStringHeavyEvent: +10.4% (801K → 884K ops/s)
## Backward Compatibility
- ✅ Heap mode remains the default behavior
- ✅ Existing API unchanged - no breaking changes
- ✅ All existing tests pass without modification
- ✅ New functionality accessed only through explicit opt-in
## Testing
- **Unit Tests**: 850+ lines covering core functionality
- **Integration Tests**: Multi-threaded stress tests, large event tests
- **Benchmarks**: Comprehensive JMH benchmark suite with comparison tools
- **Validation**: All existing JFR Writer tests pass
## Commits
1. **Add JMH benchmark infrastructure** (44aa6377) - JMH benchmarks for performance validation
2. **Add memory-mapped file support** (5def3258) - Core mmap implementation
3. **Refactor to builder pattern** (aaddf983) - Move from system properties to builder API
4. **Fix JMH benchmark build** (7264aa4e) - Enable out-of-the-box benchmark execution
5. **Add comparison tool** (449eefdc) - Python script for benchmark result analysis
## Documentation
- README.md with comprehensive usage instructions
- JMH benchmark guide with examples
- Comparison tool for performance analysis
🤖 Generated with [Claude Code](https://claude.com/claude-code)
-------------
Commit messages:
- Add benchmark comparison tool and enhance documentation
- Fix JMH benchmark build and add comprehensive documentation
- Refactor mmap configuration from system properties to builder pattern
- Add memory-mapped file support for JFR Writer
- Add JMH benchmark infrastructure for JFR Writer performance analysis
- 8475: Writing events with fields not explicitly set can corrupt the recording
Changes: https://git.openjdk.org/jmc/pull/691/files
Webrev: https://webrevs.openjdk.org/?repo=jmc&pr=691&range=00
Issue: https://bugs.openjdk.org/browse/JMC-8477
Stats: 5545 lines in 27 files changed: 5489 ins; 10 del; 46 mod
Patch: https://git.openjdk.org/jmc/pull/691.diff
Fetch: git fetch https://git.openjdk.org/jmc.git pull/691/head:pull/691
PR: https://git.openjdk.org/jmc/pull/691
More information about the jmc-dev
mailing list