diff --git a/NativeScript/runtime/MetadataBuilder.h b/NativeScript/runtime/MetadataBuilder.h index 81547fecf..992a4abf5 100644 --- a/NativeScript/runtime/MetadataBuilder.h +++ b/NativeScript/runtime/MetadataBuilder.h @@ -12,6 +12,7 @@ namespace tns { +struct NativeSetter; struct NativeSetters; class MetadataBuilder { @@ -32,18 +33,21 @@ class MetadataBuilder { void* data, StructStorage storage, v8::Local parent); - // Runs the setter of `owner`'s native property `property` on `receiver`, as - // the property's accessor would, and returns true. Returns false, having - // run nothing, unless `owner` is a native class's prototype, still holding - // the accessor pair it was built with for `property`, which has a setter. - // The caller establishes that `owner` is where `receiver`'s prototype chain - // finds `property`. Only canary mode records the accessors this needs. - static bool TrySetNativeProperty(v8::Isolate* isolate, - v8::Local context, - v8::Local owner, - v8::Local property, - v8::Local receiver, - v8::Local value); + // Canary mode: the setter of `owner`'s native property `property`, when + // `owner` is a native class's prototype still holding the accessor pair it + // was built with for `property`, which has a setter; null otherwise. The + // caller establishes that `owner` is where a receiver's prototype chain + // finds `property`. The result stays valid for the isolate's lifetime. + static NativeSetter* FindNativeSetter(v8::Isolate* isolate, + v8::Local context, + v8::Local owner, + v8::Local property); + // Runs `setter` on `receiver`, as the property's accessor would, and + // returns true; false, having run nothing, once JS has assigned or defined + // the property on its prototype since FindNativeSetter. + static bool RunNativeSetter(v8::Isolate* isolate, NativeSetter* setter, + v8::Local receiver, + v8::Local value); // Where the native member guard is on (GuardsNativeMembers): turns each // of `names`, and Symbol.iterator with `iterator`, an own method of // `prototype`, a prototype level of a JS-extended class, that native code @@ -217,6 +221,7 @@ class MetadataBuilder { Class klass_ = nil; }; + friend struct NativeSetter; friend struct NativeSetters; static void SetNativeProperty(v8::Isolate* isolate, diff --git a/NativeScript/runtime/MetadataBuilder.mm b/NativeScript/runtime/MetadataBuilder.mm index d01535265..e2de3e844 100644 --- a/NativeScript/runtime/MetadataBuilder.mm +++ b/NativeScript/runtime/MetadataBuilder.mm @@ -89,30 +89,34 @@ bool ResolveProxyReceiver(Isolate* isolate, Local& receiver, const char* constexpr int32_t kStructFieldIndexMask = (1 << kStructViewSlotShift) - 1; } // namespace +// One native property setter a native class's prototype was built with +// (NativeSetters). Lives as long as the isolate; `item` is emptied for good +// once JS changes the name on that prototype. +struct NativeSetter { + Global name; + MetadataBuilder::CacheItem* item; +}; + // The native property setters a native class's prototype was built with, for -// TrySetNativeProperty. JS can replace one only by defining the name on that +// FindNativeSetter. JS can replace one only by defining the name on that // prototype, which its definer sees, and a name the prototype's own handlers // see defined or assigned is forgotten for good. A deleted accessor needs no // such care: the prototype then no longer has the property. struct NativeSetters { - struct Entry { - Global name; - MetadataBuilder::CacheItem* item; - }; - // In the order RegisterInstanceProperties installed them: a later accessor // of a name replaces the earlier one on the prototype. std::vector*>> installed; // By the name's identity hash. Names reaching an interceptor are internalized, - // so a lookup compares identities. - robin_hood::unordered_map> byHash; + // so a lookup compares identities. Filled once by Index: entries never move + // afterwards, as FindNativeSetter hands out pointers to them. + robin_hood::unordered_map> byHash; - Entry* Find(Local name) { + NativeSetter* Find(Local name) { auto it = byHash.find(name->GetIdentityHash()); if (it == byHash.end()) { return nullptr; } - for (Entry& entry : it->second) { + for (NativeSetter& entry : it->second) { if (entry.name == name) { return &entry; } @@ -127,7 +131,7 @@ void Index(Isolate* isolate) { v8::String::NewFromUtf8(isolate, jsName.c_str(), NewStringType::kInternalized) .ToLocalChecked(); MetadataBuilder::CacheItem* setter = item->meta_->hasSetter() ? item : nullptr; - if (Entry* entry = Find(name)) { + if (NativeSetter* entry = Find(name)) { entry->item = setter; } else if (setter != nullptr) { byHash[name->GetIdentityHash()].push_back({Global(isolate, name), setter}); @@ -142,7 +146,7 @@ void Forget(Isolate* isolate, Local name) { if (it == byHash.end()) { return; } - for (Entry& entry : it->second) { + for (NativeSetter& entry : it->second) { if (entry.name.Get(isolate)->StrictEquals(name)) { entry.item = nullptr; } @@ -1596,18 +1600,23 @@ void CollectInstanceMemberNames(const BaseClassMeta* meta, Class klass, bool own return method; } -bool MetadataBuilder::TrySetNativeProperty(Isolate* isolate, Local context, - Local owner, Local property, - Local receiver, Local value) { +NativeSetter* MetadataBuilder::FindNativeSetter(Isolate* isolate, Local context, + Local owner, Local property) { NativeSetters* setters = NativeSettersOf(isolate, context, owner); if (setters == nullptr) { - return false; + return nullptr; } - NativeSetters::Entry* entry = setters->Find(property); - if (entry == nullptr || entry->item == nullptr) { + NativeSetter* entry = setters->Find(property); + return entry != nullptr && entry->item != nullptr ? entry : nullptr; +} + +bool MetadataBuilder::RunNativeSetter(Isolate* isolate, NativeSetter* setter, + Local receiver, Local value) { + CacheItem* item = setter->item; + if (item == nullptr) { return false; } - SetNativeProperty(isolate, entry->item, receiver, value); + SetNativeProperty(isolate, item, receiver, value); return true; } diff --git a/NativeScript/runtime/NsBuiltinModules.cpp b/NativeScript/runtime/NsBuiltinModules.cpp index 3a96decec..6a88f0d5b 100644 --- a/NativeScript/runtime/NsBuiltinModules.cpp +++ b/NativeScript/runtime/NsBuiltinModules.cpp @@ -261,6 +261,7 @@ void GetWrapperLifetimeStatsCallback(const FunctionCallbackInfo& info) { {"canaryStates", stats->canaryStates}, {"canaryNativeDeaths", stats->canaryNativeDeaths}, {"canaryInterceptedWrites", stats->canaryInterceptedWrites}, + {"canaryCachedNativeWrites", stats->canaryCachedNativeWrites}, }; for (const auto& [name, value] : fields) { result diff --git a/NativeScript/runtime/ObjectManager.h b/NativeScript/runtime/ObjectManager.h index 0acb252e4..aaf44cd81 100644 --- a/NativeScript/runtime/ObjectManager.h +++ b/NativeScript/runtime/ObjectManager.h @@ -104,6 +104,9 @@ class ObjectManager { uint64_t canaryNativeDeaths = 0; // Canary mode: writes the canary handlers saw. uint64_t canaryInterceptedWrites = 0; + // Canary mode: of those, native property writes whose setter the write + // handler found in its cache rather than along the prototype chain. + uint64_t canaryCachedNativeWrites = 0; }; static LifetimeStats* GetLifetimeStats(v8::Isolate* isolate); diff --git a/NativeScript/runtime/WrapperLifetimeCanary.mm b/NativeScript/runtime/WrapperLifetimeCanary.mm index 96417234a..04e5865b4 100644 --- a/NativeScript/runtime/WrapperLifetimeCanary.mm +++ b/NativeScript/runtime/WrapperLifetimeCanary.mm @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -155,12 +156,100 @@ void SetLiveCanary(bool live) { #endif }; +// Native property writes the mirroring setter ran the native setter of, by the +// name written and the receiver's prototype, so a later write of the name +// through an object with that prototype skips the prototype chain lookup. +// Positive entries only: a name with no entry costs one read of the name tags. +// +// A hit rechecks everything the lookup it replaces read, except where the name +// resolves: +// - the receiver and each prototype below the setter's owner lack the name; +// - each prototype up to the owner is the one the entry was made with, which +// also catches setPrototypeOf anywhere on that chain; +// - the owner still has an accessor for the name, and its NativeSetters entry +// was not forgotten since (the owner's handlers forget it when JS assigns or +// defines the name there). +// Native class prototypes get the same per-name recheck as JS ones: a [[Set]] +// that starts elsewhere can define a data property on one, as its receiver, +// without reaching its handlers. +// Sets are picked by addresses, which a moving collection may change; such an +// entry just misses until it is evicted. +class NativeWriteCache { + public: + // The native setter a write of `property` to `holder` runs, or null when it + // has no current entry. `holder`'s prototype is read once and only after the + // name tags matched. + NativeSetter* Find(Local context, Local holder, Local property) { + uint32_t tag = NameTag(property); + const uint32_t* tags = nameTags_[NameSet(tag)]; + for (size_t way = 0; way < kNameWays; way++) { + if (tags[way] == tag) { + return Check(context, holder, property, tag); + } + } + return nullptr; + } + + // After a write of `property` to `holder` found `setter` on `owner`, a + // native class prototype on holder's prototype chain. + void Fill(Isolate* isolate, Local holder, Local owner, Local property, + NativeSetter* setter); + + void Reset() { entries_.reset(); } + + private: + // The holder's prototype first, the owner last. + static constexpr size_t kMaxLevels = 8; + struct Entry { + Global name; + // Weak: the cache keeps no prototype alive. + Global levels[kMaxLevels]; + uint8_t levelCount = 0; + NativeSetter* setter = nullptr; + }; + + // The low half of a name's tagged address: never 0, and only a filter, as a + // name can move or its address be reused. + static uint32_t NameTag(Local name) { + return static_cast(v8::internal::ValueHelper::ValueAsAddress(*name)); + } + static constexpr size_t kNameSets = 32; + static constexpr size_t kNameWays = 4; + static size_t NameSet(uint32_t tag) { return ((tag >> 3) ^ (tag >> 9)) & (kNameSets - 1); } + static constexpr size_t kEntrySets = 64; + static constexpr size_t kEntryWays = 4; + static size_t EntrySet(uint32_t tag, Local prototype) { + auto address = static_cast(v8::internal::ValueHelper::ValueAsAddress(*prototype)); + uint32_t mixed = (address ^ tag) * 0x9E3779B1u; + return (mixed >> 26) & (kEntrySets - 1); + } + + NativeSetter* Check(Local context, Local holder, Local property, + uint32_t tag); + + // The tags of the names entries were made for. One name has entries for + // many prototypes (a property every UIView subclass inherits). + uint32_t nameTags_[kNameSets][kNameWays] = {}; + uint8_t nameVictims_[kNameSets] = {}; + struct Table { + Entry entries[kEntrySets][kEntryWays]; + uint8_t victims[kEntrySets] = {}; + }; + std::unique_ptr entries_; +}; + struct CanaryState { std::shared_ptr registry = std::make_shared(); // The weak collections' key for a native object hangs off its state, and // names the object it stands for. A released canary holds a copy. Global keyOfState; Global objectOfKey; + ObjectManager::LifetimeStats* stats = nullptr; + // Set while the runtime copies properties between a canary and its state, + // so the canary's handlers let those defines through. The copy runs no JS, + // so only its own defines reach a handler meanwhile. + bool copyingProperties = false; + NativeWriteCache nativeWrites; }; // Under the registry mutex: marks the record died and moves it from the map to @@ -178,6 +267,110 @@ void SetLiveCanary(bool live) { return registry->records.erase(it); } +NativeSetter* NativeWriteCache::Check(Local context, Local holder, + Local property, uint32_t tag) { + if (entries_ == nullptr) { + return nullptr; + } + Local prototype = holder->GetPrototype(); + if (!prototype->IsObject()) { + return nullptr; + } + Entry* set = entries_->entries[EntrySet(tag, prototype)]; + for (size_t way = 0; way < kEntryWays; way++) { + Entry& entry = set[way]; + if (entry.name != property || entry.levels[0] != prototype) { + continue; + } + if (holder->HasRealNamedProperty(context, property).FromMaybe(true)) { + return nullptr; + } + Local level = prototype.As(); + size_t last = entry.levelCount - 1; + for (size_t i = 0; i < last; i++) { + if (level->HasRealNamedProperty(context, property).FromMaybe(true)) { + return nullptr; + } + Local next = level->GetPrototype(); + if (entry.levels[i + 1] != next) { + return nullptr; + } + level = next.As(); + } + if (!level->HasRealNamedCallbackProperty(context, property).FromMaybe(false)) { + return nullptr; + } + return entry.setter; + } + return nullptr; +} + +void NativeWriteCache::Fill(Isolate* isolate, Local holder, Local owner, + Local property, NativeSetter* setter) { + Local levels[kMaxLevels]; + uint8_t levelCount = 0; + Local next = holder->GetPrototype(); + while (true) { + // A Proxy's traps and another wrapper's handlers answer for their own + // properties, which no recheck here reads. + if (!next->IsObject() || next->IsProxy() || levelCount == kMaxLevels) { + return; + } + Local level = next.As(); + if (level == owner) { + levels[levelCount++] = level; + break; + } + if (level->InternalFieldCount() > 0) { + return; + } + levels[levelCount++] = level; + next = level->GetPrototype(); + } + if (entries_ == nullptr) { + entries_ = std::make_unique
(); + } + uint32_t tag = NameTag(property); + size_t nameIndex = NameSet(tag); + uint32_t* tags = nameTags_[nameIndex]; + if (std::find(tags, tags + kNameWays, tag) == tags + kNameWays) { + uint32_t* slot = std::find(tags, tags + kNameWays, 0u); + if (slot == tags + kNameWays) { + slot = &tags[nameVictims_[nameIndex]]; + nameVictims_[nameIndex] = (nameVictims_[nameIndex] + 1) % kNameWays; + } + *slot = tag; + } + size_t index = EntrySet(tag, levels[0]); + Entry* set = entries_->entries[index]; + Entry* entry = nullptr; + for (size_t way = 0; way < kEntryWays && entry == nullptr; way++) { + if (set[way].name == property && set[way].levels[0] == levels[0]) { + entry = &set[way]; + } + } + for (size_t way = 0; way < kEntryWays && entry == nullptr; way++) { + if (set[way].levels[0].IsEmpty()) { + entry = &set[way]; + } + } + if (entry == nullptr) { + entry = &set[entries_->victims[index]]; + entries_->victims[index] = (entries_->victims[index] + 1) % kEntryWays; + } + entry->name.Reset(isolate, property); + for (size_t i = 0; i < kMaxLevels; i++) { + if (i < levelCount) { + entry->levels[i].Reset(isolate, levels[i]); + entry->levels[i].SetWeak(); + } else { + entry->levels[i].Reset(); + } + } + entry->levelCount = levelCount; + entry->setter = setter; +} + // Isolate thread. Lets go of orphaned records no canary holds any more, and // of those whose state a canary took over. Only the list's own reference is // left then, so each handle is reset on this thread. @@ -405,11 +598,6 @@ void Sweep(const std::shared_ptr& registry) { } #endif -std::shared_ptr RegistryFor(Isolate* isolate) { - CanaryState* state = Caches::StateFor(isolate); - return state != nullptr ? state->registry : nullptr; -} - } // namespace } // namespace tns @@ -521,12 +709,6 @@ void AttachToken(const std::shared_ptr& registry, id object) { return it != state->registry->records.end() ? it->second : nullptr; } -// Set while this thread copies properties between a canary and its state, so -// the canary's handlers let those defines through. Per thread rather than per -// isolate: the copy runs no JS, so only its own defines reach an interceptor -// on this thread meanwhile. -thread_local bool copyingProperties_ = false; - Local DescriptorField(Isolate* isolate, Local context, Local descriptor, const char* name) { Local value; @@ -541,10 +723,13 @@ void AttachToken(const std::shared_ptr& registry, id object) { // owns keeps its property. void CopyOwnProperties(Isolate* isolate, Local context, Local from, Local to, bool keepExisting = false) { + CanaryState* canaryState = Caches::ExistingStateFor(isolate); HandleScope scope(isolate); TryCatch tc(isolate); - bool wasCopying = copyingProperties_; - copyingProperties_ = true; + bool wasCopying = canaryState != nullptr && canaryState->copyingProperties; + if (canaryState != nullptr) { + canaryState->copyingProperties = true; + } Local names; if (from->GetPropertyNames(context, KeyCollectionMode::kOwnOnly, PropertyFilter::ALL_PROPERTIES, IndexFilter::kSkipIndices, KeyConversionMode::kConvertToString) @@ -582,7 +767,9 @@ PropertyDescriptor accessor(DescriptorField(isolate, context, descriptor, "get") (void)to->DefineProperty(context, key, accessor); } } - copyingProperties_ = wasCopying; + if (canaryState != nullptr) { + canaryState->copyingProperties = wasCopying; + } } // The state object of the holder, if it has one. @@ -597,19 +784,16 @@ bool ExistingState(Isolate* isolate, Local holder, Local* out) { return true; } -// The state object of the holder, created on its first write. -bool StateForWrite(Isolate* isolate, Local holder, Local* out) { - ObjectWeakCallbackState* canary = CanaryOf(isolate, holder); - if (canary == nullptr) { - // A -dealloc receiver writes to its object's existing state only. - return ExistingState(isolate, holder, out); - } +// The state object of the canary `holder`, created on its first write. +bool StateForWrite(Isolate* isolate, CanaryState* canaryState, Local holder, + ObjectWeakCallbackState* canary, Local* out) { if (canary->canaryRecord_ == nullptr || canary->canaryRecord_->died.load(std::memory_order_acquire)) { - std::shared_ptr registry = RegistryFor(isolate); - if (registry == nullptr) { + // No new record once the isolate's teardown began. + if (Caches::StateFor(isolate) == nullptr) { return false; } + std::shared_ptr registry = canaryState->registry; id object = canary->lifetimeTarget_; // The record died under a live canary (its token was removed): a // forwarding canary's new record takes over the dead record's state @@ -682,9 +866,8 @@ bool StateForWrite(Isolate* isolate, Local holder, Local* out) { if (!extended) { AttachToken(registry, object); } - if (ObjectManager::LifetimeStats* stats = ObjectManager::GetLifetimeStats(isolate); - stats != nullptr && !takesOver) { - stats->canaryStates++; + if (canaryState->stats != nullptr && !takesOver) { + canaryState->stats->canaryStates++; } if (previous != nullptr && !forwards) { CopyOwnProperties(isolate, isolate->GetCurrentContext(), holder, freshState); @@ -702,6 +885,17 @@ bool StateForWrite(Isolate* isolate, Local holder, Local* out) { return true; } +// The state object of the holder, created on its first write. +bool StateForWrite(Isolate* isolate, Local holder, Local* out) { + ObjectWeakCallbackState* canary = CanaryOf(isolate, holder); + if (canary == nullptr) { + // A -dealloc receiver writes to its object's existing state only. + return ExistingState(isolate, holder, out); + } + CanaryState* canaryState = Caches::StateFor(isolate); + return canaryState != nullptr && StateForWrite(isolate, canaryState, holder, canary, out); +} + bool HasOwn(Local context, Local state, Local property) { return state->HasOwnProperty(context, property).FromMaybe(false); } @@ -729,11 +923,12 @@ bool HasOwn(Local context, Local state, Local propert // becomes state. V8 calls the setter only when the canary is the receiver. Intercepted Setter(Local property, Local value, const PropertyCallbackInfo& info) { + Isolate* isolate = info.GetIsolate(); + CanaryState* canaryState = Caches::ExistingStateFor(isolate); // v8::Object::DefineOwnProperty reaches the setter, not the definer. - if (copyingProperties_) { + if (canaryState == nullptr || canaryState->copyingProperties) { return Intercepted::kNo; } - Isolate* isolate = info.GetIsolate(); Local holder = info.Holder(); ObjectWeakCallbackState* canary = CanaryOf(isolate, holder); std::shared_ptr borrowed; @@ -743,7 +938,8 @@ Intercepted Setter(Local property, Local value, return Intercepted::kNo; } } - if (ObjectManager::LifetimeStats* stats = ObjectManager::GetLifetimeStats(isolate)) { + ObjectManager::LifetimeStats* stats = canaryState->stats; + if (stats != nullptr) { stats->canaryInterceptedWrites++; } CanaryRecord* record = canary != nullptr ? canary->canaryRecord_.get() : borrowed.get(); @@ -759,6 +955,17 @@ Intercepted Setter(Local property, Local value, return Intercepted::kNo; } } + // The setter can run JS, a collection or a -dealloc: neither the canary nor + // its record is touched after it. + if (NativeSetter* setter = canaryState->nativeWrites.Find(context, holder, property)) { + if (MetadataBuilder::RunNativeSetter(isolate, setter, holder, value)) { + if (stats != nullptr) { + stats->canaryCachedNativeWrites++; + } + info.GetReturnValue().Set(true); + return Intercepted::kYes; + } + } // Searches the prototype chain too: absent there means a new name. PropertyAttribute attributes; if (holder->GetRealNamedPropertyAttributes(context, property).To(&attributes)) { @@ -782,9 +989,14 @@ Intercepted Setter(Local property, Local value, return Intercepted::kNo; } if (accessor.FromJust()) { - // The setter can run JS, a collection or a -dealloc: neither the canary - // nor its record is touched after it. - if (MetadataBuilder::TrySetNativeProperty(isolate, context, owner, property, holder, value)) { + NativeSetter* setter = + owner != holder ? MetadataBuilder::FindNativeSetter(isolate, context, owner, property) + : nullptr; + if (setter == nullptr) { + return Intercepted::kNo; + } + canaryState->nativeWrites.Fill(isolate, holder, owner, property, setter); + if (MetadataBuilder::RunNativeSetter(isolate, setter, holder, value)) { info.GetReturnValue().Set(true); return Intercepted::kYes; } @@ -792,9 +1004,13 @@ Intercepted Setter(Local property, Local value, } } Local state; - if (!StateForWrite(isolate, holder, &state)) { + if (canary != nullptr ? !StateForWrite(isolate, canaryState, holder, canary, &state) + : !Usable(borrowed)) { return Intercepted::kNo; } + if (canary == nullptr) { + state = Local::New(isolate, borrowed->state); + } if (!HasOwn(context, state, property)) { (void)state->CreateDataProperty(context, property, value); } else if (!state->HasRealNamedCallbackProperty(context, property).FromMaybe(true)) { @@ -816,12 +1032,16 @@ Intercepted Deleter(Local property, const PropertyCallbackInfo property, const PropertyDescriptor& descriptor, const PropertyCallbackInfo& info) { - if (copyingProperties_) { + Isolate* isolate = info.GetIsolate(); + CanaryState* canaryState = Caches::ExistingStateFor(isolate); + if (canaryState == nullptr || canaryState->copyingProperties) { return Intercepted::kNo; } - Isolate* isolate = info.GetIsolate(); + Local holder = info.Holder(); + ObjectWeakCallbackState* canary = CanaryOf(isolate, holder); Local state; - if (StateForWrite(isolate, info.Holder(), &state)) { + if (canary != nullptr ? StateForWrite(isolate, canaryState, holder, canary, &state) + : ExistingState(isolate, holder, &state)) { (void)state->DefineProperty(isolate->GetCurrentContext(), property, const_cast(descriptor)); } @@ -841,7 +1061,8 @@ Intercepted Definer(Local property, const PropertyDescriptor& descript bool ForwardedState(Isolate* isolate, Local holder, Local* out) { // Copying the state onto the canary (KeepWeakCollectionKey) must find no // current property, or V8 skips defining an identical one. - if (copyingProperties_) { + CanaryState* canaryState = Caches::ExistingStateFor(isolate); + if (canaryState == nullptr || canaryState->copyingProperties) { return false; } ObjectWeakCallbackState* canary = CanaryOf(isolate, holder); @@ -882,18 +1103,21 @@ Intercepted ForwardGetter(Local property, const PropertyCallbackInfo property, Local value, const PropertyCallbackInfo& info) { + Isolate* isolate = info.GetIsolate(); + CanaryState* canaryState = Caches::ExistingStateFor(isolate); // v8::Object::DefineOwnProperty reaches the setter, not the definer. - if (copyingProperties_) { + if (canaryState == nullptr || canaryState->copyingProperties) { return Intercepted::kNo; } - Isolate* isolate = info.GetIsolate(); Local holder = info.Holder(); + ObjectWeakCallbackState* canary = CanaryOf(isolate, holder); Local state; - if (!StateForWrite(isolate, holder, &state)) { + if (canary != nullptr ? !StateForWrite(isolate, canaryState, holder, canary, &state) + : !ExistingState(isolate, holder, &state)) { return Intercepted::kNo; } - if (ObjectManager::LifetimeStats* stats = ObjectManager::GetLifetimeStats(isolate)) { - stats->canaryInterceptedWrites++; + if (canaryState->stats != nullptr) { + canaryState->stats->canaryInterceptedWrites++; } Local context = isolate->GetCurrentContext(); // v8::Object::Set reports success for a write [[Set]] rejects, so a @@ -989,12 +1213,16 @@ void ForwardEnumerator(const PropertyCallbackInfo& info) { Intercepted ForwardDefiner(Local property, const PropertyDescriptor& descriptor, const PropertyCallbackInfo& info) { - if (copyingProperties_) { + Isolate* isolate = info.GetIsolate(); + CanaryState* canaryState = Caches::ExistingStateFor(isolate); + if (canaryState == nullptr || canaryState->copyingProperties) { return Intercepted::kNo; } - Isolate* isolate = info.GetIsolate(); + Local holder = info.Holder(); + ObjectWeakCallbackState* canary = CanaryOf(isolate, holder); Local state; - if (!StateForWrite(isolate, info.Holder(), &state)) { + if (canary != nullptr ? !StateForWrite(isolate, canaryState, holder, canary, &state) + : !ExistingState(isolate, holder, &state)) { return Intercepted::kNo; } bool defined; @@ -1479,6 +1707,7 @@ void WriteWeakCollectionKey(Isolate* isolate, CanaryState* canaryState, Localregistry->isolate = isolate; + state->stats = ObjectManager::GetLifetimeStats(isolate); state->keyOfState.Reset(isolate, Private::New(isolate)); state->objectOfKey.Reset(isolate, Private::New(isolate)); if (Runtime* runtime = Runtime::GetRuntime(isolate)) { @@ -1682,6 +1911,7 @@ void WriteWeakCollectionKey(Isolate* isolate, CanaryState* canaryState, LocalnativeWrites.Reset(); std::lock_guard lock(state->registry->mutex); state->registry->closed = true; for (auto& entry : state->registry->records) { diff --git a/TestFixtures/Marshalling/TNSAllocLog.h b/TestFixtures/Marshalling/TNSAllocLog.h index 9fdcda2ef..dd7c97312 100644 --- a/TestFixtures/Marshalling/TNSAllocLog.h +++ b/TestFixtures/Marshalling/TNSAllocLog.h @@ -156,6 +156,41 @@ id TNSOwnedPrimitivesObjectAt(TNSOwnedPrimitives* holder, NSUInteger index); @end +// Targets for the canary write handler's native setter cache: `depth` is +// declared three classes above each leaf. Specs that change a prototype use +// the Shadow classes, so the others keep an unchanged chain. `dropped`, +// `reflected` and `forgotten` each belong to the one spec that changes them on +// the prototype. +@interface TNSCanaryCacheBase : NSObject + +@property(nonatomic) NSInteger depth; + +@end + +@interface TNSCanaryCacheMid : TNSCanaryCacheBase +@end + +@interface TNSCanaryCacheLeaf : TNSCanaryCacheMid +@end + +@interface TNSCanaryCacheShadowBase : NSObject + +@property(nonatomic) NSInteger depth; +@property(nonatomic) NSInteger dropped; +@property(nonatomic) NSInteger reflected; +@property(nonatomic) NSInteger forgotten; + +@end + +@interface TNSCanaryCacheShadowMid : TNSCanaryCacheShadowBase + +- (NSInteger)swizzleTarget; + +@end + +@interface TNSCanaryCacheShadowLeaf : TNSCanaryCacheShadowMid +@end + // -dealloc reads `value`. @interface TNSAccessorDeallocHost : TNSAccessorHost diff --git a/TestFixtures/Marshalling/TNSAllocLog.m b/TestFixtures/Marshalling/TNSAllocLog.m index b409e2244..b2b30df36 100644 --- a/TestFixtures/Marshalling/TNSAllocLog.m +++ b/TestFixtures/Marshalling/TNSAllocLog.m @@ -317,6 +317,29 @@ - (void)initHook { @implementation TNSAccessorHost @end +@implementation TNSCanaryCacheBase +@end + +@implementation TNSCanaryCacheMid +@end + +@implementation TNSCanaryCacheLeaf +@end + +@implementation TNSCanaryCacheShadowBase +@end + +@implementation TNSCanaryCacheShadowMid + +- (NSInteger)swizzleTarget { + return 1; +} + +@end + +@implementation TNSCanaryCacheShadowLeaf +@end + @implementation TNSCanaryWriteTarget - (void)setGuarded:(NSInteger)guarded { diff --git a/TestRunner/app/tests/WrapperLifetimeModesTests.js b/TestRunner/app/tests/WrapperLifetimeModesTests.js index 8eabd8014..a1dd1536c 100644 --- a/TestRunner/app/tests/WrapperLifetimeModesTests.js +++ b/TestRunner/app/tests/WrapperLifetimeModesTests.js @@ -1450,6 +1450,419 @@ describe("Wrapper lifetime modes", function () { }); }); + // The handler caches the native setter a write ran, by the name and + // the receiver's prototype. Each spec fills that cache with a write, + // then changes what the write should reach, then checks the next + // write reached it. + describe("native setter cache", function () { + var allowShadowing = runtime.getConfig("wrapperLifetimeAllowShadowingNativeMembers"); + // A plain canary's handlers see native property writes only when + // they mirror: forwarding ones are non-masking. + var maskingPlain = canary && scope === "all" && allowShadowing; + var forwardingPlain = canary && scope === "all" && !allowShadowing; + var depthOf = Object.getOwnPropertyDescriptor(TNSCanaryCacheBase.prototype, "depth").get; + var shadowDepthOf = Object.getOwnPropertyDescriptor(TNSCanaryCacheShadowBase.prototype, "depth").get; + + function extend(Base) { + return (function (_super) { + __extends(Sub, _super); + function Sub() { + return (_super !== null && _super.apply(this, arguments)) || this; + } + return Sub; + })(Base); + } + + function cachedWrites() { + return stats().canaryCachedNativeWrites; + } + + // An instance of a JS subclass of the extended class `Ext`, whose + // prototype has `properties`: native code cannot extend an + // extended class again. + function subclassed(Ext, properties) { + var obj = Ext.new(); + Object.setPrototypeOf(obj, Object.create(Ext.prototype, properties)); + return obj; + } + + // Runs write() twice, expecting the cache to place at least one of + // them: a collection that moves a prototype turns a hit into a + // refill. + function expectCached(write, handled) { + var before = cachedWrites(); + write(); + write(); + var hits = cachedWrites() - before; + if (canary && handled) { + expect(hits).toBeGreaterThan(0); + } else { + expect(hits).toBe(0); + } + } + + // Fills the cache with a write of obj.depth, then writes it from + // the cache. + function warm(obj, read, handled) { + obj.depth = 10; + expectCached(function () { + obj.depth = 11; + }, handled); + expect(read.call(obj)).toBe(11); + expect(hasOwn(obj, "depth")).toBe(false); + } + + function loggingSetter(log, receiver) { + return { + set: function (value) { + log.push(this === receiver ? value : "wrong this"); + }, + configurable: true + }; + } + + it("writes a native property declared on the class or prototypes up from the cache", function () { + warm(extend(TNSCanaryCacheBase).new(), depthOf, true); + warm(extend(TNSCanaryCacheLeaf).new(), depthOf, true); + var Implemented = TNSCanaryCacheLeaf.extend({}, { name: "WrapperLifetimeCacheLeafImplemented" }); + warm(Implemented.new(), depthOf, true); + warm(TNSCanaryCacheLeaf.new(), depthOf, maskingPlain); + warm(TNSCanaryCacheBase.new(), depthOf, maskingPlain); + }); + + it("writes one name through more prototypes than a cache set has ways", function () { + var objects = [ + [extend(TNSCanaryCacheBase).new(), true], + [extend(TNSCanaryCacheMid).new(), true], + [extend(TNSCanaryCacheLeaf).new(), true], + [subclassed(extend(TNSCanaryCacheLeaf), {}), true], + [TNSCanaryCacheBase.new(), maskingPlain], + [TNSCanaryCacheMid.new(), maskingPlain], + [TNSCanaryCacheLeaf.new(), maskingPlain] + ]; + objects.forEach(function (pair) { + pair[0].depth = 1; + }); + var before = cachedWrites(); + for (var pass = 0; pass < 2; pass++) { + objects.forEach(function (pair, i) { + pair[0].depth = 100 + i; + }); + } + objects.forEach(function (pair, i) { + expect(depthOf.call(pair[0])).toBe(100 + i); + expect(hasOwn(pair[0], "depth")).toBe(false); + }); + var handled = objects.filter(function (pair) { + return canary && pair[1]; + }).length; + var hits = cachedWrites() - before; + if (handled > 0) { + expect(hits).not.toBeLessThan(handled); + } else { + expect(hits).toBe(0); + } + }); + + it("writes JS properties as before, whatever names the cache has", function () { + var obj = extend(TNSCanaryCacheLeaf).new(); + warm(obj, depthOf, true); + var before = cachedWrites(); + obj.fresh = 1; + obj.fresh = 2; + obj.depthLabel = "x"; + var Plain = extend(NSObject); + var other = Plain.new(); + // A name the cache has, on an object whose prototype it has no entry for. + other.depth = 3; + other.depth = 4; + expect(cachedWrites()).toBe(before); + expect(obj.fresh).toBe(2); + expect(hasOwn(obj, "fresh")).toBe(true); + expect(obj.depthLabel).toBe("x"); + expect(other.depth).toBe(4); + expect(hasOwn(other, "depth")).toBe(true); + }); + + it("writes from the cache for an object with JS state", function () { + var obj = extend(TNSCanaryCacheLeaf).new(); + obj.label = "state"; + warm(obj, depthOf, true); + expect(obj.label).toBe("state"); + var plain = TNSCanaryCacheLeaf.new(); + plain.label = "state"; + warm(plain, depthOf, maskingPlain); + expect(plain.label).toBe("state"); + }); + + it("sends a write to an accessor defined later on a JS prototype between the object and the property", function () { + var Sub = extend(TNSCanaryCacheShadowLeaf); + var obj = Sub.new(); + warm(obj, shadowDepthOf, true); + var log = []; + Object.defineProperty(Sub.prototype, "depth", loggingSetter(log, obj)); + obj.depth = 20; + expect(log).toEqual([20]); + expect(shadowDepthOf.call(obj)).toBe(11); + delete Sub.prototype.depth; + expectCached(function () { + obj.depth = 21; + }, true); + expect(shadowDepthOf.call(obj)).toBe(21); + expect(log).toEqual([20]); + }); + + it("sends a write to an accessor or a data property defined later on a native class prototype between", function () { + var proto = TNSCanaryCacheShadowMid.prototype; + [[extend(TNSCanaryCacheShadowLeaf).new(), true], [TNSCanaryCacheShadowLeaf.new(), maskingPlain]].forEach(function (pair) { + var obj = pair[0]; + warm(obj, shadowDepthOf, pair[1]); + var log = []; + Object.defineProperty(proto, "depth", loggingSetter(log, obj)); + try { + obj.depth = 30; + expect(log).toEqual([30]); + } finally { + delete proto.depth; + } + Object.defineProperty(proto, "depth", { value: 0, writable: true, configurable: true }); + try { + obj.depth = 31; + expect(hasOwn(obj, "depth")).toBe(true); + expect(obj.depth).toBe(31); + } finally { + delete proto.depth; + } + expect(shadowDepthOf.call(obj)).toBe(11); + delete obj.depth; + expectCached(function () { + obj.depth = 32; + }, pair[1]); + expect(shadowDepthOf.call(obj)).toBe(32); + expect(hasOwn(obj, "depth")).toBe(false); + // A write that starts elsewhere and defines the name on the + // prototype as its receiver. + expect(Reflect.set({}, "depth", 0, proto)).toBe(true); + try { + expect(hasOwn(proto, "depth")).toBe(true); + obj.depth = 33; + expect(hasOwn(obj, "depth")).toBe(true); + expect(obj.depth).toBe(33); + expect(shadowDepthOf.call(obj)).toBe(32); + } finally { + delete proto.depth; + } + delete obj.depth; + expectCached(function () { + obj.depth = 34; + }, pair[1]); + expect(shadowDepthOf.call(obj)).toBe(34); + }); + }); + + it("writes the native property from the cache after a native method is swizzled on a prototype between", function () { + var obj = extend(TNSCanaryCacheShadowLeaf).new(); + warm(obj, shadowDepthOf, true); + TNSCanaryCacheShadowMid.prototype.swizzleTarget = function () { + return 2; + }; + expect(obj.swizzleTarget()).toBe(2); + expectCached(function () { + obj.depth = 40; + }, true); + expect(shadowDepthOf.call(obj)).toBe(40); + expect(hasOwn(obj, "depth")).toBe(false); + }); + + it("writes an own property defined on the object, and the native property again once it is deleted", function () { + var objects = [[extend(TNSCanaryCacheLeaf).new(), true]]; + // A forwarding canary's own properties live in its state, which + // native property writes never reach. + if (!forwardingPlain) { + objects.push([TNSCanaryCacheLeaf.new(), maskingPlain]); + } + objects.forEach(function (pair) { + var obj = pair[0]; + warm(obj, depthOf, pair[1]); + Object.defineProperty(obj, "depth", { value: 50, writable: true, enumerable: true, configurable: true }); + obj.depth = 51; + expect(Object.getOwnPropertyDescriptor(obj, "depth").value).toBe(51); + expect(depthOf.call(obj)).toBe(11); + delete obj.depth; + expectCached(function () { + obj.depth = 52; + }, pair[1]); + expect(depthOf.call(obj)).toBe(52); + expect(hasOwn(obj, "depth")).toBe(false); + }); + }); + + it("writes the own property of an object whose state went with its associations", function () { + if (typeof objc_removeAssociatedObjects !== "function" || forwardingPlain) { + return; + } + var obj = TNSCanaryCacheLeaf.new(); + Object.defineProperty(obj, "depth", { value: 60, writable: true, enumerable: true, configurable: true }); + objc_removeAssociatedObjects(obj); + warm(TNSCanaryCacheLeaf.new(), depthOf, maskingPlain); + obj.depth = 61; + expect(obj.depth).toBe(61); + expect(hasOwn(obj, "depth")).toBe(true); + expect(depthOf.call(obj)).toBe(0); + }); + + it("follows a native accessor deleted from its prototype", function () { + var proto = TNSCanaryCacheShadowBase.prototype; + var dropped = Object.getOwnPropertyDescriptor(proto, "dropped").get; + var obj = extend(TNSCanaryCacheShadowLeaf).new(); + obj.dropped = 1; + expectCached(function () { + obj.dropped = 2; + }, true); + expect(dropped.call(obj)).toBe(2); + expect(delete proto.dropped).toBe(true); + obj.dropped = 3; + expect(hasOwn(obj, "dropped")).toBe(true); + expect(obj.dropped).toBe(3); + expect(dropped.call(obj)).toBe(2); + }); + + it("follows a write whose receiver is the native prototype that has the property", function () { + var proto = TNSCanaryCacheShadowBase.prototype; + var reflected = Object.getOwnPropertyDescriptor(proto, "reflected").get; + var obj = extend(TNSCanaryCacheShadowLeaf).new(); + obj.reflected = 1; + expectCached(function () { + obj.reflected = 2; + }, true); + Reflect.set({}, "reflected", 0, proto); + var descriptor = Object.getOwnPropertyDescriptor(proto, "reflected"); + obj.reflected = 3; + if (descriptor !== undefined && typeof descriptor.set === "function") { + expect(reflected.call(obj)).toBe(3); + expect(hasOwn(obj, "reflected")).toBe(false); + } else { + expect(reflected.call(obj)).toBe(2); + expect(hasOwn(obj, "reflected")).toBe(true); + expect(obj.reflected).toBe(3); + } + }); + + it("writes the native property without the cache after JS assigns its name on the prototype that has it", function () { + var proto = TNSCanaryCacheShadowBase.prototype; + var forgotten = Object.getOwnPropertyDescriptor(proto, "forgotten").get; + var obj = extend(TNSCanaryCacheShadowLeaf).new(); + obj.forgotten = 1; + expectCached(function () { + obj.forgotten = 2; + }, true); + expect(forgotten.call(obj)).toBe(2); + // The prototype is no native instance: its native setter may throw. + try { + proto.forgotten = 5; + } catch (e) {} + expect(typeof Object.getOwnPropertyDescriptor(proto, "forgotten").set).toBe("function"); + expectCached(function () { + obj.forgotten = 3; + }, false); + expect(forgotten.call(obj)).toBe(3); + expect(hasOwn(obj, "forgotten")).toBe(false); + }); + + it("follows a prototype chain changed under a cached write", function () { + var obj = extend(TNSCanaryCacheShadowLeaf).new(); + warm(obj, shadowDepthOf, true); + Object.setPrototypeOf(obj, Object.prototype); + obj.depth = 70; + expect(hasOwn(obj, "depth")).toBe(true); + expect(shadowDepthOf.call(obj)).toBe(11); + + var Detached = extend(TNSCanaryCacheShadowLeaf); + var other = Detached.new(); + warm(other, shadowDepthOf, true); + var log = []; + var inserted = Object.create(TNSCanaryCacheShadowLeaf.prototype, { depth: loggingSetter(log, other) }); + Object.setPrototypeOf(Detached.prototype, inserted); + other.depth = 71; + expect(log).toEqual([71]); + expect(shadowDepthOf.call(other)).toBe(11); + + var trapped = []; + // The target owns `depth`, so attribute queries find it at the proxy. + var target = Object.create(TNSCanaryCacheShadowLeaf.prototype); + Object.defineProperty(target, "depth", { value: "target", writable: true, configurable: true }); + Object.setPrototypeOf(Detached.prototype, new Proxy(target, { + set: function (target, key, value, receiver) { + trapped.push(receiver === other ? value : "wrong receiver"); + return true; + } + })); + other.depth = 72; + expect(trapped).toEqual([72]); + expect(shadowDepthOf.call(other)).toBe(11); + + Object.setPrototypeOf(Detached.prototype, TNSCanaryCacheShadowLeaf.prototype); + expectCached(function () { + other.depth = 73; + }, true); + expect(shadowDepthOf.call(other)).toBe(73); + expect(log).toEqual([71]); + expect(trapped).toEqual([72]); + }); + + it("keeps apart a class and its subclass whose prototype has its own accessor", function () { + var Parent = extend(TNSCanaryCacheLeaf); + var log = []; + var child = subclassed(Parent, {}); + Object.defineProperty(Object.getPrototypeOf(child), "depth", loggingSetter(log, child)); + warm(Parent.new(), depthOf, true); + child.depth = 80; + child.depth = 81; + var parent = Parent.new(); + warm(parent, depthOf, true); + child.depth = 82; + expect(log).toEqual([80, 81, 82]); + expect(depthOf.call(child)).toBe(0); + expect(depthOf.call(parent)).toBe(11); + + var later = subclassed(Parent, {}); + warm(later, depthOf, true); + Object.defineProperty(Object.getPrototypeOf(later), "depth", loggingSetter(log, later)); + later.depth = 83; + expect(log).toEqual([80, 81, 82, 83]); + expect(depthOf.call(later)).toBe(11); + }); + + it("writes from a worker, each isolate with its own cache", function (done) { + var wt = require("node:worker_threads"); + var obj = extend(TNSCanaryCacheLeaf).new(); + warm(obj, depthOf, true); + var worker = new wt.Worker("~/tests/canaryNativeWriteCacheWorker.js"); + worker.on("message", function (result) { + worker.terminate(); + expect(result.error).toBeUndefined(); + expect(result.values).toEqual([3]); + expect(result.own).toBe(false); + if (canary) { + expect(result.hits).toBeGreaterThan(0); + } else { + expect(result.hits).toBe(0); + } + expectCached(function () { + obj.depth = 12; + }, true); + expect(depthOf.call(obj)).toBe(12); + done(); + }); + worker.on("error", function (error) { + fail("worker error: " + error.message); + worker.terminate(); + done(); + }); + worker.postMessage(0); + }); + }); + it("handles writes to JS-extended instances only, under scope extended", function () { var Ext = TNSAllocLog.extend({}, { name: "WrapperLifetimeWriteHandlerExt" }); var before = stats(); diff --git a/TestRunner/app/tests/WrapperLifetimeTests.js b/TestRunner/app/tests/WrapperLifetimeTests.js index 2f5c97dd8..43adf4422 100644 --- a/TestRunner/app/tests/WrapperLifetimeTests.js +++ b/TestRunner/app/tests/WrapperLifetimeTests.js @@ -326,6 +326,7 @@ describe("Wrapper lifetime", function () { "canaryStates", "canaryNativeDeaths", "canaryInterceptedWrites", + "canaryCachedNativeWrites", "stateLostCandidates", "stateLostConfirmed", ].sort()); diff --git a/TestRunner/app/tests/canaryNativeWriteCacheWorker.js b/TestRunner/app/tests/canaryNativeWriteCacheWorker.js new file mode 100644 index 000000000..da7f7e5b5 --- /dev/null +++ b/TestRunner/app/tests/canaryNativeWriteCacheWorker.js @@ -0,0 +1,27 @@ +// Writes a native property from another isolate, which keeps a native setter +// cache of its own. +onmessage = function () { + var result = { values: [] }; + try { + var runtime = require("ns:runtime"); + var Sub = (function (_super) { + __extends(Sub, _super); + function Sub() { + return (_super !== null && _super.apply(this, arguments)) || this; + } + return Sub; + })(TNSCanaryCacheLeaf); + var depth = Object.getOwnPropertyDescriptor(TNSCanaryCacheBase.prototype, "depth").get; + var obj = Sub.new(); + var before = runtime.getWrapperLifetimeStats().canaryCachedNativeWrites; + obj.depth = 1; + obj.depth = 2; + obj.depth = 3; + result.hits = runtime.getWrapperLifetimeStats().canaryCachedNativeWrites - before; + result.values.push(depth.call(obj)); + result.own = Object.prototype.hasOwnProperty.call(obj, "depth"); + } catch (e) { + result.error = String((e && e.message) || e); + } + postMessage(result); +}; diff --git a/docs/knowledge/v8-resurrecting-finalizers.md b/docs/knowledge/v8-resurrecting-finalizers.md index 20d6326c4..92d548c4d 100644 --- a/docs/knowledge/v8-resurrecting-finalizers.md +++ b/docs/knowledge/v8-resurrecting-finalizers.md @@ -272,10 +272,19 @@ to the canary without calling the definer: a name that resolves to an inherited native property, a JS getter/setter) or a read-only data member never becomes state. When the first object on the chain with the name is a native class prototype that still records a native setter for it, the handler runs that setter itself -(`MetadataBuilder::TrySetNativeProperty`, the same code as the accessor's setter callback). +(`MetadataBuilder::FindNativeSetter`/`RunNativeSetter`, the same code as the accessor's setter +callback). Everything else is left to V8: a JS accessor, a read-only member, a native property without a setter, and a name JS assigned or defined on that prototype, which its own setter and definer -interceptors forget for good. The state is rooted from its first write until the native +interceptors forget for good. The handler caches the setter it found by the name and the +receiver's prototype (`NativeWriteCache`), so a later write of that name through an object with +that prototype skips the chain lookup. A hit rechecks that the receiver and every prototype +below the setter's owner still lack the name, that each prototype up to the owner is the one +the entry was made with, and that the owner still has an accessor whose setter was not +forgotten. Native class prototypes get the per-name recheck too: a `[[Set]]` that starts +elsewhere and has the prototype as its receiver (`Reflect.set({}, name, v, proto)`) defines a +data property there without reaching the prototype's interceptors. A name with no entry costs one read of +a small table of name tags. The state is rooted from its first write until the native object is deallocated (or, with the default death signal below, until its token is released), and stays the source of truth: a canary built later for the same object, or the receiver a JS-implemented `-dealloc` runs with, gets the state's diff --git a/docs/ns-builtin-modules.md b/docs/ns-builtin-modules.md index 930f3b790..d856dfa39 100644 --- a/docs/ns-builtin-modules.md +++ b/docs/ns-builtin-modules.md @@ -156,7 +156,8 @@ The `TypeError` messages are part of the contract: `getWrapperLifetimeStats()` returns counters for the calling isolate, kept in every build. Most cost an increment only on finalizer, GC-callback and error paths or when a state object is created; `canaryInterceptedWrites` costs one -on every write to a canary: +on every write to a canary, and `canaryCachedNativeWrites` one on each such +write the cache below places: | counter | counts | |---|---| @@ -172,6 +173,7 @@ on every write to a canary: | `canaryStates` | `"canary"` only: state objects created to hold native objects' JS properties, or only to hold the key a weak collection made for the object, a plain object's included under scope `"extended"` (see [Weak collections in canary mode](#weak-collections-in-canary-mode)) | | `canaryNativeDeaths` | `"canary"` only: state objects let go of because their native object was deallocated or, with the default death signal, because `objc_removeAssociatedObjects` released its lifecycle token while the object was still alive | | `canaryInterceptedWrites` | `"canary"` only: writes to canaries the runtime's write handler saw. Other wrappers have no handler | +| `canaryCachedNativeWrites` | `"canary"` only: of those writes, native property writes whose setter the handler found from an earlier write of the same name through an object with the same prototype, without looking the name up along the prototype chain | A wrapper whose native object was released keeps its JS identity. Passing it to native code follows `releasedObjectPolicy`: under `"report"` the argument diff --git a/types/ns-runtime.d.ts b/types/ns-runtime.d.ts index dee337de5..13e591233 100644 --- a/types/ns-runtime.d.ts +++ b/types/ns-runtime.d.ts @@ -138,6 +138,8 @@ declare module "ns:runtime" { canaryNativeDeaths: number; /** `"canary"` only: writes to canaries the runtime's write handler saw. */ canaryInterceptedWrites: number; + /** `"canary"` only: of those writes, native property writes whose setter the handler found from an earlier write of the same name through an object with the same prototype, without looking the name up along the prototype chain. */ + canaryCachedNativeWrites: number; } /** Live native object wrappers of one class in the calling isolate. */