简体   繁体   English

我在哪里可以找到Java库中`native`方法的源代码?

[英]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? 如何轻松找到这些方法的开源实现?

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

  1. jdk\\src\\linux source for linux. 用于linux的jdk \\ src \\ linux源码。
  2. jdk\\src\\windows source for windows. 用于Windows的jdk \\ src \\ windows源代码。
  3. jdk\\src\\solaris souce for solaris. solaris的jdk \\ src \\ solaris源。
  4. jd\\src\\share common source. jd \\ src \\ share共同来源。

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.

相关问题 我在哪里可以找到netlib-java的源代码? - Where can I find the source-code for netlib-java? 在哪里可以找到Java中“ build”类的源代码? - Where can I find the source code of the “build” classes in Java? 在哪里可以找到我在 Java 中导入的包的源代码? - Where do I find the source code for packages that I import in Java? 在哪里可以找到所有Java(SE 7)标准库类的列表,这些类具有的方法将引发EOFException? - Where can I find the list of all Java (SE 7) standard library classes which have methods which will throw an EOFException? Java 中的库是什么,在哪里可以找到 Java 中的标准库? - What is a library in Java and where can I find the standard libraries in Java? 在哪里可以找到大多数javaFX 2功能的源代码实现? - Where can I find source code implementations for most javaFX 2 features? 在哪里可以找到Aerith Project源代码 - Where can I find Aerith Project source code 我在哪里可以找到充气城堡的源代码 - Where can I find the Bouncy Castle source code 我在哪里可以找到J2ME的源代码? - Where can I find the source code for J2ME? 在哪里可以找到具有良好Java源代码的网站? - where can I find websites with good java source codes that work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM