On Sat, 2 Nov 2024 01:05:27 GMT, Jiangli Zhou <jian...@openjdk.org> wrote:
> > > I finally noticed that you are testing a precompiled HelloWorld class, > > > and I have been running with a source file argument to have java compile > > > it on the fly. > > > When I try using a pre-compiled HelloWorld, the linux port works for me > > > too. > > > @jianglizhou Can you please verify if you can run this with a .java file > > > directly? To be clear: this works fine on my mac with this PR, and (as I > > > said), I'm pretty certain it used to work at least at some point during > > > development on this PR. > > > ``` > > > ihse@sthihse:/localhome/git/jdk-ALT$ cat > HelloWorld.java > > > public class HelloWorld { > > > public static void main(String[] args) { > > > System.out.println("Hello, world!"); > > > } > > > } > > > ihse@sthihse:/localhome/git/jdk-ALT$ javac HelloWorld.java > > > ihse@sthihse:/localhome/git/jdk-ALT$ > > > ./build/linux-x64/images/static-jdk/bin/java HelloWorld > > > Hello, world! > > > ihse@sthihse:/localhome/git/jdk-ALT$ > > > ./build/linux-x64/images/static-jdk/bin/java HelloWorld.java > > > Error: Unable to load main class > > > com.sun.tools.javac.launcher.SourceLauncher in module jdk.compiler > > > Caused by: java.lang.UnsatisfiedLinkError: no jimage in system library > > > path: /localhome/git/jdk-ALT/build/linux-x64/images/static-jdk/bin > > > Runtime.exit(1) logging failed: Could not initialize class > > > jdk.internal.module.SystemModuleFinders$SystemImage > > > ihse@sthihse:/localhome/git/jdk-ALT$ > > > ``` > > > > > > I can reproduce the issue with running a `.java` directly using > > static-jdk/bin/java built from your branch. The issue does not exist with > > the `bin/javastatic` built from > > https://github.com/openjdk/leyden/tree/hermetic-java-runtime (I just > > tested). I have a hunch of where is problem might be. I'll do some > > debugging. > > ``` > > $ bin/java /usr/local/google/home/jianglizhou/tests/HelloWorld.java > > Error: Unable to load main class > > com.sun.tools.javac.launcher.SourceLauncher in module jdk.compiler > > Caused by: java.lang.UnsatisfiedLinkError: no jimage in system library > > path: > > /usr/local/google/home/jianglizhou/github/jdk_pull_20837/build/linux-x86_64-server-slowdebug/images/static-jdk/bin > > Runtime.exit(1) logging failed: Could not initialize class > > jdk.internal.module.SystemModuleFinders$SystemImage > > ``` > > Ok, I've found the cause. It's because `<jdk_build_path>/static-jdk/bin` > instead of `<jdk_build_path>/static-jdk/lib` is set as the > `_sun_boot_library_path` by `Arguments::set_dll_dir()`, during > `os::init_system_properties_values()`. The path is retrieved via > `StaticProperty.sunBootLibraryPath()` and used by `ClassLoader.loadLibrary()` > to locate `jimage`. Hence the failure. > > Looking at why it only fails with running with `.java` but not with `.class`, > a quick looks shows me that the following call path is only taken when > running with `.java`: > > ``` > at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2410) > at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:927) > at java.base/java.lang.System.loadLibrary(System.java:2078) > at > java.base/jdk.internal.jimage.NativeImageBuffer$1.run(NativeImageBuffer.java:43) > at > java.base/jdk.internal.jimage.NativeImageBuffer$1.run(NativeImageBuffer.java:40) > at > java.base/java.security.AccessController.doPrivileged(AccessController.java:319) > at > java.base/jdk.internal.jimage.NativeImageBuffer.<clinit>(NativeImageBuffer.java:39) > at > java.base/jdk.internal.jimage.BasicImageReader.<init>(BasicImageReader.java:97) > at > java.base/jdk.internal.jimage.ImageReader$SharedImageReader.<init>(ImageReader.java:229) > at > java.base/jdk.internal.jimage.ImageReader$SharedImageReader.open(ImageReader.java:243) > at java.base/jdk.internal.jimage.ImageReader.open(ImageReader.java:67) > at java.base/jdk.internal.jimage.ImageReader.open(ImageReader.java:71) > at > java.base/jdk.internal.jimage.ImageReaderFactory$1.apply(ImageReaderFactory.java:70) > at > java.base/jdk.internal.jimage.ImageReaderFactory$1.apply(ImageReaderFactory.java:67) > at > java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1714) > at > java.base/jdk.internal.jimage.ImageReaderFactory.get(ImageReaderFactory.java:61) > at > java.base/jdk.internal.jimage.ImageReaderFactory.getImageReader(ImageReaderFactory.java:85) > at > java.base/jdk.internal.module.SystemModuleFinders$SystemImage.<clinit>(SystemModuleFinders.java:385) > at > java.base/jdk.internal.module.SystemModuleFinders$SystemModuleReader.findImageLocation(SystemModuleFinders.java:429) > at > java.base/jdk.internal.module.SystemModuleFinders$SystemModuleReader.read(SystemModuleFinders.java:483) > at > java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:809) > at > java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:741) > at > java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:621) > at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:640) > at java.base/java.lang.Class.forName(Class.java:673) > at java.base/java.lang.Class.forName(Class.java:648) > at > java.base/sun.launcher.LauncherHelper.loadModuleMainClass(LauncherHelper.java:798) > at > java.base/sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:733) > ``` > > I'm going to look into a fix and update in this comment thread. > > While investigating, I also just found there a new issue in > https://github.com/openjdk/leyden/tree/hermetic-java-runtime. Let's focus on > resolving the `.java` run issue with your PR to make progress first. With further debugging I found the problem is actually due to failing to load `jimage` as a **built-in** native library. And, that's because `DEF_STATIC_JNI_OnLoad` is missing from jimage.cpp, see change in https://github.com/openjdk/leyden/blob/3cfd92bfcc6e54377fc2cd4004c926db6aa5e16e/src/java.base/share/native/libjimage/jimage.cpp#L44. I'm going to create a bug to fix the missing `DEF_STATIC_JNI_OnLoad` in the mainline now. With your PR, `libjimage.so` is statically linked into `static-jdk/bin/java`. As a result there is no `lib/libjimage.so`. So the `_sun_boot_library_path` issue that I pointed out earlier is not the direct cause of the failure. I don't think we need to address that in your PR. We can fix it later. I think we would need to decide what is the `dll_dir` with the static JDK support and hermetic support. While debugging the issue, I found debugging symbols do not work for `static-jdk/bin/java`. There is no `static-jdk/bin/java.debuginfo`. I do see there's a `./support/static-native/launcher/java.debuginfo`. Please fix the debugging symbol issue in your PR. Reading symbols from images/static-jdk/bin/java... (No debugging symbols found in images/static-jdk/bin/java) (gdb) ------------- PR Comment: https://git.openjdk.org/jdk/pull/20837#issuecomment-2453298940