JDK-8213362 : [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 12
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2018-11-04
  • Updated: 2020-03-24
  • Resolved: 2018-11-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12
12 b23Fixed
Related Reports
Duplicate :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
OS: MacOS Sierra 10.12.6 (16G1618)
-------------------------
Java:
openjdk version "12-ea" 2019-03-19
OpenJDK Runtime Environment (build 12-ea+17)
OpenJDK 64-Bit Server VM (build 12-ea+17, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
With the https://bugs.openjdk.java.net/browse/JDK-8210931 libjli has moved from "jli" subdirectory into standard lib directory.
However `GetJREPath` method in `src/java.base/macosx/native/libjli/java_md_macosx.m` still assumes that `libjli.dylib` should be on `lib/jli/libjli.dylib` path.

The fix is simplly to remove `/jli` from the lastPathComponent like patch below shows:
--- a/src/java.base/macosx/native/libjli/java_md_macosx.m       Fri Nov 02 19:38:54 2018 +0100
+++ b/src/java.base/macosx/native/libjli/java_md_macosx.m       Sun Nov 04 16:36:19 2018 +0100
@@ -508,7 +508,7 @@
         return JNI_FALSE;
     }
 
-    const char lastPathComponent[] = "/lib/jli/libjli.dylib";
+    const char lastPathComponent[] = "/lib/libjli.dylib";
     size_t sizeOfLastPathComponent = sizeof(lastPathComponent) - 1;
     if (pathLen < sizeOfLastPathComponent) {
         return JNI_FALSE;


REGRESSION : Last worked in version 11.0.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run application which uses `JNI_CreateJavaVM` to create a JVM (like Eclipse 4.9/4.10 does).
Download Eclipse application, run Eclipse with `-vm` parameter pointing to the openJDK 12 build as shown below:
$ ~/Workspace/test/Eclipse.app/Contents/MacOS/eclipse -vm ~/Workspace/test/jdk-12.jdk/Contents/Home/bin/java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Eclipse application starts.

ACTUAL -
Eclipse fails to start with "Failed to create the Java Virtual Machine." error dialog. In console "Failed to GetJREPath()" is printed:
$ ~/Workspace/test/Eclipse.app/Contents/MacOS/eclipse -vm ~/Workspace/test/jdk-12.jdk/Contents/Home/bin/java
CONSOLE OUT:
Error: could not find libjava.dylib
Failed to GetJREPath()


FREQUENCY : always



Comments
Based on my research, it appears that Eclipse is not using libjli directly, therefore, I believe Eclipse is not depending directly on libjli. https://github.com/eclipse/rt.equinox.framework
20-11-2018

Priyanka - do you know if Eclipse using libjli directly? I don't think this was ever a supported interface. We need to fix GetJREPath of course but important to also understand if Eclipse is depending directly on libjli.
05-11-2018

I believe jni methods are in this 'java legacy interface' library (libjli.dylib) on mac os, while they are in the normal libjvm on all other platforms. Sent for review: http://cr.openjdk.java.net/~pmangal/8213362/webrev.00/
05-11-2018

The GetJREPath implementation needs to be updated but I'm curious how Eclipse runs into this as I don't think it should run into this when using the JNI Innovcation API. Does Eclipse use libjli directly in some code paths?
05-11-2018

Issue is reproducible and its a regression from JDK-8210931 with fixed version as JDK 12-ea+13. When ran Eclipse using -vm argument with JDK 12-ea+18, got Eclipse failed to start with Alert popup saying "Failed to create the Java Virtual Machine" : $ Eclipse.app/Contents/MacOS/eclipse -vm /JDK/12-ea+18/jdk-12.jdk/Content/Home/bin/java Error: could not find libjava.dylib Failed to GetJREPath() As mentioned by Submitter, fix is to correct the "lastPathComponent" in 'src/java.base/macosx/native/libjli/java_md_macosx.m' file : - const char lastPathComponent[] = "/lib/jli/libjli.dylib"; + const char lastPathComponent[] = "/lib/libjli.dylib"; 12-ea+12 : Pass 12-ea+13 : Fail
05-11-2018