RFR: 8371667: Shenandoah: Re-design alloc request type enum for better efficiency and cleaner code
Xiaolong Peng
xpeng at openjdk.org
Wed Nov 12 02:06:10 UTC 2025
Current alloc request type enum:
enum Type {
_alloc_shared, // Allocate common, outside of TLAB
_alloc_shared_gc, // Allocate common, outside of GCLAB/PLAB
_alloc_cds, // Allocate for CDS
_alloc_tlab, // Allocate TLAB
_alloc_gclab, // Allocate GCLAB
_alloc_plab, // Allocate PLAB
_ALLOC_LIMIT
};
With current design, we have to use switch statement resulting in unnecessary branches, for instance the function is_mutator_alloc:
inline bool is_mutator_alloc() const {
switch (_alloc_type) {
case _alloc_tlab:
case _alloc_shared:
case _alloc_cds:
return true;
case _alloc_gclab:
case _alloc_plab:
case _alloc_shared_gc:
return false;
default:
ShouldNotReachHere();
return false;
}
}
In PR, I have re-designed the enum to make the function like is_mutator_alloc much simpler by making the values of the enum follow two simple rules:
1. Smaller value for mutator alloc, large value for gc alloc
2. Odd for lab, even number for non-lab
Three functions have been simplified to one-line impl w/o branches in machine code:
inline bool is_mutator_alloc() const {
return _alloc_type <= _alloc_shared;
}
inline bool is_gc_alloc() const {
return _alloc_type >= _alloc_shared_gc;
}
inline bool is_lab_alloc() const {
return (_alloc_type & 1) == 1;
}
Test:
- [x] TEST=hotspot_gc_shenandoah
- [ ] Tier 1
-------------
Commit messages:
- touch-up
- Merge branch 'openjdk:master' into JDK-8371667
- re-shuffle the enum values and add comments
- 8371667: Shenandoah: Re-design alloc request type enum for better efficiency and cleaner code
Changes: https://git.openjdk.org/jdk/pull/28247/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28247&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8371667
Stats: 56 lines in 1 file changed: 6 ins; 41 del; 9 mod
Patch: https://git.openjdk.org/jdk/pull/28247.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28247/head:pull/28247
PR: https://git.openjdk.org/jdk/pull/28247
More information about the hotspot-gc-dev
mailing list