From d27001da519a7a65b920d3b6da88df2b365d767f Mon Sep 17 00:00:00 2001 From: Gregor Wagner Date: Thu, 10 Mar 2011 15:27:21 -0800 Subject: [PATCH] Bug 638199 - Shrink ArenaHeader (r=wmccloskey) --- js/src/jsgc.cpp | 21 +++++++++++++-------- js/src/jsgc.h | 8 +++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 9c019c91e7c6..b76f7be04b8e 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -170,8 +170,6 @@ Arena::init(JSCompartment *compartment, unsigned thingKind) aheader.compartment = compartment; aheader.thingKind = thingKind; aheader.freeList = &t.things[0].cell; - aheader.thingSize = sizeof(T); - aheader.isUsed = true; JS_ASSERT(sizeof(T) == sizeof(ThingOrCell)); ThingOrCell *thing = &t.things[0]; ThingOrCell *last = &t.things[JS_ARRAY_LENGTH(t.things) - 1]; @@ -181,6 +179,8 @@ Arena::init(JSCompartment *compartment, unsigned thingKind) } last->cell.link = NULL; #ifdef DEBUG + aheader.thingSize = sizeof(T); + aheader.isUsed = true; aheader.hasFreeThings = true; #endif } @@ -211,16 +211,15 @@ template inline ConservativeGCTest Arena::mark(T *thing, JSTracer *trc) { - JS_ASSERT(sizeof(T) == aheader.thingSize); - T *alignedThing = getAlignedThing(thing); if (alignedThing > &t.things[ThingsPerArena-1].t || alignedThing < &t.things[0].t) return CGCT_NOTARENA; - if (!aheader.isUsed || inFreeList(alignedThing)) + if (!aheader.compartment || inFreeList(alignedThing)) return CGCT_NOTLIVE; + JS_ASSERT(sizeof(T) == aheader.thingSize); JS_SET_TRACING_NAME(trc, "machine stack"); Mark(trc, alignedThing); @@ -290,11 +289,17 @@ Chunk::init(JSRuntime *rt) Arena *last = &arenas[JS_ARRAY_LENGTH(arenas) - 1]; while (arena < last) { arena->header()->next = arena + 1; + arena->header()->compartment = NULL; +#ifdef DEBUG arena->header()->isUsed = false; +#endif ++arena; } last->header()->next = NULL; + last->header()->compartment = NULL; +#ifdef DEBUG last->header()->isUsed = false; +#endif info.numFree = ArenasPerChunk; } @@ -353,7 +358,10 @@ Chunk::releaseArena(Arena *arena) rt->gcBytes -= sizeof(Arena); comp->gcBytes -= sizeof(Arena); info.emptyArenaLists.insert((Arena *)arena); +#ifdef DEBUG arena->header()->isUsed = false; +#endif + arena->header()->compartment = NULL; ++info.numFree; if (unused()) info.age = 0; @@ -632,9 +640,6 @@ MarkIfGCThingWord(JSTracer *trc, jsuword w, uint32 &thingKind) ArenaHeader *aheader = cell->arena()->header(); - if (!aheader->isUsed) - return CGCT_FREEARENA; - ConservativeGCTest test; thingKind = aheader->thingKind; diff --git a/js/src/jsgc.h b/js/src/jsgc.h index bb666e617e55..774b36837a9e 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -113,9 +113,9 @@ struct ArenaHeader { Arena *next; FreeCell *freeList; unsigned thingKind; - bool isUsed; - size_t thingSize; #ifdef DEBUG + size_t thingSize; + bool isUsed; bool hasFreeThings; #endif }; @@ -304,7 +304,9 @@ EmptyArenaLists::getNext(JSCompartment *comp, unsigned thingKind) { if (arena) { JS_ASSERT(arena->header()->isUsed == false); JS_ASSERT(arena->header()->thingSize == sizeof(T)); +#ifdef DEBUG arena->header()->isUsed = true; +#endif arena->header()->thingKind = thingKind; arena->header()->compartment = comp; return arena; @@ -433,7 +435,7 @@ Arena::getAlignedThing(void *thing) { jsuword start = reinterpret_cast(&t.things[0]); jsuword offset = reinterpret_cast(thing) - start; - offset -= offset % aheader.thingSize; + offset -= offset % sizeof(T); return reinterpret_cast(start + offset); }