RFR: 8339332: Clean up the java launcher code

Jaikiran Pai jpai at openjdk.org
Thu Sep 12 05:30:42 UTC 2024


Can I please get a review of this change which cleans up the code in the `java` launcher? The original motivation for the change was to prevent the `java` launcher's C code from parsing a jar's manifest when launching an application through `java -jar foo.jar`. The jar parsing code in C currently doesn't have the same level of robustness and features as what's available in the Java side implementation of `Zip/JarFile` API in `java.util.zip`. Among them, one is the lack of ZIP64 support in the launcher's jar parsing code. That issue was noticed in https://bugs.openjdk.org/browse/JDK-8328995 and a PR (https://github.com/openjdk/jdk/pull/18479) was proposed to enhance this C code in the launcher to support ZIP64 jar files. Even before the proposed changes in that PR, there already were a few concerns about long term maintainability of the jar parsing code in the launcher given that it duplicates what we already do in the Java side implementation, so adding new C code here isn't preferab
 le.

The change in this current PR removes the part where the launcher's C code was parsing the jar's manifest file to identify "Main-Class" and "SplashScreen-Image" attributes from the manifest of the jar that was being launched. This was being done in the C code to support a long outdated "JRE selection" feature (mJRE https://bugs.openjdk.org/browse/JDK-8058407) which required it to parse the jar's manifest. After that feature was removed, the sole reason the jar's manifest was continued to be parsed in this launcher code was for convenience.

With the changes proposed in this PR, the launcher will use the jar parsing C code only if the jar has a "SplashScreen-Image" in its manifest. The number of such jars, based on an experiment against a large corpus of jar files, is very minimal (we found just 26 jars in around 900K odd jar files with a "SplashScreen-Image"). The updated code in this PR also delegates the identification of the "SplashScreen-Image" attribute to the java code (in `LauncherHelper`) thus removing the need to parse the manifest in C code. The only time the C code will now do the jar parsing is to display a splash screen image (if any is present) from the jar file. I think even that can be avoided, but I haven't experimented with it and I would like to pursue that separately in future, instead of this PR.

Finally, a few of the utility functions that were introduced in the launcher C code in a recent JEP to support "Implicitly Declared Classes and Instance Main Methods" have been instead moved into the Java code (in `LauncherHelper`) to simplify the launcher.

With these changes, tier testing of tier1 through tier8 has passed without issues. A new jtreg test has been added in this PR which reproduces the issue noted in https://bugs.openjdk.org/browse/JDK-8328995 and verifies the fix.

-------------

Commit messages:
 - comment cleanup
 - move ShowSplashScreen() to PostJVMInit()
 - 8339332: Clean up the java launcher code
 - 8328995: add a test case for launching a ZIP64 executable jar

Changes: https://git.openjdk.org/jdk/pull/20929/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20929&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8339332
  Stats: 991 lines in 11 files changed: 415 ins; 457 del; 119 mod
  Patch: https://git.openjdk.org/jdk/pull/20929.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/20929/head:pull/20929

PR: https://git.openjdk.org/jdk/pull/20929


More information about the core-libs-dev mailing list