JEP 178 - working example?

Steve Poole spoole at linux.vnet.ibm.com
Thu May 30 03:15:35 PDT 2013


Thanks for the quick response Bob.

This all seems quite manual - are there any plans to add support to OpenJDK to help with this process?   



On 29 May 2013, at 00:06, Bob Vandette <bob.vandette at oracle.com> wrote:

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



More information about the jdk8-dev mailing list