Repository navigation
Conversation
The only throw/try/catch sites in ddprof-lib/src/main/cpp were here: a try/catch(std::bad_alloc) guarding the unordered_set pre-size calls and a UNIT_TEST throw in unusableTableForTest. C++ exceptions are now forbidden in native code (follow-up commit adds the AGENTS.md rule and the qualityChecks enforcement). allocateTables() allocates the three tables with nothrow new and drops the eager rehash() pre-sizing: std containers cannot pre-size without the throwing allocator contract. Bucket arrays allocate on first rotation; per-rotation node allocation is unchanged. Out-of-contract test-hook input aborts instead of throwing, pinned with SIGABRT death tests; a new nullTableForTest hook covers the nothrow-new failure path and the partial- failure cleanup.
utils/check-cpp-exceptions.py flags throw/try/catch and the throwing std helpers in ddprof-lib/src/main/cpp after blanking comments and string literals; the exception list starts empty and stale entries fail the check. Wired into :ddprof-lib:qualityChecks, documented in utils/README.md, hermetic cases added to test_quality_check_scripts.sh.
New AGENTS.md rule: no throw/try/catch in ddprof-lib/src/main/cpp — bugs are assert/abort, expected failures are error codes, survivable OOM uses nothrow/ mmap allocation; plain new and std containers still terminate on OOM. The contract-violation bullet is scoped to the Java API, and the native AGENTS.md carries the pointer invariant.
Exception-list entries become (path, keyword, occurrence) triples that exempt exactly one occurrence; raw string bodies are parsed and blanked, character literals match only the single-character form so digit separators cannot hide a keyword, and the docstring states the blanking limits honestly. T10 grows the mutation-sensitive cases (digit separators, raw strings, helper keywords, occurrence semantics, environment error, file-mode stale skip) and the rule wording in AGENTS.md and utils/README.md is scoped to the listed helpers with the libraryPatcher_linux.cpp forced-unwind mechanism stated precisely. Stale exception-safety comments in flightRecorder and the collection comments are updated to the no-exception reality, and the test sentinel is renamed to NO_TABLE_FOR_TEST.
|
@DataDog review |
There was a problem hiding this comment.
The new exemption tests can pass when exempted exception keywords are incorrectly reported because their negative assertions quote the wildcard. A focused Bash reproduction confirmed the missed matches.
🤖 Bits Code Review · Commit 6983410
| if [[ "$out" == *"bad.cpp:2:* (try)"* ]]; then | ||
| fail "T10g the listed occurrence is not exempt:"$'\n'"$out" | ||
| else | ||
| pass | ||
| fi | ||
| rc=0; out=$(run_exc_module exempt_second) || rc=$? | ||
| expect "T10g2 second try exempt, first still flagged" 1 "$rc" "$out" "$SRC/bad.cpp:2: C++ exceptions are forbidden in native code (try)" | ||
| if [[ "$out" == *"bad.cpp:3:* (try)"* ]]; then | ||
| fail "T10g2 the listed occurrence is not exempt:"$'\n'"$out" | ||
| else | ||
| pass | ||
| fi |
There was a problem hiding this comment.
Unquote the wildcard in both exemption assertions
If the checker incorrectly reports an exempted try, both exemption tests still pass: Bash treats the wildcard inside the quoted diagnostic pattern literally. A focused Bash reproduction confirmed that neither negative assertion matches a checker-format diagnostic. The positive assertions only require the nonexempt occurrence, so broken exemption handling goes undetected. Unquote the internal wildcard in both assertions.
| if [[ "$out" == *"bad.cpp:2:* (try)"* ]]; then | |
| fail "T10g the listed occurrence is not exempt:"$'\n'"$out" | |
| else | |
| pass | |
| fi | |
| rc=0; out=$(run_exc_module exempt_second) || rc=$? | |
| expect "T10g2 second try exempt, first still flagged" 1 "$rc" "$out" "$SRC/bad.cpp:2: C++ exceptions are forbidden in native code (try)" | |
| if [[ "$out" == *"bad.cpp:3:* (try)"* ]]; then | |
| fail "T10g2 the listed occurrence is not exempt:"$'\n'"$out" | |
| else | |
| pass | |
| fi | |
| if [[ "$out" == *"bad.cpp:2:"*" (try)"* ]]; then | |
| fail "T10g the listed occurrence is not exempt:"$'\n'"$out" | |
| else | |
| pass | |
| fi | |
| rc=0; out=$(run_exc_module exempt_second) || rc=$? | |
| expect "T10g2 second try exempt, first still flagged" 1 "$rc" "$out" "$SRC/bad.cpp:2: C++ exceptions are forbidden in native code (try)" | |
| if [[ "$out" == *"bad.cpp:3:"*" (try)"* ]]; then | |
| fail "T10g2 the listed occurrence is not exempt:"$'\n'"$out" | |
| else | |
| pass | |
| fi |
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
There was a problem hiding this comment.
Verified: the quoted inner wildcard made both negative assertions no-ops — a checker that reported an exempted try still passed T10g/T10g2. Fixed in 5907474 with grep-based, line-bounded guards (the suggested unquoted glob would have matched across lines).
CI Test ResultsRun: #45069175053 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-11-22 21:19:02 UTC |
|
🐶 babysit-pr watched this PR — CI breakages and mechanical findings fixed automatically; design decisions brought to the author. This run
✅ stopped 21:48 UTC · bits-review/head PASS, one flake retried green; dd-gitlab [hotspot,8]/[openj9,8] red on a persistent Fabric egress download failure (infra — left for the author); codeowner approval on |
The negative assertions quoted the inner wildcard, making both guards no-ops: a checker that flagged an exempted occurrence would still pass T10g/T10g2 (Bits finding on PR #1039). Replace them with line-bounded grep guards; bash [[ == ]] globs span lines and over-match. Verified in both directions: healthy run passes, an exemption-disabled checker mutant fails the suite.
|
❌ 38 passed, 0 failed, 2 without a result out of 40 expected configurations Test Matrix
No result producedThese configurations wrote no validation log, so their outcome is unknown and
Links
|
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 4 Pipeline jobs failed
Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 5907474 | Docs | View more details | Give us feedback! |
|
@DataDog review |
There was a problem hiding this comment.
More details
The checker accepts the reviewed sources and detects the four removed exception sites. Moving bucket-allocation OOM failures to the first trace rotation is an explicitly accepted behavior change.
🤖 Bits Code Review · Commit 5907474
What does this PR do?:
Forbids C++ exceptions (
throw/try/catch) inddprof-lib/src/main/cppandenforces the rule mechanically. Three changes:
CallTraceStorage::allocateTables()no longer uses exceptions: the threetables are allocated with
new (std::nothrow)and the eagerunordered_setpre-sizing (rehash) is dropped — std containers cannotpre-size without the throwing allocator contract. Bucket arrays now
allocate on first rotation; per-rotation node allocation is unchanged.
utils/check-cpp-exceptions.pyflagsthrow/try/catchand thethrowing std helpers (
rethrow_exception,throw_with_nested,__cxa_throw, ...) in native sources after blanking comments and stringliterals. Wired into
:ddprof-lib:qualityChecks(CIsource-invariant-checksjob). The exception list starts empty; stale entries fail the check.
AGENTS.md("C++ exceptions"): bugs areassert+abort(), expected failures are error codes, OOM that must be survivableuses nothrow/mmap allocation. The existing "contract violations → throw"
bullet is scoped to the Java API.
Motivation:
PROF-16668. PR #943 introduced the first
throwsites in native code(
std::logic_erroron an out-of-contract tag), reachable from the JVMTIFollowReferencescallback on the VM thread; the review replaced them withassert + abort. An uncaught exception escaping through a JVMTI callback
terminates the JVM — like
abort, but opaque — and the unwinder conflictswith the static-libgcc/-static-libstdc++ link (
libraryPatcher_linux.cpp) andthe pthread-cancellation cleanup rules (
j9WallClock.cpp). The rule makes thepolicy explicit and mechanically checked so it does not regress.
Additional Notes:
collections (~33 KB of bucket arrays) used to fail
acquire()cleanly viathe caught
std::bad_alloc; it now surfaces at the firstprocessTraces()rotation, where
bad_allocwas never caught (pre-existing hazard). Inpractice the pre-size only held until 2048 traces, after which the sets
rehashed anyway, and
clear()keeps the buckets at their high-water mark.(
failAllocationForTest); its test intent (OOM at start fails cleanly,nothing published) is covered by the mmap-failure path, and a new
nullTableForTesthook covers the nothrow-new failure path plus thepartial-failure cleanup (SIGABRT-pinned death tests per the PR refchain: reduce ancestor-fanout and batch allocation churn (PROF-16467) #943
precedent).
CRITICAL / 0 HIGH; 5 LOW + 1 INFO. Fixed: the checker docstring no longer
claims "never silent misses" next to a bullet describing a silent miss
(commit
69834100c). Dismissed with evidence: the raw-string regex ends atthe first
)delim", which is exactly C++ raw-string termination semantics.Accepted, no fix:
_liveness_checkers.reserve(4)can throw on OOM — that isthe documented convention (std containers terminate on OOM; never caught).
Listed, out of scope (pre-existing design/tests): liveness checkers run
under the
_liveness_lockshared lock, so a slow checker stalls aconcurrent recording start/stop; the
unregisterLivenessCheckerpath hasno dedicated test. One generalist reviewer worker settled without
submitting; coverage shows 0 uncovered files. Fix range re-reviewed: 0
findings.
(Sphinx over
origin/main..HEAD, plus a re-review of the fix commit).-fno-exceptionsbuild flag: the ticket's build plan is the rule + thecheck; a flag change would force further refactoring of std-container use
and is out of scope.
the OOM-at-start behavior described above; both deserve an engineer's
confirmation beyond the agentic review.
How to test the change?:
utils/tests/test_quality_check_scripts.sh— hermetic cases T10a–T10h coverkeyword detection, comment/string/digit-separator blanking, tracked-mode
source filtering, the empty exception list, exemption and stale-entry
behavior (284 groups pass on Linux).
python3 utils/check-cpp-exceptions.pyagainst the pre-refactor sourcesreports exactly the four removed sites; against this tree it is clean.
:ddprof-lib:gtestDebug(incl. the reworkedCallTraceStorageAcquireTestdeath tests),
:ddprof-lib:gtestAsan_test_callTraceStorageand:ddprof-lib:gtestTsan_test_callTraceStoragein the glibc aarch64container — all pass on the final candidate, LeakSanitizer clean on the
partial-failure paths.
:ddprof-lib:qualityCheckspasses on the final tree.origin/main..HEAD+ fix range, bothclean of CRITICAL/HIGH findings.
For Datadog employees:
credentials of any kind, I've requested a security review (run the
dd:platform-security-reviewskill, or file a request via the PSEC review form).
bewairealso runs automatically on every PR.Unsure? Have a question? Request a review!