Skip to content

Added GraalVM for JDK 21 #78

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

Merged
merged 2 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 87 additions & 49 deletions oci-build-examples/oci_devops_build_with_graalenterprise/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Allow dynamic-group <YOUR_DynamicGroup_NAME> to use ons-topics in compartment <
![](images/oci_buildpipeline_managedbuild.png)

- Click `Next` and provide the details.
- In the `Build spec file path`, enter `build_spec.yaml` to use the [GraalVM Enterprise 22.x Java 17 build spec](build_spec.yaml). Alternatively, you can enter `build_spec_oracle_graalvm_jdk17.yaml` to use the [Oracle GraalVM for JDK 17 build spec](./build_spec_oracle_graalvm_jdk17.yaml) or `build_spec_oracle_graalvm_jdk20.yaml` to use the [Oracle GraalVM for JDK 20 build spec](./build_spec_oracle_graalvm_jdk20.yaml).
- In the `Build spec file path`, enter `build_spec_oracle_graalvm_jdk21.yaml` to use [Oracle GraalVM for JDK 21](./build_spec_oracle_graalvm_jdk21.yaml) or `build_spec_oracle_graalvm_jdk17.yaml` to use [Oracle GraalVM for JDK 17](./build_spec_oracle_graalvm_jdk17.yaml). Alternatively, you can enter `build_spec.yaml` to use the legacy [GraalVM Enterprise 22.x Java 17](build_spec.yaml).

![](images/oci_buildstage_1.png)

Expand All @@ -99,17 +99,17 @@ To install and use Oracle GraalVM in the DevOps build pipeline, the build specif
```shell
steps:
- type: Command
name: "Install Oracle GraalVM Enterprise 22.x Native Image for Java17"
name: "Install Oracle GraalVM for JDK 21 (Native Image and JDK)"
command: |
yum -y install graalvm22-ee-17-native-image
yum -y install graalvm-21-native-image
```

2. Set the JAVA_HOME environment variable.

```shell
env:
variables:
"JAVA_HOME" : "/usr/lib64/graalvm/graalvm22-ee-java17"
"JAVA_HOME" : "/usr/lib64/graalvm/graalvm-java21"
```

3. Set the PATH environment variable.
Expand Down Expand Up @@ -139,15 +139,13 @@ To install and use Oracle GraalVM in the DevOps build pipeline, the build specif

5. The executable file can be found under `target/my-app`.

```markdown
- name: app_native_executable
type: BINARY
location: target/my-app
```
```markdown
- name: app_native_executable
type: BINARY
location: target/my-app
```

Here's the complete [build specification for GraalVM Enterprise 22.x Java 17](build_spec.yaml) file. Alternatively, you can use the
[build specification for Oracle GraalVM for JDK 17](./build_spec_oracle_graalvm_jdk17.yaml) or
[build specification for Oracle GraalVM for JDK 20](./build_spec_oracle_graalvm_jdk20.yaml).
Here's the complete [build specification for Oracle GraalVM for JDK 21](./build_spec_oracle_graalvm_jdk21.yaml). Alternatively, you can use the [build specification for Oracle GraalVM for JDK 17](./build_spec_oracle_graalvm_jdk17.yaml) or the legacy [build specification for GraalVM Enterprise 22.x Java 17](build_spec.yaml) file.


## How to export the executable file outside of the build pipeline stage.
Expand All @@ -171,7 +169,7 @@ The following instructions will help you to export the `executable app file` to

- Use option `Set Custom Location` as Artifact location.
- Provide a path and version as `${BUILDRUN_HASH}`, this is to maintain immutable artifacts.
- The variable `BUILDRUN_HASH` is derived during managed build stage and exported as an exportedVariables.You may use any other name ,but ensure to update the file [build_spec.yaml](build_spec.yaml).
- The variable `BUILDRUN_HASH` is derived during managed build stage and exported as an exportedVariables.You may use any other name, but ensure to update the corresponding build specification file.
- Select `Yes, substitute placeholders` as an option and click `Add`.

![](images/oci_devops_artifact_3.png)
Expand All @@ -186,7 +184,7 @@ The following instructions will help you to export the `executable app file` to


- Use `app_native_executable` result artifact name.
- The name `app_native_executable` is a reference to the outputArtifact defined under the the file [build_spec.yaml](build_spec.yaml).
- The name `app_native_executable` is a reference to the outputArtifact defined under the corresponding build specification file.
- Click `Add` and add the stage.

![](images/oci_upload_artifact.png)
Expand Down Expand Up @@ -217,7 +215,7 @@ The following instructions will help you to export the `executable app file` to
## Optional - Run build with more verbose output.

- An additional build instruction file as [build_spec_verbose.yaml](build_spec_verbose.yaml)
can be used for more verbose output with the managed build.
can be used for more verbose output with the managed build.
- To do so, switch to `OCI DevOps project` > `OCI Build pipeline ` > Click `3 dots` on the `Managed Build` stage and click on `View details` and then `Edit Stage`.

![](images/oci_buildstage_details.png)
Expand All @@ -235,54 +233,94 @@ The following instructions will help you to export the `executable app file` to
```shell
...
EXEC: Installed:
EXEC: graalvm22-ee-17-native-image.x86_64 0:22.1.0.1-1.el7
EXEC: graalvm-21-native-image.x86_64 0:21.0.7-1.el7
EXEC:
EXEC: Dependency Installed:
EXEC: glibc-static.x86_64 0:2.17-326.0.1.el7_9
EXEC: graalvm22-ee-17-jdk.x86_64 0:22.1.0.1-1.el7
EXEC: glibc-static.x86_64 0:2.17-326.0.9.el7_9.3
EXEC: graalvm-21-jdk.x86_64 0:21.0.7-1.el7
EXEC: libstdc++-static.x86_64 0:4.8.5-44.0.3.el7
EXEC: zlib-static.x86_64 0:1.2.7-20.el7_9
EXEC: zlib-static.x86_64 0:1.2.7-21.el7_9
EXEC:
EXEC: Complete!
EXEC: Dependency Updated:
EXEC: glibc.x86_64 0:2.17-326.0.9.el7_9.3
EXEC: glibc-common.x86_64 0:2.17-326.0.9.el7_9.3
EXEC: glibc-devel.x86_64 0:2.17-326.0.9.el7_9.3
EXEC: glibc-headers.x86_64 0:2.17-326.0.9.el7_9.3
EXEC:
EXEC: Complete!
...
```

2. The native executable build log statements should be similar to:

```shell
...
EXEC: ==================================================================
EXEC: ========================================================================================================================
EXEC: GraalVM Native Image: Generating 'my-app' (executable)...
EXEC: ==================================================================
EXEC: [1/7] Initializing... (5.6s @ 0.11GB)
EXEC: Version info: 'GraalVM 22.1.0.1 Java 17 EE'
EXEC: ========================================================================================================================
EXEC: For detailed information and explanations on the build output, visit:
EXEC: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
EXEC: ------------------------------------------------------------------------------------------------------------------------
EXEC: [1/8] Initializing... (3.6s @ 0.09GB)
EXEC: Java version: 21.0.7+8-LTS, vendor version: Oracle GraalVM 21.0.7+8.1
EXEC: Graal compiler: optimization level: 2, target machine: x86-64-v3, PGO: ML-inferred
EXEC: C compiler: gcc (redhat, x86_64, 4.8.5)
EXEC: Garbage collector: Serial GC
EXEC: [2/7] Performing analysis... [******] (9.5s @ 0.32GB)
EXEC: 1,880 (62.46%) of 3,010 classes reachable
EXEC: 1,684 (46.71%) of 3,605 fields reachable
EXEC: 7,784 (36.98%) of 21,049 methods reachable
EXEC: 21 classes, 0 fields, and 285 methods registered for reflection
EXEC: 48 classes, 32 fields, and 47 methods registered for JNI access
EXEC: [3/7] Building universe... (1.1s @ 0.45GB)
EXEC: [4/7] Parsing methods... [*] (0.8s @ 0.58GB)
EXEC: [5/7] Inlining methods... [****] (1.2s @ 0.97GB)
EXEC: [6/7] Compiling methods... [*****] (21.2s @ 0.75GB)
EXEC: [7/7] Creating image... (0.9s @ 0.92GB)
EXEC: 2.62MB (46.31%) for code area: 3,708 compilation units
EXEC: 2.45MB (43.34%) for image heap: 945 classes and 38,518 objects
EXEC: 600.06KB (10.35%) for other data
EXEC: 5.66MB in total
EXEC: ------------------------------------------------------------------
...
EXEC: ------------------------------------------------------------------
EXEC: 0.9s (2.1% of total time) in 18 GCs | Peak RSS: 2.44GB | CPU load: 3.41
EXEC: ------------------------------------------------------------------
EXEC: Garbage collector: Serial GC (max heap size: 80% of RAM)
EXEC: 1 user-specific feature(s):
EXEC: - com.oracle.svm.thirdparty.gson.GsonFeature
EXEC: ------------------------------------------------------------------------------------------------------------------------
EXEC: Build resources:
EXEC: - 5.11GB of memory (75.6% of 6.76GB system memory, determined at start)
EXEC: - 4 thread(s) (100.0% of 4 available processor(s), determined at start)
EXEC: [2/8] Performing analysis... [*****] (8.5s @ 0.19GB)
EXEC: 2,052 reachable types (60.0% of 3,421 total)
EXEC: 1,935 reachable fields (45.3% of 4,272 total)
EXEC: 8,767 reachable methods (36.2% of 24,223 total)
EXEC: 741 types, 37 fields, and 332 methods registered for reflection
EXEC: 49 types, 33 fields, and 48 methods registered for JNI access
EXEC: 4 native libraries: dl, pthread, rt, z
EXEC: [3/8] Building universe... (1.5s @ 0.23GB)
EXEC: [4/8] Parsing methods... [**] (2.7s @ 0.23GB)
EXEC: [5/8] Inlining methods... [***] (0.8s @ 0.24GB)
EXEC: [6/8] Compiling methods... [****] (17.1s @ 0.27GB)
EXEC: [7/8] Laying out methods... [*] (0.7s @ 0.26GB)
EXEC: [8/8] Creating image... [*] (1.1s @ 0.23GB)
EXEC: 2.82MB (42.58%) for code area: 3,945 compilation units
EXEC: 3.18MB (48.04%) for image heap: 53,077 objects and 43 resources
EXEC: 636.31kB ( 9.39%) for other data
EXEC: 6.62MB in total
EXEC: ------------------------------------------------------------------------------------------------------------------------
EXEC: Top 10 origins of code area: Top 10 object types in image heap:
EXEC: 1.41MB java.base 765.27kB byte[] for code metadata
EXEC: 1.12MB svm.jar (Native Image) 693.88kB byte[] for java.lang.String
EXEC: 84.35kB com.oracle.svm.svm_enterprise 363.73kB java.lang.String
EXEC: 42.24kB jdk.proxy2 322.13kB java.lang.Class
EXEC: 37.79kB jdk.proxy1 168.13kB java.util.HashMap$Node
EXEC: 30.20kB org.graalvm.nativeimage.base 114.01kB char[]
EXEC: 27.42kB org.graalvm.collections 94.77kB heap alignment
EXEC: 21.20kB jdk.internal.vm.ci 81.83kB java.lang.Object[]
EXEC: 16.79kB jdk.internal.vm.compiler 81.45kB byte[] for reflection metadata
EXEC: 11.80kB jdk.proxy3 80.16kB com.oracle.svm.core.hub.DynamicHubCompanion
EXEC: 389.00B for 1 more packages 490.66kB for 523 more object types
EXEC: Use '-H:+BuildReport' to create a report with more details.
EXEC: ------------------------------------------------------------------------------------------------------------------------
EXEC: Security report:
EXEC: - Binary does not include Java deserialization.
EXEC: - Use '--enable-sbom' to embed a Software Bill of Materials (SBOM) in the binary.
EXEC: ------------------------------------------------------------------------------------------------------------------------
EXEC: Recommendations:
EXEC: G1GC: Use the G1 GC ('--gc=G1') for improved latency and throughput.
EXEC: PGO: Use Profile-Guided Optimizations ('--pgo') for improved throughput.
EXEC: INIT: Adopt '--strict-image-heap' to prepare for the next GraalVM release.
EXEC: HEAP: Set max heap for improved and more predictable memory usage.
EXEC: CPU: Enable more CPU features with '-march=native' for improved performance.
EXEC: ------------------------------------------------------------------------------------------------------------------------
EXEC: 2.8s (7.5% of total time) in 262 GCs | Peak RSS: 0.79GB | CPU load: 3.27
EXEC: ------------------------------------------------------------------------------------------------------------------------
EXEC: Produced artifacts:
EXEC: /workspace/gvmee-yum/target/my-app (executable)
EXEC: /workspace/gvmee-yum/target/my-app.build_artifacts.txt
EXEC: ==================================================================
EXEC: Finished generating 'my-app' in 41.7s.
EXEC: ========================================================================================================================
EXEC: Finished generating 'my-app' in 36.7s.
...
```

Expand All @@ -298,7 +336,7 @@ Contributors

- Author: [Rahul M R](https://github.com/RahulMR42).
- Collaborators: [Sachin Pikle](https://github.com/sachin-pikle)
- Last release: July 2022
- Last updated: July 2025

### Back to examples.
----
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: 0.1
component: build
timeoutInSeconds: 600
runAs: root
shell: bash
env:
exportedVariables:
- BUILDRUN_HASH
variables:
"JAVA_HOME" : "/usr/lib64/graalvm/graalvm-java21"
# PATH is a reserved variable and cannot be defined as a variable.
# However, PATH can be changed in a build step and the change is visible in subsequent steps.
steps:
- type: Command
name: "Define unique tag"
timeoutInSeconds: 40
command: |
export BUILDRUN_HASH=`echo ${OCI_BUILD_RUN_ID} | rev | cut -c 1-7`
echo "BUILDRUN_HASH: " $BUILDRUN_HASH

- type: Command
name: "Install Oracle GraalVM for JDK 21 (Native Image and JDK)"
command: |
yum -y install graalvm-21-native-image
- type: Command
name: "Set PATH Variable"
command: |
export PATH=$JAVA_HOME/bin:$PATH
# - type: Command
# name: "Build a Jar"
# command: |
# mvn --no-transfer-progress clean package
- type: Command
name: "Build a native executable "
command: |
mvn --no-transfer-progress -Pnative -DskipTests package

outputArtifacts:
# - name: app_jar
# type: BINARY
# location: target/my-app-1.0-SNAPSHOT.jar
- name: app_native_executable
type: BINARY
location: target/my-app
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
exportedVariables:
- BUILDRUN_HASH
variables:
"JAVA_HOME" : "/usr/lib64/graalvm/graalvm22-ee-java17"
"JAVA_HOME" : "/usr/lib64/graalvm/graalvm-java21"
# PATH is a reserved variable and cannot be defined as a variable.
# However, PATH can be changed in a build step and the change is visible in subsequent steps.
steps:
Expand All @@ -24,15 +24,15 @@ steps:
- type: Command
name: "Pre-yum repo checks"
command: |
printf "\n\n Contents of graal_spec.yaml file:\n $(cat graal_spec.yaml) \n\n"
printf "\n\n Contents of build_spec_verbose.yaml file:\n $(cat build_spec_verbose.yaml) \n\n"
printf "Contents of /etc/pki/rpm-gpg/:\n $(ls -alh /etc/pki/rpm-gpg/) \n"
printf "Contents of /etc/yum.repos.d/:\n $(ls -alh /etc/yum.repos.d/) \n"
printf "Contents of etc/yum.repos.d/oci-included-ol7.repo file:\n $(cat "etc/yum.repos.d/oci-included-ol7.repo") \n"
printf "Output of yum list graalvm22-ee-17* :\n $(yum list graalvm22-ee-17*) \n"
printf "Output of yum list graalvm-21* :\n $(yum list graalvm-21*) \n"
- type: Command
name: "Install GraalVM 22.x Native Image for Java17"
name: "Install Oracle GraalVM for JDK 21 (Native Image and JDK)"
command: |
yum -y install graalvm22-ee-17-native-image
yum -y install graalvm-21-native-image
- type: Command
name: "Set PATH Variable"
command: |
Expand All @@ -49,7 +49,7 @@ steps:
printf "Maven version:\n $(mvn --version) \n"
echo "Current dir: $(pwd)"
printf "Current dir contents:\n $(ls -alh)"
printf "Output of yum list graalvm22-ee-17* :\n $(yum list graalvm22-ee-17*) \n"
printf "Output of yum list graalvm-21* :\n $(yum list graalvm-21*) \n"
- type: Command
name: "Build a Jar"
command: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
<native.maven.plugin.version>0.9.13</native.maven.plugin.version>
<native.maven.plugin.version>0.10.6</native.maven.plugin.version>
</properties>

<dependencies>
Expand Down