在哪里可以找到 java.lang 本地方法的源代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2292629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:45:28  来源:igfitidea点击:

Where to find source code for java.lang native methods?

javajava-native-interfacenative

提问by Ben Simmons

I'm vaguely familiar with the JNI, and I'm curious to see my machine-specific implementation for some native methods in the java.lang package. Thread#currentThread(), for example.

我对JNI有点熟悉,我很想知道 java.lang 包中某些本机方法的特定于机器的实现。Thread#currentThread(), 例如。

I've found a bunch of DLLs in [JDK_HOME]/jre/bin, but like I said I'm trying to find the source code.

我在 [JDK_HOME]/jre/bin 中找到了一堆 DLL,但就像我说的那样,我正在尝试查找源代码。

Does anyone know where the native source code can be found? Is it even available, or is it classified by Sun (oops I mean "We're In It To Win It" Oracle)?

有谁知道哪里可以找到本机源代码?它甚至可用,还是被 Sun 分类(哎呀,我的意思是“我们要赢得它”Oracle)?

采纳答案by Tom Hawtin - tackline

For JDK6 you can download the source from java.net. For java.langthe story begins at j2se/src/share/native/java/lang/, and then search... JDK7 rearranges the directory structure a little.

对于 JDK6,您可以从java.net下载源代码。因为java.lang故事从 开始j2se/src/share/native/java/lang/,然后搜索... JDK7 稍微重新排列了目录结构。

Some methods, such as Object.hashCode, may be implemented by hotspot instead or in addition to through JNI/Java.

某些方法,例如Object.hashCode,可以通过热点替代或通过 JNI/Java 来实现。

JDK6 is freely licensed through the Java Research License (JRL) and Java Internal Use License (JIUL). JDK7 and OpenJDK6 is licensed under GPL 2 with CLASSPATH exception (roughly speaking you can link to it without catching the GNU virus). I am not a lawyer.

JDK6 通过 Java Research License (JRL) 和 Java Internal Use License (JIUL) 获得免费许可。JDK7 和 OpenJDK6 在 GPL 2 下获得许可,但有 CLASSPATH 例外(粗略地说,您可以链接到它而不会感染 GNU 病毒)。我不是律师。

(BTW: The real lawyers would like to point out that I am still an employee of Sun Microsystems.Sun UK is no more. It is nowOracle.)

顺便说一句:真正的律师想指出的是,我仍然Sun Microsystems公司的员工。孙英国是没有更多的是的。现在的Oracle)。

Update (Adding location for Thread.c): http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/share/native/java/lang/Thread.c

更新(为 Thread.c 添加位置):http: //hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/share/native/java/lang/Thread.c

回答by Chris Jester-Young

You can look at the source code for OpenJDK(licensed under GPLv2 with Classpath Exception). Probably the best way to study the JDK implementation internals, unless you want to be bound by the Java Research Licence, in which case you can access the actual JDK 6 source.

您可以查看OpenJDK的源代码(在GPLv2使用 Classpath Exception获得许可)。可能是研究 JDK 实现内部结构的最佳方式,除非您想受Java Research License 的约束,在这种情况下,您可以访问实际的JDK 6 源代码