Polymorphic inline caches are immutable linked lists in AST, each time we only add a new node to the inline cache. Until it becomes megamorphic then it’s removed entirely.
This has no problems because if you read an old entry that it just means a cache miss.
We can defer visible change to the MRO, this depends on language semantics.
What guarantees do we need to make to the user?
Discuss what is the worst that could happen between two DEOPT_IF checks. Is that something that we allow in CPython semantics or something that will crash the interpreter? We definitely don’t want to crash the interpreter, but if it’s undefined semantics then we may not need to support it, after all the user should protect the code with locks.
For TruffleRuby: made object namespaces thread-safe was as simple as changing HashMap to ConcurrentHashMap, which is slightly slower, but it’s okay because inline cache speeds it up anyways so there’s few accesses to ConcurrentHashMap.
compareAndSet might work but only if it’s a smaller inline cache entry which fits a machine word (64-bit entry).
CRuby recently added support for thread-safe inline caches only for method lookups. We might want to take a look into that. https://bugs.ruby-lang.org/issues/16614
Massive thanks to @eregon for taking the time to discuss with me about how TruffleRuby does things, and how CPython can handle this.
Video Call with Benoit Daloze
Note: transcribed by me (KJ). Not verbatim.
Re: Inline caches in TruffleRuby
compareAndSet
Re:
LOAD_ATTR_INSTANCE_VALUE
DEOPT_IF
checks. Is that something that we allow in CPython semantics or something that will crash the interpreter? We definitely don’t want to crash the interpreter, but if it’s undefined semantics then we may not need to support it, after all the user should protect the code with locks.HashMap
toConcurrentHashMap
, which is slightly slower, but it’s okay because inline cache speeds it up anyways so there’s few accesses toConcurrentHashMap
.compareAndSet
might work but only if it’s a smaller inline cache entry which fits a machine word (64-bit entry).Massive thanks to @eregon for taking the time to discuss with me about how TruffleRuby does things, and how CPython can handle this.