views:

155

answers:

2

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

+5  A: 

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.

Chris Jester-Young
+2  A: 

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

Tom Hawtin - tackline
Sort-of through HotSpot, though mostly through the `JVM_*` interface (what _is_ that interface called?), which provides a fairly nice abstraction layer for the VM itself.
Chris Jester-Young
I especially enjoy the fact that the bytecode verifier is implemented using _only_ JNI and the `JVM_*` interface, without touching any HotSpot internals. :-)
Chris Jester-Young