Skip to content
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

bazel compilejava.lang.OutOfMemoryErro #1308

Closed
JaidenChiang opened this issue May 24, 2016 · 6 comments
Closed

bazel compilejava.lang.OutOfMemoryErro #1308

JaidenChiang opened this issue May 24, 2016 · 6 comments

Comments

@JaidenChiang
Copy link

JaidenChiang commented May 24, 2016

Hello everybody,i have a problem need your help,I'm very appreciate that you can help me to fix it.
Details:
......
The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: Java heap space
at com.sun.tools.javac.util.ArrayUtils.ensureCapacity(ArrayUtils.java:60)
at com.sun.tools.javac.util.SharedNameTable.fromUtf(SharedNameTable.java:130)
at com.sun.tools.javac.util.Names.fromUtf(Names.java:342)
at com.sun.tools.javac.util.ByteBuffer.toName(ByteBuffer.java:159)
at com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.toName(ClassWriter.java:328)
at com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.access$300(ClassWriter.java:273)
at com.sun.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:343)
at com.sun.tools.javac.jvm.ClassWriter.writeMemberAttrs(ClassWriter.java:624)
at com.sun.tools.javac.jvm.ClassWriter.writeField(ClassWriter.java:1091)
at com.sun.tools.javac.jvm.ClassWriter.writeFields(ClassWriter.java:1591)
at com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1691)
at com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1621)
at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:746)
at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1572)
at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1536)
at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
at com.sun.tools.javac.main.Main.compile(Main.java:381)
at com.sun.tools.javac.main.Main.compile(Main.java:370)
at com.sun.tools.javac.main.Main.compile(Main.java:361)
at com.sun.tools.javac.Main.compile(Main.java:56)
at com.sun.tools.javac.Main.main(Main.java:42)

Compiling Bazel Java code...

There are my environment:
Platform:
Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) i686 GNU/Linux
java version:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) Server VM (build 25.91-b14, mixed mode)
java -XshowSettings:vm
VM settings:
Max. Heap Size (Estimated): 437.50M
Ergonomics Machine Class: server
Using VM: Java HotSpot(TM) Server VM

The javac's heap size is 256m in the Java Visual VM.
I had tried every way as I could.
Thanks very much!

@JaidenChiang
Copy link
Author

I find the way to fix this problem:
vim scripts/bootstrap/compile.sh
find the "run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}"" and add
-J-Xms256m -J-Xmx384m
as
" run "${JAVAC}" -J-Xms256m -J-Xmx384m -classpath "${classpath}" -sourcepath "${sourcepath}""
and it works well.

@doug-ross
Copy link

Thanks, that's awesome!

@zubroid
Copy link

zubroid commented Mar 23, 2017

Hi everyone!
The previous answer helped me in the begging of compilation, but in the very end I get the same again even with extra options. The error code:

ERROR: /home/iwi/bazel/src/main/java/com/google/devtools/build/lib/standalone/BUILD:5:1: Java compilation in rule '//src/main/java/com/google/devtools/build/lib/standalone:standalone' failed: Worker process sent response with exit code: 1. An exception has occurred in the compiler (9-internal). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you. java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Arrays.java:3520) at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1069) at com.sun.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:130) at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:139) at java.nio.file.FileSystems.newFileSystem(FileSystems.java:390) at com.sun.tools.javac.file.JavacFileManager$ArchiveContainer.<init>(JavacFileManager.java:501) at com.sun.tools.javac.file.JavacFileManager.getContainer(JavacFileManager.java:310) at com.sun.tools.javac.file.JavacFileManager.list(JavacFileManager.java:692) at com.sun.tools.javac.code.ClassFinder.scanPlatformPath(ClassFinder.java:590) at com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:511) at com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:294) at com.sun.tools.javac.code.ClassFinder.access$000(ClassFinder.java:73) at com.sun.tools.javac.code.ClassFinder$1.complete(ClassFinder.java:165) at com.sun.tools.javac.code.Symbol.complete(Symbol.java:590) at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:299) at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:509) at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:255) at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:270) at com.sun.tools.javac.comp.Enter.complete(Enter.java:485) at com.sun.tools.javac.comp.Enter.main(Enter.java:469) at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:932) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:815) at com.sun.tools.javac.api.JavacTaskImpl$1.call(JavacTaskImpl.java:97) at com.sun.tools.javac.api.JavacTaskImpl$1.call(JavacTaskImpl.java:93) at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:128) at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:93) at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:87) at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:104) at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder$1.invokeJavac(SimpleJavaLibraryBuilder.java:163) at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:52) at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:166) at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:178) Target //src:bazel failed to build INFO: Elapsed time: 1646.645s, Critical Path: 1382.24s

@Niaoutheron
Copy link

Niaoutheron commented Nov 9, 2018

Hello,
I know this is an old post but I tried what @JaidenChiang did and still had a "system out of resources" message. @JaidenChiang still got it right! I only had to add this to his line edit: -J-Xms512m and it works now, the edited line becomes like:
run "${JAVAC}" -J-Xms256m -J-Xmx384m –J-Xms512m -classpath "${classpath}" -sourcepath "${sourcepath}
Hope this helps those who encountered something similar to what I had :)

@xiaket
Copy link

xiaket commented Nov 10, 2018

Sorry to leave a comment on a closed issue and bother everyone, but with the commit 09222fa in place, it is now possible to set up an environment variable and insert extra javac options, like this:

env BAZEL_JAVAC_OPTS="-J-Xms384m -J-Xmx512m" bash ./compile.sh

@ElectricRCAircraftGuy
Copy link
Contributor

ElectricRCAircraftGuy commented Mar 2, 2022

If anyone is still stuck on this and stumbles upon this thread, here is the quick fix from my Stack Overflow answer here:

If bazel runs out of memory while building, and you see this error:

java.lang.OutOfMemoryError: Java heap space

...then do this:

  1. Increase your RAM or your virtual memory swap file size, to emulate having more RAM (details on how to do this are below).
  2. From now on, build with this bazel command, for example, to give Bazel more heap space (RAM) while building. In this case I am giving it 32GB maximum RAM:
    # Do this to give Bazel up to 32GB of RAM wile building
    time bazel --host_jvm_args=-Xmx32g build //...
    
    # ...instead of doing this
    time bazel build //...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants