Skip to content

Fix JITted context tagging - #8862

Merged
csjh merged 1 commit into
mainfrom
cormick/fix-jitted-context-tagging
Nov 24, 2026
Merged

csjh merged 1 commit into
mainfrom
cormick/fix-jitted-context-tagging

Conversation

@csjh

@csjh csjh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Make promise context tagging work in JITted code.

Every promise now records the PromiseContextTag root, which is the hole outside any PromiseContextScope. Builtins copy and compare the tag inline and call the runtime only when the tags differ. Optimized code (Maglev and TurboFan) allocates promises inline while the PromiseHook protector holds, without tagging them, so setting the cross-context callback now invalidates the protector.

Patch changes:

  • Implement-Promise-Context-Tagging: the tag moves into a root, the default tag is the hole instead of Smi 0, tag checks happen inline in builtins, and a PromiseContextTagTest unittest is added.
  • Implement-cross-request-context-promise-resolve-handling: the root move now lives in the patch above, and the PromiseResolveContextCheck runtime call is replaced by the inline NeedsPromiseContextSwitch check.
  • Four other patches change only in their index lines.

This mirrors the same fix in internal V8 patches.

🤖 Generated with Claude Code

@csjh
csjh requested review from a team as code owners November 24, 2026 05:17

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of d3533f2b.

This review, of 09ebc2d1

💬 Approved with comments — No blocking or warning-level defects. There is one question about the new root's placement for debug builds and one informational note about the cost of invalidating the PromiseHook protector.

Findings: 1 question · 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: ❓ 1 question

The patches are internally consistent. One question about how the new mutable root is set.

Recommendation: 💬 Optional Nits

  • [QUESTION] Please confirm that the new PromiseContextTag root sits in a movable mutable root list, so Heap::set_promise_context_tag can be called after deserialization (on every PromiseContextScope entry) and can hold a young-generation object without tripping a debug-build DCHECK. (patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:479)
View full review
  • The index line chain across the six patches is consistent.
  • Moving the tag into PromiseInit, InnerNewJSPromise and Factory::NewJSPromiseWithoutHook covers the promise creation paths in the patch.
  • NeedsPromiseContextSwitch matches the runtime and JSPromise::Fulfill/Reject semantics.
  • One question: PromiseContextTag is a mutable root, and PromiseContextScope writes it on every scope entry after deserialization has finished. Please confirm it sits in a root list whose setter allows that, so debug builds do not hit a DCHECK.

⚡ Performance: 💬 1 info

Invalidating the protector turns off inline promise allocation in optimized code for every isolate that sets the callback. The builtin changes are a net improvement.

Recommendation: 💬 Optional Nits

  • [INFO] Setting the cross-context callback invalidates the PromiseHook protector, which turns off inline promise allocation (and other fast paths that depend on the protector) in Maglev and TurboFan for every Worker isolate. (patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:258)
View full review
  • Builtins now copy and compare the tag inline and call the runtime only when the tags differ. That removes the per-promise PromiseContextInit and PromiseResolveContextCheck runtime calls from the hot path.
  • The trade-off: set_promise_cross_context_callback invalidates the PromiseHook protector. workerd installs that callback in every Worker isolate, so Maglev and TurboFan never allocate promises inline there. This cost is required for correctness.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security concerns in the reworked promise context tagging patches.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates are needed.


📝 Documentation: ✅ LGTM

The patch commit message describes the new behaviour accurately.


Reviewed commit: 09ebc2d1

Make promise context tagging work in JITted code. Every promise now
records the PromiseContextTag root, which is the hole outside any
PromiseContextScope; builtins copy and compare the tag inline and
call the runtime only when the tags differ. Optimized code allocates
promises inline while the PromiseHook protector holds, so setting the
cross-context callback invalidates the protector.

The root-based tag moves from the cross-request resolve patch into
the context tagging patch, and the resolve patch drops its
PromiseResolveContextCheck runtime call in favor of the inline check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@csjh
csjh force-pushed the cormick/fix-jitted-context-tagging branch from 09ebc2d to d3533f2 Compare November 24, 2026 17:30
@csjh
csjh enabled auto-merge (squash) November 24, 2026 17:30

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💬 Approved with comments — No blocking or warning-level defects. There is one question about the new root's placement for debug builds and one informational note about the cost of invalidating the PromiseHook protector.

Findings: 1 question · 1 info

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: ❓ 1 question

The patches are internally consistent. One question about how the new mutable root is set.

Recommendation: 💬 Optional Nits

  • [QUESTION] Please confirm that the new PromiseContextTag root sits in a movable mutable root list, so Heap::set_promise_context_tag can be called after deserialization (on every PromiseContextScope entry) and can hold a young-generation object without tripping a debug-build DCHECK. (patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:479)
View full review
  • The index line chain across the six patches is consistent.
  • Moving the tag into PromiseInit, InnerNewJSPromise and Factory::NewJSPromiseWithoutHook covers the promise creation paths in the patch.
  • NeedsPromiseContextSwitch matches the runtime and JSPromise::Fulfill/Reject semantics.
  • One question: PromiseContextTag is a mutable root, and PromiseContextScope writes it on every scope entry after deserialization has finished. Please confirm it sits in a root list whose setter allows that, so debug builds do not hit a DCHECK.

⚡ Performance: 💬 1 info

Invalidating the protector turns off inline promise allocation in optimized code for every isolate that sets the callback. The builtin changes are a net improvement.

Recommendation: 💬 Optional Nits

  • [INFO] Setting the cross-context callback invalidates the PromiseHook protector, which turns off inline promise allocation (and other fast paths that depend on the protector) in Maglev and TurboFan for every Worker isolate. (patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:258)
View full review
  • Builtins now copy and compare the tag inline and call the runtime only when the tags differ. That removes the per-promise PromiseContextInit and PromiseResolveContextCheck runtime calls from the hot path.
  • The trade-off: set_promise_cross_context_callback invalidates the PromiseHook protector. workerd installs that callback in every Worker isolate, so Maglev and TurboFan never allocate promises inline there. This cost is required for correctness.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security concerns in the reworked promise context tagging patches.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates are needed.


📝 Documentation: ✅ LGTM

The patch commit message describes the new behaviour accurately.


Reviewed commit: d3533f2b — same changes as 09ebc2d1, so this is that commit's review (no new review was run; line numbers are as of 09ebc2d1)

@csjh
csjh merged commit 1b795e9 into main Nov 24, 2026
23 of 25 checks passed
@csjh
csjh deleted the cormick/fix-jitted-context-tagging branch November 24, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Promises created in optimized code have no context tag, so a request awaiting one resumes in the wrong request

3 participants