On May 28, 2013, at 7:06 AM, Steve Poole wrote:
>
> hi everyone,
>
> I've been reading JEP 178 (Statically-Linked JNI Libraries )
> http://openjdk.java.net/jeps/178
>
> There is a sentence in the section on JNI Specification changes that says
>
> "A native library may be statically linked with the VM. The manner in which
> the library and VM image are combined is implementation-dependent."
>
> I can't find anything that explains the process in more detail so posting
> here.
>
> Basically - if I want to statically link my JNI library to Hotspot what are
> the instructions for the OpenJDK implementation?
Since the procedure for statically linking binaries into a executable is very
platform specific, the specification
intentionally leaves out these details.
The key functional changes that were implemented to support this spec change,
were:
1. Require JNI_OnLoad_{libraryname} for static libraries.
2. Modify the Java API's that load native JNI libraries to support static
libraries by detecting the
presence of the library specific OnLoad function.
3. Support JNI_OnUnLoad_{libraryname}
So you can either build the entire JDK as static libraries, change every
JNI_OnLoad function to be
unique and link them all together with a java launcher.
OR
You can create a single static library, making sure to give it a unique
JNI_OnLoad_{libraryname}
entrypoint, link it with a program executable that loads the VM via the Java
launcher or Invocation APIs.
For example: If your library name is speciallibrary.a, you would then call
System.loadLibrary("speciallibrary")
Once the loadLibrary call succeeds, you can then call any native Java methods
defined by the static library.
Bob.
>
>
> Cheers
>
> Steve