[concurrency-interest] Curious: How Java Memory Model is satisfied in JSR166 locks?

Rémi Forax forax at univ-mlv.fr
Tue Aug 21 09:23:51 EDT 2007

Osvaldo Pinali Doederlein a écrit :
> Hi,
> Yes there is black magic - it's in class sun.misc.Unsafe, in methods 
> like park(), compareAndSwapXxx() and others that are used by the 
> implementations of j.u.c classes. These methods of the Unsafe class (as 
> I understand it) are declared as common native methods, without any 
> synchronization that you can notice, but they are really implemented as 
> HotSpot intrinsics, i.e. the JVM will usually replace invocations to 
> those methods for inline code that both avoids JNI overhead, and 
> includes the necessary instructions for JMM satisfaction. Notice that 
> you cannot invoke Unsafe's methods from your own code,
technically you can (with some reflection black magic) but you should not :)
>  access to that 
> class is restricted to core classes. So you must channel your needs 
> though public APIs like j.u.c locks, atomic objects and base classes 
> like AQS.
> A+
> Osvaldo

More information about the Concurrency-interest mailing list