Open mmoayyed opened 9 months ago
macOS runners come with 14GB of memory, so the first thing I'd try is to increase the max heap limit to something like 12GB. Maybe the application you're trying to compile is too big to compile with your current settings. Given you're initializing a lot at build time, it could also be a configuration problem.
Thank you! That helped to move past that stage, though the build likely requires even more memory:
]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-build-resources\Build](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-build-resources%1B\Build) resources]8;;\:
- 10.67GB of memory (76.2% of 14.00GB system memory, set via '-Xmx12G')
- 3 thread(s) (100.0% of 3 available processor(s), determined at start)
# Printing compilation-target information to: /Users/runner/work/cas/cas/webapp/cas-server-webapp-native/build/native/nativeCompile/reports/target_info_20231003_035334.txt
# Printing security services automatic registration to: /Users/runner/work/cas/cas/webapp/cas-server-webapp-native/build/native/nativeCompile/reports/security_services_20231003_035341.txt
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
# Printing native-library information to: /Users/runner/work/cas/cas/webapp/cas-server-webapp-native/build/native/nativeCompile/reports/native_library_info_20231003_035919.txt
[2/8] ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-analysis\Performing](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-analysis%1B\Performing) analysis]8;;\... [*******] (345.4s @ 5.61GB)
53,627 ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-reachability\reachable](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-reachability%1B\reachable) types]8;;\ (91.8% of 58,449 total)
80,612 ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-reachability\reachable](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-reachability%1B\reachable) fields]8;;\ (65.7% of 122,605 total)
276,150 ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-reachability\reachable](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-reachability%1B\reachable) methods]8;;\ (68.0% of 405,977 total)
18,482 types, 2,660 fields, and 36,714 methods ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-reflection-registrations\registered](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-reflection-registrations%1B\registered) for reflection]8;;\
66 types, 66 fields, and 56 methods ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-jni-access-registrations\registered](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#glossary-jni-access-registrations%1B\registered) for JNI access]8;;\
5 native libraries: -framework CoreServices, -framework Foundation, dl, pthread, z
[3/8] ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-universe\Building](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-universe%1B\Building) universe]8;;\... (57.4s @ 6.96GB)
[4/8] ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-parsing\Parsing](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-parsing%1B\Parsing) methods]8;;\... [*********] (86.4s @ 6.37GB)
[5/8] ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-inlining\Inlining](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-inlining%1B\Inlining) methods]8;;\... [**] (4.9s @ 4.79GB)
[6/8] ]8;;[https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-compiling\Compiling](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#stage-compiling%1B\Compiling) methods]8;;\... [*****************************************************] (2847.1s @ 9.35GB)
GC warning: 1797.3s spent in 191 GCs during the last stage, taking up 63.10% of the time.
Please ensure more than 9.97GB of memory is available for Native Image
to reduce GC overhead and improve image build time.
Does this really mean that '-Xmx12G' is not enough, and perhaps I can switch up to 13G? Is there anything else one might do to reduce the amount of memory required here?
A lot of what is initialized at build time has to do with Groovy, and sadly, I don't think these can be avoided:
buildArgs.add('--initialize-at-build-time=groovyjarjarantlr4.v4.runtime')
buildArgs.add('--initialize-at-build-time=org.codehaus.groovy')
buildArgs.add('--initialize-at-build-time=org.apache.groovy')
buildArgs.add('--initialize-at-build-time=groovy.lang'
Hi @mmoayyed, it seems --pgo-instrument
introduces a significant memory overhead when building your application. We are currently looking into what is going on and how to fix this, but at the moment, I'm afraid you can't build your app with a max heap of 13GB. I was able to build it on a machine with 32GB, but that's a lot more than what GitHub's free runners provide.
While we are looking into this, maybe disable --pgo-instrument
for now and see whether it unblocks the build.
Thank you @fniephaus. Removing PGO instrumentation allows the build to proceed in about 14mins with 12GB:
Finished generating 'cas' in 14m 33s.
[native-image-plugin] Native Image written to: /Users/runner/work/cas/cas/webapp/cas-server-webapp-native/build/native/nativeCompile
I do however see this when the image runs:
2023-10-13 23:38:21 ERROR o.s.b.SpringApplication - Application run failed
java.lang.NoClassDefFoundError: org.graalvm.home.Version
at org.apereo.cas.nativex.CasNativeBannerContributor.contribute(CasNativeBannerContributor.java:21)
The CasNativeBannerContributor
does the following:
import org.graalvm.home.Version;
...
var version = Version.getCurrent().toString();
Is this related to the above issue somehow, or may I submit a new report?
My understanding is that GraalVM SDK must not be packaged with the app so I don't get why this would show up (and it did not before in prior releases of GraalVM for JDK 17)
I have switched to Java 22 and looks like I am still seeing the same sort of error:
java version "22" 2024-03-19
Java(TM) SE Runtime Environment Oracle GraalVM 22+36.1 (build 22+36-jvmci-b02)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 22+36.1 (build 22+36-jvmci-b02, mixed mode, sharing)
This is with Gradle 8.7-rc-3
:
> Task :webapp:cas-server-webapp-native:nativeCompile
[native-image-plugin] GraalVM Toolchain detection is disabled
[native-image-plugin] GraalVM location read from environment variable: JAVA_HOME
[native-image-plugin] Native Image executable path: /Library/Java/JavaVirtualMachines/graalvm/Contents/Home/lib/svm/bin/native-image
Warning: The option '-H:ServiceLoaderFeatureExcludeServices=org.hibernate.bytecode.spi.BytecodeProvider' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ReflectionConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-el/tomcat-reflection.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:+BuildReport' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:+InlineBeforeAnalysis' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ResourceConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-core/tomcat-resource.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ReflectionConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-core/tomcat-reflection.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ResourceConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-el/tomcat-resource.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:+TraceSecurityServices' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: Please re-evaluate whether any experimental option is required, and either remove or unlock it. The build output lists all active experimental options, including where they come from and possible alternatives. If you think an experimental option should be considered as stable, please file an issue.
Warning: Option 'InlineBeforeAnalysis' is deprecated and might be removed in a future release: It no longer has any effect, and no replacement is available. Please refer to the GraalVM release notes.
========================================================================================================================
GraalVM Native Image: Generating 'cas' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
Warning: Using -g is not supported on macOS
Registering BouncyCastle security provider
The URL protocol jar is not tested and might not work as expected.
Supported URL protocols enabled by default: file,resource. Supported URL protocols available on demand: http,https.
The URL protocol file is enabled by default. The option --enable-url-protocols=file is not needed.
The URL protocol resource is enabled by default. The option --enable-url-protocols=resource is not needed.
[1/8] Initializing... (12.0s @ 0.74GB)
Java version: 22+36, vendor version: Oracle GraalVM 22+36.1
Graal compiler: optimization level: b, target machine: native, PGO: off
C compiler: cc (apple, arm64, 15.0.0)
Garbage collector: Serial GC (max heap size: 80% of RAM)
7 user-specific feature(s):
- com.oracle.svm.polyglot.groovy.GroovyIndyInterfaceFeature
- com.oracle.svm.thirdparty.gson.GsonFeature
- org.apereo.cas.nativex.features.DefaultNativeImageFeature
- org.eclipse.angus.activation.nativeimage.AngusActivationFeature
- org.eclipse.angus.mail.nativeimage.AngusMailFeature
- org.graalvm.home.HomeFinderFeature: Finds GraalVM paths and its version number
- org.springframework.aot.nativex.feature.PreComputeFieldFeature
------------------------------------------------------------------------------------------------------------------------
6 experimental option(s) unlocked:
- '-H:ServiceLoaderFeatureExcludeServices' (origin(s): 'META-INF/native-image/org.springframework/spring-orm/native-image.properties' in 'file:///Users/misagh/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/6.1.5/d2dc2b996680fcc8ae5aea294f0ce6bda5577c7c/spring-orm-6.1.5.jar')
- '-H:+BuildReport' (origin(s): command line)
- '-H:+InlineBeforeAnalysis' (origin(s): command line)
- '-H:ResourceConfigurationResources': Use a resource-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead. (origin(s): 'META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-core/native-image.properties' in 'file:///Users/misagh/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/10.1.19/3dbbca8acbd4dd6a137c3d6f934a2931512b42ce/tomcat-embed-core-10.1.19.jar', 'META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-el/native-image.properties' in 'file:///Users/misagh/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-el/10.1.19/c61a582c391aca130884a5421deedfe1a96c7415/tomcat-embed-el-10.1.19.jar')
- '-H:+TraceSecurityServices' (origin(s): command line)
- '-H:ReflectionConfigurationResources': Use a reflect-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead. (origin(s): 'META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-core/native-image.properties' in 'file:///Users/misagh/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/10.1.19/3dbbca8acbd4dd6a137c3d6f934a2931512b42ce/tomcat-embed-core-10.1.19.jar', 'META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-el/native-image.properties' in 'file:///Users/misagh/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-el/10.1.19/c61a582c391aca130884a5421deedfe1a96c7415/tomcat-embed-el-10.1.19.jar')
------------------------------------------------------------------------------------------------------------------------
Build resources:
- 10.67GB of memory (16.7% of 64.00GB system memory, set via '-Xmx12G')
- 10 thread(s) (100.0% of 10 available processor(s), determined at start)
# Printing compilation-target information to: /Users/misagh/Workspace/GitWorkspace/cas-server/webapp/cas-server-webapp-native/build/native/nativeCompile/reports/target_info_20240320_171746.txt
# Printing security services automatic registration to: /Users/misagh/Workspace/GitWorkspace/cas-server/webapp/cas-server-webapp-native/build/native/nativeCompile/reports/security_services_20240320_171752.txt
=== Image generator watchdog detected no activity. This can be a sign of a deadlock during image building. Dumping all stack traces. Current time: Wed Mar 20 17:27:59 GST 2024
"main" Id=1 in BLOCKED on lock=com.oracle.graal.pointsto.flow.MethodTypeFlow@126edb08
owned by ForkJoinPool.commonPool-worker-3 Id=29
at app/org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:158)
at app/org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureFlowsGraphCreated(MethodTypeFlow.java:152)
at app/org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.getOrCreateMethodFlowsGraphInfo(MethodTypeFlow.java:110)
at app/org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.lambda$update$0(DefaultStaticInvokeTypeFlow.java:75)
at app/org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow$$Lambda/0x000003fe0366ec90.accept(Unknown Source)
I can share the full stacktrace if it helps.
What happens if you double the memory limit from -Xmx12G
to -Xmx24G
? If the build works, then 12GB is unfortunately not enough for the application and config you are building with.
Unfortunately I have run into a snag because Gradle 8.7 is not quite able to build with java 22 so I'll have to revisit.
Is it alarming that the same exact application setup builds ok under GraalVM 21? Under 10 minutes?
Unfortunately I have run into a snag because Gradle 8.7 is not quite able to build with java 22 so I'll have to revisit.
That's what GRAALVM_HOME
is for: set JAVA_HOME
to a JDK 21 and GRAALVM_HOME
to the JDK 22 release and you should be good. Gradle will run on JDK 21 but then use the native-image
launcher from JDK 22.
Is it alarming that the same exact application setup builds ok under GraalVM 21? Under 10 minutes?
Yes, it is and it'd be nice to track down the problem. Do you have --strict-image-heap
enabled in the GraalVM 21 build? If not, can you turn it on and see whether that slows down your build times in the same way?
Thank you. Looks like I needed to add --initialize-at-build-time=groovyjarjarasm.asm.Handle
. With JDK 21 and GraalVM 22 and Gradle 8.7, I am able to build in less than 2 minutes now.
I recall you mentioned a while ago that using pgo is somewhat problematic. Is that still the case here with GraalVM 22?
that using pgo is somewhat problematic. Is that still the case here with GraalVM 22?
What I meant was that --pgo-instrument
requires additional memory, and in some cases that can be significant. We are working on improving this but I don't think this has been resolved entirely in 22.
Describe the issue
GraalVM
21+35.1
on macos-x64 hangs indefinitely when building native images. This issue happens both during local development and in GitHub Actions.Sample build run where the native image build process times out: https://github.com/mmoayyed/cas/actions/runs/6366202699/job/17283751171
The timeout happens after 90 minutes.
Steps to reproduce the issue
git clone --depth 1 git@github.com:mmoayyed/cas.git
Then:
Describe GraalVM and your environment:
GRAALVM: /Users/runner/hostedtoolcache/graalvm-jdk-21_macos-x64_bin/21.0.0/x64/graalvm-jdk-21+35.1/Contents/Home JDK: 21 Corretto OS: MacOS 12 (Github Actions) x64 Gradle: 8.4 RC3
More details
Output from the native image build process. The hang up appears to be during the stage-inlining phase.
GraalVM Gradle plugin configuration: