Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VarHandle Performance #3019

Open
2 of 6 tasks
liqunl opened this issue Sep 25, 2018 · 3 comments
Open
2 of 6 tasks

VarHandle Performance #3019

liqunl opened this issue Sep 25, 2018 · 3 comments

Comments

@liqunl
Copy link
Contributor

liqunl commented Sep 25, 2018

VarHandle has been added as a feature of Java9, to replace Unsafe.

In openj9, VarHandle is implemented using MethodHandle. In the JIT, we recognize and transform a VarHandle call into an invokeGeneric on a MethodHandle object which is an element of Varhandle.handleTable. The invokeGeneric becomes a invokeExact on a MethodHandle after conversion in the trees.

In simplified trees, the call is transformed from

call VarHandle.set
   aload VH

to

acall MethodHandle.asType
   aloadi VarHandle.handleTable[i]
      aload VH
   aload <call site MethodType>
call MethodHandle.invokeExact
   ==>acall MethodHandle.asType

As stated in http://openjdk.java.net/jeps/193, users of VarHandle is encouraged to store VarHandle objects into static final fields to allow constant folding to fold away some checks.

For predictable behaviour and performance at runtime VarHandle instances should be held in static final fields

Currently, our goal is to optimize VarHandle calls on VarHandle instances that are held in static final fields. The following are the main things we need,

Other optimizations include

  • Try to replace acall MethodHandle.asType with conversion trees for invoke generic.
    asType will create a new MethodHandle for invoke generic, stopping the JIT from targeted inlining.
  • More optimized java code in VarHandle subclasses.

Changes we have made
#671
#663
#264
#235
#210
#2121
eclipse-omr/omr#1796

@liqunl
Copy link
Contributor Author

liqunl commented Sep 25, 2018

FYI @andrewcraik

@pshipton
Copy link
Member

According to @andrewcraik the work targeted to 0.11.0 is completed. Moving to 0.12.0 for any remaining work.

liqunl pushed a commit to liqunl/openj9 that referenced this issue Oct 12, 2018
VarHandle concreate access methods contain information on the field to
be accessed, thus the unsafe calls can be transformed into direct
memory access or codegen intrinsics.

Part of Issue eclipse-openj9#3019

Signed-off-by: Liqun Liu <[email protected]>
acrowthe pushed a commit to acrowthe/openj9 that referenced this issue Nov 5, 2018
VarHandle concreate access methods contain information on the field to
be accessed, thus the unsafe calls can be transformed into direct
memory access or codegen intrinsics.

Part of Issue eclipse-openj9#3019

Signed-off-by: Liqun Liu <[email protected]>
@pshipton
Copy link
Member

pshipton commented Jan 7, 2019

The expected performance improvements are delivered in the 0.12 milestone. Re-targeting to 0.14 (the next quarterly delivery) for the remaining work. If this happens to complete before the 0.13 (Java 12) milestone the target milestone will be adjusted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants