Repository navigation
Provide API to enable field-injected ObjectStore access - #182
Merged
Merged
Conversation
mcculls
marked this pull request as ready for review
December 4, 2026 14:12
mcculls
requested review from
amarziali and
ygree
and removed request for
a team
December 4, 2026 14:12
amarziali
approved these changes
Dec 4, 2026
Initialize bootstrap dispatch before redirecting ObjectStore, falling back to local dispatch if bootstrap setup fails. Preserve global storage when dispatch cannot be enabled. Cover existing values, repeated retransformation, and failed enablement. Isolate bootstrap test bindings and exclude generated glue constants from SpotBugs analysis.
mcculls
force-pushed
the
mcculls/enable-field-injection
branch
from
December 4, 2026 22:42
6873d35 to
4aa17f0
Compare
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 Do
Add
FieldInjector.enableFieldInjection(Instrumentation)to redirectObjectStoreinstance operations through dispatch via retransformation. Initialize bootstrap dispatch before redirecting calls, fall back to local dispatch if bootstrap setup fails, and preserve global-store access if retransformation fails. Static cleanup stays onGlobalObjectStore.Motivation
The goal of field injection is to store associated values directly in eligible key objects, avoiding global weak-map lookups while keeping the same
ObjectStoreAPI and a weak-map fallback for keys that cannot support injected storage.Earlier work introduced the global store, the generated
KeyWithValueaccessor interface, and local/bootstrap dispatch that selects between injected accessors and the global fallback. #181 simplifies that dispatch glue. Until this change, productionObjectStoremethods still callGlobalObjectStoredirectly; the dispatch rewrite exists only in tests and benchmarks.This PR connects the public API to that dispatch machinery. An agent can enable access at startup, installing and initializing the bootstrap glue before transforming
ObjectStore. Itsget,put,getOrPut,getOrCompute, andremoveoperations can then use injected accessors when the key implementsKeyWithValue, while ordinary keys continue through the global weak store. Bootstrap-visible glue supports access from bootstrap-loaded key classes as well as application classes.Additional Notes
Stacked on #181, targeting
mcculls/prune-dispatch-bindings.The remaining work for full field-injection support is the key-class transformation: selecting eligible classes and stores, adding storage fields, and implementing the generated accessor interface with weak fallback where a store has no injected field. This PR provides the API and installation path for accessing that storage; it does not yet add fields to key classes. The tests supply accessor implementations to exercise both injected and fallback paths.
The transformation test and benchmarks reuse the production visitor and transformer. Tests cover existing values, bootstrap and local dispatch, repeated retransformation, failed enablement, and retry.
Contributor Checklist
./gradlew :field-inject:check --no-configuration-cachepassed on Java 8, 11, 17, 21, and 25, including formatting, SpotBugs, and benchmark compilation.