RFR: 8353067: Shenandoah: Re-shuffle GC state enum for better encoding

Xiaolong Peng xpeng at openjdk.org
Fri Feb 27 01:27:02 UTC 2026


Currently, we have weird code generation in aarch64 Shenandoah barriers, e.g.:

  // Check for heap stability
  if (is_strong) {
    __ tbz(rscratch2, ShenandoahHeap::HAS_FORWARDED_BITPOS, heap_stable);
  } else {
    Label lrb;
    __ tbnz(rscratch2, ShenandoahHeap::WEAK_ROOTS_BITPOS, lrb);
    __ tbz(rscratch2, ShenandoahHeap::HAS_FORWARDED_BITPOS, heap_stable);
    __ bind(lrb);
  }

The double-test in the weak-path could be avoided by doing something like:

  __ andb(rscratch2, rscratch2, ShenandoahHeap::WEAK_ROOTS | ShenandoahHeap::HAS_FORWARDED);
  __ cbz(done);


However, the two constants together makes 17, and this can not be encoded as immediate in aarch64. Re-ordering the GC state enum such that the two constants are adjacent would likely solve this.

In this PR:
* GC state enum has been re-shuffled to make HAS_FORWARDED and WEAK_ROOTS adjacent,
* The assemble code is also updated  to leverage this to reduce instructions.


### Test
- [x] hotspot_gc_shenandoah
- [ ] GHA

-------------

Commit messages:
 - 8353067: Optimize weak barrier check with AND+CBZ
 - 8353067: Shenandoah: Re-shuffle GC state enum for better encoding

Changes: https://git.openjdk.org/jdk/pull/29949/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29949&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8353067
  Stats: 18 lines in 2 files changed: 8 ins; 5 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/29949.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/29949/head:pull/29949

PR: https://git.openjdk.org/jdk/pull/29949


More information about the shenandoah-dev mailing list