Add @Strategy marker annotation for static-polymorphism strategies#11984
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: 120469d | Docs | Datadog PR Page | Give us feedback! |
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
4a05183 to
fbb0085
Compare
…orphism strategies Marker-only (no enforcement yet): telegraphs the static-polymorphism strategy pattern and gives a future checker targets. @strategy marks strategy types/parameters; @StrategyConsumer marks the higher-order methods that must inline for them to specialize. Contracts live in the javadoc. Applications land in stacked PRs (FlatHashtable first). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
fbb0085 to
da64961
Compare
There was a problem hiding this comment.
More details
Two marker annotations for static-polymorphism strategies: @strategy (for types/parameters) and @StrategyConsumer (for methods). Both use SOURCE retention, require no runtime behavior, and contain no enforcement. Compilation, metaannotations, and javadoc are correct; no uses yet (by design). Zero behavioral or bytecode impact — this is a documentation-first pattern telegraph.
📊 Validated against 5 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit da64961 · What is Autotest? · Any feedback? Reach out in #autotest
Address review: describe 'static polymorphism' directly in the annotation rather than referring to FlatHashtable, which is a consumer of @strategy — the reference was a conceptual back-reference that left the base annotation unable to stand on its own. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| * -XX:+PrintInlining}. | ||
| */ | ||
| @Documented | ||
| @Inherited |
There was a problem hiding this comment.
@Inherited has no affect on source-only annotations, so this could be dropped
(it also has no affect on parameter annotations - it's only really useful on class annotations: https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Inherited.html)
There was a problem hiding this comment.
Yes, I thought about that. Ultimately, I decided to keep it to show the intent -- that the concept transfers from parent to child -- including abstract child classes.
mcculls
left a comment
There was a problem hiding this comment.
Interested to see where this goes
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
What Does This Do
Adds
@Strategy, a marker annotation for static-polymorphism strategy types and parameters — the stateless, concrete-typed policy objects the JIT can devirtualize and inline so one shared algorithm specializes to straight-line code per caller.Motivation
Marks where static-polymorphism approach to an API is being used.
The intention is to clearly signal when this style of API is being used.
The annotation will serve as documentation on how to get the most performance out of such an API.
And eventually, tooling will be able to check if the API is being used as intended.
Additional Notes
From Claude...
Marker-only — no enforcement yet. The discipline it names is held by hand for now; the contract lives in the javadoc.
Design notes
@Target({TYPE, PARAMETER})— on a type: "this is a strategy" (hold itstatic final, concrete-typed, so it inlines). On a parameter: "this is a strategy slot" (the arg should be astatic finalconstant or a non-capturing lambda). The parameter target lets us tag a slot even when its type can't be (e.g. ajava.util.function.Functionwe don't own).@Retention(SOURCE)— zero bytecode footprint, no runtime metadata (agent hygiene); a source-level checker reads it fine.@Documented— the contract is human-facing, so it belongs in the generated javadoc.@Inherited— documentary intent (a concrete subclass of a strategy base is a strategy); inert underSOURCEretention, kept as a signal.Applications
None here, by design — the first uses land in the stacked FlatHashtable PR that builds on this one.
🤖 Generated with Claude Code