[lworld] RFR: Unsafe primitives for values

Mandy Chung mandy.chung at oracle.com
Wed Dec 12 18:33:27 UTC 2018



On 12/12/18 9:09 AM, Roland Westrelin wrote:
> Hi Mandy,
>
>> The new Unsafe APIs for values include the following:
>>
>> boolean Unsafe::isFlattened(Field f);
>> boolean Unsafe::isFlattenedArray(Class<?> arrayClass);
>> <V> long valueHeaderSize(Class<V> vc);
>> <V> V makePrivateBuffer(V value);
>> <V> V finishPrivateBuffer(V value);
>> <V> V getValue(Object o, long offset, Class<?> vc);
>> <V> void putValue(Object o, long offset, Class<?> vc, V v);
>>
>> makePrivateBuffer creates a value instance whose layout and
>> contents is exactly the same as the input value and marks it in
>> larval state and finishPrivateBuffer will exit the larval state.
>> In between Unsafe.putXXX on the buffer will update the larval
>> value instance.
> John suggested this API some months ago but my recollection is that the
> last time this was discussed (at the face to face meeting in
> Burlington), John proposed going with another API (one that would work a
> bit like the withfield bytecode: Unsafe.withInt() etc.). Was it decided
> to not go with this one after all? Or maybe I'm misremembering?
>

Your memory is correct and we went with the "Unsafe::withXXX" option 
initially.  John talked to me a couple weeks ago that he suggests to go 
with the "private buffer" option which is more robust than the "new 
withXXX API points, 10 of them (primitive + ref + value)". With the 
private buffer option, the existing Unsafe::putXXX APIs on the buffer 
will have predictable effects. The JIT can easily eliminate the 
allocation away the buffer.  John sketched the rough idea of this option 
[1].  I did prototype the withXXX option to get a sense of the usage of 
these new API points.  I do like this private buffer option better.

Mandy
[1] 
http://mail.openjdk.java.net/pipermail/valhalla-dev/2018-June/004501.html
[2] 
http://cr.openjdk.java.net/~mchung/valhalla/webrevs/unsafe/unsafe-withfield-api/


More information about the valhalla-dev mailing list