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 HEAD OOMs during analysis phase when JavaPluginInfo provides Java outputs information #14287

Closed
Bencodes opened this issue Nov 17, 2021 · 11 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-Java Issues for Java rules

Comments

@Bencodes
Copy link
Contributor

Description of the problem / feature request:

Bazel HEAD runs out of memory during the analysis phase of a build.

I did a git bisect tracking the issue back to this commit f73e28c as the culprit.

The stacktrace that eventually comes out:

(19:11:00) FATAL: bazel ran out of memory and crashed. Printing stack trace:
net.starlark.java.eval.Starlark$UncheckedEvalError: OutOfMemoryError thrown during Starlark evaluation (//instant-features/rider/last-mile/fieldwork/stationdetail/plugins:lib_kt)
        at <starlark>.compile(<builtin>:0)
        at <starlark>._run_kt_java_builder_actions(/private/var/tmp/_bazel_blee/499a001013731d09bffd82f8601a3161/external/io_bazel_rules_kotlin/kotlin/internal/jvm/compile.bzl:780)
        at <starlark>.kt_jvm_produce_jar_actions(/private/var/tmp/_bazel_blee/499a001013731d09bffd82f8601a3161/external/io_bazel_rules_kotlin/kotlin/internal/jvm/compile.bzl:517)
        at <starlark>.kt_jvm_library_impl(/private/var/tmp/_bazel_blee/499a001013731d09bffd82f8601a3161/external/io_bazel_rules_kotlin/kotlin/internal/jvm/impl.bzl:235)
Caused by: java.lang.OutOfMemoryError: Java heap space
        at java.base/java.util.Arrays.copyOf(Unknown Source)
        at com.google.common.collect.ImmutableList.asImmutableList(ImmutableList.java:371)
        at com.google.common.collect.ImmutableList$Builder.build(ImmutableList.java:871)
        at com.google.devtools.build.lib.rules.java.JavaPluginInfo.merge(JavaPluginInfo.java:179)
        at com.google.devtools.build.lib.rules.java.JavaInfoBuildHelper.mergeExportedJavaPluginInfo(JavaInfoBuildHelper.java:238)
        at com.google.devtools.build.lib.rules.java.JavaInfoBuildHelper.createJavaCompileAction(JavaInfoBuildHelper.java:298)
        at com.google.devtools.build.lib.rules.java.JavaStarlarkCommon.createJavaCompileAction(JavaStarlarkCommon.java:118)
        at jdk.internal.reflect.GeneratedMethodAccessor163.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at net.starlark.java.eval.MethodDescriptor.call(MethodDescriptor.java:162)
        at net.starlark.java.eval.BuiltinFunction.fastcall(BuiltinFunction.java:77)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:619)
        at net.starlark.java.eval.Eval.evalCall(Eval.java:672)
        at net.starlark.java.eval.Eval.eval(Eval.java:489)
        at net.starlark.java.eval.Eval.execAssignment(Eval.java:109)
        at net.starlark.java.eval.Eval.exec(Eval.java:268)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
        at net.starlark.java.eval.Eval.execIf(Eval.java:205)
        at net.starlark.java.eval.Eval.exec(Eval.java:283)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
        at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:66)
        at net.starlark.java.eval.StarlarkFunction.fastcall(StarlarkFunction.java:191)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:619)
        at net.starlark.java.eval.Eval.evalCall(Eval.java:672)
        at net.starlark.java.eval.Eval.eval(Eval.java:489)
        at net.starlark.java.eval.Eval.execAssignment(Eval.java:109)
        at net.starlark.java.eval.Eval.exec(Eval.java:268)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
        at net.starlark.java.eval.Eval.execIf(Eval.java:205)
        at net.starlark.java.eval.Eval.exec(Eval.java:283)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:82)

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Create a large java project that has lots of java plugins attached to each target. I'm able to repro with one of our smaller apps which has about 583 java targets, most of which have annotation processors.

@Bencodes
Copy link
Contributor Author

@comius FYI I think you added this commit.

@comius comius added team-Rules-Java Issues for Java rules untriaged labels Nov 17, 2021
@comius
Copy link
Contributor

comius commented Nov 17, 2021

I would need a reproducer for this, can you provide one?

It seems though rules_kotlin are at fault, what version are you using? Does changing the rules_kotlin version make things better/worse?

Is there something useful in the heapdump? You're looking for a large number of JavaPluginInfo/JavaOutputs. To get a heap dump increase memory using --host_jvm_args=-Xmx18g and run jmap -histo:live $BAZEL_PID.

Ideally I would compare a heapdump before and after the commit f73e28c.

@Bencodes
Copy link
Contributor Author

Bencodes commented Nov 17, 2021

It seems though rules_kotlin are at fault, what version are you using? Does changing the rules_kotlin version make things better/worse?

We are using an up to date version of rules Kotlin that has the JavaPluginInfo patches in it.

Is there something useful in the heapdump? You're looking for a large number of JavaPluginInfo/JavaOutputs. To get a heap dump increase memory using --host_jvm_args=-Xmx18g and run jmap -histo:live $BAZEL_PID.

I'll work on getting a heap dump.

@Bencodes
Copy link
Contributor Author

Heap for 5.0.0 RC2 jmapd-5.0.0-RC2.txt
Heap for 5.0.0 RC2 with f73e28c reverted jmapd-5.0.0-RC2-with-revert.txt

@Bencodes
Copy link
Contributor Author

The stack trace is a bit off compared to rules_kotlin HEAD. The call at io_bazel_rules_kotlin/kotlin/internal/jvm/compile.bzl:780 is the call to java_info = java_common.compile(...)

@meisterT
Copy link
Member

Cc @Wyverald

@comius
Copy link
Contributor

comius commented Nov 17, 2021

Comparison of heap dumps show insane increase in object arrays and some increase in integer arrays:

 objsize  chg   instances       space KB    class name
------------------------------------------------------
      99 +20426     -435368    26237030 KB    [Ljava.lang.Object;
      44 +1161      -85749       71739 KB    [I

merge call using a list for javaOutputs looks to be at fault here:
f73e28c#diff-f5262116f466c897bb45cfb13277e052945b108e22245b50b1d98cc6f9d3f398R172

@comius
Copy link
Contributor

comius commented Nov 17, 2021

Can you check if #14288 fixes it? Perhaps provide new heapdump.

@Bencodes
Copy link
Contributor Author

The heap looks much better with that commit pulled in. jmapd-patched.txt

The heap for a larger app jmapd-patched-larger-app.txt

@comius comius added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Nov 17, 2021
@comius comius self-assigned this Nov 17, 2021
@comius
Copy link
Contributor

comius commented Nov 17, 2021

Comparing jmap reverted and patched, there is even 34MB improvement.

@Wyverald Wyverald added this to the Bazel 5.0 Release Blockers milestone Nov 17, 2021
@Wyverald
Copy link
Member

Thanks for flagging @meisterT. Let's get the fix cherrypicked into the rc2 branch.

@Wyverald Wyverald reopened this Nov 17, 2021
Wyverald pushed a commit that referenced this issue Nov 19, 2021
JavaPluginInfo merging of java_outputs caused a significant regression when a large number of plugins is present.

This value is not used by native code and it does not get exposed to Starlark. The only use case for java_outputs is IDE integrations, where the value is used from a single java_plugin target.

Fixes #14287

Closes #14288.

PiperOrigin-RevId: 410502716
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants