Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

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)?

like image 241
Ben Simmons Avatar asked Feb 18 '10 22:02

Ben Simmons


People also ask

What is native Java code?

The JNI is a native programming interface. It allows Java code that runs inside a Java Virtual Machine (VM) to interoperate with applications and libraries written in other programming languages, such as C, C++, and assembly.

What is native method library?

Native Method Libraries are libraries that are written in other programming languages, such as C, C++, and assembly. These libraries can be loaded through JNI. So, the picture you posted is saying that JNI allows access to Native Method Libraries. Follow this answer to receive notifications.

What are native libraries Java?

A native library is a library that contains "native" code. That is, code that has been compiled for a specific hardware architecture or operating system such as x86 or windows. Including such native library in your project may break the platform-independence of you application.


2 Answers

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

Some methods, such as Object.hashCode, may be implemented by hotspot instead or in addition to through 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.

(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 now Oracle.)

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

like image 75
Tom Hawtin - tackline Avatar answered Oct 06 '22 03:10

Tom Hawtin - tackline


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.

like image 31
Chris Jester-Young Avatar answered Oct 06 '22 02:10

Chris Jester-Young