← All reports

Private field get ICs fold to megamorphic loads

Component: JSC JIT | 567d5ec

Source/JavaScriptCore/jit/AssemblyHelpers.cpp

+ AssemblyHelpers::loadMegamorphicPrivateProperty(...)
+ // shares findMegamorphicCacheEntry with loadMegamorphicProperty
+ // accepts an entry only when it is an own-property hit

Source/JavaScriptCore/bytecode/InlineCacheCompiler.cpp

+ tryFoldToMegamorphic: now handles GetPrivateName / GetPrivateNameById
(folds to IndexedMegamorphicLoad / LoadMegamorphic)

Source/JavaScriptCore/jit/JITOperations.cpp

+ getPrivateNameMegamorphic: slow path does not discard IC for uncacheable receivers (ProxyObject, uncacheable dictionary)

JSC's inline caches specialize property accesses per Structure (JSC's hidden class) and keep up to maxAccessVariantListSize variants. Past that limit, tryFoldToMegamorphic replaces the IC with a generic lookup in the global MegamorphicCache, keyed by structure and property name. Private fields (#x) are stored as own properties keyed by private Symbols, but reading a missing one throws a TypeError instead of returning undefined, so until now private-name gets were excluded from folding.

GetPrivateName/GetPrivateNameById ICs now fold to IndexedMegamorphicLoad/LoadMegamorphic once the variant list is full. They use a new loadMegamorphicPrivateProperty that shares findMegamorphicCacheEntry with ordinary loads but accepts only own-property hits. Missing fields always take the slow path so the throw is preserved. Uncacheable receivers such as Proxy and uncacheable dictionaries no longer cause the IC to be discarded.

Reads of #field from a base-class method over many subclass shapes leave a permanent give-up slow path, with the megamorphic microbenchmark about 2.35x faster (182ms to 78ms). The change also extends hand-written megamorphic JIT codegen to a new access kind with different miss semantics.

The own-property-hit check in loadMegamorphicPrivateProperty is the load-bearing guard: a private-symbol hit that is not an own property, or a stale offset, would yield a type confusion or out-of-bounds load. Check cache-entry invalidation when dictionary structures are flattened or properties are deleted; the dictionary stress test notes the private field offset changes on flattening. Exercise Proxy and other exotic receivers, and structures carrying a same-named private symbol with a different identity, as in the different-symbols test. Confirm that missing fields always throw and that negative or prototype-chain hits are never stored. Finally, examine how keeping the IC for uncacheable receivers interacts with repatching state.