On Thu, 18 Dec 2025 08:26:03 GMT, Marc Chevalier <[email protected]> wrote:
> Let's proceed piece by piece. > > # `G1BarrierSetAssembler::g1_write_barrier_pre` in > `g1BarrierSetAssembler_aarch64.cpp` > > https://github.com/openjdk/valhalla/blob/1077e4f9f06336af30d95fc28cbab4d31c9f2a44/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.cpp#L216-L220 > > `push_call_clobbered_registers`/`pop_call_clobbered_registers` should be > enough around a runtime call, that's what clobbered registers are. > > But let's dig a bit, that will be useful later! > > > push_call_clobbered_registers() > => push_call_clobbered_registers_except(exclude = empty set) > => push(call_clobbered_gp_registers() - exclude, sp) // with exclude = empty > set > > So, we save at least `call_clobbered_gp_registers` which is defined as: > > https://github.com/openjdk/valhalla/blob/1077e4f9f06336af30d95fc28cbab4d31c9f2a44/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L3614-L3620 > > So, we save r0-r7 and r10-r17 > > # `CardTableBarrierSetAssembler::oop_store_at` in > `cardTableBarrierSetAssembler_aarch64.cpp` and > `cardTableBarrierSetAssembler_x86.cpp` > > https://github.com/openjdk/valhalla/blob/1077e4f9f06336af30d95fc28cbab4d31c9f2a44/src/hotspot/cpu/aarch64/gc/shared/cardTableBarrierSetAssembler_aarch64.cpp#L116-L124 > > Digging the history, it seems it was added to fix a corruption of > `dst.base()`. Yet, it might not be always necessary. It's rather nicer to > save where it matter that the register is not corrupted than all the way > down. So, there are a few such places: > > - `gen_c2i_adapter_helper` in `sharedRuntime_x86_64.cpp` > `gen_c2i_adapter_helper` calls `store_heap_oop` that can corrupts > `to.base()`. `gen_c2i_adapter_helper` is called, for instance from > `gen_c2i_adapter`: > > https://github.com/openjdk/valhalla/blob/1077e4f9f06336af30d95fc28cbab4d31c9f2a44/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp#L1069-L1070 > where we can see that `to.base()` is `r14`, which is set > > https://github.com/openjdk/valhalla/blob/1077e4f9f06336af30d95fc28cbab4d31c9f2a44/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp#L1026 > before the loop enclosing the call to `gen_c2i_adapter_helper` > > https://github.com/openjdk/valhalla/blob/1077e4f9f06336af30d95fc28cbab4d31c9f2a44/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp#L1036 > If we do more than one iteration of this loop when entering the > `store_heap_oop` branch, `r14` is corrupted at the second call and we get a > segfault. > - `generate_buffered_inline_type_adapter` in `sharedRuntime_x86_64.cpp`: same > with register `rax` being corrupted in a loop. > - `pack_inline_helper` ... This pull request has now been integrated. Changeset: d8438ac7 Author: Marc Chevalier <[email protected]> URL: https://git.openjdk.org/valhalla/commit/d8438ac789f1425030dc61403384f9fbb548ee13 Stats: 118 lines in 9 files changed: 35 ins; 55 del; 28 mod 8366717: [lworld] Cleanup defensive fixing of JDK-8365996 Reviewed-by: thartmann ------------- PR: https://git.openjdk.org/valhalla/pull/1824
