Skip to content

fix(taskblock): reject invalid thresholds and recover abandoned intervals (PROF-14931) - #915

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

jbachorik wants to merge 51 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?:

Hardens the paired TaskBlock API added in #664:

  • Fails closed when the 1 ms threshold derived from the TSC frequency is zero. These intervals count in task_block_threshold_invalid, not in task_block_skipped_too_short.
  • beginTaskBlock() recovers an interval whose endTaskBlock() never ran. Recovery runs only after the begin admission checks, and it closes the tracker run only when the token matches the current slot and generation. It counts in task_block_recovered_abandoned.
  • JVMSupport::isPlatformThread() returns false on non-HotSpot VMs that report JNI 19 or later, without reading the virtual-thread slot of the JNI function table.
  • Counts a blockEnter skipped by an active trace context in block_enter_skipped_trace_context.

Motivation:

An uncalibrated clock (TSC frequency below 1 kHz) makes the threshold zero. A zero threshold would admit every positive interval and hide the clock problem as normal events.

A missed endTaskBlock() must not leave the thread's paired token in place forever, because that also suppresses its later wall signals. Native code cannot tell an abandoned begin from a nested one, so the replacement rule must be explicit.

IsVirtualThread is read through a hard-coded JNI table offset (slot 234). This offset is verified only on HotSpot. Reading it on another VM could call the wrong function.

Additional Notes:

  • Stack: builds on feat(taskblock): record completed intervals with DEBUG diagnostic receipts (PROF-14931) #664. The clock change validates the derived threshold. It does not change TSC calibration.
  • Reviewer acknowledgment, paired API semantics: a begin that passes admission discards any pending interval without an event, nested or abandoned. A later endTaskBlock() with the discarded token returns false. Begin keeps the pending interval when it returns 0 for these early reasons: recording inactive, caller not verified, not a platform thread, or active span. A later failure to arm the replacement can also return 0 after the discard, so 0 alone does not mean the old interval was kept. Callers must still call endTaskBlock() in finally; the Javadoc says so.
  • Under an active span, recovery waits: a nested live interval is indistinguishable from an abandoned one, and keeping the live one has priority.
  • Reviewer acknowledgment, VM support: on non-HotSpot VMs with JNI 19 or later, beginTaskBlock() always returns 0 and endTaskBlock() returns false. This restricts the paired API only, not other profiling. feat(taskblock): add JVM producers and retain failed recording output (PROF-14931) #665 extends the classifier contract to the JVM producers.
  • No new JFR field, automatic producer, backend change or rollout.
  • Contracts: paired intervals, platform-thread classification.
  • Human review: mandatory (label human_review:mandatory). Reason: changes the public beginTaskBlock() contract (silent discard of a pending interval) and JVM-specific classification.

How to test the change?:

Added coverage:

  • gtests: TaskBlockRecorderTest.UncalibratedTscFailsClosed and UninitializedThresholdIsRecomputedFromTscFrequency; AbandonedTaskBlockTest (abandoned run closed, nothing pending, non-decodable token, newer run and foreign slot not closed); TaskBlockRealRecorderTest (stripe release and single count on stack failure, contention, inactive recorder, thread-table overflow); PairedTaskBlockRestartTest; JvmSupportNonHotspotTest (JNI 19 and 21 rejected without reading the table); ProfilerLockIndexTest; WallClockInitialEpochTest; WallTailRecordingTest.TailCarriesWeightAccumulatedWhileBlocked.
  • Java: JavaProfilerTaskBlockApiTest (abandonedIntervalDoesNotDisableTaskBlockForThread, traceContextRejectionKeepsOpenInterval), JavaProfilerTaskBlockNonHotspotTest.platformThreadCannotArmTaskBlock (fail-closed classification, no event), UnfilteredWallPrecheckTest.tracedBlockEnterIsSkippedAndCounted, JavaProfilerTaskBlockLightweightTest.

Run:

  • ./.claude/commands/build-and-summarize :ddprof-lib:gtestDebug :ddprof-lib:gtestRelease
  • ./.claude/commands/build-and-summarize :ddprof-test:testDebug -Ptests='JavaProfilerTaskBlock*'
  • JavaProfilerTaskBlockNonHotspotTest needs a non-HotSpot JDK 19+ as JAVA_TEST_HOME; it runs only where platform-thread classification is not supported.

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

Unsure? Have a question? Request a review!

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: #45696093374 | Commit: cfd431f | Duration: 26m 4s (longest job)

❌ 1 of 32 test jobs failed

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

⚠️ Flaky tests — failed, then passed on retry

Test Cells Message
MallocArenaWarningTest.statsEventsDescribeTheArenas__ glibc-8-orcl-debug-amd64 org.opentest4j.AssertionFailedError: expected: <489684992> but was: <477626368>

These fail the build. Passing on a second run makes a test flaky, not passing. Fix it, or quarantine it against a ticket so the debt is tracked rather than forgotten.

Consider quarantining these — click for ready-made entries

A quarantined test still runs and still reports; its failures just stop
turning CI red. To quarantine one:

  1. Open a PROF ticket for the test, linking the failing job.
  2. Append the line below to ddprof-test/quarantine.txt, replacing
    PROF-XXXXX with the ticket number.
  3. Check the cells and reason columns — the proposal only knows what
    failed in this run, and a narrower cells glob keeps the same test
    gating everywhere it has not misbehaved.

CI fails once review_by passes, so an entry expires instead of piling up.

# test | ticket | added | review_by | cells | reason
com.datadoghq.profiler.nativemem.MallocArenaWarningTest.statsEventsDescribeTheArenas | PROF-XXXXX | 2026-11-25 | 2027-02-23 | glibc-8-orcl-debug-amd64 | org.opentest4j.AssertionFailedError: expected: <489684992> but was: <477626368> (seen in: glibc-8-orcl-debug-amd64)

Retried 1 of 32 cells.

Failed Jobs

Summary: Total: 32 | Passed: 31 | Failed: 1


Updated: 2026-11-25 21:05:01 UTC

@dd-octo-sts

dd-octo-sts Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 846e9980

@datadog-datadog-prod-us1

This comment has been minimized.

@kaahos
kaahos added this pull request to stack #988 November 12, 2026 23:32
Emit the getLockIndex definition for cross-translation-unit callers and
cover optimized linking with a recording-stripe lookup regression.

Wait for the wall timer's initial sampling epoch in the debug-only
synchronous dump driver. Bound the normal-thread wait and test ready,
delayed-publication, and timeout behavior without changing zero-epoch
production fallback or weakening the JFR assertions.
@dd-octo-sts

dd-octo-sts Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Reliability & Chaos Results

✅ All reliability & chaos checks passed Pipeline: https://gitlab.ddbuild.io/DataDog/java-profiler/-/pipelines/153120055

@kaahos
kaahos removed this pull request from stack #988 November 14, 2026 10:46
kaahos added a commit that referenced this pull request Nov 20, 2026
kaahos added a commit that referenced this pull request Nov 20, 2026
kaahos added a commit that referenced this pull request Nov 23, 2026
# Conflicts:
#	ddprof-test/src/test/java/com/datadoghq/profiler/wallclock/UnownedWallTailContextTransitionTest.java
kaahos added a commit that referenced this pull request Nov 23, 2026
kaahos added a commit that referenced this pull request Nov 23, 2026
kaahos added a commit that referenced this pull request Nov 24, 2026
kaahos added a commit that referenced this pull request Nov 24, 2026
kaahos added a commit that referenced this pull request Nov 25, 2026
# Conflicts:
#	ddprof-lib/src/main/cpp/wallClock.h
#	ddprof-lib/src/test/cpp/wallClock_ut.cpp
kaahos added a commit that referenced this pull request Nov 25, 2026
# Conflicts:
#	ddprof-lib/src/main/cpp/wallClock.h
#	ddprof-test/src/test/java/com/datadoghq/profiler/JavaProfilerTestSupport.java
kaahos added a commit that referenced this pull request Nov 25, 2026
kaahos added a commit that referenced this pull request Nov 25, 2026
# Conflicts:
#	doc/README.md
@dd-octo-sts

dd-octo-sts Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Memory overhead check: ✅ within budget

Profiler 846e99802, pipeline. Budget: utils/memcheck/budget.txt. NMT and /proc values are profiled minus no-profiler runs on the same runner.

scenario metric value Δ since budget set limit headroom
allocs native_mem_live_bytes 21.91 MiB +227 KiB 21.95 MiB 39 KiB ok
allocs native_mem_max_bytes 23.16 MiB +210 KiB 23.20 MiB 46 KiB ok
allocs nmt.class 302 KiB +5 KiB 563 KiB 261 KiB ok
allocs nmt.internal 369 KiB +0 KiB 666 KiB 297 KiB ok
classesM native_mem_live_bytes (coverage-corrected) 23.48 MiB +209 KiB 23.55 MiB 68 KiB ok
classesM native_mem_max_bytes (coverage-corrected) 25.42 MiB +237 KiB 25.45 MiB 29 KiB ok
classesM nmt.class 2.94 MiB −1 KiB 3.20 MiB 267 KiB ok
classesM nmt.internal 3.21 MiB +12 KiB 3.50 MiB 296 KiB ok
mixed native_mem_live_bytes 23.40 MiB +253 KiB 23.45 MiB 55 KiB ok
mixed native_mem_max_bytes 40.97 MiB +257 KiB 41.00 MiB 30 KiB ok
mixed nmt.class 302 KiB −5 KiB 563 KiB 261 KiB ok
mixed nmt.internal 406 KiB −3 KiB 717 KiB 310 KiB ok
threads native_mem_live_bytes 19.31 MiB +225 KiB 19.35 MiB 41 KiB ok
threads native_mem_max_bytes 20.34 MiB +231 KiB 20.40 MiB 66 KiB ok
threads nmt.class 114 KiB +1 KiB 410 KiB 296 KiB ok
threads nmt.internal 158 KiB −6 KiB 461 KiB 303 KiB ok
traces native_mem_live_bytes 20.44 MiB +217 KiB 20.50 MiB 60 KiB ok
traces native_mem_max_bytes 21.66 MiB +251 KiB 21.70 MiB 46 KiB ok
traces nmt.class 470 KiB −1 KiB 768 KiB 298 KiB ok
traces nmt.internal 611 KiB −3 KiB 870 KiB 259 KiB ok

✅ nmt.tracing absent in every scenario.

Not budgeted (too noisy on shared runners)
scenario nmt.code nmt.gc nmt.total proc.VmRSS proc.RssAnon
allocs 1.70 MiB 2 KiB 2.97 MiB 31.93 MiB 27.60 MiB
classesM 5.50 MiB 15 KiB 13.73 MiB 36.83 MiB 32.24 MiB
mixed 1.61 MiB 4 KiB 3.24 MiB 22.78 MiB 18.25 MiB
threads 6 KiB 1 KiB 486 KiB 24.96 MiB 19.90 MiB
traces 4.36 MiB −2 KiB 5.96 MiB 26.68 MiB 22.16 MiB

kaahos added a commit that referenced this pull request Nov 25, 2026
# Conflicts:
#	ddprof-test/src/test/java/com/datadoghq/profiler/wallclock/UnownedWallTailContextTransitionTest.java
kaahos added a commit that referenced this pull request Nov 25, 2026
kaahos added a commit that referenced this pull request Nov 25, 2026
kaahos added a commit that referenced this pull request Nov 25, 2026

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

AI human_review:mandatory Human review required — see PR description

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants