On Wed, 24 Jun 2026 13:10:03 GMT, Viktor Klang <[email protected]> wrote:

>> 1. `weakCompareAndSetReferenceXxx` in `Unsafe` were delegating to wrong 
>> methods
>> 2. Replace use of `0` for reference layout with `Unsafe.NON_FLAT_LAYOUT`
>> 3. Replace use of `31 - Integer.numberOfLeadingZeros(ascale)` with 
>> `numberOfTrailingZeros`
>> 4. Remove null check for VarHandle getting from NR fields (parity with 
>> ArrayVarHandle and DirectMethodHandle), add missing null check for flat 
>> value var handles
>> 5. Remove the weird directives and old flags of RecursiveValueClass
>> 
>> Thanks to @JornVernee and @AlanBateman for spotting these issues.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> src/java.base/share/classes/java/lang/invoke/ArrayVarHandle.java line 44:
> 
>> 42: /// This var handle must check each incoming array instance to determine 
>> the
>> 43: /// layout and the correct operation for that array.
>> 44: final class ArrayVarHandle extends VarHandle {
> 
> Given the repetition of logic, and the risk of missing some change down the 
> line, at what point do we consider using a template to generate this file?

I think if that's the case, we should update all X-VarHandleXxx.java.template 
templates to be similarly generaetd. Even though they are templates, they do 
feature a lot of duplications. And given they are preexisting, I think this is 
better handled in mainline.

> src/java.base/share/classes/jdk/internal/misc/Unsafe.java line 1723:
> 
>> 1721:     private final boolean isValueObject(Class<?> valueType, Object o) {
>> 1722:         return ValueClass.isValueObjectCompatible(valueType)
>> 1723:                 && o != null && o.getClass().isValue();
> 
> I suspect having the null-check first is going to be cheaper?

I think the `isValueObjectCompatible` is likely to be cheaper because it is 
going to be eliminated if `valueType` is a constant (it mostly is in the 
context of var handles and method handles)

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2576#discussion_r3467594545
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2576#discussion_r3467588550

Reply via email to