RFR(XS): make shared variables volatile

Andrew Haley aph at redhat.com
Thu Sep 22 15:24:50 UTC 2016


On 22/09/16 16:20, Zhengyu Gu wrote:
> On 09/22/2016 11:04 AM, Andrew Haley wrote:
> 
>> On 21/09/16 15:47, Aleksey Shipilev wrote:
>>> On 09/21/2016 04:40 PM, Zhengyu Gu wrote:
>>>> http://cr.openjdk.java.net/~zgu/volatile/webrev.01/
>>> +1
>>>
>>> I wonder if this means we should update/poll these volatile variables
>>> with Atomic::* too, at least for the benefit of weak arches like AArch64.
>> Always.  volatile is never sufficient for variables accessed racily by
>> multiple threads, and in C++11 it's undefined behaviour.  I remember
>> finding and fixing a couple of these when I did the AArch64 Shenandoah
>> port.
> 
> My intention here is simply preventing compiler from caching the shared variables, ex.
> 
> ShenandoahHeapRegion::object_iterate_interruptible()
>    ...
>    while (p < top() && !(allow_cancel && heap->cancelled_concgc()))
>    ...
> 
> 
> Setting _cancelled_concgc is followed by a full fence, I have yet checked the others.

There is no point preventing the compiler from caching the shared variables
unless you also prevent the CPU from doing the same thing.

Andrew.



More information about the shenandoah-dev mailing list