Skip to content

Commit 9d2bddf

Browse files
jbachorikclaude
andcommitted
Add arm64 ordering, concurrent iteration, and comment precision rules
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2cd9e86 commit 9d2bddf

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,17 @@ The profiler uses a sophisticated double-buffered storage system for call traces
357357
- **Atomic Operations**: Instance ID management and counter updates use atomics
358358
- **Memory Allocation**: Minimize malloc() in hot paths, use pre-allocated containers
359359

360+
### Atomic Memory Ordering (Critical for arm64)
361+
arm64 has a weakly-ordered memory model (unlike x86 TSO). Incorrect ordering causes real lockups on arm64 that never reproduce on x86.
362+
- **Cross-thread reads**: Always use `__ATOMIC_ACQUIRE` for loads that must see stores from another thread. Never use `__ATOMIC_RELAXED` for cross-thread visibility unless you can prove no ordering dependency exists.
363+
- **Cross-thread writes**: Use `__ATOMIC_RELEASE` for stores that must be visible to other threads. Pair with `__ATOMIC_ACQUIRE` loads.
364+
- **Count + pointer patterns**: When a data structure publishes a count and a separate pointer (two-phase add), both the count load and pointer load need acquire semantics so the reader sees the pointer store that preceded the count increment.
365+
- **Default stance**: When in doubt, use acquire/release. The performance cost is negligible; the correctness cost of relaxed ordering bugs is enormous (silent arm64-only lockups).
366+
367+
### Concurrent Data Structure Iteration
368+
- **NULL gaps**: When iterating a concurrent array (e.g., `CodeCacheArray`), always NULL-check each slot — a slot may be count-allocated but pointer-not-yet-stored.
369+
- **Cursor advancement**: Never permanently advance an iteration cursor past NULL gaps. Stop at the first NULL or track the last contiguous non-NULL entry, so missing entries are retried on the next pass.
370+
360371
### 64-bit Trace ID System
361372
- **Collision Avoidance**: Instance-based IDs prevent collisions across storage swaps
362373
- **JFR Compatibility**: 64-bit IDs work with JFR constant pool indices
@@ -705,3 +716,9 @@ The CI caches JDKs via `.github/workflows/cache_java.yml`. When adding a new JDK
705716
- Always provide tests for bug fixes - test fails before the fix, passes after the fix
706717
- All code needs to strive to be lean in terms of resources consumption and easy to follow -
707718
do not shy away from factoring out self containing code to shorter functions with explicit name
719+
720+
### C/C++ Code Style
721+
- **Indentation**: Match the exact indentation style of the surrounding code in each file. Do not introduce inconsistent indentation — reviewers will flag it.
722+
- **Minimal complexity**: Do not split inline logic into separate helper functions unless the helpers are reused or the original is genuinely hard to follow. Unnecessary splits add indirection without value.
723+
- **Comment precision**: Comments explaining "why" must reference concrete mechanisms (e.g., "ASAN's allocator lock is reentrant" not "internal bookkeeping"). Vague comments get challenged in review. Every claim in a comment must be verifiable from the code or documented behavior of the referenced system (ASAN, glibc NPTL, HotSpot, etc.).
724+
- **No speculative comments**: Do not claim a system (HotSpot, glibc, ASAN) uses a specific mechanism unless you are certain. If unsure, describe the observable symptom instead of guessing the cause.

0 commit comments

Comments
 (0)