Search code examples
javajava-native-interfacejvm-hotspot

What is the Java libjli library for?


I am using JNI to allow C code to offload some work best done in Java. In this question I was trying to link the libjvm and libjli libraries for my code to work, but now I'm questioning whether I even need the JLI library.

I cannot find any documentation that clearly states what the purpose of the JLI library is.

This other SO question hints at JLI being some OSX passthrough library:

#elif defined(__APPLE__)
// jli needs to be loaded on OSX because otherwise the OS tries to run the system Java

As does this blog:

When compiling on OS X it’s very important to link the jli library before the jvm library

My questions:

  1. What is the JLI library for?
  2. Do I need it for C/Java JNI development in RedHat/CentOS-only environments (no OSX)?

Solution

  • What is the JLI library for?

    The libjli.so contains a launcher interface for preparing arguments passed in the command line and launching the virtual machine with them.

    The launcher main.c is the main entry point in all Java programs. It prepares the C command line arguments and passes them into JLI_Launch function which performs argument parsing, loading virtual machine from libjvm.so, forking primordial thread and then passing control to the JVM.

    Do I need it for C/Java JNI development in RedHat/CentOS-only environments (no OSX)?

    Very unlikely. If you need you are probably doing something wrong. At least I cannot imagine any useful general use-case.