Finish separating gcMaxMallocBytes, account for scope hashtables in gcMallocBytes (319980, r/sr=mrbkap/bz).

This commit is contained in:
brendan%mozilla.org 2006-03-02 20:47:04 +00:00
Родитель 85822474d2
Коммит 9875e92b3a
2 изменённых файлов: 15 добавлений и 10 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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);