0

I am trying to build a native-image for Micronaut project for AWS Lambda, but it is not going through. When I run the build using ./gradlew clean buildNativeLambda -Pmicronaut.runtime=lambda command, the memory and CPU usage shoots to 100% and after 30-40 mins, it fails with below exception (truncated):

=== Image generator watchdog detected no activity. This can be a sign of a deadlock during image building. Dumping all stack traces. Current time: Mon Oct 03 10:48:30 UTC 2022                                                                                                                                                                 
"main" Id=1 in RUNNABLE                                                                                                                                       

at app//com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow$AbstractUnsafeStoreTypeFlow.handleUnsafeAccessedFields(OffsetStoreTypeFlow.java:244)   
at app//com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow$UnsafeStoreTypeFlow.onObservedUpdate(OffsetStoreTypeFlow.java:292)                     
at app//com.oracle.graal.pointsto.flow.TypeFlow.update(TypeFlow.java:552)                                                                         
at app//com.oracle.graal.pointsto.PointsToAnalysis$1.run(PointsToAnalysis.java:631)                                                               
at app//com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)                                             
at app//com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)                                    
at app//com.oracle.graal.pointsto.util.CompletionExecutor$$Lambda$677/0x00000007c3273440.run(Unknown Source)
at java.base@11.0.15/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)                                         
at java.base@11.0.15/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)                                                              
at java.base@11.0.15/java.util.concurrent.ForkJoinPool.awaitQuiescence(ForkJoinPool.java:2984)                                                    
at app//com.oracle.graal.pointsto.util.CompletionExecutor.complete(CompletionExecutor.java:243)                                                   
at app//com.oracle.graal.pointsto.PointsToAnalysis.doTypeflow(PointsToAnalysis.java:688)                                                          
at app//com.oracle.graal.pointsto.PointsToAnalysis.finish(PointsToAnalysis.java:676)                                                              
at app//com.oracle.graal.pointsto.PointsToAnalysis.runAnalysis(PointsToAnalysis.java:732)                                                         
at app//com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:723)                                             
at app//com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:558)                                                           
at app//com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:515)                                                             
at app//com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)                                          
at app//com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)                                               
at app//com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)                                                
at app//com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)                                                                                                                                                                                      

"Reference Handler" Id=2 in RUNNABLE
at java.base@11.0.15/java.lang.ref.Reference.processPendingReferences(Reference.java:261)                                                         
at java.base@11.0.15/java.lang.ref.Reference$ReferenceHandler.run(Reference.java:213)                                                                                                                                                                                                           

"Finalizer" Id=3 in WAITING on lock=java.lang.ref.ReferenceQueue$Lock@16974940
at java.base@11.0.15/java.lang.Object.wait(Native Method)
at java.base@11.0.15/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:155)                                                                 
at java.base@11.0.15/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:176)                                                                 
at java.base@11.0.15/java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:170)                                                                                                                                                                                                             

"Signal Dispatcher" Id=4 in RUNNABLE                                                                                                                                                                                                                                                                                   

"JVMCI-native CompilerThread0" Id=6 in RUNNABLE                                                                                                                                                                                                                                                                                      

"Common-Cleaner" Id=9 in RUNNABLE
at java.base@11.0.15/java.lang.invoke.MethodHandleNatives.clearCallSiteContext(Native Method)
at java.base@11.0.15/java.lang.invoke.MethodHandleNatives$CallSiteContext.run(MethodHandleNatives.java:92)                                        
at java.base@11.0.15/jdk.internal.ref.CleanerImpl$PhantomCleanableRef.performCleanup(CleanerImpl.java:186)                                        
at java.base@11.0.15/jdk.internal.ref.PhantomCleanable.clean(PhantomCleanable.java:133)                                                           
at java.base@11.0.15/jdk.internal.ref.CleanerImpl.run(CleanerImpl.java:150)                                                                       
at java.base@11.0.15/java.lang.Thread.run(Thread.java:829)                                                                                        
at java.base@11.0.15/jdk.internal.misc.InnocuousThread.run(InnocuousThread.java:161)                                                                                                                           

"native-image pid watcher" Id=13 in TIMED_WAITING on lock=java.util.TaskQueue@1850a5e2
at java.base@11.0.15/java.lang.Object.wait(Native Method)
at java.base@11.0.15/java.util.TimerThread.mainLoop(Timer.java:553)
at java.base@11.0.15/java.util.TimerThread.run(Timer.java:506)                                                                                                                                                                                                                                                                              

"Libgraal MBean Registration" Id=22 in TIMED_WAITING
at java.base@11.0.15/java.lang.Thread.sleep(Native Method)
at platform/jdk.internal.vm.compiler.management/org.graalvm.compiler.hotspot.management.Factory.run(Factory.java:111)                                                                                          

"ForkJoinPool.commonPool-worker-5" Id=24 in TIMED_WAITING on lock=java.util.concurrent.ForkJoinPool@18cbf3e3
at java.base@11.0.15/jdk.internal.misc.Unsafe.park(Native Method)
at java.base@11.0.15/java.util.concurrent.locks.LockSupport.parkUntil(LockSupport.java:275)
at java.base@11.0.15/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1619)
at java.base@11.0.15/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)                                                                                                              

"ForkJoinPool.commonPool-worker-15" Id=29 in WAITING on lock=java.util.concurrent.ForkJoinPool@18cbf3e3
at java.base@11.0.15/jdk.internal.misc.Unsafe.park(Native Method)
at java.base@11.0.15/java.util.concurrent.locks.LockSupport.park(LockSupport.java:194)
at java.base@11.0.15/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1628)
at java.base@11.0.15/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Below are the dependencies in build.gradle:

dependencies {
    annotationProcessor('io.micronaut:micronaut-inject-java')
    annotationProcessor("io.micronaut.data:micronaut-data-processor")
    annotationProcessor("io.micronaut:micronaut-http-validation")
    implementation("io.micronaut:micronaut-http-client")
    implementation("io.micronaut:micronaut-jackson-databind")
    implementation("jakarta.annotation:jakarta.annotation-api")
    runtimeOnly("ch.qos.logback:logback-classic")
//    runtimeOnly('org.slf4j:log4j-over-slf4j:2.0.2')
    implementation("io.micronaut:micronaut-validation")
    implementation("io.micronaut.aws:micronaut-function-aws-custom-runtime")
    implementation("io.micronaut.data:micronaut-data-hibernate-jpa")
    implementation("io.micronaut.sql:micronaut-jdbc-hikari")
    runtimeOnly("mysql:mysql-connector-java")
    compileOnly("org.graalvm.nativeimage:svm")

    implementation("io.micronaut.aws:micronaut-function-aws")

    implementation("io.micronaut.aws:micronaut-function-aws-custom-runtime")
    implementation group: 'org.json', name: 'json', version: "${orgJsonVersion}"

    implementation group: 'org.apache.poi', name: 'poi', version: "${poiVersion}"
    implementation group: 'org.apache.poi', name: 'poi-ooxml', version: "${poiVersion}"
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: "${apacheCommons}"
    implementation group: 'com.google.code.gson', name: 'gson', version: "${googleGson}"
//    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: "${springValidation}"
    implementation group: 'org.eclipse.persistence', name: 'eclipselink', version: "${eclipseLink}"
//    compileOnly group: 'javax.servlet', name: 'servlet-api', version: "${servletApi}"
    implementation("org.apache.velocity:velocity:${velocity}") {
        exclude group: 'log4j', module: 'log4j'
    }
    implementation("org.apache.velocity:velocity-tools:${velocityTools}") {
        exclude group: 'log4j', module: 'log4j'
    }
    implementation group: 'org.apache.kafka', name: 'kafka-clients', version: "${kafkaClient}"
    implementation group: 'com.google.guava', name: 'guava', version: "${googleGuava}"

}

Below are the build configurations in build.gradle:

tasks.named("dockerfileNative") {
    args(
        "-XX:MaximumHeapSizePercent=80",
        "-Dio.netty.allocator.numDirectArenas=0",
        "-Dio.netty.noPreferDirect=true"
    )
}

graalvmNative.binaries.all {
    buildArgs.add("--no-server -J-Xmx12g -J-Xms4g")
}

I tried to playing with graalvmNative.binaries.all arguments, but nothing seems to be working.

System configuration:

  • RAM: 16GB
  • CPU: i5 11th Gen
  • OS: Windows 10

I am not sure what is going wrong here, and also I am not sure like what are the resource requirements to build the Graalvm native-image. Any help on this please.

Jignesh M. Khatri
  • 1,407
  • 1
  • 14
  • 22
  • 1
    So it either hangs or takes excessively long time during analysis. One idea is to skip most expensive parts of the analysis -- try passing `-Ob` or `-O0` options – peterz Oct 04 '22 at 06:52
  • @peterz What does these options do? Any documentation? And what are the consequences of these options? I mean will they degrade the performance or anything else? – Jignesh M. Khatri Oct 04 '22 at 07:35
  • @peterz I think you were correct. By adding `-O0` option, build was successful. I found that this option will disable the optimizations. But what are the consequences of it? What kind of optimizations will be disabled and how it will impact the performance? – Jignesh M. Khatri Oct 04 '22 at 08:21
  • 1
    AFAICT `-O0` partially disables inlining, so performance may suffer (OTOH image size will likely be smaller). `-Ob` means "optimize for build time", it is shortly mentioned [here](https://www.graalvm.org/release-notes/22_1/#native-image) – peterz Oct 04 '22 at 10:08

0 Answers0