You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Furkan KAMACI <fu...@gmail.com> on 2014/03/08 20:33:48 UTC

volatile write to make isCleaning visible at ConcurrentLRUCache

Hi;

ConcurrentLRUCache<K,V>  class has that lines:

...
long oldestEntry = this.oldestEntry;
isCleaning = true;
this.oldestEntry = oldestEntry;     // volatile write to make isCleaning
visible
...

What does that assignment and so makes isCleaning visible?

Thanks;
Furkan KAMACI

Re: volatile write to make isCleaning visible at ConcurrentLRUCache

Posted by Yonik Seeley <yo...@heliosearch.com>.
On Sat, Mar 8, 2014 at 3:28 PM, Shawn Heisey <so...@elyograg.org> wrote:
> Do we have any idea whether this side effect of volatile access is part
> of the Java specification

Yep, it's part of the JMM (Java Memory Model) and is guaranteed behavior.

-Yonik
http://heliosearch.org - native off-heap filters and fieldcache for solr

Re: volatile write to make isCleaning visible at ConcurrentLRUCache

Posted by Shawn Heisey <so...@elyograg.org>.
On 3/8/2014 12:50 PM, Yonik Seeley wrote:
> On Sat, Mar 8, 2014 at 2:33 PM, Furkan KAMACI <fu...@gmail.com> wrote:
>> ConcurrentLRUCache<K,V>  class has that lines:
>>
>> ...
>> long oldestEntry = this.oldestEntry;
>> isCleaning = true;
>> this.oldestEntry = oldestEntry;     // volatile write to make isCleaning
>> visible
>> ...
>>
>> What does that assignment and so makes isCleaning visible?
> 
> It's called piggy-backing...
> All changes before a volatile write will be visible to another thread
> after reading that volatile variable.

Is there any kind of testing we can put in Lucene or Solr that can
detect if a future version of Java changes in a way that breaks this?

Do we have any idea whether this side effect of volatile access is part
of the Java specification or simply an exploitable side effect of
current implementations?  If it's the latter, perhaps we need to locate
and comment uses like this in a way that can be easily found later.

Thanks,
Shawn


Re: volatile write to make isCleaning visible at ConcurrentLRUCache

Posted by Yonik Seeley <yo...@heliosearch.com>.
On Sat, Mar 8, 2014 at 2:33 PM, Furkan KAMACI <fu...@gmail.com> wrote:
> ConcurrentLRUCache<K,V>  class has that lines:
>
> ...
> long oldestEntry = this.oldestEntry;
> isCleaning = true;
> this.oldestEntry = oldestEntry;     // volatile write to make isCleaning
> visible
> ...
>
> What does that assignment and so makes isCleaning visible?

It's called piggy-backing...
All changes before a volatile write will be visible to another thread
after reading that volatile variable.

-Yonik
http://heliosearch.org - native off-heap filters and fieldcache for solr