----- Original Message -----
> From: "John Rose" <[email protected]>
> To: "Remi Forax" <[email protected]>
> Cc: "valhalla-dev" <[email protected]>
> Sent: Thursday, May 21, 2026 1:43:47 AM
> Subject: Re: [External] : Some value related methods of 
> jdk.internal.miscUnsafe are unsound ?

> You are worried about unsoundness in Unsafe!? 

Yes ! Using Unsafe is hard, why make it harder ?

> The V there is not idiomatic
> generics for sure. I suppose it has a marginal value of showing which Object
> corresponds to the value type. Like a C typedef of void*.
> 
> So, what? It’s an internal API.

An internal API like this is still potentially used by a lot of people,
even without counting the ones that crack open that API using command line 
flags.

Did you notice that the valueType is not typed Class<V> but Class<?> so using a 
type parameter here does not make the API easier to use, worst, getFlatValue() 
can return any Object and the compiler will stealthily add a cast making the 
performance model hard to understand. 

So V in putFlatValue is useless, it adds a generic signature in the bytecode 
for no reason and V in getFlatValue() let the compiler inserts an unsafe cast.

regards,
Rémi

> 
>> On May 20, 2026, at 2:10 PM, Remi Forax <[email protected]> wrote:
>> 
>> Hello,
>> I wonder why
>>  public native <V> V getFlatValue(Object o, long offset, int layoutKind, 
>> Class<?>
>>  valueType);
>> 
>> and
>>  public native <V> void putFlatValue(Object o, long offset, int layoutKind,
>>  Class<?> valueType, V v);
>> 
>> are using a type parameter V in such unsound way ?
>> 
>> Moreover, having methods that are both native and generic may be an issue in 
>> the
>> future, when we try to implement type argument propagation (parametric VM or
>> not).
>> 
>> Is there a reason why those two methods are using a type parameter ?
>> 
>> regards,
>> Rémi
>> 

Reply via email to