Skip to content

Generate field-inject dispatch code - #130

Merged
mcculls merged 3 commits into
mainfrom
mcculls/field-inject-dispatch
Oct 5, 2026
Merged

mcculls merged 3 commits into
mainfrom
mcculls/field-inject-dispatch

Conversation

@mcculls

@mcculls mcculls commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

What Does This Do

Adds build-time generation of the support bytecode needed for field-injected object-store dispatch:

  • generates a synthetic KeyWithValue interface exposing indexed get/set accessors
  • generates ObjectStoreDispatch, which uses injected accessors when available and falls back to GlobalObjectStore otherwise
  • provides weakGet/weakPut entry points so an injected accessor can fall back without recursively re-entering dispatch
  • preserves atomic getOrPut, getOrCompute, and remove behavior on the injected fast path with double-checked locking
  • relocates the dispatch types and GlobalObjectStore implementation under java.lang.$Datadog$ and packs them as glue for future bootstrap-classpath injection
  • strips annotations, generic signatures, and debug metadata from the relocated glue, and keeps the generated constant holder out of the published jar
  • keeps GlobalObjectStore and ObjectStoreIds as package-private implementation details

Motivation

Field injection needs a fast path that stores values directly on instrumented key objects, while retaining the existing weak global store for keys that cannot be injected and for stores without an injected field.

This PR establishes the generated runtime types and bootstrap-safe fallback implementation needed for that dispatch. It is intentionally preparatory: it does not yet switch the public ObjectStore methods to the generated dispatcher or add the key-class transformation.

Additional Notes

Tests cover:

  • structural and type-resolving verification of generated bytecode
  • relocation of every Datadog-owned dependency needed by the bootstrap glue
  • fast-path and fallback behavior for all dispatch operations
  • fallback from an injected accessor without recursive dispatch
  • single-winner behavior for concurrent getOrPut calls

Verified with:

./gradlew :field-inject:test

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@mcculls mcculls changed the title Mcculls/field inject dispatch WIP: field inject dispatch Oct 1, 2026
@mcculls mcculls changed the title WIP: field inject dispatch WIP: generate field inject dispatch code Oct 1, 2026
@mcculls mcculls changed the title WIP: generate field inject dispatch code WIP: generate field-inject dispatch code Oct 1, 2026
@mcculls
mcculls force-pushed the mcculls/glue-build-improvements branch from 3c711a3 to 031caf6 Compare October 2, 2026 08:33
Base automatically changed from mcculls/glue-build-improvements to main October 2, 2026 12:09
@mcculls
mcculls force-pushed the mcculls/field-inject-dispatch branch 3 times, most recently from dfe44f3 to a0ad0b5 Compare October 2, 2026 16:27
@mcculls mcculls changed the title WIP: generate field-inject dispatch code Generate field-inject dispatch code Oct 2, 2026
@mcculls
mcculls marked this pull request as ready for review October 2, 2026 16:50
@mcculls
mcculls requested a review from a team as a code owner October 2, 2026 16:50
@mcculls
mcculls requested review from amarziali and jbachorik and removed request for a team and jbachorik October 2, 2026 16:50
@mcculls
mcculls force-pushed the mcculls/field-inject-dispatch branch from b1cbac3 to 37de13a Compare October 3, 2026 11:08
@mcculls
mcculls force-pushed the mcculls/field-inject-dispatch branch from 37de13a to 0cc4ce6 Compare October 3, 2026 14:06

@amarziali amarziali left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good from my pov. I added a comment to understand better the implication of having different constraints on put wrt to things like getOrPut

@mcculls
mcculls merged commit aac6573 into main Oct 5, 2026
6 checks passed
@mcculls
mcculls deleted the mcculls/field-inject-dispatch branch October 5, 2026 10:06
@github-actions github-actions Bot added this to the 0.1.0 milestone Oct 5, 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