Skip to content

Provide API to enable field-injected ObjectStore access - #182

Merged
mcculls merged 1 commit into
mainfrom
mcculls/enable-field-injection
Dec 4, 2026
Merged

mcculls merged 1 commit into
mainfrom
mcculls/enable-field-injection

Conversation

@mcculls

@mcculls mcculls commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

What Does This Do

Add FieldInjector.enableFieldInjection(Instrumentation) to redirect ObjectStore instance 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 on GlobalObjectStore.

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 ObjectStore API and a weak-map fallback for keys that cannot support injected storage.

Earlier work introduced the global store, the generated KeyWithValue accessor interface, and local/bootstrap dispatch that selects between injected accessors and the global fallback. #181 simplifies that dispatch glue. Until this change, production ObjectStore methods still call GlobalObjectStore directly; 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. Its get, put, getOrPut, getOrCompute, and remove operations can then use injected accessors when the key implements KeyWithValue, 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-cache passed on Java 8, 11, 17, 21, and 25, including formatting, SpotBugs, and benchmark compilation.

@mcculls mcculls changed the title Enable ObjectStore dispatch through retransformation Enable field-injected ObjectStore access with bootstrap dispatch and local fallback Dec 4, 2026
@mcculls mcculls changed the title Enable field-injected ObjectStore access with bootstrap dispatch and local fallback Provide API to enable field-injected ObjectStore access Dec 4, 2026
@mcculls
mcculls marked this pull request as ready for review December 4, 2026 14:12
@mcculls
mcculls requested a review from a team as a code owner December 4, 2026 14:12
@mcculls
mcculls requested review from amarziali and ygree and removed request for a team December 4, 2026 14:12
Base automatically changed from mcculls/prune-dispatch-bindings to main December 4, 2026 22:41
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
mcculls force-pushed the mcculls/enable-field-injection branch from 6873d35 to 4aa17f0 Compare December 4, 2026 22:42
@mcculls
mcculls merged commit 1702916 into main Dec 4, 2026
6 checks passed
@mcculls
mcculls deleted the mcculls/enable-field-injection branch December 4, 2026 22:54
@github-actions github-actions Bot added this to the 0.1.0 milestone Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants