AtomicLongArray

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

AtomicLongArray

Sleiman Jneidi
Hi everyone, I was looking at source code of AtomicLongArray and found this line in JDK 1.6

public AtomicLongArray(int length) {
    array = new long[length];
    // must perform at least one volatile write to conform to JMM
    if (length > 0)
        unsafe.putLongVolatile(array, rawIndex(0), 0);
}

  Now, at later versions I noticed that lines were removed, and the code looks like this now

public AtomicLongArray(int length) {
        array = new long[length];
}

Any changes to the  JMM between 1.6 and 1.7?


Thanks,

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: AtomicLongArray

Andrew Haley
On 11/26/2015 01:02 PM, Sleiman Jneidi wrote:

> Hi everyone, I was looking at source code of AtomicLongArray and found this
> line in JDK 1.6
>
> public AtomicLongArray(int length) {
>     array = new long[length];
>     // must perform at least one volatile write to conform to JMM
>     if (length > 0)
>         unsafe.putLongVolatile(array, rawIndex(0), 0);
> }
>
>   Now, at later versions I noticed that lines were removed, and the code
> looks like this now
>
> public AtomicLongArray(int length) {
>         array = new long[length];
> }
>
> Any changes to the  JMM between 1.6 and 1.7?

array is final, so the VM guarantees safe publication.  This was guaranteed
in Java SE5, so I guess this must have been a hangover from old code.

Andrew.


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest