Repository navigation
fix(agent-feed): an AtomicLongFieldUpdater publishes and feeds the check-then-act rule (#1275, #1317, part) - #1456
Merged
Merged
Conversation
…#1317, part) #1315 made set, getAndSet, compareAndSet and the arithmetic forms of AtomicBoolean/AtomicInteger/AtomicLong release and get acquire. A field published through lazySet, setRelease, updateAndGet/getAndUpdate/ accumulateAndGet/getAndAccumulate, a won compareAndExchange(Release) or a won weakCompareAndSetVolatile/Release, and read after a get that saw the value, was still reported by AtomicityValidator as an unordered publication on correct code. And a reader whose read was getAndSet's previous value, a compareAndExchange witness, or what an add or update returned acquired nothing. Those hooks now call primitiveSlotStoring (before the store; after a won swap for the compare forms) and HappensBefore.acquireVolatile on the value read. The update and accumulate forms run as a CAS loop like addPublishing, so the value to be stored is known before the store. setPlain, setOpaque and weakCompareAndSetPlain stay unordered, as the JMM says; AtomicFlagPublicationWeavingTest pins setPlain. Verified failing first: 23 new AtomicFlagPublicationWeavingTest rows (one per form) failed before the hook change and pass after; the setPlain negative passed throughout. Library atomic, spinlock, happens-before and atomicity tests plus MinTrustGateTest under -P e2e, the full agent suite under -P e2e and the corpus eval are green; static gates and the javadoc jar are clean. Still open on #1317: getAcquire, intValue and longValue reads, the AtomicLong forms the weaver does not substitute, and the updater, VarHandle and array forms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous commit made the value an increment, add, update or accumulate returns acquire. The corpus idioms lane then filled a 2 GB heap within seconds on CI (Java 26 OOM; 21 and 25 hung past 25 min), reproduced locally under -Xmx2g. A heap histogram of the dead fork showed 1.38 GB of long[] and 690 MB of int[] averaging 32 KB and 14 KB: HappensBefore stamps near MAX_ENTRIES (4096). The add releases before its store, so a counter every thread bumps (CorpusRecorder's static BODY_EXECUTIONS, bumped once per body execution) collects every bumper's clock; acquiring on the read handed that whole clock to each bumper, and every access it recorded afterwards pinned a copy. A user suite with a global id counter would hit the same OOM. The add and update forms now release only, as on main before #1317. getAndSet and the compareAndExchange witness still acquire, and a get of the counter still acquires what it published. Verified failing first: AtomicCounterClockTest (11 forms, 200 earlier bumpers) failed with a clock of 201 threads on every form and passes after. AtomicFlagPublicationWeavingTest's two add/update-result rows are inverted to assertRaced, pinning the decision. Idioms lane under -Xmx2g: OOM before, 220/220 in 37 s after; full corpus (6 lanes) green; library -P fast 4336 tests green; static gates and javadoc jar clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The woven addAll released every element before the call and, outside queues, withdrew nothing. An element a concurrent set refused (it held an equal one) or one a call throwing part way never added stayed published, so a thread that reached it another way was ordered after the producer by a hand-off that never happened, hiding a race. HappensBefore.retract could not be reused: it keeps only the thread's last release and forgets it at the next stamped access, which the element's own equals/hashCode makes inside addAll. HappensBefore.releaseWithdrawable hands each release back and withdraw takes it back exactly (CAS of the element's clock from what the release installed to what it held before; a later release by another thread keeps it). collectionAddAll withdraws every element's release when the call returns false, and those of elements the collection does not hold by identity when it throws. Verified failing first: AgentHappensBeforeFeedTest's two new tests (newKeySet already holding equal tags; newKeySet.addAll stopping at a null) failed before and pass after; the twin (the element that went in stays published) passes throughout. Library -P fast 4338 green, full corpus green after a fresh install, static gates and javadoc jar clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…se (#1316, part) The woven increment, add and update forms of AtomicInteger/AtomicLong release the value they are about to store before each compare-and-set attempt (#1315). An attempt that lost to another thread storing the same value left its release as the atomic's latest, so a get that saw the winner's value was ordered after the loser's earlier writes too: an edge the program does not have, which can hide a race on them. HappensBefore.releaseVolatile now remembers, per thread and without allocating, the field clock and the release it installed; withdrawVolatile puts the field back to the release before it while it is still the latest. addPublishing (int, long) and updatePublishing call it after a lost compareAndSet. When the winner released after the loser, its cumulative release already holds the loser's clock and nothing is withdrawn; #1316 stays open for that order. Verified failing first: AgentHappensBeforeFeedTest .aLostAttemptWithdrawsItsRelease (the update function lets another thread win the first swap, then a reader gets the winner's value) was red before and is green after; its twin (the attempt stored the value) stays silent throughout. Library -P fast 4339, agent AtomicFlagPublicationWeavingTest 35/35 under -P e2e, full corpus after a fresh install, static gates and javadoc jar all green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… function are ordered (#1336, part) With the agent attached, an AtomicReferenceArray element replaced by a successor built in updateAndGet (or getAndUpdate, accumulateAndGet, getAndAccumulate, compareAndExchange, weakCompareAndSetVolatile), or a field replaced through an AtomicReferenceFieldUpdater's update or accumulate forms, was reported by AtomicityValidator at PROMPT when another thread read the successor's state through the slot. These forms stored with a volatile write that released nothing; #1334 fixed only AtomicReference's. Each form now has a hook that runs it as the woven get and the woven compareAndSet of its slot kind, the loop the JDK runs inside it, and FieldAccessWeaver's REFERENCE_ARRAY_FORMS and REFERENCE_UPDATER_FORMS substitute them. weakCompareAndSetPlain and the deprecated weakCompareAndSet stay unwoven (SpinLockHookTableTest pins it). The AsyncTestAgent @aicore note names the new substitutions; the guardrail files are regenerated from it. Verified failing first: the two new must-stay-silent corpus idiom rows (idiom_arrayUpdateAndGet_/idiom_updaterUpdateAndGet_buildsTheSuccessor InTheFunction) were both reported before the hooks; with them the lane passes 224/224 and the full corpus is green. TelemetryRegistryHooksMatch TheJdkTest compares every new hook with the JDK call. Library -P fast 4339, agent -P e2e 610, static gates green. Still open on #1336: the reference VarHandle compareAndExchange and weak swaps, and the acquire/release flavours on every slot kind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ompareAndSet publish (#1336, part) With the agent attached, an object published through a reference VarHandle compareAndExchange loop on a volatile field was reported by AtomicityValidator at PROMPT when another thread read its state through the handle: compareAndExchange and weakCompareAndSet (volatile on a handle) stored with a volatile write that released nothing. Each now has a hook for an instance field, a static field and an array element, run as the woven compareAndSet and, for a lost exchange, the woven getVolatile witness. FieldAccessWeaver.referenceHandleHook matches them and the hook descriptor returns Object (narrowed back by the existing CHECKCAST) or boolean. weakCompareAndSetPlain and the acquire and release flavours stay unwoven; SpinLockHookTableTest pins both sides. The AsyncTestAgent @aicore note and the generated guardrails name the new substitutions. Verified failing first: the new must-stay-silent idiom row idiom_varHandleCompareAndExchange_retriesFromTheWitness was reported against the jar without these hooks (lane 226, 1 failure) and passes with them; the full corpus is green. TelemetryRegistryHooksMatchTheJdk Test compares each hook with the handle's own call. Agent -P e2e 610, library -P fast (JavadocDescribesRatherThanRestates caught two restating @PARAM lines, fixed), static gates and javadoc jar green. Still open on #1336: the acquire and release flavours on every slot kind, which need a decision on what a one-sided swap publishes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omic acquire (#1317, part) With the agent attached, a field published through a store into an AtomicBoolean, AtomicInteger or AtomicLong and read after getAcquire(), intValue() or longValue() saw the stored value was reported by AtomicityValidator as an unordered publication on correct code: the weaver substituted only get, so these reads acquired nothing. Seven hooks now weave them: getAcquire on all three, intValue and longValue on AtomicInteger and AtomicLong. Each acquires what the store of the value it returned published, and the AtomicInteger/AtomicLong ones are the check half of a check-then-act, as get is (#1249). The AsyncTestAgent @aicore note and the generated guardrails name them. Verified failing first: seven new AtomicFlagPublicationWeavingTest rows (one per read, through a woven bean) were red before the hooks and are green after. TelemetryRegistryHooksMatchTheJdkTest compares each hook with the JDK call (AtomicLong.intValue on a value above 2^32 included). Agent -P e2e 617, library -P fast 4339, full corpus, static gates and javadoc jar green. Still open on #1317: the AtomicLong forms the weaver does not substitute, and the updater, VarHandle and array forms of a primitive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orm AtomicInteger does (#1317, part) With the agent attached, a field published through AtomicLong.getAndSet, a won compareAndExchange or compareAndExchangeRelease, a won weakCompareAndSetRelease, or updateAndGet and the other update and accumulate forms, then read after a get that saw the value, was reported by AtomicityValidator as an unordered publication on correct code: the weaver did not substitute those forms on AtomicLong, so they released nothing. A getAndSet's previous value and a compareAndExchange or compareAndExchangeAcquire witness acquired nothing either. Ten hooks, modelled on AtomicInteger's without the spinlock parts (an AtomicLong is never treated as a lock): releases before the store or after a won swap per flavour, acquires on a returned previous value or witness per flavour, and the update forms as the CAS loop that releases before each attempt and withdraws a lost one (#1316). The plain and opaque forms still order nothing. The @aicore note and the generated guardrails name the new substitutions. Verified failing first: 11 new AtomicFlagPublicationWeavingTest rows (8 publish, 3 acquire) were red before the hooks and green after (53). TelemetryRegistryHooksMatchTheJdkTest compares each hook with the JDK call on a value above 2^32. Agent -P e2e 628, library -P fast 4339, full corpus, static gates and javadoc jar green. Still open on #1317: the updater, VarHandle and array forms of a primitive, which need a slot identity that matches direct access. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Updater is reported (#1275, part) if (UPDATER.get(o) < LIMIT) UPDATER.incrementAndGet(o) admits past the limit when another thread's update lands between the check and the increment, as the same code on an AtomicInteger does, but only the latter was reported: AtomicNonAtomicUpdateDetector keys its rule by the atomic object, and an updater names a field of an owner. The updater's get, incrementAndGet and getAndIncrement were not woven at all. Design call: the slot is keyed by HappensBefore.fieldKey(receiver, field), the field clock the model already keeps once per object and field and holds weakly, so the key is canonical and keeps nothing alive; the finding is named by the field (DeclaringClass.field, as SpinLocks.fieldOf reads it), so no string is built on the record path. The detector gains (key, name, receiver) overloads; the receiver is the object whose monitor can guard the field. Every woven IntUpdater hook reports its role (read, increment, swap, store), and get, incrementAndGet and getAndIncrement are now substituted. Verified failing first: corpus idiom pair idiom_updaterAdmission_*; the check-then-increment row was SILENT but MUST_FIRE before, fires after, and the get/compareAndSet loop twin stays silent (lane 228). AtomicNonAtomicUpdateDetectorTest pins the field-named finding and that two fields of one object are two slots. Agent -P e2e 628, library -P fast 4341, full corpus, static gates, javadoc jar green. SubstitutionHooksArePointsTest lists the four new recording entry points with the existing atomic* ones. Still open on #1275: AtomicLongFieldUpdater and VarHandle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ld's own slot (#1317, part) With the agent attached, a field published through an AtomicIntegerFieldUpdater's set, lazySet, won compareAndSet, getAndSet or arithmetic and update forms, then read after the updater's get (or a direct volatile read of the field), was reported by AtomicityValidator as an unordered publication on correct code, and so was a direct volatile write read through the updater: updater calls released and acquired nothing. The updater's stores now release, and its get and getAndSet's previous value acquire, under the field's own name (DeclaringClass.field, as SpinLocks.fieldOf resolves it), which is the slot FieldAccessWeaver gives a direct volatile access of the field, so the two kinds of access order each other. The arithmetic and update forms run as a releasing compare-and-set loop that withdraws a lost attempt (#1316); the value they return acquires nothing, for AtomicCounterClockTest's reason. An updater whose field cannot be resolved keeps the JDK's own call. Verified failing first: 9 new AtomicFlagPublicationWeavingTest rows (7 updater forms, and updater/direct access in both directions) were red before and are green after; the "set before the update" negative stays raced. A woven trace of all 13 forms checks each returns the JDK's value. Agent -P e2e 639 (spinlock weaving tests included), library -P fast 4341, full corpus, static gates and javadoc jar green. Still open on #1317: AtomicLongFieldUpdater, VarHandle and array forms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eck-then-act rule (#1275, #1317, part) Nothing an AtomicLongFieldUpdater did was woven. With the agent attached, a field published through its stores and read after its get (or a direct volatile read) was reported by AtomicityValidator as an unordered publication on correct code, and a check-then-increment through it was silent, though the same code through an AtomicIntegerFieldUpdater now publishes (#1455) and is reported (#1454). Its 15 forms that order or check something (all but the plain deprecated weakCompareAndSet) are now substituted (LONG_UPDATER_FORMS). Each hook reports its check-then-act role under HappensBefore.fieldKey(receiver, field) and publishes or acquires under the field's own slot, the arithmetic and update forms as a releasing compare-and-set loop that withdraws a lost attempt. The field is resolved by SpinLocks.longFieldOf from the JDK's CASUpdater, whose offset/tclass/(Class, String, Class) shape matches the int updater's; SpinLocks.describe now takes the implementation and field type, and JdkUpdaterShapeCanaryTest pins the long updater's shape too. A long field is never a spinlock flag, so it is not added to SPIN_FIELDS. Verified failing first: 6 AtomicFlagPublicationWeavingTest rows (4 forms, direct/updater both ways) were red and are green; a woven trace of all 13 arithmetic forms returns the JDK's values; corpus idiom pair idiom_longUpdaterAdmission_* had its MUST_FIRE row silent before and firing after (lane 230). SpinLockHookTableTest now checks every AtomicLongFieldUpdater substitution names a real hook. Agent -P e2e 646, library -P fast 4343, full corpus, static gates, javadoc jar green. Still open: VarHandle on #1275, VarHandle and array primitive forms on #1317. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Part of #1275 and #1317. Stacked on #1444, #1446, #1447, #1448, #1452, #1453, #1454 and #1455, review the last commit.
Why
Nothing an
AtomicLongFieldUpdaterdid was woven. With the agent attached, that caused two problems:get(or a direct volatile read), was reported byAtomicityValidatoras an unordered publication on correct code;The same code through an
AtomicIntegerFieldUpdaternow publishes (#1455) and is reported (#1454).Change
LONG_UPDATER_FORMSsubstitutes 15 forms, every one that orders or checks something. The deprecatedweakCompareAndSethas plain semantics and is left alone.TelemetryRegistry. Each reports its check-then-act role underHappensBefore.fieldKey(receiver, field), and publishes or acquires under the field's own slot. The arithmetic and update forms run as a releasing compare-and-set loop that withdraws a lost attempt. An unresolved field keeps the JDK's call.SpinLocks.longFieldOfreads the JDK'sCASUpdater, whoseoffset/tclass/(Class, String, Class)shape matches the int updater's.SpinLocks.describenow takes the implementation class name and field type, so both updaters share one reader.JdkUpdaterShapeCanaryTestnow pins the long updater's shape too.@AICorenote and the generated guardrails name the new substitutions.Still open:
VarHandleon #1275, and theVarHandleand array primitive forms on #1317.Verified
AtomicFlagPublicationWeavingTestrows (4 forms, plus direct and updater access in both directions) were red before the change and are green after.idiom_longUpdaterAdmission_*: the must-fire row was silent before and fires after. Idioms lane 230/230.SpinLockHookTableTestnow checks that everyAtomicLongFieldUpdatersubstitution names a real hook.TelemetryRegistryHooksMatchTheJdkTestcovers the hooks' fallback path.-P e2e: 646 tests green. Library-P fast: 4343 tests green. Full corpus green after a fresh install. Static gates, the javadoc jar and the guardrail drift check are clean.Docs
docs/agent/attaching.md.docs/DETECTOR_CATALOG.md.docs/CHANGELOG.md.AsyncTestAgentguardrail note and the generated files.🤖 Generated with Claude Code