mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 13:57:32 +00:00
Backed out changeset e7436725f170 due to crashes in mochitest and elsewhere. a=backout
This commit is contained in:
parent
42d93b99ed
commit
b19d6a671f
@ -987,7 +987,7 @@ xpc_CreateGlobalObject(JSContext *cx, JSClass *clasp,
|
||||
xpc::PtrAndPrincipalHashKey *priv_key =
|
||||
new xpc::PtrAndPrincipalHashKey(ptr, uri);
|
||||
xpc::CompartmentPrivate *priv =
|
||||
new xpc::CompartmentPrivate(priv_key, wantXrays, NS_IsMainThread());
|
||||
new xpc::CompartmentPrivate(priv_key, wantXrays);
|
||||
if(!CreateNewCompartment(cx, clasp, principal, priv,
|
||||
global, compartment))
|
||||
{
|
||||
@ -1024,7 +1024,7 @@ xpc_CreateMTGlobalObject(JSContext *cx, JSClass *clasp,
|
||||
// threadsafety assumptions.
|
||||
nsCOMPtr<nsIPrincipal> principal(do_QueryInterface(ptr));
|
||||
xpc::CompartmentPrivate *priv =
|
||||
new xpc::CompartmentPrivate(ptr, false, NS_IsMainThread());
|
||||
new xpc::CompartmentPrivate(ptr, false);
|
||||
if(!CreateNewCompartment(cx, clasp, principal, priv, global,
|
||||
compartment))
|
||||
{
|
||||
|
@ -408,45 +408,16 @@ void XPCJSRuntime::TraceXPConnectRoots(JSTracer *trc)
|
||||
JS_DHashTableEnumerate(&mJSHolders, TraceJSHolder, trc);
|
||||
}
|
||||
|
||||
struct Closure
|
||||
{
|
||||
JSContext *cx;
|
||||
bool cycleCollectionEnabled;
|
||||
nsCycleCollectionTraversalCallback *cb;
|
||||
};
|
||||
|
||||
static void
|
||||
CheckParticipatesInCycleCollection(PRUint32 aLangID, void *aThing, void *aClosure)
|
||||
{
|
||||
Closure *closure = static_cast<Closure*>(aClosure);
|
||||
|
||||
if(aLangID == nsIProgrammingLanguage::JAVASCRIPT && closure->cycleCollectionEnabled)
|
||||
{
|
||||
uint32 kind = js_GetGCThingTraceKind(aThing);
|
||||
if(kind == JSTRACE_OBJECT)
|
||||
closure->cycleCollectionEnabled =
|
||||
xpc::ParticipatesInCycleCollection(closure->cx, static_cast<JSObject*>(aThing));
|
||||
else if(kind == JSTRACE_STRING)
|
||||
closure->cycleCollectionEnabled =
|
||||
xpc::ParticipatesInCycleCollection(closure->cx,
|
||||
static_cast<JSString*>(aThing)->asCell());
|
||||
}
|
||||
}
|
||||
|
||||
static JSDHashOperator
|
||||
NoteJSHolder(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 number,
|
||||
void *arg)
|
||||
{
|
||||
ObjectHolder* entry = reinterpret_cast<ObjectHolder*>(hdr);
|
||||
Closure *closure = static_cast<Closure*>(arg);
|
||||
|
||||
closure->cycleCollectionEnabled = PR_TRUE;
|
||||
entry->tracer->Trace(entry->holder, CheckParticipatesInCycleCollection, closure);
|
||||
if(!closure->cycleCollectionEnabled)
|
||||
return JS_DHASH_NEXT;
|
||||
|
||||
closure->cb->NoteRoot(nsIProgrammingLanguage::CPLUSPLUS, entry->holder,
|
||||
entry->tracer);
|
||||
nsCycleCollectionTraversalCallback* cb =
|
||||
static_cast<nsCycleCollectionTraversalCallback*>(arg);
|
||||
cb->NoteRoot(nsIProgrammingLanguage::CPLUSPLUS, entry->holder,
|
||||
entry->tracer);
|
||||
|
||||
return JS_DHASH_NEXT;
|
||||
}
|
||||
@ -476,8 +447,6 @@ void XPCJSRuntime::AddXPConnectRoots(JSContext* cx,
|
||||
nsXPConnect::JSContextParticipant());
|
||||
}
|
||||
|
||||
AutoLockJSGC lock(cx->runtime);
|
||||
|
||||
XPCWrappedNativeScope::SuspectAllWrappers(this, cx, cb);
|
||||
|
||||
for(XPCRootSetElem *e = mVariantRoots; e ; e = e->GetNextRoot())
|
||||
@ -485,22 +454,12 @@ void XPCJSRuntime::AddXPConnectRoots(JSContext* cx,
|
||||
|
||||
for(XPCRootSetElem *e = mWrappedJSRoots; e ; e = e->GetNextRoot())
|
||||
{
|
||||
nsXPCWrappedJS *wrappedJS = static_cast<nsXPCWrappedJS*>(e);
|
||||
JSObject *obj = wrappedJS->GetJSObject();
|
||||
|
||||
// Only suspect wrappedJSObjects that are in a compartment that
|
||||
// participates in cycle collection.
|
||||
if(!xpc::ParticipatesInCycleCollection(cx, obj))
|
||||
continue;
|
||||
|
||||
cb.NoteXPCOMRoot(static_cast<nsIXPConnectWrappedJS *>(wrappedJS));
|
||||
nsIXPConnectWrappedJS *wrappedJS = static_cast<nsXPCWrappedJS*>(e);
|
||||
cb.NoteXPCOMRoot(wrappedJS);
|
||||
}
|
||||
|
||||
if(mJSHolders.ops)
|
||||
{
|
||||
Closure closure = { cx, PR_TRUE, &cb };
|
||||
JS_DHashTableEnumerate(&mJSHolders, NoteJSHolder, &closure);
|
||||
}
|
||||
JS_DHashTableEnumerate(&mJSHolders, NoteJSHolder, &cb);
|
||||
}
|
||||
|
||||
void
|
||||
@ -822,6 +781,20 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
// Auto JS GC lock helper.
|
||||
class AutoLockJSGC
|
||||
{
|
||||
public:
|
||||
AutoLockJSGC(JSRuntime* rt) : mJSRuntime(rt) { JS_LOCK_GC(mJSRuntime); }
|
||||
~AutoLockJSGC() { JS_UNLOCK_GC(mJSRuntime); }
|
||||
private:
|
||||
JSRuntime* mJSRuntime;
|
||||
|
||||
// Disable copy or assignment semantics.
|
||||
AutoLockJSGC(const AutoLockJSGC&);
|
||||
void operator=(const AutoLockJSGC&);
|
||||
};
|
||||
|
||||
//static
|
||||
void
|
||||
XPCJSRuntime::WatchdogMain(void *arg)
|
||||
|
@ -472,21 +472,6 @@ private:
|
||||
static void operator delete(void* /*memory*/) {}
|
||||
};
|
||||
|
||||
/************************************************/
|
||||
|
||||
class AutoLockJSGC
|
||||
{
|
||||
public:
|
||||
AutoLockJSGC(JSRuntime* rt) : mJSRuntime(rt) { JS_LOCK_GC(mJSRuntime); }
|
||||
~AutoLockJSGC() { JS_UNLOCK_GC(mJSRuntime); }
|
||||
private:
|
||||
JSRuntime* mJSRuntime;
|
||||
|
||||
// Disable copy or assignment semantics.
|
||||
AutoLockJSGC(const AutoLockJSGC&);
|
||||
void operator=(const AutoLockJSGC&);
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
****************************************************************************
|
||||
*
|
||||
@ -4523,18 +4508,16 @@ namespace xpc {
|
||||
|
||||
struct CompartmentPrivate
|
||||
{
|
||||
CompartmentPrivate(PtrAndPrincipalHashKey *key, bool wantXrays, bool cycleCollectionEnabled)
|
||||
CompartmentPrivate(PtrAndPrincipalHashKey *key, bool wantXrays)
|
||||
: key(key),
|
||||
ptr(nsnull),
|
||||
wantXrays(wantXrays),
|
||||
cycleCollectionEnabled(cycleCollectionEnabled)
|
||||
wantXrays(wantXrays)
|
||||
{
|
||||
}
|
||||
CompartmentPrivate(nsISupports *ptr, bool wantXrays, bool cycleCollectionEnabled)
|
||||
CompartmentPrivate(nsISupports *ptr, bool wantXrays)
|
||||
: key(nsnull),
|
||||
ptr(ptr),
|
||||
wantXrays(wantXrays),
|
||||
cycleCollectionEnabled(cycleCollectionEnabled)
|
||||
wantXrays(wantXrays)
|
||||
{
|
||||
}
|
||||
|
||||
@ -4542,25 +4525,8 @@ struct CompartmentPrivate
|
||||
nsAutoPtr<PtrAndPrincipalHashKey> key;
|
||||
nsCOMPtr<nsISupports> ptr;
|
||||
bool wantXrays;
|
||||
bool cycleCollectionEnabled;
|
||||
};
|
||||
|
||||
inline bool
|
||||
CompartmentParticipatesInCycleCollection(JSContext *cx, JSCompartment *compartment)
|
||||
{
|
||||
CompartmentPrivate *priv =
|
||||
static_cast<CompartmentPrivate *>(JS_GetCompartmentPrivate(cx, compartment));
|
||||
NS_ASSERTION(priv, "This should never be null!");
|
||||
|
||||
return priv->cycleCollectionEnabled;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ParticipatesInCycleCollection(JSContext *cx, js::gc::Cell *cell)
|
||||
{
|
||||
return CompartmentParticipatesInCycleCollection(cx, cell->compartment());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef XPC_IDISPATCH_SUPPORT
|
||||
|
@ -415,22 +415,17 @@ WrappedNativeSuspecter(JSDHashTable *table, JSDHashEntryHdr *hdr,
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(),
|
||||
"Suspecting wrapped natives from non-main thread");
|
||||
|
||||
// Only suspect wrappedJSObjects that are in a compartment that
|
||||
// participates in cycle collection.
|
||||
JSObject* obj = wrapper->GetFlatJSObject();
|
||||
if(!xpc::ParticipatesInCycleCollection(closure->cx, obj))
|
||||
return JS_DHASH_NEXT;
|
||||
|
||||
NS_ASSERTION(!JS_IsAboutToBeFinalized(closure->cx, obj),
|
||||
NS_ASSERTION(!JS_IsAboutToBeFinalized(closure->cx, wrapper->GetFlatJSObject()),
|
||||
"WrappedNativeSuspecter attempting to touch dead object");
|
||||
|
||||
// Only record objects that might be part of a cycle as roots, unless
|
||||
// the callback wants all traces (a debug feature).
|
||||
if(!(closure->cb.WantAllTraces()) && !nsXPConnect::IsGray(obj))
|
||||
if(!(closure->cb.WantAllTraces()) &&
|
||||
!nsXPConnect::IsGray(wrapper->GetFlatJSObject()))
|
||||
return JS_DHASH_NEXT;
|
||||
|
||||
closure->cb.NoteRoot(nsIProgrammingLanguage::JAVASCRIPT, obj,
|
||||
closure->cb.NoteRoot(nsIProgrammingLanguage::JAVASCRIPT,
|
||||
wrapper->GetFlatJSObject(),
|
||||
nsXPConnect::GetXPConnect());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user