How to build libgraal for latest JDK (in theory)

Vladimir Kozlov vladimir.kozlov at oracle.com
Wed Aug 26 01:43:03 UTC 2020


Hi,

There was this question few months ago and I did not answered because it was "complicated" then and it still is.

I just updated Metropolis repo to JDK 15 and build libgraal for it. So I decided share the process.

But first, if you want to try libgraal - use GraalVM CE [1] which is more stable and more tested.

There are Java 8 and Java 11 based GraalVM releases. They use libgraal by default and based on latest Graal sources.

Back to Metropolis. The main complication is that libgraal build requires several components to be in sync: JDK 
libraries (Java API), Graal, SubstrateVM and JVMCI. But because GraalVM development is concentrated mostly on LTS JDK 
releases (8 and 11) it has issues building with latest JDK (SVM is "good" example). So you may need to apply few patches 
there and there which greatly complicate the process.

In theory current process of building libgraal with latest JDK is next (linux-x64 only):

1. Clone mx, graal, JDK:

git clone git at github.com:graalvm/mx.git
git clone git at github.com:oracle/graal.git
git clone git at github.com:openjdk/jdk.git

2. Set environment.

  - make sure the same C++ is used to build JDK and libgraal (use PATH to point compiler)
  - add your /<my_dir>/mx/ to PATH

3. Build your JDK and set JAVA_HOME

cd /<my_dir>/jdk
bash ./configure
make jdk-image
export JAVA_HOME=/<my_dir>/jdk/build/linux-x86_64-server-release/images/jdk

4. Update your JDK to latest Graal (16 is current JDK version) and rename packages/dirs in Graal to match JDK

cd /<my_dir>/graal/compiler
mx updategraalinopenjdk --pretty PRETTY --metro /<my_dir>/jdk 16
mx renamegraalpackages 16

5. Rebuild your JDK with updated Graal and build static libraries for libgraal

cd /<my_dir>/jdk
make clean
make jdk-image
make static-libs-image
cp build/linux-x86_64-server-release/images/static-libs/lib/* build/linux-x86_64-server-release/images/jdk/lib/

6. Build libgraal

cd /<my_dir>/graal/vm
mx --env libgraal build

If successful it will create copy of JDK you build with libgraal in it:

/<my_dir>/graal/sdk/mxbuild/linux-amd64/GRAALVM_LIBGRAAL_JAVA16/graalvm-libgraal-java16-20.3.0-dev/bin/java

Or you can copy libgraal into your JDK:

cp /<my_dir>/graal/sdk/mxbuild/linux-amd64/libjvmcicompiler.so.image/libjvmcicompiler.so $JAVA_HOME/lib

I would suggest to use GRAALVM_LIBGRAAL_JAVA16 because all JVMCI flags are product. In $JAVA_HOME you have to add 
-XX:+UnlockExperimentalVMOptions when use JVMCI flags since JVMCI and Graal are experimental features in JDK.

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

Unfortunately step 6 fail currently (August 25, 2020) because JDK misses JVMCI part of 8209961 fix [2] which is used by 
latest Graal which already have that fix.

Regards,
Vladimir

[1] https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-20.2.0
[2] https://bugs.openjdk.java.net/browse/JDK-8209961


More information about the metropolis-dev mailing list