Skip to content

[JSC] LLInt: the guards of a prototype load cache are keyed by site - #736

Closed
robobun wants to merge 1 commit into
mainfrom
robobun/a388476a/llint-get-by-id-site-guards
Closed

robobun wants to merge 1 commit into
mainfrom
robobun/a388476a/llint-get-by-id-site-guards

Conversation

@robobun

@robobun robobun commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fix

  • The key is the BytecodeIndex, which has the checkpoint. The entry has the StructureID and the watchpoints.
  • CodeBlock::llintGetByIdModeMetadata() finds the metadata of a site. The watchpoint and the collector each had that switch.
  • clearToDefaultModeWithoutCache(), setUnsetMode() and setArrayLengthMode() set bytes 8 to 13 of GetByIdModeMetadata to zero.
  • Verified: the JSTests/stress/llint-*.js tests on an assert build, in each of their modes.

Behaviour change: none

Background

  • The LLInt is the interpreter. A get_by_id site has 16 bytes of metadata for its inline cache. In ProtoLoad mode (a value of the prototype chain), 8 of them are the pointer to the object with the value.
  • A watchpoint runs code when a structure changes. The watchpoints of a ProtoLoad cache clear it when an object of the chain changes.
  • A site is one get_by_id of an instruction. iterator_next and instanceof have two. The checkpoint of the BytecodeIndex says which.

Downsides

  • A watchpoint or a collection clears the cache that it guards. Before, it cleared what the site had at that time, and both caches of iterator_next and instanceof. Only $vm and the time of a read show that.
  • A bucket of the map is 24 bytes. It was 16.
Notes

Tests that cover the code. llint-proto-get-by-id-cache-change-prototype.js, llint-proto-get-by-id-cache-intercept-value.js, llint-get-by-id-cache-prototype-load-from-dictionary.js and llint-cache-replace-then-cache-get-and-fold-then-invalidate.js make a prototype load cache and make a watchpoint clear it. The tests of #735 pass on this build in the modes that do not read the state of a cache: llint-proto-get-by-id-cache-rearm.js, llint-get-by-id-cache-random.js, llint-get-by-id-unset-cache.js and llint-get-length-string.js, with the defaults, with a threshold of 200 and no concurrent compiler, and with --collectContinuously=1.

Why a site has one entry at most before #735. The countdown of a site (hitCountForLLIntCaching) runs once, so setupGetByIdPrototypeCache() runs once for a site at most. The assertion that the entry is new is still there.

CodeBlock::m_llintGetByIdWatchpointMap had the key (StructureID, BytecodeIndex).
A site could have more than one entry, and nothing could find the entry of a
site without the structure. The key is now the BytecodeIndex, which has the
checkpoint. The entry has the structure and the watchpoints.

The watchpoint and the collector each had a switch that finds the metadata of
a site. CodeBlock::llintGetByIdModeMetadata() is that switch, once. It uses the
checkpoint, so a dead entry of iterator_next or instanceof clears the cache
that it guards, not both caches of the instruction.

A watchpoint or a collection clears the cache that the guards are for, which is
a ProtoLoad or Unset cache. A cache of an own property or of the length of an
array, that the site got later, stays.

clearToDefaultModeWithoutCache(), setUnsetMode() and setArrayLengthMode() set
bytes 8 to 13 of GetByIdModeMetadata to zero. A site that leaves ProtoLoad mode
had bytes of the pointer to the slot base there. Only ProtoLoad mode reads
them.

A program cannot see a difference.
@robobun

robobun commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

Status

@github-actions

Copy link
Copy Markdown

Preview build of 5f1f719: autobuild-preview-pr-736-5f1f7193

robobun added a commit to oven-sh/bun that referenced this pull request Sep 26, 2026
…e misses count toward the Baseline JIT

The interpreter of JavaScriptCore (LLInt) has one cache entry for each
property read, for one object shape. A read that sees several shapes calls
its slow path each time, and nothing counted those calls toward the
Baseline JIT.

oven-sh/WebKit#735 (on top of oven-sh/WebKit#736) adds four JSC options, all
on by default:

- missCountForLLIntTierUp (12): the 12th slow path call of one get_by_id or
  put_by_id site lowers the threshold of the Baseline JIT for its function.
  The startup JIT policy (--compile-jit-policy) does not apply to such a
  function.
- useLLIntUnsetCaching: a read that finds no property is cached.
- useLLIntStringLengthFastPath: the length of a string is read with no call
  of the slow path.
- useLLIntPrototypeCacheRearming: the cache of a value of the prototype
  chain is made again after it is cleared or replaced, 4 times at most for
  a read.

The pin is the preview build of that pull request, which is the previous
pin (f20ce77445) plus the two changes. Replace it with the merge commit
before this merges.

The test runs a fixture of property reads in 9 configurations of the
options. What a read returns must not depend on what the cache holds.
robobun added a commit to oven-sh/bun that referenced this pull request Sep 27, 2026
…e misses count toward the Baseline JIT

The interpreter of JavaScriptCore (LLInt) has one cache entry for each
property read, for one object shape. A read that sees several shapes calls
its slow path each time, and nothing counted those calls toward the
Baseline JIT.

oven-sh/WebKit#735 (on top of oven-sh/WebKit#736) adds these JSC options:

- missCountForLLIntTierUp (12): the 12th slow path call of one get_by_id or
  put_by_id site lowers the threshold of the Baseline JIT for its function.
  The startup JIT policy (--compile-jit-policy) does not apply to such a
  function. With useStartupJITDeferralAfterLLIntMisses (off) it applies.
- useLLIntStringLengthFastPath (on): the length of a string is read with no
  call of the slow path.
- useLLIntUnsetCaching (off): a read that finds no property is cached.
- useLLIntPrototypeCacheRearming (off): the cache of a value of the
  prototype chain is made again after it is cleared or replaced, 4 times at
  most for a read.

The object of a vm.constants.DONT_CONTEXTIFY context answers a property read
with what the global object of the context has, so it can get a property and
keep its structure. Its class now has the flag
GetOwnPropertySlotIsImpureForPropertyAbsence. Without the flag, an inline
cache of the JIT kept "no such property" for it, and a read returned
undefined for a property that the context got later.

The pin is the preview build of that pull request, which is the previous
pin (f20ce77445) plus the two changes. Replace it with the merge commit
before this merges.

The test runs a fixture of property reads in 12 configurations of the
options. What a read returns must not depend on what the cache holds.
robobun added a commit to oven-sh/bun that referenced this pull request Sep 27, 2026
…e misses count toward the Baseline JIT

The interpreter of JavaScriptCore (LLInt) has one cache entry for each
property read, for one object shape. A read that sees several shapes calls
its slow path each time, and nothing counted those calls toward the
Baseline JIT.

oven-sh/WebKit#735 (on top of oven-sh/WebKit#736) adds these JSC options:

- missCountForLLIntTierUp (12): the 12th slow path call of one get_by_id or
  put_by_id site lowers the threshold of the Baseline JIT for its function.
  The startup JIT policy (--compile-jit-policy) does not apply to such a
  function. With useStartupJITDeferralAfterLLIntMisses (off) it applies.
- useLLIntStringLengthFastPath (on): the length of a string is read with no
  call of the slow path.
- useLLIntUnsetCaching (off): a read that finds no property is cached.
- useLLIntPrototypeCacheRearming (off): the cache of a value of the
  prototype chain is made again after it is cleared or replaced, 4 times at
  most for a read.

The object of a vm.constants.DONT_CONTEXTIFY context answers a property read
with what the global object of the context has, so it can get a property and
keep its structure. Its class now has the flag
GetOwnPropertySlotIsImpureForPropertyAbsence. Without the flag, an inline
cache of the JIT kept "no such property" for it, and a read returned
undefined for a property that the context got later.

The pin is the preview build of that pull request, which is the previous
pin (f20ce77445) plus the two changes. Replace it with the merge commit
before this merges.

The test runs a fixture of property reads in 12 configurations of the
options. What a read returns must not depend on what the cache holds.
@robobun

robobun commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: this commit is now the first commit of #735, which has main as its base. The preview build autobuild-preview-pr-735-4fcab1e7 already has it.

@robobun robobun closed this Sep 27, 2026
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.

2 participants