From 9875e92b3abb0f92416f79ad6c9c34a9867c9a2b Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Thu, 2 Mar 2006 20:47:04 +0000 Subject: [PATCH] Finish separating gcMaxMallocBytes, account for scope hashtables in gcMallocBytes (319980, r/sr=mrbkap/bz). --- js/src/jsapi.c | 2 +- js/src/jsscope.c | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/js/src/jsapi.c b/js/src/jsapi.c index b932d108e66f..da3ffc1435ea 100644 --- a/js/src/jsapi.c +++ b/js/src/jsapi.c @@ -1855,7 +1855,7 @@ JS_MaybeGC(JSContext *cx) bytes = rt->gcBytes; lastBytes = rt->gcLastBytes; if ((bytes > 8192 && bytes > lastBytes + lastBytes / 2) || - rt->gcMallocBytes > rt->gcMaxBytes) { + rt->gcMallocBytes > rt->gcMaxMallocBytes) { /* * Run the GC if we have half again as many bytes of GC-things as * the last time we GC'd, or if we have malloc'd more bytes through diff --git a/js/src/jsscope.c b/js/src/jsscope.c index ed6525f5ec21..dd6d50ed43de 100644 --- a/js/src/jsscope.c +++ b/js/src/jsscope.c @@ -98,7 +98,7 @@ InitMinimalScope(JSScope *scope) } static JSBool -CreateScopeTable(JSScope *scope) +CreateScopeTable(JSContext *cx, JSScope *scope, JSBool report) { int sizeLog2; JSScopeProperty *sprop, **spp; @@ -120,8 +120,14 @@ CreateScopeTable(JSScope *scope) scope->table = (JSScopeProperty **) calloc(JS_BIT(sizeLog2), sizeof(JSScopeProperty *)); - if (!scope->table) + if (!scope->table) { + if (report) + JS_ReportOutOfMemory(cx); return JS_FALSE; + } + + /* Racy update after calloc, to help keep the GC self-scheduled well. */ + cx->runtime->gcMallocBytes += JS_BIT(sizeLog2) * sizeof(JSScopeProperty *); scope->hashShift = JS_DHASH_BITS - sizeLog2; for (sprop = scope->lastProp; sprop; sprop = sprop->parent) { @@ -348,6 +354,9 @@ ChangeScope(JSContext *cx, JSScope *scope, int change) oldtable = scope->table; scope->table = table; + /* Treat the above calloc as a JS_malloc, to match CreateScopeTable. */ + cx->runtime->gcMallocBytes += nbytes; + /* Copy only live entries, leaving removed and free ones behind. */ for (oldspp = oldtable; oldsize != 0; oldspp++) { sprop = SPROP_FETCH(oldspp); @@ -968,10 +977,8 @@ js_AddScopeProperty(JSContext *cx, JSScope *scope, jsid id, * delete code is simple-minded that way! */ if (!scope->table) { - if (!CreateScopeTable(scope)) { - JS_ReportOutOfMemory(cx); + if (!CreateScopeTable(cx, scope, JS_TRUE)) return NULL; - } spp = js_SearchScope(scope, id, JS_TRUE); sprop = overwriting = SPROP_FETCH(spp); } @@ -1167,7 +1174,7 @@ js_AddScopeProperty(JSContext *cx, JSScope *scope, jsid id, * entry count just reached the threshold. */ if (!scope->table && scope->entryCount >= SCOPE_HASH_THRESHOLD) - (void) CreateScopeTable(scope); + (void) CreateScopeTable(cx, scope, JS_FALSE); } METER(adds); @@ -1309,10 +1316,8 @@ js_RemoveScopeProperty(JSContext *cx, JSScope *scope, jsid id) /* Convert from a list to a hash so we can handle "middle deletes". */ if (!scope->table && sprop != scope->lastProp) { - if (!CreateScopeTable(scope)) { - JS_ReportOutOfMemory(cx); + if (!CreateScopeTable(cx, scope, JS_TRUE)) return JS_FALSE; - } spp = js_SearchScope(scope, id, JS_FALSE); stored = *spp; sprop = SPROP_CLEAR_COLLISION(stored);