JDK-8205549: unsafe and LW1: needed for MethodHandles, VarHandles and Reflection

mandy chung mandy.chung at oracle.com
Wed Jun 27 22:23:31 UTC 2018


On 6/27/18 2:36 PM, Karen Kinnear wrote:
> I’ve appended a summary of Unsafe object accessors used in
> MethodHandles, VarHandles and Reflection.
> 
> Thanks to Remi’s hashCode that Mandy was trying, we identified a hole
> in our current implementation. Turns out our tests for MethodHandles,
> VarHandles and Reflection did not include testing for field
> accessors to flattened value type fields, which all use unsafe.

In fact Roland reported the crash [1] (thanks).

> Next Steps:
> 
> Roland: Please do look at C2 intrinsics for the unsafe Object
> accessors and see what it would take to make these intrinsics work 
> for value types If you think there is significant benefit in adding
> new APIs, please help us understand what APIs might be most helpful.
> 
> Mandy, Paul - could you possibly send your webrevs when you are
> ready?

http://cr.openjdk.java.net/~mchung/valhalla/webrevs/unsafe-flat-fields-webrev/index.html

This approach adds Unsafe::getFlatObject and Unsafe::putFlatObject for 
flattened field access.  This allows Unsafe::getObjectXXX and 
putObjectXXX to work for non-flattened fields without suffering the 
performance hit.  Paul suggests to add Unsafe::isFlatField method.  For 
now, I piggyback on Field's modifiers and MemberName's flags to indicate 
if it's flattened or not.

This is still work in progress but this should give you a good idea what 
the new APIs we are thinking about.  This way it allows the system to 
move forward to minimize the performance impact on non-value types and 
give time to implement the proper optimization for flattened field access.

> Then we can have a better conversation of alternatives with our C2
> folks.
> 
> We will need a more complete set of tests specifically for
> MethodHandles, VarHandles and Reflection as well as for unsafe.

Agree. I'm adding more tests for java.lang.invoke and java.lang.reflect 
w.r.t. flattened/flattenable fields.

Mandy
[1] 
http://mail.openjdk.java.net/pipermail/valhalla-dev/2018-June/004383.html



More information about the valhalla-dev mailing list