Repository navigation
[JSC] LLInt checks the slot base of get_by_id_direct, and DebuggerScope prohibits property caching - #1048
[JSC] LLInt checks the slot base of get_by_id_direct, and DebuggerScope prohibits property caching#1048robobun wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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() == baseValueguard inslow_path_get_by_id_directmatches the existingget_by_idfill condition at LLIntSlowPaths.cpp:1099; the metadata clear still happens before the cacheability check. ProhibitsPropertyCachingandGetOwnPropertySlotIsImpureForPropertyAbsenceonDebuggerScopeare consulted byStructure::propertyAccessesAreCacheable,actionForCell,HasOwnPropertyCache::tryAdd,PropertyConditionabsence checks andJSPromise's thenable check; the slower per-pause scope view is a deliberate trade-off, not a defect.$vm.createDebuggerScopeusesDebuggerScope::create(vm, JSScope*)with the global object orJSCallee::scope(), consistent with existing$vmhelpers.- 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.
|
No actionable comments were generated in the recent review. WalkthroughThe 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. ChangesGlobal Proxy Direct Reads
Debugger Scope Property Caches
Suggested reviewers: Merge Risk:
|
|
Preview build of 7a4400a: |
6888512 to
2eaae17
Compare
…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.
2eaae17 to
7a4400a
Compare
There was a problem hiding this comment.
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_directinSource/JavaScriptCore/llint/LLIntSlowPaths.cpp: the newslot.slotBase() == baseValueguard is the same conditionslow_path_get_by_idalready uses at line 1101, so aJSGlobalProxyread 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:ProhibitsPropertyCachingandGetOwnPropertySlotIsImpureForPropertyAbsenceare consumed only by cache gates (actionForCell,HasOwnPropertyCache::tryAdd,propertyAccessesAreCacheable,PropertyCondition,JSPromise::isDefinitelyNonThenable, the AOT cache answers), matching howProxyObject,JSCallbackObjectandJSModuleNamespaceObjectuse them; no non-cache semantics change.$vm.createDebuggerScopehandles a non-function or absent argument (dynamicDowncastreturns null on a non-cell) and takes the structure from the scope's own realm; both new stress tests are listed inJSTests/BUN-TEST-DIFFERENCES.mdas 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.
…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.
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.
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>
Problem
get_by_id_direct) ofglobalThisloads from the wrong cell on its second run in LLInt. In Bun, the thirdconsole.write.call(globalThis, "")ends a release build:Segmentation fault at address 0xFFFFFFFFFFFFFE78inllint_op_get_by_id_direct.slow_path_get_by_id_direct(llint/LLIntSlowPaths.cpp:913) stores the base's structure withslot.cachedOffset(). AJSGlobalProxyanswers with the slot of its target.DebuggerScopeanswers with the slot of its scope, and all scope objects of a realm share one structure. Caches keyed on it are wrong.Fix
slot.slotBase() == baseValue, asget_by_iddoes at line 1100.DebuggerScopegetsProhibitsPropertyCachingandGetOwnPropertySlotIsImpureForPropertyAbsence.$vm.createDebuggerScope()makes a scope object for the tests.JSTests/stress. The releasejscofmainexits 139 on the first. Bun's tests: test: own-property reads of a global proxy in builtins, and the debugger's scope objects bun#48831.Background
get_by_id_directreads an own property, never the prototype chain. Builtins write@getByIdDirect.globalThisis aJSGlobalProxy: the global object behind it holds the properties. ADebuggerScopeis the inspector's object for a scope of a paused frame.DebuggerScopelefthasOwnPropertyanddeletewrong.Downsides
jsc, JIT off).globalThis.xcosts 433.splicefunction and a finitelengthshows as an array at every pause, not only the first.Notes
The branch is on
main59e584e. The two commits have the source lines that they had on de04322. The one conflict withmainwas in the table ofJSTests/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:The first run stores the proxy's StructureID with the offset that
hellohas 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:tryCacheGetByswitches to the proxy's target (bytecode/Repatch.cpp:586), andGetByStatus::computeFromLLInttakes 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, thenSegmentation fault.console.writekeeps its writer onthiswith@putByIdDirectPrivateand reads it with@getByIdDirectPrivate. The put goes throughdefineOwnPropertyto the global object. The second read stores the pair and the third loads through it. That code is from 2022-12.vm.createContext(vm.constants.DONT_CONTEXTIFY):Segmentation fault.vm.createContext({}): the third call throwsTypeError: 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 faultat the second handshake (Bun v1.4.4 and later).$getByIdDirectPrivate(globalThis, ...)) and changed its call site.robobun/529430d7/shell-own-raw-read) makes the shell's$readrawof 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 releasejscofmain(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, thentestLoopCounttimes. SIGSEGV at the second read.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.$vm.createGlobalProxy) and that realm's global object. SIGSEGV.expected 50 but got function Number() { [native code] }. With--useJIT=0: SIGSEGV.@getByIdDirectPrivateafter@putByIdDirectPrivatethrough the proxy: read, define, read, read. SIGSEGV.main.The
DebuggerScopehalf.DebuggerScope::getOwnPropertySlotcallsgetPropertySloton the scope object with the caller's slot, andput,deletePropertyanddefineOwnPropertyforward too.mainhas four kinds of cache that go by the structure of the scope object: the inline caches of reads,inanddelete, theHasOwnPropertyCache, the LLInt cache above, and the structure's memory that an object is not thenable.ProhibitsPropertyCachingis whatactionForCell(Repatch.cpp:360),Structure::propertyAccessesAreCacheable()andHasOwnPropertyCache::tryAddask for.isDefinitelyNonThenable(runtime/JSPromise.cpp:705) asks for the absence flag alone.ProxyObjectandJSCallbackObjecthave 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: seesplicebelow.The second stress test,
debugger-scope-property-caches.js. Nine blocks, on scope objects from$vm.createDebuggerScope(). Results on a debugjscof the first head of this branch, with one or both flags taken out ofDebuggerScope::createStructurefor the run:ProhibitsPropertyCachinginthat hitundefinedobjectPrototypeHasOwnPropertydeleteafter the function was compiledwithobject inheritsundefinedundefinedPromise.resolve(scope)readsthenWith
--useJIT=0and no flag, the threehasOwnPropertyblocks and thethenblock fail. The own reads pass there: the LLInt condition covers them.splice.RemoteObject.subtype()(inspector/InjectedScriptSource.js:1155) calls a value an array whentypeof value.splice === "function"andvalue.lengthis finite, and the inspector asks that of every scope object at every pause. For a function withvar length = 2; function splice() {}, paused 12 times:maingives the scope object the subtypearrayat the first pause and none at the next 11, because the inline cache ofvalue.splicekeeps a miss for the structure of scope objects. With this change it isarrayat 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)
jscwith assertions and on the releasejscof this branch's preview build (autobuild-preview-pr-1048-7a4400aa), each with default options,--useJIT=0,--useLLInt=0,--useFTLJIT=false,--useLLIntICs=0, and--useConcurrentJIT=0with thresholds of 10, 100 and 1000: 24 of 24 runs pass. The releasejscofmainexits 139 on the first file. It has no$vm.createDebuggerScopefor the second.Test bun-webkit-linux-arm64-lto-hardened-aotpassed 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).jsc-stress.test.ts(139),inspect.test.ts(34),console-write.test.ts(7) andnode-tls-connect-hostname-verification.test.ts(21). With the prebuilt WebKit of Bun'smain(499846f), 0 of the 11 pass.JSTests/stresswhose names holdget-by-id-direct,debugger-scope,class-field,private-name,private-method,private-accessor,private-getter,private-brand,private-in,global-proxy,global-thisorobject-assign-fast-path, with default options, with--useJIT=0and with--useLLInt=0, on a debug ASANjsc: all passed.Measurements. Sizes and counts are of the release
jsc(LTO,bun-webkit-linux-amd64-lto-aot) ofmain59e584e and of this branch's preview build. Instruction counts per iteration areperf_event_opencounts ofinstructions:u, the difference of runs of 2,000,000 and 1,000,000 iterations, with--useJIT=0.perfandvalgrindare not on the machine. Rows marked "first base" are from de04322 and the first head of this branch: objects of Bun'srelease-localconfiguration (clang 23,-O3, no LTO), and Bun debug builds.llint_op_get_by_id_direct,_wide16,_wide32LowLevelInterpreter.cpp.o,-O3object (first base)llint_slow_path_get_by_id_direct, LTOllint_slow_path_get_by_id_direct,-O3object (first base)cmpq, +1jne)DebuggerScope::createStructure, LTOfunctionCreateDebuggerScope, LTOtextofjsc(llvm-size), which has$vmnew Aofclass A { x = 1 }, LLInt onlyglobalThis, LLInt only--useLLIntICs=0)globalThis.hellothroughget_by_id, LLInt onlyglobalThisat one site, LLInt only, with the loopnew A, JIT offglobalThisglobalThisat one siteglobalThis, JIT onRuntime.getDisplayablePropertiesof each scope; first base)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 releasebunhas 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 basesdebugger/has no difference, andinspector/has one, inInspectorHeapAgent.cpp. So the count of lookups stands.Both new files end in 12 to 13 ms on the release
jscof the preview build with default options, and in 5 to 9 ms with--useJIT=0. On the debug ASANjscthey take 0.1 to 1.3 s.In Bun (debug build of 24e5faf8d3 with the preview build),
llint_slow_path_get_by_id_directis entered 0 times bybun -e 0and byconsole.log(1), once byconsole.write("x"), 3 times by a script that makes a TLS server, and once more for atls.connect()to it.Not in this change
globalThis.xeither (LLIntSlowPaths.cpp:1100).tryCacheGetBystill takes the offset of a slot for the base when an own read hits in another cell (Repatch.cpp:642).DebuggerScopewas the one class that reached it. With the flag no class does, so a condition there would have no test.slow_path_get_by_id_direct. Both need to keep the condition.LLIntSlowPaths.cppandDebuggerScope.h.