Bug 408113: allocate stackPools less often, r=brendan, a=blocking1.9 (schrep)

This commit is contained in:
crowder@fiverocks.com 2008-01-29 18:11:30 -08:00
parent 5d1a7870b7
commit fa431d439a
5 changed files with 39 additions and 2 deletions

View File

@ -2500,6 +2500,9 @@ JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value)
case JSGC_MAX_MALLOC_BYTES:
rt->gcMaxMallocBytes = value;
break;
case JSGC_STACKPOOL_LIFESPAN:
rt->gcStackPoolLifespan = value;
break;
}
}

View File

@ -1101,8 +1101,14 @@ extern JS_PUBLIC_API(JSBool)
JS_IsAboutToBeFinalized(JSContext *cx, void *thing);
typedef enum JSGCParamKey {
JSGC_MAX_BYTES = 0, /* maximum nominal heap before last ditch GC */
JSGC_MAX_MALLOC_BYTES = 1 /* # of JS_malloc bytes before last ditch GC */
/* Maximum nominal heap before last ditch GC. */
JSGC_MAX_BYTES = 0,
/* Number of JS_malloc bytes before last ditch GC. */
JSGC_MAX_MALLOC_BYTES = 1,
/* Hoard stackPools for this long, in ms, default is 30 seconds. */
JSGC_STACKPOOL_LIFESPAN = 2
} JSGCParamKey;
extern JS_PUBLIC_API(void)

View File

@ -180,6 +180,7 @@ struct JSRuntime {
uint32 gcLastBytes;
uint32 gcMaxBytes;
uint32 gcMaxMallocBytes;
uint32 gcStackPoolLifespan;
uint32 gcLevel;
uint32 gcNumber;
JSTracer *gcMarkingTracer;

View File

@ -902,6 +902,7 @@ js_InitGC(JSRuntime *rt, uint32 maxbytes)
* for default backward API compatibility.
*/
rt->gcMaxBytes = rt->gcMaxMallocBytes = maxbytes;
rt->gcStackPoolLifespan = 30000;
METER(memset(&rt->gcStats, 0, sizeof rt->gcStats));
return JS_TRUE;
@ -2199,10 +2200,24 @@ TraceWeakRoots(JSTracer *trc, JSWeakRoots *wr)
JS_FRIEND_API(void)
js_TraceContext(JSTracer *trc, JSContext *acx)
{
JSArena *a;
int64 *timestamp;
JSStackFrame *fp, *nextChain;
JSStackHeader *sh;
JSTempValueRooter *tvr;
/*
* Release stackPool here, if it has been in existence for longer
* than the limit specified by gcStackPoolLifespan.
*/
a = acx->stackPool.current;
if (a == acx->stackPool.first.next &&
a->avail == a->base + sizeof(int64)) {
timestamp = (int64 *) a->base;
if (JS_Now() - *timestamp > acx->runtime->gcStackPoolLifespan * 1000)
JS_FinishArenaPool(&acx->stackPool);
}
/*
* Iterate frame chain and dormant chains.
*

View File

@ -296,6 +296,18 @@ js_AllocRawStack(JSContext *cx, uintN nslots, void **markp)
{
jsval *sp;
if (!cx->stackPool.first.next) {
int64 *timestamp;
JS_ARENA_ALLOCATE(timestamp, &cx->stackPool, sizeof(*timestamp));
if (!timestamp) {
js_ReportOutOfScriptQuota(cx);
return NULL;
}
*timestamp = JS_Now();
}
if (markp)
*markp = JS_ARENA_MARK(&cx->stackPool);
JS_ARENA_ALLOCATE_CAST(sp, jsval *, &cx->stackPool, nslots * sizeof(jsval));