Fix JITted context tagging #8862
<!-- durable-reviewer:finding -->
ℹ️ INFO · Performance
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.
workerd installs this callback for every Worker isolate, so from here on optimized code never allocates promises inline. That is required for correctness, since inline-allocated promises would not be tagged. It is worth running a promise-heavy benchmark to measure the cost, and noting the trade-off so a later rebase does not drop this line as if it were a regression.
<!-- durable-reviewer:review run=347941be-6305-4b6e-9a6e-b90682063d41 -->
Superseded by the review of d3533f2b.<details>
<summary>This review, of <code>09ebc2d1</code></summary>
💬 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)
<sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>
---
📋 Code Quality: ❓ 1 question
The patches are internally consistent. One question about how the new mutable root is set.
Recommendation: 💬 Optional Nits
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)<details>
<summary>View full review</summary>
index line chain across the six patches is consistent.PromiseInit, InnerNewJSPromise and Factory::NewJSPromiseWithoutHook covers the promise creation paths in the patch.NeedsPromiseContextSwitch matches the runtime and JSPromise::Fulfill/Reject semantics.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.</details>
---
⚡ 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
patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:258)<details>
<summary>View full review</summary>
PromiseContextInit and PromiseResolveContextCheck runtime calls from the hot path.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.</details>
---
<details>
<summary>✅ All other checks passed</summary>
🔒 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.
</details>
---
<sub>Reviewed commit: 09ebc2d1</sub>
</details>
Approved these changes.
<!-- durable-reviewer:review run=f49ed487-1eb4-4bb7-9ecf-78601ff2de7e -->
💬 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
<sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>
---
📋 Code Quality: ❓ 1 question
The patches are internally consistent. One question about how the new mutable root is set.
Recommendation: 💬 Optional Nits
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)<details>
<summary>View full review</summary>
index line chain across the six patches is consistent.PromiseInit, InnerNewJSPromise and Factory::NewJSPromiseWithoutHook covers the promise creation paths in the patch.NeedsPromiseContextSwitch matches the runtime and JSPromise::Fulfill/Reject semantics.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.</details>
---
⚡ 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
patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:258)<details>
<summary>View full review</summary>
PromiseContextInit and PromiseResolveContextCheck runtime calls from the hot path.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.</details>
---
<details>
<summary>✅ All other checks passed</summary>
🔒 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.
</details>
---
<sub>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)</sub>
Approved these changes.
mar-cf
csjh
Make promise context tagging work in JITted code.
Every promise now records the
PromiseContextTagroot, which is the hole outside anyPromiseContextScope. 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 aPromiseContextTagTestunittest is added.Implement-cross-request-context-promise-resolve-handling: the root move now lives in the patch above, and thePromiseResolveContextCheckruntime call is replaced by the inlineNeedsPromiseContextSwitchcheck.indexlines.This mirrors the same fix in internal V8 patches.
🤖 Generated with Claude Code