RFR(S): 8050972: Concurrency problem in PcDesc cache
martin.doerr at sap.com
Fri Jul 18 08:27:25 UTC 2014
yes, the compiler is allowed to generate 2 loads in your example.
And yes, declaring the field volatile suffices to prevent this.
From: hotspot-dev [mailto:hotspot-dev-bounces at openjdk.java.net] On Behalf Of David Holmes
Sent: Freitag, 18. Juli 2014 07:28
To: Lindenmaier, Goetz; hotspot-dev at openjdk.java.net
Subject: Re: RFR(S): 8050972: Concurrency problem in PcDesc cache
On 17/07/2014 6:54 PM, Lindenmaier, Goetz wrote:
> This webrev fixes an important concurrency issue in nmethod.
> Please review and test this change. I please need a sponsor.
> This should be fixed into 8u20, too.
> The entries of the PcDesc cache in nmethods are not declared as volatile, but they are accessed and modified by several threads concurrently. Some compilers (namely xlC 12 on AIX) duplicate some memory accesses to non-volatile fields. In this case, this has led to the situation that a thread had successfully matched a pc in the cache, but returned the reloaded value which was already overwritten by another thread.
Do you mean that code like:
int val = ptr->field;
int val2 = 2*val;
might result in the compiler generating two loads for ptr->field?
That would surely break a lot of lock-free algorithms! Or are you saying
that would only happen if field (ptr?) is not volatile?
Otherwise this change seems insufficient to ensure general MT
correctness as Vitaly suggested.
> Best regards,
> Martin and Goetz.
More information about the hotspot-dev