Acquire/Release vs Volatile in VarHandle

Aleksey Shipilev shade at redhat.com
Wed Jul 19 13:43:44 UTC 2017


On 07/19/2017 03:41 PM, Gianluca Stivan wrote:
> I tried running two tests, one using 3 setVolatiles calls, the other using 3
> setOpaque/setRelease and JMH identified the three following hot regions:
> 
> c1, java.lang.invoke.VarHandleInts$FieldStaticReadWrite::setRelease
> c1, java.lang.invoke.VarHandleInts$FieldStaticReadWrite::setVolatile
> c1, java.lang.invoke.VarHandleInts$FieldStaticReadWrite::setOpaque
> 
> The assembly generated is identical in all three cases, so from what I can see,
> it does seem that indeed there is no difference. 
> Result is similar with fences: fullFence and releaseFence both compile to `dmb sy`.

Yeah, so it might not be as optimized as you would want.

> The one thing that I was wondering tho, is that all those methods are from C1. I
> read that increasing the iterations is more likely to trigger C2, but that
> didn't happen.

Tiered compilation policy may decide to compile "trivial" methods with C1, not
with C2. Try with -XX:-TieredCompilation.

-Aleksey



More information about the jdk9-dev mailing list