JDK-8211288: app-image fails to find JLI lib at launch time JDK-8200758-branch
authorherrick
Tue, 09 Oct 2018 18:29:53 -0400
branchJDK-8200758-branch
changeset 56948 60e53f98dac0
parent 56947 5a03c4524b90
child 56949 b06759b804fc
JDK-8211288: app-image fails to find JLI lib at launch time Reviewed-by: almatvee, kcr
src/java.base/macosx/native/libjli/java_md_macosx.m
src/jdk.packager/macosx/classes/jdk/packager/internal/builders/mac/MacAppImageBuilder.java
src/jdk.packager/macosx/native/launcher/main.m
src/jdk.packager/macosx/native/library/MacPlatform.mm
src/jdk.packager/share/native/library/common/LinuxPlatform.cpp
src/jdk.packager/share/native/library/common/main.cpp
--- a/src/java.base/macosx/native/libjli/java_md_macosx.m	Tue Oct 09 17:50:26 2018 -0400
+++ b/src/java.base/macosx/native/libjli/java_md_macosx.m	Tue Oct 09 18:29:53 2018 -0400
@@ -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;
--- a/src/jdk.packager/macosx/classes/jdk/packager/internal/builders/mac/MacAppImageBuilder.java	Tue Oct 09 17:50:26 2018 -0400
+++ b/src/jdk.packager/macosx/classes/jdk/packager/internal/builders/mac/MacAppImageBuilder.java	Tue Oct 09 18:29:53 2018 -0400
@@ -457,8 +457,14 @@
         // copy library
         Path runtimeMacOSDir = Files.createDirectories(
                 runtimeDir.resolve("Contents/MacOS"));
-        Files.copy(runtimeRoot.resolve("lib/jli/libjli.dylib"),
-                runtimeMacOSDir.resolve("libjli.dylib"));
+
+        // JDK 9, 10, and 11 have extra '/jli/' subdir
+        Path jli = runtimeRoot.resolve("lib/libjli.dylib");
+        if (!Files.exists(jli)) {
+            jli = runtimeRoot.resolve("lib/jli/libjli.dylib");
+        }
+
+        Files.copy(jli, runtimeMacOSDir.resolve("libjli.dylib"));
     }
 
     private void sign() throws IOException {
--- a/src/jdk.packager/macosx/native/launcher/main.m	Tue Oct 09 17:50:26 2018 -0400
+++ b/src/jdk.packager/macosx/native/launcher/main.m	Tue Oct 09 18:29:53 2018 -0400
@@ -51,17 +51,21 @@
         }
 
         if (library != NULL) {
-            start_launcher start = (start_launcher)dlsym(library, "start_launcher");
-            stop_launcher stop = (stop_launcher)dlsym(library, "stop_launcher");
+            start_launcher start =
+                    (start_launcher)dlsym(library, "start_launcher");
+            stop_launcher stop =
+                    (stop_launcher)dlsym(library, "stop_launcher");
 
-            if (start(argc, argv) == true) {
-                result = 0;
-
-                if (stop != NULL) {
+            if (start != NULL && stop != NULL) {
+                if (start(argc, argv) == true) {
+                    result = 0;
                     stop();
                 }
+            } else if (start == NULL) {
+                NSLog(@"start_launcher not found in %@.\n", libraryName);
+            } else {
+                NSLog(@"stop_launcher not found in %@.\n", libraryName);
             }
-
             dlclose(library);
         }
     } @catch (NSException *exception) {
--- a/src/jdk.packager/macosx/native/library/MacPlatform.mm	Tue Oct 09 17:50:26 2018 -0400
+++ b/src/jdk.packager/macosx/native/library/MacPlatform.mm	Tue Oct 09 18:29:53 2018 -0400
@@ -179,12 +179,17 @@
 TString MacPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) {
     TString result;
 
-    result = FilePath::IncludeTrailingSeparater(RuntimePath) + _T("Contents/Home/jre/lib/jli/libjli.dylib");
+    // first try lib/, then lib/jli
+    result = FilePath::IncludeTrailingSeparater(RuntimePath) +
+             _T("Contents/Home/lib/libjli.dylib");
 
     if (FilePath::FileExists(result) == false) {
-        result = FilePath::IncludeTrailingSeparater(RuntimePath) + _T("Contents/Home/lib/jli/libjli.dylib");
+        result = FilePath::IncludeTrailingSeparater(RuntimePath) +
+                 _T("Contents/Home/lib/jli/libjli.dylib");
 
         if (FilePath::FileExists(result) == false) {
+            // cannot find
+            NSLog(@"Cannot find libjli.dysym!");
             result = _T("");
         }
     }
--- a/src/jdk.packager/share/native/library/common/LinuxPlatform.cpp	Tue Oct 09 17:50:26 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/LinuxPlatform.cpp	Tue Oct 09 18:29:53 2018 -0400
@@ -130,11 +130,14 @@
 
 TString LinuxPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) {
     TString result = FilePath::IncludeTrailingSeparater(RuntimePath) +
-        "lib/jli/libjli.so";
+        "lib/libjli.so";
 
     if (FilePath::FileExists(result) == false) {
         result = FilePath::IncludeTrailingSeparater(RuntimePath) +
             "lib/jli/libjli.so";
+        if (FilePath::FileExists(result) == false) {
+            printf("Cannot find libjli.so!");
+        }
     }
 
     return result;
--- a/src/jdk.packager/share/native/library/common/main.cpp	Tue Oct 09 17:50:26 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/main.cpp	Tue Oct 09 18:29:53 2018 -0400
@@ -68,13 +68,9 @@
     BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
         return true;
     }
+#endif //WINDOWS
 
-    __declspec(dllexport)
-#endif //WINDOWS
-#ifdef LINUX
-    __attribute__((externally_visible,visibility("default")))
-#endif //LINUX
-    bool start_launcher(int argc, TCHAR* argv[]) {
+    JNIEXPORT bool start_launcher(int argc, TCHAR* argv[]) {
         bool result = false;
         bool parentProcess = true;
 
@@ -208,12 +204,6 @@
         return result;
     }
 
-#ifdef WINDOWS
-    __declspec(dllexport)
-#endif //WINDOWS
-#ifdef LINUX
-    __attribute__((externally_visible,visibility("default")))
-#endif //LINUX
-    void stop_launcher() {
+    JNIEXPORT void stop_launcher() {
     }
 }