Bug 778993 - Separate runtime's gcMallocBytes from compartment's gcMallocBytes Bug 778993 - Separate runtime's gcMallocBytes from compartment's gcMallocBytes (r=gwagner)

This commit is contained in:
Bill McCloskey 2012-07-31 18:33:29 -07:00
parent ee625140f8
commit 2f97ce9b6a
2 changed files with 9 additions and 8 deletions

View File

@ -1161,14 +1161,15 @@ JSRuntime::setGCMaxMallocBytes(size_t value)
void
JSRuntime::updateMallocCounter(JSContext *cx, size_t nbytes)
{
/* We tolerate any thread races when updating gcMallocBytes. */
ptrdiff_t oldCount = gcMallocBytes;
ptrdiff_t newCount = oldCount - ptrdiff_t(nbytes);
gcMallocBytes = newCount;
if (JS_UNLIKELY(newCount <= 0 && oldCount > 0))
onTooMuchMalloc();
else if (cx && cx->compartment)
if (cx && cx->compartment) {
cx->compartment->updateMallocCounter(nbytes);
} else {
ptrdiff_t oldCount = gcMallocBytes;
ptrdiff_t newCount = oldCount - ptrdiff_t(nbytes);
gcMallocBytes = newCount;
if (JS_UNLIKELY(newCount <= 0 && oldCount > 0))
onTooMuchMalloc();
}
}
JS_FRIEND_API(void)

View File

@ -70,7 +70,7 @@ JSCompartment::JSCompartment(JSRuntime *rt)
sourceMapMap(NULL),
debugScriptMap(NULL)
{
setGCMaxMallocBytes(rt->gcMaxMallocBytes * 0.9);
setGCMaxMallocBytes(rt->gcMaxMallocBytes);
}
JSCompartment::~JSCompartment()