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

Java 16 toolchain support #13270

Closed
davido opened this issue Mar 27, 2021 · 4 comments
Closed

Java 16 toolchain support #13270

davido opened this issue Mar 27, 2021 · 4 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules

Comments

@davido
Copy link
Contributor

davido commented Mar 27, 2021

Description of the problem / feature request:

Support for java 16 to be used with toolchain resolution for java rules, e.g. with this section in .bazelrc:

# Builds using remote_jdk16, executes using remote_jdk16 or local_jdk
build:java16 --java_language_version=16
build:java16 --java_runtime_version=16
build:java16 --tool_java_language_version=16
build:java16 --tool_java_runtime_version=16

This build command should fetch remote JDK 16 and produce major java version 16:

  $ bazeldev build --config=java16 gerrit

Feature requests: what underlying problem are you trying to solve with this feature?

Build Java code and produce major java version 16.

According to JDK 16 release schedule: [1] the general availability was announced on 2021/03/16.

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

  $ bazel build \
  --java_language_version=16 \
  --java_runtime_version=16 \
  --tool_java_language_version=16 \
  --tool_java_runtime_version=16 \
  gerrit

What operating system are you running Bazel on?

Linux.

What's the output of bazel info release?

Bazel@HEAD, Next major Bazel release (5.x) should include this feature.

Have you found anything relevant by searching the web?

There is a known issue with DumpPlatformClassPath.

[1] https://openjdk.java.net/projects/jdk/16

@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules labels Mar 27, 2021
@davido
Copy link
Contributor Author

davido commented Mar 27, 2021

As the workaround, I'm trying to add support for building with JDK16 using remote_java_repository and default_java_toolchain for Gerrit Code Review: [1].

Unfortunately it doesn't work yet:

  $ bazel build --config=java16 java/com/google/gerrit/common:server
  [...]
  xports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' ... (remaining 14 argument(s) skipped)
java.lang.IllegalArgumentException: error: invalid source release: 16
	at jdk.compiler/com.sun.tools.javac.main.Arguments.error(Arguments.java:907)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:383)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
	at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
	at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:114)
	at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.fallback(ReducedClasspathJavaLibraryBuilder.java:103)
	at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:65)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:110)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:118)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.build(BazelJavaBuilder.java:97)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.parseAndBuild(BazelJavaBuilder.java:77)
	at com.google.devtools.build.lib.worker.WorkRequestHandler.respondToRequest(WorkRequestHandler.java:115)
	at com.google.devtools.build.lib.worker.WorkRequestHandler.lambda$createResponseThread$0(WorkRequestHandler.java:98)
	at java.base/java.lang.Thread.run(Thread.java:831)
Target //java/com/google/gerrit/common:server failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.273s, Critical Path: 0.09s
INFO: 7 processes: 7 internal.
FAILED: Build did NOT complete successfully

Even though, the external OpenJDK was fetched as expected:

  $  /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/openjdk_16_linux/bin/java -fullversion
  openjdk full version "16+36"

@comius Any idea, what I am missing?

[1] https://gerrit-review.googlesource.com/c/gerrit/+/301362

davido added a commit to davido/bazel that referenced this issue Mar 28, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
davido added a commit to davido/bazel that referenced this issue Mar 30, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
davido added a commit to davido/bazel that referenced this issue Mar 30, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
davido added a commit to davido/bazel that referenced this issue Apr 2, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
davido added a commit to davido/bazel that referenced this issue Apr 2, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
@cushon
Copy link
Contributor

cushon commented Apr 4, 2021

what I am missing?

The JDK9_JVM_OPTS include --patch-module= flags which override the JDK's javac with the one from java_tools, which isn't a JDK 16 javac. That vendored javac version is only needed for older JDK versions, JDK 13 and newer include the fixes that are needed by Strict Java Deps.

diff --git a/tools/BUILD b/tools/BUILD
index c5f3691eae..2fb94b3947 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -1,8 +1,8 @@
 load(
     "@bazel_tools//tools/jdk:default_java_toolchain.bzl",
+    "BASE_JDK9_JVM_OPTS",
     "DEFAULT_JAVACOPTS",
     "DEFAULT_TOOLCHAIN_CONFIGURATION",
-    "JDK9_JVM_OPTS",
     "default_java_toolchain",
 )
 load("@rules_java//java:defs.bzl", "java_package_configuration")
@@ -13,7 +13,7 @@ default_java_toolchain(
     name = "toolchain_jdk_16",
     configuration = DEFAULT_TOOLCHAIN_CONFIGURATION,
     java_runtime = "@openjdk_16_linux//:jdk",
-    jvm_opts = JDK9_JVM_OPTS,
+    jvm_opts = BASE_JDK9_JVM_OPTS,
     misc = DEFAULT_JAVACOPTS,
     source_version = "16",
     target_version = "16",

davido added a commit to davido/bazel that referenced this issue Apr 4, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
@davido
Copy link
Contributor Author

davido commented Apr 4, 2021

@cushon Thanks, it's embarrassing I missed that.

I've updated gerrit CL: [1] and it works as expected. Unfortunately, I still need to patch Bazel with this PR.

[1] https://gerrit-review.googlesource.com/c/gerrit/+/301362

davido added a commit to davido/bazel that referenced this issue Apr 8, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
@davido
Copy link
Contributor Author

davido commented Apr 8, 2021

As can be seen from the failing coverage test with Java 16 toolchain:

  $ bazeldev test src/test/shell/bazel/bazel_coverage_java_jdk16_toolchain_released_test
  [...]
  java.io.IOException: Error while instrumenting bazel-out/k8-fastbuild/bin/_javac/collatz-lib/libcollatz-lib_classes/com/example/Collatz.class.
	at org.jacoco.core.instr.Instrumenter.instrumentError(Instrumenter.java:170)
	at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:120)
	at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:145)
	at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:165)
	at com.google.devtools.build.buildjar.instrumentation.JacocoInstrumentationProcessor$1.visitFile(JacocoInstrumentationProcessor.java:141)
	at com.google.devtools.build.buildjar.instrumentation.JacocoInstrumentationProcessor$1.visitFile(JacocoInstrumentationProcessor.java:113)
	at java.base/java.nio.file.Files.walkFileTree(Files.java:2804)
	at java.base/java.nio.file.Files.walkFileTree(Files.java:2876)
	at com.google.devtools.build.buildjar.instrumentation.JacocoInstrumentationProcessor.instrumentRecursively(JacocoInstrumentationProcessor.java:111)
	at com.google.devtools.build.buildjar.instrumentation.JacocoInstrumentationProcessor.processRequest(JacocoInstrumentationProcessor.java:85)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.buildJar(SimpleJavaLibraryBuilder.java:151)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:120)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.build(BazelJavaBuilder.java:99)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.parseAndBuild(BazelJavaBuilder.java:79)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.main(BazelJavaBuilder.java:63)
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 60
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:196)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:177)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:163)
	at org.jacoco.core.internal.instr.InstrSupport.classReaderFor(InstrSupport.java:247)
	at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:86)
	at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:118)
	... 13 more

JaCoCo version needs to be bumped to support Java 16.

An actually asm update is needed. Currently is asm 8.0 used in Bazel, but the Java 16 support was only added in ASM_9_0_BETA:

14 July 2020: ASM 9.0 beta (tag ASM_9_0_BETA)
JDK 16 support (sealed classes), new ASM9 api version

[1] https://asm.ow2.io/versions.html

bazel-io pushed a commit that referenced this issue Apr 14, 2021
Closes bazelbuild/java_tools#49
Closes #11674
Unblocks #13270, #13274.

Closes #13343.

PiperOrigin-RevId: 368428107
davido added a commit to davido/bazel that referenced this issue Apr 14, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
davido added a commit to davido/bazel that referenced this issue Apr 15, 2021
Closes bazelbuild#13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants