Repository navigation
Conversation
🤖 GitHub commentsJust comment with:
|
Keep both changelog entries under Fixes.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The test leaves Unsafe-disabled startup unverified because agent initialization occurs before it runs; a fresh-JVM regression test must verify successful dispatcher initialization and bootstrap-loader/module placement with -Dnet.bytebuddy.safe=true.
1 open issue
What changed in this PR
This PR addresses #4519 by removing the invokedynamic dispatcher’s dependence on Unsafe injection on Java 9+, avoiding the reported JDK 26+ startup failure while preserving the Java 7/8 fallback.
Changes:
- Uses reflective lookup-based injection and opens
java.langto the agent’s defining class loader. - Preserves dispatcher reuse and limits the J9 module override to cases where it is needed.
- Adds initialization and failure-path tests, plus a release note.
| File | Description |
|---|---|
CHANGELOG.next-release.md |
Documents the dispatcher startup fix. |
apm-agent-core/src/test/java/co/elastic/apm/agent/bci/IndyBootstrapTest.java |
Adds dispatcher initialization and failure-path checks; isolates the legacy module-setter test. |
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/IndyBootstrap.java |
Adds lookup-based injection for modern JDKs while retaining legacy Unsafe paths. |
Review effort: Balanced
Start a separate JVM with net.bytebuddy.safe=true so Byte Buddy never enables Unsafe, then check the dispatcher lands in the bootstrap loader and java.base.
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
This branch has not been deployed
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