Silence protobuf sun.misc.Unsafe warnings from the direct header comp… - #375
Open
davido wants to merge 1 commit into
Open
Silence protobuf sun.misc.Unsafe warnings from the direct header comp…#375davido wants to merge 1 commit into
davido wants to merge 1 commit into
Conversation
davido
force-pushed
the
turbine-direct-unsafe-memory-access
branch
from
August 18, 2026 05:29
cf27565 to
68de125
Compare
hvadehra
requested changes
Aug 19, 2026
TurbineDirect bundles protobuf, whose UnsafeUtil calls terminally-deprecated sun.misc.Unsafe methods. On JDK 24+ (JEP 498), the JVM prints a warning for each such call during header compilation: WARNING: A terminally deprecated method in sun.misc.Unsafe has been called WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.google.protobuf.UnsafeUtil The direct header compiler has two invocation shapes. TurbineDirect's deploy jar runs as java -jar, but the prebuilt turbine_direct_graal tools are native binaries. Only the deploy jar can receive JVM options; the native binary parses the same values as Turbine CLI options and fails with: unknown option: --sun-misc-unsafe-memory-access=allow Expose a turbine_direct_jvm_opts java_toolchain attribute so toolchains can pass JVM options to the direct header compiler without reusing turbine_jvm_opts or hard-coding tool-specific policy in java_toolchain.bzl. Set the default toolchain's direct JVM opts only on platforms where //toolchains:turbine_direct falls back to the Java TurbineDirect deploy jar. Leave the option empty where turbine_direct_graal is selected. This select intentionally mirrors the //toolchains:turbine_direct select so the flag is not passed to native direct compilers. Also reject turbine_direct_jvm_opts when header_compiler_direct is a native executable. Without that guard an accidental configuration would reach turbine_direct_graal as Turbine command-line options and fail at execution time with a less clear "unknown option" error. Projects that use a deploy-jar direct header compiler can now set turbine_direct_jvm_opts in their java_toolchain. That setting is typically guarded by the same platform select that chooses the Java TurbineDirect deploy jar over native turbine_direct_graal. Add analysis tests for the new attribute: explicit direct JVM opts reach direct header compilation, no direct opts are injected by default, and regular turbine_jvm_opts do not apply to the direct compiler. Also test that the new attr rejects native direct header compilers. See protocolbuffers/protobuf#20760. Closes bazelbuild#374 Tested: * buildifier java/common/rules/java_toolchain.bzl \ toolchains/default_java_toolchain.bzl \ test/java/toolchains/java_toolchain_tests.bzl * bazelisk test //test/java/toolchains:java_toolchain_tests \ --test_output=errors
davido
force-pushed
the
turbine-direct-unsafe-memory-access
branch
from
August 19, 2026 13:04
68de125 to
8d5a82c
Compare
hvadehra
requested changes
Aug 19, 2026
| header_compiler_direct_data = [] | ||
| header_compiler_direct_jvm_opts = [] | ||
|
|
||
| turbine_direct_jvm_opts = get_internal_java_common().expand_java_opts( |
Member
There was a problem hiding this comment.
Lets not complicate things unnecessarily. Just use the opts as is without expansion for now.
| tokenize = False, | ||
| exec_paths = True, | ||
| ) | ||
| if turbine_direct_jvm_opts and not _is_deploy_jar_tool(ctx.attr.header_compiler_direct): |
Member
There was a problem hiding this comment.
If we're going with a dedicated attribute, I don't think we need to perform all this validation. Lets just pass the user-specified opts as is.
Maybe just a warning note in the attribute docs about graal vs deploy jar.
| The list of arguments for the JVM when invoking turbine. | ||
| """, | ||
| ), | ||
| "turbine_direct_jvm_opts": attr.string_list( |
Member
There was a problem hiding this comment.
For consistency lets call this header_compiler_direct_opts
| "-Xmaxwarns -1", | ||
| ] | ||
|
|
||
| TURBINE_DIRECT_JAVA_FALLBACK_JVM_OPTS = select({ |
Member
There was a problem hiding this comment.
I don't think this makes sense - the header_compiler_direct is a public attribute and user-settable. Expecting the non-graal executable based on platform isn't correct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…iler
turbine_direct (header_compiler_direct) bundles protobuf, whose UnsafeUtil calls terminally-deprecated sun.misc.Unsafe methods. On JDK 24+ (JEP 498) the JVM prints a warning for each such call during header compilation:
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by
com.google.protobuf.UnsafeUtil (.../java_tools/turbine_direct_binary_deploy.jar)
Unlike the Turbine worker, header_compiler_direct does not receive turbine_jvm_opts, and --jvmopt does not reach header-compilation actions, so a toolchain currently has no way to silence these warnings for the direct header compiler. Add --sun-misc-unsafe-memory-access=allow to header_compiler_direct_jvm_opts, gated on the runtime feature version since the flag is rejected on JDK <= 22.
See protocolbuffers/protobuf#20760.
Closes #374