mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1148214 - Replace manual AllocKind range checks with a few centralized functions. r=terrence
This commit is contained in:
parent
6187011b84
commit
06fb3fb01e
@ -99,7 +99,7 @@ js::Allocate(ExclusiveContext *cx, AllocKind kind, size_t nDynamicSlots, Initial
|
||||
const Class *clasp)
|
||||
{
|
||||
static_assert(mozilla::IsConvertible<T *, JSObject *>::value, "must be JSObject derived");
|
||||
MOZ_ASSERT(kind <= AllocKind::OBJECT_LAST);
|
||||
MOZ_ASSERT(IsObjectAllocKind(kind));
|
||||
size_t thingSize = Arena::thingSize(kind);
|
||||
|
||||
MOZ_ASSERT(thingSize == Arena::thingSize(kind));
|
||||
|
@ -110,8 +110,27 @@ enum class AllocKind {
|
||||
LAST = LIMIT - 1
|
||||
};
|
||||
|
||||
static_assert(uint8_t(AllocKind::OBJECT0) == 0, "Please check AllocKind iterations and comparisons"
|
||||
" of the form |kind <= AllocKind::OBJECT_LAST| to ensure their range is still valid!");
|
||||
static_assert(int(AllocKind::FIRST) == 0, "Various places depend on AllocKind starting at 0, "
|
||||
"please audit them carefully!");
|
||||
static_assert(int(AllocKind::OBJECT0) == 0, "Various places depend on AllocKind::OBJECT0 being 0, "
|
||||
"please audit them carefully!");
|
||||
|
||||
inline bool
|
||||
IsObjectAllocKind(AllocKind kind)
|
||||
{
|
||||
return kind >= AllocKind::OBJECT0 && kind <= AllocKind::OBJECT_LAST;
|
||||
}
|
||||
|
||||
inline bool
|
||||
IsValidAllocKind(AllocKind kind)
|
||||
{
|
||||
return kind >= AllocKind::FIRST && kind <= AllocKind::LAST;
|
||||
}
|
||||
|
||||
inline bool IsAllocKind(AllocKind kind)
|
||||
{
|
||||
return kind >= AllocKind::FIRST && kind <= AllocKind::LIMIT;
|
||||
}
|
||||
|
||||
// Returns a sequence for use in a range-based for loop,
|
||||
// to iterate over all alloc kinds.
|
||||
@ -134,8 +153,8 @@ ObjectAllocKinds()
|
||||
inline decltype(mozilla::MakeEnumeratedRange<int>(AllocKind::FIRST, AllocKind::LIMIT))
|
||||
SomeAllocKinds(AllocKind first = AllocKind::FIRST, AllocKind limit = AllocKind::LIMIT)
|
||||
{
|
||||
MOZ_ASSERT(limit <= AllocKind::LIMIT);
|
||||
MOZ_ASSERT(first <= limit);
|
||||
MOZ_ASSERT(IsAllocKind(first), "|first| is not a valid AllocKind!");
|
||||
MOZ_ASSERT(IsAllocKind(limit), "|limit| is not a valid AllocKind!");
|
||||
return mozilla::MakeEnumeratedRange<int>(first, limit);
|
||||
}
|
||||
|
||||
@ -615,8 +634,8 @@ struct ArenaHeader
|
||||
inline Chunk *chunk() const;
|
||||
|
||||
bool allocated() const {
|
||||
MOZ_ASSERT(allocKind <= size_t(AllocKind::LIMIT));
|
||||
return allocKind < size_t(AllocKind::LIMIT);
|
||||
MOZ_ASSERT(IsAllocKind(AllocKind(allocKind)));
|
||||
return IsValidAllocKind(AllocKind(allocKind));
|
||||
}
|
||||
|
||||
void init(JS::Zone *zoneArg, AllocKind kind) {
|
||||
|
@ -1144,7 +1144,7 @@ void
|
||||
MacroAssembler::allocateObject(Register result, Register temp, gc::AllocKind allocKind,
|
||||
uint32_t nDynamicSlots, gc::InitialHeap initialHeap, Label *fail)
|
||||
{
|
||||
MOZ_ASSERT(allocKind <= gc::AllocKind::OBJECT_LAST);
|
||||
MOZ_ASSERT(gc::IsObjectAllocKind(allocKind));
|
||||
|
||||
checkAllocatorState(fail);
|
||||
|
||||
@ -1180,7 +1180,7 @@ MacroAssembler::newGCThing(Register result, Register temp, JSObject *templateObj
|
||||
gc::InitialHeap initialHeap, Label *fail)
|
||||
{
|
||||
gc::AllocKind allocKind = templateObj->asTenured().getAllocKind();
|
||||
MOZ_ASSERT(allocKind <= gc::AllocKind::OBJECT_LAST);
|
||||
MOZ_ASSERT(gc::IsObjectAllocKind(allocKind));
|
||||
|
||||
size_t ndynamic = 0;
|
||||
if (templateObj->isNative())
|
||||
@ -1194,7 +1194,7 @@ MacroAssembler::createGCObject(Register obj, Register temp, JSObject *templateOb
|
||||
bool convertDoubleElements)
|
||||
{
|
||||
gc::AllocKind allocKind = templateObj->asTenured().getAllocKind();
|
||||
MOZ_ASSERT(allocKind <= gc::AllocKind::OBJECT_LAST);
|
||||
MOZ_ASSERT(gc::IsObjectAllocKind(allocKind));
|
||||
|
||||
uint32_t nDynamicSlots = 0;
|
||||
if (templateObj->isNative()) {
|
||||
|
@ -1160,7 +1160,7 @@ AssertValidObjectPtr(JSContext *cx, JSObject *obj)
|
||||
if (obj->isTenured()) {
|
||||
MOZ_ASSERT(obj->isAligned());
|
||||
gc::AllocKind kind = obj->asTenured().getAllocKind();
|
||||
MOZ_ASSERT(kind <= js::gc::AllocKind::OBJECT_LAST);
|
||||
MOZ_ASSERT(gc::IsObjectAllocKind(kind));
|
||||
MOZ_ASSERT(obj->asTenured().zone() == cx->zone());
|
||||
}
|
||||
#endif
|
||||
|
@ -1833,7 +1833,7 @@ CanRelocateZone(JSRuntime *rt, Zone *zone)
|
||||
static bool
|
||||
CanRelocateAllocKind(AllocKind kind)
|
||||
{
|
||||
return kind <= AllocKind::OBJECT_LAST;
|
||||
return IsObjectAllocKind(kind);
|
||||
}
|
||||
|
||||
size_t ArenaHeader::countFreeCells()
|
||||
@ -1959,7 +1959,7 @@ RelocateCell(Zone *zone, TenuredCell *src, AllocKind thingKind, size_t thingSize
|
||||
// Copy source cell contents to destination.
|
||||
memcpy(dst, src, thingSize);
|
||||
|
||||
if (thingKind <= AllocKind::OBJECT_LAST) {
|
||||
if (IsObjectAllocKind(thingKind)) {
|
||||
JSObject *srcObj = static_cast<JSObject *>(static_cast<Cell *>(src));
|
||||
JSObject *dstObj = static_cast<JSObject *>(static_cast<Cell *>(dst));
|
||||
|
||||
@ -2311,7 +2311,7 @@ struct ArenasToUpdate
|
||||
|
||||
bool ArenasToUpdate::shouldProcessKind(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(kind < AllocKind::LIMIT);
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
|
||||
// GC things that do not contain JSObject pointers don't need updating.
|
||||
if (kind == AllocKind::FAT_INLINE_STRING ||
|
||||
|
@ -81,7 +81,7 @@ template <> struct MapTypeToFinalizeKind<jit::JitCode> { static const Alloc
|
||||
static inline bool
|
||||
IsNurseryAllocable(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(kind < AllocKind::LIMIT);
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
static const bool map[] = {
|
||||
false, /* AllocKind::OBJECT0 */
|
||||
true, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
@ -114,7 +114,7 @@ IsNurseryAllocable(AllocKind kind)
|
||||
static inline bool
|
||||
IsBackgroundFinalized(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(kind < AllocKind::LIMIT);
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
static const bool map[] = {
|
||||
false, /* AllocKind::OBJECT0 */
|
||||
true, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
@ -147,7 +147,7 @@ IsBackgroundFinalized(AllocKind kind)
|
||||
static inline bool
|
||||
CanBeFinalizedInBackground(AllocKind kind, const Class *clasp)
|
||||
{
|
||||
MOZ_ASSERT(kind <= AllocKind::OBJECT_LAST);
|
||||
MOZ_ASSERT(IsObjectAllocKind(kind));
|
||||
/* If the class has no finalizer or a finalizer that is safe to call on
|
||||
* a different thread, we change the alloc kind. For example,
|
||||
* AllocKind::OBJECT0 calls the finalizer on the main thread,
|
||||
@ -219,7 +219,7 @@ static inline AllocKind
|
||||
GetBackgroundAllocKind(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(!IsBackgroundFinalized(kind));
|
||||
MOZ_ASSERT(kind < AllocKind::OBJECT_LAST);
|
||||
MOZ_ASSERT(IsObjectAllocKind(kind));
|
||||
return AllocKind(size_t(kind) + 1);
|
||||
}
|
||||
|
||||
|
@ -1385,7 +1385,7 @@ JSObject *
|
||||
js::NewObjectWithGroupCommon(ExclusiveContext *cx, HandleObjectGroup group,
|
||||
gc::AllocKind allocKind, NewObjectKind newKind)
|
||||
{
|
||||
MOZ_ASSERT(allocKind <= gc::AllocKind::OBJECT_LAST);
|
||||
MOZ_ASSERT(gc::IsObjectAllocKind(allocKind));
|
||||
if (CanBeFinalizedInBackground(allocKind, group->clasp()))
|
||||
allocKind = GetBackgroundAllocKind(allocKind);
|
||||
|
||||
|
@ -242,7 +242,7 @@ Shape::fixupDictionaryShapeAfterMovingGC()
|
||||
AllocKind kind = TenuredCell::fromPointer(cell)->getAllocKind();
|
||||
MOZ_ASSERT(kind == AllocKind::SHAPE ||
|
||||
kind == AllocKind::ACCESSOR_SHAPE ||
|
||||
kind <= AllocKind::OBJECT_LAST);
|
||||
IsObjectAllocKind(kind));
|
||||
if (kind == AllocKind::SHAPE || kind == AllocKind::ACCESSOR_SHAPE) {
|
||||
// listp points to the parent field of the next shape.
|
||||
Shape *next = reinterpret_cast<Shape *>(uintptr_t(listp) -
|
||||
|
Loading…
Reference in New Issue
Block a user