Skip to content

native-image shell script requires a modded JDK to work. #2502

@zakkak

Description

@zakkak

Describe the issue
When building Graal bits for use with openJDK, native-image needs to pass the following arguments to the jvm --upgrade-module-path ${location}/../../jvmci/graal.jar --add-modules "org.graalvm.truffle,org.graalvm.sdk" --module-path ${location}/../../truffle/truffle-api.jar:${location}/../../jvmci/graal-sdk.jar and -J--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler to native-image.

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

curl -sL https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases/download/jdk-11.0.9%2B2/OpenJDK11U-jdk_x64_linux_11.0.9_2_ea.tar.gz -o jdk.tar.gz
curl -sL https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases/download/jdk-11.0.9%2B2/OpenJDK11U-static-libs_x64_linux_11.0.9_2_ea.tar.gz -o jdk-static-libs.tar.gz
mkdir -p openjdk
tar xf jdk.tar.gz -C openjdk --strip-components=1
tar xf jdk-static-libs.tar.gz -C openjdk --strip-components=1
export JAVA_HOME=$(pwd)/openjdk
git clone --depth 1 https://github.com/oracle/graal
pushd graal/substratevm
mx --components="Native Image" build
popd

export GRAAL_REPO=./graal
export MANDREL_JDK=./mandrel

cp -r ${JAVA_HOME} ${MANDREL_JDK}

mkdir ${MANDREL_JDK}/lib/svm
cp ${GRAAL_REPO}/substratevm/mxbuild/dists/jdk1.8/library-support.jar ${MANDREL_JDK}/lib/svm

mkdir ${MANDREL_JDK}/lib/svm/builder
cp ${GRAAL_REPO}/substratevm/mxbuild/dists/jdk11/{svm,pointsto}.jar ${MANDREL_JDK}/lib/svm/builder
cp ${GRAAL_REPO}/substratevm/mxbuild/dists/jdk1.8/objectfile.jar ${MANDREL_JDK}/lib/svm/builder

mkdir ${MANDREL_JDK}/languages
cp ${GRAAL_REPO}/truffle/mxbuild/dists/jdk11/truffle-nfi.jar ${MANDREL_JDK}/languages

mkdir ${MANDREL_JDK}/lib/graalvm
cp ${GRAAL_REPO}/substratevm/mxbuild/dists/jdk1.8/svm-driver.jar ${MANDREL_JDK}/lib/graalvm

mkdir ${MANDREL_JDK}/lib/jvmci
cp ${GRAAL_REPO}/sdk/mxbuild/dists/jdk11/graal-sdk.jar ${MANDREL_JDK}/lib/jvmci
cp ${GRAAL_REPO}/compiler/mxbuild/dists/jdk11/graal.jar ${MANDREL_JDK}/lib/jvmci

mkdir ${MANDREL_JDK}/lib/truffle
cp ${GRAAL_REPO}/truffle/mxbuild/dists/jdk11/truffle-api.jar ${MANDREL_JDK}/lib/truffle

mkdir -p ${MANDREL_JDK}/lib/svm/clibraries/linux-amd64/include
cp ${GRAAL_REPO}/substratevm/src/com.oracle.svm.native.libchelper/include/amd64cpufeatures.h ${MANDREL_JDK}/lib/svm/clibraries/linux-amd64/incl
ude
cp ${GRAAL_REPO}/substratevm/src/com.oracle.svm.native.libchelper/include/aarch64cpufeatures.h ${MANDREL_JDK}/lib/svm/clibraries/linux-amd64/in
clude
cp ${GRAAL_REPO}/substratevm/src/com.oracle.svm.libffi/include/svm_libffi.h ${MANDREL_JDK}/lib/svm/clibraries/linux-amd64/include
cp ${GRAAL_REPO}/truffle/src/com.oracle.truffle.nfi.native/include/trufflenfi.h ${MANDREL_JDK}/lib/svm/clibraries/linux-amd64/include
cp ${GRAAL_REPO}/substratevm/mxbuild/linux-amd64/src/com.oracle.svm.native.libchelper/amd64/liblibchelper.a ${MANDREL_JDK}/lib/svm/clibraries/l
inux-amd64
cp ${GRAAL_REPO}/substratevm/mxbuild/linux-amd64/src/com.oracle.svm.native.jvm.posix/amd64/libjvm.a ${MANDREL_JDK}/lib/svm/clibraries/linux-amd
64

mkdir ${MANDREL_JDK}/lib/svm/bin
cp ${GRAAL_REPO}/sdk/mxbuild/linux-amd64/native-image.image-bash/native-image ${MANDREL_JDK}/lib/svm/bin/native-image

ln -s ../lib/svm/bin/native-image ${MANDREL_JDK}/bin/native-image

./mandrel/bin/native-image -version

Note that the cp commands just copy graalvm bits in the openjdk filesystem adding them where native-image expects to find them.

Describe GraalVM and your environment:

  • GraalVM version: 16a2a12
  • JDK major version: 11
  • OS: Linux
  • Architecture: AMD64

More details

./mandrelJDK/bin/native-image --native-image-info --verbose HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: org/graalvm/word/UnsignedWord
        at com.oracle.svm.driver.NativeImage.getPlatform(NativeImage.java:104)
        at com.oracle.svm.driver.NativeImage.<clinit>(NativeImage.java:101)
        at com.oracle.svm.driver.NativeImage$JDK9Plus.main(NativeImage.java:1753)
Caused by: java.lang.ClassNotFoundException: org.graalvm.word.UnsignedWord
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 3 more

Applying the following patch to ./mandrelJDK/lib/svm/bin/native-image makes it work.

diff --git a/graal/sdk/mxbuild/linux-amd64/native-image.image-bash/native-image b/mandrel/lib/svm/bin/native-image
index 992d85b..11d365a 100755
--- a/graal/sdk/mxbuild/linux-amd64/native-image.image-bash/native-image
+++ b/mandrel/lib/svm/bin/native-image
@@ -108,4 +108,4 @@ if [[ "${VERBOSE_GRAALVM_LAUNCHERS}" == "true" ]]; then
     set -x
 fi
 
-exec "${location}/../../../bin/java" --add-exports=java.base/jdk.internal.module=ALL-UNNAMED -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI "${jvm_args[@]}" -cp "${cp}" 'com.oracle.svm.driver.NativeImage$JDK9Plus' "${launcher_args[@]}"
+exec "${location}/../../../bin/java" --upgrade-module-path ${location}/../../jvmci/graal.jar --add-modules "org.graalvm.truffle,org.graalvm.sdk" --module-path ${location}/../../truffle/truffle-api.jar:${location}/../../jvmci/graal-sdk.jar --add-exports=java.base/jdk.internal.module=ALL-UNNAMED -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI "${jvm_args[@]}" -cp "${cp}" 'com.oracle.svm.driver.NativeImage$JDK9Plus' -J--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler "${launcher_args[@]}"

Results after patch:

$ ./mandrel/bin/native-image HelloWorld                                
[helloworld:238051]    classlist:   1,176.86 ms,  1.00 GB
[helloworld:238051]        (cap):     627.54 ms,  1.00 GB
[helloworld:238051]        setup:   1,760.69 ms,  1.58 GB
[helloworld:238051]     (clinit):     222.38 ms,  1.92 GB
[helloworld:238051]   (typeflow):   4,243.92 ms,  1.92 GB
[helloworld:238051]    (objects):   3,886.14 ms,  1.92 GB
[helloworld:238051]   (features):     219.58 ms,  1.92 GB
[helloworld:238051]     analysis:   8,828.33 ms,  1.92 GB
[helloworld:238051]     universe:     319.31 ms,  1.92 GB
[helloworld:238051]      (parse):     922.83 ms,  1.92 GB
[helloworld:238051]     (inline):   1,381.27 ms,  2.42 GB
[helloworld:238051]    (compile):   7,252.56 ms,  2.42 GB
[helloworld:238051]      compile:   9,986.78 ms,  2.42 GB
[helloworld:238051]        image:   1,291.74 ms,  2.42 GB
[helloworld:238051]        write:     156.78 ms,  2.42 GB
[helloworld:238051]      [total]:  23,738.09 ms,  2.42 GB

$ ./helloworld 
Hello world!!!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions