mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 21:35:39 +00:00
bug 467441 - avoiding js_(Add|Remove)Root for regexp statics. r=crowder
This commit is contained in:
parent
5715a47f60
commit
3886ed2912
@ -295,21 +295,7 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
|
||||
1024, /* FIXME: bug 421435 */
|
||||
sizeof(jsdouble), &cx->scriptStackQuota);
|
||||
|
||||
/*
|
||||
* To avoid multiple allocations in InitMatch() (in jsregexp.c), the arena
|
||||
* size parameter should be at least as big as:
|
||||
* INITIAL_BACKTRACK
|
||||
* + (sizeof(REProgState) * INITIAL_STATESTACK)
|
||||
* + (offsetof(REMatchState, parens) + avgParanSize * sizeof(RECapture))
|
||||
*/
|
||||
JS_INIT_ARENA_POOL(&cx->regexpPool, "regexp",
|
||||
12 * 1024 - 40, /* FIXME: bug 421435 */
|
||||
sizeof(void *), &cx->scriptStackQuota);
|
||||
|
||||
if (!js_InitRegExpStatics(cx, &cx->regExpStatics)) {
|
||||
js_DestroyContext(cx, JSDCM_NEW_FAILED);
|
||||
return NULL;
|
||||
}
|
||||
js_InitRegExpStatics(cx);
|
||||
|
||||
cx->resolveFlags = 0;
|
||||
|
||||
@ -428,13 +414,8 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
|
||||
JS_ClearAllWatchPoints(cx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove more GC roots in regExpStatics, then collect garbage.
|
||||
* XXX anti-modularity alert: we rely on the call to js_RemoveRoot within
|
||||
* XXX this function call to wait for any racing GC to complete, in the
|
||||
* XXX case where JS_DestroyContext is called outside of a request on cx
|
||||
*/
|
||||
js_FreeRegExpStatics(cx, &cx->regExpStatics);
|
||||
/* Remove more GC roots in regExpStatics, then collect garbage. */
|
||||
JS_ClearRegExpRoots(cx);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
/*
|
||||
@ -475,9 +456,9 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
|
||||
}
|
||||
|
||||
/* Free the stuff hanging off of cx. */
|
||||
js_FreeRegExpStatics(cx);
|
||||
JS_FinishArenaPool(&cx->stackPool);
|
||||
JS_FinishArenaPool(&cx->tempPool);
|
||||
JS_FinishArenaPool(&cx->regexpPool);
|
||||
|
||||
if (cx->lastMessage)
|
||||
free(cx->lastMessage);
|
||||
|
@ -3002,6 +3002,8 @@ js_TraceContext(JSTracer *trc, JSContext *acx)
|
||||
|
||||
if (acx->sharpObjectMap.depth > 0)
|
||||
js_TraceSharpMap(trc, &acx->sharpObjectMap);
|
||||
|
||||
js_TraceRegExpStatics(trc, acx);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -4249,21 +4249,42 @@ enum regexp_static_tinyid {
|
||||
REGEXP_STATIC_RIGHT_CONTEXT = -6
|
||||
};
|
||||
|
||||
JSBool
|
||||
js_InitRegExpStatics(JSContext *cx, JSRegExpStatics *res)
|
||||
void
|
||||
js_InitRegExpStatics(JSContext *cx)
|
||||
{
|
||||
/*
|
||||
* To avoid multiple allocations in InitMatch(), the arena size parameter
|
||||
* should be at least as big as:
|
||||
* INITIAL_BACKTRACK
|
||||
* + (sizeof(REProgState) * INITIAL_STATESTACK)
|
||||
* + (offsetof(REMatchState, parens) + avgParanSize * sizeof(RECapture))
|
||||
*/
|
||||
JS_INIT_ARENA_POOL(&cx->regexpPool, "regexp",
|
||||
12 * 1024 - 40, /* FIXME: bug 421435 */
|
||||
sizeof(void *), &cx->scriptStackQuota);
|
||||
|
||||
JS_ClearRegExpStatics(cx);
|
||||
return js_AddRoot(cx, &res->input, "res->input");
|
||||
}
|
||||
|
||||
void
|
||||
js_FreeRegExpStatics(JSContext *cx, JSRegExpStatics *res)
|
||||
js_TraceRegExpStatics(JSTracer *trc, JSContext *acx)
|
||||
{
|
||||
JSRegExpStatics *res = &acx->regExpStatics;
|
||||
|
||||
if (res->input)
|
||||
JS_CALL_STRING_TRACER(trc, res->input, "res->input");
|
||||
}
|
||||
|
||||
void
|
||||
js_FreeRegExpStatics(JSContext *cx)
|
||||
{
|
||||
JSRegExpStatics *res = &cx->regExpStatics;
|
||||
|
||||
if (res->moreParens) {
|
||||
JS_free(cx, res->moreParens);
|
||||
res->moreParens = NULL;
|
||||
}
|
||||
js_RemoveRoot(cx->runtime, &res->input);
|
||||
JS_FinishArenaPool(&cx->regexpPool);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
|
@ -131,15 +131,14 @@ extern JSBool
|
||||
js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
|
||||
JSBool test, jsval *rval);
|
||||
|
||||
/*
|
||||
* These two add and remove GC roots, respectively, so their calls must be
|
||||
* well-ordered.
|
||||
*/
|
||||
extern JSBool
|
||||
js_InitRegExpStatics(JSContext *cx, JSRegExpStatics *res);
|
||||
extern void
|
||||
js_InitRegExpStatics(JSContext *cx);
|
||||
|
||||
extern void
|
||||
js_FreeRegExpStatics(JSContext *cx, JSRegExpStatics *res);
|
||||
js_TraceRegExpStatics(JSTracer *trc, JSContext *acx);
|
||||
|
||||
extern void
|
||||
js_FreeRegExpStatics(JSContext *cx);
|
||||
|
||||
#define VALUE_IS_REGEXP(cx, v) \
|
||||
(JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \
|
||||
|
Loading…
Reference in New Issue
Block a user