Skip to content

fix: address TaskBlock review findings (stacked on #664) - #915

Open
jbachorik wants to merge 14 commits into
paul.fournillon/taskblock-corefrom
taskblock-review-fixes
Open

jbachorik wants to merge 14 commits into
paul.fournillon/taskblock-corefrom
taskblock-review-fixes

Conversation

@jbachorik

@jbachorik jbachorik commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?:

Implements the 8 findings from an agentic code review of #664 (TaskBlock event recording core), as a stacked fix branch so the fixes can be accepted directly instead of being re-derived from review comments. One commit per finding group, plus the review's second-round fixes.

Motivation:

The review of #664 surfaced one functional hazard and several contract/test gaps in the new TaskBlock recording path:

  • beginTaskBlock() without a matching endTaskBlock() (e.g. an exception without finally) stranded the thread-local token forever: every later beginTaskBlock() failed for the life of the thread, and the orphaned TASK_BLOCK-owned tracker run suppressed wall-clock signals for that thread indefinitely. A generation-checked recovery now supersedes an abandoned interval at the next beginTaskBlock() (TASK_BLOCK_RECOVERED_ABANDONED).
  • JVMSupport::isPlatformThread() assumed any non-HotSpot JVM at JNI ≥ 19 has no virtual threads, admitting virtual threads into carrier-only state. It now fails closed: non-HotSpot JVMs classify no thread as a platform thread until each VM's JNI table is verified.
  • An uncalibrated TSC made the 1 ms duration threshold compute to 0, letting every block through silently; the filter now fails closed and counts it under a dedicated task_block_threshold_invalid counter instead of masquerading as "too short".
  • blockEnter0 silently disarmed owned-block suppression for traced threads; it now increments block_enter_skipped_trace_context, symmetric with beginTaskBlock0.
  • Contract and test-adequacy gaps closed: the JFR duration encoding, the deferred-tail weight, and the duration-threshold fallback are now asserted; stale comments fixed.

Additional Notes:

  • Review provenance: two sphinx review rounds over this change set (19 + 7 findings). All MEDIUM/HIGH findings were fixed; the rest were fixed or explicitly dismissed with rationale in the review sessions (srs_ADHSJBhREPCPpU9ld3ea6fpV, srs_6btCf90wtiQrlxxlT8hiYKbF).
  • Behavior change for non-HotSpot JVMs on JDK 19+: no TaskBlock events and no ProfilerOwnedBlockHooks.blockEnter runs until each VM is verified. The J9/Zing-specific arming tests are skipped there accordingly.
  • Recovery under a permanently active trace context is deferred by design (documented in javaApi.cpp): the caller-visible contract ("a 0 return keeps the open interval") takes precedence, since native code cannot distinguish a nested live interval from an abandoned one.

How to test the change?:

New coverage: AbandonedTaskBlockTest and threshold tests in taskBlockRecorder_ut.cpp, the no-observer tail-write and non-decodable-token cases in wallTailRecording_ut.cpp, JavaProfilerTaskBlockNonHotspotTest, duration/weight assertions in JavaProfilerTaskBlockApiTest/JavaProfilerTaskBlockLightweightTest, and traceContextRejectionKeepsOpenInterval in JavaProfilerTaskBlockApiTest.

  • ./.claude/commands/build-and-summarize :ddprof-lib:gtestDebug
  • ./.claude/commands/build-and-summarize :ddprof-test:testDebug -Ptests=JavaProfilerTaskBlockApiTest
  • ./.claude/commands/build-and-summarize :ddprof-test:testDebug -Ptests=UnfilteredWallPrecheckTest

All of the above pass on JDK 21 HotSpot, plus the full gtestDebug suite and spotlessCheck.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a security review (run the dd:platform-security-review skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: PROF-14931

A begin whose endTaskBlock was never reached left the TLS token set,
so every later begin on the thread failed, and its TASK_BLOCK run kept
suppressing wall-clock signals. A new begin now supersedes the pending
interval: it clears the token and closes the run with the
generation-checked exitBlockedRun(), counting
TASK_BLOCK_RECOVERED_ABANDONED. Document the finally requirement and
the supersede policy on beginTaskBlock.
isPlatformThread() returned true on non-HotSpot JVMs reporting JNI 19+
without probing, so virtual threads could enter task-block producer
state. The hardcoded IsVirtualThread table offset is only trusted on
HotSpot, so other VMs now report every thread as non-platform, which
keeps task-block hooks disabled there. Skip the arming TaskBlock tests
on those JVMs and add a test asserting begin returns 0 there.
computeMinTaskBlockTicks() yields 0 when TSC::frequency() is below
1 kHz, and a zero threshold let every block pass the 1 ms minimum.
exceedsMinTaskBlockDuration() now rejects in that case, which the
caller counts as TASK_BLOCK_SKIPPED_TOO_SHORT. Add test-only hooks to
reset the cached threshold and replace the frequency source, and
cover the lazy recompute path and the fail-closed path.
Add TaskBlockAssertions.assertContainsDuration() and bound the encoded
duration in the paired-API and lightweight TaskBlock tests.
Add a test-only observer for the event recordUnownedBlockedTail()
writes and a gtest that accumulates suppressed weight before the tail
flush and checks the emitted weight matches it.
blockEnter0 returned 0 for traced threads without any counter, unlike
beginTaskBlock0. Increment BLOCK_ENTER_SKIPPED_TRACE_CONTEXT on that
path and test it.
@jbachorik jbachorik added the AI label Oct 27, 2026
@jbachorik
jbachorik marked this pull request as ready for review October 27, 2026 18:03
@jbachorik
jbachorik requested a review from a team as a code owner October 27, 2026 18:03
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T18:06:58.404891Z b626adf Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Abandoned TaskBlock recovery retains generation checks, and invalid duration thresholds fail closed. The completed static review reported no actionable correctness regression; runtime behavior was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b626adf

@dd-octo-sts

dd-octo-sts Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #40555987154 | Commit: 9e35e51 | Duration: 19m 42s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ ✅ - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-10-27 18:30:31 UTC

@dd-octo-sts

dd-octo-sts Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 b626adff

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant