Bug 882162: Part 9 - Kill nsCycleCollectionJSRuntime. r=mccr8

This commit is contained in:
Kyle Huey 2013-06-18 12:02:16 -07:00
parent 67e8082658
commit 1b8071cf87
8 changed files with 23 additions and 223 deletions

View File

@ -89,8 +89,6 @@ nsXPConnect::nsXPConnect()
{
mRuntime = XPCJSRuntime::newXPCJSRuntime(this);
nsCycleCollector_registerJSRuntime(this);
char* reportableEnv = PR_GetEnv("MOZ_REPORT_ALL_JS_EXCEPTIONS");
if (reportableEnv && *reportableEnv)
gReportAllJSExceptions = 1;
@ -99,7 +97,6 @@ nsXPConnect::nsXPConnect()
nsXPConnect::~nsXPConnect()
{
mRuntime->DeleteJunkScope();
nsCycleCollector_forgetJSRuntime();
JSContext *cx = nullptr;
if (mRuntime) {
@ -239,73 +236,13 @@ nsXPConnect::GetInfoForName(const char * name, nsIInterfaceInfo** info)
return NS_FAILED(rv) ? NS_OK : NS_ERROR_NO_INTERFACE;
}
bool
nsXPConnect::NeedCollect()
{
return GetRuntime()->NeedCollect();
}
void
nsXPConnect::Collect(uint32_t reason)
{
return GetRuntime()->Collect(reason);
}
NS_IMETHODIMP
nsXPConnect::GarbageCollect(uint32_t reason)
{
Collect(reason);
GetRuntime()->Collect(reason);
return NS_OK;
}
void
nsXPConnect::FixWeakMappingGrayBits()
{
GetRuntime()->FixWeakMappingGrayBits();
}
nsresult
nsXPConnect::BeginCycleCollection(nsCycleCollectionNoteRootCallback &cb)
{
return GetRuntime()->BeginCycleCollection(cb);
}
bool
nsXPConnect::NotifyLeaveMainThread()
{
return mRuntime->NotifyLeaveMainThread();
}
void
nsXPConnect::NotifyEnterCycleCollectionThread()
{
mRuntime->NotifyEnterCycleCollectionThread();
}
void
nsXPConnect::NotifyLeaveCycleCollectionThread()
{
mRuntime->NotifyLeaveCycleCollectionThread();
}
void
nsXPConnect::NotifyEnterMainThread()
{
mRuntime->NotifyEnterMainThread();
}
bool
nsXPConnect::UsefulToMergeZones()
{
return GetRuntime()->UsefulToMergeZones();
}
nsCycleCollectionParticipant *
nsXPConnect::GetParticipant()
{
return GetRuntime()->GCThingParticipant();
}
JSBool
xpc_GCThingIsGrayCCThing(void *thing)
{
@ -338,18 +275,11 @@ xpc_TryUnmarkWrappedGrayObject(nsISupports* aWrappedJS)
}
}
// static
nsCycleCollectionParticipant*
nsXPConnect::JSContextParticipant()
{
return mozilla::CycleCollectedJSRuntime::JSContextParticipant();
}
NS_IMETHODIMP_(void)
nsXPConnect::NoteJSContext(JSContext *aJSContext,
nsCycleCollectionTraversalCallback &aCb)
{
aCb.NoteNativeChild(aJSContext, JSContextParticipant());
aCb.NoteNativeChild(aJSContext, mozilla::CycleCollectedJSRuntime::JSContextParticipant());
}
@ -1237,26 +1167,6 @@ nsXPConnect::OnDispatchedEvent(nsIThreadInternal* aThread)
return NS_ERROR_UNEXPECTED;
}
void
nsXPConnect::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
{
mRuntime->AddJSHolder(aHolder, aTracer);
}
void
nsXPConnect::RemoveJSHolder(void* aHolder)
{
mRuntime->RemoveJSHolder(aHolder);
}
#ifdef DEBUG
bool
nsXPConnect::TestJSHolder(void* aHolder)
{
return mRuntime->TestJSHolder(aHolder);
}
#endif
NS_IMETHODIMP
nsXPConnect::SetReportAllJSExceptions(bool newval)
{
@ -1719,22 +1629,6 @@ nsXPConnect::ReadFunction(nsIObjectInputStream *stream, JSContext *cx, JSObject
return ReadScriptOrFunction(stream, cx, nullptr, functionObjp);
}
#ifdef DEBUG
void
nsXPConnect::SetObjectToUnlink(void* aObject)
{
if (mRuntime)
mRuntime->SetObjectToUnlink(aObject);
}
void
nsXPConnect::AssertNoObjectsToTrace(void* aPossibleJSHolder)
{
if (mRuntime)
mRuntime->AssertNoObjectsToTrace(aPossibleJSHolder);
}
#endif
/* These are here to be callable from a debugger */
JS_BEGIN_EXTERN_C
JS_EXPORT_API(void) DumpJSStack()

View File

@ -97,7 +97,6 @@
#include "nsXPCOM.h"
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCycleCollectionJSRuntime.h"
#include "nsCycleCollectorUtils.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "nsDebug.h"
@ -434,7 +433,6 @@ AddToCCKind(JSGCTraceKind kind)
class nsXPConnect : public nsIXPConnect,
public nsIThreadObserver,
public nsSupportsWeakReference,
public nsCycleCollectionJSRuntime,
public nsIJSRuntimeService,
public nsIJSEngineTelemetryStats
{
@ -463,15 +461,6 @@ public:
static XPCJSRuntime* GetRuntimeInstance();
XPCJSRuntime* GetRuntime() {return mRuntime;}
void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer) MOZ_OVERRIDE;
void RemoveJSHolder(void* aHolder) MOZ_OVERRIDE;
#ifdef DEBUG
bool TestJSHolder(void* aHolder) MOZ_OVERRIDE;
void SetObjectToUnlink(void* aObject);
void AssertNoObjectsToTrace(void* aPossibleJSHolder);
#endif
static JSBool IsISupportsDescendant(nsIInterfaceInfo* info);
nsIXPCSecurityManager* GetDefaultSecurityManager() const
@ -500,21 +489,6 @@ public:
nsresult GetInfoForIID(const nsIID * aIID, nsIInterfaceInfo** info);
nsresult GetInfoForName(const char * name, nsIInterfaceInfo** info);
// nsCycleCollectionJSRuntime
virtual bool NotifyLeaveMainThread(); // DONE
virtual void NotifyEnterCycleCollectionThread(); // DONE
virtual void NotifyLeaveCycleCollectionThread(); // DONE
virtual void NotifyEnterMainThread(); // DONE
virtual nsresult BeginCycleCollection(nsCycleCollectionNoteRootCallback &cb); // DONE
virtual nsCycleCollectionParticipant *GetParticipant(); // DONE
virtual bool UsefulToMergeZones(); // DONE
virtual void FixWeakMappingGrayBits(); // DONE
virtual bool NeedCollect(); // DONE
virtual void Collect(uint32_t reason); // DONE
// This returns the singleton nsCycleCollectionParticipant for JSContexts.
static nsCycleCollectionParticipant *JSContextParticipant();
virtual nsIPrincipal* GetPrincipal(JSObject* obj,
bool allowShortCircuit) const;

View File

@ -417,9 +417,6 @@ JSObject *
GetJunkScope();
} // namespace xpc
nsCycleCollectionParticipant *
xpc_JSZoneParticipant();
namespace mozilla {
namespace dom {

View File

@ -11,6 +11,7 @@
#include "jsprf.h"
#include "nsCycleCollectionNoteRootCallback.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCycleCollector.h"
#include "nsDOMJSUtils.h"
#include "nsLayoutStatics.h"
#include "xpcpublic.h"
@ -396,13 +397,6 @@ sJSZoneCycleCollectorGlobal = {
NS_IMPL_CYCLE_COLLECTION_NATIVE_VTABLE(JSZoneParticipant)
};
// XXXkhuey this is totally wrong ...
nsCycleCollectionParticipant*
xpc_JSZoneParticipant()
{
return sJSZoneCycleCollectorGlobal.GetParticipant();
}
CycleCollectedJSRuntime::CycleCollectedJSRuntime(uint32_t aMaxbytes,
JSUseHelperThreads aUseHelperThreads,
bool aExpectUnrootedGlobals)
@ -422,10 +416,14 @@ CycleCollectedJSRuntime::CycleCollectedJSRuntime(uint32_t aMaxbytes,
JS_SetGrayGCRootsTracer(mJSRuntime, TraceGrayJS, this);
mJSHolders.Init(512);
nsCycleCollector_registerJSRuntime(this);
}
CycleCollectedJSRuntime::~CycleCollectedJSRuntime()
{
nsCycleCollector_forgetJSRuntime();
JS_DestroyRuntime(mJSRuntime);
mJSRuntime = nullptr;
}

View File

@ -101,7 +101,7 @@
/* This must occur *after* base/process_util.h to avoid typedefs conflicts. */
#include "mozilla/Util.h"
#include "nsCycleCollectionJSRuntime.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCycleCollectionNoteRootCallback.h"
#include "nsCycleCollectorUtils.h"
@ -992,7 +992,7 @@ class nsCycleCollector
nsCycleCollectorResults *mResults;
TimeStamp mCollectionStart;
nsCycleCollectionJSRuntime *mJSRuntime;
CycleCollectedJSRuntime *mJSRuntime;
GCGraph mGraph;
@ -1022,10 +1022,10 @@ private:
uint32_t mMergedInARow;
public:
void RegisterJSRuntime(nsCycleCollectionJSRuntime *aJSRuntime);
void RegisterJSRuntime(CycleCollectedJSRuntime *aJSRuntime);
void ForgetJSRuntime();
inline nsCycleCollectionJSRuntime*
inline CycleCollectedJSRuntime*
JSRuntime() const
{
return mJSRuntime;
@ -1734,7 +1734,7 @@ private:
public:
GCGraphBuilder(nsCycleCollector *aCollector,
GCGraph &aGraph,
nsCycleCollectionJSRuntime *aJSRuntime,
CycleCollectedJSRuntime *aJSRuntime,
nsICycleCollectorListener *aListener,
bool aMergeZones);
~GCGraphBuilder();
@ -1817,7 +1817,7 @@ private:
GCGraphBuilder::GCGraphBuilder(nsCycleCollector *aCollector,
GCGraph &aGraph,
nsCycleCollectionJSRuntime *aJSRuntime,
CycleCollectedJSRuntime *aJSRuntime,
nsICycleCollectorListener *aListener,
bool aMergeZones)
: mCollector(aCollector),
@ -1825,7 +1825,7 @@ GCGraphBuilder::GCGraphBuilder(nsCycleCollector *aCollector,
mEdgeBuilder(aGraph.mEdges),
mWeakMaps(aGraph.mWeakMaps),
mJSParticipant(nullptr),
mJSZoneParticipant(xpc_JSZoneParticipant()),
mJSZoneParticipant(nullptr),
mListener(aListener),
mMergeZones(aMergeZones),
mRanOutOfMemory(false)
@ -1837,7 +1837,8 @@ GCGraphBuilder::GCGraphBuilder(nsCycleCollector *aCollector,
}
if (aJSRuntime) {
mJSParticipant = aJSRuntime->GetParticipant();
mJSParticipant = aJSRuntime->GCThingParticipant();
mJSZoneParticipant = aJSRuntime->ZoneParticipant();
}
uint32_t flags = 0;
@ -2555,7 +2556,7 @@ nsCycleCollector::ShutdownThreads()
}
void
nsCycleCollector::RegisterJSRuntime(nsCycleCollectionJSRuntime *aJSRuntime)
nsCycleCollector::RegisterJSRuntime(CycleCollectedJSRuntime *aJSRuntime)
{
if (mParams.mDoNothing)
return;
@ -2964,7 +2965,7 @@ HaveCollector(nsCycleCollector* aCollector)
////////////////////////////////////////////////////////////////////////
void
nsCycleCollector_registerJSRuntime(nsCycleCollectionJSRuntime *rt)
nsCycleCollector_registerJSRuntime(CycleCollectedJSRuntime *rt)
{
nsCycleCollector *collector = sCollector.get();

View File

@ -6,11 +6,14 @@
#ifndef nsCycleCollector_h__
#define nsCycleCollector_h__
class nsCycleCollectionJSRuntime;
class nsICycleCollectorListener;
class nsISupports;
class nsScriptObjectTracer;
namespace mozilla {
class CycleCollectedJSRuntime;
}
// Contains various stats about the cycle collection.
class nsCycleCollectorResults
{
@ -52,7 +55,7 @@ void nsCycleCollector_shutdownThreads();
void nsCycleCollector_shutdown();
// Helpers for interacting with JS
void nsCycleCollector_registerJSRuntime(nsCycleCollectionJSRuntime *aRt);
void nsCycleCollector_registerJSRuntime(mozilla::CycleCollectedJSRuntime *aRt);
void nsCycleCollector_forgetJSRuntime();
#define NS_CYCLE_COLLECTOR_LOGGER_CID \

View File

@ -30,7 +30,6 @@ SDK_HEADERS = \
nsCategoryCache.h \
nsClassHashtable.h \
nsComponentManagerUtils.h \
nsCycleCollectionJSRuntime.h \
nsCycleCollectionParticipant.h \
nsCycleCollectorUtils.h \
nsDataHashtable.h \

View File

@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsCycleCollectionJSRuntime_h__
#define nsCycleCollectionJSRuntime_h__
class nsCycleCollectionParticipant;
class nsCycleCollectionNoteRootCallback;
class nsScriptObjectTracer;
// Various methods the cycle collector needs to deal with Javascript.
struct nsCycleCollectionJSRuntime
{
virtual nsresult BeginCycleCollection(nsCycleCollectionNoteRootCallback &aCb) = 0;
/**
* Called before/after transitioning to/from the main thread.
*
* NotifyLeaveMainThread may return 'false' to prevent the cycle collector
* from leaving the main thread.
*/
virtual bool NotifyLeaveMainThread() = 0;
virtual void NotifyEnterCycleCollectionThread() = 0;
virtual void NotifyLeaveCycleCollectionThread() = 0;
virtual void NotifyEnterMainThread() = 0;
/**
* Unmark gray any weak map values, as needed.
*/
virtual void FixWeakMappingGrayBits() = 0;
/**
* Return true if merging content zones may greatly reduce the size of the CC graph.
*/
virtual bool UsefulToMergeZones() = 0;
/**
* Should we force a JavaScript GC before a CC?
*/
virtual bool NeedCollect() = 0;
/**
* Runs the JavaScript GC. |reason| is a gcreason::Reason from jsfriendapi.h.
*/
virtual void Collect(uint32_t aReason) = 0;
/**
* Get the JS cycle collection participant.
*/
virtual nsCycleCollectionParticipant *GetParticipant() = 0;
virtual void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer) = 0;
virtual void RemoveJSHolder(void* aHolder) = 0;
#ifdef DEBUG
virtual bool TestJSHolder(void* aHolder) = 0;
virtual void SetObjectToUnlink(void* aObject) = 0;
virtual void AssertNoObjectsToTrace(void* aPossibleJSHolder) = 0;
#endif
};
#endif // nsCycleCollectionJSRuntime_h__