Get Started with Oracle GraalVM on Oracle Linux in OCI

0
0
Send lab feedback

Get Started with Oracle GraalVM on Oracle Linux in OCI

Introduction

This hands-on lab shows how to install Oracle GraalVM and its features on Oracle Linux 8 in Oracle Cloud Infrastructure (OCI). To learn how to install Oracle GraalVM on Oracle Linux 7 or 9, see this guide .

  Oracle GraalVM is available at no cost on OCI.

Oracle GraalVM compiles your Java applications ahead of time into standalone binaries that start instantly, provide peak performance with no warmup, and use fewer resources. You can use the GraalVM JDK just like any other JDK.

Lab Contents

In this lab you will:

  • Connect to a VM instance in Oracle Cloud
  • Install Oracle GraalVM on Oracle Linux 8
  • Add additional Oracle GraalVM features

Estimated Workshop Time: 20 minutes

NOTE: To copy the command, hover over the field and then click the copy to clipboard icon.

Task 1: Connect to a VM instance in Oracle Cloud

When you launch the lab, the necessary resources are provisioned in the background: Virtual Cloud Network (VCN) and a Compute Instance with the Oracle Linux 8 pre-built image. It can take 1-2 minutes to complete provisioning. You can tell when the resources are fully provisioned and ready by consulting the Resources tab on the Luna Lab webpage (see step 1, below).

  1. Double-click the Luna Lab icon on the desktop to open the browser.

    Wait until the the animated gear besides Resources turns into a checkmark. It means all the required compute and network resources are provisioned and you can proceed.

  2. Unfold Resources and copy the Public IP address from the SERVER_IP box. You many need to click on View Details. You can use the Copy to clipboard button on the far right that appears when you hover over the box.

  3. Minimize the browser window so you can see the Luna Desktop. Click the Applications menu and open a Terminal Emulator.

  4. Enter SSH connection command where <SERVER_IP> is your VM instance public IP address:

    ssh opc@<SERVER_IP>

    Accept the ECDSA key fingerprint by typing yes at the prompt.

You are now connected to a remote host in Oracle Cloud and can proceed to the next task.

Task 2: Install Oracle GraalVM

In this task you will install Oracle GraalVM on Oracle Linux 8 and set it as a default Java runtime. To learn how to install Oracle GraalVM on Oracle Linux 7 or 9, see this guide .

For convenience, Oracle GraalVM RPMs are available in the Oracle YUM repository. RPMs for Oracle GraalVM for JDK 17 and Oracle GraalVM for JDK 20 are available with the package names graalvm-17-native-image and graalvm-20-native-image respectively. Each Oracle GraalVM RPM is self-contained and all required dependencies will be automatically resolved during the installation.

  1. In a Terminal window connected to your virtual host, run these commands one by one:

    sudo yum update -y oraclelinux-release-el8
    sudo yum config-manager --set-enabled ol8_codeready_builder
    sudo yum install graalvm-17-native-image

    Confirm if the installed package size is okay by typing yes at the prompt.

    It will install the latest version of Oracle GraalVM for JDK 17 which includes the JDK, the Graal compiler, Native Image, and all dependent packages, for example, libpolyglot, etc. After the installation, the package files are placed in the /usr/lib64/graalvm directory, and binaries in bin accordingly.

  2. Configure environment variables to point to the Oracle GraalVM installation for this SSH session. Set the PATH and JAVA_HOME environment variables in the bash configuration with the following commands:

    echo "export JAVA_HOME=/usr/lib64/graalvm/graalvm-java17" >> ~/.bashrc
    echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
  3. Activate this change:

    source ~/.bashrc
  4. Check the versions to see if the installation was successful:

    java -version
    native-image --version

At this point you can run any Java workload on Oracle GraalVM. Oracle GraalVM employs the Graal optimizing compiler as the top-tier JIT compiler which performs advanced optimization and applies aggressive inlining techniques to accelerate application performance.

We recommend you to take the Accelerate Applications in Oracle Cloud with GraalVM Enterprise lab upon this lab completion. That lab focuses on comparing the performance of the Graal JIT compiler vs. C2 while running a Java Microbenchmark Harness (JMH).

You can proceed to the next task.

Task 3: Add Additional Features to Oracle GraalVM

Oracle GraalVM is shipped with core components (to save the filesize) and can be extended with more features on demand. For example, you can install Java on Truffle, the Python runtime, the LLVM toolchain, etc. Check the product documentation for more information on available features .

  1. Check what additional features are available for your current Oracle GraalVM installation:

    sudo yum list graalvm-17*

    The printed list may be large. If you are interested in a particular feature, for example, the Python runtime, narrow down the search providing the exact package name:

    sudo yum list graalvm-17-python*
  2. Install the feature to Oracle GraalVM using its <package_name>. For example, to install the Python runtime, run:

    sudo yum install graalvm-17-python

    Confirm if the installed package size is okay by typing yes at the prompt.

  3. Check the Python version to see if the installation was successful:

    graalpython --version

Congratulations! You have successfully completed this lab.

Learn More

To end this session, click the End Session button in the toolbar.

SSR