Skip to content

Commit

Permalink
Bug 1821959 - Use unshiftedElementsHeader when transplanting objects.…
Browse files Browse the repository at this point in the history
… r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D173171
  • Loading branch information
moztcampbell committed Mar 28, 2023
1 parent c3a95ae commit abeb53a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions js/src/vm/JSObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,13 @@ bool NativeObject::prepareForSwap(JSContext* cx,

if (hasDynamicElements()) {
ObjectElements* elements = getElementsHeader();
void* allocatedElements = getUnshiftedElementsHeader();
size_t count = elements->numAllocatedElements();
size_t size = count * sizeof(HeapSlot);

if (isTenured()) {
RemoveCellMemory(this, size, MemoryUse::ObjectElements);
} else if (cx->nursery().isInside(elements)) {
} else if (cx->nursery().isInside(allocatedElements)) {
// Move nursery allocated elements in case they end up in a tenured
// object.
ObjectElements* newElements =
Expand All @@ -1045,7 +1046,7 @@ bool NativeObject::prepareForSwap(JSContext* cx,
memmove(newElements, elements, size);
elements_ = newElements->elements();
} else {
cx->nursery().removeMallocedBuffer(elements, size);
cx->nursery().removeMallocedBuffer(allocatedElements, size);
}
MOZ_ASSERT(hasDynamicElements());
}
Expand Down Expand Up @@ -1095,11 +1096,12 @@ bool NativeObject::fixupAfterSwap(JSContext* cx, Handle<NativeObject*> obj,

if (obj->hasDynamicElements()) {
ObjectElements* elements = obj->getElementsHeader();
MOZ_ASSERT(!cx->nursery().isInside(elements));
void* allocatedElements = obj->getUnshiftedElementsHeader();
MOZ_ASSERT(!cx->nursery().isInside(allocatedElements));
size_t size = elements->numAllocatedElements() * sizeof(HeapSlot);
if (obj->isTenured()) {
AddCellMemory(obj, size, MemoryUse::ObjectElements);
} else if (!cx->nursery().registerMallocedBuffer(elements, size)) {
} else if (!cx->nursery().registerMallocedBuffer(allocatedElements, size)) {
return false;
}
}
Expand Down Expand Up @@ -3259,7 +3261,7 @@ js::gc::AllocKind JSObject::allocKindForTenure(
MOZ_ASSERT(nobj.numFixedSlots() == 0);

/* Use minimal size object if we are just going to copy the pointer. */
if (!nursery.isInside(nobj.getElementsHeader())) {
if (!nursery.isInside(nobj.getUnshiftedElementsHeader())) {
return gc::AllocKind::OBJECT0_BACKGROUND;
}

Expand Down

0 comments on commit abeb53a

Please sign in to comment.