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 0.16: Unrecognized VM Option "CompactStrings" #5726

Closed
robfig opened this issue Aug 1, 2018 · 15 comments
Closed

Bazel 0.16: Unrecognized VM Option "CompactStrings" #5726

robfig opened this issue Aug 1, 2018 · 15 comments
Assignees

Comments

@robfig
Copy link

robfig commented Aug 1, 2018

Description of the problem / feature request:

Upgrading from 0.15 to 0.16 results in this error when building any java_library

ERROR: /Users/robfig/alpha/thirdparty/heapster/BUILD:39:1: Building thirdparty/heapster/libheapster-java.jar (1 source file) failed: Worker process did not return a WorkResponse:

---8<---8<--- Start of log, file at /private/var/tmp/_bazel_robfig/1db08896ecff7e5e96a745981c3b77e6/bazel-workers/worker-0-Javac.log ---8<---8<---
Unrecognized VM option 'CompactStrings'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
---8<---8<--- End of log ---8<---8<---

Re-running the command shows me a similar error message, this time including the command

ERROR: /Users/robfig/alpha/src/com/corp/util/propagate/BUILD:3:1: Compiling Java headers src/com/corp/util/propagate/libpropagate-hjar.jar (2 files) failed (Exit 1): java failed: error executing command
  (cd /private/var/tmp/_bazel_robfig/1db08896ecff7e5e96a745981c3b77e6/execroot/corp && \
  exec env - \
  external/local_jdk/bin/java -Xverify:none -XX:+UseParallelOldGC -XX:-CompactStrings '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' '--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--patch-module=java.compiler=external/bazel_tools/third_party/java/jdk/langtools/java_compiler.jar' '--patch-module=jdk.compiler=external/bazel_tools/third_party/java/jdk/langtools/jdk_compiler.jar' '--add-opens=java.base/java.nio=ALL-UNNAMED' -jar external/bazel_tools/tools/jdk/turbine_deploy.jar --output bazel-out/darwin-fastbuild/bin/src/com/corp/util/propagate/libpropagate-hjar.jar --output_deps bazel-out/darwin-fastbuild/bin/src/com/corp/util/propagate/libpropagate-hjar.jdeps --temp_dir bazel-out/darwin-fastbuild/bin/src/com/corp/util/propagate/_javac/propagate/libpropagate-hjar_temp --bootclasspath external/local_jdk/jre/lib/rt.jar external/local_jdk/jre/lib/resources.jar external/local_jdk/jre/lib/jsse.jar external/local_jdk/jre/lib/jce.jar external/local_jdk/jre/lib/charsets.jar external/local_jdk/jre/lib/ext/cldrdata.jar external/local_jdk/jre/lib/ext/dnsns.jar external/local_jdk/jre/lib/ext/jaccess.jar external/local_jdk/jre/lib/ext/jfxrt.jar external/local_jdk/jre/lib/ext/localedata.jar external/local_jdk/jre/lib/ext/nashorn.jar external/local_jdk/jre/lib/ext/sunec.jar external/local_jdk/jre/lib/ext/sunjce_provider.jar external/local_jdk/jre/lib/ext/sunpkcs11.jar external/local_jdk/jre/lib/ext/zipfs.jar --sources src/com/corp/util/propagate/PropagatedValue.java src/com/corp/util/propagate/Propagator.java --javacopts -source 8 -target 8 '-XDskipDuplicateBridges=true' -g -parameters -- --target_label //src/com/corp/util/propagate:propagate)

Use --sandbox_debug to see verbose messages from the sandbox
Unrecognized VM option 'CompactStrings'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
INFO: Elapsed time: 0.793s, Critical Path: 0.31s
INFO: 3 processes: 3 darwin-sandbox.
FAILED: Build did NOT complete successfully

I believe this happens because my system Java is JDK8, and Bazel is using it by default (the local_jdk reference). However, it is passing a parameter only understood by Java 9.

This appears to have been added by this commit, by @buchgr :
3842bd3

Is it expected that bazel no longer works on systems with JDK 8 installed? Is there a way to cause bazel to use the embedded JDK and do you recommend that (or are there other downsides)?

Thank you,
Rob

What operating system are you running Bazel on?

Mac OS High Sierra

What's the output of bazel info release?

release 0.16.0

Have you found anything relevant by searching the web?

I haven't found any other reports of this.

@buchgr
Copy link
Contributor

buchgr commented Aug 2, 2018

Hi,

we changed the default toolchain to JDK9. If you would like to use JDK8, you can specify the JDK8 toolchain by adding build --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 to your .bazelrc.

@buchgr buchgr closed this as completed Aug 2, 2018
@robfig
Copy link
Author

robfig commented Aug 2, 2018

Thank you for the guidance. How would I use the embedded JDK instead?
(I looked through bazel/tools/jdk/BUILD and associated files and didn't see anything obvious)

@cushon
Copy link
Contributor

cushon commented Aug 2, 2018

The embedded JDK is the default server and host javabase. Are you passing any javabase flags to the build? And do you have a self-contained example that reproduces the issue you're seeing?

@cushon cushon reopened this Aug 2, 2018
@buchgr
Copy link
Contributor

buchgr commented Aug 2, 2018

@robfig the embedded jdk should be the default. I assumed you were overwriting the embedded with your own?

@robfig
Copy link
Author

robfig commented Aug 2, 2018

I'm not intentionally overriding it, no.

We use no-argument "bazel build" and "bazel test" commands. There's nothing relevant in our WORKSPACE afaik, but here's our bazel.rc:
https://gist.github.com/robfig/189641a65dfa39f08575b6cfaf0bbfc6

Example target

package(default_visibility = ["//visibility:public"])

java_library(
    name = "function",
    srcs = glob(["*.java"]),
    deps = [
        "//thirdparty:google-guava",
        "//thirdparty:jsr305",
    ],
)

Without that --java_toolchain override in the bazel.rc, I get the CompactStrings failure.

$ bazel version
Build label: 0.16.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Jul 31 17:10:14 2018 (1533057014)
Build timestamp: 1533057014
Build timestamp as int: 1533057014

$ bazel build src/com/corp/util/function/...
INFO: Build options have changed, discarding analysis cache.
INFO: Analysed target //src/com/corp/util/function:function (0 packages loaded).
INFO: Found 1 target...
ERROR: /Users/robfig/alpha/src/com/corp/util/function/BUILD:3:1: Building src/com/corp/util/function/libfunction.jar (2 source files) failed: Worker process did not return a WorkResponse:

---8<---8<--- Start of log, file at /private/var/tmp/_bazel_robfig/1db08896ecff7e5e96a745981c3b77e6/bazel-workers/worker-12-Javac.log ---8<---8<---
Unrecognized VM option 'CompactStrings'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
---8<---8<--- End of log ---8<---8<---
Target //src/com/corp/util/function:function failed to build
INFO: Elapsed time: 0.751s, Critical Path: 0.05s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Passing -s shows that it's using local_jdk

This is a proprietary codebase, so I'm afraid I can't share it.

Any ideas?

@robfig
Copy link
Author

robfig commented Aug 2, 2018

We discovered that it's this flag

# Disable distinct host configuration so that we avoid rebuilding libraries twice
build --distinct_host_configuration=false

Setting that back to true causes it to use the embedded JDK again. I recall I added this flag because it seemed that libraries were being built twice. I'll investigate furtther.

@cushon
Copy link
Contributor

cushon commented Aug 2, 2018

Ah, that makes sense. There's another bug for that: #5572

@cushon cushon closed this as completed Aug 2, 2018
@robfig
Copy link
Author

robfig commented Aug 7, 2018

Can you confirm the recommended next steps?

I see these options for us:

  • Wait for a point release fixing that issue
  • Remove the --nodistinct_host_configuration flag (which seems like it would slow builds by a decent amount in our pure JVM repo)
  • Leave --nodistinct_host_configuration and add these flags: --host_javabase=@bazel_tools//tools/jdk:jdk and --javabase=@bazel_tools//tools/jdk:jdk (untested)
  • Use the Host JDK instead of the embedded JDK and add --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 (undesirable compared to using embedded)

Thanks @cushon!

@cushon
Copy link
Contributor

cushon commented Aug 7, 2018

cc @buchgr

I tentatively think some of this is going to be fixed by a point release together with #5744 and #5594.

JDK 8 is not going to be supported as a host_javabase for that much longer, though, at which point using --nodistinct_host_configuration would require using a JDK 9 as both the host and target javabase.

@robfig
Copy link
Author

robfig commented Aug 14, 2018

I tried out 0.16.1, but ran into issues with both jdk9 and jdk8.

With these flags

build --distinct_host_configuration=false

build --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build --host_javabase=@bazel_tools//tools/jdk:jdk
build --javabase=@bazel_tools//tools/jdk:jdk

My understanding is that those flags should use my workstation's JDK, but I get this error for our crypto package, which seems to say it's using java 9 for compiling, and not including jce.jar on the bootclasspath.

ERROR: /Users/robfig/alpha/src/com/corp/util/crypto/BUILD:3:1: Building src/com/corp/util/crypto/libEncryptor.jar (3 source files) failed (Exit 1): java failed: error executing command
  (cd /private/var/tmp/_bazel_robfig/1db08896ecff7e5e96a745981c3b77e6/execroot/corp && \
  exec env - \
    LC_CTYPE=en_US.UTF-8 \
  external/local_jdk/bin/java -Xbootclasspath/p:external/bazel_tools/third_party/java/jdk/langtools/javac-9+181-r4173-1.jar -jar external/bazel_tools/tools/jdk/JavaBuilder_deploy.jar @bazel-out/darwin-fastbuild/bin/src/com/corp/util/crypto/libEncryptor.jar-2.params)
src/com/corp/util/crypto/Encryptor.java:11: error: package javax.crypto does not exist
import javax.crypto.Cipher;
                   ^
...

Trying to use the embedded JDK, with these flags

build --distinct_host_configuration=false

build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java9
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_java9
build --host_javabase=@bazel_tools//tools/jdk:host_jdk
build --javabase=@bazel_tools//tools/jdk:host_jdk

Returns a bug that looks like an issue with JDK9, but not JDK8 or JDK10. I guess I can write a program to scan all our jars to find which one the issue resides in and repackage it, then perhaps this approach will work.

https://bugs.java.com/view_bug.do?bug_id=8194730

ERROR: /Users/robfig/alpha/src/com/corp/config/BUILD:18:1: Building src/com/corp/config/libprotobuf.jar (1 source jar) failed (Exit 1): java failed: error executing command
  (cd /private/var/tmp/_bazel_robfig/1db08896ecff7e5e96a745981c3b77e6/execroot/corp && \
  exec env - \
    LC_CTYPE=en_US.UTF-8 \
  external/embedded_jdk/bin/java -XX:+UseParallelOldGC -XX:-CompactStrings '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' '--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--patch-module=java.compiler=external/bazel_tools/third_party/java/jdk/langtools/java_compiler.jar' '--patch-module=jdk.compiler=external/bazel_tools/third_party/java/jdk/langtools/jdk_compiler.jar' '--add-opens=java.base/java.nio=ALL-UNNAMED' -jar external/bazel_tools/tools/jdk/JavaBuilder_deploy.jar @bazel-out/darwin-fastbuild/bin/src/com/corp/config/libprotobuf.jar-2.params)
java.time.DateTimeException: Invalid value for MonthOfYear (valid values 1 - 12): 0
	at java.base/java.time.temporal.ValueRange.checkValidValue(Unknown Source)
	at java.base/java.time.temporal.ChronoField.checkValidValue(Unknown Source)
	at java.base/java.time.LocalDate.of(Unknown Source)
	at java.base/java.time.LocalDateTime.of(Unknown Source)
	at jdk.zipfs/jdk.nio.zipfs.ZipUtils.dosToJavaTime(Unknown Source)
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem$Entry.cen(Unknown Source)
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem$Entry.readCEN(Unknown Source)
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.getEntry(Unknown Source)
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.getFileAttributes(Unknown Source)
	at jdk.zipfs/jdk.nio.zipfs.ZipPath.getAttributes(Unknown Source)
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.readAttributes(Unknown Source)
	at java.base/java.nio.file.Files.readAttributes(Unknown Source)
	at java.base/java.nio.file.FileTreeWalker.getAttributes(Unknown Source)
	at java.base/java.nio.file.FileTreeWalker.visit(Unknown Source)
	at java.base/java.nio.file.FileTreeWalker.next(Unknown Source)
	at java.base/java.nio.file.Files.walkFileTree(Unknown Source)
	at java.base/java.nio.file.Files.walkFileTree(Unknown Source)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.setUpSourceJars(SimpleJavaLibraryBuilder.java:200)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.prepareSourceCompilation(SimpleJavaLibraryBuilder.java:56)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:114)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:133)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.processRequest(BazelJavaBuilder.java:105)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.runPersistentWorker(BazelJavaBuilder.java:67)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.main(BazelJavaBuilder.java:45)

As an aside, the naming of tools/jdk:host_jdk vs tools/jdk:jdk seems backwards from what I would expect. host_jdk seems to refer to the embedded jdk, rather than the one installed on the host. Thinking I might be wrong on that point, I tried this combination, with the associated error:

build --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build --host_javabase=@bazel_tools//tools/jdk:host_jdk
build --javabase=@bazel_tools//tools/jdk:host_jdk
...
ERROR: /Users/robfig/alpha/test/com/corp/util/csv/BUILD:5:1: Building test/com/corp/util/csv/libresources-class.jar () failed: Worker process returned an unparseable WorkResponse!

---8<---8<--- Start of log ---8<---8<---
-Xbootclasspath/p is no longer a supported option.
ion.
---8<---8<--- End of log ---8<---8<---

I'll continue working on getting our codebase buildable with JDK9.

Thanks

@buchgr buchgr removed their assignment Aug 14, 2018
@cushon
Copy link
Contributor

cushon commented Aug 14, 2018

the naming of tools/jdk:host_jdk vs tools/jdk:jdk seems backwards from what I would expect. host_jdk seems to refer to the embedded jdk, rather than the one installed on the host.

tools/jdk:host_jdk and tools/jdk:jdk are the default values of --javabase and --host_javabase. They shouldn't usually be used directly.

--distinct_host_configuration should work if you set --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 --host_java_toolch ain=@bazel_tools//tools/jdk:toolchain_hostjdk8 with a JDK 8 javabase, which you can get by setting JAVA_HOME or defining a java_runtime for a JDK 8 and setting --javabase and --host_javabase to the label of that java_runtime.

@robfig
Copy link
Author

robfig commented Aug 14, 2018

Ah, thanks for the explanation. That combination still leads to an error with JAVA_HOME:

build --distinct_host_configuration=false
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
...

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home

$ bazel test -j 4  test/com/corp/util/...
ERROR: /Users/robfig/alpha/src/com/corp/util/crypto/BUILD:3:1: Building src/com/corp/util/crypto/libEncryptor.jar (3 source files) failed (Exit 1): java failed: error executing command
  (cd /private/var/tmp/_bazel_robfig/1db08896ecff7e5e96a745981c3b77e6/execroot/corp && \
  exec env - \
    LC_CTYPE=en_US.UTF-8 \
  external/local_jdk/bin/java -Xbootclasspath/p:external/bazel_tools/third_party/java/jdk/langtools/javac-9+181-r4173-1.jar -jar external/bazel_tools/tools/jdk/JavaBuilder_deploy.jar @bazel-out/darwin-fastbuild/bin/src/com/corp/util/crypto/libEncryptor.jar-2.params)
src/com/corp/util/crypto/Encryptor.java:11: error: package javax.crypto does not exist
import javax.crypto.Cipher;
                   ^

I get the same error when running with a defined java_runtime:

java_runtime(
    name = "jdk8",
    java_home = "/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home",
)

build --distinct_host_configuration=false
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build --javabase=//tools:jdk8
build --host_javabase=//tools:jdk8

@cushon
Copy link
Contributor

cushon commented Aug 15, 2018

error: package javax.crypto does not exist
import javax.crypto.Cipher;
                   ^

That's because this line:

Path rtJar = path.resolve("jre/lib/rt.jar");

should include all of: rt.jar, resources.jar, jsse.jar, jce.jar, charsets.jar instead of just rt.jar.

I fixed this in #5894 (which mostly fixes #5888), but I'll leave this bug open until this part of the issue is resolved on way or another.

@cushon cushon reopened this Aug 15, 2018
@cushon cushon closed this as completed Aug 21, 2018
@robfig
Copy link
Author

robfig commented Sep 12, 2018

We are still waiting for 0.16.2 which will include the platform classpath fix to upgrade.. is there any place I can track it to verify that it will include the fix or see the progress it's making for planning purposes? Thanks!

@cushon
Copy link
Contributor

cushon commented Sep 12, 2018

@robfig 0.16.2 is being tracked by #6132

wchargin added a commit to tensorflow/tensorboard that referenced this issue Dec 6, 2018
Summary:
Bazel 0.20.0 introduced some incompatible changes that broke both our
code and our dependencies. Our dependencies also introduced some
incompatible changes of their own. This commit upgrades our dependencies
and fixes up our code to accommodate them.

An upgrade to transitive dependency `rules_go` introduces a dependency
on the `@bazel_tools//tools/build_defs/cc:action_names.bzl` builtin
target. This target was only introduced in Bazel 0.16.0, so as a
consequence our workspace is no longer compatible with earlier versions
of Bazel. In practice, we must use at least version 0.16.1 to fix a
regression in 0.16.0: <bazelbuild/bazel#5726>.

Unfortunately, Bazel 0.16.0 also introduced a regression that prevents
us from using the `--distinct_host_configuration=false` option; this has
not been fixed as of Bazel 0.20.0. As a result, parts of our build will
now be twice as slow.

The new `urllib3` dependency is due to a transitive Selenium upgrade.

This commit shifts our Bazel version window from [0.13.0, 0.19.2] to
[0.16.1, 0.20.0].

Test Plan:
Running `bazel test //tensorboard/...` passes in Python 2 and 3 in Bazel
versions 0.16.1 and 0.20.0 (latest at time of writing), with
the `.bazelrc` file set up as on Travis:

```sh
>~/.bazelrc
echo "startup --output_base=${HOME}/.bazel-output-base" >>~/.bazelrc
echo "startup --host_jvm_args=-Xms500m" >>~/.bazelrc
echo "startup --host_jvm_args=-Xmx500m" >>~/.bazelrc
echo "startup --host_jvm_args=-XX:-UseParallelGC" >>~/.bazelrc
echo "build --local_resources=400,2,1.0" >>~/.bazelrc
echo "build --worker_max_instances=2" >>~/.bazelrc
echo "build --worker_verbose" >>~/.bazelrc
echo "build --worker_sandboxing" >>~/.bazelrc
echo "build --spawn_strategy=sandboxed" >>~/.bazelrc
echo "build --genrule_strategy=sandboxed" >>~/.bazelrc
echo "test --test_verbose_timeout_warnings" >>~/.bazelrc
echo "build --verbose_failures" >>~/.bazelrc
echo "test --test_output=errors" >>~/.bazelrc
```

wchargin-branch: bazel-0.20.0-fixes
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

4 participants