Bug 1001159 (part 6) - Used ArenaCellIterImpl in Arena::finalize(). r=billm.

This commit is contained in:
Nicholas Nethercote 2014-04-29 18:03:28 -07:00
parent 36baf4fea3
commit cfcbd44588
2 changed files with 36 additions and 33 deletions

View File

@ -443,42 +443,30 @@ Arena::finalize(FreeOp *fop, AllocKind thingKind, size_t thingSize)
JS_ASSERT(!aheader.markOverflow);
JS_ASSERT(!aheader.allocatedDuringIncremental);
uintptr_t thing = thingsStart(thingKind);
uintptr_t firstThingOrSuccessorOfLastMarkedThing = thing;
uintptr_t firstThing = thingsStart(thingKind);
uintptr_t firstThingOrSuccessorOfLastMarkedThing = firstThing;
uintptr_t lastByte = thingsEnd() - 1;
FreeSpan nextFree(aheader.getFirstFreeSpan());
nextFree.checkSpan();
FreeSpan newListHead;
FreeSpan *newListTail = &newListHead;
size_t nmarked = 0;
for (;; thing += thingSize) {
JS_ASSERT(thing <= lastByte + 1);
if (thing == nextFree.first) {
JS_ASSERT(nextFree.last <= lastByte);
if (nextFree.last == lastByte)
break;
JS_ASSERT(Arena::isAligned(nextFree.last, thingSize));
thing = nextFree.last;
nextFree = *nextFree.nextSpan();
nextFree.checkSpan();
} else {
T *t = reinterpret_cast<T *>(thing);
if (t->isMarked()) {
if (thing != firstThingOrSuccessorOfLastMarkedThing) {
// We just finished passing over one or more free things,
// so record a new FreeSpan.
newListTail->first = firstThingOrSuccessorOfLastMarkedThing;
newListTail->last = thing - thingSize;
newListTail = newListTail->nextSpanUnchecked(thingSize);
}
firstThingOrSuccessorOfLastMarkedThing = thing + thingSize;
nmarked++;
} else {
t->finalize(fop);
JS_POISON(t, JS_SWEPT_TENURED_PATTERN, thingSize);
for (ArenaCellIterUnderFinalize i(&aheader); !i.done(); i.next()) {
T *t = i.get<T>();
if (t->isMarked()) {
uintptr_t thing = reinterpret_cast<uintptr_t>(t);
if (thing != firstThingOrSuccessorOfLastMarkedThing) {
// We just finished passing over one or more free things,
// so record a new FreeSpan.
newListTail->first = firstThingOrSuccessorOfLastMarkedThing;
newListTail->last = thing - thingSize;
newListTail = newListTail->nextSpanUnchecked(thingSize);
}
firstThingOrSuccessorOfLastMarkedThing = thing + thingSize;
nmarked++;
} else {
t->finalize(fop);
JS_POISON(t, JS_SWEPT_TENURED_PATTERN, thingSize);
}
}

View File

@ -159,7 +159,7 @@ class ArenaIter
class ArenaCellIterImpl
{
// These three are set in init().
// These three are set in initUnsynchronized().
size_t firstThingOffset;
size_t thingSize;
#ifdef DEBUG
@ -188,10 +188,9 @@ class ArenaCellIterImpl
public:
ArenaCellIterImpl() {}
void init(ArenaHeader *aheader) {
void initUnsynchronized(ArenaHeader *aheader) {
AllocKind kind = aheader->getAllocKind();
#ifdef DEBUG
JS_ASSERT(aheader->zone->allocator.arenas.isSynchronizedFreeList(kind));
isInited = true;
#endif
firstThingOffset = Arena::firstThingOffset(kind);
@ -199,6 +198,14 @@ class ArenaCellIterImpl
reset(aheader);
}
void init(ArenaHeader *aheader) {
#ifdef DEBUG
AllocKind kind = aheader->getAllocKind();
JS_ASSERT(aheader->zone->allocator.arenas.isSynchronizedFreeList(kind));
#endif
initUnsynchronized(aheader);
}
// Use this to move from an Arena of a particular kind to another Arena of
// the same kind.
void reset(ArenaHeader *aheader) {
@ -241,6 +248,14 @@ class ArenaCellIterUnderGC : public ArenaCellIterImpl
}
};
class ArenaCellIterUnderFinalize : public ArenaCellIterImpl
{
public:
ArenaCellIterUnderFinalize(ArenaHeader *aheader) {
initUnsynchronized(aheader);
}
};
class ZoneCellIterImpl
{
ArenaIter arenaIter;