Avoid integer math for GC trigger factor calculation in allocation path (503463, r=dmandelin).

This commit is contained in:
Andreas Gal 2009-07-13 13:24:25 -07:00
parent b9dc1bb9d6
commit 0c6942b658
3 changed files with 29 additions and 9 deletions

View File

@ -2583,7 +2583,7 @@ JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value)
default:
JS_ASSERT(key == JSGC_TRIGGER_FACTOR);
JS_ASSERT(value >= 100);
rt->gcTriggerFactor = value;
rt->SetGCTriggerFactor(value);
return;
}
}

View File

@ -369,15 +369,16 @@ struct JSRuntime {
JSDHashTable gcRootsHash;
JSDHashTable *gcLocksHash;
jsrefcount gcKeepAtoms;
uint32 gcBytes;
uint32 gcLastBytes;
uint32 gcMaxBytes;
uint32 gcMaxMallocBytes;
size_t gcBytes;
size_t gcLastBytes;
size_t gcMaxBytes;
size_t gcMaxMallocBytes;
uint32 gcEmptyArenaPoolLifespan;
uint32 gcLevel;
uint32 gcNumber;
JSTracer *gcMarkingTracer;
uint32 gcTriggerFactor;
size_t gcTriggerBytes;
volatile JSBool gcIsNeeded;
/*
@ -682,6 +683,9 @@ struct JSRuntime {
JSFunctionMeter functionMeter;
char lastScriptFilename[1024];
#endif
void SetGCTriggerFactor(uint32 factor);
void SetGCLastBytes(size_t lastBytes);
};
/* Common macros to access thread-local caches in JSThread or JSRuntime. */

View File

@ -1304,13 +1304,13 @@ js_InitGC(JSRuntime *rt, uint32 maxbytes)
* By default the trigger factor gets maximum possible value. This
* means that GC will not be triggered by growth of GC memory (gcBytes).
*/
rt->gcTriggerFactor = (uint32) -1;
rt->SetGCTriggerFactor((uint32) -1);
/*
* The assigned value prevents GC from running when GC memory is too low
* (during JS engine start).
*/
rt->gcLastBytes = 8192;
rt->SetGCLastBytes(8192);
METER(memset(&rt->gcStats, 0, sizeof rt->gcStats));
return JS_TRUE;
@ -1796,6 +1796,22 @@ EnsureLocalFreeList(JSContext *cx)
#endif
void
JSRuntime::SetGCTriggerFactor(uint32 factor)
{
JS_ASSERT(factor >= 100);
gcTriggerFactor = factor;
SetGCLastBytes(gcLastBytes);
}
void
JSRuntime::SetGCLastBytes(size_t lastBytes)
{
gcLastBytes = lastBytes;
gcTriggerBytes = lastBytes * gcTriggerFactor / 100;
}
static JS_INLINE bool
IsGCThresholdReached(JSRuntime *rt)
{
@ -1810,7 +1826,7 @@ IsGCThresholdReached(JSRuntime *rt)
* the gcBytes value is close to zero at the JS engine start.
*/
return rt->gcMallocBytes >= rt->gcMaxMallocBytes ||
rt->gcBytes / rt->gcTriggerFactor >= rt->gcLastBytes / 100;
rt->gcBytes >= rt->gcTriggerBytes;
}
void *
@ -3842,7 +3858,7 @@ out:
goto restart;
}
rt->gcLastBytes = rt->gcBytes;
rt->SetGCLastBytes(rt->gcBytes);
done_running:
rt->gcLevel = 0;
rt->gcRunning = JS_FALSE;