dougxc / jdk

GNU General Public License v2.0
0 stars 0 forks source link

add CopyFilesPlugin jlink plugin #2

Open dougxc opened 2 years ago

dougxc commented 2 years ago

Javadoc for CopyFilesPlugin:

/**
 * Jlink plugin to copy files in the current runtime image into the output image.
 * The files to copy are specified in {@code <java.home>/conf/jlink.copyfiles}.
 * There is one file specified per line with its path relative to the image root
 * (e.g., lib/server/libjvm.so).
 */

For GraalVM, this means on linux, we'd generate conf/jlink.copyfiles to contain:

lib/libjvmcicompiler.so

It could also be used to copy across everything in the language/ directory if we wanted.

AlanBateman commented 2 years ago

This is an unusual plugin and not intuitive to specify "--copy-files" without a value. So if it does move forward as is then we should seek out a better name.

At a high-level, the jlink tool produces a run-time image from a set modules. The desire here seems to be to overlay, or copy, files that aren't part of any module into the run-time image. If this replaces files that are in a module then it suggests the need for a jlink --patch-module option, something that hasn't been needed to date. Another part seems to be the desire to persist the list of files that are copied so that it can be used again when the resulting run-time image is used to stamp out another run-time image. So I think the main question is whether adding this feature make sense or not. If it doesn't make sense then how hard would be for these other files to be packaged into a module so that they can participate in the normal jlink process? Is it mostly that libjvmcicompiler.so is huge and retaining the packaged modules double the space?

As regards the details then ${java.home}/conf/jlink.copyfiles feels like an attractive nuisance. Maybe this could be resource that is generated at link time into a resource (like jdk/internal/vm/options) so it can't be edited. Could the initial copy be explicit so that it is clear from the initial jlink command what is going on? By this I mean, could the list of files to copy be specified to the option with something like this:

--copy-files lib/libjvmcicompiler.so=/graal/libs/libjvmcicompiler.so,lib/truffle.jar=/graal/libs/truffle.jar
dougxc commented 2 years ago

This is an unusual plugin and not intuitive to specify "--copy-files" without a value. So if it does move forward as is then we should seek out a better name.

How about --enable-copy-files? It would be disabled with --disable-plugin option.

Maybe this could be resource that is generated at link time into a resource

For completeness, this is the workflow we want when building GraalVM:

  1. Create a base GraalVM image using jlink.
  2. Use that base image to run Native Image and create libjvmcicompiler.so.
  3. Create a final GraalVM image by copying the base image and overlaying it with libjvmcicompiler.so. We do not want to have to use jlink for this step as it's very slow. Furthermore, we don't to pay the footprint of libjvmcicompiler.so twice, once in lib/libjvmcicompiler.so and again packaged in a jmod file. This approach is incompatible with the suggested--copy-files command line option since libjvmcicompiler.so does not yet exist when creating the base image.
  4. Have jlink in the final GraalVM image propagate libjvmcicompiler.so without any extra jlink options.