Bug 720686, add some cycle collection optimizations to XPC, f=mrbkap,r=mccr8

--HG--
extra : rebase_source : 7e8f68a30048f613acc99201c3c1e12b6f74eaba
This commit is contained in:
Olli Pettay 2012-01-26 14:52:25 +01:00
Родитель e93f5dfbff
Коммит 3352edee98
5 изменённых файлов: 74 добавлений и 5 удалений

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

@ -56,7 +56,7 @@
#include "mozilla/Telemetry.h"
#include "nsContentUtils.h"
#include "nsCCUncollectableMarker.h"
#include "jsfriendapi.h"
#include "js/MemoryMetrics.h"
@ -573,12 +573,30 @@ XPCJSRuntime::AddXPConnectRoots(JSContext* cx,
XPCWrappedNativeScope::SuspectAllWrappers(this, cx, cb);
for (XPCRootSetElem *e = mVariantRoots; e ; e = e->GetNextRoot())
cb.NoteXPCOMRoot(static_cast<XPCTraceableVariant*>(e));
for (XPCRootSetElem *e = mVariantRoots; e ; e = e->GetNextRoot()) {
XPCTraceableVariant* v = static_cast<XPCTraceableVariant*>(e);
if (nsCCUncollectableMarker::InGeneration(cb,
v->CCGeneration())) {
jsval val = v->GetJSValPreserveColor();
if (val.isObject() && !xpc_IsGrayGCThing(&val.toObject()))
continue;
}
cb.NoteXPCOMRoot(v);
}
for (XPCRootSetElem *e = mWrappedJSRoots; e ; e = e->GetNextRoot()) {
nsXPCWrappedJS *wrappedJS = static_cast<nsXPCWrappedJS*>(e);
JSObject *obj = wrappedJS->GetJSObjectPreserveColor();
// If traversing wrappedJS wouldn't release it, nor
// cause any other objects to be added to the graph, no
// need to add it to the graph at all.
if (nsCCUncollectableMarker::sGeneration &&
!cb.WantAllTraces() && (!obj || !xpc_IsGrayGCThing(obj)) &&
!wrappedJS->IsSubjectToFinalization() &&
wrappedJS->GetRootWrapper() == wrappedJS &&
!wrappedJS->IsAggregatedToNative()) {
continue;
}
// Only suspect wrappedJSObjects that are in a compartment that
// participates in cycle collection.

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

@ -60,7 +60,7 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(XPCVariant)
NS_IMPL_CYCLE_COLLECTING_RELEASE(XPCVariant)
XPCVariant::XPCVariant(XPCCallContext& ccx, jsval aJSVal)
: mJSVal(aJSVal)
: mJSVal(aJSVal), mCCGeneration(0)
{
nsVariant::Initialize(&mData);
if (!JSVAL_IS_PRIMITIVE(mJSVal)) {

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

@ -823,6 +823,30 @@ NoteJSChild(JSTracer *trc, void *thing, JSGCTraceKind kind)
}
}
void
xpc_MarkInCCGeneration(nsISupports* aVariant, PRUint32 aGeneration)
{
nsCOMPtr<XPCVariant> variant = do_QueryInterface(aVariant);
if (variant) {
variant->SetCCGeneration(aGeneration);
variant->GetJSVal(); // Unmarks gray JSObject.
XPCVariant* weak = variant.get();
variant = nsnull;
if (weak->IsPurple()) {
weak->RemovePurple();
}
}
}
void
xpc_UnmarkGrayObject(nsIXPConnectWrappedJS* aWrappedJS)
{
if (aWrappedJS) {
// Unmarks gray JSObject.
static_cast<nsXPCWrappedJS*>(aWrappedJS)->GetJSObject();
}
}
static JSBool
WrapperIsNotMainThreadOnly(XPCWrappedNative *wrapper)
{

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

@ -4279,6 +4279,22 @@ public:
nsIVariant* variant,
nsresult* pErr, jsval* pJSVal);
bool IsPurple()
{
return mRefCnt.IsPurple();
}
void RemovePurple()
{
mRefCnt.RemovePurple();
}
void SetCCGeneration(PRUint32 aGen)
{
mCCGeneration = aGen;
}
PRUint32 CCGeneration() { return mCCGeneration; }
protected:
virtual ~XPCVariant() { }
@ -4287,7 +4303,8 @@ protected:
protected:
nsDiscriminatedUnion mData;
jsval mJSVal;
JSBool mReturnRawObject;
bool mReturnRawObject : 1;
PRUint32 mCCGeneration : 31;
};
NS_DEFINE_STATIC_IID_ACCESSOR(XPCVariant, XPCVARIANT_IID)

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

@ -55,6 +55,7 @@
#include "nsTArray.h"
class nsIPrincipal;
class nsIXPConnectWrappedJS;
struct nsDOMClassInfoData;
#ifndef BAD_TLS_INDEX
@ -189,6 +190,15 @@ xpc_UnmarkGrayObject(JSObject *obj)
xpc_UnmarkGrayObjectRecursive(obj);
}
// If aVariant is an XPCVariant, this marks the object to be in aGeneration.
// This also unmarks the gray JSObject.
extern void
xpc_MarkInCCGeneration(nsISupports* aVariant, PRUint32 aGeneration);
// Unmarks aWrappedJS's JSObject.
extern void
xpc_UnmarkGrayObject(nsIXPConnectWrappedJS* aWrappedJS);
// No JS can be on the stack when this is called. Probably only useful from
// xpcshell.
NS_EXPORT_(void)