fix: initialize the indy dispatcher without Unsafe on modern JDKs - #4577
Open
mvanhorn wants to merge 1 commit into
Open
fix: initialize the indy dispatcher without Unsafe on modern JDKs#4577mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
🤖 GitHub commentsJust comment with:
|
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.
What does this PR do?
On Java 9+, define the
java.lang.IndyBootstrapDispatcherresource with Byte Buddy'sClassInjector.UsingLookup: openjava.base/java.langto the agent's actual defining class loader through the existingElasticApmAgent.openModuleAPI, obtain a private lookup anchored onObject.class, and inject the existing bytes. Keep the Java 7/8 Unsafe path, invoke the newer lookup API reflectively to preserve the Java 7 production API baseline, and retain the initialClass.forName(..., false, null)check so repeated initialization reuses the bootstrap class. Update the production call sites insideIndyBootstrap.javato distinguish the dispatcher lookup anchor from the legacyModuleSetterinjection, and apply the existing J9 module override only when the dispatcher is not already injava.base, comparing modules with Byte Buddy's existingJavaModuleabstraction.On JDK 26+, agent startup can fail while preparing instrumentation because Byte Buddy disables its Unsafe class injector by default. The supplied stack trace reaches
IndyBootstrap.loadClassInBootstrap, which still unconditionally usesClassInjector.UsingUnsafe.ofBootLoader()in this checkout. The maintainer identifies this injection site and suggests method-handle-based injection;-Dnet.bytebuddy.safe=falseis a temporary workaround. The June 30 comment says Java 26 was outside the supported-version policy at that time, but neither claims the work nor rejects the proposed code correction.Fixes #4519
Checklist