Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jlink requires additional module since GraalVM 22.3.0 #7064

Closed
ganadist opened this issue Jul 26, 2023 · 11 comments
Closed

jlink requires additional module since GraalVM 22.3.0 #7064

ganadist opened this issue Jul 26, 2023 · 11 comments
Assignees
Labels

Comments

@ganadist
Copy link

Describe the issue
A clear and concise description of the issue. We recommend using the latest snapshot builds to replicate the issue as bugs are constantly being fixed in the master branch

Steps to reproduce the issue
Please include both build steps as well as run steps

$ git clone https://github.com/ganadist/VersionCodeDemo -b graalvm_jlink
$ cd VersionCodeDemo

$ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
$ $JAVA_HOME/bin/java -version
openjdk 17.0.8 2023-07-18
OpenJDK Runtime Environment (build 17.0.8+7)
OpenJDK 64-Bit Server VM (build 17.0.8+7, mixed mode)

$ ./gradlew clean :app:assembleDebug --no-build-cache
BUILD SUCCESSFUL in 5s

$ export JAVA_HOME=/usr/lib/jvm/graalvm-ce-java17-22.2.0
$ $JAVA_HOME/bin/java -version
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06)
OpenJDK 64-Bit Server VM GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06, mixed mode, sharing)

$ ./gradlew clean :app:assembleDebug --no-build-cache
BUILD SUCCESSFUL in 901ms

$ export JAVA_HOME=/usr/lib/jvm/graalvm-ce-java17-22.3.0
$ $JAVA_HOME/bin/java -version
openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing)

$ ./gradlew clean :app:assembleDebug --no-build-cache
> Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':app:androidJdkImage'.
   > Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JdkImageTransform: /home/ganadist/Library/Android/sdk/platforms/android-33/core-for-system-modules.jar.
         > Error while executing process /usr/lib/jvm/graalvm-ce-java17-22.3.0/bin/jlink with arguments {--module-path /home/ganadist/.gradle/caches/transforms-3/eccdbd91038de66e1213c7a7da63a393/transformed/output/temp/jmod --add-modules java.base --output /home/ganadist/.gradle/caches/transforms-3/eccdbd91038de66e1213c7a7da63a393/transformed/output/jdkImage --disable-plugin system-modules}

$ export JAVA_HOME=/usr/lib/jvm/graalvm-community-openjdk-17.0.7+4.1
$ openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment GraalVM CE 17.0.7-dev+4.1 (build 17.0.7+4-jvmci-23.1-b02)
OpenJDK 64-Bit Server VM GraalVM CE 17.0.7-dev+4.1 (build 17.0.7+4-jvmci-23.1-b02, mixed mode, sharing)

$ ./gradlew clean :app:assembleDebug --no-build-cache
> Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':app:androidJdkImage'.
   > Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JdkImageTransform: /home/ganadist/Library/Android/sdk/platforms/android-33/core-for-system-modules.jar.
         > Error while executing process /usr/lib/jvm/graalvm-community-openjdk-17.0.7+4.1/bin/jlink with arguments {--module-path /home/ganadist/.gradle/caches/transforms-3/4219e5d8ce414f8e06176bc50768acc4/transformed/output/temp/jmod --add-modules java.base --output /home/ganadist/.gradle/caches/transforms-3/4219e5d8ce414f8e06176bc50768acc4/transformed/output/jdkImage --disable-plugin system-modules}


Describe GraalVM and your environment:

  • GraalVM version (latest snapshot builds can be found here), or commit id if built from source: [e.g. EE 19.3, CE 20.0, CE 20.1.0-dev-20200304_0848]
    • CE 22.3, CE 23.0, CE 23.1-dev
  • JDK major version: 17
  • OS: Linux, MacOS
  • Architecture: AMD64, AARCH64

More details
jlink is invoked by Android Gradle Plugin from JdkImageTransformDelegate

Until Graalvm 22.2.0, it worked properly, but since Graalvm 22.3.0, jlink is not working properly.

When I tried to invoke jlink manually, I can see following error.

/Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.0/Contents/Home/bin/jlink \
  --module-path /Users/ganadist/.gradle/caches/transforms-3/0ada5dc945506ea0165a07b88bb0fadf/transformed/output/temp/jmod \
  --add-modules java.base \
  --output /Users/ganadist/.gradle/caches/transforms-3/0ada5dc945506ea0165a07b88bb0fadf/transformed/output/jdkImage \
  --disable-plugin system-modules
Error: Module [jdk.internal.vm.ci](http://jdk.internal.vm.ci/) not found
java.lang.module.FindException: Module [jdk.internal.vm.ci](http://jdk.internal.vm.ci/) not found
        at java.base/java.lang.module.Resolver.findFail(Resolver.java:893)
        at java.base/java.lang.module.Resolver.resolve(Resolver.java:129)
        at java.base/java.lang.module.Configuration.resolve(Configuration.java:421)
        at java.base/java.lang.module.Configuration.resolve(Configuration.java:255)
        at jdk.jlink/jdk.tools.jlink.internal.Jlink$JlinkConfiguration.resolve(Jlink.java:217)
        at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImageProvider(JlinkTask.java:551)
        at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImage(JlinkTask.java:439)
        at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.run(JlinkTask.java:291)
        at jdk.jlink/jdk.tools.jlink.internal.Main.run(Main.java:55)
        at jdk.jlink/jdk.tools.jlink.internal.Main.main(Main.java:33)```
@ganadist ganadist added the bug label Jul 26, 2023
@ganadist ganadist changed the title jlink failed since GraalVM 22.3.0 jlink requires additional module since GraalVM 22.3.0 Jul 26, 2023
@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Aug 7, 2023
@oubidar-Abderrahim
Copy link
Member

Thank you for reporting this, we'll take a look into it shortly

@oubidar-Abderrahim
Copy link
Member

Is it possible to isolate a reproducer that doesn't require Android SDK?

@ganadist
Copy link
Author

ganadist commented Aug 9, 2023

@oubidar-Abderrahim

Thank you for your interest.

I added standalone reproducer at same branch ( graalvm_jlink : 08198c8f5 )

$ git clone https://github.com/ganadist/VersionCodeDemo -b graalvm_jlink
$ cd VersionCodeDemo/standalone
$ env JAVA_HOME=/usr/lib/jvm/java-17-openjdk ./test.sh
openjdk version "17.0.8" 2023-07-18
OpenJDK Runtime Environment (build 17.0.8+7)
OpenJDK 64-Bit Server VM (build 17.0.8+7, mixed mode)
./jdkImage:
total 8
drwxr-xr-x 2 ganadist users 4096 Aug 10 00:31 lib
-rw-r--r-- 1 ganadist users   38 Aug 10 00:31 release

./jdkImage/lib:
total 3556
-rw-r--r-- 1 ganadist users 3639350 Aug 10 00:31 modules
$ env JAVA_HOME=/usr/lib/jvm/graalvm-ce-java17-22.2.0 ./test.sh
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06)
OpenJDK 64-Bit Server VM GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06, mixed mode, sharing)
./jdkImage:
total 8
drwxr-xr-x 2 ganadist users 4096 Aug 10 00:31 lib
-rw-r--r-- 1 ganadist users   38 Aug 10 00:31 release

./jdkImage/lib:
total 3556
-rw-r--r-- 1 ganadist users 3639350 Aug 10 00:31 modules
$ env JAVA_HOME=/usr/lib/jvm/graalvm-ce-java17-22.3.2 ./test.sh
openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment GraalVM CE 22.3.2 (build 17.0.7+7-jvmci-22.3-b18)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.2 (build 17.0.7+7-jvmci-22.3-b18, mixed mode, sharing)
Error: Module jdk.internal.vm.ci not found
java.lang.module.FindException: Module jdk.internal.vm.ci not found
	at java.base/java.lang.module.Resolver.findFail(Resolver.java:893)
	at java.base/java.lang.module.Resolver.resolve(Resolver.java:129)
	at java.base/java.lang.module.Configuration.resolve(Configuration.java:421)
	at java.base/java.lang.module.Configuration.resolve(Configuration.java:255)
	at jdk.jlink/jdk.tools.jlink.internal.Jlink$JlinkConfiguration.resolve(Jlink.java:217)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImageProvider(JlinkTask.java:551)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImage(JlinkTask.java:439)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.run(JlinkTask.java:291)
	at jdk.jlink/jdk.tools.jlink.internal.Main.run(Main.java:55)
	at jdk.jlink/jdk.tools.jlink.internal.Main.main(Main.java:33)

Note : standalone/jmod/java.base.jmod is intermediates output from Android Sdk

@ganadist
Copy link
Author

ganadist commented Aug 11, 2023

@oubidar-Abderrahim
Copy link
Member

Tracked internally on GR 48003

@dougxc
Copy link
Member

dougxc commented Aug 17, 2023

As of GraalVM 22.3, jlink in Graalvm ensures that a jlink'ed image automatically includes libgraal. This is done by persisting certain jlink options, including the --add-modules=jdk.internal.vm.ci option you point out above. These options are persisted in /modules/jdk.jlink/jdk/tools/jlink/internal/options in the JDK image. You can see this with jshell:

jshell> java.nio.file.Files.readString(FileSystems.newFileSystem(URI.create("jrt:/"), java.util.Collections.emptyMap()).getPath("/modules/jdk.jlink/jdk/tools/jlink/internal/options"))
$1 ==> "--add-modules=jdk.internal.vm.ci\n--add-options=\"-XX:ThreadPriorityPolicy=1 -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCIProduct -XX:-UnlockExperimentalVMOptions\"\n--vendor-version=\"Oracle GraalVM 21-dev+34.1\""

Since it appears as though you are modifying java.base in your build process, you can remove these extra jlink options. Or you could create an empty jdk.internal.vm.ci module.

@oubidar-Abderrahim oubidar-Abderrahim assigned dougxc and unassigned dougxc Aug 17, 2023
@oubidar-Abderrahim oubidar-Abderrahim removed their assignment Aug 17, 2023
@ganadist
Copy link
Author

@dougxc
Thank you for your advices.

you can remove these extra jlink options.

I tried to add empty /modules/jdk.jlink/jdk/tools/jlink/internal/options into modified java.base module, but it still failed to find jdk.internal.vm.ci module.

$ mkdir -p temp/modules/jdk.jlink/jdk/tools/jlink/internal/
$ touch temp/modules/jdk.jlink/jdk/tools/jlink/internal/options
$ jar cf jar cf jlink_option.jar -C temp

$ jmod create --module-version 17.0.7 --target-platform LINUX-OTHER --class-path ./android-33/core-for-system-modules.jar:jlink_option.jar:./module-description ./jmod/java.base.jmod
Warning: ignoring duplicate entry META-INF/MANIFEST.MF, in section CLASSES

$ jlink -v --module-path ./jmod --add-modules java.base --output ./jdkImage --disable-plugin system-modules
Error: Module jdk.internal.vm.ci not found

Or you could create an empty jdk.internal.vm.ci module.

I tried to create module-info.class for empty jdk.internal.vm.ci module with --system=none option.
But, it is impossible to create module-info.class

$ cat module-info.java
module jdk.internal.vm.ci {
}

$ javac --system=none --patch-module=java.base=standalone/android-33/core-for-system-modules.jar  module-info.java
Fatal Error: Unable to find package java.lang in classpath or bootclasspath

@dougxc
Copy link
Member

dougxc commented Sep 10, 2023

I tried to add empty /modules/jdk.jlink/jdk/tools/jlink/internal/options into modified java.base module

You're updating the wrong module. As implied by the prefix "/modules/jdk.jlink", jdk/tools/jlink/internal/options is a resource in the jdk.jlink module, not the java.base module.

@dougxc
Copy link
Member

dougxc commented Jan 23, 2024

I assume the above tip resolved the problem. Feel free to re-open this issue with extra details if not.

@dougxc dougxc closed this as completed Jan 23, 2024
@binarynoise
Copy link

Hi,
I think I have the same issue. My Gradle build fails with the same error and running the jlink manually also shows the same error.
As jlink is run through Gradle, I have no control over the call parameters.

I tried to create the empty module but as ganadist didn't write what worked for them in the end, I couldn't follow. I guess the javac command at the end would need to be adapted to use the right modules and paths.

Would you be so kind and provide the working command?

To implement a fix rather than a workaround like this, would it make sense to raise an issue at Google, so they include that (empty) module by default in their android libraries?
Or for graal to add a fallback in case that module doesn't exist?

java --version
openjdk 17.0.8 2023-07-18
OpenJDK Runtime Environment GraalVM CE 17.0.8+7.1 (build 17.0.8+7-jvmci-23.0-b15)
OpenJDK 64-Bit Server VM GraalVM CE 17.0.8+7.1 (build 17.0.8+7-jvmci-23.0-b15, mixed mode, sharing)

@denzap
Copy link

denzap commented Oct 23, 2024

Have the same issue as binarynoise with android gradle build

java --version
openjdk 21.0.2 2024-01-16
OpenJDK Runtime Environment GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30)
OpenJDK 64-Bit Server VM GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30, mixed mode, sharing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants