Skip to content

[JSC] LLInt checks the slot base of get_by_id_direct, and DebuggerScope prohibits property caching - #1048

Open
robobun wants to merge 2 commits into
mainfrom
robobun/beafc4e8/llint-get-by-id-direct-slot-base
Open

robobun wants to merge 2 commits into
mainfrom
robobun/beafc4e8/llint-get-by-id-direct-slot-base

Conversation

@robobun

@robobun robobun commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • An own property read (get_by_id_direct) of globalThis loads from the wrong cell on its second run in LLInt. In Bun, the third console.write.call(globalThis, "") ends a release build: Segmentation fault at address 0xFFFFFFFFFFFFFE78 in llint_op_get_by_id_direct.
  • slow_path_get_by_id_direct (llint/LLIntSlowPaths.cpp:913) stores the base's structure with slot.cachedOffset(). A JSGlobalProxy answers with the slot of its target.
  • A DebuggerScope answers with the slot of its scope, and all scope objects of a realm share one structure. Caches keyed on it are wrong.

Fix

Background

  • get_by_id_direct reads an own property, never the prototype chain. Builtins write @getByIdDirect.
  • globalThis is a JSGlobalProxy: the global object behind it holds the properties. A DebuggerScope is the inspector's object for a scope of a paused frame.
  • Considered an LLInt cache that loads from the proxy's target: same cases, 2 more instructions per miss. Per-cache checks for DebuggerScope left hasOwnProperty and delete wrong.

Downsides

  • LLInt does not cache an own read of a proxy: 371 instructions per read against 36 (release jsc, JIT off). globalThis.x costs 433.
  • A paused scope that has a splice function and a finite length shows as an array at every pause, not only the first.
  • 13 bytes of text: 2 instructions per LLInt cache fill of this op.
Notes

The branch is on main 59e584e. The two commits have the source lines that they had on de04322. The one conflict with main was in the table of JSTests/BUN-TEST-DIFFERENCES.md, where other changes had added rows at the same place. The two rows of this change are now higher up in that table. The numbers below are from the new base, except where a row says otherwise.

Repro in jsc. jsc --useDollarVM=1 x.js:

var read = $vm.createBuiltin(`(function (o) { return @getByIdDirect(o, "hello"); })`);
globalThis.hello = 42;
print(read(globalThis)); // 42
print(read(globalThis)); // SIGSEGV. With --useLLIntICs=0: 42

The first run stores the proxy's StructureID with the offset that hello has in the global object. The second run finds the StructureID and loads that offset from the proxy. The proxy has no butterfly, so the address is a small negative number. The other tiers are right for a proxy: tryCacheGetBy switches to the proxy's target (bytecode/Repatch.cpp:586), and GetByStatus::computeFromLLInt takes the offset from the structure again.

What a user of Bun sees (release build, no flags. Each passes with BUN_JSC_useLLIntICs=0.)

  • for (let i = 0; i < 4; i++) console.write.call(globalThis, i + "\n") prints 0 and 1, then Segmentation fault. console.write keeps its writer on this with @putByIdDirectPrivate and reads it with @getByIdDirectPrivate. The put goes through defineOwnProperty to the global object. The second read stores the pair and the third loads through it. That code is from 2022-12.
  • The same with the global of vm.createContext(vm.constants.DONT_CONTEXTIFY): Segmentation fault.
  • The same with the global of vm.createContext({}): the third call throws TypeError: undefined is not a function. The read returns the cell in the proxy's first inline slot, which is its target, in place of the writer.
  • new tls.TLSSocket(undefined, { ca }).connect(globalThis), twice: Segmentation fault at the second handshake (Bun v1.4.4 and later).
  • No user reported any of these. hot: let the newest console iterator take stdin after a reload bun#43951 met the crash in a draft ($getByIdDirectPrivate(globalThis, ...)) and changed its call site.
  • A Bun branch that is not merged (robobun/529430d7/shell-own-raw-read) makes the shell's $ read raw of its first argument with $getByIdDirect. A first argument that is a global proxy needs this change.

The first stress test, get-by-id-direct-global-proxy.js. Six blocks. On the release jsc of main (59e584e) with default options, three end with SIGSEGV, one reads a wrong value and two pass. With --useJIT=0, the first five end with SIGSEGV.

  • globalThis: store, delete, inherited only, add again, getter, data property again. Each is read twice in a function that is still in LLInt, then testLoopCount times. SIGSEGV at the second read.
  • One site that reads an object and the proxy in turn. In the loop every read misses on main, so the loop passes there. The read of the proxy after the loop is the second in a row: SIGSEGV if the function is still in LLInt, which it always is with --useJIT=0. With default options the block passed in 40 of 40 runs on an idle machine.
  • A proxy of another realm ($vm.createGlobalProxy) and that realm's global object. SIGSEGV.
  • A proxy that has a private field of its own, and so a butterfly: expected 50 but got function Number() { [native code] }. With --useJIT=0: SIGSEGV.
  • @getByIdDirectPrivate after @putByIdDirectPrivate through the proxy: read, define, read, read. SIGSEGV.
  • A global variable, which is an own property of the global object with no offset. Passes on main.

The DebuggerScope half. DebuggerScope::getOwnPropertySlot calls getPropertySlot on the scope object with the caller's slot, and put, deleteProperty and defineOwnProperty forward too. main has four kinds of cache that go by the structure of the scope object: the inline caches of reads, in and delete, the HasOwnPropertyCache, the LLInt cache above, and the structure's memory that an object is not thenable. ProhibitsPropertyCaching is what actionForCell (Repatch.cpp:360), Structure::propertyAccessesAreCacheable() and HasOwnPropertyCache::tryAdd ask for. isDefinitelyNonThenable (runtime/JSPromise.cpp:705) asks for the absence flag alone. ProxyObject and JSCallbackObject have the first flag, and the module namespace object has the second.

Only a function that a debugger client runs with a scope object as this (Runtime.callFunctionOn) reaches the own read. The inspector reaches the other caches itself: see splice below.

The second stress test, debugger-scope-property-caches.js. Nine blocks, on scope objects from $vm.createDebuggerScope(). Results on a debug jsc of the first head of this branch, with one or both flags taken out of DebuggerScope::createStructure for the run:

block no flag only ProhibitsPropertyCaching only the absence flag both
own read, read and in that hit SEGV in JIT code pass SEGV in JIT code pass
a miss, then the scope gains the property stale undefined pass pass pass
two scope objects, one holds the property assertion in objectPrototypeHasOwnProperty pass the same assertion pass
delete after the function was compiled returns true, deletes nothing pass the same pass
a getter of the global object SEGV in JIT code pass SEGV in JIT code pass
a property that a with object inherits another cell in place of the value pass the same pass
a store pass pass pass pass
a miss through a scope object as a prototype stale undefined pass stale undefined pass
Promise.resolve(scope) reads then 0 reads 0 reads 1 read 1 read

With --useJIT=0 and no flag, the three hasOwnProperty blocks and the then block fail. The own reads pass there: the LLInt condition covers them.

splice. RemoteObject.subtype() (inspector/InjectedScriptSource.js:1155) calls a value an array when typeof value.splice === "function" and value.length is finite, and the inspector asks that of every scope object at every pause. For a function with var length = 2; function splice() {}, paused 12 times: main gives the scope object the subtype array at the first pause and none at the next 11, because the inline cache of value.splice keeps a miss for the structure of scope objects. With this change it is array at all 12. Bun's debug adapter lists such a scope by index. The rule, and not the read, is what is wrong for a scope. It is not changed here.

Tests run (head 7a4400a)

  • Both new files on the debug ASAN jsc with assertions and on the release jsc of this branch's preview build (autobuild-preview-pr-1048-7a4400aa), each with default options, --useJIT=0, --useLLInt=0, --useFTLJIT=false, --useLLIntICs=0, and --useConcurrentJIT=0 with thresholds of 10, 100 and 1000: 24 of 24 runs pass. The release jsc of main exits 139 on the first file. It has no $vm.createDebuggerScope for the second.
  • This repository's CI on this head: the 7 test jobs pass (3 on linux x64, 4 on linux arm64). Test bun-webkit-linux-arm64-lto-hardened-aot passed at its third run. The first two runs got runners without pointer authentication, and that lane's test step fails on such a runner whatever the tests did (.github/workflows/ci.yml:467).
  • In Bun (debug ASAN build of 24e5faf8d3 with the preview build): the 11 tests of test: own-property reads of a global proxy in builtins, and the debugger's scope objects bun#48831 pass, and so do their files: jsc-stress.test.ts (139), inspect.test.ts (34), console-write.test.ts (7) and node-tls-connect-hostname-verification.test.ts (21). With the prebuilt WebKit of Bun's main (499846f), 0 of the 11 pass.
  • On the first base (de04322): 128 files of JSTests/stress whose names hold get-by-id-direct, debugger-scope, class-field, private-name, private-method, private-accessor, private-getter, private-brand, private-in, global-proxy, global-this or object-assign-fast-path, with default options, with --useJIT=0 and with --useLLInt=0, on a debug ASAN jsc: all passed.

Measurements. Sizes and counts are of the release jsc (LTO, bun-webkit-linux-amd64-lto-aot) of main 59e584e and of this branch's preview build. Instruction counts per iteration are perf_event_open counts of instructions:u, the difference of runs of 2,000,000 and 1,000,000 iterations, with --useJIT=0. perf and valgrind are not on the machine. Rows marked "first base" are from de04322 and the first head of this branch: objects of Bun's release-local configuration (clang 23, -O3, no LTO), and Bun debug builds.

before after
the handlers llint_op_get_by_id_direct, _wide16, _wide32 225, 228, 228 bytes 225, 228, 228 bytes
LowLevelInterpreter.cpp.o, -O3 object (first base) the same SHA-256
llint_slow_path_get_by_id_direct, LTO 2,808 bytes 2,821 bytes
llint_slow_path_get_by_id_direct, -O3 object (first base) 2,364 bytes, 562 instructions 2,377 bytes, 564 instructions (+1 cmpq, +1 jne)
DebuggerScope::createStructure, LTO 223 bytes 223 bytes
functionCreateDebuggerScope, LTO 261 bytes
text of jsc (llvm-size), which has $vm 57,078,977 57,079,233
instructions for new A of class A { x = 1 }, LLInt only 942.69, 942.30, 942.37 942.37, 942.30, 942.28
instructions for an own read of a plain object, LLInt only 36 36
instructions for an own read of globalThis, LLInt only SIGSEGV at read 2 (370 with --useLLIntICs=0) 371
instructions for globalThis.hello through get_by_id, LLInt only 433 433
instructions for one turn of a loop that reads an object and globalThis at one site, LLInt only, with the loop 1,546 1,223
LLInt slow-path entries for 1,000 more reads of a plain object, or 1,000 more new A, JIT off 0 0
the same for 1,000 more reads of globalThis SIGSEGV at read 2 1,000
the same for 1,000 more pairs of an object and globalThis at one site 2,000 1,000
LLInt slow-path entries in 100,000 reads of globalThis, JIT on 36 to 41, then the JIT caches the read
lookups on scope objects for one pause with a variables listing (Bun, Runtime.getDisplayableProperties of each scope; first base) 34 60

The counts for one read are less the 520 instructions of the loop and the call. The slow-path entries are breakpoint counts in gdb. A release bun has no $vm, so the helper adds nothing there: the 13 bytes of the slow path are the whole change in its text. Between the two bases debugger/ has no difference, and inspector/ has one, in InspectorHeapAgent.cpp. So the count of lookups stands.

Both new files end in 12 to 13 ms on the release jsc of the preview build with default options, and in 5 to 9 ms with --useJIT=0. On the debug ASAN jsc they take 0.1 to 1.3 s.

In Bun (debug build of 24e5faf8d3 with the preview build), llint_slow_path_get_by_id_direct is entered 0 times by bun -e 0 and by console.log(1), once by console.write("x"), 3 times by a script that makes a TLS server, and once more for a tls.connect() to it.

Not in this change

@claude claude 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.

I reviewed this PR and didn't find any bugs. Because it changes LLInt inline-cache fill conditions and the structure flags of a debugger-owned object, a human look would still be worthwhile.

What was reviewed:

  • The new slot.slotBase() == baseValue guard in slow_path_get_by_id_direct matches the existing get_by_id fill condition at LLIntSlowPaths.cpp:1099; the metadata clear still happens before the cacheability check.
  • ProhibitsPropertyCaching and GetOwnPropertySlotIsImpureForPropertyAbsence on DebuggerScope are consulted by Structure::propertyAccessesAreCacheable, actionForCell, HasOwnPropertyCache::tryAdd, PropertyCondition absence checks and JSPromise's thenable check; the slower per-pause scope view is a deliberate trade-off, not a defect.
  • $vm.createDebuggerScope uses DebuggerScope::create(vm, JSScope*) with the global object or JSCallee::scope(), consistent with existing $vm helpers.
  • Not done here: the JSTests/README 200ms-per-configuration budget and the fails-without-fix check for the two new stress tests could not be run in this review; the PR's own test results were not independently reproduced.
Extended reasoning...

The change touches the LLInt get_by_id_direct cache fill in Source/JavaScriptCore/llint/LLIntSlowPaths.cpp, the StructureFlags of DebuggerScope in Source/JavaScriptCore/debugger/DebuggerScope.h, a new test-only $vm.createDebuggerScope helper in Source/JavaScriptCore/tools/JSDollarVM.cpp, two new stress tests, and a doc table row. It touches no injection, auth or data-exposure surface; the fix prevents a wrong-offset load (memory-safety crash) in the interpreter. Deferring rather than approving because the diff alters inline-cache semantics in the core engine, the debugger directory is covered by .github/CODEOWNERS, and the test timing and regression checks the JSTests README requires could not be executed in this run.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adjusts direct-read inline-cache handling for global proxies and debugger scopes. It adds a DollarVM helper for creating debugger scopes and adds stress tests for global-proxy reads, debugger-scope property behavior, and promise resolution.

Changes

Global Proxy Direct Reads

Layer / File(s) Summary
Direct-read cache and global-proxy tests
Source/JavaScriptCore/llint/LLIntSlowPaths.cpp, JSTests/stress/get-by-id-direct-global-proxy.js, JSTests/BUN-TEST-DIFFERENCES.md
The direct-read slow path now caches a value slot only when its slot base is the original base value. The new stress test covers global-proxy reads, updates, deletion, inheritance, getters, other realms, and private-name access. The fork test table describes both new tests.

Debugger Scope Property Caches

Layer / File(s) Summary
Debugger scope creation and cache behavior
Source/JavaScriptCore/debugger/DebuggerScope.h, Source/JavaScriptCore/tools/JSDollarVM.cpp, JSTests/stress/debugger-scope-property-caches.js
DebuggerScope adds flags that prohibit property caching and mark absent-property lookup as impure. DollarVM adds $vm.createDebuggerScope, which uses a function’s captured scope when given a JSFunction, or the current global object otherwise. The stress test covers reads, membership checks, deletion, getters, inheritance, writes, and promise resolution.

Suggested reviewers: patrickangle

Merge Risk: Minimal · up to 68885

The change makes LLInt skip caching property reads that are forwarded through a global proxy, and stops DebuggerScope lookups from being cached. This should fix incorrect reads and crashes, at the cost of slightly slower proxy reads. No actionable merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes: the LLInt slot-base check for get_by_id_direct and the DebuggerScope property-caching prohibition. Both match the changeset, which modifies LLIntSlowPaths.cpp and…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description covers the problem, the fix, background, downsides, and test evidence. It follows the WebKit template's intent: it names the bug and the affected code (LLIntSlowPaths.cpp, DebuggerScop…
Full details: Title check

Explanation

The title names the two main changes: the LLInt slot-base check for get_by_id_direct and the DebuggerScope property-caching prohibition. Both match the changeset, which modifies LLIntSlowPaths.cpp and DebuggerScope.h and adds the createDebuggerScope helper. The title is long but specific and accurate.

Full details: Description check

Explanation

The description covers the problem, the fix, background, downsides, and test evidence. It follows the WebKit template's intent: it names the bug and the affected code (LLIntSlowPaths.cpp, DebuggerScope.h, JSDollarVM.cpp), explains why the change fixes the bug, and reports verification. It does not include the template's Bugzilla bug link or the Reviewed-by line, and it does not list changed files in the template's ChangeLog-style format. These are the template items the author would need to add before merge, but the description is otherwise mostly complete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

The configuration directory could not be loaded. This review used the available YAML and UI settings; directory instructions and checks were not evaluated.

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ed87182f-0c4d-44db-be2a-06d9f8ff90f2
Commits

Reviewing files that changed from the base of the PR and between de04322 and 6888512.

Files selected for processing: 6

  • JSTests/BUN-TEST-DIFFERENCES.md
  • JSTests/stress/debugger-scope-property-caches.js
  • JSTests/stress/get-by-id-direct-global-proxy.js
  • Source/JavaScriptCore/debugger/DebuggerScope.h
  • Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
  • Source/JavaScriptCore/tools/JSDollarVM.cpp

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Preview build of 7a4400a: autobuild-preview-pr-1048-7a4400aa

…he property

A JSGlobalProxy answers an own property lookup with the slot of its
target, the global object. LLInt stored the structure of the proxy with
the offset of that slot, and the next run of the bytecode loaded that
offset from the proxy.

LLInt stores the pair only when the slot base is the base, as it does
for get_by_id.
A DebuggerScope answers a lookup with the slot of the scope behind it,
and every scope object of a realm has one structure. A cache that goes
by that structure kept where one scope has a property as a place in the
scope object, what one scope holds as what every scope holds, and that
a name is missing after the scope had got it.

The class gets ProhibitsPropertyCaching and
GetOwnPropertySlotIsImpureForPropertyAbsence, as the other classes that
forward a lookup have. $vm.createDebuggerScope() makes a scope object
without a debugger, for the tests.
@robobun
robobun force-pushed the robobun/beafc4e8/llint-get-by-id-direct-slot-base branch from 2eaae17 to 7a4400a Compare November 21, 2026 23:53

@claude claude 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.

I reviewed the current version of this PR and found no bugs; because it changes LLInt inline-cache fill policy and the type-info flags of an inspector object (paths covered by CODEOWNERS), a human look from a JSC/debugger owner would still be worthwhile.

What was reviewed:

  • slow_path_get_by_id_direct in Source/JavaScriptCore/llint/LLIntSlowPaths.cpp: the new slot.slotBase() == baseValue guard is the same condition slow_path_get_by_id already uses at line 1101, so a JSGlobalProxy read can no longer store the target's offset under the proxy's StructureID; when the guard fails the metadata is left as is, which is safe because the proxy's structure is never recorded in it.
  • DebuggerScope::StructureFlags: ProhibitsPropertyCaching and GetOwnPropertySlotIsImpureForPropertyAbsence are consumed only by cache gates (actionForCell, HasOwnPropertyCache::tryAdd, propertyAccessesAreCacheable, PropertyCondition, JSPromise::isDefinitelyNonThenable, the AOT cache answers), matching how ProxyObject, JSCallbackObject and JSModuleNamespaceObject use them; no non-cache semantics change.
  • $vm.createDebuggerScope handles a non-function or absent argument (dynamicDowncast returns null on a non-cell) and takes the structure from the scope's own realm; both new stress tests are listed in JSTests/BUN-TEST-DIFFERENCES.md as the root CLAUDE.md asks.
  • Not done in this run: running the two new stress tests or the JSTests suite against a built jsc.
Extended reasoning...

The change is two one-line engine edits (a slot-base guard in the LLInt get_by_id_direct cache fill, and two structure flags on DebuggerScope), a new $vm test helper, two stress tests, and a test-differences doc entry; it touches no auth, injection or data-exposure surface, but it does touch the inline-cache path whose stale offset caused a segfault and changes caching behavior for every inspector scope object across all tiers. The code matches the established get_by_id pattern and existing flag usage, and the bug hunt ran dry, which argues for correctness; what decided defer over approve is that all changed paths fall under CODEOWNERS entries for JavaScriptCore and its debugger directory, the prior review's text on the earlier push is not visible so I cannot confirm its points were addressed, and the tests were not run here.

robobun added a commit to oven-sh/bun that referenced this pull request Nov 22, 2026
…ger's scope objects

console.write and TLSSocket#connect() read an own property of an object
that the caller gives them. With globalThis, or the global of a node:vm
context, JavaScriptCore's interpreter kept the place of the property in
the global object as a place in the proxy, and the next read crashed or
returned another cell. The scope objects of a paused call frame had
caches of the same kind.

oven-sh/WebKit#1048 corrects the engine. These are Bun's tests for it.
robobun added a commit to oven-sh/bun that referenced this pull request Nov 22, 2026
Not for merge. The preview build is WebKit main 59e584ea0b with the two
commits of that pull request, which the tests of this branch need. The line
and webkit.sha256 go back when main's WebKit has the change.
robobun added a commit to oven-sh/bun that referenced this pull request Nov 22, 2026
Not for merge. The preview build of oven-sh/WebKit#1048 has WebKit main in
it, and with it oven-sh/WebKit#1083, which Bun's main does not pin yet.
These are the three test changes that #49366 makes for that
engine. The commit goes when that pull request is in main.

Co-authored-by: SUZUKI Sosuke <14838850+sosukesuzuki@users.noreply.github.com>
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.

1 participant