Repository navigation
Bytecode cache: build 1–3 character inline atoms from the slot's bytes, not from the loaded word - #519
Conversation
…s, not from the loaded word atomForInlineString took the slot as a uint32_t and shifted each character out of it into a stack array before handing that to AtomStringImpl::add. The slot is already four bytes in the payload — tag byte, then the characters — so pass it as a span and give add() bytes 1..length directly: no per-character extraction, no temporary. The two-character table index and the SmallStrings lookup read the same bytes. Motivation is a field signature on the 1.4.1 --compile --bytecode payload (Windows only, a handful of machines, repeatable per machine): `ReferenceError: \rzt is not defined` where the payload holds `Rzt`, i.e. the atom's first character is the slot's tag byte (0x0D for length 3) with characters 2-3 intact. In the shipped x64 code that is the single `mov m8, bh` that stores character 0 behaving as `mov m8, bl`; nothing at the source level produces it. Reading the characters from memory removes that instruction sequence from the path regardless of what mis-executes it.
|
Warning Review limit reached
On-demand reviews are free for the next 25 days. After that, they cost $0.25 per reviewed file. Or wait 46 minutes for your next included review. View limit detailsLimit details: You’ve used the included review currently available. Your 80 included PR review attempts over the past 7 days set your current allowance at 1 review per hour. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
There was a problem hiding this comment.
LGTM — semantics-preserving refactor from shift/mask to a byte-span view.
What was reviewed:
- Verified against the encoder (
tryEncodeInlineString): on little-endian, byte 0 istag|len<<2and bytes 1..3 are the characters, soslot[0]>>2 & 3andslot.subspan(1).first(length)read exactly what the old shifts extracted; thestatic_assertpins that assumption. - Length-2 cache index
characters[0] | characters[1]<<8equals the old(packed>>8) & 0xffff; length is masked to ≤3 so.first(length)on the 3-byte subspan is always in bounds. asByteSpan<Offset, 4>(m_offset)(Offset = int32_t) yieldsspan<const uint8_t, 4>over the in-payload field;AtomStringImpl::addcopies, so no lifetime concern, and theslot→entryrename removes the parameter shadow.
Extended reasoning...
Overview
The PR changes Decoder::atomForInlineString in Source/JavaScriptCore/runtime/CachedTypes.cpp (and its declaration in CachedTypes.h) to accept a std::span<const uint8_t, 4> view over the 4-byte inline-string slot instead of a uint32_t loaded via bit_cast. The single call site, VariableLengthObject::inlineString, now passes asByteSpan<Offset, sizeof(Offset)>(m_offset) (where Offset is int32_t). The encoder side (tryEncodeInlineString) is unchanged: it writes tag | len<<2 | c0<<8 | c1<<16 | c2<<24 bit-cast into m_offset, so on a little-endian host the byte layout is [tag|len<<2][c0][c1][c2]. The new decoder reads slot[0] for the length and slot[1..1+len) for the characters, which is byte-for-byte identical to the old shift/mask logic. A static_assert(std::endian::native == std::endian::little) documents and enforces the assumption. The local slot (cache-table entry reference) was renamed to entry to avoid shadowing the new parameter.
Security risks
None introduced. The bytecode cache decoder already trusts the payload it maps; this change does not widen that trust. length is masked with & 3, subspan(1) on a fixed-extent span of 4 yields a fixed-extent span of 3, and .first(length) with length ≤ 3 is always in bounds. Latin1Character is unsigned char, so the uint8_t span converts without reinterpretation. AtomStringImpl::add copies its input, so the span pointing into the cached object's storage does not escape. No new heap writes, no format change, no auth/crypto/permissions surface.
Level of scrutiny
Low-to-moderate. This is a ~20-line refactor confined to one function and one call site, with mechanically verifiable equivalence to the prior code on little-endian targets (the only targets JSC ships on, now enforced at compile time). The motivation — sidestepping a suspected legacy high-byte-register store miscompile/misexecution on some x64 Windows environments — does not affect correctness review: the new code is equivalent regardless of whether that theory holds.
Other factors
The repository's CODEOWNERS lists /Source/JavaScriptCore @ WebKit/jsc-reviewers, but that file is inherited from upstream WebKit, explicitly states contributors do not "own" components, and references an upstream team not applicable to this fork — so it is advisory reviewer routing rather than an ownership gate here. The PR description reports passing the bytecode-cache-* stress tests plus a targeted 1/2/3-char round-trip script under JSC_forceDiskCache. The bug-hunting run exited on dry_streak with no findings and no candidates ruled out.
Preview Builds
|
Bytecode cache: build 1-3 character inline atoms from the slot's bytes, not from the loaded word (oven-sh/WebKit#519).
### What does this PR do? Bumps WebKit from `76882271d74a` to `2da33d53e33e` — one commit: - oven-sh/WebKit#519 — Bytecode cache: build 1-3 character inline atoms from the slot's bytes, not from the loaded word ### How did you verify your code works? Release `autobuild-2da33d53e33e71055d66f4b84537aa8cb0b0e99d` is published with all 42 prebuilt assets; CI builds against it.
Main moved WEBKIT_VERSION to 2da33d53 (oven-sh/WebKit#519). oven-sh/WebKit#268 is rebased onto that commit, so its preview carries everything main's pin has plus the two async context fixes.
Main moved WEBKIT_VERSION to 2da33d53 (oven-sh/WebKit#519). oven-sh/WebKit#268 is rebased onto that commit, so its preview carries everything main's pin has plus the two async context fixes.
Main moved WEBKIT_VERSION to 2da33d53 (oven-sh/WebKit#519). oven-sh/WebKit#268 is rebased onto that commit, so its preview carries everything main's pin has plus the two async context fixes.
What
Decoder::atomForInlineStringtook the 4-byte slot as auint32_tand shifted each character out of the register into astd::arrayon the stack, then passed that toAtomStringImpl::add. The slot is already sitting in the payload as[tag|len<<2][c0][c1][c2], so take it asstd::span<const uint8_t, 4>and handadd()bytes1..lengthdirectly. Length 1 (SmallStrings) and the length-2 VM table index read the same bytes. No format change; encoder untouched. Astatic_assertrecords that the byte view assumes the little-endian word the encoder writes.x64 before (3-char path, as shipped in bun 1.4.1 / win-x64):
after:
Why
Field reports on the 1.4.1
--compile --bytecode --splittingpayload:ReferenceError: \rzt is not definedat a position where the payload holdsRzt— and the same fordor,TYr,qms,Bqe,$Pt, and the globalSet(\ret). Every case is a 3-character name whose first character became0x0D, which is exactly the slot's tag byte for length 3, with characters 2–3 intact. In the code above that is the onemov m8, bhstoringbl: same register, correct value in it (chars 2–3 prove that), no intervening instruction. Nothing at the source level produces that, and the.bunsection is mapped read-only, so this looks like the execution environment (CPU or an x64 translation layer) mis-handling a legacy high-byte-register store. Reading the characters from memory takes that sequence off the path; if the signature survives the release that ships this, that theory is dead and we've lost nothing — the new code is shorter either way.Verified
JSCOnly RelWithDebInfo,
USE_BUN_JSC_ADDITIONS=ON:JSTests/stress/bytecode-cache-*.js,class-fields-bytecode-cache.js,code-cache-incorrect-caching.js+ 300 random stress files throughbytecode-cache-test-helper.sh(encode run, thenJSC_forceDiskCachedecode run): 296 pass / 10 fail, the 10 fail identically on a build ofmain(flag-dependent tests run without their//@flags).Set,Map,NaN): encode-run and forced-decode-run output identical.