Bug 373175: hiding code to set arena names behind JS_ARENAMETER. r=brendan

This commit is contained in:
igor@mir2.org 2007-04-10 06:29:10 -07:00
parent e84992e751
commit 9585daa79d
9 changed files with 55 additions and 32 deletions

View File

@ -3789,8 +3789,8 @@ CompileTokenStream(JSContext *cx, JSObject *obj, JSTokenStream *ts,
CHECK_REQUEST(cx);
eof = JS_FALSE;
JS_InitArenaPool(&codePool, "code", 1024, sizeof(jsbytecode));
JS_InitArenaPool(&notePool, "note", 1024, sizeof(jssrcnote));
JS_INIT_ARENA_POOL(&codePool, "code", 1024, sizeof(jsbytecode));
JS_INIT_ARENA_POOL(&notePool, "note", 1024, sizeof(jssrcnote));
if (!js_InitCodeGenerator(cx, &cg, &codePool, &notePool,
ts->filename, ts->lineno,
ts->principals)) {
@ -4150,9 +4150,9 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name,
JSString *str;
CHECK_REQUEST(cx);
jp = js_NewPrinter(cx, name,
indent & ~JS_DONT_PRETTY_PRINT,
!(indent & JS_DONT_PRETTY_PRINT));
jp = JS_NEW_PRINTER(cx, name,
indent & ~JS_DONT_PRETTY_PRINT,
!(indent & JS_DONT_PRETTY_PRINT));
if (!jp)
return NULL;
if (js_DecompileScript(jp, script))
@ -4170,9 +4170,9 @@ JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent)
JSString *str;
CHECK_REQUEST(cx);
jp = js_NewPrinter(cx, JS_GetFunctionName(fun),
indent & ~JS_DONT_PRETTY_PRINT,
!(indent & JS_DONT_PRETTY_PRINT));
jp = JS_NEW_PRINTER(cx, "JS_DecompileFunction",
indent & ~JS_DONT_PRETTY_PRINT,
!(indent & JS_DONT_PRETTY_PRINT));
if (!jp)
return NULL;
if (js_DecompileFunction(jp, fun))
@ -4190,9 +4190,9 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent)
JSString *str;
CHECK_REQUEST(cx);
jp = js_NewPrinter(cx, JS_GetFunctionName(fun),
indent & ~JS_DONT_PRETTY_PRINT,
!(indent & JS_DONT_PRETTY_PRINT));
jp = JS_NEW_PRINTER(cx, "JS_DecompileFunctionBody",
indent & ~JS_DONT_PRETTY_PRINT,
!(indent & JS_DONT_PRETTY_PRINT));
if (!jp)
return NULL;
if (js_DecompileFunctionBody(jp, fun))

View File

@ -61,7 +61,8 @@ static JSArenaStats *arena_stats_list;
#define JS_ARENA_DEFAULT_ALIGN sizeof(double)
JS_PUBLIC_API(void)
JS_InitArenaPool(JSArenaPool *pool, const char *name, size_t size, size_t align)
JS_INIT_NAMED_ARENA_POOL(JSArenaPool *pool, const char *name, size_t size,
size_t align)
{
if (align == 0)
align = JS_ARENA_DEFAULT_ALIGN;
@ -485,7 +486,6 @@ JS_DumpArenaStats(FILE *fp)
fprintf(fp, "\n%s allocation statistics:\n", stats->name);
fprintf(fp, " number of arenas: %u\n", stats->narenas);
fprintf(fp, " number of allocations: %u\n", stats->nallocs);
fprintf(fp, " number of free arena reclaims: %u\n", stats->nreclaims);
fprintf(fp, " number of malloc calls: %u\n", stats->nmallocs);
fprintf(fp, " number of deallocations: %u\n", stats->ndeallocs);
fprintf(fp, " number of allocation growths: %u\n", stats->ngrows);

View File

@ -93,6 +93,14 @@ struct JSArenaPool {
#endif
};
#ifdef JS_ARENAMETER
#define JS_INIT_NAMED_ARENA_POOL(pool, name, size, align) \
JS_InitArenaPool(pool, name, size, align)
#else
#define JS_INIT_NAMED_ARENA_POOL(pool, name, size, align) \
JS_InitArenaPool(pool, size, align)
#endif
/*
* If the including .c file uses only one power-of-2 alignment, it may define
* JS_ARENA_CONST_ALIGN_MASK to the alignment mask and save a few instructions
@ -102,10 +110,15 @@ struct JSArenaPool {
#define JS_ARENA_ALIGN(pool, n) (((jsuword)(n) + JS_ARENA_CONST_ALIGN_MASK) \
& ~(jsuword)JS_ARENA_CONST_ALIGN_MASK)
#define JS_INIT_ARENA_POOL(pool, name, size) \
JS_InitArenaPool(pool, name, size, JS_ARENA_CONST_ALIGN_MASK + 1)
#define JS_INIT_ARENA_POOL(pool, name, size) \
JS_INIT_NAMED_ARENA_POOL(pool, name, size, JS_ARENA_CONST_ALIGN_MASK + 1)
#else
#define JS_ARENA_ALIGN(pool, n) (((jsuword)(n) + (pool)->mask) & ~(pool)->mask)
#define JS_INIT_ARENA_POOL(pool, name, size, align) \
JS_INIT_NAMED_ARENA_POOL(pool, name, size, align)
#endif
#define JS_ARENA_ALLOCATE(p, pool, nb) \
@ -211,12 +224,13 @@ struct JSArenaPool {
JS_END_MACRO
/*
* Initialize an arena pool with the given name for debugging and metering,
* with a minimum size per arena of size bytes.
* Initialize an arena pool with a minimum size per arena of size bytes.
* Always call JS_SET_ARENA_METER_NAME before calling this or use
* JS_INIT_ARENA_POOL macro to provide a name for for debugging and metering.
*/
extern JS_PUBLIC_API(void)
JS_InitArenaPool(JSArenaPool *pool, const char *name, size_t size,
size_t align);
JS_INIT_NAMED_ARENA_POOL(JSArenaPool *pool, const char *name, size_t size,
size_t align);
/*
* Free the arenas in pool. The user may continue to allocate from pool

View File

@ -258,8 +258,8 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
* done by js_DestroyContext).
*/
cx->version = JSVERSION_DEFAULT;
JS_InitArenaPool(&cx->stackPool, "stack", stackChunkSize, sizeof(jsval));
JS_InitArenaPool(&cx->tempPool, "temp", 1024, sizeof(jsdouble));
JS_INIT_ARENA_POOL(&cx->stackPool, "stack", stackChunkSize, sizeof(jsval));
JS_INIT_ARENA_POOL(&cx->tempPool, "temp", 1024, sizeof(jsdouble));
if (!js_InitRegExpStatics(cx, &cx->regExpStatics)) {
js_DestroyContext(cx, JSDCM_NEW_FAILED);

View File

@ -613,7 +613,7 @@ struct JSPrinter {
#define JS_IN_GROUP_CONTEXT 0x10000
JSPrinter *
js_NewPrinter(JSContext *cx, const char *name, uintN indent, JSBool pretty)
JS_NEW_PRINTER(JSContext *cx, const char *name, uintN indent, JSBool pretty)
{
JSPrinter *jp;
@ -621,7 +621,7 @@ js_NewPrinter(JSContext *cx, const char *name, uintN indent, JSBool pretty)
if (!jp)
return NULL;
INIT_SPRINTER(cx, &jp->sprinter, &jp->pool, 0);
JS_InitArenaPool(&jp->pool, name, 256, 1);
JS_INIT_ARENA_POOL(&jp->pool, name, 256, 1);
jp->indent = indent & ~JS_IN_GROUP_CONTEXT;
jp->pretty = pretty;
jp->grouped = (indent & JS_IN_GROUP_CONTEXT) != 0;
@ -1956,8 +1956,8 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
do_function:
obj = ATOM_TO_OBJECT(atom);
fun = (JSFunction *) JS_GetPrivate(cx, obj);
jp2 = js_NewPrinter(cx, JS_GetFunctionName(fun),
jp->indent, jp->pretty);
jp2 = JS_NEW_PRINTER(cx, "nested_function",
jp->indent, jp->pretty);
if (!jp2)
return NULL;
jp2->scope = jp->scope;
@ -4827,7 +4827,7 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
}
name = NULL;
jp = js_NewPrinter(cx, "js_DecompileValueGenerator", 0, JS_FALSE);
jp = JS_NEW_PRINTER(cx, "js_DecompileValueGenerator", 0, JS_FALSE);
if (jp) {
if (fp->fun && fp->fun->object) {
JS_ASSERT(OBJ_IS_NATIVE(fp->fun->object));

View File

@ -255,8 +255,17 @@ js_QuoteString(JSContext *cx, JSString *str, jschar quote);
* value from js_GetPrinterOutput() is the printer's cumulative output, in
* a GC'ed string.
*/
#ifdef JS_ARENAMETER
# define JS_NEW_PRINTER(cx, name, indent, pretty) \
js_NewPrinter(cx, name, indent, pretty)
#else
# define JS_NEW_PRINTER(cx, name, indent, pretty) \
js_NewPrinter(cx, indent, pretty)
#endif
extern JSPrinter *
js_NewPrinter(JSContext *cx, const char *name, uintN indent, JSBool pretty);
JS_NEW_PRINTER(JSContext *cx, const char *name, uintN indent, JSBool pretty);
extern void
js_DestroyPrinter(JSPrinter *jp);

View File

@ -782,8 +782,8 @@ js_CompileFunctionBody(JSContext *cx, JSTokenStream *ts, JSFunction *fun)
JSObject *funobj;
JSParseNode *pn;
JS_InitArenaPool(&codePool, "code", 1024, sizeof(jsbytecode));
JS_InitArenaPool(&notePool, "note", 1024, sizeof(jssrcnote));
JS_INIT_ARENA_POOL(&codePool, "code", 1024, sizeof(jsbytecode));
JS_INIT_ARENA_POOL(&notePool, "note", 1024, sizeof(jssrcnote));
if (!js_InitCodeGenerator(cx, &funcg, &codePool, &notePool,
ts->filename, ts->lineno,
ts->principals)) {

View File

@ -3361,7 +3361,7 @@ js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
gData.start = start;
gData.skipped = 0;
JS_InitArenaPool(&gData.pool, "RegExpPool", 8096, 4);
JS_INIT_ARENA_POOL(&gData.pool, "RegExpPool", 8096, 4);
x = InitMatch(cx, &gData, re, length);
if (!x) {

View File

@ -1876,8 +1876,8 @@ js_InitPropertyTree(JSRuntime *rt)
rt->propertyTreeHash.ops = NULL;
return JS_FALSE;
}
JS_InitArenaPool(&rt->propertyArenaPool, "properties",
256 * sizeof(JSScopeProperty), sizeof(void *));
JS_INIT_ARENA_POOL(&rt->propertyArenaPool, "properties",
256 * sizeof(JSScopeProperty), sizeof(void *));
return JS_TRUE;
}