On Wed, 1 Jul 2026 12:53:13 GMT, Christian Hagedorn <[email protected]> 
wrote:

>> src/hotspot/share/opto/library_call.cpp line 5188:
>> 
>>> 5186:       // passing in primitive class mirrors like int.class which do 
>>> not have corresponding Klass* pointers.
>>> 5187:       // In these cases, klass_node will be top. Emit a trap to throw 
>>> in the interpreter in this case.
>>> 5188:       bail_out_from_array_copyOf(bailout);
>> 
>> What if the `j.l.Class` is not a constant, but the runtime value is 
>> `int.class`, it will return `null`, right? Which explains the null check 
>> below. In that case, is it an inconsistency? Can it be an issue if a 
>> `j.l.Class` is narrowed to the constant `int.class` during IGVN, then the 
>> node will become `top` and the whole graph is incorrectly killed.
>
> Yes, if it's not a constant, then we will have type `j.l.Object`. When later 
> folding to `int.class`, the `LoadKlass` will be replaced by `null` and the 
> null check makes sure the graph is folded correctly.

Ah, I see the reason here, inside `LibraryCallKit::load_klass_from_mirror`, we 
null-check the result we get from the load. This means that if we have a 
constant `int.class`, the load will be a constant `null`, and the return value 
is `top`. But this also means that `klass_node` has already been null-checked, 
so the null-check we do right below seems redundant.

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2569#discussion_r3513822774

Reply via email to