Repository: bazelbuild/bazel
Issue: Update embedded JDK to 11 to fix a host of docker related issues
Labels: type: feature request
P2
area-EngProd
team-Rules-Java
team-OSS

### Description of the problem / feature request:

As far as I can tell bazel is currently coming embedded with openjdk 9 and it is having issues with easily running out of memory in docker containers (most prominently CircleCI it seems), or more generically not respecting cgroups for resource limits.

issues I could find that seem releated:
https://github.com/bazelbuild/bazel/issues/3886
https://github.com/bazelbuild/bazel/issues/4616
https://github.com/bazelbuild/bazel/issues/5180
https://github.com/bazelbuild/bazel/issues/3645
https://github.com/bazelbuild/bazel/issues/5389

https://github.com/bazelbuild/rules_docker/issues/520

### Feature requests: what underlying problem are you trying to solve with this feature?

It turns out OpenJDK 10 comes with a host of fixes that would improve that situation and for us also just seemed to have solved an issue with using CircleCI. I installed bazel pointing at jdk 11 using `startup --server_javabase /usr/lib/jvm/java-11-openjdk-amd64/"` in the bazelrc, removed any flags around `local_resources` and builds that would continuously fail before are now working, in fact I had a build that would even fail with `local_resources` and `-Xmx3072m` set, but pointing bazel to use jdk 11 fixed that.

Here the links to the openjdk issues:
https://bugs.openjdk.java.net/browse/JDK-8196595
https://bugs.openjdk.java.net/browse/JDK-8146115
https://bugs.openjdk.java.net/browse/JDK-8170888
https://bugs.openjdk.java.net/browse/JDK-8140793

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Probably not that easy to reproduce, but I know rules_nodejs use circleci and had similar issues in the past that where solved with setting the same flags here: https://github.com/bazelbuild/rules_nodejs/blob/master/.circleci/bazel.rc#L17

So maybe they would be a good test case, trying to remove the flags and see if the situation improves. cc @alexeagle

### What operating system are you running Bazel on?

Ubuntu 18.04, the docker images are running on debian stretch

### What's the output of `bazel info release`?

release 0.19.0

###  Have you found anything relevant by searching the web?

Yep, see issues linked above.

Issue comments:
Cc @lberki @iirina 
Related: #6661.
@Monnoroch There's no requirement anymore to have the same embedded JDK version as we use for the host javabase so #6661 is talking about updating the JDK version, it's a different JDK.

Independently, we also plan to upgrade the embedded JDK after we have submitted some other changes and hopefully it'll land before we cut 0.22.

If I understand the new java container support correctly, you probably still want to set a JVM flag in the container. The JVM uses by default 1/4 of the physical available memory for the heap. In a container, you may have less memory available than what's physically in your machine. Now, if the heap grows too large, Bazel gets killed. With the new container support, the "physical available memory" is limited to the memory available in the container. Thus, the heap will not grow too large, but it's using 1/4 of the available memory. That may not be enough and you might want to set MaxRamFraction in your CI environment.

> Independently, we also plan to upgrade the embedded JDK after we have submitted some other changes and hopefully it'll land before we cut 0.22.

I tried 0.22rc2 yesterday and it is still using JDK 9.
David, that's correct. I wasn't able to properly test and land the changes mostly because of holidays. I'll definitely do it before 0.23.
@meisterT Thanks. Let me know, if you have a commit somewhere. I would be happy to build Bazel from scratch and test it against Gerrit Code Review and related projects.

Pull request review comments:

Patch that resolved the issue:
diff --git a/WORKSPACE b/WORKSPACE
index 7f4b66eb29a675..1b8f7685255a43 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -131,9 +131,9 @@ http_file(
 http_file(
     name = "openjdk_linux_vanilla",
     downloaded_file_path = "zulu-linux-vanilla.tar.gz",
-    sha256 = "232b1c3511f0d26e92582b7c3cc363be7ac633e371854ca2f2e9f2b50eb72a75",
+    sha256 = "f3f44b6235508e87b760bf37a49e186cc1fa4e9cd28384c4dbf5a33991921e08",
     urls = [
-        "https://mirror.bazel.build/openjdk/azul-zulu11.2.3-jdk11.0.1/zulu11.2.3-jdk11.0.1-linux_x64.tar.gz",
+        "https://mirror.bazel.build/openjdk/azul-zulu11.29.3-ca-jdk11.0.2/zulu11.29.3-ca-jdk11.0.2-linux_x64.tar.gz",
     ],
 )
 
@@ -170,9 +170,9 @@ http_file(
 http_file(
     name = "openjdk_macos_vanilla",
     downloaded_file_path = "zulu-macos-vanilla.tar.gz",
-    sha256 = "1edf366ee821e5db8e348152fcb337b28dfd6bf0f97943c270dcc6747cedb6cb",
+    sha256 = "059f8e3484bf07b63a8f2820d5f528f473eff1befdb1896ee4f8ff06be3b8d8f",
     urls = [
-        "https://mirror.bazel.build/openjdk/azul-zulu11.2.3-jdk11.0.1/zulu11.2.3-jdk11.0.1-macosx_x64.tar.gz",
+        "https://mirror.bazel.build/openjdk/azul-zulu11.29.3-ca-jdk11.0.2/zulu11.29.3-ca-jdk11.0.2-macosx_x64.zip",
     ],
 )
 
@@ -197,9 +197,9 @@ http_file(
 http_file(
     name = "openjdk_win_vanilla",
     downloaded_file_path = "zulu-win-vanilla.zip",
-    sha256 = "8e1e2b8347de6746f3fd1538840dd643201533ab113abc4ed93678e342d28aa3",
+    sha256 = "e1f5b4ce1b9148140fae2fcfb8a96d1c9b7eac5b8df0e13fbcad9b8561284880",
     urls = [
-        "https://mirror.bazel.build/openjdk/azul-zulu11.2.3-jdk11.0.1/zulu11.2.3-jdk11.0.1-win_x64.zip",
+        "https://mirror.bazel.build/openjdk/azul-zulu11.29.3-ca-jdk11.0.2/zulu11.29.3-ca-jdk11.0.2-win_x64.zip",
     ],
 )
 
@@ -282,6 +282,9 @@ distdir_tar(
         "zulu11.2.3-jdk11.0.1-linux_x64.tar.gz",
         "zulu11.2.3-jdk11.0.1-macosx_x64.tar.gz",
         "zulu11.2.3-jdk11.0.1-win_x64.zip",
+        "zulu11.29.3-ca-jdk11.0.2-linux_x64.tar.gz",
+        "zulu11.29.3-ca-jdk11.0.2-macosx_x64.zip",
+        "zulu11.29.3-ca-jdk11.0.2-win_x64.zip",
     ],
     dirname = "jdk_WORKSPACE/distdir",
     sha256 = {
@@ -297,6 +300,9 @@ distdir_tar(
         "zulu11.2.3-jdk11.0.1-linux_x64.tar.gz": "232b1c3511f0d26e92582b7c3cc363be7ac633e371854ca2f2e9f2b50eb72a75",
         "zulu11.2.3-jdk11.0.1-macosx_x64.tar.gz": "1edf366ee821e5db8e348152fcb337b28dfd6bf0f97943c270dcc6747cedb6cb",
         "zulu11.2.3-jdk11.0.1-win_x64.zip": "8e1e2b8347de6746f3fd1538840dd643201533ab113abc4ed93678e342d28aa3",
+        "zulu11.29.3-ca-jdk11.0.2-linux_x64.tar.gz": "f3f44b6235508e87b760bf37a49e186cc1fa4e9cd28384c4dbf5a33991921e08",
+        "zulu11.29.3-ca-jdk11.0.2-macosx_x64.zip": "059f8e3484bf07b63a8f2820d5f528f473eff1befdb1896ee4f8ff06be3b8d8f",
+        "zulu11.29.3-ca-jdk11.0.2-win_x64.zip": "e1f5b4ce1b9148140fae2fcfb8a96d1c9b7eac5b8df0e13fbcad9b8561284880",
     },
     urls = {
         "zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules.tar.gz"],
@@ -311,6 +317,9 @@ distdir_tar(
         "zulu11.2.3-jdk11.0.1-linux_x64.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu11.2.3-jdk11.0.1/zulu11.2.3-jdk11.0.1-linux_x64.tar.gz"],
         "zulu11.2.3-jdk11.0.1-macosx_x64.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu11.2.3-jdk11.0.1/zulu11.2.3-jdk11.0.1-macosx_x64.tar.gz"],
         "zulu11.2.3-jdk11.0.1-win_x64.zip": ["https://mirror.bazel.build/openjdk/azul-zulu11.2.3-jdk11.0.1/zulu11.2.3-jdk11.0.1-win_x64.zip"],
+        "zulu11.29.3-ca-jdk11.0.2-linux_x64.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu11.29.3-ca-jdk11.0.2/zulu11.29.3-ca-jdk11.0.2-linux_x64.tar.gz"],
+        "zulu11.29.3-ca-jdk11.0.2-macosx_x64.zip": ["https://mirror.bazel.build/openjdk/azul-zulu11.29.3-ca-jdk11.0.2/zulu11.29.3-ca-jdk11.0.2-macosx_x64.zip"],
+        "zulu11.29.3-ca-jdk11.0.2-win_x64.zip": ["https://mirror.bazel.build/openjdk/azul-zulu11.29.3-ca-jdk11.0.2/zulu11.29.3-ca-jdk11.0.2-win_x64.zip"],
     },
 )
 


Test patch: