Reputation: 47051
In the sun.misc
package, I saw these methods under Unsafe
class.
public final native boolean compareAndSwapObject(Object var1, long var2, Object var4, Object var5);
public final native boolean compareAndSwapInt(Object var1, long var2, int var4, int var5);
public final native boolean compareAndSwapLong(Object var1, long var2, long var4, long var6);
It seems that these methods are atomic and are written in C, but I can't find the source code for these method on Github.. Does anyone have any ideas about this? How can I find an open-source implementation for these methods easily?
Upvotes: 11
Views: 7676
Reputation: 11028
You can check out the OpenJDK code here: http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/tip/src/share/vm/prims/unsafe.cpp
Upvotes: 8
Reputation: 2055
Your question specifically asks for java 8
. Run this from command line (you need Mercurial
client installed)
hg clone http://hg.openjdk.java.net/jdk8/jdk8
This will get you source code for HotSpot
and everything else.
Upvotes: -1
Reputation: 47051
Thanks @Buddy
Finally I find source code in the Github mirror for jdk7-hotspot here:
https://github.com/openjdk-mirror/jdk7u-hotspot/blob/master/src/share/vm/prims/unsafe.cpp
Upvotes: 0
Reputation: 24157
You can download OpenJdk source code JDK7. There is a folder share(jdk\src\share) where you can get source code. The folder native (jdk\src\share\native) has source written (in c and c++):
Upvotes: 1