[英]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. 在sun.misc
包中,我在Unsafe
类下看到了这些方法。
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? 似乎这些方法都是原子的并且是用C语言编写的,但我在Github上找不到这些方法的源代码。有没有人对此有任何想法? How can I find an open-source implementation for these methods easily? 如何轻松找到这些方法的开源实现?
你可以在这里查看OpenJDK代码: http : //hg.openjdk.java.net/jdk8/jdk8/hotspot/file/tip/src/share/vm/prims/unsafe.cpp
You can download OpenJdk source code JDK7 . 您可以下载OpenJdk源代码JDK7 。 There is a folder share(jdk\\src\\share) where you can get source code. 有一个文件夹共享(jdk \\ src \\ share),您可以在其中获取源代码。 The folder native (jdk\\src\\share\\native) has source written (in c and c++): 文件夹native(jdk \\ src \\ share \\ native)有源代码(用c和c ++编写):
Thanks @Buddy 谢谢哥们儿
Finally I find source code in the Github mirror for jdk7-hotspot here: 最后,我在github镜像中找到了jdk7-hotspot的源代码:
https://github.com/openjdk-mirror/jdk7u-hotspot/blob/master/src/share/vm/prims/unsafe.cpp https://github.com/openjdk-mirror/jdk7u-hotspot/blob/master/src/share/vm/prims/unsafe.cpp
Your question specifically asks for java 8
. 你的问题特别要求java 8
。 Run this from command line (you need Mercurial
client installed) 从命令行运行(您需要安装Mercurial
客户端)
hg clone http://hg.openjdk.java.net/jdk8/jdk8
This will get you source code for HotSpot
and everything else. 这将为您提供HotSpot
和其他所有内容的源代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.