Bug 1062473: Make JSObject::allocKindForTenure out of GetObjectAllocKindForCopy. r=terrence
This commit is contained in:
@@ -3897,6 +3897,68 @@ js::DumpBacktrace(JSContext* cx)
|
||||
|
||||
/* * */
|
||||
|
||||
js::gc::AllocKind
|
||||
JSObject::allocKindForTenure(const js::Nursery& nursery) const
|
||||
{
|
||||
if (is<ArrayObject>()) {
|
||||
const ArrayObject& aobj = as<ArrayObject>();
|
||||
MOZ_ASSERT(aobj.numFixedSlots() == 0);
|
||||
|
||||
/* Use minimal size object if we are just going to copy the pointer. */
|
||||
if (!nursery.isInside(aobj.getElementsHeader()))
|
||||
return AllocKind::OBJECT0_BACKGROUND;
|
||||
|
||||
size_t nelements = aobj.getDenseCapacity();
|
||||
return GetBackgroundAllocKind(GetGCArrayKind(nelements));
|
||||
}
|
||||
|
||||
if (is<JSFunction>())
|
||||
return as<JSFunction>().getAllocKind();
|
||||
|
||||
/*
|
||||
* Typed arrays in the nursery may have a lazily allocated buffer, make
|
||||
* sure there is room for the array's fixed data when moving the array.
|
||||
*/
|
||||
if (is<TypedArrayObject>() && !as<TypedArrayObject>().buffer()) {
|
||||
size_t nbytes = as<TypedArrayObject>().byteLength();
|
||||
return GetBackgroundAllocKind(TypedArrayObject::AllocKindForLazyBuffer(nbytes));
|
||||
}
|
||||
|
||||
// Proxies have finalizers and are not nursery allocated.
|
||||
MOZ_ASSERT(!IsProxy(this));
|
||||
|
||||
// Unboxed plain objects are sized according to the data they store.
|
||||
if (is<UnboxedPlainObject>()) {
|
||||
size_t nbytes = as<UnboxedPlainObject>().layoutDontCheckGeneration().size();
|
||||
return GetGCObjectKindForBytes(UnboxedPlainObject::offsetOfData() + nbytes);
|
||||
}
|
||||
|
||||
// Inlined typed objects are followed by their data, so make sure we copy
|
||||
// it all over to the new object.
|
||||
if (is<InlineTypedObject>()) {
|
||||
// Figure out the size of this object, from the prototype's TypeDescr.
|
||||
// The objects we are traversing here are all tenured, so we don't need
|
||||
// to check forwarding pointers.
|
||||
TypeDescr& descr = as<InlineTypedObject>().typeDescr();
|
||||
MOZ_ASSERT(!IsInsideNursery(&descr));
|
||||
return InlineTypedObject::allocKindForTypeDescriptor(&descr);
|
||||
}
|
||||
|
||||
// Outline typed objects use the minimum allocation kind.
|
||||
if (is<OutlineTypedObject>())
|
||||
return AllocKind::OBJECT0;
|
||||
|
||||
// All nursery allocatable non-native objects are handled above.
|
||||
MOZ_ASSERT(isNative());
|
||||
|
||||
AllocKind kind = GetGCObjectFixedSlotsKind(as<NativeObject>().numFixedSlots());
|
||||
MOZ_ASSERT(!IsBackgroundFinalized(kind));
|
||||
if (!CanBeFinalizedInBackground(kind, getClass()))
|
||||
return kind;
|
||||
return GetBackgroundAllocKind(kind);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JSObject::addSizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf, JS::ClassInfo* info)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user