RFR: 8345067: C2: enable implicit null checks for ZGC reads
Roberto Castañeda Lozano
rcastanedalo at openjdk.org
Tue May 13 17:44:53 UTC 2025
On Tue, 13 May 2025 08:53:08 GMT, Roberto Castañeda Lozano <rcastanedalo at openjdk.org> wrote:
>> @robcasloz Thanks for the explanations!
>> I have no idea how the GC barriers work, and what addresses they load from. So I just had a list of questions run through my mind, about what could possibly go wrong. But the questions are more speculations, because I really have no idea what the GC barriers do.
>>
>> I think I need to have a look at the GC barrier code myself, to see which things are constant and which things can be mutated (possibly by another thread). What code / documentation do you recommend I look at?
>>
>> Ideally, we would have some sort of semi-formal proof, to guarantee that if we did ever encounter a null-pointer, we would have to encounter it already on that first load.
>
>> I think I need to have a look at the GC barrier code myself, to see which things are constant and which things can be mutated (possibly by another thread). What code / documentation do you recommend I look at?
>
> Regarding code, I recommend you starting [here](https://github.com/openjdk/jdk/blob/522c7b446fef17a8400bc589c55b161e939770cc/src/hotspot/cpu/x86/gc/z/z_x86_64.ad#L126-L129) and following `z_load_barrier`. The slow barrier path is generated in a stub [here](https://github.com/openjdk/jdk/blob/522c7b446fef17a8400bc589c55b161e939770cc/src/hotspot/cpu/x86/gc/z/zBarrierSetAssembler_x86.cpp#L1217-L1235).
>
> Regarding documentation, you might have a look at the [TOPLAS paper](https://dl.acm.org/doi/full/10.1145/3538532) (which is unfortunately a bit outdated because it only covers non-generational ZGC, but might still offer some intuition that is valid for the latest ZGC version, in particular regarding concurrent relocation and load barriers), the [Generational ZGC JEP](https://openjdk.org/jeps/439), or one of the numerous presentations available on YouTube (e.g. I found the overview in https://www.youtube.com/watch?v=YyXjC68l8mw&t=864s pretty useful).
> @robcasloz Alright, to me this sounds convincing. I suggest you add a comment about this assumption, i.e. that the address we load from is always the same.
Thanks, I added comments to the zLoadP implementations (commit 20d960e6).
> And then let a GC engineer have a look at this PR, to confirm that this assumption is always correct, and that there is not some other path where the address could change ;)
Absolutely, after getting approval from the compiler side, I will request a formal review from the GC side.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25066#issuecomment-2877434993
More information about the hotspot-gc-dev
mailing list