Skip to content

[Native Image] Terminating due to java.lang.OutOfMemoryError: Java heap space #11542

Open
@chris910512

Description

@chris910512

Describe the Issue

Hi Team,

This is more like a question, but might be an issue.

I'm trying to convert my Maven based project into Gradle.
I believe my project is not that big - source codes are just 300 kb * 8 modules + 1 common of 1mb module.

The problem is, gradle build with native image is slower than the Maven building, which is hard to believe for me.

Pieces of my scripts for native building

./gradlew --refresh-dependencies :my-service:nativeCompile -x test -Pnative

graalvmNative {
binaries {
named("main") {
imageName.set("app")
buildArgs.addAll(
listOf(
"--gc=G1",
)
)
}
}
}

With this information, it mostly fails to build with the basic runner on Github actions.
Most of the times, it fails with this information.

  - name: Set up JDK 24
    uses: graalvm/[email protected]
    with:
      java-version: "24"
      distribution: "graalvm"
      github-token: ${{ secrets.GITHUB_TOKEN }}
      cache: "gradle"

Build resources:

  • 5.86GB of memory (75.6% of 7.76GB system memory, determined at start)
  • 2 thread(s) (100.0% of 2 available processor(s), determined at start)
    SLF4J(W): No SLF4J providers were found.
    SLF4J(W): Defaulting to no-operation (NOP) logger implementation
    SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
    [2/8] Performing analysis... [*****] (257.4s @ 5.15GB)
    66,505 reachable types (92.7% of 71,761 total)
    84,964 reachable fields (56.8% of 149,512 total)
    266,334 reachable methods (59.1% of 450,315 total)
    15,899 types, 647 fields, and 3,126 methods registered for reflection
    81 types, 83 fields, and 64 methods registered for JNI access
    9 native libraries: dl, g1gc-cr, m, pthread, rt, stdc++, z
    [3/8] Building universe... (117.7s @ 4.66GB)
    GC warning: 77.0s spent in 11 GCs during the last stage, taking up 65.28% of the time.
    Please ensure more than 7.14GB of memory is available for Native Image
    to reduce GC overhead and improve image build time.
    [4/8] Parsing methods... [] (107.8s @ 4.86GB)
    [5/8] Inlining methods... [
    ] (13.5s @ 5.19GB)
    [6/8] Compiling methods... [
    ***************************] (1187.2s @ 5.92GB)
    GC warning: 616.7s spent in 202 GCs during the last stage, taking up 51.95% of the time.
    Please ensure more than 7.15GB of memory is available for Native Image
    to reduce GC overhead and improve image build time.
    Terminating due to java.lang.OutOfMemoryError: Java heap space

I've tried to build the image with external runner on my AWS with larger resource, then it the build finishes successfully.

My issues at this moments -

  1. Can it be possible the native building with Gradle slower than Maven? <- this might be not the proper question here, but I'd like to get to know if you have any reference...
  2. Doesn't it support the basic plan of Github runner?
  3. Given information and symptoms, do you think I've got a huge mistake on building Gradle + Native Compile?

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

  - name: Set up JDK 24
    uses: graalvm/[email protected]
    with:
      java-version: "24"
      distribution: "graalvm"
      github-token: ${{ secrets.GITHUB_TOKEN }}
      cache: "gradle"

Operating System and Version

Github actions basic plan of ubuntu-latest

Build Command

./gradlew --refresh-dependencies :my-service:nativeCompile -x test -Pnative

Expected Behavior

Successfully finishing the building.
Better building performance than Maven ideally.

Actual Behavior

Terminating due to java.lang.OutOfMemoryError: Java heap space

Steps to Reproduce

  - name: Set up JDK 24
    uses: graalvm/setup-graalvm@v1
    with:
      java-version: "24"
      distribution: "graalvm"
      github-token: ${{ secrets.GITHUB_TOKEN }}
      cache: "gradle"

  - name: Make gradlew executable
    run: chmod +x ./gradlew
  - name: Build project with Gradle
    id: gradle_package
    run: |
          ./gradlew --refresh-dependencies :provisioning-service:nativeCompile -x test -Pnative   

Additional Context

No response

Build Log Output and Error Messages

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions