fix: upgrade protobuf-java to 4.36.1 to stop using sun.misc.Unsafe - #365
Conversation
protobuf-java 4.36 stopped routing standard (non-lite) generated code through UnsafeUtil, so the class is never loaded and JDK 24+ no longer prints the terminally-deprecated sun.misc.Unsafe warning. It also makes the runtime survive environments where Unsafe is present but throws (--sun-misc-unsafe-memory-access=deny), which 4.33.x did not. Fixes grafana#361 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Heads-up on a side effect of this upgrade, found while benchmarking the labels encoder in #363 — 4.36.1 encodes just as fast as 4.33.5, but allocates more, and quite a lot more for non-ASCII Same benchmark, protobuf only, both versions driven through our
Every timing delta sits inside overlapping error bars, so there is no measurable throughput change. Likely mechanism, and it follows directly from what makes the fix work: with the full (non-lite) Practical impact is modest — this is per Two caveats: measured on a 16-vCPU QEMU VM (ratios are more reliable than absolutes), and this is Method, raw JMH output and the full tables: the benchmark comment on 🤖 Generated with Claude Code |
Fixes #361
What
Bumps the vendored
com.google.protobuf:protobuf-javafrom4.33.5to4.36.1. That is the whole change.Why this fixes it
protobuf v36.0 stopped routing standard (non-lite) generated code through
UnsafeUtil. OurJfrLabelsgencode is full, not lite, soUnsafeUtilis now never class-loaded and the JDK 24+ warning never fires.Note that 4.36.1 still contains
sun.misc.Unsafereferences (kept for the Lite path) and the classes are still in the shaded jar — they are just never touched. It also makesgetUnsafe()probearrayBaseOffsetand fall back gracefully if it throws, which fixes the second half of the issue: with 4.33.5 the agent hard-crashes under--sun-misc-unsafe-memory-access=deny.Gencode/runtime compatibility is fine: our checked-in gencode is 4.26.1, same major, older minor, which
RuntimeVersionaccepts. protobuf-java 4.36.1 still targets class file major 52 (Java 8) and has no transitive dependencies.Verification
Built
pyroscope.jarbefore and after viaubuntu-test.Dockerfile, ran the same labels-serializing program under Temurin 25.0.4 with-javaagent:Before (4.33.5):
After (4.36.1):
(The unrelated
java.lang.System::loadrestricted-method warning from async-profiler is present in both and untouched by this PR.)Also checked the
--sun-misc-unsafe-memory-access=denycase with a plain roundtrip over ourJfrLabelsgencode — 4.33.5 dies withExceptionInInitializerError/UnsupportedOperationException: arrayBaseOffset, 4.36.1 round-trips fine../gradlew testpasses (run in the Java 11 builder container).🤖 Generated with Claude Code