RFR: 8350722: Remove duplicate SerialGC logic for detecting pointers in young gen
Thomas Schatzl
tschatzl at openjdk.org
Wed Feb 26 08:48:58 UTC 2025
On Wed, 26 Feb 2025 06:54:19 GMT, Saint Wesonga <duke at openjdk.org> wrote:
> Checking whether a pointer is in the young generation is currently done by comparing the pointer to the end of the young generation reserved space. The duplication of these checks in various places complicates any changes the layout of the young generation since all these locations need to be updated. This PR replaces the duplicated logic with the DefNewGeneration::is_in_reserved method.
src/hotspot/share/gc/serial/defNewGeneration.cpp line 150:
> 148: bool do_object_b(oop p) {
> 149: HeapWord* heap_word_ptr = cast_from_oop<HeapWord*>(p);
> 150: bool is_in_young_gen = _young_gen->is_in_reserved((void*)heap_word_ptr);
The check for only the boundary is intentional, and guided by performance. One comparison/memory load in the original code is faster than the two memory loads/comparisons (both bounds of the reserved area) plus the eventual indirect load via `_young_gen` is just slower.
The same reason why most of the places it is used store a local copy of the generation boundary.
This adds up for hundreds of thousands of checks/references to evacuate; at least it did last time years ago.
If the goal is just factoring out the check to make it change for all locations whenever heap layout is changed, I would prefer adding a helper method in `SerialHeap` for example that's easily inlinable for the compiler.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23792#discussion_r1971169800
More information about the hotspot-gc-dev
mailing list