From 10ecb8388408c3ad1bd067f1e0c618a77958aa5c Mon Sep 17 00:00:00 2001 From: "Gang Zhao (Hermes)" Date: Mon, 21 Oct 2024 18:47:01 -0700 Subject: [PATCH] Pass the pointer of owning object in GCPointer::set() part I (#1502) Summary: Pull Request resolved: https://github.com/facebook/hermes/pull/1502 Differential Revision: D62222257 --- include/hermes/VM/GCPointer-inline.h | 14 ++++++++++-- include/hermes/VM/GCPointer.h | 16 ++++++++------ include/hermes/VM/HiddenClass.h | 2 +- include/hermes/VM/JSArray.h | 2 +- include/hermes/VM/JSDataView.h | 2 +- include/hermes/VM/JSMapImpl.h | 5 +++-- include/hermes/VM/JSObject.h | 4 ++-- include/hermes/VM/OrderedHashMap.h | 2 +- lib/VM/Domain.cpp | 8 +++---- lib/VM/DummyObject.cpp | 2 +- lib/VM/FastArray.cpp | 6 +++--- lib/VM/HiddenClass.cpp | 6 ++++-- lib/VM/JSCallableProxy.cpp | 4 ++-- lib/VM/JSError.cpp | 6 ++++-- lib/VM/JSGeneratorObject.cpp | 2 +- lib/VM/JSObject.cpp | 32 +++++++++++++++++----------- lib/VM/JSProxy.cpp | 4 ++-- lib/VM/JSRegExp.cpp | 7 +++--- lib/VM/JSTypedArray.cpp | 2 +- lib/VM/OrderedHashMap.cpp | 15 +++++++------ lib/VM/PrimitiveBox.cpp | 3 ++- 21 files changed, 87 insertions(+), 57 deletions(-) diff --git a/include/hermes/VM/GCPointer-inline.h b/include/hermes/VM/GCPointer-inline.h index fa5f7633ed5..582bdd5d010 100644 --- a/include/hermes/VM/GCPointer-inline.h +++ b/include/hermes/VM/GCPointer-inline.h @@ -32,19 +32,29 @@ GCPointerBase::GCPointerBase( } } -inline void GCPointerBase::set(PointerBase &base, GCCell *ptr, GC &gc) { +inline void GCPointerBase::set( + PointerBase &base, + GCCell *ptr, + GC &gc, + const GCCell *owningObj) { assert( (!ptr || gc.validPointer(ptr)) && "Cannot set a GCPointer to an invalid pointer"); // Write barrier must happen before the write. + (void)owningObj; gc.writeBarrier(this, ptr); setNoBarrier(CompressedPointer::encode(ptr, base)); } -inline void GCPointerBase::setNonNull(PointerBase &base, GCCell *ptr, GC &gc) { +inline void GCPointerBase::setNonNull( + PointerBase &base, + GCCell *ptr, + GC &gc, + const GCCell *owningObj) { assert( gc.validPointer(ptr) && "Cannot set a GCPointer to an invalid pointer"); // Write barrier must happen before the write. + (void)owningObj; gc.writeBarrier(this, ptr); setNoBarrier(CompressedPointer::encodeNonNull(ptr, base)); } diff --git a/include/hermes/VM/GCPointer.h b/include/hermes/VM/GCPointer.h index 09db5f06d87..5b6d545b5d4 100644 --- a/include/hermes/VM/GCPointer.h +++ b/include/hermes/VM/GCPointer.h @@ -38,9 +38,12 @@ class GCPointerBase : public CompressedPointer { /// \param ptr The memory being pointed to. /// \param base The base of ptr. /// \param gc Used for write barriers. - inline void set(PointerBase &base, GCCell *ptr, GC &gc); + /// \param owningObj The object that contains this GCPointer. + inline void + set(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj); inline void set(PointerBase &base, CompressedPointer ptr, GC &gc); - inline void setNonNull(PointerBase &base, GCCell *ptr, GC &gc); + inline void + setNonNull(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj); /// Set this pointer to null. This needs a write barrier in some types of /// garbage collectors. @@ -90,11 +93,12 @@ class GCPointer : public GCPointerBase { /// \param base The base of ptr. /// \param ptr The memory being pointed to. /// \param gc Used for write barriers. - void set(PointerBase &base, T *ptr, GC &gc) { - GCPointerBase::set(base, ptr, gc); + /// \param owningObj The object that contains this GCPointer. + void set(PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) { + GCPointerBase::set(base, ptr, gc, owningObj); } - void setNonNull(PointerBase &base, T *ptr, GC &gc) { - GCPointerBase::setNonNull(base, ptr, gc); + void setNonNull(PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) { + GCPointerBase::setNonNull(base, ptr, gc, owningObj); } /// Convenience overload of GCPointer::set for other GCPointers. diff --git a/include/hermes/VM/HiddenClass.h b/include/hermes/VM/HiddenClass.h index b87a06d8d43..2870132b914 100644 --- a/include/hermes/VM/HiddenClass.h +++ b/include/hermes/VM/HiddenClass.h @@ -326,7 +326,7 @@ class HiddenClass final : public GCCell { } void setForInCache(BigStorage *arr, Runtime &runtime) { - forInCache_.set(runtime, arr, runtime.getHeap()); + forInCache_.set(runtime, arr, runtime.getHeap(), this); } void clearForInCache(Runtime &runtime) { diff --git a/include/hermes/VM/JSArray.h b/include/hermes/VM/JSArray.h index a61092bff13..4aeec334366 100644 --- a/include/hermes/VM/JSArray.h +++ b/include/hermes/VM/JSArray.h @@ -121,7 +121,7 @@ class ArrayImpl : public JSObject { /// Set the indexed storage of this array to be \p p. The pointer is allowed /// to be null. void setIndexedStorage(PointerBase &base, StorageType *p, GC &gc) { - indexedStorage_.set(base, p, gc); + indexedStorage_.set(base, p, gc, this); } /// @} diff --git a/include/hermes/VM/JSDataView.h b/include/hermes/VM/JSDataView.h index eeb8afe27c7..63050eb4eda 100644 --- a/include/hermes/VM/JSDataView.h +++ b/include/hermes/VM/JSDataView.h @@ -92,7 +92,7 @@ class JSDataView final : public JSObject { assert( offset + length <= buffer->size() && "A DataView cannot be looking outside of the storage"); - buffer_.setNonNull(runtime, buffer, runtime.getHeap()); + buffer_.setNonNull(runtime, buffer, runtime.getHeap(), this); offset_ = offset; length_ = length; } diff --git a/include/hermes/VM/JSMapImpl.h b/include/hermes/VM/JSMapImpl.h index a5627c42a00..c023fa77f5f 100644 --- a/include/hermes/VM/JSMapImpl.h +++ b/include/hermes/VM/JSMapImpl.h @@ -145,7 +145,7 @@ class JSMapIteratorImpl final : public JSObject { Runtime &runtime, Handle::ContainerKind>> data, IterationKind kind) { - data_.set(runtime, data.get(), runtime.getHeap()); + data_.set(runtime, data.get(), runtime.getHeap(), this); iterationKind_ = kind; assert(data_ && "Invalid storage data"); @@ -171,7 +171,8 @@ class JSMapIteratorImpl final : public JSObject { runtime, self->data_.getNonNull(runtime)->iteratorNext( runtime, self->itr_.get(runtime)), - runtime.getHeap()); + runtime.getHeap(), + *self); if (self->itr_) { switch (self->iterationKind_) { case IterationKind::Key: diff --git a/include/hermes/VM/JSObject.h b/include/hermes/VM/JSObject.h index 441858d1be0..47bcca3716a 100644 --- a/include/hermes/VM/JSObject.h +++ b/include/hermes/VM/JSObject.h @@ -463,7 +463,7 @@ class JSObject : public GCCell { /// cycle checking. static void unsafeSetParentInternal(JSObject *self, Runtime &runtime, JSObject *parent) { - self->parent_.set(runtime, parent, runtime.getHeap()); + self->parent_.set(runtime, parent, runtime.getHeap(), self); } /// Return the value of an internal property slot. Use getDirectSlotValue if @@ -1640,7 +1640,7 @@ inline ExecutionStatus JSObject::allocatePropStorage( return ExecutionStatus::EXCEPTION; selfHandle->propStorage_.setNonNull( - runtime, vmcast(*res), runtime.getHeap()); + runtime, vmcast(*res), runtime.getHeap(), *selfHandle); return ExecutionStatus::RETURNED; } diff --git a/include/hermes/VM/OrderedHashMap.h b/include/hermes/VM/OrderedHashMap.h index 61b08afb91d..c2c221b8960 100644 --- a/include/hermes/VM/OrderedHashMap.h +++ b/include/hermes/VM/OrderedHashMap.h @@ -200,7 +200,7 @@ class OrderedHashMapBase { return ExecutionStatus::EXCEPTION; } - self->hashTable_.set(runtime, arrRes->get(), runtime.getHeap()); + self->hashTable_.set(runtime, arrRes->get(), runtime.getHeap(), *self); return ExecutionStatus::RETURNED; } diff --git a/lib/VM/Domain.cpp b/lib/VM/Domain.cpp index c0d2b7b3916..f833950262d 100644 --- a/lib/VM/Domain.cpp +++ b/lib/VM/Domain.cpp @@ -167,7 +167,7 @@ ExecutionStatus Domain::importCJSModuleTable( return ExecutionStatus::EXCEPTION; } - self->throwingRequire_.set(runtime, *requireFn, runtime.getHeap()); + self->throwingRequire_.set(runtime, *requireFn, runtime.getHeap(), *self); } else { cjsModules = self->cjsModules_.get(runtime); } @@ -308,7 +308,7 @@ ExecutionStatus Domain::importCJSModuleTable( } } - self->cjsModules_.set(runtime, cjsModules.get(), runtime.getHeap()); + self->cjsModules_.set(runtime, cjsModules.get(), runtime.getHeap(), *self); return ExecutionStatus::RETURNED; } @@ -343,8 +343,8 @@ Handle RequireContext::create( runtime.getHiddenClassForPrototype( *objProto, numOverlapSlots())); auto self = JSObjectInit::initToHandle(runtime, cell); - self->domain_.set(runtime, *domain, runtime.getHeap()); - self->dirname_.set(runtime, *dirname, runtime.getHeap()); + self->domain_.set(runtime, *domain, runtime.getHeap(), *self); + self->dirname_.set(runtime, *dirname, runtime.getHeap(), *self); return self; } diff --git a/lib/VM/DummyObject.cpp b/lib/VM/DummyObject.cpp index cab35da5c22..244c43e4e5a 100644 --- a/lib/VM/DummyObject.cpp +++ b/lib/VM/DummyObject.cpp @@ -53,7 +53,7 @@ void DummyObject::releaseExtMem(GC &gc) { } void DummyObject::setPointer(GC &gc, DummyObject *obj) { - other.set(gc.getPointerBase(), obj, gc); + other.set(gc.getPointerBase(), obj, gc, this); } /* static */ constexpr CellKind DummyObject::getCellKind() { diff --git a/lib/VM/FastArray.cpp b/lib/VM/FastArray.cpp index a7dd89f23e9..b1af3e15ee8 100644 --- a/lib/VM/FastArray.cpp +++ b/lib/VM/FastArray.cpp @@ -104,7 +104,7 @@ CallResult FastArray::create(Runtime &runtime, size_t capacity) { return ExecutionStatus::EXCEPTION; lv.self->indexedStorage_.setNonNull( - runtime, vmcast(*arrRes), runtime.getHeap()); + runtime, vmcast(*arrRes), runtime.getHeap(), *lv.self); auto shv = SmallHermesValue::encodeNumberValue(0, runtime); lv.self->setLength(runtime, shv); @@ -122,7 +122,7 @@ FastArray::pushSlow(Handle self, Runtime &runtime, Handle<> val) { ExecutionStatus::EXCEPTION)) return ExecutionStatus::EXCEPTION; - self->indexedStorage_.setNonNull(runtime, *storage, runtime.getHeap()); + self->indexedStorage_.setNonNull(runtime, *storage, runtime.getHeap(), *self); auto newSz = SmallHermesValue::encodeNumberValue(storage->size(), runtime); self->setLength(runtime, newSz); return ExecutionStatus::RETURNED; @@ -141,7 +141,7 @@ ExecutionStatus FastArray::appendSlow( ArrayStorageSmall::append(storage, runtime, otherStorage) == ExecutionStatus::EXCEPTION)) return ExecutionStatus::EXCEPTION; - self->indexedStorage_.setNonNull(runtime, *storage, runtime.getHeap()); + self->indexedStorage_.setNonNull(runtime, *storage, runtime.getHeap(), *self); auto newSz = SmallHermesValue::encodeNumberValue(storage->size(), runtime); self->setLength(runtime, newSz); return ExecutionStatus::RETURNED; diff --git a/lib/VM/HiddenClass.cpp b/lib/VM/HiddenClass.cpp index fcd069eb0a5..cbc32ffdc55 100644 --- a/lib/VM/HiddenClass.cpp +++ b/lib/VM/HiddenClass.cpp @@ -826,7 +826,8 @@ ExecutionStatus HiddenClass::addToPropertyMap( return ExecutionStatus::EXCEPTION; } - selfHandle->propertyMap_.setNonNull(runtime, *updatedMap, runtime.getHeap()); + selfHandle->propertyMap_.setNonNull( + runtime, *updatedMap, runtime.getHeap(), *selfHandle); return ExecutionStatus::RETURNED; } @@ -889,7 +890,8 @@ void HiddenClass::initializeMissingPropertyMap( inserted->first->slot = slotIndex++; } - selfHandle->propertyMap_.setNonNull(runtime, *mapHandle, runtime.getHeap()); + selfHandle->propertyMap_.setNonNull( + runtime, *mapHandle, runtime.getHeap(), *selfHandle); } void HiddenClass::stealPropertyMapFromParent( diff --git a/lib/VM/JSCallableProxy.cpp b/lib/VM/JSCallableProxy.cpp index 6dddc36a8aa..568c69227c6 100644 --- a/lib/VM/JSCallableProxy.cpp +++ b/lib/VM/JSCallableProxy.cpp @@ -64,8 +64,8 @@ void JSCallableProxy::setTargetAndHandler( Runtime &runtime, Handle target, Handle handler) { - slots_.target.set(runtime, target.get(), runtime.getHeap()); - slots_.handler.set(runtime, handler.get(), runtime.getHeap()); + slots_.target.set(runtime, target.get(), runtime.getHeap(), this); + slots_.handler.set(runtime, handler.get(), runtime.getHeap(), this); } CallResult diff --git a/lib/VM/JSError.cpp b/lib/VM/JSError.cpp index edd77e49418..d634512461c 100644 --- a/lib/VM/JSError.cpp +++ b/lib/VM/JSError.cpp @@ -495,7 +495,8 @@ ExecutionStatus JSError::recordStackTrace( } } } - selfHandle->domains_.set(runtime, domains.get(), runtime.getHeap()); + selfHandle->domains_.set( + runtime, domains.get(), runtime.getHeap(), *selfHandle); // Remove the last entry. stack->pop_back(); @@ -509,7 +510,8 @@ ExecutionStatus JSError::recordStackTrace( "Function names and stack trace must have same size."); selfHandle->stacktrace_ = std::move(stack); - selfHandle->funcNames_.set(runtime, *funcNames, runtime.getHeap()); + selfHandle->funcNames_.set( + runtime, *funcNames, runtime.getHeap(), *selfHandle); return ExecutionStatus::RETURNED; } diff --git a/lib/VM/JSGeneratorObject.cpp b/lib/VM/JSGeneratorObject.cpp index 40e7ca07562..65bf8500a07 100644 --- a/lib/VM/JSGeneratorObject.cpp +++ b/lib/VM/JSGeneratorObject.cpp @@ -43,7 +43,7 @@ CallResult> JSGeneratorObject::create( parentHandle, runtime.getHiddenClassForPrototype( *parentHandle, numOverlapSlots())); - cell->innerFunction_.set(runtime, *innerFunction, runtime.getHeap()); + cell->innerFunction_.set(runtime, *innerFunction, runtime.getHeap(), cell); return JSObjectInit::initToPseudoHandle(runtime, cell); } diff --git a/lib/VM/JSObject.cpp b/lib/VM/JSObject.cpp index 89f736a036b..01bc5547169 100644 --- a/lib/VM/JSObject.cpp +++ b/lib/VM/JSObject.cpp @@ -101,7 +101,7 @@ PseudoHandle JSObject::create( Runtime &runtime, Handle clazz) { auto obj = JSObject::create(runtime, clazz->getNumProperties()); - obj->clazz_.setNonNull(runtime, *clazz, runtime.getHeap()); + obj->clazz_.setNonNull(runtime, *clazz, runtime.getHeap(), obj.get()); // If the hidden class has index like property, we need to clear the fast path // flag. if (LLVM_UNLIKELY( @@ -115,7 +115,7 @@ PseudoHandle JSObject::create( Handle parentHandle, Handle clazz) { PseudoHandle obj = JSObject::create(runtime, clazz); - obj->parent_.set(runtime, parentHandle.get(), runtime.getHeap()); + obj->parent_.set(runtime, parentHandle.get(), runtime.getHeap(), obj.get()); return obj; } @@ -224,7 +224,7 @@ CallResult JSObject::setParent( } } // 9. - self->parent_.set(runtime, parent, runtime.getHeap()); + self->parent_.set(runtime, parent, runtime.getHeap(), self); // 10. return true; } @@ -252,7 +252,7 @@ void JSObject::allocateNewSlotStorage( auto arrRes = runtime.ignoreAllocationFailure( PropStorage::create(runtime, DEFAULT_PROPERTY_CAPACITY)); selfHandle->propStorage_.setNonNull( - runtime, vmcast(arrRes), runtime.getHeap()); + runtime, vmcast(arrRes), runtime.getHeap(), *selfHandle); } else if (LLVM_UNLIKELY( newSlotIndex >= selfHandle->propStorage_.getNonNull(runtime)->capacity())) { @@ -262,7 +262,8 @@ void JSObject::allocateNewSlotStorage( "allocated slot must be at end"); auto hnd = runtime.makeMutableHandle(selfHandle->propStorage_); PropStorage::resize(hnd, runtime, newSlotIndex + 1); - selfHandle->propStorage_.setNonNull(runtime, *hnd, runtime.getHeap()); + selfHandle->propStorage_.setNonNull( + runtime, *hnd, runtime.getHeap(), *selfHandle); } { @@ -1924,7 +1925,8 @@ CallResult JSObject::deleteNamed( // Perform the actual deletion. auto newClazz = HiddenClass::deleteProperty( runtime.makeHandle(selfHandle->clazz_), runtime, *pos); - selfHandle->clazz_.setNonNull(runtime, *newClazz, runtime.getHeap()); + selfHandle->clazz_.setNonNull( + runtime, *newClazz, runtime.getHeap(), *selfHandle); return true; } @@ -2024,7 +2026,8 @@ CallResult JSObject::deleteComputed( // Remove the property descriptor. auto newClazz = HiddenClass::deleteProperty( runtime.makeHandle(selfHandle->clazz_), runtime, *pos); - selfHandle->clazz_.setNonNull(runtime, *newClazz, runtime.getHeap()); + selfHandle->clazz_.setNonNull( + runtime, *newClazz, runtime.getHeap(), *selfHandle); } else if (LLVM_UNLIKELY(selfHandle->flags_.proxyObject)) { CallResult> key = toPropertyKey(runtime, nameValPrimitiveHandle); if (key == ExecutionStatus::EXCEPTION) @@ -2613,7 +2616,8 @@ ExecutionStatus JSObject::seal(Handle selfHandle, Runtime &runtime) { auto newClazz = HiddenClass::makeAllNonConfigurable( runtime.makeHandle(selfHandle->clazz_), runtime); - selfHandle->clazz_.setNonNull(runtime, *newClazz, runtime.getHeap()); + selfHandle->clazz_.setNonNull( + runtime, *newClazz, runtime.getHeap(), *selfHandle); selfHandle->flags_.sealed = true; @@ -2638,7 +2642,8 @@ ExecutionStatus JSObject::freeze( auto newClazz = HiddenClass::makeAllReadOnly( runtime.makeHandle(selfHandle->clazz_), runtime); - selfHandle->clazz_.setNonNull(runtime, *newClazz, runtime.getHeap()); + selfHandle->clazz_.setNonNull( + runtime, *newClazz, runtime.getHeap(), *selfHandle); selfHandle->flags_.frozen = true; selfHandle->flags_.sealed = true; @@ -2658,7 +2663,8 @@ void JSObject::updatePropertyFlagsWithoutTransitions( flagsToClear, flagsToSet, props); - selfHandle->clazz_.setNonNull(runtime, *newClazz, runtime.getHeap()); + selfHandle->clazz_.setNonNull( + runtime, *newClazz, runtime.getHeap(), *selfHandle); } CallResult JSObject::isExtensible( @@ -2783,7 +2789,8 @@ ExecutionStatus JSObject::addOwnPropertyImpl( if (LLVM_UNLIKELY(addResult == ExecutionStatus::EXCEPTION)) { return ExecutionStatus::EXCEPTION; } - selfHandle->clazz_.setNonNull(runtime, *addResult->first, runtime.getHeap()); + selfHandle->clazz_.setNonNull( + runtime, *addResult->first, runtime.getHeap(), *selfHandle); allocateNewSlotStorage( selfHandle, runtime, addResult->second, valueOrAccessor); @@ -2826,7 +2833,8 @@ CallResult JSObject::updateOwnProperty( runtime, propertyPos, desc.flags); - selfHandle->clazz_.setNonNull(runtime, *newClazz, runtime.getHeap()); + selfHandle->clazz_.setNonNull( + runtime, *newClazz, runtime.getHeap(), *selfHandle); } if (updateStatus->first == PropertyUpdateStatus::done) diff --git a/lib/VM/JSProxy.cpp b/lib/VM/JSProxy.cpp index 79570b85c54..a8c2ba546a3 100644 --- a/lib/VM/JSProxy.cpp +++ b/lib/VM/JSProxy.cpp @@ -108,8 +108,8 @@ void JSProxy::setTargetAndHandler( Handle target, Handle handler) { auto &slots = detail::slots(*selfHandle); - slots.target.set(runtime, target.get(), runtime.getHeap()); - slots.handler.set(runtime, handler.get(), runtime.getHeap()); + slots.target.set(runtime, target.get(), runtime.getHeap(), *selfHandle); + slots.handler.set(runtime, handler.get(), runtime.getHeap(), *selfHandle); } namespace { diff --git a/lib/VM/JSRegExp.cpp b/lib/VM/JSRegExp.cpp index a8140cfd34c..442753492b9 100644 --- a/lib/VM/JSRegExp.cpp +++ b/lib/VM/JSRegExp.cpp @@ -101,7 +101,7 @@ void JSRegExp::initialize( assert( pattern && flags && "Null pattern and/or flags passed to JSRegExp::initialize"); - selfHandle->pattern_.set(runtime, *pattern, runtime.getHeap()); + selfHandle->pattern_.set(runtime, *pattern, runtime.getHeap(), *selfHandle); DefinePropertyFlags dpf = DefinePropertyFlags::getDefaultNewPropertyFlags(); dpf.enumerable = 0; @@ -220,7 +220,8 @@ ExecutionStatus JSRegExp::initializeGroupNameMappingObj( return ExecutionStatus::EXCEPTION; } - selfHandle->groupNameMappings_.set(runtime, *obj, runtime.getHeap()); + selfHandle->groupNameMappings_.set( + runtime, *obj, runtime.getHeap(), *selfHandle); return ExecutionStatus::RETURNED; } @@ -231,7 +232,7 @@ Handle JSRegExp::getGroupNameMappings(Runtime &runtime) { } void JSRegExp::setGroupNameMappings(Runtime &runtime, JSObject *groupObj) { - groupNameMappings_.set(runtime, groupObj, runtime.getHeap()); + groupNameMappings_.set(runtime, groupObj, runtime.getHeap(), this); } void JSRegExp::initializeBytecode(llvh::ArrayRef bytecode) { diff --git a/lib/VM/JSTypedArray.cpp b/lib/VM/JSTypedArray.cpp index 518ff5d9293..5b21e57c09e 100644 --- a/lib/VM/JSTypedArray.cpp +++ b/lib/VM/JSTypedArray.cpp @@ -305,7 +305,7 @@ void JSTypedArrayBase::setBuffer( assert( self->getByteWidth() == byteWidth && "Cannot set to a buffer of a different byte width"); - self->buffer_.setNonNull(runtime, buf, runtime.getHeap()); + self->buffer_.setNonNull(runtime, buf, runtime.getHeap(), self); self->offset_ = offset; self->length_ = size / byteWidth; } diff --git a/lib/VM/OrderedHashMap.cpp b/lib/VM/OrderedHashMap.cpp index 06f0911ed74..5c45095cd3b 100644 --- a/lib/VM/OrderedHashMap.cpp +++ b/lib/VM/OrderedHashMap.cpp @@ -191,7 +191,8 @@ ExecutionStatus OrderedHashMapBase::rehash( } rawSelf->deletedCount_ = 0; - rawSelf->hashTable_.setNonNull(runtime, newHashTable, runtime.getHeap()); + rawSelf->hashTable_.setNonNull( + runtime, newHashTable, runtime.getHeap(), *self); assert( rawSelf->hashTable_.getNonNull(runtime)->size(runtime) == rawSelf->capacity_ && @@ -337,17 +338,17 @@ ExecutionStatus OrderedHashMapBase::doInsert( if (!rawSelf->firstIterationEntry_) { // If we are inserting the first ever element, update // first iteration entry pointer. - rawSelf->firstIterationEntry_.set(runtime, newMapEntry.get(), heap); - rawSelf->lastIterationEntry_.set(runtime, newMapEntry.get(), heap); + rawSelf->firstIterationEntry_.set(runtime, newMapEntry.get(), heap, *self); + rawSelf->lastIterationEntry_.set(runtime, newMapEntry.get(), heap, *self); } else { // Connect the new entry with the last entry. - rawSelf->lastIterationEntry_.getNonNull(runtime)->nextIterationEntry.set( - runtime, newMapEntry.get(), heap); + auto *previousLastEntry = rawSelf->lastIterationEntry_.getNonNull(runtime); + previousLastEntry->nextIterationEntry.set( + runtime, newMapEntry.get(), heap, previousLastEntry); newMapEntry->prevIterationEntry.set( runtime, rawSelf->lastIterationEntry_, heap); - BucketType *previousLastEntry = rawSelf->lastIterationEntry_.get(runtime); - rawSelf->lastIterationEntry_.set(runtime, newMapEntry.get(), heap); + rawSelf->lastIterationEntry_.set(runtime, newMapEntry.get(), heap, *self); if (previousLastEntry && previousLastEntry->isDeleted()) { // If the last entry was a deleted entry, we no longer need to keep it. diff --git a/lib/VM/PrimitiveBox.cpp b/lib/VM/PrimitiveBox.cpp index dc4f620e0a6..bc80dc76fb3 100644 --- a/lib/VM/PrimitiveBox.cpp +++ b/lib/VM/PrimitiveBox.cpp @@ -81,7 +81,8 @@ void JSString::setPrimitiveString( auto shv = SmallHermesValue::encodeNumberValue(string->getStringLength(), runtime); JSObject::setNamedSlotValueUnsafe(*selfHandle, runtime, desc, shv); - selfHandle->primitiveValue_.set(runtime, *string, runtime.getHeap()); + selfHandle->primitiveValue_.set( + runtime, *string, runtime.getHeap(), *selfHandle); } bool JSString::_haveOwnIndexedImpl(