Bug 572057 - TM: remove weak roots (pigeon hole) r=igor

This commit is contained in:
Gregor Wagner 2010-08-18 12:46:47 -07:00
Родитель 216951068a
Коммит 92dbea21cf
10 изменённых файлов: 21 добавлений и 136 удалений

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

@ -1974,12 +1974,6 @@ JS_RemoveGCThingRoot(JSContext *cx, void **rp)
return js_RemoveRoot(cx->runtime, (void *)rp);
}
JS_PUBLIC_API(void)
JS_ClearNewbornRoots(JSContext *cx)
{
JS_CLEAR_WEAK_ROOTS(&cx->weakRoots);
}
#ifdef DEBUG
JS_PUBLIC_API(void)
@ -4398,7 +4392,6 @@ inline static void
LAST_FRAME_CHECKS(JSContext *cx, bool result)
{
if (!JS_IsRunning(cx)) {
cx->weakRoots.lastInternalResult = NULL;
LAST_FRAME_EXCEPTION_CHECK(cx, result);
}
}
@ -4623,18 +4616,18 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
argAtom = js_Atomize(cx, argnames[i], strlen(argnames[i]), 0);
if (!argAtom) {
fun = NULL;
goto out;
goto out2;
}
if (!js_AddLocal(cx, fun, argAtom, JSLOCAL_ARG)) {
fun = NULL;
goto out;
goto out2;
}
}
if (!Compiler::compileFunctionBody(cx, fun, principals,
chars, length, filename, lineno)) {
fun = NULL;
goto out;
goto out2;
}
if (obj && funAtom &&
@ -4653,9 +4646,6 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
JS_BASIC_STATS_ACCUM(&cx->runtime->hostenvScopeDepthStats, depth);
}
#endif
out:
cx->weakRoots.finalizableNewborns[FINALIZE_FUNCTION] = fun;
}
out2:

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

@ -1179,10 +1179,8 @@ js_RemoveRoot(JSRuntime *rt, void *rp);
*/
#define JS_TYPED_ROOTING_API
extern JS_PUBLIC_API(void)
JS_ClearNewbornRoots(JSContext *cx);
/* Obsolete rooting APIs. */
#define JS_ClearNewbornRoots(cx) ((void) 0)
#define JS_EnterLocalRootScope(cx) (JS_TRUE)
#define JS_LeaveLocalRootScope(cx) ((void) 0)
#define JS_LeaveLocalRootScopeWithResult(cx, rval) ((void) 0)

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

@ -3050,12 +3050,7 @@ js_NewArrayObject(JSContext *cx, jsuint length, const Value *vector)
*/
JS_ASSERT(obj->getProto());
if (!InitArrayObject(cx, obj, length, vector))
obj = NULL;
/* Set/clear newborn root, in case we lost it. */
cx->weakRoots.finalizableNewborns[FINALIZE_OBJECT] = obj;
return obj;
return InitArrayObject(cx, obj, length, vector) ? obj : NULL;
}
JSObject *

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

@ -554,7 +554,6 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
JS_ASSERT(key->isAtomized());
JSAtom *atom = STRING_TO_ATOM(key);
cx->weakRoots.lastAtom = atom;
JS_UNLOCK(cx, &state->lock);
return atom;
}

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

@ -62,7 +62,7 @@ js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp)
if (v.isString()) {
str = v.toString();
if (str->isAtomized()) {
cx->weakRoots.lastAtom = *atomp = STRING_TO_ATOM(str);
*atomp = STRING_TO_ATOM(str);
return true;
}
} else {

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

@ -1921,9 +1921,6 @@ struct JSContext
/* Top-level object and pointer to top stack frame's scope chain. */
JSObject *globalObject;
/* Storage to root recently allocated GC things and script result. */
JSWeakRoots weakRoots;
/* Regular expression class statics. */
js::RegExpStatics regExpStatics;
@ -2411,20 +2408,19 @@ class AutoGCRooter {
enum {
JSVAL = -1, /* js::AutoValueRooter */
SPROP = -2, /* js::AutoScopePropertyRooter */
WEAKROOTS = -3, /* js::AutoSaveWeakRoots */
PARSER = -4, /* js::Parser */
SCRIPT = -5, /* js::AutoScriptRooter */
ENUMERATOR = -6, /* js::AutoEnumStateRooter */
IDARRAY = -7, /* js::AutoIdArray */
DESCRIPTORS = -8, /* js::AutoPropDescArrayRooter */
NAMESPACES = -9, /* js::AutoNamespaceArray */
XML = -10, /* js::AutoXMLRooter */
OBJECT = -11, /* js::AutoObjectRooter */
ID = -12, /* js::AutoIdRooter */
VALVECTOR = -13, /* js::AutoValueVector */
DESCRIPTOR = -14, /* js::AutoPropertyDescriptorRooter */
STRING = -15, /* js::AutoStringRooter */
IDVECTOR = -16 /* js::AutoIdVector */
PARSER = -3, /* js::Parser */
SCRIPT = -4, /* js::AutoScriptRooter */
ENUMERATOR = -5, /* js::AutoEnumStateRooter */
IDARRAY = -6, /* js::AutoIdArray */
DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */
NAMESPACES = -8, /* js::AutoNamespaceArray */
XML = -9, /* js::AutoXMLRooter */
OBJECT = -10, /* js::AutoObjectRooter */
ID = -11, /* js::AutoIdRooter */
VALVECTOR = -12, /* js::AutoValueVector */
DESCRIPTOR = -13, /* js::AutoPropertyDescriptorRooter */
STRING = -14, /* js::AutoStringRooter */
IDVECTOR = -15 /* js::AutoIdVector */
};
private:
@ -2433,28 +2429,6 @@ class AutoGCRooter {
void operator=(AutoGCRooter &ida);
};
class AutoPreserveWeakRoots : private AutoGCRooter
{
public:
explicit AutoPreserveWeakRoots(JSContext *cx
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: AutoGCRooter(cx, WEAKROOTS), savedRoots(cx->weakRoots)
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}
~AutoPreserveWeakRoots()
{
context->weakRoots = savedRoots;
}
friend void AutoGCRooter::trace(JSTracer *trc);
private:
JSWeakRoots savedRoots;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/* FIXME(bug 332648): Move this into a public header. */
class AutoValueRooter : private AutoGCRooter
{

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

@ -1596,7 +1596,6 @@ LastDitchGC(JSContext *cx)
JS_ASSERT(!JS_ON_TRACE(cx));
/* The last ditch GC preserves weak roots and all atoms. */
AutoPreserveWeakRoots save(cx);
AutoKeepAtoms keep(cx->runtime);
/*
@ -1710,7 +1709,6 @@ js_NewFinalizableGCThing(JSContext *cx, unsigned thingKind)
JSGCThing *thing = *freeListp;
if (thing) {
*freeListp = thing->link;
cx->weakRoots.finalizableNewborns[thingKind] = thing;
CheckGCFreeListLink(thing);
METER(cx->runtime->gcStats.arenaStats[thingKind].localalloc++);
return thing;
@ -1731,8 +1729,6 @@ js_NewFinalizableGCThing(JSContext *cx, unsigned thingKind)
CheckGCFreeListLink(thing);
cx->weakRoots.finalizableNewborns[thingKind] = thing;
return thing;
}
@ -2253,40 +2249,6 @@ js_TraceStackFrame(JSTracer *trc, JSStackFrame *fp)
JS_CALL_OBJECT_TRACER(trc, fp->getScopeChain(), "scope chain");
}
void
JSWeakRoots::mark(JSTracer *trc)
{
#ifdef DEBUG
const char * const newbornNames[] = {
"newborn_object", /* FINALIZE_OBJECT */
"newborn_function", /* FINALIZE_FUNCTION */
#if JS_HAS_XML_SUPPORT
"newborn_xml", /* FINALIZE_XML */
#endif
"newborn_short_string", /* FINALIZE_SHORT_STRING */
"newborn_string", /* FINALIZE_STRING */
"newborn_external_string0", /* FINALIZE_EXTERNAL_STRING0 */
"newborn_external_string1", /* FINALIZE_EXTERNAL_STRING1 */
"newborn_external_string2", /* FINALIZE_EXTERNAL_STRING2 */
"newborn_external_string3", /* FINALIZE_EXTERNAL_STRING3 */
"newborn_external_string4", /* FINALIZE_EXTERNAL_STRING4 */
"newborn_external_string5", /* FINALIZE_EXTERNAL_STRING5 */
"newborn_external_string6", /* FINALIZE_EXTERNAL_STRING6 */
"newborn_external_string7", /* FINALIZE_EXTERNAL_STRING7 */
};
#endif
for (size_t i = 0; i != JS_ARRAY_LENGTH(finalizableNewborns); ++i) {
void *newborn = finalizableNewborns[i];
if (newborn) {
JS_CALL_TRACER(trc, newborn, GetFinalizableTraceKind(i),
newbornNames[i]);
}
}
if (lastAtom)
MarkString(trc, ATOM_TO_STRING(lastAtom), "lastAtom");
MarkGCThing(trc, lastInternalResult, "lastInternalResult");
}
inline void
AutoGCRooter::trace(JSTracer *trc)
{
@ -2299,10 +2261,6 @@ AutoGCRooter::trace(JSTracer *trc)
static_cast<AutoScopePropertyRooter *>(this)->sprop->trace(trc);
return;
case WEAKROOTS:
static_cast<AutoPreserveWeakRoots *>(this)->savedRoots.mark(trc);
return;
case PARSER:
static_cast<Parser *>(this)->trace(trc);
return;
@ -2399,7 +2357,6 @@ js_TraceContext(JSTracer *trc, JSContext *acx)
/* Mark other roots-by-definition in acx. */
if (acx->globalObject && !JS_HAS_OPTION(acx, JSOPTION_UNROOTED_GLOBAL))
JS_CALL_OBJECT_TRACER(trc, acx->globalObject, "global object");
acx->weakRoots.mark(trc);
if (acx->throwing) {
MarkValue(trc, acx->exception, "exception");
} else {
@ -3028,8 +2985,6 @@ PreGCCleanup(JSContext *cx, JSGCInvocationKind gckind)
while (JSContext *acx = js_ContextIterator(rt, JS_TRUE, &iter))
acx->purge();
}
JS_CLEAR_WEAK_ROOTS(&cx->weakRoots);
}
/*

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

@ -347,21 +347,6 @@ struct JSGCFreeLists {
extern void
js_DestroyScriptsToGC(JSContext *cx, JSThreadData *data);
struct JSWeakRoots {
/* Most recently created things by type, members of the GC's root set. */
void *finalizableNewborns[FINALIZE_LIMIT];
/* Atom root for the last-looked-up atom on this context. */
JSAtom *lastAtom;
/* Root for the result of the most recent js_InternalInvoke call. */
void *lastInternalResult;
void mark(JSTracer *trc);
};
#define JS_CLEAR_WEAK_ROOTS(wr) (memset((wr), 0, sizeof(JSWeakRoots)))
namespace js {
#ifdef JS_THREADSAFE

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

@ -739,15 +739,7 @@ InternalInvoke(JSContext *cx, const Value &thisv, const Value &fval, uintN flags
if (!Invoke(cx, args, flags))
return JS_FALSE;
/*
* Store *rval in the lastInternalResult pigeon-hole GC root, solely
* so users of js_InternalInvoke and its direct and indirect
* (js_ValueToString for example) callers do not need to manage roots
* for local, temporary references to such results.
*/
*rval = args.rval();
if (rval->isMarkable())
cx->weakRoots.lastInternalResult = rval->asGCThing();
return JS_TRUE;
}
@ -5947,11 +5939,9 @@ END_CASE(JSOP_NEWINIT)
BEGIN_CASE(JSOP_ENDINIT)
{
/* Re-set the newborn root to the top of this object tree. */
/* FIXME remove JSOP_ENDINIT bug 588522 */
JS_ASSERT(regs.sp - fp->base() >= 1);
const Value &lref = regs.sp[-1];
JS_ASSERT(lref.isObject());
cx->weakRoots.finalizableNewborns[FINALIZE_OBJECT] = &lref.toObject();
JS_ASSERT(regs.sp[-1].isObject());
}
END_CASE(JSOP_ENDINIT)

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

@ -103,7 +103,6 @@ typedef struct JSThread JSThread;
typedef struct JSThreadData JSThreadData;
typedef struct JSTreeContext JSTreeContext;
typedef struct JSTryNote JSTryNote;
typedef struct JSWeakRoots JSWeakRoots;
/* Friend "Advanced API" typedefs. */
typedef struct JSAtom JSAtom;