You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ballerina原生构建失败,退出码137(OOM内存不足)

问题

执行bal build --native命令构建Ballerina项目时失败,报错信息如下:

[1/7] Initializing...                                                                                   (16.3s @ 0.60GB)
 Version info: 'GraalVM 22.3.2 Java 11 CE'
 Java version info: '11.0.19+7-jvmci-22.3-b18'
 C compiler: gcc (linux, x86_64, 7.5.0)
 Garbage collector: Serial GC
 2 user-specific feature(s)
 - com.oracle.svm.thirdparty.gson.GsonFeature
 - io.ballerina.stdlib.crypto.svm.BouncyCastleFeature
[2/7] Performing analysis...  [************]                                                           (198.4s @ 3.66GB)
  27,643 (94.18%) of 29,352 classes reachable
 109,383 (84.89%) of 128,846 fields reachable
 166,411 (75.81%) of 219,506 methods reachable
   1,477 classes,   768 fields, and 2,931 methods registered for reflection
      91 classes,    93 fields, and    69 methods registered for JNI access
       7 native libraries: dl, m, pthread, rt, stdc++, z
[3/7] Building universe...                                                                              (20.4s @ 4.62GB)
[4/7] Parsing methods...      [*****]                                                                   (21.8s @ 4.05GB)
[5/7] Inlining methods...     [***]                                                                     (11.9s @ 5.56GB)
[6/7] Compiling methods...    [*****************]                                                      (295.5s @ 7.62GB)
Error: Image build request failed with exit status 137
error: unable to create native image

从报错exit status 137可判断是内存不足(OOM)导致构建被系统终止,当前执行命令的虚拟机拥有14GB内存,请问是否可以通过给bal build命令添加参数来配置内存限制?

回答

可以通过bal build --native的参数配置GraalVM Native Image的内存分配,具体方法如下:

  • 使用--graalvm-options参数直接传递JVM内存参数给底层的GraalVM Native Image构建流程。比如要分配10GB堆内存,执行命令:
bal build --native --graalvm-options="-Xmx10g"

-Xmx10g表示设置最大堆内存为10GB,结合你当前14GB的VM内存,这个值既不会耗尽系统内存,也能给Native Image构建提供足够空间。

  • 也可结合调整垃圾收集器优化内存使用,比如改用G1GC,命令如下:
bal build --native --graalvm-options="-Xmx10g -XX:+UseG1GC"

G1GC在内存占用和垃圾回收效率上比默认的Serial GC更适配大内存场景,能减少内存碎片产生。

exit status 137是系统因进程内存占用过高终止进程的典型标识,调整内存参数后基本可解决这类问题。

内容的提问来源于stack exchange,提问作者Sachith Kasthuriarachchi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 15:17:43