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

Use @argument files in the Java binary wrapper script #6354

Open
cushon opened this issue Oct 10, 2018 · 20 comments
Open

Use @argument files in the Java binary wrapper script #6354

cushon opened this issue Oct 10, 2018 · 20 comments
Labels
not stale Issues or PRs that are inactive but not considered stale P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request

Comments

@cushon
Copy link
Contributor

cushon commented Oct 10, 2018

The Java binary wrapper script works around command line length limits by creating a jar file with a Class-Path manifest entry containing the long classpath (related: #6289).

JDK 9 adds support for flag files using the @argument-file syntax, see "java Command-Line Argument Files" in https://docs.oracle.com/javase/9/tools/java.htm.

We should use that instead of the manifest jar hack when targeting JDK 9.

We could back-fill support for that syntax for older --javabase versions by adding logic to the wrapper script.

@petroseskinder
Copy link
Member

petroseskinder commented Oct 15, 2018

@cushon will this change resolve the long classpath issue documented in #6289?
Additionally, is there anything we can do in the ensuing time period to stop the bleeding?

We have ran unused_deps and have removed all obviously unnecessary dependencies.

@cushon
Copy link
Contributor Author

cushon commented Oct 15, 2018

(previous bug about @argfiles: #1392)

@cushon
Copy link
Contributor Author

cushon commented Oct 15, 2018

@petroseskinder I filed this as a reminder to look at @argfiles if/when it's worth adding features that only work for JDK > 9. I think we need a different short-term fix for #6289.

@petroseskinder
Copy link
Member

I see. Thank you. Does the suggestion by @brown suffice for the short term (pre-JDK >9) fix?

@cushon
Copy link
Contributor Author

cushon commented Oct 17, 2018

I actually didn't realize there was a patch there because github mangled the formatting :/
I left a comment: #6289 (comment)

@laszlocsomor
Copy link
Contributor

laszlocsomor commented Jan 7, 2019

#6471 was pushed on 2018-10-29, and IIUC it fixed #6289. According to GitHub this patch is included in Bazel 0.20.0.

@petroseskinder : did this Bazel version "stop the bleeding" with older JDKs?
@cushon : with #6289 fixed, what's the motivation to resolve this bug, is it just to avoid writing a classpath jar if we can get away with writing an argument file?

@cushon
Copy link
Contributor Author

cushon commented Jan 7, 2019

what's the motivation to resolve this bug

I don't see any reason to prefer the current approach over @argument files, aside from supporting legacy JDK versions? @argument files are a standard solution to the same problem that probably performs better and won't need maintenance in the future.

@lberki lberki added P3 We're not considering working on this, but happy to review a PR. (No assignee) P2 We'll consider working on this in future. (Assignee optional) and removed untriaged P3 We're not considering working on this, but happy to review a PR. (No assignee) labels Mar 14, 2019
@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed P2 We'll consider working on this in future. (Assignee optional) labels Nov 21, 2020
@ittaiz
Copy link
Member

ittaiz commented Jul 13, 2022

Should this be fixed? Like @cushon I have a hunch (no data unfortunately) that using an argument file will perform better than a classpath jar

@cushon
Copy link
Contributor Author

cushon commented Jul 13, 2022

I think the main challenge is that we can only rely on this feature for JDK 9 and newer.

There was some related discussion prompted by https://github.com/bazelbuild/bazel/pull/15487/files

One option is to add some information to java_runtime that tells Bazel if it can rely on argument files, e.g.

  • java_runtime(..., supports_params_files = True)
  • java_runtime(..., feature_version = 9)
  • java_runtime(..., features = ["params_file"], ...)

@ittaiz
Copy link
Member

ittaiz commented Jul 14, 2022

I see. Thanks.
For better and for worse rules_scala has its own fork of java_stub_template so it can do this for itself.

@ittaiz
Copy link
Member

ittaiz commented Jul 14, 2022

@cushon isn't the version already accessible on the toolchain now? I forgot already what it contains but the Java version sounds like something that should be there and then in the template you "just" check if it's bigger than 8

@ittaiz
Copy link
Member

ittaiz commented Jul 14, 2022

One last thing (and really sorry for spamming) but from a few runs this is shaving for us 1s-1.5s internally and we have thousands of not more of test targets with large class paths (partially because we have fine grain build targets)

@cushon
Copy link
Contributor Author

cushon commented Jul 14, 2022

I forgot already what it contains but the Java version sounds like something that should be there

There isn't anything in java_runtime that reliably declares what version the toolchain is.

from a few runs this is shaving for us 1s-1.5s internally and we have thousands of not more of test targets with large class paths (partially because we have fine grain build targets)

Nice! This is definitely something I'd like to see happen, we just need a way to do it conditionally for newer JDKs, or wait for JDK 8 support to be dropped.

And I think for Google we're not seeing this be a bottleneck because we're not relying on the Class-Path jar logic, our JDK has a higher command line length limit.

@ittaiz
Copy link
Member

ittaiz commented Jul 15, 2022

Thanks!
We'll roll out the change today or on Sunday probably but this is a divergence I obviously would like to remove.
Btw, the measurement is on my M1. We still have many people on intel chips and my colleagues tell me that there this preparation takes ~4s on many targets.
Really interested in the full rollout 😁🤞🏽

@ittaiz
Copy link
Member

ittaiz commented Nov 10, 2022

@cushon do you know if there are any plans on dropping JDK 8 support?

benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 14, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 14, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 14, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 14, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 14, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 14, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 14, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 21, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 21, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 21, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
benjaminp added a commit to benjaminp/bazel that referenced this issue Mar 21, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)
copybara-service bot pushed a commit that referenced this issue Mar 23, 2023
1. As suggested in #6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes #14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)

Closes #17775.

PiperOrigin-RevId: 518860040
Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6
ShreeM01 pushed a commit to ShreeM01/bazel that referenced this issue Mar 24, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)

Closes bazelbuild#17775.

PiperOrigin-RevId: 518860040
Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6
ShreeM01 pushed a commit to ShreeM01/bazel that referenced this issue Mar 28, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)

Closes bazelbuild#17775.

PiperOrigin-RevId: 518860040
Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6
hvadehra pushed a commit that referenced this issue Mar 29, 2023
1. As suggested in #6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes #14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)

Closes #17775.

PiperOrigin-RevId: 518860040
Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6

(cherry picked from commit 7556e11)
hvadehra added a commit that referenced this issue Mar 31, 2023
As suggested in Use @argument files in the Java binary wrapper script #6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes Bazel@HEAD on JDK 17: GoogleTestSecurityManager WARNING: System::setSecurityManager will be removed in a future release #14502.

To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)

Closes #17775.

PiperOrigin-RevId: 518860040
Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6
hvadehra pushed a commit that referenced this issue Apr 3, 2023
1. As suggested in #6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes #14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)

Closes #17775.

PiperOrigin-RevId: 518860040
Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6

(cherry picked from commit 7556e11)
meteorcloudy pushed a commit that referenced this issue Apr 3, 2023
* Add version to JavaRuntimeInfo.

1. As suggested in #6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes #14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)

Closes #17775.

PiperOrigin-RevId: 518860040
Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6

(cherry picked from commit 7556e11)

* Use string.replace() instead of string.format() to avoid issues with select{} in the template string

* Remove test and fix formatting

* Fix starlark_repository_test

Change the grep pattern to exactly match what the test is looking for. The old pattern would match BUILD file content from the jdk_build_file.bzl template

---------

Co-authored-by: Benjamin Peterson <[email protected]>
fweikert pushed a commit to fweikert/bazel that referenced this issue May 25, 2023
1. As suggested in bazelbuild#6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version.

2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes bazelbuild#14502.

3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.)

Closes bazelbuild#17775.

PiperOrigin-RevId: 518860040
Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jan 19, 2024
@cushon
Copy link
Contributor Author

cushon commented Jan 19, 2024

If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

Please keep this one open for now

@meteorcloudy meteorcloudy added not stale Issues or PRs that are inactive but not considered stale and removed stale Issues or PRs that are stale (no activity for 30 days) labels Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not stale Issues or PRs that are inactive but not considered stale P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request
Projects
None yet
Development

No branches or pull requests

8 participants