Backed out changeset 2e2b2ae083e5

This commit is contained in:
Robert O'Callahan 2010-08-12 15:55:51 +12:00
Родитель 08bf4d1075
Коммит cdbec872a9
6 изменённых файлов: 100 добавлений и 101 удалений

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

@ -521,7 +521,7 @@ nsDOMWindowUtils::Focus(nsIDOMElement* aElement)
}
NS_IMETHODIMP
nsDOMWindowUtils::GarbageCollect(PRBool aDrawGraph)
nsDOMWindowUtils::GarbageCollect()
{
// Always permit this in debug builds.
#ifndef DEBUG
@ -530,7 +530,7 @@ nsDOMWindowUtils::GarbageCollect(PRBool aDrawGraph)
}
#endif
nsJSContext::CC(aDrawGraph);
nsJSContext::CC();
return NS_OK;
}

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

@ -307,7 +307,7 @@ NS_IMETHODIMP
nsCCMemoryPressureObserver::Observe(nsISupports* aSubject, const char* aTopic,
const PRUnichar* aData)
{
nsJSContext::CC(PR_FALSE);
nsJSContext::CC();
return NS_OK;
}
@ -973,7 +973,7 @@ nsJSContext::DOMOperationCallback(JSContext *cx)
mem->IsLowMemory(&lowMemory);
if (lowMemory) {
// try to clean up:
nsJSContext::CC(PR_FALSE);
nsJSContext::CC();
// never prevent system scripts from running
if (!::JS_IsSystemObject(cx, ::JS_GetGlobalObject(cx))) {
@ -3616,7 +3616,7 @@ nsJSContext::ScriptExecuted()
//static
void
nsJSContext::CC(PRBool aDrawGraph)
nsJSContext::CC()
{
NS_TIME_FUNCTION_MIN(1.0);
@ -3631,7 +3631,7 @@ nsJSContext::CC(PRBool aDrawGraph)
// nsCycleCollector_collect() no longer forces a JS garbage collection,
// so we have to do it ourselves here.
nsContentUtils::XPConnect()->GarbageCollect();
sCollectedObjectsCounts = nsCycleCollector_collect(aDrawGraph);
sCollectedObjectsCounts = nsCycleCollector_collect();
sCCSuspectedCount = nsCycleCollector_suspectedCount();
sSavedGCCount = JS_GetGCParameter(nsJSRuntime::sRuntime, JSGC_NUMBER);
#ifdef DEBUG_smaug
@ -3719,7 +3719,7 @@ nsJSContext::IntervalCC()
{
if ((PR_Now() - sPreviousCCTime) >=
PRTime(NS_MIN_CC_INTERVAL * PR_USEC_PER_MSEC)) {
nsJSContext::CC(PR_FALSE);
nsJSContext::CC();
return PR_TRUE;
}
#ifdef DEBUG_smaug

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

@ -188,7 +188,7 @@ public:
// CC does always call cycle collector and it also updates the counters
// that MaybeCC uses.
static void CC(PRBool aDrawGraph);
static void CC();
// MaybeCC calls cycle collector if certain conditions are fulfilled.
// The conditions are:

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

@ -53,7 +53,7 @@ interface nsIDOMEvent;
interface nsITransferable;
interface nsIQueryContentEventResult;
[scriptable, uuid(bf4df3a0-4567-47ec-be6d-9ec60eaed63c)]
[scriptable, uuid(1e042706-0343-4cba-a549-6a83eefb1835)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -258,12 +258,8 @@ interface nsIDOMWindowUtils : nsISupports {
*
* Will throw a DOM security error if called without UniversalXPConnect
* privileges in non-debug builds. Available to all callers in debug builds.
*
* @param aDrawGraph when true, a cycle collection graph will be
* dumped to a file named cycle-graph-*.dot in the current working
* directory
*/
void garbageCollect(in boolean aDrawGraph);
void garbageCollect();
/**
* Force processing of any queued paints

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

@ -156,10 +156,6 @@
//#define COLLECT_TIME_DEBUG
#if defined(DEBUG_CC) || defined(DEBUG)
#define DEBUG_CC_GRAPHS
#endif
#ifdef DEBUG_CC
#define IF_DEBUG_CC_PARAM(_p) , _p
#define IF_DEBUG_CC_ONLY_PARAM(_p) _p
@ -181,10 +177,10 @@
struct nsCycleCollectorParams
{
PRBool mDoNothing;
PRBool mDrawGraphs;
#ifdef DEBUG_CC
PRBool mReportStats;
PRBool mHookMalloc;
PRBool mDrawGraphs;
PRBool mFaultIsFatal;
PRBool mLogPointers;
@ -202,8 +198,7 @@ struct nsCycleCollectorParams
mShutdownCollections(DEFAULT_SHUTDOWN_COLLECTIONS)
#else
mDoNothing (PR_FALSE),
mDrawGraphs (PR_FALSE)
mDoNothing (PR_FALSE)
#endif
{
#ifdef DEBUG_CC
@ -451,12 +446,9 @@ struct PtrInfo
EdgePool::Iterator mFirstChild; // first
EdgePool::Iterator mLastChild; // one after last
#ifdef DEBUG_CC_GRAPHS
char *mName;
#endif
#ifdef DEBUG_CC
size_t mBytes;
char *mName;
PRUint32 mLangID;
// For finding roots in ExplainLiveExpectedGarbage (when there are
@ -468,9 +460,9 @@ struct PtrInfo
ReversedEdge* mReversedEdges; // linked list
PtrInfo* mShortestPathToExpectedGarbage;
nsCString* mShortestPathToExpectedGarbageEdgeName;
#endif
nsTArray<nsCString> mEdgeNames;
#endif
PtrInfo(void *aPointer, nsCycleCollectionParticipant *aParticipant
IF_DEBUG_CC_PARAM(PRUint32 aLangID)
@ -482,11 +474,9 @@ struct PtrInfo
mRefCount(0),
mFirstChild(),
mLastChild()
#ifdef DEBUG_CC_GRAPHS
, mName(nsnull)
#endif
#ifdef DEBUG_CC
, mBytes(0),
mName(nsnull),
mLangID(aLangID),
mSCCIndex(0),
mReversedEdges(nsnull),
@ -496,12 +486,12 @@ struct PtrInfo
{
}
#ifdef DEBUG_CC
void Destroy() {
#ifdef DEBUG_CC_GRAPHS
PL_strfree(mName);
#endif
mEdgeNames.~nsTArray<nsCString>();
}
#endif
// Allow NodePool::Block's constructor to compile.
PtrInfo() {
@ -661,7 +651,7 @@ struct GCGraph
// Add/Remove/Has rather than PutEntry/RemoveEntry/GetEntry.
typedef nsTHashtable<nsVoidPtrHashKey> PointerSet;
#ifdef DEBUG_CC_GRAPHS
#ifdef DEBUG_CC
static void
WriteGraph(FILE *stream, GCGraph &graph, const void *redPtr);
#endif
@ -1005,7 +995,7 @@ struct nsCycleCollector
nsPurpleBufferEntry* Suspect2(nsISupports *n);
PRBool Forget2(nsPurpleBufferEntry *e);
PRUint32 Collect(PRUint32 aTryCollections, PRBool aDrawGraph);
PRUint32 Collect(PRUint32 aTryCollections = 1);
PRBool BeginCollection();
PRBool FinishCollection();
PRUint32 SuspectedCount();
@ -1018,15 +1008,12 @@ struct nsCycleCollector
mGraph.mRootCount = 0;
}
#ifdef DEBUG_CC_GRAPHS
void MaybeDrawGraphs();
#endif
#ifdef DEBUG_CC
nsCycleCollectorStats mStats;
FILE *mPtrLog;
void MaybeDrawGraphs();
void Allocated(void *n, size_t sz);
void Freed(void *n);
@ -1314,12 +1301,13 @@ private:
PLDHashTable mPtrToNodeMap;
PtrInfo *mCurrPi;
nsCycleCollectionLanguageRuntime **mRuntimes; // weak, from nsCycleCollector
#ifdef DEBUG_CC
nsCString mNextEdgeName;
#endif
public:
GCGraphBuilder(GCGraph &aGraph,
nsCycleCollectionLanguageRuntime **aRuntimes,
PRBool aDrawGraph);
nsCycleCollectionLanguageRuntime **aRuntimes);
~GCGraphBuilder();
bool Initialized();
@ -1354,8 +1342,7 @@ private:
};
GCGraphBuilder::GCGraphBuilder(GCGraph &aGraph,
nsCycleCollectionLanguageRuntime **aRuntimes,
PRBool aDrawGraph)
nsCycleCollectionLanguageRuntime **aRuntimes)
: mNodeBuilder(aGraph.mNodes),
mEdgeBuilder(aGraph.mEdges),
mRuntimes(aRuntimes)
@ -1363,13 +1350,11 @@ GCGraphBuilder::GCGraphBuilder(GCGraph &aGraph,
if (!PL_DHashTableInit(&mPtrToNodeMap, &PtrNodeOps, nsnull,
sizeof(PtrToNodeEntry), 32768))
mPtrToNodeMap.ops = nsnull;
#ifndef DEBUG_CC
if (aDrawGraph)
#ifdef DEBUG_CC
// Do we need to set these all the time?
mFlags |= nsCycleCollectionTraversalCallback::WANT_DEBUG_INFO |
nsCycleCollectionTraversalCallback::WANT_ALL_TRACES;
#endif
{
mFlags |= nsCycleCollectionTraversalCallback::WANT_DEBUG_INFO |
nsCycleCollectionTraversalCallback::WANT_ALL_TRACES;
}
}
GCGraphBuilder::~GCGraphBuilder()
@ -1473,11 +1458,7 @@ GCGraphBuilder::DescribeNode(CCNodeType type, nsrefcnt refCount,
{
#ifdef DEBUG_CC
mCurrPi->mBytes = objSz;
#endif
#ifdef DEBUG_CC_GRAPHS
if (WantDebugInfo()) {
mCurrPi->mName = PL_strdup(objName);
}
mCurrPi->mName = PL_strdup(objName);
#endif
if (type == RefCounted) {
@ -1497,11 +1478,10 @@ GCGraphBuilder::DescribeNode(CCNodeType type, nsrefcnt refCount,
NS_IMETHODIMP_(void)
GCGraphBuilder::NoteXPCOMChild(nsISupports *child)
{
nsCString edgeName;
if (WantDebugInfo()) {
edgeName.Assign(mNextEdgeName);
mNextEdgeName.Truncate();
}
#ifdef DEBUG_CC
nsCString edgeName(mNextEdgeName);
mNextEdgeName.Truncate();
#endif
if (!child || !(child = canonicalize(child)))
return;
@ -1517,9 +1497,9 @@ GCGraphBuilder::NoteXPCOMChild(nsISupports *child)
if (!childPi)
return;
mEdgeBuilder.Add(childPi);
if (WantDebugInfo()) {
mCurrPi->mEdgeNames.AppendElement(edgeName);
}
#ifdef DEBUG_CC
mCurrPi->mEdgeNames.AppendElement(edgeName);
#endif
++childPi->mInternalRefs;
}
}
@ -1528,11 +1508,10 @@ NS_IMETHODIMP_(void)
GCGraphBuilder::NoteNativeChild(void *child,
nsCycleCollectionParticipant *participant)
{
nsCString edgeName;
if (WantDebugInfo()) {
edgeName.Assign(mNextEdgeName);
mNextEdgeName.Truncate();
}
#ifdef DEBUG_CC
nsCString edgeName(mNextEdgeName);
mNextEdgeName.Truncate();
#endif
if (!child)
return;
@ -1542,17 +1521,19 @@ GCGraphBuilder::NoteNativeChild(void *child,
if (!childPi)
return;
mEdgeBuilder.Add(childPi);
if (WantDebugInfo()) {
mCurrPi->mEdgeNames.AppendElement(edgeName);
}
#ifdef DEBUG_CC
mCurrPi->mEdgeNames.AppendElement(edgeName);
#endif
++childPi->mInternalRefs;
}
NS_IMETHODIMP_(void)
GCGraphBuilder::NoteScriptChild(PRUint32 langID, void *child)
{
#ifdef DEBUG_CC
nsCString edgeName(mNextEdgeName);
mNextEdgeName.Truncate();
#endif
if (!child)
return;
@ -1575,18 +1556,18 @@ GCGraphBuilder::NoteScriptChild(PRUint32 langID, void *child)
if (!childPi)
return;
mEdgeBuilder.Add(childPi);
if (WantDebugInfo()) {
mCurrPi->mEdgeNames.AppendElement(edgeName);
}
#ifdef DEBUG_CC
mCurrPi->mEdgeNames.AppendElement(edgeName);
#endif
++childPi->mInternalRefs;
}
NS_IMETHODIMP_(void)
GCGraphBuilder::NoteNextEdgeName(const char* name)
{
if (WantDebugInfo()) {
mNextEdgeName = name;
}
#ifdef DEBUG_CC
mNextEdgeName = name;
#endif
}
static PRBool
@ -2098,7 +2079,8 @@ nsCycleCollector::ForgetRuntime(PRUint32 langID)
mRuntimes[langID] = nsnull;
}
#ifdef DEBUG_CC_GRAPHS
#ifdef DEBUG_CC
static void
WriteGraph(FILE *stream, GCGraph &graph, const void *redPtr)
{
@ -2126,36 +2108,62 @@ WriteGraph(FILE *stream, GCGraph &graph, const void *redPtr)
"\", fillcolor=%s, fontcolor=%s]\n",
(redPtr && redPtr == p ? "red" : (pi->mColor == black ? "black" : "white")),
(pi->mColor == black ? "white" : "black"));
PRInt32 i = 0;
for (EdgePool::Iterator child = pi->mFirstChild,
child_end = pi->mLastChild;
child != child_end; ++child) {
fprintf(stream, "n%p -> n%p [label=\"%s\"]\n", p,
(*child)->mPointer, pi->mEdgeNames[i].get());
++i;
fprintf(stream, "n%p -> n%p\n", p, (*child)->mPointer);
}
}
fprintf(stream, "\n}\n");
}
static PRUint32 gCounter;
void
nsCycleCollector::MaybeDrawGraphs()
{
if (mParams.mDrawGraphs) {
FILE *stream;
char name[255];
sprintf(name, "cycle-graph-%d.dot", ++gCounter);
stream = fopen(name, "w");
WriteGraph(stream, mGraph, nsnull);
fclose(stream);
// We draw graphs only if there were any white nodes.
PRBool anyWhites = PR_FALSE;
NodePool::Enumerator fwetor(mGraph.mNodes);
while (!fwetor.IsDone())
{
PtrInfo *pinfo = fwetor.GetNext();
if (pinfo->mColor == white) {
anyWhites = PR_TRUE;
break;
}
}
if (anyWhites) {
// We can't just use _popen here because graphviz-for-windows
// doesn't set up its stdin stream properly, sigh.
FILE *stream;
#ifdef WIN32
stream = fopen("c:\\cycle-graph.dot", "w+");
#else
stream = popen("dotty -", "w");
#endif
WriteGraph(stream, mGraph, nsnull);
#ifdef WIN32
fclose(stream);
// Even dotty doesn't work terribly well on windows, since
// they execute lefty asynchronously. So we'll just run
// lefty ourselves.
_spawnlp(_P_WAIT,
"lefty",
"lefty",
"-e",
"\"load('dotty.lefty');"
"dotty.simple('c:\\cycle-graph.dot');\"",
NULL);
unlink("c:\\cycle-graph.dot");
#else
pclose(stream);
#endif
}
}
}
#endif
#ifdef DEBUG_CC
class Suppressor :
public nsCycleCollectionTraversalCallback
@ -2408,7 +2416,7 @@ nsCycleCollector::Freed(void *n)
#endif
PRUint32
nsCycleCollector::Collect(PRUint32 aTryCollections, PRBool aDrawGraph)
nsCycleCollector::Collect(PRUint32 aTryCollections)
{
#if defined(DEBUG_CC) && !defined(__MINGW32__)
if (!mParams.mDoNothing && mParams.mHookMalloc)
@ -2426,9 +2434,6 @@ nsCycleCollector::Collect(PRUint32 aTryCollections, PRBool aDrawGraph)
PRTime start = PR_Now();
#endif
PRBool drawGraphs = mParams.mDrawGraphs;
mParams.mDrawGraphs |= aDrawGraph;
mCollectionInProgress = PR_TRUE;
nsCOMPtr<nsIObserverService> obs =
@ -2498,8 +2503,6 @@ nsCycleCollector::Collect(PRUint32 aTryCollections, PRBool aDrawGraph)
mCollectionInProgress = PR_FALSE;
mParams.mDrawGraphs = drawGraphs;
#ifdef XP_OS2
// Now that the cycle collector has freed some memory, we can try to
// force the C library to give back as much memory to the system as
@ -2523,7 +2526,7 @@ nsCycleCollector::BeginCollection()
if (mParams.mDoNothing)
return PR_FALSE;
GCGraphBuilder builder(mGraph, mRuntimes, mParams.mDrawGraphs);
GCGraphBuilder builder(mGraph, mRuntimes);
if (!builder.Initialized())
return PR_FALSE;
@ -2601,7 +2604,7 @@ nsCycleCollector::BeginCollection()
(PR_Now() - now) / PR_USEC_PER_MSEC);
#endif
#ifdef DEBUG_CC_GRAPHS
#ifdef DEBUG_CC
MaybeDrawGraphs();
#endif
@ -2689,7 +2692,7 @@ nsCycleCollector::Shutdown()
mRuntimes[i]->CommenceShutdown();
}
Collect(SHUTDOWN_COLLECTIONS(mParams), PR_FALSE);
Collect(SHUTDOWN_COLLECTIONS(mParams));
#ifdef DEBUG_CC
GCGraphBuilder builder(mGraph, mRuntimes);
@ -3160,9 +3163,9 @@ NS_CycleCollectorForget2(nsPurpleBufferEntry *e)
PRUint32
nsCycleCollector_collect(PRBool aDrawGraph)
nsCycleCollector_collect()
{
return sCollector ? sCollector->Collect(1, aDrawGraph) : 0;
return sCollector ? sCollector->Collect() : 0;
}
PRUint32

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

@ -63,7 +63,7 @@ struct nsCycleCollectionLanguageRuntime
nsresult nsCycleCollector_startup();
// Returns the number of collected nodes.
NS_COM PRUint32 nsCycleCollector_collect(PRBool aDrawGraph);
NS_COM PRUint32 nsCycleCollector_collect();
NS_COM PRUint32 nsCycleCollector_suspectedCount();
void nsCycleCollector_shutdown();