Hanfei Sun
Hanfei Sun

Reputation: 47051

Where can I find the source code for `native` methods in Java library?

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

Answers (4)

Buddy
Buddy

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

oᴉɹǝɥɔ
oᴉɹǝɥɔ

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

Hanfei Sun
Hanfei Sun

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

akhil_mittal
akhil_mittal

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++):

  1. jdk\src\linux source for linux.
  2. jdk\src\windows source for windows.
  3. jdk\src\solaris souce for solaris.
  4. jd\src\share common source.

Upvotes: 1

Related Questions