2007-01-05 01:31:26 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2013-01-15 04:26:47 +04:00
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2007-01-05 01:31:26 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// This file implements a garbage-cycle collector based on the paper
|
2012-11-07 05:38:29 +04:00
|
|
|
//
|
2007-01-05 01:31:26 +03:00
|
|
|
// Concurrent Cycle Collection in Reference Counted Systems
|
|
|
|
// Bacon & Rajan (2001), ECOOP 2001 / Springer LNCS vol 2072
|
|
|
|
//
|
|
|
|
// We are not using the concurrent or acyclic cases of that paper; so
|
|
|
|
// the green, red and orange colors are not used.
|
|
|
|
//
|
|
|
|
// The collector is based on tracking pointers of four colors:
|
|
|
|
//
|
|
|
|
// Black nodes are definitely live. If we ever determine a node is
|
|
|
|
// black, it's ok to forget about, drop from our records.
|
|
|
|
//
|
|
|
|
// White nodes are definitely garbage cycles. Once we finish with our
|
|
|
|
// scanning, we unlink all the white nodes and expect that by
|
|
|
|
// unlinking them they will self-destruct (since a garbage cycle is
|
|
|
|
// only keeping itself alive with internal links, by definition).
|
|
|
|
//
|
2013-07-09 21:30:58 +04:00
|
|
|
// Snow-white is an addition to the original algorithm. Snow-white object
|
|
|
|
// has reference count zero and is just waiting for deletion.
|
|
|
|
//
|
2007-01-05 01:31:26 +03:00
|
|
|
// Grey nodes are being scanned. Nodes that turn grey will turn
|
|
|
|
// either black if we determine that they're live, or white if we
|
|
|
|
// determine that they're a garbage cycle. After the main collection
|
|
|
|
// algorithm there should be no grey nodes.
|
|
|
|
//
|
|
|
|
// Purple nodes are *candidates* for being scanned. They are nodes we
|
|
|
|
// haven't begun scanning yet because they're not old enough, or we're
|
|
|
|
// still partway through the algorithm.
|
|
|
|
//
|
|
|
|
// XPCOM objects participating in garbage-cycle collection are obliged
|
|
|
|
// to inform us when they ought to turn purple; that is, when their
|
|
|
|
// refcount transitions from N+1 -> N, for nonzero N. Furthermore we
|
|
|
|
// require that *after* an XPCOM object has informed us of turning
|
|
|
|
// purple, they will tell us when they either transition back to being
|
|
|
|
// black (incremented refcount) or are ultimately deleted.
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
// Incremental cycle collection
|
|
|
|
//
|
|
|
|
// Beyond the simple state machine required to implement incremental
|
|
|
|
// collection, the CC needs to be able to compensate for things the browser
|
|
|
|
// is doing during the collection. There are two kinds of problems. For each
|
|
|
|
// of these, there are two cases to deal with: purple-buffered C++ objects
|
|
|
|
// and JS objects.
|
|
|
|
|
|
|
|
// The first problem is that an object in the CC's graph can become garbage.
|
|
|
|
// This is bad because the CC touches the objects in its graph at every
|
|
|
|
// stage of its operation.
|
|
|
|
//
|
|
|
|
// All cycle collected C++ objects that die during a cycle collection
|
|
|
|
// will end up actually getting deleted by the SnowWhiteKiller. Before
|
|
|
|
// the SWK deletes an object, it checks if an ICC is running, and if so,
|
|
|
|
// if the object is in the graph. If it is, the CC clears mPointer and
|
|
|
|
// mParticipant so it does not point to the raw object any more. Because
|
|
|
|
// objects could die any time the CC returns to the mutator, any time the CC
|
|
|
|
// accesses a PtrInfo it must perform a null check on mParticipant to
|
|
|
|
// ensure the object has not gone away.
|
|
|
|
//
|
|
|
|
// JS objects don't always run finalizers, so the CC can't remove them from
|
|
|
|
// the graph when they die. Fortunately, JS objects can only die during a GC,
|
|
|
|
// so if a GC is begun during an ICC, the browser synchronously finishes off
|
|
|
|
// the ICC, which clears the entire CC graph. If the GC and CC are scheduled
|
|
|
|
// properly, this should be rare.
|
|
|
|
//
|
|
|
|
// The second problem is that objects in the graph can be changed, say by
|
|
|
|
// being addrefed or released, or by having a field updated, after the object
|
2013-12-18 07:29:57 +04:00
|
|
|
// has been added to the graph. The problem is that ICC can miss a newly
|
|
|
|
// created reference to an object, and end up unlinking an object that is
|
|
|
|
// actually alive.
|
|
|
|
//
|
|
|
|
// The basic idea of the solution, from "An on-the-fly Reference Counting
|
|
|
|
// Garbage Collector for Java" by Levanoni and Petrank, is to notice if an
|
|
|
|
// object has had an additional reference to it created during the collection,
|
|
|
|
// and if so, don't collect it during the current collection. This avoids having
|
|
|
|
// to rerun the scan as in Bacon & Rajan 2001.
|
|
|
|
//
|
|
|
|
// For cycle collected C++ objects, we modify AddRef to place the object in
|
|
|
|
// the purple buffer, in addition to Release. Then, in the CC, we treat any
|
|
|
|
// objects in the purple buffer as being alive, after graph building has
|
|
|
|
// completed. Because they are in the purple buffer, they will be suspected
|
|
|
|
// in the next CC, so there's no danger of leaks. This is imprecise, because
|
|
|
|
// we will treat as live an object that has been Released but not AddRefed
|
|
|
|
// during graph building, but that's probably rare enough that the additional
|
|
|
|
// bookkeeping overhead is not worthwhile.
|
|
|
|
//
|
|
|
|
// For JS objects, the cycle collector is only looking at gray objects. If a
|
|
|
|
// gray object is touched during ICC, it will be made black by UnmarkGray.
|
|
|
|
// Thus, if a JS object has become black during the ICC, we treat it as live.
|
|
|
|
// Merged JS zones have to be handled specially: we scan all zone globals.
|
|
|
|
// If any are black, we treat the zone as being black.
|
2013-12-06 22:17:20 +04:00
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
// Safety
|
2007-01-05 01:31:26 +03:00
|
|
|
//
|
|
|
|
// An XPCOM object is either scan-safe or scan-unsafe, purple-safe or
|
|
|
|
// purple-unsafe.
|
|
|
|
//
|
2013-05-02 02:35:13 +04:00
|
|
|
// An nsISupports object is scan-safe if:
|
2007-01-05 01:31:26 +03:00
|
|
|
//
|
2013-05-02 02:35:13 +04:00
|
|
|
// - It can be QI'ed to |nsXPCOMCycleCollectionParticipant|, though
|
|
|
|
// this operation loses ISupports identity (like nsIClassInfo).
|
|
|
|
// - Additionally, the operation |traverse| on the resulting
|
2007-05-24 18:10:02 +04:00
|
|
|
// nsXPCOMCycleCollectionParticipant does not cause *any* refcount
|
2007-01-05 01:31:26 +03:00
|
|
|
// adjustment to occur (no AddRef / Release calls).
|
|
|
|
//
|
2013-05-02 02:35:13 +04:00
|
|
|
// A non-nsISupports ("native") object is scan-safe by explicitly
|
|
|
|
// providing its nsCycleCollectionParticipant.
|
|
|
|
//
|
2007-01-05 01:31:26 +03:00
|
|
|
// An object is purple-safe if it satisfies the following properties:
|
|
|
|
//
|
2013-05-04 19:39:44 +04:00
|
|
|
// - The object is scan-safe.
|
2007-01-05 01:31:26 +03:00
|
|
|
//
|
|
|
|
// When we receive a pointer |ptr| via
|
|
|
|
// |nsCycleCollector::suspect(ptr)|, we assume it is purple-safe. We
|
|
|
|
// can check the scan-safety, but have no way to ensure the
|
|
|
|
// purple-safety; objects must obey, or else the entire system falls
|
|
|
|
// apart. Don't involve an object in this scheme if you can't
|
2013-05-02 02:35:13 +04:00
|
|
|
// guarantee its purple-safety. The easiest way to ensure that an
|
|
|
|
// object is purple-safe is to use nsCycleCollectingAutoRefCnt.
|
2007-01-05 01:31:26 +03:00
|
|
|
//
|
|
|
|
// When we have a scannable set of purple nodes ready, we begin
|
|
|
|
// our walks. During the walks, the nodes we |traverse| should only
|
|
|
|
// feed us more scan-safe nodes, and should not adjust the refcounts
|
2013-05-04 19:39:44 +04:00
|
|
|
// of those nodes.
|
2007-01-05 01:31:26 +03:00
|
|
|
//
|
|
|
|
// We do not |AddRef| or |Release| any objects during scanning. We
|
2013-05-02 02:35:13 +04:00
|
|
|
// rely on the purple-safety of the roots that call |suspect| to
|
|
|
|
// hold, such that we will clear the pointer from the purple buffer
|
|
|
|
// entry to the object before it is destroyed. The pointers that are
|
|
|
|
// merely scan-safe we hold only for the duration of scanning, and
|
|
|
|
// there should be no objects released from the scan-safe set during
|
|
|
|
// the scan.
|
2007-01-05 01:31:26 +03:00
|
|
|
//
|
2013-07-09 21:30:58 +04:00
|
|
|
// We *do* call |Root| and |Unroot| on every white object, on
|
2007-01-05 01:31:26 +03:00
|
|
|
// either side of the calls to |Unlink|. This keeps the set of white
|
|
|
|
// objects alive during the unlinking.
|
2013-05-04 19:39:44 +04:00
|
|
|
//
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2011-05-01 22:59:24 +04:00
|
|
|
#if !defined(__MINGW32__)
|
2007-01-05 01:31:26 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
2007-01-23 03:39:25 +03:00
|
|
|
#endif
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2011-10-07 00:22:43 +04:00
|
|
|
#include "base/process_util.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-11-21 02:35:16 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
|
|
|
#include "mozilla/CycleCollectedJSRuntime.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
/* This must occur *after* base/process_util.h to avoid typedefs conflicts. */
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-11-10 01:15:44 +04:00
|
|
|
#include "mozilla/LinkedList.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-05-21 00:08:11 +04:00
|
|
|
#include "nsCycleCollectionNoteRootCallback.h"
|
2007-01-05 01:31:26 +03:00
|
|
|
#include "nsDeque.h"
|
|
|
|
#include "nsCycleCollector.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "prenv.h"
|
2007-03-06 00:07:51 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2007-03-27 13:49:06 +04:00
|
|
|
#include "nsTArray.h"
|
2008-01-07 01:05:10 +03:00
|
|
|
#include "nsIConsoleService.h"
|
2012-06-06 03:51:58 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-08-12 04:03:23 +04:00
|
|
|
#include "nsICycleCollectorListener.h"
|
2011-07-09 02:49:31 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
2012-10-16 06:12:14 +04:00
|
|
|
#include "nsIFile.h"
|
2013-03-01 19:41:17 +04:00
|
|
|
#include "nsMemoryInfoDumper.h"
|
2011-03-29 00:05:48 +04:00
|
|
|
#include "xpcpublic.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2013-12-03 22:47:47 +04:00
|
|
|
#include "js/SliceBudget.h"
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2007-01-05 01:31:26 +03:00
|
|
|
#include <stdio.h>
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2013-11-05 16:45:20 +04:00
|
|
|
#include "mozilla/PoisonIOInterposer.h"
|
2011-06-21 01:47:58 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
2013-08-20 15:48:22 +04:00
|
|
|
#include "mozilla/ThreadLocal.h"
|
2010-11-12 01:52:30 +03:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-07-16 05:08:47 +04:00
|
|
|
//#define COLLECT_TIME_DEBUG
|
|
|
|
|
2013-04-25 19:42:44 +04:00
|
|
|
// Enable assertions that are useful for diagnosing errors in graph construction.
|
|
|
|
//#define DEBUG_CC_GRAPH
|
|
|
|
|
2009-10-23 08:47:27 +04:00
|
|
|
#define DEFAULT_SHUTDOWN_COLLECTIONS 5
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-05-24 22:26:09 +04:00
|
|
|
// One to do the freeing, then another to detect there is no more work to do.
|
|
|
|
#define NORMAL_SHUTDOWN_COLLECTIONS 2
|
|
|
|
|
2012-12-20 02:35:50 +04:00
|
|
|
// Cycle collector environment variables
|
|
|
|
//
|
|
|
|
// XPCOM_CC_LOG_ALL: If defined, always log cycle collector heaps.
|
|
|
|
//
|
|
|
|
// XPCOM_CC_LOG_SHUTDOWN: If defined, log cycle collector heaps at shutdown.
|
|
|
|
//
|
|
|
|
// XPCOM_CC_ALL_TRACES_AT_SHUTDOWN: If defined, any cycle collector
|
|
|
|
// logging done at shutdown will be WantAllTraces, which disables
|
|
|
|
// various cycle collector optimizations to give a fuller picture of
|
|
|
|
// the heap.
|
|
|
|
//
|
2013-02-27 01:34:32 +04:00
|
|
|
// XPCOM_CC_RUN_DURING_SHUTDOWN: In non-DEBUG or builds, if this is set,
|
|
|
|
// run cycle collections at shutdown.
|
2013-02-22 06:10:59 +04:00
|
|
|
//
|
|
|
|
// MOZ_CC_LOG_DIRECTORY: The directory in which logs are placed (such as
|
|
|
|
// logs from XPCOM_CC_LOG_ALL and XPCOM_CC_LOG_SHUTDOWN, or other uses
|
|
|
|
// of nsICycleCollectorListener)
|
2012-09-28 21:11:33 +04:00
|
|
|
|
2012-02-21 00:13:29 +04:00
|
|
|
MOZ_NEVER_INLINE void
|
|
|
|
CC_AbortIfNull(void *ptr)
|
|
|
|
{
|
|
|
|
if (!ptr)
|
2012-06-08 01:41:11 +04:00
|
|
|
MOZ_CRASH();
|
2012-02-21 00:13:29 +04:00
|
|
|
}
|
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
// Various parameters of this collector can be tuned using environment
|
|
|
|
// variables.
|
|
|
|
|
|
|
|
struct nsCycleCollectorParams
|
|
|
|
{
|
2012-12-20 02:35:50 +04:00
|
|
|
bool mLogAll;
|
|
|
|
bool mLogShutdown;
|
|
|
|
bool mAllTracesAtShutdown;
|
2013-05-04 19:39:44 +04:00
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
nsCycleCollectorParams() :
|
2013-10-11 00:41:00 +04:00
|
|
|
mLogAll (PR_GetEnv("XPCOM_CC_LOG_ALL") != nullptr),
|
|
|
|
mLogShutdown (PR_GetEnv("XPCOM_CC_LOG_SHUTDOWN") != nullptr),
|
|
|
|
mAllTracesAtShutdown (PR_GetEnv("XPCOM_CC_ALL_TRACES_AT_SHUTDOWN") != nullptr)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-12 20:02:01 +04:00
|
|
|
#ifdef COLLECT_TIME_DEBUG
|
|
|
|
class TimeLog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TimeLog() : mLastCheckpoint(TimeStamp::Now()) {}
|
|
|
|
|
|
|
|
void
|
|
|
|
Checkpoint(const char* aEvent)
|
|
|
|
{
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dur = (uint32_t) ((now - mLastCheckpoint).ToMilliseconds());
|
2012-02-12 20:02:01 +04:00
|
|
|
if (dur > 0) {
|
|
|
|
printf("cc: %s took %dms\n", aEvent, dur);
|
|
|
|
}
|
|
|
|
mLastCheckpoint = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TimeStamp mLastCheckpoint;
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
class TimeLog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TimeLog() {}
|
|
|
|
void Checkpoint(const char* aEvent) {}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Base types
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
struct PtrInfo;
|
|
|
|
|
|
|
|
class EdgePool
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// EdgePool allocates arrays of void*, primarily to hold PtrInfo*.
|
|
|
|
// However, at the end of a block, the last two pointers are a null
|
|
|
|
// and then a void** pointing to the next block. This allows
|
|
|
|
// EdgePool::Iterators to be a single word but still capable of crossing
|
|
|
|
// block boundaries.
|
|
|
|
|
|
|
|
EdgePool()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mSentinelAndBlocks[0].block = nullptr;
|
|
|
|
mSentinelAndBlocks[1].block = nullptr;
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~EdgePool()
|
2008-01-10 17:10:03 +03:00
|
|
|
{
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(!mSentinelAndBlocks[0].block &&
|
|
|
|
!mSentinelAndBlocks[1].block,
|
|
|
|
"Didn't call Clear()?");
|
2008-01-10 17:10:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
|
|
|
Block *b = Blocks();
|
|
|
|
while (b) {
|
|
|
|
Block *next = b->Next();
|
|
|
|
delete b;
|
|
|
|
b = next;
|
|
|
|
}
|
2008-01-10 17:10:03 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mSentinelAndBlocks[0].block = nullptr;
|
|
|
|
mSentinelAndBlocks[1].block = nullptr;
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool IsEmpty()
|
|
|
|
{
|
|
|
|
return !mSentinelAndBlocks[0].block &&
|
|
|
|
!mSentinelAndBlocks[1].block;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
private:
|
|
|
|
struct Block;
|
|
|
|
union PtrInfoOrBlock {
|
|
|
|
// Use a union to avoid reinterpret_cast and the ensuing
|
|
|
|
// potential aliasing bugs.
|
|
|
|
PtrInfo *ptrInfo;
|
|
|
|
Block *block;
|
|
|
|
};
|
|
|
|
struct Block {
|
2011-06-18 03:19:41 +04:00
|
|
|
enum { BlockSize = 16 * 1024 };
|
2007-04-26 01:12:11 +04:00
|
|
|
|
|
|
|
PtrInfoOrBlock mPointers[BlockSize];
|
|
|
|
Block() {
|
2012-07-30 18:20:58 +04:00
|
|
|
mPointers[BlockSize - 2].block = nullptr; // sentinel
|
|
|
|
mPointers[BlockSize - 1].block = nullptr; // next block pointer
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
2012-11-07 05:38:29 +04:00
|
|
|
Block*& Next() { return mPointers[BlockSize - 1].block; }
|
|
|
|
PtrInfoOrBlock* Start() { return &mPointers[0]; }
|
|
|
|
PtrInfoOrBlock* End() { return &mPointers[BlockSize - 2]; }
|
2007-04-26 01:12:11 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Store the null sentinel so that we can have valid iterators
|
|
|
|
// before adding any edges and without adding any blocks.
|
|
|
|
PtrInfoOrBlock mSentinelAndBlocks[2];
|
|
|
|
|
2012-11-07 05:38:29 +04:00
|
|
|
Block*& Blocks() { return mSentinelAndBlocks[1].block; }
|
|
|
|
Block* Blocks() const { return mSentinelAndBlocks[1].block; }
|
2007-04-26 01:12:11 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
class Iterator
|
|
|
|
{
|
|
|
|
public:
|
2012-07-30 18:20:58 +04:00
|
|
|
Iterator() : mPointer(nullptr) {}
|
2007-04-26 01:12:11 +04:00
|
|
|
Iterator(PtrInfoOrBlock *aPointer) : mPointer(aPointer) {}
|
|
|
|
Iterator(const Iterator& aOther) : mPointer(aOther.mPointer) {}
|
|
|
|
|
|
|
|
Iterator& operator++()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mPointer->ptrInfo == nullptr) {
|
2007-04-26 01:12:11 +04:00
|
|
|
// Null pointer is a sentinel for link to the next block.
|
|
|
|
mPointer = (mPointer + 1)->block->mPointers;
|
|
|
|
}
|
|
|
|
++mPointer;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PtrInfo* operator*() const
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mPointer->ptrInfo == nullptr) {
|
2007-04-26 01:12:11 +04:00
|
|
|
// Null pointer is a sentinel for link to the next block.
|
|
|
|
return (mPointer + 1)->block->mPointers->ptrInfo;
|
|
|
|
}
|
|
|
|
return mPointer->ptrInfo;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool operator==(const Iterator& aOther) const
|
2007-04-26 01:12:11 +04:00
|
|
|
{ return mPointer == aOther.mPointer; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool operator!=(const Iterator& aOther) const
|
2007-04-26 01:12:11 +04:00
|
|
|
{ return mPointer != aOther.mPointer; }
|
|
|
|
|
2013-04-25 19:42:44 +04:00
|
|
|
#ifdef DEBUG_CC_GRAPH
|
|
|
|
bool Initialized() const
|
|
|
|
{
|
|
|
|
return mPointer != nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
private:
|
|
|
|
PtrInfoOrBlock *mPointer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Builder;
|
|
|
|
friend class Builder;
|
|
|
|
class Builder {
|
|
|
|
public:
|
|
|
|
Builder(EdgePool &aPool)
|
|
|
|
: mCurrent(&aPool.mSentinelAndBlocks[0]),
|
|
|
|
mBlockEnd(&aPool.mSentinelAndBlocks[0]),
|
2012-11-07 05:38:29 +04:00
|
|
|
mNextBlockPtr(&aPool.Blocks())
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-05-04 03:07:26 +04:00
|
|
|
Iterator Mark() { return Iterator(mCurrent); }
|
2007-04-26 01:12:11 +04:00
|
|
|
|
|
|
|
void Add(PtrInfo* aEdge) {
|
|
|
|
if (mCurrent == mBlockEnd) {
|
2007-05-04 03:07:26 +04:00
|
|
|
Block *b = new Block();
|
2007-04-26 01:12:11 +04:00
|
|
|
*mNextBlockPtr = b;
|
|
|
|
mCurrent = b->Start();
|
|
|
|
mBlockEnd = b->End();
|
|
|
|
mNextBlockPtr = &b->Next();
|
|
|
|
}
|
|
|
|
(mCurrent++)->ptrInfo = aEdge;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
// mBlockEnd points to space for null sentinel
|
|
|
|
PtrInfoOrBlock *mCurrent, *mBlockEnd;
|
2007-05-04 03:07:26 +04:00
|
|
|
Block **mNextBlockPtr;
|
2007-04-26 01:12:11 +04:00
|
|
|
};
|
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
|
2012-11-07 05:38:29 +04:00
|
|
|
size_t n = 0;
|
|
|
|
Block *b = Blocks();
|
|
|
|
while (b) {
|
|
|
|
n += aMallocSizeOf(b);
|
|
|
|
b = b->Next();
|
|
|
|
}
|
|
|
|
return n;
|
2011-07-09 02:49:31 +04:00
|
|
|
}
|
2007-04-26 01:12:11 +04:00
|
|
|
};
|
|
|
|
|
2013-04-25 19:42:44 +04:00
|
|
|
#ifdef DEBUG_CC_GRAPH
|
|
|
|
#define CC_GRAPH_ASSERT(b) MOZ_ASSERT(b)
|
|
|
|
#else
|
|
|
|
#define CC_GRAPH_ASSERT(b)
|
|
|
|
#endif
|
|
|
|
|
2013-09-10 19:29:45 +04:00
|
|
|
#define CC_TELEMETRY(_name, _value) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (NS_IsMainThread()) { \
|
|
|
|
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR##_name, _value); \
|
|
|
|
} else { \
|
|
|
|
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR_WORKER##_name, _value); \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
enum NodeColor { black, white, grey };
|
|
|
|
|
2007-04-20 12:01:01 +04:00
|
|
|
// This structure should be kept as small as possible; we may expect
|
2011-06-18 03:19:41 +04:00
|
|
|
// hundreds of thousands of them to be allocated and touched
|
|
|
|
// repeatedly during each cycle collection.
|
2007-04-20 12:01:01 +04:00
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
struct PtrInfo
|
|
|
|
{
|
2007-04-26 01:12:11 +04:00
|
|
|
void *mPointer;
|
2007-05-24 18:10:02 +04:00
|
|
|
nsCycleCollectionParticipant *mParticipant;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mColor : 2;
|
|
|
|
uint32_t mInternalRefs : 30;
|
|
|
|
uint32_t mRefCount;
|
2011-06-10 01:55:04 +04:00
|
|
|
private:
|
|
|
|
EdgePool::Iterator mFirstChild;
|
2007-04-20 12:01:01 +04:00
|
|
|
|
2011-06-10 01:55:04 +04:00
|
|
|
public:
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2012-05-03 23:28:11 +04:00
|
|
|
PtrInfo(void *aPointer, nsCycleCollectionParticipant *aParticipant)
|
2007-04-26 01:12:11 +04:00
|
|
|
: mPointer(aPointer),
|
2007-05-24 18:10:02 +04:00
|
|
|
mParticipant(aParticipant),
|
2007-04-26 01:12:11 +04:00
|
|
|
mColor(grey),
|
|
|
|
mInternalRefs(0),
|
2013-12-06 22:17:20 +04:00
|
|
|
mRefCount(UINT32_MAX - 1),
|
2011-06-10 01:55:04 +04:00
|
|
|
mFirstChild()
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
2013-12-06 22:17:20 +04:00
|
|
|
// We initialize mRefCount to a large non-zero value so
|
|
|
|
// that it doesn't look like a JS object to the cycle collector
|
|
|
|
// in the case where the object dies before being traversed.
|
|
|
|
|
2012-05-03 23:28:10 +04:00
|
|
|
MOZ_ASSERT(aParticipant);
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
2007-04-20 12:01:01 +04:00
|
|
|
|
2008-03-18 02:11:08 +03:00
|
|
|
// Allow NodePool::Block's constructor to compile.
|
|
|
|
PtrInfo() {
|
|
|
|
NS_NOTREACHED("should never be called");
|
|
|
|
}
|
2011-06-10 01:55:04 +04:00
|
|
|
|
|
|
|
EdgePool::Iterator FirstChild()
|
|
|
|
{
|
2013-04-25 19:42:44 +04:00
|
|
|
CC_GRAPH_ASSERT(mFirstChild.Initialized());
|
2011-06-10 01:55:04 +04:00
|
|
|
return mFirstChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this PtrInfo must be part of a NodePool
|
|
|
|
EdgePool::Iterator LastChild()
|
|
|
|
{
|
2013-04-25 19:42:44 +04:00
|
|
|
CC_GRAPH_ASSERT((this + 1)->mFirstChild.Initialized());
|
2011-06-10 01:55:04 +04:00
|
|
|
return (this + 1)->mFirstChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFirstChild(EdgePool::Iterator aFirstChild)
|
|
|
|
{
|
2013-04-25 19:42:44 +04:00
|
|
|
CC_GRAPH_ASSERT(aFirstChild.Initialized());
|
2011-06-10 01:55:04 +04:00
|
|
|
mFirstChild = aFirstChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this PtrInfo must be part of a NodePool
|
|
|
|
void SetLastChild(EdgePool::Iterator aLastChild)
|
|
|
|
{
|
2013-04-25 19:42:44 +04:00
|
|
|
CC_GRAPH_ASSERT(aLastChild.Initialized());
|
2011-06-10 01:55:04 +04:00
|
|
|
(this + 1)->mFirstChild = aLastChild;
|
|
|
|
}
|
2007-04-26 01:12:11 +04:00
|
|
|
};
|
2007-04-20 12:01:01 +04:00
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
/**
|
|
|
|
* A structure designed to be used like a linked list of PtrInfo, except
|
|
|
|
* that allocates the PtrInfo 32K-at-a-time.
|
|
|
|
*/
|
|
|
|
class NodePool
|
2007-04-20 12:01:01 +04:00
|
|
|
{
|
2007-04-26 01:12:11 +04:00
|
|
|
private:
|
2011-06-18 03:19:41 +04:00
|
|
|
enum { BlockSize = 8 * 1024 }; // could be int template parameter
|
2007-04-20 12:01:01 +04:00
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
struct Block {
|
2008-03-18 02:11:08 +03:00
|
|
|
// We create and destroy Block using NS_Alloc/NS_Free rather
|
|
|
|
// than new and delete to avoid calling its constructor and
|
|
|
|
// destructor.
|
2012-11-07 05:38:29 +04:00
|
|
|
Block() { NS_NOTREACHED("should never be called"); }
|
2008-03-18 02:11:08 +03:00
|
|
|
~Block() { NS_NOTREACHED("should never be called"); }
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
Block* mNext;
|
2011-06-10 01:55:04 +04:00
|
|
|
PtrInfo mEntries[BlockSize + 1]; // +1 to store last child of last node
|
2007-04-26 01:12:11 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
NodePool()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mBlocks(nullptr),
|
2012-11-07 05:38:29 +04:00
|
|
|
mLast(nullptr)
|
2007-04-20 12:01:01 +04:00
|
|
|
{
|
|
|
|
}
|
2007-04-26 01:12:11 +04:00
|
|
|
|
|
|
|
~NodePool()
|
2008-01-10 17:10:03 +03:00
|
|
|
{
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(!mBlocks, "Didn't call Clear()?");
|
2008-01-10 17:10:03 +03:00
|
|
|
}
|
|
|
|
|
2010-08-18 11:46:54 +04:00
|
|
|
void Clear()
|
2007-04-20 12:01:01 +04:00
|
|
|
{
|
2007-04-26 01:12:11 +04:00
|
|
|
Block *b = mBlocks;
|
|
|
|
while (b) {
|
|
|
|
Block *n = b->mNext;
|
2008-03-18 02:11:08 +03:00
|
|
|
NS_Free(b);
|
2007-04-26 01:12:11 +04:00
|
|
|
b = n;
|
2007-04-24 03:34:33 +04:00
|
|
|
}
|
2008-01-10 17:10:03 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mBlocks = nullptr;
|
|
|
|
mLast = nullptr;
|
2007-04-20 12:01:01 +04:00
|
|
|
}
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool IsEmpty()
|
|
|
|
{
|
|
|
|
return !mBlocks && !mLast;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
class Builder;
|
|
|
|
friend class Builder;
|
|
|
|
class Builder {
|
|
|
|
public:
|
|
|
|
Builder(NodePool& aPool)
|
|
|
|
: mNextBlock(&aPool.mBlocks),
|
|
|
|
mNext(aPool.mLast),
|
2012-11-07 05:38:29 +04:00
|
|
|
mBlockEnd(nullptr)
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(aPool.mBlocks == nullptr && aPool.mLast == nullptr,
|
|
|
|
"pool not empty");
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
2012-05-03 23:28:11 +04:00
|
|
|
PtrInfo *Add(void *aPointer, nsCycleCollectionParticipant *aParticipant)
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
|
|
|
if (mNext == mBlockEnd) {
|
2013-04-30 21:41:23 +04:00
|
|
|
Block *block = static_cast<Block*>(NS_Alloc(sizeof(Block)));
|
|
|
|
*mNextBlock = block;
|
2007-04-26 01:12:11 +04:00
|
|
|
mNext = block->mEntries;
|
|
|
|
mBlockEnd = block->mEntries + BlockSize;
|
2012-07-30 18:20:58 +04:00
|
|
|
block->mNext = nullptr;
|
2007-04-26 01:12:11 +04:00
|
|
|
mNextBlock = &block->mNext;
|
|
|
|
}
|
2012-05-03 23:28:11 +04:00
|
|
|
return new (mNext++) PtrInfo(aPointer, aParticipant);
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
Block **mNextBlock;
|
|
|
|
PtrInfo *&mNext;
|
|
|
|
PtrInfo *mBlockEnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Enumerator;
|
|
|
|
friend class Enumerator;
|
|
|
|
class Enumerator {
|
|
|
|
public:
|
|
|
|
Enumerator(NodePool& aPool)
|
|
|
|
: mFirstBlock(aPool.mBlocks),
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurBlock(nullptr),
|
|
|
|
mNext(nullptr),
|
|
|
|
mBlockEnd(nullptr),
|
2007-04-26 01:12:11 +04:00
|
|
|
mLast(aPool.mLast)
|
|
|
|
{
|
|
|
|
}
|
2007-04-20 12:01:01 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDone() const
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
|
|
|
return mNext == mLast;
|
|
|
|
}
|
2007-04-20 12:01:01 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool AtBlockEnd() const
|
2011-06-10 01:55:29 +04:00
|
|
|
{
|
|
|
|
return mNext == mBlockEnd;
|
|
|
|
}
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
PtrInfo* GetNext()
|
|
|
|
{
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(!IsDone(), "calling GetNext when done");
|
2007-04-26 01:12:11 +04:00
|
|
|
if (mNext == mBlockEnd) {
|
|
|
|
Block *nextBlock = mCurBlock ? mCurBlock->mNext : mFirstBlock;
|
|
|
|
mNext = nextBlock->mEntries;
|
|
|
|
mBlockEnd = mNext + BlockSize;
|
|
|
|
mCurBlock = nextBlock;
|
|
|
|
}
|
|
|
|
return mNext++;
|
|
|
|
}
|
|
|
|
private:
|
2013-04-25 19:42:44 +04:00
|
|
|
// mFirstBlock is a reference to allow an Enumerator to be constructed
|
|
|
|
// for an empty graph.
|
|
|
|
Block *&mFirstBlock;
|
|
|
|
Block *mCurBlock;
|
2007-04-26 01:12:11 +04:00
|
|
|
// mNext is the next value we want to return, unless mNext == mBlockEnd
|
|
|
|
// NB: mLast is a reference to allow enumerating while building!
|
|
|
|
PtrInfo *mNext, *mBlockEnd, *&mLast;
|
|
|
|
};
|
2007-04-20 12:01:01 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
|
2012-11-07 05:38:29 +04:00
|
|
|
// We don't measure the things pointed to by mEntries[] because those
|
|
|
|
// pointers are non-owning.
|
|
|
|
size_t n = 0;
|
|
|
|
Block *b = mBlocks;
|
|
|
|
while (b) {
|
|
|
|
n += aMallocSizeOf(b);
|
|
|
|
b = b->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
2011-07-09 02:49:31 +04:00
|
|
|
}
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
private:
|
|
|
|
Block *mBlocks;
|
|
|
|
PtrInfo *mLast;
|
2007-01-05 01:31:26 +03:00
|
|
|
};
|
|
|
|
|
2007-06-19 05:29:10 +04:00
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
// Declarations for mPtrToNodeMap.
|
|
|
|
|
|
|
|
struct PtrToNodeEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
// The key is mNode->mPointer
|
|
|
|
PtrInfo *mNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
PtrToNodeMatchEntry(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const PtrToNodeEntry *n = static_cast<const PtrToNodeEntry*>(entry);
|
|
|
|
return n->mNode->mPointer == key;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashTableOps PtrNodeOps = {
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PtrToNodeMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
PL_DHashClearEntryStub,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-11-24 16:35:56 +04:00
|
|
|
struct WeakMapping
|
|
|
|
{
|
|
|
|
// map and key will be null if the corresponding objects are GC marked
|
|
|
|
PtrInfo *mMap;
|
|
|
|
PtrInfo *mKey;
|
2012-10-18 05:22:46 +04:00
|
|
|
PtrInfo *mKeyDelegate;
|
2011-11-24 16:35:56 +04:00
|
|
|
PtrInfo *mVal;
|
|
|
|
};
|
|
|
|
|
2007-11-02 01:51:57 +03:00
|
|
|
class GCGraphBuilder;
|
2007-06-19 05:29:10 +04:00
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
struct GCGraph
|
|
|
|
{
|
|
|
|
NodePool mNodes;
|
|
|
|
EdgePool mEdges;
|
2011-11-24 16:35:56 +04:00
|
|
|
nsTArray<WeakMapping> mWeakMaps;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mRootCount;
|
2007-04-26 01:12:11 +04:00
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
private:
|
|
|
|
PLDHashTable mPtrToNodeMap;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GCGraph() : mRootCount(0)
|
|
|
|
{
|
|
|
|
mPtrToNodeMap.ops = nullptr;
|
2007-06-19 05:29:10 +04:00
|
|
|
}
|
2013-11-21 02:35:17 +04:00
|
|
|
|
|
|
|
~GCGraph()
|
|
|
|
{
|
|
|
|
if (mPtrToNodeMap.ops) {
|
|
|
|
PL_DHashTableFinish(&mPtrToNodeMap);
|
|
|
|
}
|
2007-06-19 05:29:10 +04:00
|
|
|
}
|
2013-11-21 02:35:17 +04:00
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
2013-12-06 22:17:20 +04:00
|
|
|
MOZ_ASSERT(IsEmpty(), "Failed to call GCGraph::Clear");
|
2013-11-21 02:35:17 +04:00
|
|
|
if (!PL_DHashTableInit(&mPtrToNodeMap, &PtrNodeOps, nullptr,
|
|
|
|
sizeof(PtrToNodeEntry), 32768)) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2007-06-19 05:29:10 +04:00
|
|
|
}
|
2011-07-09 02:49:31 +04:00
|
|
|
|
2013-09-10 19:56:36 +04:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mNodes.Clear();
|
|
|
|
mEdges.Clear();
|
|
|
|
mWeakMaps.Clear();
|
|
|
|
mRootCount = 0;
|
2013-11-21 02:35:17 +04:00
|
|
|
PL_DHashTableFinish(&mPtrToNodeMap);
|
|
|
|
mPtrToNodeMap.ops = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool IsEmpty()
|
|
|
|
{
|
|
|
|
return mNodes.IsEmpty() && mEdges.IsEmpty() &&
|
|
|
|
mWeakMaps.IsEmpty() && mRootCount == 0 &&
|
|
|
|
!mPtrToNodeMap.ops;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
PtrInfo* FindNode(void *aPtr);
|
|
|
|
PtrToNodeEntry* AddNodeToMap(void *aPtr);
|
2013-12-06 22:17:20 +04:00
|
|
|
void RemoveNodeFromMap(void *aPtr);
|
2013-11-21 02:35:17 +04:00
|
|
|
|
|
|
|
uint32_t MapCount() const
|
|
|
|
{
|
|
|
|
return mPtrToNodeMap.entryCount;
|
2013-09-10 19:56:36 +04:00
|
|
|
}
|
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
|
2013-09-10 19:56:36 +04:00
|
|
|
size_t *aNodesSize, size_t *aEdgesSize,
|
|
|
|
size_t *aWeakMapsSize) const {
|
2012-11-07 05:38:29 +04:00
|
|
|
*aNodesSize = mNodes.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
*aEdgesSize = mEdges.SizeOfExcludingThis(aMallocSizeOf);
|
2011-07-09 02:49:31 +04:00
|
|
|
|
2013-09-10 19:56:36 +04:00
|
|
|
// We don't measure what the WeakMappings point to, because the
|
|
|
|
// pointers are non-owning.
|
|
|
|
*aWeakMapsSize = mWeakMaps.SizeOfExcludingThis(aMallocSizeOf);
|
2012-11-07 05:38:29 +04:00
|
|
|
}
|
2007-04-26 01:12:11 +04:00
|
|
|
};
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
PtrInfo*
|
|
|
|
GCGraph::FindNode(void *aPtr)
|
|
|
|
{
|
|
|
|
PtrToNodeEntry *e = static_cast<PtrToNodeEntry*>(PL_DHashTableOperate(&mPtrToNodeMap, aPtr, PL_DHASH_LOOKUP));
|
|
|
|
if (!PL_DHASH_ENTRY_IS_BUSY(e)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return e->mNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
PtrToNodeEntry*
|
|
|
|
GCGraph::AddNodeToMap(void *aPtr)
|
|
|
|
{
|
|
|
|
PtrToNodeEntry *e = static_cast<PtrToNodeEntry*>(PL_DHashTableOperate(&mPtrToNodeMap, aPtr, PL_DHASH_ADD));
|
|
|
|
if (!e) {
|
|
|
|
// Caller should track OOMs
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
void
|
|
|
|
GCGraph::RemoveNodeFromMap(void *aPtr)
|
|
|
|
{
|
|
|
|
PL_DHashTableOperate(&mPtrToNodeMap, aPtr, PL_DHASH_REMOVE);
|
|
|
|
}
|
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
|
2012-08-24 20:50:06 +04:00
|
|
|
static nsISupports *
|
|
|
|
CanonicalizeXPCOMParticipant(nsISupports *in)
|
|
|
|
{
|
|
|
|
nsISupports* out;
|
|
|
|
in->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
|
|
|
|
reinterpret_cast<void**>(&out));
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2009-06-01 23:22:18 +04:00
|
|
|
static inline void
|
|
|
|
ToParticipant(nsISupports *s, nsXPCOMCycleCollectionParticipant **cp);
|
|
|
|
|
2012-08-24 20:50:06 +04:00
|
|
|
static void
|
|
|
|
CanonicalizeParticipant(void **parti, nsCycleCollectionParticipant **cp)
|
|
|
|
{
|
|
|
|
// If the participant is null, this is an nsISupports participant,
|
|
|
|
// so we must QI to get the real participant.
|
|
|
|
|
|
|
|
if (!*cp) {
|
|
|
|
nsISupports *nsparti = static_cast<nsISupports*>(*parti);
|
|
|
|
nsparti = CanonicalizeXPCOMParticipant(nsparti);
|
|
|
|
NS_ASSERTION(nsparti,
|
|
|
|
"Don't add objects that don't participate in collection!");
|
|
|
|
nsXPCOMCycleCollectionParticipant *xcp;
|
|
|
|
ToParticipant(nsparti, &xcp);
|
|
|
|
*parti = nsparti;
|
|
|
|
*cp = xcp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 23:29:59 +04:00
|
|
|
struct nsPurpleBufferEntry {
|
|
|
|
union {
|
|
|
|
void *mObject; // when low bit unset
|
|
|
|
nsPurpleBufferEntry *mNextInFreeList; // when low bit set
|
|
|
|
};
|
|
|
|
|
|
|
|
nsCycleCollectingAutoRefCnt *mRefCnt;
|
|
|
|
|
|
|
|
nsCycleCollectionParticipant *mParticipant; // nullptr for nsISupports
|
|
|
|
};
|
|
|
|
|
2013-07-27 14:48:45 +04:00
|
|
|
class nsCycleCollector;
|
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
struct nsPurpleBuffer
|
|
|
|
{
|
2009-05-07 00:46:04 +04:00
|
|
|
private:
|
|
|
|
struct Block {
|
|
|
|
Block *mNext;
|
2012-11-07 05:38:29 +04:00
|
|
|
// Try to match the size of a jemalloc bucket, to minimize slop bytes.
|
|
|
|
// - On 32-bit platforms sizeof(nsPurpleBufferEntry) is 12, so mEntries
|
|
|
|
// is 16,380 bytes, which leaves 4 bytes for mNext.
|
|
|
|
// - On 64-bit platforms sizeof(nsPurpleBufferEntry) is 24, so mEntries
|
|
|
|
// is 32,544 bytes, which leaves 8 bytes for mNext.
|
|
|
|
nsPurpleBufferEntry mEntries[1365];
|
|
|
|
|
|
|
|
Block() : mNext(nullptr) {
|
|
|
|
// Ensure Block is the right size (see above).
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(
|
2012-11-07 05:38:29 +04:00
|
|
|
sizeof(Block) == 16384 || // 32-bit
|
|
|
|
sizeof(Block) == 32768, // 64-bit
|
|
|
|
"ill-sized nsPurpleBuffer::Block"
|
|
|
|
);
|
|
|
|
}
|
2013-04-30 21:41:23 +04:00
|
|
|
|
|
|
|
template <class PurpleVisitor>
|
|
|
|
void VisitEntries(nsPurpleBuffer &aBuffer, PurpleVisitor &aVisitor)
|
|
|
|
{
|
|
|
|
nsPurpleBufferEntry *eEnd = ArrayEnd(mEntries);
|
|
|
|
for (nsPurpleBufferEntry *e = mEntries; e != eEnd; ++e) {
|
|
|
|
if (!(uintptr_t(e->mObject) & uintptr_t(1))) {
|
|
|
|
aVisitor.Visit(aBuffer, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-07 00:46:04 +04:00
|
|
|
};
|
|
|
|
// This class wraps a linked list of the elements in the purple
|
|
|
|
// buffer.
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCount;
|
2009-05-07 00:46:04 +04:00
|
|
|
Block mFirstBlock;
|
|
|
|
nsPurpleBufferEntry *mFreeList;
|
|
|
|
|
2013-04-30 21:41:23 +04:00
|
|
|
public:
|
2013-05-18 03:59:34 +04:00
|
|
|
nsPurpleBuffer()
|
2007-04-21 21:43:19 +04:00
|
|
|
{
|
2009-05-07 00:46:04 +04:00
|
|
|
InitBlocks();
|
2007-04-21 21:43:19 +04:00
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
|
|
|
|
~nsPurpleBuffer()
|
|
|
|
{
|
2009-05-07 00:46:04 +04:00
|
|
|
FreeBlocks();
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2013-04-30 21:41:23 +04:00
|
|
|
template <class PurpleVisitor>
|
|
|
|
void VisitEntries(PurpleVisitor &aVisitor)
|
|
|
|
{
|
|
|
|
for (Block *b = &mFirstBlock; b; b = b->mNext) {
|
|
|
|
b->VisitEntries(*this, aVisitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-07 00:46:04 +04:00
|
|
|
void InitBlocks()
|
2007-04-21 21:43:19 +04:00
|
|
|
{
|
2009-05-07 00:46:04 +04:00
|
|
|
mCount = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
mFreeList = nullptr;
|
2009-05-07 00:46:04 +04:00
|
|
|
StartBlock(&mFirstBlock);
|
2007-04-21 21:43:19 +04:00
|
|
|
}
|
|
|
|
|
2009-05-07 00:46:04 +04:00
|
|
|
void StartBlock(Block *aBlock)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2009-05-07 00:46:04 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mFreeList, "should not have free list");
|
|
|
|
|
|
|
|
// Put all the entries in the block on the free list.
|
|
|
|
nsPurpleBufferEntry *entries = aBlock->mEntries;
|
|
|
|
mFreeList = entries;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 1; i < ArrayLength(aBlock->mEntries); ++i) {
|
2009-05-07 00:46:04 +04:00
|
|
|
entries[i - 1].mNextInFreeList =
|
2012-04-12 04:17:44 +04:00
|
|
|
(nsPurpleBufferEntry*)(uintptr_t(entries + i) | 1);
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2011-10-11 09:50:08 +04:00
|
|
|
entries[ArrayLength(aBlock->mEntries) - 1].mNextInFreeList =
|
2009-05-07 00:46:04 +04:00
|
|
|
(nsPurpleBufferEntry*)1;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2009-05-07 00:46:04 +04:00
|
|
|
void FreeBlocks()
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2009-06-01 23:22:18 +04:00
|
|
|
if (mCount > 0)
|
|
|
|
UnmarkRemainingPurple(&mFirstBlock);
|
2012-11-07 05:38:29 +04:00
|
|
|
Block *b = mFirstBlock.mNext;
|
2009-05-07 00:46:04 +04:00
|
|
|
while (b) {
|
2009-06-01 23:22:18 +04:00
|
|
|
if (mCount > 0)
|
|
|
|
UnmarkRemainingPurple(b);
|
2009-05-07 00:46:04 +04:00
|
|
|
Block *next = b->mNext;
|
|
|
|
delete b;
|
|
|
|
b = next;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mFirstBlock.mNext = nullptr;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2013-04-30 21:41:23 +04:00
|
|
|
struct UnmarkRemainingPurpleVisitor
|
2009-06-01 23:22:18 +04:00
|
|
|
{
|
2013-04-30 21:41:23 +04:00
|
|
|
void
|
|
|
|
Visit(nsPurpleBuffer &aBuffer, nsPurpleBufferEntry *aEntry)
|
|
|
|
{
|
2013-07-09 21:30:58 +04:00
|
|
|
if (aEntry->mRefCnt) {
|
|
|
|
aEntry->mRefCnt->RemoveFromPurpleBuffer();
|
|
|
|
aEntry->mRefCnt = nullptr;
|
2009-06-01 23:22:18 +04:00
|
|
|
}
|
2013-07-09 21:30:58 +04:00
|
|
|
aEntry->mObject = nullptr;
|
2013-05-10 00:19:00 +04:00
|
|
|
--aBuffer.mCount;
|
2009-06-01 23:22:18 +04:00
|
|
|
}
|
2013-04-30 21:41:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void UnmarkRemainingPurple(Block *b)
|
|
|
|
{
|
|
|
|
UnmarkRemainingPurpleVisitor visitor;
|
|
|
|
b->VisitEntries(*this, visitor);
|
2009-06-01 23:22:18 +04:00
|
|
|
}
|
|
|
|
|
2009-05-07 00:46:04 +04:00
|
|
|
void SelectPointers(GCGraphBuilder &builder);
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-07-27 14:48:45 +04:00
|
|
|
// RemoveSkippable removes entries from the purple buffer synchronously
|
|
|
|
// (1) if aAsyncSnowWhiteFreeing is false and nsPurpleBufferEntry::mRefCnt is 0 or
|
|
|
|
// (2) if the object's nsXPCOMCycleCollectionParticipant::CanSkip() returns true or
|
|
|
|
// (3) if nsPurpleBufferEntry::mRefCnt->IsPurple() is false.
|
|
|
|
// (4) If removeChildlessNodes is true, then any nodes in the purple buffer
|
|
|
|
// that will have no children in the cycle collector graph will also be
|
|
|
|
// removed. CanSkip() may be run on these children.
|
|
|
|
void RemoveSkippable(nsCycleCollector* aCollector,
|
|
|
|
bool removeChildlessNodes,
|
|
|
|
bool aAsyncSnowWhiteFreeing,
|
2013-07-09 21:30:58 +04:00
|
|
|
CC_ForgetSkippableCallback aCb);
|
2012-01-14 20:58:05 +04:00
|
|
|
|
2013-10-17 18:05:13 +04:00
|
|
|
MOZ_ALWAYS_INLINE nsPurpleBufferEntry* NewEntry()
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-10-17 18:05:13 +04:00
|
|
|
if (MOZ_UNLIKELY(!mFreeList)) {
|
2009-05-07 00:46:04 +04:00
|
|
|
Block *b = new Block;
|
|
|
|
StartBlock(b);
|
|
|
|
|
|
|
|
// Add the new block as the second block in the list.
|
|
|
|
b->mNext = mFirstBlock.mNext;
|
|
|
|
mFirstBlock.mNext = b;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2009-05-07 00:46:04 +04:00
|
|
|
|
|
|
|
nsPurpleBufferEntry *e = mFreeList;
|
|
|
|
mFreeList = (nsPurpleBufferEntry*)
|
2012-04-12 04:17:44 +04:00
|
|
|
(uintptr_t(mFreeList->mNextInFreeList) & ~uintptr_t(1));
|
2009-05-07 00:46:04 +04:00
|
|
|
return e;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2008-02-25 20:47:25 +03:00
|
|
|
|
2013-10-17 18:05:13 +04:00
|
|
|
MOZ_ALWAYS_INLINE void Put(void *p, nsCycleCollectionParticipant *cp,
|
|
|
|
nsCycleCollectingAutoRefCnt *aRefCnt)
|
2008-02-25 20:47:25 +03:00
|
|
|
{
|
2009-05-07 00:46:04 +04:00
|
|
|
nsPurpleBufferEntry *e = NewEntry();
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2009-05-07 00:46:04 +04:00
|
|
|
++mCount;
|
|
|
|
|
|
|
|
e->mObject = p;
|
2013-07-09 21:30:58 +04:00
|
|
|
e->mRefCnt = aRefCnt;
|
2012-08-24 20:50:06 +04:00
|
|
|
e->mParticipant = cp;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2009-05-07 00:46:04 +04:00
|
|
|
|
|
|
|
void Remove(nsPurpleBufferEntry *e)
|
|
|
|
{
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(mCount != 0, "must have entries");
|
2009-05-07 00:46:04 +04:00
|
|
|
|
2013-07-09 21:30:58 +04:00
|
|
|
if (e->mRefCnt) {
|
|
|
|
e->mRefCnt->RemoveFromPurpleBuffer();
|
|
|
|
e->mRefCnt = nullptr;
|
|
|
|
}
|
2009-05-07 00:46:04 +04:00
|
|
|
e->mNextInFreeList =
|
2012-04-12 04:17:44 +04:00
|
|
|
(nsPurpleBufferEntry*)(uintptr_t(mFreeList) | uintptr_t(1));
|
2009-05-07 00:46:04 +04:00
|
|
|
mFreeList = e;
|
|
|
|
|
|
|
|
--mCount;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t Count() const
|
2009-05-07 00:46:04 +04:00
|
|
|
{
|
|
|
|
return mCount;
|
|
|
|
}
|
2011-07-09 02:49:31 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-07-09 02:49:31 +04:00
|
|
|
{
|
2012-11-07 05:38:29 +04:00
|
|
|
size_t n = 0;
|
|
|
|
|
|
|
|
// Don't measure mFirstBlock because it's within |this|.
|
|
|
|
const Block *block = mFirstBlock.mNext;
|
|
|
|
while (block) {
|
|
|
|
n += aMallocSizeOf(block);
|
|
|
|
block = block->mNext;
|
|
|
|
}
|
2011-07-09 02:49:31 +04:00
|
|
|
|
2013-05-18 03:59:34 +04:00
|
|
|
// mFreeList is deliberately not measured because it points into
|
|
|
|
// the purple buffer, which is within mFirstBlock and thus within |this|.
|
2012-11-07 05:38:29 +04:00
|
|
|
//
|
|
|
|
// We also don't measure the things pointed to by mEntries[] because
|
|
|
|
// those pointers are non-owning.
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
2009-05-07 00:46:04 +04:00
|
|
|
};
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2012-08-24 20:50:06 +04:00
|
|
|
static bool
|
2013-09-07 00:40:34 +04:00
|
|
|
AddPurpleRoot(GCGraphBuilder &aBuilder, void *aRoot, nsCycleCollectionParticipant *aParti);
|
2012-08-24 20:50:06 +04:00
|
|
|
|
2013-04-30 21:41:23 +04:00
|
|
|
struct SelectPointersVisitor
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-04-30 21:41:23 +04:00
|
|
|
SelectPointersVisitor(GCGraphBuilder &aBuilder)
|
|
|
|
: mBuilder(aBuilder)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
Visit(nsPurpleBuffer &aBuffer, nsPurpleBufferEntry *aEntry)
|
|
|
|
{
|
2013-07-18 20:07:28 +04:00
|
|
|
MOZ_ASSERT(aEntry->mObject, "Null object in purple buffer");
|
|
|
|
MOZ_ASSERT(aEntry->mRefCnt->get() != 0,
|
2013-07-09 21:30:58 +04:00
|
|
|
"SelectPointersVisitor: snow-white object in the purple buffer");
|
2013-07-18 20:07:28 +04:00
|
|
|
if (!aEntry->mRefCnt->IsPurple() ||
|
2013-07-09 21:30:58 +04:00
|
|
|
AddPurpleRoot(mBuilder, aEntry->mObject, aEntry->mParticipant)) {
|
2013-04-30 21:41:23 +04:00
|
|
|
aBuffer.Remove(aEntry);
|
2009-05-07 00:46:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-30 21:41:23 +04:00
|
|
|
private:
|
|
|
|
GCGraphBuilder &mBuilder;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPurpleBuffer::SelectPointers(GCGraphBuilder &aBuilder)
|
|
|
|
{
|
|
|
|
SelectPointersVisitor visitor(aBuilder);
|
|
|
|
VisitEntries(visitor);
|
|
|
|
|
2013-05-10 00:19:00 +04:00
|
|
|
NS_ASSERTION(mCount == 0, "AddPurpleRoot failed");
|
2009-05-07 00:46:04 +04:00
|
|
|
if (mCount == 0) {
|
|
|
|
FreeBlocks();
|
|
|
|
InitBlocks();
|
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2013-12-03 22:47:46 +04:00
|
|
|
enum ccPhase {
|
|
|
|
IdlePhase,
|
|
|
|
GraphBuildingPhase,
|
|
|
|
ScanAndCollectWhitePhase,
|
|
|
|
CleanupPhase
|
|
|
|
};
|
|
|
|
|
2013-04-30 03:41:41 +04:00
|
|
|
enum ccType {
|
|
|
|
ScheduledCC, /* Automatically triggered, based on time or the purple buffer. */
|
|
|
|
ManualCC, /* Explicitly triggered. */
|
|
|
|
ShutdownCC /* Shutdown CC, used for finding leaks. */
|
|
|
|
};
|
|
|
|
|
2013-06-03 14:14:42 +04:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
#include "ipc/Nuwa.h"
|
|
|
|
#endif
|
|
|
|
|
2007-03-27 13:49:06 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2012-05-03 23:28:11 +04:00
|
|
|
// Top level structure for the cycle collector.
|
2007-03-27 13:49:06 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-12-03 22:47:47 +04:00
|
|
|
typedef js::SliceBudget SliceBudget;
|
|
|
|
|
2013-12-08 09:39:47 +04:00
|
|
|
class nsCycleCollector : public nsIMemoryReporter
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-11-26 03:57:53 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2013-12-08 09:39:47 +04:00
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2013-11-26 03:57:53 +04:00
|
|
|
|
2013-12-03 22:47:47 +04:00
|
|
|
bool mActivelyCollecting;
|
2013-09-07 00:40:34 +04:00
|
|
|
// mScanInProgress should be false when we're collecting white objects.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mScanInProgress;
|
2013-11-21 02:35:16 +04:00
|
|
|
CycleCollectorResults mResults;
|
2011-05-12 22:22:25 +04:00
|
|
|
TimeStamp mCollectionStart;
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
CycleCollectedJSRuntime *mJSRuntime;
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-12-03 22:47:46 +04:00
|
|
|
ccPhase mIncrementalPhase;
|
2008-01-10 17:10:03 +03:00
|
|
|
GCGraph mGraph;
|
2013-11-21 02:35:15 +04:00
|
|
|
nsAutoPtr<GCGraphBuilder> mBuilder;
|
2013-12-03 22:47:47 +04:00
|
|
|
nsAutoPtr<NodePool::Enumerator> mCurrNode;
|
2013-11-21 02:35:15 +04:00
|
|
|
nsCOMPtr<nsICycleCollectorListener> mListener;
|
2008-01-10 17:10:03 +03:00
|
|
|
|
2013-08-04 03:55:40 +04:00
|
|
|
nsIThread* mThread;
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
nsCycleCollectorParams mParams;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mWhiteNodeCount;
|
2008-02-15 16:12:55 +03:00
|
|
|
|
2012-01-14 20:58:05 +04:00
|
|
|
CC_BeforeUnlinkCallback mBeforeUnlinkCB;
|
|
|
|
CC_ForgetSkippableCallback mForgetSkippableCB;
|
|
|
|
|
2012-04-25 19:10:09 +04:00
|
|
|
nsPurpleBuffer mPurpleBuf;
|
|
|
|
|
2013-04-30 03:41:41 +04:00
|
|
|
uint32_t mUnmergedNeeded;
|
|
|
|
uint32_t mMergedInARow;
|
|
|
|
|
2013-03-26 01:26:00 +04:00
|
|
|
public:
|
2013-09-10 19:56:35 +04:00
|
|
|
nsCycleCollector();
|
2013-11-26 03:57:53 +04:00
|
|
|
virtual ~nsCycleCollector();
|
2013-09-10 19:56:35 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
void RegisterJSRuntime(CycleCollectedJSRuntime *aJSRuntime);
|
2012-05-03 23:28:11 +04:00
|
|
|
void ForgetJSRuntime();
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-03-26 01:26:00 +04:00
|
|
|
void SetBeforeUnlinkCallback(CC_BeforeUnlinkCallback aBeforeUnlinkCB)
|
|
|
|
{
|
2013-09-07 00:41:42 +04:00
|
|
|
CheckThreadSafety();
|
2013-03-26 01:26:00 +04:00
|
|
|
mBeforeUnlinkCB = aBeforeUnlinkCB;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetForgetSkippableCallback(CC_ForgetSkippableCallback aForgetSkippableCB)
|
|
|
|
{
|
2013-09-07 00:41:42 +04:00
|
|
|
CheckThreadSafety();
|
2013-03-26 01:26:00 +04:00
|
|
|
mForgetSkippableCB = aForgetSkippableCB;
|
|
|
|
}
|
|
|
|
|
2013-07-09 21:30:58 +04:00
|
|
|
void Suspect(void *n, nsCycleCollectionParticipant *cp,
|
|
|
|
nsCycleCollectingAutoRefCnt *aRefCnt);
|
2013-09-10 19:56:35 +04:00
|
|
|
uint32_t SuspectedCount();
|
|
|
|
void ForgetSkippable(bool aRemoveChildlessNodes, bool aAsyncSnowWhiteFreeing);
|
|
|
|
bool FreeSnowWhite(bool aUntilNoSWInPurpleBuffer);
|
2009-05-07 00:46:04 +04:00
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
// This method assumes its argument is already canonicalized.
|
|
|
|
void RemoveObjectFromGraph(void *aPtr);
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
void PrepareForGarbageCollection();
|
|
|
|
|
2013-09-07 03:15:10 +04:00
|
|
|
bool Collect(ccType aCCType,
|
2013-12-03 22:47:47 +04:00
|
|
|
SliceBudget &aBudget,
|
2013-09-11 03:33:41 +04:00
|
|
|
nsICycleCollectorListener *aManualListener);
|
2013-09-10 19:56:35 +04:00
|
|
|
void Shutdown();
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
void SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
2013-09-10 19:56:35 +04:00
|
|
|
size_t *aObjectSize,
|
|
|
|
size_t *aGraphNodesSize,
|
|
|
|
size_t *aGraphEdgesSize,
|
2013-09-10 19:56:36 +04:00
|
|
|
size_t *aWeakMapsSize,
|
2013-09-10 19:56:35 +04:00
|
|
|
size_t *aPurpleBufferSize) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void CheckThreadSafety();
|
2013-09-11 03:33:40 +04:00
|
|
|
void ShutdownCollect();
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-01-08 22:36:51 +04:00
|
|
|
void FixGrayBits(bool aForceGC);
|
2013-04-30 03:41:41 +04:00
|
|
|
bool ShouldMergeZones(ccType aCCType);
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-09-11 03:33:41 +04:00
|
|
|
void BeginCollection(ccType aCCType, nsICycleCollectorListener *aManualListener);
|
2013-12-03 22:47:47 +04:00
|
|
|
void MarkRoots(SliceBudget &aBudget);
|
2013-12-18 07:29:57 +04:00
|
|
|
void ScanRoots(bool aFullySynchGraphBuild);
|
|
|
|
void ScanIncrementalRoots();
|
2013-09-10 19:56:35 +04:00
|
|
|
void ScanWeakMaps();
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-09-10 19:56:35 +04:00
|
|
|
// returns whether anything was collected
|
2013-09-11 03:33:40 +04:00
|
|
|
bool CollectWhite();
|
2013-07-09 21:30:58 +04:00
|
|
|
|
2013-09-10 19:56:35 +04:00
|
|
|
void CleanupAfterCollection();
|
2007-01-05 01:31:26 +03:00
|
|
|
};
|
|
|
|
|
2013-12-08 09:39:47 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsCycleCollector, nsIMemoryReporter)
|
2013-11-26 03:57:53 +04:00
|
|
|
|
2010-01-12 19:51:39 +03:00
|
|
|
/**
|
|
|
|
* GraphWalker is templatized over a Visitor class that must provide
|
|
|
|
* the following two methods:
|
|
|
|
*
|
2011-09-29 10:19:26 +04:00
|
|
|
* bool ShouldVisitNode(PtrInfo const *pi);
|
2010-01-12 19:51:39 +03:00
|
|
|
* void VisitNode(PtrInfo *pi);
|
|
|
|
*/
|
|
|
|
template <class Visitor>
|
2007-04-26 01:12:11 +04:00
|
|
|
class GraphWalker
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2007-04-20 12:01:01 +04:00
|
|
|
private:
|
2010-01-12 19:51:39 +03:00
|
|
|
Visitor mVisitor;
|
2009-10-27 15:38:18 +03:00
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
void DoWalk(nsDeque &aQueue);
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-05-29 04:42:13 +04:00
|
|
|
void CheckedPush(nsDeque &aQueue, PtrInfo *pi)
|
|
|
|
{
|
|
|
|
CC_AbortIfNull(pi);
|
|
|
|
if (!aQueue.Push(pi, fallible_t())) {
|
|
|
|
mVisitor.Failed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
public:
|
2007-04-26 01:12:11 +04:00
|
|
|
void Walk(PtrInfo *s0);
|
|
|
|
void WalkFromRoots(GCGraph &aGraph);
|
2010-01-12 19:51:39 +03:00
|
|
|
// copy-constructing the visitor should be cheap, and less
|
|
|
|
// indirection than using a reference
|
|
|
|
GraphWalker(const Visitor aVisitor) : mVisitor(aVisitor) {}
|
2007-01-05 01:31:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2013-06-18 23:02:16 +04:00
|
|
|
// The static collector struct
|
2007-01-05 01:31:26 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
struct CollectorData {
|
2013-11-26 03:57:53 +04:00
|
|
|
nsRefPtr<nsCycleCollector> mCollector;
|
2013-06-18 23:02:16 +04:00
|
|
|
CycleCollectedJSRuntime* mRuntime;
|
|
|
|
};
|
|
|
|
|
|
|
|
static mozilla::ThreadLocal<CollectorData*> sCollectorData;
|
2007-01-05 01:31:26 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utility functions
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-03-16 08:13:08 +04:00
|
|
|
MOZ_NEVER_INLINE static void
|
2012-07-30 18:20:58 +04:00
|
|
|
Fault(const char *msg, const void *ptr=nullptr)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2012-03-16 08:13:08 +04:00
|
|
|
if (ptr)
|
|
|
|
printf("Fault in cycle collector: %s (ptr: %p)\n", msg, ptr);
|
|
|
|
else
|
|
|
|
printf("Fault in cycle collector: %s\n", msg);
|
2007-03-06 00:07:51 +03:00
|
|
|
|
2012-03-16 08:13:08 +04:00
|
|
|
NS_RUNTIMEABORT("cycle collector fault");
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2007-07-06 02:38:38 +04:00
|
|
|
static void
|
|
|
|
Fault(const char *msg, PtrInfo *pi)
|
|
|
|
{
|
|
|
|
Fault(msg, pi->mPointer);
|
|
|
|
}
|
|
|
|
|
2007-06-07 02:04:26 +04:00
|
|
|
static inline void
|
|
|
|
ToParticipant(nsISupports *s, nsXPCOMCycleCollectionParticipant **cp)
|
|
|
|
{
|
|
|
|
// We use QI to move from an nsISupports to an
|
|
|
|
// nsXPCOMCycleCollectionParticipant, which is a per-class singleton helper
|
|
|
|
// object that implements traversal and unlinking logic for the nsISupports
|
|
|
|
// in question.
|
|
|
|
CallQueryInterface(s, cp);
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:51:39 +03:00
|
|
|
template <class Visitor>
|
2012-02-21 00:13:29 +04:00
|
|
|
MOZ_NEVER_INLINE void
|
2010-01-12 19:51:39 +03:00
|
|
|
GraphWalker<Visitor>::Walk(PtrInfo *s0)
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
|
|
|
nsDeque queue;
|
2013-05-29 04:42:13 +04:00
|
|
|
CheckedPush(queue, s0);
|
2007-04-26 01:12:11 +04:00
|
|
|
DoWalk(queue);
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:51:39 +03:00
|
|
|
template <class Visitor>
|
2012-02-21 00:13:29 +04:00
|
|
|
MOZ_NEVER_INLINE void
|
2010-01-12 19:51:39 +03:00
|
|
|
GraphWalker<Visitor>::WalkFromRoots(GCGraph& aGraph)
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
|
|
|
nsDeque queue;
|
|
|
|
NodePool::Enumerator etor(aGraph.mNodes);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < aGraph.mRootCount; ++i) {
|
2013-05-29 04:42:13 +04:00
|
|
|
CheckedPush(queue, etor.GetNext());
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
DoWalk(queue);
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:51:39 +03:00
|
|
|
template <class Visitor>
|
2012-02-21 00:13:29 +04:00
|
|
|
MOZ_NEVER_INLINE void
|
2010-01-12 19:51:39 +03:00
|
|
|
GraphWalker<Visitor>::DoWalk(nsDeque &aQueue)
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
|
|
|
// Use a aQueue to match the breadth-first traversal used when we
|
|
|
|
// built the graph, for hopefully-better locality.
|
|
|
|
while (aQueue.GetSize() > 0) {
|
2007-07-08 11:08:04 +04:00
|
|
|
PtrInfo *pi = static_cast<PtrInfo*>(aQueue.PopFront());
|
2012-02-21 00:13:29 +04:00
|
|
|
CC_AbortIfNull(pi);
|
2007-04-26 01:12:11 +04:00
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
if (pi->mParticipant && mVisitor.ShouldVisitNode(pi)) {
|
2010-01-12 19:51:39 +03:00
|
|
|
mVisitor.VisitNode(pi);
|
2011-06-10 01:55:04 +04:00
|
|
|
for (EdgePool::Iterator child = pi->FirstChild(),
|
|
|
|
child_end = pi->LastChild();
|
2010-07-30 13:57:19 +04:00
|
|
|
child != child_end; ++child) {
|
2013-05-29 04:42:13 +04:00
|
|
|
CheckedPush(aQueue, *child);
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
}
|
2013-05-29 04:42:13 +04:00
|
|
|
}
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
|
2013-11-10 01:15:44 +04:00
|
|
|
struct CCGraphDescriber : public LinkedListElement<CCGraphDescriber>
|
2012-02-17 21:35:22 +04:00
|
|
|
{
|
|
|
|
CCGraphDescriber()
|
2013-11-12 17:53:51 +04:00
|
|
|
: mAddress("0x"), mCnt(0), mType(eUnknown) {}
|
2012-02-17 21:35:22 +04:00
|
|
|
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
eRefCountedObject,
|
|
|
|
eGCedObject,
|
|
|
|
eGCMarkedObject,
|
|
|
|
eEdge,
|
|
|
|
eRoot,
|
|
|
|
eGarbage,
|
|
|
|
eUnknown
|
|
|
|
};
|
|
|
|
|
|
|
|
nsCString mAddress;
|
|
|
|
nsCString mName;
|
2013-11-12 17:53:51 +04:00
|
|
|
nsCString mCompartmentOrToAddress;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCnt;
|
2012-02-17 21:35:22 +04:00
|
|
|
Type mType;
|
|
|
|
};
|
2007-04-26 01:12:11 +04:00
|
|
|
|
2012-06-06 03:51:58 +04:00
|
|
|
class nsCycleCollectorLogger MOZ_FINAL : public nsICycleCollectorListener
|
2010-08-12 04:03:23 +04:00
|
|
|
{
|
|
|
|
public:
|
2012-02-17 21:35:22 +04:00
|
|
|
nsCycleCollectorLogger() :
|
2012-07-30 18:20:58 +04:00
|
|
|
mStream(nullptr), mWantAllTraces(false),
|
2013-11-10 01:15:44 +04:00
|
|
|
mDisableLog(false), mWantAfterProcessing(false)
|
2010-08-12 04:03:23 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
~nsCycleCollectorLogger()
|
|
|
|
{
|
2013-11-10 01:15:44 +04:00
|
|
|
ClearDescribers();
|
2010-08-12 04:03:23 +04:00
|
|
|
if (mStream) {
|
2013-04-25 19:42:44 +04:00
|
|
|
MozillaUnRegisterDebugFILE(mStream);
|
2010-08-12 04:03:23 +04:00
|
|
|
fclose(mStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2012-09-28 21:11:33 +04:00
|
|
|
void SetAllTraces()
|
2012-01-02 01:48:42 +04:00
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
mWantAllTraces = true;
|
2012-09-28 21:11:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD AllTraces(nsICycleCollectorListener** aListener)
|
|
|
|
{
|
|
|
|
SetAllTraces();
|
2012-02-17 21:35:22 +04:00
|
|
|
NS_ADDREF(*aListener = this);
|
|
|
|
return NS_OK;
|
2012-01-02 01:48:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetWantAllTraces(bool* aAllTraces)
|
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
*aAllTraces = mWantAllTraces;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetDisableLog(bool* aDisableLog)
|
|
|
|
{
|
|
|
|
*aDisableLog = mDisableLog;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetDisableLog(bool aDisableLog)
|
|
|
|
{
|
|
|
|
mDisableLog = aDisableLog;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetWantAfterProcessing(bool* aWantAfterProcessing)
|
|
|
|
{
|
|
|
|
*aWantAfterProcessing = mWantAfterProcessing;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetWantAfterProcessing(bool aWantAfterProcessing)
|
|
|
|
{
|
|
|
|
mWantAfterProcessing = aWantAfterProcessing;
|
|
|
|
return NS_OK;
|
2012-01-02 01:48:42 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 06:12:14 +04:00
|
|
|
NS_IMETHOD GetFilenameIdentifier(nsAString& aIdentifier)
|
|
|
|
{
|
|
|
|
aIdentifier = mFilenameIdentifier;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetFilenameIdentifier(const nsAString& aIdentifier)
|
|
|
|
{
|
|
|
|
mFilenameIdentifier = aIdentifier;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-12 04:03:23 +04:00
|
|
|
NS_IMETHOD Begin()
|
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
mCurrentAddress.AssignLiteral("0x");
|
2013-11-10 01:15:44 +04:00
|
|
|
ClearDescribers();
|
2012-02-17 21:35:22 +04:00
|
|
|
if (mDisableLog) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-02-03 04:32:30 +04:00
|
|
|
|
2012-10-16 06:12:14 +04:00
|
|
|
// Initially create the log in a file starting with
|
|
|
|
// "incomplete-gc-edges". We'll move the file and strip off the
|
|
|
|
// "incomplete-" once the dump completes. (We do this because we don't
|
|
|
|
// want scripts which poll the filesystem looking for gc/cc dumps to
|
|
|
|
// grab a file before we're finished writing to it.)
|
|
|
|
nsCOMPtr<nsIFile> gcLogFile = CreateTempFile("incomplete-gc-edges");
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(!gcLogFile))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2012-02-03 04:32:30 +04:00
|
|
|
|
|
|
|
// Dump the JS heap.
|
2012-10-16 06:12:14 +04:00
|
|
|
FILE* gcLogANSIFile = nullptr;
|
|
|
|
gcLogFile->OpenANSIFileDesc("w", &gcLogANSIFile);
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(!gcLogANSIFile))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2013-04-25 19:42:44 +04:00
|
|
|
MozillaRegisterDebugFILE(gcLogANSIFile);
|
2013-08-04 03:55:39 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
|
|
|
if (data && data->mRuntime)
|
|
|
|
data->mRuntime->DumpJSHeap(gcLogANSIFile);
|
2013-04-25 19:42:44 +04:00
|
|
|
MozillaUnRegisterDebugFILE(gcLogANSIFile);
|
2012-10-16 06:12:14 +04:00
|
|
|
fclose(gcLogANSIFile);
|
|
|
|
|
|
|
|
// Strip off "incomplete-".
|
|
|
|
nsCOMPtr<nsIFile> gcLogFileFinalDestination =
|
|
|
|
CreateTempFile("gc-edges");
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(!gcLogFileFinalDestination))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2012-10-16 06:12:14 +04:00
|
|
|
|
|
|
|
nsAutoString gcLogFileFinalDestinationName;
|
|
|
|
gcLogFileFinalDestination->GetLeafName(gcLogFileFinalDestinationName);
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(gcLogFileFinalDestinationName.IsEmpty()))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2010-08-12 04:03:23 +04:00
|
|
|
|
2012-10-16 06:12:14 +04:00
|
|
|
gcLogFile->MoveTo(/* directory */ nullptr, gcLogFileFinalDestinationName);
|
|
|
|
|
|
|
|
// Log to the error console.
|
2012-01-02 02:34:00 +04:00
|
|
|
nsCOMPtr<nsIConsoleService> cs =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (cs) {
|
2012-10-16 06:12:14 +04:00
|
|
|
nsAutoString gcLogPath;
|
|
|
|
gcLogFileFinalDestination->GetPath(gcLogPath);
|
2012-09-14 17:47:12 +04:00
|
|
|
|
2012-10-16 06:12:14 +04:00
|
|
|
nsString msg = NS_LITERAL_STRING("Garbage Collector log dumped to ") +
|
|
|
|
gcLogPath;
|
2012-09-14 17:47:12 +04:00
|
|
|
cs->LogStringMessage(msg.get());
|
2012-01-02 02:34:00 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 06:12:14 +04:00
|
|
|
// Open a file for dumping the CC graph. We again prefix with
|
|
|
|
// "incomplete-".
|
|
|
|
mOutFile = CreateTempFile("incomplete-cc-edges");
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(!mOutFile))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2012-10-16 06:12:14 +04:00
|
|
|
MOZ_ASSERT(!mStream);
|
|
|
|
mOutFile->OpenANSIFileDesc("w", &mStream);
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(!mStream))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2013-04-25 19:42:44 +04:00
|
|
|
MozillaRegisterDebugFILE(mStream);
|
2012-10-16 06:12:14 +04:00
|
|
|
|
2013-07-19 21:00:53 +04:00
|
|
|
fprintf(mStream, "# WantAllTraces=%s\n", mWantAllTraces ? "true" : "false");
|
|
|
|
|
2012-02-03 04:32:30 +04:00
|
|
|
return NS_OK;
|
2010-08-12 04:03:23 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD NoteRefCountedObject(uint64_t aAddress, uint32_t refCount,
|
2011-06-22 21:41:17 +04:00
|
|
|
const char *aObjectDescription)
|
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
if (!mDisableLog) {
|
|
|
|
fprintf(mStream, "%p [rc=%u] %s\n", (void*)aAddress, refCount,
|
|
|
|
aObjectDescription);
|
2013-05-04 19:39:44 +04:00
|
|
|
}
|
2012-02-17 21:35:22 +04:00
|
|
|
if (mWantAfterProcessing) {
|
2013-11-10 01:15:44 +04:00
|
|
|
CCGraphDescriber* d = new CCGraphDescriber();
|
|
|
|
mDescribers.insertBack(d);
|
2012-02-17 21:35:22 +04:00
|
|
|
mCurrentAddress.AssignLiteral("0x");
|
|
|
|
mCurrentAddress.AppendInt(aAddress, 16);
|
|
|
|
d->mType = CCGraphDescriber::eRefCountedObject;
|
|
|
|
d->mAddress = mCurrentAddress;
|
|
|
|
d->mCnt = refCount;
|
|
|
|
d->mName.Append(aObjectDescription);
|
2013-05-04 19:39:44 +04:00
|
|
|
}
|
2011-06-22 21:41:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD NoteGCedObject(uint64_t aAddress, bool aMarked,
|
2013-11-12 17:53:51 +04:00
|
|
|
const char *aObjectDescription,
|
|
|
|
uint64_t aCompartmentAddress)
|
2010-08-12 04:03:23 +04:00
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
if (!mDisableLog) {
|
|
|
|
fprintf(mStream, "%p [gc%s] %s\n", (void*)aAddress,
|
|
|
|
aMarked ? ".marked" : "", aObjectDescription);
|
|
|
|
}
|
|
|
|
if (mWantAfterProcessing) {
|
2013-11-10 01:15:44 +04:00
|
|
|
CCGraphDescriber* d = new CCGraphDescriber();
|
|
|
|
mDescribers.insertBack(d);
|
2012-02-17 21:35:22 +04:00
|
|
|
mCurrentAddress.AssignLiteral("0x");
|
|
|
|
mCurrentAddress.AppendInt(aAddress, 16);
|
|
|
|
d->mType = aMarked ? CCGraphDescriber::eGCMarkedObject :
|
|
|
|
CCGraphDescriber::eGCedObject;
|
|
|
|
d->mAddress = mCurrentAddress;
|
|
|
|
d->mName.Append(aObjectDescription);
|
2013-11-12 17:53:51 +04:00
|
|
|
if (aCompartmentAddress) {
|
|
|
|
d->mCompartmentOrToAddress.AssignLiteral("0x");
|
|
|
|
d->mCompartmentOrToAddress.AppendInt(aCompartmentAddress, 16);
|
|
|
|
} else {
|
|
|
|
d->mCompartmentOrToAddress.SetIsVoid(true);
|
|
|
|
}
|
2012-02-17 21:35:22 +04:00
|
|
|
}
|
2010-08-12 04:03:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD NoteEdge(uint64_t aToAddress, const char *aEdgeName)
|
2010-08-12 04:03:23 +04:00
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
if (!mDisableLog) {
|
|
|
|
fprintf(mStream, "> %p %s\n", (void*)aToAddress, aEdgeName);
|
|
|
|
}
|
|
|
|
if (mWantAfterProcessing) {
|
2013-11-10 01:15:44 +04:00
|
|
|
CCGraphDescriber* d = new CCGraphDescriber();
|
|
|
|
mDescribers.insertBack(d);
|
2012-02-17 21:35:22 +04:00
|
|
|
d->mType = CCGraphDescriber::eEdge;
|
|
|
|
d->mAddress = mCurrentAddress;
|
2013-11-12 17:53:51 +04:00
|
|
|
d->mCompartmentOrToAddress.AssignLiteral("0x");
|
|
|
|
d->mCompartmentOrToAddress.AppendInt(aToAddress, 16);
|
2012-02-17 21:35:22 +04:00
|
|
|
d->mName.Append(aEdgeName);
|
|
|
|
}
|
2010-08-12 04:03:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-07-26 19:12:51 +04:00
|
|
|
NS_IMETHOD NoteWeakMapEntry(uint64_t aMap, uint64_t aKey,
|
|
|
|
uint64_t aKeyDelegate, uint64_t aValue)
|
|
|
|
{
|
|
|
|
if (!mDisableLog) {
|
|
|
|
fprintf(mStream, "WeakMapEntry map=%p key=%p keyDelegate=%p value=%p\n",
|
|
|
|
(void*)aMap, (void*)aKey, (void*)aKeyDelegate, (void*)aValue);
|
|
|
|
}
|
|
|
|
// We don't support after-processing for weak map entries.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-06-22 21:41:17 +04:00
|
|
|
NS_IMETHOD BeginResults()
|
2010-08-12 04:03:23 +04:00
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
if (!mDisableLog) {
|
|
|
|
fputs("==========\n", mStream);
|
2013-05-04 19:39:44 +04:00
|
|
|
}
|
2010-08-12 04:03:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD DescribeRoot(uint64_t aAddress, uint32_t aKnownEdges)
|
2010-08-12 04:03:23 +04:00
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
if (!mDisableLog) {
|
|
|
|
fprintf(mStream, "%p [known=%u]\n", (void*)aAddress, aKnownEdges);
|
|
|
|
}
|
|
|
|
if (mWantAfterProcessing) {
|
2013-11-10 01:15:44 +04:00
|
|
|
CCGraphDescriber* d = new CCGraphDescriber();
|
|
|
|
mDescribers.insertBack(d);
|
2012-02-17 21:35:22 +04:00
|
|
|
d->mType = CCGraphDescriber::eRoot;
|
|
|
|
d->mAddress.AppendInt(aAddress, 16);
|
|
|
|
d->mCnt = aKnownEdges;
|
|
|
|
}
|
2010-08-12 04:03:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD DescribeGarbage(uint64_t aAddress)
|
2010-08-12 04:03:23 +04:00
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
if (!mDisableLog) {
|
|
|
|
fprintf(mStream, "%p [garbage]\n", (void*)aAddress);
|
|
|
|
}
|
|
|
|
if (mWantAfterProcessing) {
|
2013-11-10 01:15:44 +04:00
|
|
|
CCGraphDescriber* d = new CCGraphDescriber();
|
|
|
|
mDescribers.insertBack(d);
|
2012-02-17 21:35:22 +04:00
|
|
|
d->mType = CCGraphDescriber::eGarbage;
|
|
|
|
d->mAddress.AppendInt(aAddress, 16);
|
|
|
|
}
|
2010-08-12 04:03:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHOD End()
|
|
|
|
{
|
2012-02-17 21:35:22 +04:00
|
|
|
if (!mDisableLog) {
|
2012-10-16 06:12:14 +04:00
|
|
|
MOZ_ASSERT(mStream);
|
|
|
|
MOZ_ASSERT(mOutFile);
|
|
|
|
|
2013-04-25 19:42:44 +04:00
|
|
|
MozillaUnRegisterDebugFILE(mStream);
|
2012-02-17 21:35:22 +04:00
|
|
|
fclose(mStream);
|
2012-07-30 18:20:58 +04:00
|
|
|
mStream = nullptr;
|
2012-10-16 06:12:14 +04:00
|
|
|
|
|
|
|
// Strip off "incomplete-" from the log file's name.
|
|
|
|
nsCOMPtr<nsIFile> logFileFinalDestination =
|
|
|
|
CreateTempFile("cc-edges");
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(!logFileFinalDestination))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2012-10-16 06:12:14 +04:00
|
|
|
|
|
|
|
nsAutoString logFileFinalDestinationName;
|
|
|
|
logFileFinalDestination->GetLeafName(logFileFinalDestinationName);
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(logFileFinalDestinationName.IsEmpty()))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2012-10-16 06:12:14 +04:00
|
|
|
|
|
|
|
mOutFile->MoveTo(/* directory = */ nullptr,
|
|
|
|
logFileFinalDestinationName);
|
|
|
|
mOutFile = nullptr;
|
|
|
|
|
|
|
|
// Log to the error console.
|
|
|
|
nsCOMPtr<nsIConsoleService> cs =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (cs) {
|
|
|
|
nsAutoString ccLogPath;
|
|
|
|
logFileFinalDestination->GetPath(ccLogPath);
|
|
|
|
|
|
|
|
nsString msg = NS_LITERAL_STRING("Cycle Collector log dumped to ") +
|
|
|
|
ccLogPath;
|
|
|
|
cs->LogStringMessage(msg.get());
|
|
|
|
}
|
2012-02-17 21:35:22 +04:00
|
|
|
}
|
2010-08-12 04:03:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-02-17 21:35:22 +04:00
|
|
|
NS_IMETHOD ProcessNext(nsICycleCollectorHandler* aHandler,
|
|
|
|
bool* aCanContinue)
|
|
|
|
{
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(!aHandler) || NS_WARN_IF(!mWantAfterProcessing))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2013-11-10 01:15:44 +04:00
|
|
|
CCGraphDescriber* d = mDescribers.popFirst();
|
|
|
|
if (d) {
|
|
|
|
switch (d->mType) {
|
2012-02-17 21:35:22 +04:00
|
|
|
case CCGraphDescriber::eRefCountedObject:
|
2013-11-10 01:15:44 +04:00
|
|
|
aHandler->NoteRefCountedObject(d->mAddress,
|
|
|
|
d->mCnt,
|
|
|
|
d->mName);
|
2012-02-17 21:35:22 +04:00
|
|
|
break;
|
|
|
|
case CCGraphDescriber::eGCedObject:
|
|
|
|
case CCGraphDescriber::eGCMarkedObject:
|
2013-11-10 01:15:44 +04:00
|
|
|
aHandler->NoteGCedObject(d->mAddress,
|
|
|
|
d->mType ==
|
2012-02-17 21:35:22 +04:00
|
|
|
CCGraphDescriber::eGCMarkedObject,
|
2013-11-12 17:53:51 +04:00
|
|
|
d->mName,
|
|
|
|
d->mCompartmentOrToAddress);
|
2012-02-17 21:35:22 +04:00
|
|
|
break;
|
|
|
|
case CCGraphDescriber::eEdge:
|
2013-11-10 01:15:44 +04:00
|
|
|
aHandler->NoteEdge(d->mAddress,
|
2013-11-12 17:53:51 +04:00
|
|
|
d->mCompartmentOrToAddress,
|
2013-11-10 01:15:44 +04:00
|
|
|
d->mName);
|
2012-02-17 21:35:22 +04:00
|
|
|
break;
|
|
|
|
case CCGraphDescriber::eRoot:
|
2013-11-10 01:15:44 +04:00
|
|
|
aHandler->DescribeRoot(d->mAddress,
|
|
|
|
d->mCnt);
|
2012-02-17 21:35:22 +04:00
|
|
|
break;
|
|
|
|
case CCGraphDescriber::eGarbage:
|
2013-11-10 01:15:44 +04:00
|
|
|
aHandler->DescribeGarbage(d->mAddress);
|
2012-02-17 21:35:22 +04:00
|
|
|
break;
|
|
|
|
case CCGraphDescriber::eUnknown:
|
|
|
|
NS_NOTREACHED("CCGraphDescriber::eUnknown");
|
|
|
|
break;
|
|
|
|
}
|
2013-11-10 01:15:44 +04:00
|
|
|
delete d;
|
2012-02-17 21:35:22 +04:00
|
|
|
}
|
2013-11-10 01:15:44 +04:00
|
|
|
if (!(*aCanContinue = !mDescribers.isEmpty())) {
|
2012-02-17 21:35:22 +04:00
|
|
|
mCurrentAddress.AssignLiteral("0x");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-12 04:03:23 +04:00
|
|
|
private:
|
2012-10-16 06:12:14 +04:00
|
|
|
/**
|
|
|
|
* Create a new file named something like aPrefix.$PID.$IDENTIFIER.log in
|
|
|
|
* $MOZ_CC_LOG_DIRECTORY or in the system's temp directory. No existing
|
|
|
|
* file will be overwritten; if aPrefix.$PID.$IDENTIFIER.log exists, we'll
|
|
|
|
* try a file named something like aPrefix.$PID.$IDENTIFIER-1.log, and so
|
|
|
|
* on.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIFile>
|
|
|
|
CreateTempFile(const char* aPrefix)
|
|
|
|
{
|
|
|
|
nsPrintfCString filename("%s.%d%s%s.log",
|
|
|
|
aPrefix,
|
|
|
|
base::GetCurrentProcId(),
|
|
|
|
mFilenameIdentifier.IsEmpty() ? "" : ".",
|
|
|
|
NS_ConvertUTF16toUTF8(mFilenameIdentifier).get());
|
|
|
|
|
2013-03-01 19:41:17 +04:00
|
|
|
// Get the log directory either from $MOZ_CC_LOG_DIRECTORY or from
|
2013-04-28 15:52:10 +04:00
|
|
|
// the fallback directories in OpenTempFile. We don't use an nsCOMPtr
|
|
|
|
// here because OpenTempFile uses an in/out param and getter_AddRefs
|
|
|
|
// wouldn't work.
|
2013-04-11 23:39:20 +04:00
|
|
|
nsIFile* logFile = nullptr;
|
2013-03-01 19:41:17 +04:00
|
|
|
if (char* env = PR_GetEnv("MOZ_CC_LOG_DIRECTORY")) {
|
2012-10-16 06:12:14 +04:00
|
|
|
NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true,
|
2013-04-11 23:39:20 +04:00
|
|
|
&logFile);
|
|
|
|
}
|
|
|
|
nsresult rv = nsMemoryInfoDumper::OpenTempFile(filename, &logFile);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_IF_RELEASE(logFile);
|
|
|
|
return nullptr;
|
2013-02-27 17:58:29 +04:00
|
|
|
}
|
2012-10-16 06:12:14 +04:00
|
|
|
|
2013-04-28 15:52:10 +04:00
|
|
|
return dont_AddRef(logFile);
|
2012-10-16 06:12:14 +04:00
|
|
|
}
|
|
|
|
|
2013-11-10 01:15:44 +04:00
|
|
|
void ClearDescribers()
|
|
|
|
{
|
|
|
|
CCGraphDescriber* d;
|
|
|
|
while((d = mDescribers.popFirst())) {
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-12 04:03:23 +04:00
|
|
|
FILE *mStream;
|
2012-10-16 06:12:14 +04:00
|
|
|
nsCOMPtr<nsIFile> mOutFile;
|
2012-01-02 01:48:42 +04:00
|
|
|
bool mWantAllTraces;
|
2012-02-17 21:35:22 +04:00
|
|
|
bool mDisableLog;
|
|
|
|
bool mWantAfterProcessing;
|
2012-10-16 06:12:14 +04:00
|
|
|
nsString mFilenameIdentifier;
|
2013-05-04 19:39:44 +04:00
|
|
|
nsCString mCurrentAddress;
|
2013-11-10 01:15:44 +04:00
|
|
|
mozilla::LinkedList<CCGraphDescriber> mDescribers;
|
2010-08-12 04:03:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsCycleCollectorLogger, nsICycleCollectorListener)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCycleCollectorLoggerConstructor(nsISupports* aOuter,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void* *aInstancePtr)
|
|
|
|
{
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(aOuter))
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
2010-08-12 04:03:23 +04:00
|
|
|
|
|
|
|
nsISupports *logger = new nsCycleCollectorLogger();
|
|
|
|
|
|
|
|
return logger->QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Bacon & Rajan's |MarkRoots| routine.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-05-21 00:08:11 +04:00
|
|
|
class GCGraphBuilder : public nsCycleCollectionTraversalCallback,
|
|
|
|
public nsCycleCollectionNoteRootCallback
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
|
|
|
private:
|
2013-11-21 02:35:16 +04:00
|
|
|
GCGraph &mGraph;
|
2013-11-21 02:35:16 +04:00
|
|
|
CycleCollectorResults &mResults;
|
2007-04-26 01:12:11 +04:00
|
|
|
NodePool::Builder mNodeBuilder;
|
|
|
|
EdgePool::Builder mEdgeBuilder;
|
|
|
|
PtrInfo *mCurrPi;
|
2012-05-03 23:28:10 +04:00
|
|
|
nsCycleCollectionParticipant *mJSParticipant;
|
2013-03-17 07:36:37 +04:00
|
|
|
nsCycleCollectionParticipant *mJSZoneParticipant;
|
2008-03-18 02:11:08 +03:00
|
|
|
nsCString mNextEdgeName;
|
2011-01-14 13:06:09 +03:00
|
|
|
nsICycleCollectorListener *mListener;
|
2013-03-17 07:36:37 +04:00
|
|
|
bool mMergeZones;
|
2013-05-25 02:00:36 +04:00
|
|
|
bool mRanOutOfMemory;
|
2007-04-26 01:12:11 +04:00
|
|
|
|
|
|
|
public:
|
2013-11-21 02:35:16 +04:00
|
|
|
GCGraphBuilder(GCGraph &aGraph,
|
|
|
|
CycleCollectorResults &aResults,
|
2013-06-18 23:02:16 +04:00
|
|
|
CycleCollectedJSRuntime *aJSRuntime,
|
2012-06-27 19:09:56 +04:00
|
|
|
nsICycleCollectorListener *aListener,
|
2013-03-17 07:36:37 +04:00
|
|
|
bool aMergeZones);
|
2013-11-21 02:35:15 +04:00
|
|
|
virtual ~GCGraphBuilder();
|
2007-04-26 01:12:11 +04:00
|
|
|
|
2013-05-21 00:08:11 +04:00
|
|
|
bool WantAllTraces() const
|
|
|
|
{
|
|
|
|
return nsCycleCollectionNoteRootCallback::WantAllTraces();
|
|
|
|
}
|
|
|
|
|
2013-09-10 19:56:35 +04:00
|
|
|
PtrInfo* AddNode(void *aPtr, nsCycleCollectionParticipant *aParticipant);
|
2011-11-24 16:35:56 +04:00
|
|
|
PtrInfo* AddWeakMapNode(void* node);
|
2007-04-26 01:12:11 +04:00
|
|
|
void Traverse(PtrInfo* aPtrInfo);
|
2011-06-10 01:55:29 +04:00
|
|
|
void SetLastChild();
|
2007-04-26 01:12:11 +04:00
|
|
|
|
2013-05-25 02:00:36 +04:00
|
|
|
bool RanOutOfMemory() const { return mRanOutOfMemory; }
|
|
|
|
|
2008-02-16 01:23:16 +03:00
|
|
|
private:
|
2012-08-27 21:41:04 +04:00
|
|
|
void DescribeNode(uint32_t refCount, const char *objName)
|
2011-06-24 01:10:52 +04:00
|
|
|
{
|
2011-06-22 21:41:17 +04:00
|
|
|
mCurrPi->mRefCount = refCount;
|
2011-06-24 01:10:52 +04:00
|
|
|
}
|
|
|
|
|
2012-05-03 23:28:11 +04:00
|
|
|
public:
|
2013-05-21 00:08:11 +04:00
|
|
|
// nsCycleCollectionNoteRootCallback methods.
|
|
|
|
NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports *root);
|
|
|
|
NS_IMETHOD_(void) NoteJSRoot(void *root);
|
|
|
|
NS_IMETHOD_(void) NoteNativeRoot(void *root, nsCycleCollectionParticipant *participant);
|
|
|
|
NS_IMETHOD_(void) NoteWeakMapping(void *map, void *key, void *kdelegate, void *val);
|
|
|
|
|
2012-05-03 23:28:11 +04:00
|
|
|
// nsCycleCollectionTraversalCallback methods.
|
2012-08-27 21:41:04 +04:00
|
|
|
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refCount,
|
2011-06-24 01:10:52 +04:00
|
|
|
const char *objName);
|
2013-11-12 17:53:51 +04:00
|
|
|
NS_IMETHOD_(void) DescribeGCedNode(bool isMarked, const char *objName,
|
|
|
|
uint64_t aCompartmentAddress);
|
2012-05-03 23:28:11 +04:00
|
|
|
|
2007-09-18 04:30:06 +04:00
|
|
|
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child);
|
2012-05-03 23:28:10 +04:00
|
|
|
NS_IMETHOD_(void) NoteJSChild(void *child);
|
2007-09-18 04:30:06 +04:00
|
|
|
NS_IMETHOD_(void) NoteNativeChild(void *child,
|
2012-02-27 01:18:44 +04:00
|
|
|
nsCycleCollectionParticipant *participant);
|
2008-03-18 02:11:08 +03:00
|
|
|
NS_IMETHOD_(void) NoteNextEdgeName(const char* name);
|
2012-05-03 23:28:11 +04:00
|
|
|
|
2012-02-27 01:18:44 +04:00
|
|
|
private:
|
2012-05-03 23:28:11 +04:00
|
|
|
NS_IMETHOD_(void) NoteRoot(void *root,
|
2012-05-03 23:28:11 +04:00
|
|
|
nsCycleCollectionParticipant *participant)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(root);
|
|
|
|
MOZ_ASSERT(participant);
|
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
if (!participant->CanSkipInCC(root) || MOZ_UNLIKELY(WantAllTraces())) {
|
2012-05-03 23:28:11 +04:00
|
|
|
AddNode(root, participant);
|
2012-05-03 23:28:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-27 01:18:44 +04:00
|
|
|
NS_IMETHOD_(void) NoteChild(void *child, nsCycleCollectionParticipant *cp,
|
2012-05-03 23:28:11 +04:00
|
|
|
nsCString edgeName)
|
2012-02-27 01:18:44 +04:00
|
|
|
{
|
2012-05-03 23:28:11 +04:00
|
|
|
PtrInfo *childPi = AddNode(child, cp);
|
2012-02-27 01:18:44 +04:00
|
|
|
if (!childPi)
|
|
|
|
return;
|
|
|
|
mEdgeBuilder.Add(childPi);
|
|
|
|
if (mListener) {
|
2012-08-22 19:56:38 +04:00
|
|
|
mListener->NoteEdge((uint64_t)child, edgeName.get());
|
2012-02-27 01:18:44 +04:00
|
|
|
}
|
|
|
|
++childPi->mInternalRefs;
|
|
|
|
}
|
2012-06-27 19:09:56 +04:00
|
|
|
|
2013-03-17 07:36:37 +04:00
|
|
|
JS::Zone *MergeZone(void *gcthing) {
|
|
|
|
if (!mMergeZones) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-06-27 19:09:56 +04:00
|
|
|
}
|
2013-03-19 14:35:41 +04:00
|
|
|
JS::Zone *zone = JS::GetGCThingZone(gcthing);
|
2013-03-17 07:36:37 +04:00
|
|
|
if (js::IsSystemZone(zone)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-06-27 19:09:56 +04:00
|
|
|
}
|
2013-03-17 07:36:37 +04:00
|
|
|
return zone;
|
2012-06-27 19:09:56 +04:00
|
|
|
}
|
2007-04-26 01:12:11 +04:00
|
|
|
};
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
GCGraphBuilder::GCGraphBuilder(GCGraph &aGraph,
|
|
|
|
CycleCollectorResults &aResults,
|
2013-06-18 23:02:16 +04:00
|
|
|
CycleCollectedJSRuntime *aJSRuntime,
|
2012-06-27 19:09:56 +04:00
|
|
|
nsICycleCollectorListener *aListener,
|
2013-03-17 07:36:37 +04:00
|
|
|
bool aMergeZones)
|
2013-11-21 02:35:16 +04:00
|
|
|
: mGraph(aGraph),
|
|
|
|
mResults(aResults),
|
2013-03-26 01:26:00 +04:00
|
|
|
mNodeBuilder(aGraph.mNodes),
|
2007-04-26 01:12:11 +04:00
|
|
|
mEdgeBuilder(aGraph.mEdges),
|
2012-07-30 18:20:58 +04:00
|
|
|
mJSParticipant(nullptr),
|
2013-06-18 23:02:16 +04:00
|
|
|
mJSZoneParticipant(nullptr),
|
2012-06-27 19:09:56 +04:00
|
|
|
mListener(aListener),
|
2013-05-25 02:00:36 +04:00
|
|
|
mMergeZones(aMergeZones),
|
|
|
|
mRanOutOfMemory(false)
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
2012-05-03 23:28:10 +04:00
|
|
|
if (aJSRuntime) {
|
2013-06-18 23:02:16 +04:00
|
|
|
mJSParticipant = aJSRuntime->GCThingParticipant();
|
|
|
|
mJSZoneParticipant = aJSRuntime->ZoneParticipant();
|
2012-05-03 23:28:10 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = 0;
|
2012-01-02 01:48:42 +04:00
|
|
|
if (!flags && mListener) {
|
|
|
|
flags = nsCycleCollectionTraversalCallback::WANT_DEBUG_INFO;
|
|
|
|
bool all = false;
|
|
|
|
mListener->GetWantAllTraces(&all);
|
|
|
|
if (all) {
|
|
|
|
flags |= nsCycleCollectionTraversalCallback::WANT_ALL_TRACES;
|
2013-05-21 00:08:11 +04:00
|
|
|
mWantAllTraces = true; // for nsCycleCollectionNoteRootCallback
|
2012-01-02 01:48:42 +04:00
|
|
|
}
|
2010-08-12 04:03:23 +04:00
|
|
|
}
|
2012-01-02 01:48:42 +04:00
|
|
|
|
|
|
|
mFlags |= flags;
|
2012-06-27 19:09:56 +04:00
|
|
|
|
2013-03-17 07:36:37 +04:00
|
|
|
mMergeZones = mMergeZones && MOZ_LIKELY(!WantAllTraces());
|
2013-05-21 00:08:11 +04:00
|
|
|
|
|
|
|
MOZ_ASSERT(nsCycleCollectionNoteRootCallback::WantAllTraces() ==
|
|
|
|
nsCycleCollectionTraversalCallback::WantAllTraces());
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GCGraphBuilder::~GCGraphBuilder()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PtrInfo*
|
2013-09-10 19:56:35 +04:00
|
|
|
GCGraphBuilder::AddNode(void *aPtr, nsCycleCollectionParticipant *aParticipant)
|
2007-04-26 01:12:11 +04:00
|
|
|
{
|
2013-11-21 02:35:17 +04:00
|
|
|
PtrToNodeEntry *e = mGraph.AddNodeToMap(aPtr);
|
2013-05-10 00:19:00 +04:00
|
|
|
if (!e) {
|
2013-05-25 02:00:36 +04:00
|
|
|
mRanOutOfMemory = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2013-05-10 00:19:00 +04:00
|
|
|
}
|
2009-07-17 00:06:48 +04:00
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
PtrInfo *result;
|
|
|
|
if (!e->mNode) {
|
|
|
|
// New entry.
|
2013-09-10 19:56:35 +04:00
|
|
|
result = mNodeBuilder.Add(aPtr, aParticipant);
|
2007-04-26 01:12:11 +04:00
|
|
|
e->mNode = result;
|
2013-05-10 00:19:00 +04:00
|
|
|
NS_ASSERTION(result, "mNodeBuilder.Add returned null");
|
2007-04-26 01:12:11 +04:00
|
|
|
} else {
|
|
|
|
result = e->mNode;
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(result->mParticipant == aParticipant,
|
|
|
|
"nsCycleCollectionParticipant shouldn't change!");
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-02-21 00:13:29 +04:00
|
|
|
MOZ_NEVER_INLINE void
|
2007-04-26 01:12:11 +04:00
|
|
|
GCGraphBuilder::Traverse(PtrInfo* aPtrInfo)
|
|
|
|
{
|
|
|
|
mCurrPi = aPtrInfo;
|
|
|
|
|
2011-06-10 01:55:04 +04:00
|
|
|
mCurrPi->SetFirstChild(mEdgeBuilder.Mark());
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
if (!aPtrInfo->mParticipant) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-24 18:10:02 +04:00
|
|
|
nsresult rv = aPtrInfo->mParticipant->Traverse(aPtrInfo->mPointer, *this);
|
2007-04-26 01:12:11 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2007-07-06 02:38:38 +04:00
|
|
|
Fault("script pointer traversal failed", aPtrInfo);
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
2011-06-10 01:55:29 +04:00
|
|
|
}
|
2007-04-26 01:12:11 +04:00
|
|
|
|
2011-06-10 01:55:29 +04:00
|
|
|
void
|
|
|
|
GCGraphBuilder::SetLastChild()
|
|
|
|
{
|
2011-06-10 01:55:04 +04:00
|
|
|
mCurrPi->SetLastChild(mEdgeBuilder.Mark());
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
|
2007-11-02 01:51:57 +03:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
GCGraphBuilder::NoteXPCOMRoot(nsISupports *root)
|
|
|
|
{
|
2012-08-24 20:50:06 +04:00
|
|
|
root = CanonicalizeXPCOMParticipant(root);
|
2007-11-02 01:51:57 +03:00
|
|
|
NS_ASSERTION(root,
|
|
|
|
"Don't add objects that don't participate in collection!");
|
|
|
|
|
|
|
|
nsXPCOMCycleCollectionParticipant *cp;
|
|
|
|
ToParticipant(root, &cp);
|
|
|
|
|
2012-05-03 23:28:11 +04:00
|
|
|
NoteRoot(root, cp);
|
2007-11-02 01:51:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2012-05-03 23:28:11 +04:00
|
|
|
GCGraphBuilder::NoteJSRoot(void *root)
|
2007-11-02 01:51:57 +03:00
|
|
|
{
|
2013-03-17 07:36:37 +04:00
|
|
|
if (JS::Zone *zone = MergeZone(root)) {
|
|
|
|
NoteRoot(zone, mJSZoneParticipant);
|
2012-06-27 19:09:56 +04:00
|
|
|
} else {
|
|
|
|
NoteRoot(root, mJSParticipant);
|
|
|
|
}
|
2012-05-03 23:28:11 +04:00
|
|
|
}
|
2007-11-02 01:51:57 +03:00
|
|
|
|
2012-05-03 23:28:11 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
GCGraphBuilder::NoteNativeRoot(void *root, nsCycleCollectionParticipant *participant)
|
|
|
|
{
|
2012-05-03 23:28:11 +04:00
|
|
|
NoteRoot(root, participant);
|
2007-11-02 01:51:57 +03:00
|
|
|
}
|
|
|
|
|
2007-09-18 04:30:06 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2012-08-27 21:41:04 +04:00
|
|
|
GCGraphBuilder::DescribeRefCountedNode(nsrefcnt refCount, const char *objName)
|
2011-06-24 01:10:52 +04:00
|
|
|
{
|
|
|
|
if (refCount == 0)
|
|
|
|
Fault("zero refcount", mCurrPi);
|
2012-09-28 10:57:33 +04:00
|
|
|
if (refCount == UINT32_MAX)
|
2011-06-24 01:10:52 +04:00
|
|
|
Fault("overflowing refcount", mCurrPi);
|
2013-11-21 02:35:16 +04:00
|
|
|
mResults.mVisitedRefCounted++;
|
2011-06-22 21:41:17 +04:00
|
|
|
|
|
|
|
if (mListener) {
|
2012-08-22 19:56:38 +04:00
|
|
|
mListener->NoteRefCountedObject((uint64_t)mCurrPi->mPointer, refCount,
|
2011-06-22 21:41:17 +04:00
|
|
|
objName);
|
|
|
|
}
|
|
|
|
|
2012-08-27 21:41:04 +04:00
|
|
|
DescribeNode(refCount, objName);
|
2011-06-24 01:10:52 +04:00
|
|
|
}
|
2007-07-06 02:38:38 +04:00
|
|
|
|
2011-06-24 01:10:52 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2013-11-12 17:53:51 +04:00
|
|
|
GCGraphBuilder::DescribeGCedNode(bool isMarked, const char *objName,
|
|
|
|
uint64_t aCompartmentAddress)
|
2011-06-24 01:10:52 +04:00
|
|
|
{
|
2012-09-28 10:57:33 +04:00
|
|
|
uint32_t refCount = isMarked ? UINT32_MAX : 0;
|
2013-11-21 02:35:16 +04:00
|
|
|
mResults.mVisitedGCed++;
|
2011-06-22 21:41:17 +04:00
|
|
|
|
|
|
|
if (mListener) {
|
2012-08-22 19:56:38 +04:00
|
|
|
mListener->NoteGCedObject((uint64_t)mCurrPi->mPointer, isMarked,
|
2013-11-12 17:53:51 +04:00
|
|
|
objName, aCompartmentAddress);
|
2011-06-22 21:41:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-27 21:41:04 +04:00
|
|
|
DescribeNode(refCount, objName);
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2007-09-18 04:30:06 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2013-05-04 19:39:44 +04:00
|
|
|
GCGraphBuilder::NoteXPCOMChild(nsISupports *child)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2010-08-12 04:03:23 +04:00
|
|
|
nsCString edgeName;
|
|
|
|
if (WantDebugInfo()) {
|
|
|
|
edgeName.Assign(mNextEdgeName);
|
|
|
|
mNextEdgeName.Truncate();
|
|
|
|
}
|
2012-08-24 20:50:06 +04:00
|
|
|
if (!child || !(child = CanonicalizeXPCOMParticipant(child)))
|
|
|
|
return;
|
2007-01-09 04:33:02 +03:00
|
|
|
|
2007-05-24 18:10:02 +04:00
|
|
|
nsXPCOMCycleCollectionParticipant *cp;
|
|
|
|
ToParticipant(child, &cp);
|
2012-01-30 04:45:08 +04:00
|
|
|
if (cp && (!cp->CanSkipThis(child) || WantAllTraces())) {
|
2012-05-03 23:28:11 +04:00
|
|
|
NoteChild(child, cp, edgeName);
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-18 04:30:06 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2007-05-24 18:10:02 +04:00
|
|
|
GCGraphBuilder::NoteNativeChild(void *child,
|
|
|
|
nsCycleCollectionParticipant *participant)
|
|
|
|
{
|
2010-08-12 04:03:23 +04:00
|
|
|
nsCString edgeName;
|
|
|
|
if (WantDebugInfo()) {
|
|
|
|
edgeName.Assign(mNextEdgeName);
|
|
|
|
mNextEdgeName.Truncate();
|
|
|
|
}
|
2007-05-24 18:10:02 +04:00
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(participant, "Need a nsCycleCollectionParticipant!");
|
2012-05-03 23:28:11 +04:00
|
|
|
NoteChild(child, participant, edgeName);
|
2007-05-24 18:10:02 +04:00
|
|
|
}
|
|
|
|
|
2007-09-18 04:30:06 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2013-05-04 19:39:44 +04:00
|
|
|
GCGraphBuilder::NoteJSChild(void *child)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2012-05-03 23:28:10 +04:00
|
|
|
if (!child) {
|
2008-06-21 19:25:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-03 23:28:10 +04:00
|
|
|
nsCString edgeName;
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(WantDebugInfo())) {
|
2012-05-03 23:28:10 +04:00
|
|
|
edgeName.Assign(mNextEdgeName);
|
|
|
|
mNextEdgeName.Truncate();
|
2007-04-21 21:43:19 +04:00
|
|
|
}
|
2007-01-09 04:33:02 +03:00
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
if (xpc_GCThingIsGrayCCThing(child) || MOZ_UNLIKELY(WantAllTraces())) {
|
2013-03-17 07:36:37 +04:00
|
|
|
if (JS::Zone *zone = MergeZone(child)) {
|
|
|
|
NoteChild(zone, mJSZoneParticipant, edgeName);
|
2012-06-27 19:09:56 +04:00
|
|
|
} else {
|
|
|
|
NoteChild(child, mJSParticipant, edgeName);
|
|
|
|
}
|
2011-03-29 00:05:48 +04:00
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2008-03-18 02:11:08 +03:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
GCGraphBuilder::NoteNextEdgeName(const char* name)
|
|
|
|
{
|
2010-08-12 04:03:23 +04:00
|
|
|
if (WantDebugInfo()) {
|
|
|
|
mNextEdgeName = name;
|
|
|
|
}
|
2009-07-09 05:10:29 +04:00
|
|
|
}
|
2008-03-18 02:11:08 +03:00
|
|
|
|
2011-11-24 16:35:56 +04:00
|
|
|
PtrInfo*
|
|
|
|
GCGraphBuilder::AddWeakMapNode(void *node)
|
|
|
|
{
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(node, "Weak map node should be non-null.");
|
2011-11-24 16:35:56 +04:00
|
|
|
|
|
|
|
if (!xpc_GCThingIsGrayCCThing(node) && !WantAllTraces())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-11-24 16:35:56 +04:00
|
|
|
|
2013-03-17 07:36:37 +04:00
|
|
|
if (JS::Zone *zone = MergeZone(node)) {
|
|
|
|
return AddNode(zone, mJSZoneParticipant);
|
2012-06-27 19:09:56 +04:00
|
|
|
} else {
|
|
|
|
return AddNode(node, mJSParticipant);
|
|
|
|
}
|
2011-11-24 16:35:56 +04:00
|
|
|
}
|
|
|
|
|
2011-11-24 16:35:56 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2012-10-18 05:22:46 +04:00
|
|
|
GCGraphBuilder::NoteWeakMapping(void *map, void *key, void *kdelegate, void *val)
|
2011-11-24 16:35:56 +04:00
|
|
|
{
|
2012-12-03 21:02:57 +04:00
|
|
|
// Don't try to optimize away the entry here, as we've already attempted to
|
|
|
|
// do that in TraceWeakMapping in nsXPConnect.
|
2013-11-21 02:35:16 +04:00
|
|
|
WeakMapping *mapping = mGraph.mWeakMaps.AppendElement();
|
2012-07-30 18:20:58 +04:00
|
|
|
mapping->mMap = map ? AddWeakMapNode(map) : nullptr;
|
|
|
|
mapping->mKey = key ? AddWeakMapNode(key) : nullptr;
|
2012-10-18 05:22:46 +04:00
|
|
|
mapping->mKeyDelegate = kdelegate ? AddWeakMapNode(kdelegate) : mapping->mKey;
|
2012-12-03 21:02:57 +04:00
|
|
|
mapping->mVal = val ? AddWeakMapNode(val) : nullptr;
|
2013-07-26 19:12:51 +04:00
|
|
|
|
|
|
|
if (mListener) {
|
|
|
|
mListener->NoteWeakMapEntry((uint64_t)map, (uint64_t)key,
|
|
|
|
(uint64_t)kdelegate, (uint64_t)val);
|
|
|
|
}
|
2011-11-24 16:35:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-24 20:50:06 +04:00
|
|
|
static bool
|
2013-09-07 00:40:34 +04:00
|
|
|
AddPurpleRoot(GCGraphBuilder &aBuilder, void *aRoot, nsCycleCollectionParticipant *aParti)
|
2012-08-24 20:50:06 +04:00
|
|
|
{
|
2013-09-07 00:40:34 +04:00
|
|
|
CanonicalizeParticipant(&aRoot, &aParti);
|
2012-08-24 20:50:06 +04:00
|
|
|
|
2013-09-07 00:40:34 +04:00
|
|
|
if (aBuilder.WantAllTraces() || !aParti->CanSkipInCC(aRoot)) {
|
|
|
|
PtrInfo *pinfo = aBuilder.AddNode(aRoot, aParti);
|
2012-08-24 20:50:06 +04:00
|
|
|
if (!pinfo) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-06 01:48:04 +04:00
|
|
|
// MayHaveChild() will be false after a Traverse if the object does
|
|
|
|
// not have any children the CC will visit.
|
|
|
|
class ChildFinder : public nsCycleCollectionTraversalCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ChildFinder() : mMayHaveChild(false) {}
|
|
|
|
|
|
|
|
// The logic of the Note*Child functions must mirror that of their
|
|
|
|
// respective functions in GCGraphBuilder.
|
|
|
|
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child);
|
|
|
|
NS_IMETHOD_(void) NoteNativeChild(void *child,
|
|
|
|
nsCycleCollectionParticipant *helper);
|
2012-05-03 23:28:10 +04:00
|
|
|
NS_IMETHOD_(void) NoteJSChild(void *child);
|
2012-03-06 01:48:04 +04:00
|
|
|
|
|
|
|
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refcount,
|
2012-07-26 19:16:28 +04:00
|
|
|
const char *objname) {}
|
2012-03-06 01:48:04 +04:00
|
|
|
NS_IMETHOD_(void) DescribeGCedNode(bool ismarked,
|
2013-11-12 17:53:51 +04:00
|
|
|
const char *objname,
|
|
|
|
uint64_t aCompartmentAddress) {}
|
2012-07-26 19:16:28 +04:00
|
|
|
NS_IMETHOD_(void) NoteNextEdgeName(const char* name) {}
|
2012-03-06 01:48:04 +04:00
|
|
|
bool MayHaveChild() {
|
|
|
|
return mMayHaveChild;
|
2012-07-26 19:16:28 +04:00
|
|
|
}
|
2012-03-06 01:48:04 +04:00
|
|
|
private:
|
|
|
|
bool mMayHaveChild;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
ChildFinder::NoteXPCOMChild(nsISupports *child)
|
|
|
|
{
|
2012-08-24 20:50:06 +04:00
|
|
|
if (!child || !(child = CanonicalizeXPCOMParticipant(child)))
|
|
|
|
return;
|
2012-03-06 01:48:04 +04:00
|
|
|
nsXPCOMCycleCollectionParticipant *cp;
|
|
|
|
ToParticipant(child, &cp);
|
|
|
|
if (cp && !cp->CanSkip(child, true))
|
|
|
|
mMayHaveChild = true;
|
2012-07-26 19:16:28 +04:00
|
|
|
}
|
2012-03-06 01:48:04 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
ChildFinder::NoteNativeChild(void *child,
|
|
|
|
nsCycleCollectionParticipant *helper)
|
|
|
|
{
|
|
|
|
if (child)
|
|
|
|
mMayHaveChild = true;
|
2012-07-26 19:16:28 +04:00
|
|
|
}
|
2012-03-06 01:48:04 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2012-05-03 23:28:10 +04:00
|
|
|
ChildFinder::NoteJSChild(void *child)
|
2012-03-06 01:48:04 +04:00
|
|
|
{
|
2012-05-03 23:28:10 +04:00
|
|
|
if (child && xpc_GCThingIsGrayCCThing(child)) {
|
|
|
|
mMayHaveChild = true;
|
2012-03-06 01:48:04 +04:00
|
|
|
}
|
2012-07-26 19:16:28 +04:00
|
|
|
}
|
2012-03-06 01:48:04 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2012-08-24 20:50:06 +04:00
|
|
|
MayHaveChild(void *o, nsCycleCollectionParticipant* cp)
|
2012-03-06 01:48:04 +04:00
|
|
|
{
|
|
|
|
ChildFinder cf;
|
|
|
|
cp->Traverse(o, cf);
|
|
|
|
return cf.MayHaveChild();
|
|
|
|
}
|
|
|
|
|
2013-07-09 21:30:58 +04:00
|
|
|
struct SnowWhiteObject
|
|
|
|
{
|
|
|
|
void* mPointer;
|
|
|
|
nsCycleCollectionParticipant* mParticipant;
|
|
|
|
nsCycleCollectingAutoRefCnt* mRefCnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SnowWhiteKiller
|
2012-01-14 20:58:05 +04:00
|
|
|
{
|
2013-04-30 21:41:23 +04:00
|
|
|
public:
|
2013-12-06 22:17:20 +04:00
|
|
|
SnowWhiteKiller(nsCycleCollector *aCollector, uint32_t aMaxCount)
|
|
|
|
: mCollector(aCollector)
|
2013-07-09 21:30:58 +04:00
|
|
|
{
|
2013-12-06 22:17:20 +04:00
|
|
|
MOZ_ASSERT(mCollector, "Calling SnowWhiteKiller after nsCC went away");
|
2013-07-19 16:53:16 +04:00
|
|
|
while (true) {
|
|
|
|
if (mObjects.SetCapacity(aMaxCount)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (aMaxCount == 1) {
|
|
|
|
NS_RUNTIMEABORT("Not enough memory to even delete objects!");
|
|
|
|
}
|
|
|
|
aMaxCount /= 2;
|
|
|
|
}
|
2013-07-09 21:30:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~SnowWhiteKiller()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mObjects.Length(); ++i) {
|
|
|
|
SnowWhiteObject& o = mObjects[i];
|
|
|
|
if (!o.mRefCnt->get() && !o.mRefCnt->IsInPurpleBuffer()) {
|
2013-12-06 22:17:20 +04:00
|
|
|
mCollector->RemoveObjectFromGraph(o.mPointer);
|
2013-07-09 21:30:58 +04:00
|
|
|
o.mRefCnt->stabilizeForDeletion();
|
|
|
|
o.mParticipant->DeleteCycleCollectable(o.mPointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Visit(nsPurpleBuffer& aBuffer, nsPurpleBufferEntry* aEntry)
|
|
|
|
{
|
2013-07-18 20:07:28 +04:00
|
|
|
MOZ_ASSERT(aEntry->mObject, "Null object in purple buffer");
|
|
|
|
if (!aEntry->mRefCnt->get()) {
|
2013-07-09 21:30:58 +04:00
|
|
|
void *o = aEntry->mObject;
|
|
|
|
nsCycleCollectionParticipant *cp = aEntry->mParticipant;
|
|
|
|
CanonicalizeParticipant(&o, &cp);
|
|
|
|
SnowWhiteObject swo = { o, cp, aEntry->mRefCnt };
|
2013-07-19 16:53:16 +04:00
|
|
|
if (mObjects.AppendElement(swo)) {
|
|
|
|
aBuffer.Remove(aEntry);
|
|
|
|
}
|
2013-07-09 21:30:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-07 00:40:34 +04:00
|
|
|
bool HasSnowWhiteObjects() const
|
2013-07-09 21:30:58 +04:00
|
|
|
{
|
|
|
|
return mObjects.Length() > 0;
|
|
|
|
}
|
2013-12-06 22:17:20 +04:00
|
|
|
|
2013-07-09 21:30:58 +04:00
|
|
|
private:
|
2013-12-06 22:17:20 +04:00
|
|
|
nsCycleCollector *mCollector;
|
2013-07-19 16:53:16 +04:00
|
|
|
FallibleTArray<SnowWhiteObject> mObjects;
|
2013-07-09 21:30:58 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class RemoveSkippableVisitor : public SnowWhiteKiller
|
|
|
|
{
|
|
|
|
public:
|
2013-07-27 14:48:45 +04:00
|
|
|
RemoveSkippableVisitor(nsCycleCollector* aCollector,
|
|
|
|
uint32_t aMaxCount, bool aRemoveChildlessNodes,
|
|
|
|
bool aAsyncSnowWhiteFreeing,
|
2013-07-09 21:30:58 +04:00
|
|
|
CC_ForgetSkippableCallback aCb)
|
2013-12-06 22:17:20 +04:00
|
|
|
: SnowWhiteKiller(aCollector, aAsyncSnowWhiteFreeing ? 0 : aMaxCount),
|
2013-07-09 21:30:58 +04:00
|
|
|
mRemoveChildlessNodes(aRemoveChildlessNodes),
|
2013-07-27 14:48:45 +04:00
|
|
|
mAsyncSnowWhiteFreeing(aAsyncSnowWhiteFreeing),
|
|
|
|
mDispatchedDeferredDeletion(false),
|
2013-07-09 21:30:58 +04:00
|
|
|
mCallback(aCb)
|
2013-04-30 21:41:23 +04:00
|
|
|
{}
|
|
|
|
|
2013-07-09 21:30:58 +04:00
|
|
|
~RemoveSkippableVisitor()
|
|
|
|
{
|
|
|
|
// Note, we must call the callback before SnowWhiteKiller calls
|
|
|
|
// DeleteCycleCollectable!
|
|
|
|
if (mCallback) {
|
|
|
|
mCallback();
|
|
|
|
}
|
2013-07-27 14:48:45 +04:00
|
|
|
if (HasSnowWhiteObjects()) {
|
|
|
|
// Effectively a continuation.
|
2013-08-04 03:55:39 +04:00
|
|
|
nsCycleCollector_dispatchDeferredDeletion(true);
|
2013-07-27 14:48:45 +04:00
|
|
|
}
|
2013-07-09 21:30:58 +04:00
|
|
|
}
|
|
|
|
|
2013-04-30 21:41:23 +04:00
|
|
|
void
|
|
|
|
Visit(nsPurpleBuffer &aBuffer, nsPurpleBufferEntry *aEntry)
|
|
|
|
{
|
2013-07-18 20:07:28 +04:00
|
|
|
MOZ_ASSERT(aEntry->mObject, "null mObject in purple buffer");
|
|
|
|
if (!aEntry->mRefCnt->get()) {
|
2013-07-27 14:48:45 +04:00
|
|
|
if (!mAsyncSnowWhiteFreeing) {
|
|
|
|
SnowWhiteKiller::Visit(aBuffer, aEntry);
|
|
|
|
} else if (!mDispatchedDeferredDeletion) {
|
|
|
|
mDispatchedDeferredDeletion = true;
|
2013-08-04 03:55:39 +04:00
|
|
|
nsCycleCollector_dispatchDeferredDeletion(false);
|
2013-07-27 14:48:45 +04:00
|
|
|
}
|
2013-07-18 20:07:28 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
void *o = aEntry->mObject;
|
|
|
|
nsCycleCollectionParticipant *cp = aEntry->mParticipant;
|
|
|
|
CanonicalizeParticipant(&o, &cp);
|
|
|
|
if (aEntry->mRefCnt->IsPurple() && !cp->CanSkip(o, false) &&
|
|
|
|
(!mRemoveChildlessNodes || MayHaveChild(o, cp))) {
|
|
|
|
return;
|
2012-01-14 20:58:05 +04:00
|
|
|
}
|
2013-04-30 21:41:23 +04:00
|
|
|
aBuffer.Remove(aEntry);
|
2012-01-14 20:58:05 +04:00
|
|
|
}
|
2013-04-30 21:41:23 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool mRemoveChildlessNodes;
|
2013-07-27 14:48:45 +04:00
|
|
|
bool mAsyncSnowWhiteFreeing;
|
|
|
|
bool mDispatchedDeferredDeletion;
|
2013-07-09 21:30:58 +04:00
|
|
|
CC_ForgetSkippableCallback mCallback;
|
2013-04-30 21:41:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2013-07-27 14:48:45 +04:00
|
|
|
nsPurpleBuffer::RemoveSkippable(nsCycleCollector* aCollector,
|
|
|
|
bool aRemoveChildlessNodes,
|
|
|
|
bool aAsyncSnowWhiteFreeing,
|
2013-07-09 21:30:58 +04:00
|
|
|
CC_ForgetSkippableCallback aCb)
|
2013-04-30 21:41:23 +04:00
|
|
|
{
|
2013-07-27 14:48:45 +04:00
|
|
|
RemoveSkippableVisitor visitor(aCollector, Count(), aRemoveChildlessNodes,
|
|
|
|
aAsyncSnowWhiteFreeing, aCb);
|
2013-04-30 21:41:23 +04:00
|
|
|
VisitEntries(visitor);
|
2013-07-09 21:30:58 +04:00
|
|
|
}
|
|
|
|
|
2013-07-27 14:48:45 +04:00
|
|
|
bool
|
2013-07-09 21:30:58 +04:00
|
|
|
nsCycleCollector::FreeSnowWhite(bool aUntilNoSWInPurpleBuffer)
|
|
|
|
{
|
2013-09-07 00:41:42 +04:00
|
|
|
CheckThreadSafety();
|
|
|
|
|
2013-07-27 14:48:45 +04:00
|
|
|
bool hadSnowWhiteObjects = false;
|
2013-07-09 21:30:58 +04:00
|
|
|
do {
|
2013-12-06 22:17:20 +04:00
|
|
|
SnowWhiteKiller visitor(this, mPurpleBuf.Count());
|
2013-07-09 21:30:58 +04:00
|
|
|
mPurpleBuf.VisitEntries(visitor);
|
2013-07-27 14:48:45 +04:00
|
|
|
hadSnowWhiteObjects = hadSnowWhiteObjects ||
|
|
|
|
visitor.HasSnowWhiteObjects();
|
2013-07-09 21:30:58 +04:00
|
|
|
if (!visitor.HasSnowWhiteObjects()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (aUntilNoSWInPurpleBuffer);
|
2013-07-27 14:48:45 +04:00
|
|
|
return hadSnowWhiteObjects;
|
2013-07-09 21:30:58 +04:00
|
|
|
}
|
|
|
|
|
2013-05-04 19:39:44 +04:00
|
|
|
void
|
2013-07-27 14:48:45 +04:00
|
|
|
nsCycleCollector::ForgetSkippable(bool aRemoveChildlessNodes,
|
|
|
|
bool aAsyncSnowWhiteFreeing)
|
2012-01-14 20:58:05 +04:00
|
|
|
{
|
2013-09-07 00:41:42 +04:00
|
|
|
CheckThreadSafety();
|
2013-12-18 07:29:57 +04:00
|
|
|
|
|
|
|
// If we remove things from the purple buffer during graph building, we may
|
|
|
|
// lose track of an object that was mutated during graph building. This should
|
|
|
|
// only happen when somebody calls nsJSContext::CycleCollectNow explicitly
|
|
|
|
// requesting extra forget skippable calls, during an incremental collection.
|
|
|
|
// See bug 950949 for fixing this so we actually run the forgetSkippable calls.
|
|
|
|
if (mIncrementalPhase != IdlePhase) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-20 01:06:50 +04:00
|
|
|
if (mJSRuntime) {
|
|
|
|
mJSRuntime->PrepareForForgetSkippable();
|
2012-01-14 20:58:05 +04:00
|
|
|
}
|
2013-09-10 19:56:36 +04:00
|
|
|
MOZ_ASSERT(!mScanInProgress, "Don't forget skippable or free snow-white while scan is in progress.");
|
2013-07-27 14:48:45 +04:00
|
|
|
mPurpleBuf.RemoveSkippable(this, aRemoveChildlessNodes,
|
|
|
|
aAsyncSnowWhiteFreeing, mForgetSkippableCB);
|
2012-01-14 20:58:05 +04:00
|
|
|
}
|
|
|
|
|
2012-02-21 00:13:29 +04:00
|
|
|
MOZ_NEVER_INLINE void
|
2013-12-03 22:47:47 +04:00
|
|
|
nsCycleCollector::MarkRoots(SliceBudget &aBudget)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-12-03 22:47:47 +04:00
|
|
|
const intptr_t kNumNodesBetweenTimeChecks = 1000;
|
|
|
|
const intptr_t kStep = SliceBudget::CounterReset / kNumNodesBetweenTimeChecks;
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
TimeLog timeLog;
|
|
|
|
AutoRestore<bool> ar(mScanInProgress);
|
|
|
|
MOZ_ASSERT(!mScanInProgress);
|
|
|
|
mScanInProgress = true;
|
2013-12-03 22:47:46 +04:00
|
|
|
MOZ_ASSERT(mIncrementalPhase == GraphBuildingPhase);
|
2013-12-03 22:47:47 +04:00
|
|
|
MOZ_ASSERT(mCurrNode);
|
2007-04-26 01:12:11 +04:00
|
|
|
|
2013-12-03 22:47:47 +04:00
|
|
|
while (!aBudget.isOverBudget() && !mCurrNode->IsDone()) {
|
2013-12-03 22:47:47 +04:00
|
|
|
PtrInfo *pi = mCurrNode->GetNext();
|
2012-02-21 00:13:29 +04:00
|
|
|
CC_AbortIfNull(pi);
|
2013-12-06 22:17:20 +04:00
|
|
|
// We need to call the builder's Traverse() method on deleted nodes, to
|
|
|
|
// set their firstChild() that may be read by a prior non-deleted
|
|
|
|
// neighbor.
|
2013-11-21 02:35:15 +04:00
|
|
|
mBuilder->Traverse(pi);
|
2013-12-03 22:47:47 +04:00
|
|
|
if (mCurrNode->AtBlockEnd()) {
|
2013-11-21 02:35:15 +04:00
|
|
|
mBuilder->SetLastChild();
|
2013-09-07 00:40:34 +04:00
|
|
|
}
|
2013-12-03 22:47:47 +04:00
|
|
|
aBudget.step(kStep);
|
2013-09-07 00:40:34 +04:00
|
|
|
}
|
2013-12-03 22:47:47 +04:00
|
|
|
|
|
|
|
if (!mCurrNode->IsDone()) {
|
2013-12-10 20:07:20 +04:00
|
|
|
timeLog.Checkpoint("MarkRoots()");
|
2013-12-03 22:47:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-07 00:40:34 +04:00
|
|
|
if (mGraph.mRootCount > 0) {
|
2013-11-21 02:35:15 +04:00
|
|
|
mBuilder->SetLastChild();
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2013-05-25 02:00:36 +04:00
|
|
|
|
2013-11-21 02:35:15 +04:00
|
|
|
if (mBuilder->RanOutOfMemory()) {
|
2013-11-07 04:58:13 +04:00
|
|
|
MOZ_ASSERT(false, "Ran out of memory while building cycle collector graph");
|
2013-09-10 19:29:45 +04:00
|
|
|
CC_TELEMETRY(_OOM, true);
|
2013-05-25 02:00:36 +04:00
|
|
|
}
|
2013-11-21 02:35:15 +04:00
|
|
|
|
|
|
|
mBuilder = nullptr;
|
2013-12-03 22:47:47 +04:00
|
|
|
mCurrNode = nullptr;
|
2013-12-03 22:47:46 +04:00
|
|
|
mIncrementalPhase = ScanAndCollectWhitePhase;
|
2013-11-21 02:35:16 +04:00
|
|
|
timeLog.Checkpoint("MarkRoots()");
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Bacon & Rajan's |ScanRoots| routine.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2010-01-12 19:51:39 +03:00
|
|
|
struct ScanBlackVisitor
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-05-29 04:42:13 +04:00
|
|
|
ScanBlackVisitor(uint32_t &aWhiteNodeCount, bool &aFailed)
|
|
|
|
: mWhiteNodeCount(aWhiteNodeCount), mFailed(aFailed)
|
2008-02-15 16:12:55 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ShouldVisitNode(PtrInfo const *pi)
|
2013-05-04 19:39:44 +04:00
|
|
|
{
|
2007-04-20 12:01:01 +04:00
|
|
|
return pi->mColor != black;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2012-02-21 00:13:29 +04:00
|
|
|
MOZ_NEVER_INLINE void VisitNode(PtrInfo *pi)
|
2007-11-02 01:51:57 +03:00
|
|
|
{
|
2008-02-15 16:12:55 +03:00
|
|
|
if (pi->mColor == white)
|
|
|
|
--mWhiteNodeCount;
|
2007-04-20 12:01:01 +04:00
|
|
|
pi->mColor = black;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2008-02-15 16:12:55 +03:00
|
|
|
|
2013-05-29 04:42:13 +04:00
|
|
|
void Failed()
|
|
|
|
{
|
|
|
|
mFailed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t &mWhiteNodeCount;
|
2013-05-29 04:42:13 +04:00
|
|
|
bool &mFailed;
|
2007-01-05 01:31:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-01-12 19:51:39 +03:00
|
|
|
struct scanVisitor
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-12-18 07:29:57 +04:00
|
|
|
scanVisitor(uint32_t &aWhiteNodeCount, bool &aFailed, bool aWasIncremental)
|
|
|
|
: mWhiteNodeCount(aWhiteNodeCount), mFailed(aFailed),
|
|
|
|
mWasIncremental(aWasIncremental)
|
2008-02-15 16:12:55 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ShouldVisitNode(PtrInfo const *pi)
|
2013-05-04 19:39:44 +04:00
|
|
|
{
|
2007-04-20 12:01:01 +04:00
|
|
|
return pi->mColor == grey;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2012-02-21 00:13:29 +04:00
|
|
|
MOZ_NEVER_INLINE void VisitNode(PtrInfo *pi)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-12-18 07:29:57 +04:00
|
|
|
if (pi->mInternalRefs > pi->mRefCount && pi->mRefCount > 0) {
|
|
|
|
// If we found more references to an object than its ref count, then
|
|
|
|
// the object should have already been marked as an incremental
|
|
|
|
// root. Note that this is imprecise, because pi could have been
|
|
|
|
// marked black for other reasons. Always fault if we weren't
|
|
|
|
// incremental, as there were no incremental roots in that case.
|
|
|
|
if (!mWasIncremental || pi->mColor != black) {
|
|
|
|
Fault("traversed refs exceed refcount", pi);
|
|
|
|
}
|
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2007-11-02 01:51:57 +03:00
|
|
|
if (pi->mInternalRefs == pi->mRefCount || pi->mRefCount == 0) {
|
2007-04-20 12:01:01 +04:00
|
|
|
pi->mColor = white;
|
2008-02-15 16:12:55 +03:00
|
|
|
++mWhiteNodeCount;
|
2007-01-05 01:31:26 +03:00
|
|
|
} else {
|
2013-05-29 04:42:13 +04:00
|
|
|
GraphWalker<ScanBlackVisitor>(ScanBlackVisitor(mWhiteNodeCount, mFailed)).Walk(pi);
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(pi->mColor == black,
|
|
|
|
"Why didn't ScanBlackVisitor make pi black?");
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
}
|
2008-02-15 16:12:55 +03:00
|
|
|
|
2013-05-29 04:42:13 +04:00
|
|
|
void Failed() {
|
|
|
|
mFailed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t &mWhiteNodeCount;
|
2013-05-29 04:42:13 +04:00
|
|
|
bool &mFailed;
|
2013-12-18 07:29:57 +04:00
|
|
|
bool mWasIncremental;
|
2007-01-05 01:31:26 +03:00
|
|
|
};
|
|
|
|
|
2011-11-24 16:35:57 +04:00
|
|
|
// Iterate over the WeakMaps. If we mark anything while iterating
|
|
|
|
// over the WeakMaps, we must iterate over all of the WeakMaps again.
|
|
|
|
void
|
|
|
|
nsCycleCollector::ScanWeakMaps()
|
|
|
|
{
|
|
|
|
bool anyChanged;
|
2013-05-29 04:42:13 +04:00
|
|
|
bool failed = false;
|
2011-11-24 16:35:57 +04:00
|
|
|
do {
|
|
|
|
anyChanged = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mGraph.mWeakMaps.Length(); i++) {
|
2011-11-24 16:35:57 +04:00
|
|
|
WeakMapping *wm = &mGraph.mWeakMaps[i];
|
|
|
|
|
2012-12-03 21:02:57 +04:00
|
|
|
// If any of these are null, the original object was marked black.
|
2012-05-25 11:18:30 +04:00
|
|
|
uint32_t mColor = wm->mMap ? wm->mMap->mColor : black;
|
|
|
|
uint32_t kColor = wm->mKey ? wm->mKey->mColor : black;
|
2012-10-18 05:22:46 +04:00
|
|
|
uint32_t kdColor = wm->mKeyDelegate ? wm->mKeyDelegate->mColor : black;
|
2012-12-03 21:02:57 +04:00
|
|
|
uint32_t vColor = wm->mVal ? wm->mVal->mColor : black;
|
2011-11-24 16:35:57 +04:00
|
|
|
|
|
|
|
// All non-null weak mapping maps, keys and values are
|
|
|
|
// roots (in the sense of WalkFromRoots) in the cycle
|
|
|
|
// collector graph, and thus should have been colored
|
|
|
|
// either black or white in ScanRoots().
|
2012-10-18 05:22:46 +04:00
|
|
|
MOZ_ASSERT(mColor != grey, "Uncolored weak map");
|
|
|
|
MOZ_ASSERT(kColor != grey, "Uncolored weak map key");
|
|
|
|
MOZ_ASSERT(kdColor != grey, "Uncolored weak map key delegate");
|
2012-12-03 21:02:57 +04:00
|
|
|
MOZ_ASSERT(vColor != grey, "Uncolored weak map value");
|
2012-10-18 05:22:46 +04:00
|
|
|
|
|
|
|
if (mColor == black && kColor != black && kdColor == black) {
|
2013-05-29 04:42:13 +04:00
|
|
|
GraphWalker<ScanBlackVisitor>(ScanBlackVisitor(mWhiteNodeCount, failed)).Walk(wm->mKey);
|
2012-10-18 05:22:46 +04:00
|
|
|
anyChanged = true;
|
|
|
|
}
|
2011-11-24 16:35:57 +04:00
|
|
|
|
2012-12-03 21:02:57 +04:00
|
|
|
if (mColor == black && kColor == black && vColor != black) {
|
2013-05-29 04:42:13 +04:00
|
|
|
GraphWalker<ScanBlackVisitor>(ScanBlackVisitor(mWhiteNodeCount, failed)).Walk(wm->mVal);
|
2011-11-24 16:35:57 +04:00
|
|
|
anyChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (anyChanged);
|
2013-05-29 04:42:13 +04:00
|
|
|
|
|
|
|
if (failed) {
|
2013-10-27 15:51:31 +04:00
|
|
|
MOZ_ASSERT(false, "Ran out of memory in ScanWeakMaps");
|
2013-09-10 19:29:45 +04:00
|
|
|
CC_TELEMETRY(_OOM, true);
|
2013-05-29 04:42:13 +04:00
|
|
|
}
|
2011-11-24 16:35:57 +04:00
|
|
|
}
|
|
|
|
|
2013-12-18 07:29:57 +04:00
|
|
|
// Flood black from any objects in the purple buffer that are in the CC graph.
|
|
|
|
class PurpleScanBlackVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PurpleScanBlackVisitor(GCGraph &aGraph, uint32_t &aCount, bool &aFailed)
|
|
|
|
: mGraph(aGraph), mCount(aCount), mFailed(aFailed)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Visit(nsPurpleBuffer &aBuffer, nsPurpleBufferEntry *aEntry)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aEntry->mObject, "Entries with null mObject shouldn't be in the purple buffer.");
|
|
|
|
MOZ_ASSERT(aEntry->mRefCnt->get() != 0, "Snow-white objects shouldn't be in the purple buffer.");
|
|
|
|
|
|
|
|
void *obj = aEntry->mObject;
|
|
|
|
if (!aEntry->mParticipant) {
|
|
|
|
obj = CanonicalizeXPCOMParticipant(static_cast<nsISupports*>(obj));
|
|
|
|
MOZ_ASSERT(obj, "Don't add objects that don't participate in collection!");
|
|
|
|
}
|
|
|
|
|
|
|
|
PtrInfo *pi = mGraph.FindNode(obj);
|
|
|
|
if (!pi) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(pi->mParticipant, "No dead objects should be in the purple buffer.");
|
|
|
|
if (pi->mColor == black) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GraphWalker<ScanBlackVisitor>(ScanBlackVisitor(mCount, mFailed)).Walk(pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GCGraph &mGraph;
|
|
|
|
uint32_t &mCount;
|
|
|
|
bool &mFailed;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Objects that have been stored somewhere since the start of incremental graph building must
|
|
|
|
// be treated as live for this cycle collection, because we may not have accurate information
|
|
|
|
// about who holds references to them.
|
2007-01-05 01:31:26 +03:00
|
|
|
void
|
2013-12-18 07:29:57 +04:00
|
|
|
nsCycleCollector::ScanIncrementalRoots()
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-11-21 02:35:16 +04:00
|
|
|
TimeLog timeLog;
|
2013-12-18 07:29:57 +04:00
|
|
|
|
|
|
|
// Reference counted objects:
|
|
|
|
// We cleared the purple buffer at the start of the current ICC, so if a
|
|
|
|
// refcounted object is purple, it may have been AddRef'd during the current
|
|
|
|
// ICC. (It may also have only been released.) If that is the case, we cannot
|
|
|
|
// be sure that the set of things pointing to the object in the CC graph
|
|
|
|
// is accurate. Therefore, for safety, we treat any purple objects as being
|
|
|
|
// live during the current CC. We don't remove anything from the purple
|
|
|
|
// buffer here, so these objects will be suspected and freed in the next CC
|
|
|
|
// if they are garbage.
|
|
|
|
bool failed = false;
|
|
|
|
PurpleScanBlackVisitor purpleScanBlackVisitor(mGraph, mWhiteNodeCount, failed);
|
|
|
|
mPurpleBuf.VisitEntries(purpleScanBlackVisitor);
|
|
|
|
timeLog.Checkpoint("ScanIncrementalRoots::fix purple");
|
|
|
|
|
|
|
|
// Garbage collected objects:
|
|
|
|
// If a GCed object was added to the graph with a refcount of zero, and is
|
|
|
|
// now marked black by the GC, it was probably gray before and was exposed
|
|
|
|
// to active JS, so it may have been stored somewhere, so it needs to be
|
|
|
|
// treated as live.
|
|
|
|
if (mJSRuntime) {
|
|
|
|
nsCycleCollectionParticipant *jsParticipant = mJSRuntime->GCThingParticipant();
|
|
|
|
nsCycleCollectionParticipant *zoneParticipant = mJSRuntime->ZoneParticipant();
|
|
|
|
NodePool::Enumerator etor(mGraph.mNodes);
|
|
|
|
|
|
|
|
while (!etor.IsDone()) {
|
|
|
|
PtrInfo *pi = etor.GetNext();
|
|
|
|
|
|
|
|
if (pi->mRefCount != 0 || pi->mColor == black) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pi->mParticipant == jsParticipant) {
|
|
|
|
if (xpc_GCThingIsGrayCCThing(pi->mPointer)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (pi->mParticipant == zoneParticipant) {
|
|
|
|
JS::Zone *zone = static_cast<JS::Zone*>(pi->mPointer);
|
|
|
|
if (js::ZoneGlobalsAreAllGray(zone)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "Non-JS thing with 0 refcount? Treating as live.");
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphWalker<ScanBlackVisitor>(ScanBlackVisitor(mWhiteNodeCount, failed)).Walk(pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
timeLog.Checkpoint("ScanIncrementalRoots::fix JS");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
NS_ASSERTION(false, "Ran out of memory in ScanIncrementalRoots");
|
|
|
|
CC_TELEMETRY(_OOM, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCycleCollector::ScanRoots(bool aFullySynchGraphBuild)
|
|
|
|
{
|
2013-11-21 02:35:16 +04:00
|
|
|
AutoRestore<bool> ar(mScanInProgress);
|
|
|
|
MOZ_ASSERT(!mScanInProgress);
|
|
|
|
mScanInProgress = true;
|
2008-02-15 16:12:55 +03:00
|
|
|
mWhiteNodeCount = 0;
|
2013-12-03 22:47:46 +04:00
|
|
|
MOZ_ASSERT(mIncrementalPhase == ScanAndCollectWhitePhase);
|
2008-02-15 16:12:55 +03:00
|
|
|
|
2013-12-18 07:29:57 +04:00
|
|
|
if (!aFullySynchGraphBuild) {
|
|
|
|
ScanIncrementalRoots();
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeLog timeLog;
|
|
|
|
|
2007-04-26 01:12:11 +04:00
|
|
|
// On the assumption that most nodes will be black, it's
|
|
|
|
// probably faster to use a GraphWalker than a
|
|
|
|
// NodePool::Enumerator.
|
2013-05-29 04:42:13 +04:00
|
|
|
bool failed = false;
|
2013-12-18 07:29:57 +04:00
|
|
|
scanVisitor sv(mWhiteNodeCount, failed, !aFullySynchGraphBuild);
|
|
|
|
GraphWalker<scanVisitor>(sv).WalkFromRoots(mGraph);
|
2013-12-18 07:29:57 +04:00
|
|
|
timeLog.Checkpoint("ScanRoots::WalkFromRoots");
|
2013-05-29 04:42:13 +04:00
|
|
|
|
|
|
|
if (failed) {
|
2013-11-07 04:58:13 +04:00
|
|
|
NS_ASSERTION(false, "Ran out of memory in ScanRoots");
|
2013-09-10 19:29:45 +04:00
|
|
|
CC_TELEMETRY(_OOM, true);
|
2013-05-29 04:42:13 +04:00
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-12-18 07:29:57 +04:00
|
|
|
// Scanning weak maps must be done last.
|
2011-11-24 16:35:57 +04:00
|
|
|
ScanWeakMaps();
|
2013-12-18 07:29:57 +04:00
|
|
|
timeLog.Checkpoint("ScanRoots::ScanWeakMaps");
|
2013-09-11 03:33:39 +04:00
|
|
|
|
2013-11-21 02:35:15 +04:00
|
|
|
if (mListener) {
|
|
|
|
mListener->BeginResults();
|
2013-09-11 03:33:39 +04:00
|
|
|
|
|
|
|
NodePool::Enumerator etor(mGraph.mNodes);
|
|
|
|
while (!etor.IsDone()) {
|
|
|
|
PtrInfo *pi = etor.GetNext();
|
2013-12-06 22:17:20 +04:00
|
|
|
if (!pi->mParticipant) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-11 03:33:40 +04:00
|
|
|
switch (pi->mColor) {
|
|
|
|
case black:
|
|
|
|
if (pi->mRefCount > 0 && pi->mRefCount < UINT32_MAX &&
|
|
|
|
pi->mInternalRefs != pi->mRefCount) {
|
2013-11-21 02:35:15 +04:00
|
|
|
mListener->DescribeRoot((uint64_t)pi->mPointer,
|
2013-09-11 03:33:40 +04:00
|
|
|
pi->mInternalRefs);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case white:
|
2013-11-21 02:35:15 +04:00
|
|
|
mListener->DescribeGarbage((uint64_t)pi->mPointer);
|
2013-09-11 03:33:40 +04:00
|
|
|
break;
|
|
|
|
case grey:
|
|
|
|
// With incremental CC, we can end up with a grey object after
|
|
|
|
// scanning if it is only reachable from an object that gets freed.
|
|
|
|
break;
|
2013-09-11 03:33:39 +04:00
|
|
|
}
|
|
|
|
}
|
2013-09-11 03:33:40 +04:00
|
|
|
|
2013-11-21 02:35:15 +04:00
|
|
|
mListener->End();
|
|
|
|
mListener = nullptr;
|
2013-12-18 07:29:57 +04:00
|
|
|
timeLog.Checkpoint("ScanRoots::listener");
|
2013-09-11 03:33:39 +04:00
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Bacon & Rajan's |CollectWhite| routine, somewhat modified.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-09-11 03:33:40 +04:00
|
|
|
nsCycleCollector::CollectWhite()
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
|
|
|
// Explanation of "somewhat modified": we have no way to collect the
|
|
|
|
// set of whites "all at once", we have to ask each of them to drop
|
|
|
|
// their outgoing links and assume this will cause the garbage cycle
|
|
|
|
// to *mostly* self-destruct (except for the reference we continue
|
2013-05-04 19:39:44 +04:00
|
|
|
// to hold).
|
|
|
|
//
|
2007-01-05 01:31:26 +03:00
|
|
|
// To do this "safely" we must make sure that the white nodes we're
|
|
|
|
// operating on are stable for the duration of our operation. So we
|
|
|
|
// make 3 sets of calls to language runtimes:
|
|
|
|
//
|
|
|
|
// - Root(whites), which should pin the whites in memory.
|
|
|
|
// - Unlink(whites), which drops outgoing links on each white.
|
|
|
|
// - Unroot(whites), which returns the whites to normal GC.
|
|
|
|
|
2012-02-12 20:02:01 +04:00
|
|
|
TimeLog timeLog;
|
2013-11-21 02:35:16 +04:00
|
|
|
nsAutoTArray<PtrInfo*, 4000> whiteNodes;
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-12-03 22:47:46 +04:00
|
|
|
MOZ_ASSERT(mIncrementalPhase == ScanAndCollectWhitePhase);
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
whiteNodes.SetCapacity(mWhiteNodeCount);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numWhiteGCed = 0;
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2008-01-10 17:10:03 +03:00
|
|
|
NodePool::Enumerator etor(mGraph.mNodes);
|
2007-04-26 01:12:11 +04:00
|
|
|
while (!etor.IsDone())
|
|
|
|
{
|
|
|
|
PtrInfo *pinfo = etor.GetNext();
|
2013-12-06 22:17:20 +04:00
|
|
|
if (pinfo->mColor == white && pinfo->mParticipant) {
|
2013-11-21 02:35:16 +04:00
|
|
|
whiteNodes.AppendElement(pinfo);
|
2013-09-12 05:57:53 +04:00
|
|
|
pinfo->mParticipant->Root(pinfo->mPointer);
|
|
|
|
if (pinfo->mRefCount == 0) {
|
2012-02-24 08:16:37 +04:00
|
|
|
// only JS objects have a refcount of 0
|
|
|
|
++numWhiteGCed;
|
2008-02-15 16:12:55 +03:00
|
|
|
}
|
2007-04-26 01:12:11 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-24 08:16:37 +04:00
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
uint32_t count = whiteNodes.Length();
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(numWhiteGCed <= count,
|
|
|
|
"More freed GCed nodes than total freed nodes.");
|
2013-11-21 02:35:16 +04:00
|
|
|
mResults.mFreedRefCounted += count - numWhiteGCed;
|
|
|
|
mResults.mFreedGCed += numWhiteGCed;
|
2012-02-24 08:16:37 +04:00
|
|
|
|
2012-02-12 20:02:01 +04:00
|
|
|
timeLog.Checkpoint("CollectWhite::Root");
|
2008-03-07 20:55:51 +03:00
|
|
|
|
2012-01-14 20:58:05 +04:00
|
|
|
if (mBeforeUnlinkCB) {
|
|
|
|
mBeforeUnlinkCB();
|
2012-02-12 20:02:01 +04:00
|
|
|
timeLog.Checkpoint("CollectWhite::BeforeUnlinkCB");
|
2012-01-14 20:58:05 +04:00
|
|
|
}
|
2008-03-07 20:55:51 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2013-11-21 02:35:16 +04:00
|
|
|
PtrInfo *pinfo = whiteNodes.ElementAt(i);
|
2013-12-06 22:17:20 +04:00
|
|
|
MOZ_ASSERT(pinfo->mParticipant, "Unlink shouldn't see objects removed from graph.");
|
2013-09-12 05:57:53 +04:00
|
|
|
pinfo->mParticipant->Unlink(pinfo->mPointer);
|
2012-11-28 04:56:06 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (mJSRuntime) {
|
|
|
|
mJSRuntime->AssertNoObjectsToTrace(pinfo->mPointer);
|
|
|
|
}
|
|
|
|
#endif
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2012-02-12 20:02:01 +04:00
|
|
|
timeLog.Checkpoint("CollectWhite::Unlink");
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2013-11-21 02:35:16 +04:00
|
|
|
PtrInfo *pinfo = whiteNodes.ElementAt(i);
|
2013-12-06 22:17:20 +04:00
|
|
|
MOZ_ASSERT(pinfo->mParticipant, "Unroot shouldn't see objects removed from graph.");
|
2013-09-12 05:57:53 +04:00
|
|
|
pinfo->mParticipant->Unroot(pinfo->mPointer);
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
2012-02-12 20:02:01 +04:00
|
|
|
timeLog.Checkpoint("CollectWhite::Unroot");
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-08-04 03:55:39 +04:00
|
|
|
nsCycleCollector_dispatchDeferredDeletion(false);
|
2013-12-03 22:47:46 +04:00
|
|
|
mIncrementalPhase = CleanupPhase;
|
2013-07-09 21:30:58 +04:00
|
|
|
|
2007-06-07 02:09:00 +04:00
|
|
|
return count > 0;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-15 04:26:47 +04:00
|
|
|
////////////////////////
|
2013-11-07 09:35:30 +04:00
|
|
|
// Memory reporting
|
2013-01-15 04:26:47 +04:00
|
|
|
////////////////////////
|
|
|
|
|
2013-12-08 09:39:47 +04:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(CycleCollectorMallocSizeOf)
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCycleCollector::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData)
|
|
|
|
{
|
|
|
|
size_t objectSize, graphNodesSize, graphEdgesSize, weakMapsSize,
|
|
|
|
purpleBufferSize;
|
2013-12-08 09:39:47 +04:00
|
|
|
SizeOfIncludingThis(CycleCollectorMallocSizeOf,
|
2013-11-07 09:35:30 +04:00
|
|
|
&objectSize,
|
|
|
|
&graphNodesSize, &graphEdgesSize,
|
|
|
|
&weakMapsSize,
|
|
|
|
&purpleBufferSize);
|
|
|
|
|
|
|
|
#define REPORT(_path, _amount, _desc) \
|
|
|
|
do { \
|
|
|
|
size_t amount = _amount; /* evaluate |_amount| only once */ \
|
|
|
|
if (amount > 0) { \
|
|
|
|
nsresult rv; \
|
|
|
|
rv = aHandleReport->Callback(EmptyCString(), \
|
|
|
|
NS_LITERAL_CSTRING(_path), \
|
|
|
|
KIND_HEAP, UNITS_BYTES, _amount, \
|
|
|
|
NS_LITERAL_CSTRING(_desc), \
|
|
|
|
aData); \
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) \
|
|
|
|
return rv; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
REPORT("explicit/cycle-collector/collector-object", objectSize,
|
|
|
|
"Memory used for the cycle collector object itself.");
|
|
|
|
|
|
|
|
REPORT("explicit/cycle-collector/graph-nodes", graphNodesSize,
|
|
|
|
"Memory used for the nodes of the cycle collector's graph. "
|
|
|
|
"This should be zero when the collector is idle.");
|
|
|
|
|
|
|
|
REPORT("explicit/cycle-collector/graph-edges", graphEdgesSize,
|
|
|
|
"Memory used for the edges of the cycle collector's graph. "
|
|
|
|
"This should be zero when the collector is idle.");
|
|
|
|
|
|
|
|
REPORT("explicit/cycle-collector/weak-maps", weakMapsSize,
|
|
|
|
"Memory used for the representation of weak maps in the "
|
|
|
|
"cycle collector's graph. "
|
|
|
|
"This should be zero when the collector is idle.");
|
|
|
|
|
|
|
|
REPORT("explicit/cycle-collector/purple-buffer", purpleBufferSize,
|
|
|
|
"Memory used for the cycle collector's purple buffer.");
|
|
|
|
|
|
|
|
#undef REPORT
|
|
|
|
|
|
|
|
return NS_OK;
|
2013-01-15 04:26:47 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Collector implementation
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-08-13 21:45:32 +04:00
|
|
|
nsCycleCollector::nsCycleCollector() :
|
2013-12-03 22:47:47 +04:00
|
|
|
mActivelyCollecting(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mScanInProgress(false),
|
2012-07-30 18:20:58 +04:00
|
|
|
mJSRuntime(nullptr),
|
2013-12-03 22:47:46 +04:00
|
|
|
mIncrementalPhase(IdlePhase),
|
2013-08-04 03:55:40 +04:00
|
|
|
mThread(NS_GetCurrentThread()),
|
2008-02-15 16:12:55 +03:00
|
|
|
mWhiteNodeCount(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mBeforeUnlinkCB(nullptr),
|
|
|
|
mForgetSkippableCB(nullptr),
|
2013-04-30 03:41:41 +04:00
|
|
|
mUnmergedNeeded(0),
|
|
|
|
mMergedInARow(0)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCycleCollector::~nsCycleCollector()
|
|
|
|
{
|
2013-11-07 09:35:30 +04:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2013-01-15 04:26:47 +04:00
|
|
|
void
|
2013-06-18 23:02:16 +04:00
|
|
|
nsCycleCollector::RegisterJSRuntime(CycleCollectedJSRuntime *aJSRuntime)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2012-05-03 23:28:11 +04:00
|
|
|
if (mJSRuntime)
|
|
|
|
Fault("multiple registrations of cycle collector JS runtime", aJSRuntime);
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2012-05-03 23:28:11 +04:00
|
|
|
mJSRuntime = aJSRuntime;
|
2013-01-15 04:26:47 +04:00
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
// We can't register as a reporter in nsCycleCollector() because that runs
|
2013-01-15 04:26:47 +04:00
|
|
|
// before the memory reporter manager is initialized. So we do it here
|
|
|
|
// instead.
|
|
|
|
static bool registered = false;
|
|
|
|
if (!registered) {
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterWeakMemoryReporter(this);
|
2013-01-15 04:26:47 +04:00
|
|
|
registered = true;
|
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2013-01-15 04:26:47 +04:00
|
|
|
void
|
2012-05-03 23:28:11 +04:00
|
|
|
nsCycleCollector::ForgetJSRuntime()
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2012-05-03 23:28:11 +04:00
|
|
|
if (!mJSRuntime)
|
|
|
|
Fault("forgetting non-registered cycle collector JS runtime");
|
2012-05-03 23:28:10 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mJSRuntime = nullptr;
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2007-05-24 18:10:02 +04:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2013-11-27 02:30:46 +04:00
|
|
|
HasParticipant(void *aPtr, nsCycleCollectionParticipant *aParti)
|
2007-05-24 18:10:02 +04:00
|
|
|
{
|
2013-11-27 02:30:46 +04:00
|
|
|
if (aParti) {
|
2012-08-24 20:50:06 +04:00
|
|
|
return true;
|
2013-11-27 02:30:46 +04:00
|
|
|
}
|
2007-05-24 18:10:02 +04:00
|
|
|
|
2012-08-24 20:50:06 +04:00
|
|
|
nsXPCOMCycleCollectionParticipant *xcp;
|
2013-11-27 02:30:46 +04:00
|
|
|
ToParticipant(static_cast<nsISupports*>(aPtr), &xcp);
|
2012-08-24 20:50:06 +04:00
|
|
|
return xcp != nullptr;
|
2007-05-24 18:10:02 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-17 18:05:13 +04:00
|
|
|
MOZ_ALWAYS_INLINE void
|
2013-11-27 02:30:46 +04:00
|
|
|
nsCycleCollector::Suspect(void *aPtr, nsCycleCollectionParticipant *aParti,
|
2013-07-09 21:30:58 +04:00
|
|
|
nsCycleCollectingAutoRefCnt *aRefCnt)
|
2009-05-07 00:46:04 +04:00
|
|
|
{
|
2013-03-26 01:26:00 +04:00
|
|
|
CheckThreadSafety();
|
2009-10-28 20:28:57 +03:00
|
|
|
|
2009-05-07 00:46:04 +04:00
|
|
|
// Re-entering ::Suspect during collection used to be a fault, but
|
|
|
|
// we are canonicalizing nsISupports pointers using QI, so we will
|
2013-05-04 19:39:44 +04:00
|
|
|
// see some spurious refcount traffic here.
|
2009-05-07 00:46:04 +04:00
|
|
|
|
2013-11-27 02:30:46 +04:00
|
|
|
if (MOZ_UNLIKELY(mScanInProgress)) {
|
2013-07-09 21:30:58 +04:00
|
|
|
return;
|
2013-11-27 02:30:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aPtr, "Don't suspect null pointers");
|
2009-05-07 00:46:04 +04:00
|
|
|
|
2013-11-27 02:30:46 +04:00
|
|
|
MOZ_ASSERT(HasParticipant(aPtr, aParti),
|
|
|
|
"Suspected nsISupports pointer must QI to nsXPCOMCycleCollectionParticipant");
|
2009-05-07 00:46:04 +04:00
|
|
|
|
2013-11-27 02:30:46 +04:00
|
|
|
mPurpleBuf.Put(aPtr, aParti, aRefCnt);
|
2009-05-07 00:46:04 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 01:26:00 +04:00
|
|
|
void
|
|
|
|
nsCycleCollector::CheckThreadSafety()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2013-08-04 03:55:40 +04:00
|
|
|
nsIThread* currentThread = NS_GetCurrentThread();
|
|
|
|
// XXXkhuey we can be called so late in shutdown that NS_GetCurrentThread
|
|
|
|
// returns null (after the thread manager has shut down)
|
|
|
|
MOZ_ASSERT(mThread == currentThread || !currentThread);
|
2013-03-26 01:26:00 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-06-16 02:53:00 +04:00
|
|
|
// The cycle collector uses the mark bitmap to discover what JS objects
|
|
|
|
// were reachable only from XPConnect roots that might participate in
|
|
|
|
// cycles. We ask the JS runtime whether we need to force a GC before
|
|
|
|
// this CC. It returns true on startup (before the mark bits have been set),
|
2013-05-04 19:39:44 +04:00
|
|
|
// and also when UnmarkGray has run out of stack. We also force GCs on shut
|
2011-06-16 02:53:00 +04:00
|
|
|
// down to collect cycles involving both DOM and JS.
|
|
|
|
void
|
2013-01-08 22:36:51 +04:00
|
|
|
nsCycleCollector::FixGrayBits(bool aForceGC)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-08-04 03:55:40 +04:00
|
|
|
CheckThreadSafety();
|
2011-06-16 02:53:00 +04:00
|
|
|
|
2012-05-03 23:28:10 +04:00
|
|
|
if (!mJSRuntime)
|
2011-06-16 02:53:00 +04:00
|
|
|
return;
|
2011-06-14 00:24:23 +04:00
|
|
|
|
2011-12-05 21:04:41 +04:00
|
|
|
if (!aForceGC) {
|
2013-01-08 22:36:51 +04:00
|
|
|
mJSRuntime->FixWeakMappingGrayBits();
|
|
|
|
|
2012-05-03 23:28:10 +04:00
|
|
|
bool needGC = mJSRuntime->NeedCollect();
|
2011-12-05 21:04:41 +04:00
|
|
|
// Only do a telemetry ping for non-shutdown CCs.
|
2013-09-10 19:29:45 +04:00
|
|
|
CC_TELEMETRY(_NEED_GC, needGC);
|
2011-12-05 21:04:41 +04:00
|
|
|
if (!needGC)
|
|
|
|
return;
|
2013-11-21 02:35:16 +04:00
|
|
|
mResults.mForcedGC = true;
|
2011-12-05 21:04:41 +04:00
|
|
|
}
|
2011-06-16 02:53:00 +04:00
|
|
|
|
2012-02-12 20:02:01 +04:00
|
|
|
TimeLog timeLog;
|
2013-01-28 00:35:12 +04:00
|
|
|
mJSRuntime->Collect(aForceGC ? JS::gcreason::SHUTDOWN_CC : JS::gcreason::CC_FORCED);
|
2012-02-12 20:02:01 +04:00
|
|
|
timeLog.Checkpoint("GC()");
|
2011-06-16 02:53:00 +04:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:52:30 +03:00
|
|
|
void
|
|
|
|
nsCycleCollector::CleanupAfterCollection()
|
|
|
|
{
|
2013-12-03 22:47:46 +04:00
|
|
|
MOZ_ASSERT(mIncrementalPhase == CleanupPhase);
|
2013-09-10 19:56:36 +04:00
|
|
|
mGraph.Clear();
|
2007-03-16 15:52:47 +03:00
|
|
|
|
2008-01-10 00:14:08 +03:00
|
|
|
#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
|
|
|
|
// possible.
|
|
|
|
_heapmin();
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t interval = (uint32_t) ((TimeStamp::Now() - mCollectionStart).ToMilliseconds());
|
2007-03-20 02:21:31 +03:00
|
|
|
#ifdef COLLECT_TIME_DEBUG
|
2012-02-12 20:02:01 +04:00
|
|
|
printf("cc: total cycle collector time was %ums\n", interval);
|
2013-11-21 02:35:16 +04:00
|
|
|
printf("cc: visited %u ref counted and %u GCed objects, freed %d ref counted and %d GCed objects.\n",
|
|
|
|
mResults.mVisitedRefCounted, mResults.mVisitedGCed,
|
|
|
|
mResults.mFreedRefCounted, mResults.mFreedGCed);
|
2012-02-12 20:02:01 +04:00
|
|
|
printf("cc: \n");
|
2007-03-20 02:21:31 +03:00
|
|
|
#endif
|
2013-09-10 19:29:45 +04:00
|
|
|
CC_TELEMETRY( , interval);
|
2013-11-21 02:35:16 +04:00
|
|
|
CC_TELEMETRY(_VISITED_REF_COUNTED, mResults.mVisitedRefCounted);
|
|
|
|
CC_TELEMETRY(_VISITED_GCED, mResults.mVisitedGCed);
|
2013-09-10 19:29:45 +04:00
|
|
|
CC_TELEMETRY(_COLLECTED, mWhiteNodeCount);
|
2013-11-21 02:35:16 +04:00
|
|
|
|
|
|
|
if (mJSRuntime) {
|
|
|
|
mJSRuntime->EndCycleCollectionCallback(mResults);
|
|
|
|
}
|
2013-12-03 22:47:46 +04:00
|
|
|
mIncrementalPhase = IdlePhase;
|
2010-11-12 01:52:30 +03:00
|
|
|
}
|
|
|
|
|
2012-02-24 08:16:37 +04:00
|
|
|
void
|
2013-09-11 03:33:40 +04:00
|
|
|
nsCycleCollector::ShutdownCollect()
|
2010-11-12 01:52:30 +03:00
|
|
|
{
|
2013-12-03 22:47:47 +04:00
|
|
|
SliceBudget unlimitedBudget;
|
2013-12-04 17:53:25 +04:00
|
|
|
uint32_t i;
|
|
|
|
for (i = 0; i < DEFAULT_SHUTDOWN_COLLECTIONS; ++i) {
|
2013-12-03 22:47:47 +04:00
|
|
|
if (!Collect(ShutdownCC, unlimitedBudget, nullptr)) {
|
2010-11-12 01:52:30 +03:00
|
|
|
break;
|
2013-09-07 00:42:27 +04:00
|
|
|
}
|
2010-11-12 01:52:30 +03:00
|
|
|
}
|
2013-12-18 14:01:32 +04:00
|
|
|
NS_ASSERTION(i < NORMAL_SHUTDOWN_COLLECTIONS, "Extra shutdown CC");
|
2007-11-02 01:51:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-03 22:47:47 +04:00
|
|
|
static void
|
|
|
|
PrintPhase(const char *aPhase)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_PHASES
|
|
|
|
printf("cc: begin %s on %s\n", aPhase,
|
|
|
|
NS_IsMainThread() ? "mainthread" : "worker");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-07 03:15:10 +04:00
|
|
|
bool
|
2013-04-30 03:41:41 +04:00
|
|
|
nsCycleCollector::Collect(ccType aCCType,
|
2013-12-03 22:47:47 +04:00
|
|
|
SliceBudget &aBudget,
|
2013-09-11 03:33:41 +04:00
|
|
|
nsICycleCollectorListener *aManualListener)
|
2013-03-26 01:26:00 +04:00
|
|
|
{
|
2013-08-13 21:45:32 +04:00
|
|
|
CheckThreadSafety();
|
|
|
|
|
2013-09-10 19:56:34 +04:00
|
|
|
// This can legitimately happen in a few cases. See bug 383651.
|
2013-12-03 22:47:47 +04:00
|
|
|
if (mActivelyCollecting) {
|
2013-09-07 03:16:45 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-03 22:47:47 +04:00
|
|
|
mActivelyCollecting = true;
|
2013-09-07 03:16:45 +04:00
|
|
|
|
2013-12-03 22:47:47 +04:00
|
|
|
bool startedIdle = (mIncrementalPhase == IdlePhase);
|
|
|
|
bool collectedAny = false;
|
|
|
|
|
|
|
|
// If the CC started idle, it will call BeginCollection, which
|
|
|
|
// will do FreeSnowWhite, so it doesn't need to be done here.
|
|
|
|
if (!startedIdle) {
|
|
|
|
FreeSnowWhite(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool finished = false;
|
|
|
|
do {
|
|
|
|
switch (mIncrementalPhase) {
|
|
|
|
case IdlePhase:
|
2013-12-03 22:47:47 +04:00
|
|
|
PrintPhase("BeginCollection");
|
2013-12-03 22:47:47 +04:00
|
|
|
BeginCollection(aCCType, aManualListener);
|
|
|
|
break;
|
|
|
|
case GraphBuildingPhase:
|
2013-12-03 22:47:47 +04:00
|
|
|
PrintPhase("MarkRoots");
|
2013-12-03 22:47:47 +04:00
|
|
|
MarkRoots(aBudget);
|
2013-12-03 22:47:47 +04:00
|
|
|
break;
|
|
|
|
case ScanAndCollectWhitePhase:
|
|
|
|
// We do ScanRoots and CollectWhite in a single slice to ensure
|
|
|
|
// that we won't unlink a live object if a weak reference is
|
|
|
|
// promoted to a strong reference after ScanRoots has finished.
|
|
|
|
// See bug 926533.
|
2013-12-03 22:47:47 +04:00
|
|
|
PrintPhase("ScanRoots");
|
2013-12-18 07:29:57 +04:00
|
|
|
ScanRoots(startedIdle);
|
2013-12-03 22:47:47 +04:00
|
|
|
PrintPhase("CollectWhite");
|
2013-12-03 22:47:47 +04:00
|
|
|
collectedAny = CollectWhite();
|
|
|
|
break;
|
|
|
|
case CleanupPhase:
|
2013-12-03 22:47:47 +04:00
|
|
|
PrintPhase("CleanupAfterCollection");
|
2013-12-03 22:47:47 +04:00
|
|
|
CleanupAfterCollection();
|
|
|
|
finished = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!aBudget.checkOverBudget() && !finished);
|
2013-12-03 22:47:46 +04:00
|
|
|
|
2013-12-03 22:47:47 +04:00
|
|
|
mActivelyCollecting = false;
|
2013-12-03 22:47:46 +04:00
|
|
|
|
2013-12-03 22:47:47 +04:00
|
|
|
if (aCCType != ScheduledCC && !startedIdle) {
|
|
|
|
// We were in the middle of an incremental CC (using its own listener).
|
|
|
|
// Somebody has forced a CC, so after having finished out the current CC,
|
|
|
|
// run the CC again using the new listener.
|
|
|
|
MOZ_ASSERT(mIncrementalPhase == IdlePhase);
|
|
|
|
if (Collect(aCCType, aBudget, aManualListener)) {
|
|
|
|
collectedAny = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT_IF(aCCType != ScheduledCC, mIncrementalPhase == IdlePhase);
|
2013-12-03 22:47:46 +04:00
|
|
|
|
2013-09-07 03:15:10 +04:00
|
|
|
return collectedAny;
|
2013-03-26 01:26:00 +04:00
|
|
|
}
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
// Any JS objects we have in the graph could die when we GC, but we
|
|
|
|
// don't want to abandon the current CC, because the graph contains
|
|
|
|
// information about purple roots. So we synchronously finish off
|
|
|
|
// the current CC.
|
2013-12-20 01:57:55 +04:00
|
|
|
void nsCycleCollector::PrepareForGarbageCollection()
|
2013-12-06 22:17:20 +04:00
|
|
|
{
|
|
|
|
if (mIncrementalPhase == IdlePhase) {
|
|
|
|
MOZ_ASSERT(mGraph.IsEmpty(), "Non-empty graph when idle");
|
|
|
|
MOZ_ASSERT(!mBuilder, "Non-null builder when idle");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SliceBudget unlimitedBudget;
|
|
|
|
PrintPhase("PrepareForGarbageCollection");
|
|
|
|
Collect(ScheduledCC, unlimitedBudget, nullptr);
|
|
|
|
MOZ_ASSERT(mIncrementalPhase == IdlePhase);
|
|
|
|
}
|
|
|
|
|
2013-04-30 03:41:41 +04:00
|
|
|
// Don't merge too many times in a row, and do at least a minimum
|
|
|
|
// number of unmerged CCs in a row.
|
|
|
|
static const uint32_t kMinConsecutiveUnmerged = 3;
|
|
|
|
static const uint32_t kMaxConsecutiveMerged = 3;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-04-30 03:41:41 +04:00
|
|
|
nsCycleCollector::ShouldMergeZones(ccType aCCType)
|
|
|
|
{
|
|
|
|
if (!mJSRuntime) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mUnmergedNeeded <= kMinConsecutiveUnmerged);
|
|
|
|
MOZ_ASSERT(mMergedInARow <= kMaxConsecutiveMerged);
|
|
|
|
|
|
|
|
if (mMergedInARow == kMaxConsecutiveMerged) {
|
|
|
|
MOZ_ASSERT(mUnmergedNeeded == 0);
|
|
|
|
mUnmergedNeeded = kMinConsecutiveUnmerged;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUnmergedNeeded > 0) {
|
|
|
|
mUnmergedNeeded--;
|
|
|
|
mMergedInARow = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCCType == ScheduledCC && mJSRuntime->UsefulToMergeZones()) {
|
|
|
|
mMergedInARow++;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
mMergedInARow = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-07 00:42:27 +04:00
|
|
|
void
|
2013-04-30 03:41:41 +04:00
|
|
|
nsCycleCollector::BeginCollection(ccType aCCType,
|
2013-09-11 03:33:41 +04:00
|
|
|
nsICycleCollectorListener *aManualListener)
|
2007-11-02 01:51:57 +03:00
|
|
|
{
|
2012-02-12 20:02:01 +04:00
|
|
|
TimeLog timeLog;
|
2013-12-03 22:47:46 +04:00
|
|
|
MOZ_ASSERT(mIncrementalPhase == IdlePhase);
|
2013-11-21 02:35:16 +04:00
|
|
|
|
|
|
|
mCollectionStart = TimeStamp::Now();
|
|
|
|
|
|
|
|
if (mJSRuntime) {
|
|
|
|
mJSRuntime->BeginCycleCollectionCallback();
|
|
|
|
timeLog.Checkpoint("BeginCycleCollectionCallback()");
|
|
|
|
}
|
|
|
|
|
2013-09-11 03:33:41 +04:00
|
|
|
bool isShutdown = (aCCType == ShutdownCC);
|
|
|
|
|
|
|
|
// Set up the listener for this CC.
|
2013-09-11 03:33:41 +04:00
|
|
|
MOZ_ASSERT_IF(isShutdown, !aManualListener);
|
2013-11-21 02:35:15 +04:00
|
|
|
MOZ_ASSERT(!mListener, "Forgot to clear a previous listener?");
|
|
|
|
mListener = aManualListener;
|
2013-09-11 03:33:41 +04:00
|
|
|
aManualListener = nullptr;
|
2013-11-21 02:35:15 +04:00
|
|
|
if (!mListener) {
|
2013-09-11 03:33:41 +04:00
|
|
|
if (mParams.mLogAll || (isShutdown && mParams.mLogShutdown)) {
|
|
|
|
nsRefPtr<nsCycleCollectorLogger> logger = new nsCycleCollectorLogger();
|
|
|
|
if (isShutdown && mParams.mAllTracesAtShutdown) {
|
|
|
|
logger->SetAllTraces();
|
|
|
|
}
|
2013-11-21 02:35:15 +04:00
|
|
|
mListener = logger.forget();
|
2013-09-11 03:33:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool forceGC = isShutdown;
|
2013-11-21 02:35:15 +04:00
|
|
|
if (!forceGC && mListener) {
|
2013-09-11 03:33:41 +04:00
|
|
|
// On a WantAllTraces CC, force a synchronous global GC to prevent
|
|
|
|
// hijinks from ForgetSkippable and compartmental GCs.
|
2013-11-21 02:35:15 +04:00
|
|
|
mListener->GetWantAllTraces(&forceGC);
|
2013-09-11 03:33:41 +04:00
|
|
|
}
|
|
|
|
FixGrayBits(forceGC);
|
|
|
|
|
|
|
|
FreeSnowWhite(true);
|
|
|
|
|
2013-11-21 02:35:15 +04:00
|
|
|
if (mListener && NS_FAILED(mListener->Begin())) {
|
|
|
|
mListener = nullptr;
|
2013-09-11 03:33:41 +04:00
|
|
|
}
|
2012-02-12 20:02:01 +04:00
|
|
|
|
2013-09-11 03:33:41 +04:00
|
|
|
// Set up the data structures for building the graph.
|
2013-11-21 02:35:17 +04:00
|
|
|
mGraph.Init();
|
2013-11-21 02:35:16 +04:00
|
|
|
mResults.Init();
|
2013-04-30 03:41:41 +04:00
|
|
|
bool mergeZones = ShouldMergeZones(aCCType);
|
2013-11-21 02:35:16 +04:00
|
|
|
mResults.mMergedZones = mergeZones;
|
2013-04-30 03:41:41 +04:00
|
|
|
|
2013-11-21 02:35:15 +04:00
|
|
|
MOZ_ASSERT(!mBuilder, "Forgot to clear mBuilder");
|
2013-11-21 02:35:16 +04:00
|
|
|
mBuilder = new GCGraphBuilder(mGraph, mResults, mJSRuntime, mListener, mergeZones);
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2012-05-03 23:28:11 +04:00
|
|
|
if (mJSRuntime) {
|
2013-11-21 02:35:15 +04:00
|
|
|
mJSRuntime->BeginCycleCollection(*mBuilder);
|
2012-05-03 23:28:11 +04:00
|
|
|
timeLog.Checkpoint("mJSRuntime->BeginCycleCollection()");
|
2007-11-02 01:51:57 +03:00
|
|
|
}
|
2007-03-20 02:21:31 +03:00
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
AutoRestore<bool> ar(mScanInProgress);
|
|
|
|
MOZ_ASSERT(!mScanInProgress);
|
2011-10-17 18:59:28 +04:00
|
|
|
mScanInProgress = true;
|
2013-11-21 02:35:15 +04:00
|
|
|
mPurpleBuf.SelectPointers(*mBuilder);
|
2013-09-07 00:41:11 +04:00
|
|
|
timeLog.Checkpoint("SelectPointers()");
|
2007-03-20 02:21:31 +03:00
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
// We've finished adding roots, and everything in the graph is a root.
|
|
|
|
mGraph.mRootCount = mGraph.MapCount();
|
2013-12-03 22:47:46 +04:00
|
|
|
|
2013-12-03 22:47:47 +04:00
|
|
|
mCurrNode = new NodePool::Enumerator(mGraph.mNodes);
|
2013-12-03 22:47:46 +04:00
|
|
|
mIncrementalPhase = GraphBuildingPhase;
|
2008-01-10 17:10:03 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2008-02-25 20:47:25 +03:00
|
|
|
nsCycleCollector::SuspectedCount()
|
|
|
|
{
|
2013-09-07 00:41:42 +04:00
|
|
|
CheckThreadSafety();
|
2008-02-25 20:47:25 +03:00
|
|
|
return mPurpleBuf.Count();
|
|
|
|
}
|
|
|
|
|
2007-01-25 03:24:08 +03:00
|
|
|
void
|
|
|
|
nsCycleCollector::Shutdown()
|
|
|
|
{
|
2013-09-07 00:41:42 +04:00
|
|
|
CheckThreadSafety();
|
|
|
|
|
2013-07-09 21:30:58 +04:00
|
|
|
// Always delete snow white objects.
|
|
|
|
FreeSnowWhite(true);
|
|
|
|
|
2012-12-14 22:41:11 +04:00
|
|
|
#ifndef DEBUG
|
|
|
|
if (PR_GetEnv("XPCOM_CC_RUN_DURING_SHUTDOWN"))
|
|
|
|
#endif
|
|
|
|
{
|
2013-09-11 03:33:40 +04:00
|
|
|
ShutdownCollect();
|
2011-08-17 21:35:40 +04:00
|
|
|
}
|
2007-01-25 03:24:08 +03:00
|
|
|
}
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
void
|
|
|
|
nsCycleCollector::RemoveObjectFromGraph(void *aObj)
|
|
|
|
{
|
|
|
|
if (mIncrementalPhase == IdlePhase) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PtrInfo *pinfo = mGraph.FindNode(aObj)) {
|
|
|
|
mGraph.RemoveNodeFromMap(aObj);
|
|
|
|
|
|
|
|
pinfo->mPointer = nullptr;
|
|
|
|
pinfo->mParticipant = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-07 05:38:29 +04:00
|
|
|
void
|
2013-11-07 09:35:30 +04:00
|
|
|
nsCycleCollector::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
2012-11-07 05:38:29 +04:00
|
|
|
size_t *aObjectSize,
|
|
|
|
size_t *aGraphNodesSize,
|
|
|
|
size_t *aGraphEdgesSize,
|
2013-09-10 19:56:36 +04:00
|
|
|
size_t *aWeakMapsSize,
|
2012-11-07 05:38:29 +04:00
|
|
|
size_t *aPurpleBufferSize) const
|
2011-07-09 02:49:31 +04:00
|
|
|
{
|
2012-11-07 05:38:29 +04:00
|
|
|
*aObjectSize = aMallocSizeOf(this);
|
|
|
|
|
2013-09-10 19:56:36 +04:00
|
|
|
mGraph.SizeOfExcludingThis(aMallocSizeOf, aGraphNodesSize, aGraphEdgesSize,
|
|
|
|
aWeakMapsSize);
|
2012-11-07 05:38:29 +04:00
|
|
|
|
|
|
|
*aPurpleBufferSize = mPurpleBuf.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// These fields are deliberately not measured:
|
|
|
|
// - mJSRuntime: because it's non-owning and measured by JS reporters.
|
|
|
|
// - mParams: because it only contains scalars.
|
2011-07-09 02:49:31 +04:00
|
|
|
}
|
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Module public API (exported in nsCycleCollector.h)
|
|
|
|
// Just functions that redirect into the singleton, once it's built.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-03 23:28:11 +04:00
|
|
|
void
|
2013-06-18 23:02:16 +04:00
|
|
|
nsCycleCollector_registerJSRuntime(CycleCollectedJSRuntime *rt)
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
|
|
|
// But we shouldn't already have a runtime.
|
|
|
|
MOZ_ASSERT(!data->mRuntime);
|
|
|
|
|
|
|
|
data->mRuntime = rt;
|
|
|
|
data->mCollector->RegisterJSRuntime(rt);
|
2007-01-05 01:31:26 +03:00
|
|
|
}
|
|
|
|
|
2012-11-07 05:38:29 +04:00
|
|
|
void
|
2012-05-03 23:28:11 +04:00
|
|
|
nsCycleCollector_forgetJSRuntime()
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
// And we shouldn't have already forgotten our runtime.
|
|
|
|
MOZ_ASSERT(data->mRuntime);
|
2009-05-07 00:46:04 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// But it may have shutdown already.
|
|
|
|
if (data->mCollector) {
|
|
|
|
data->mCollector->ForgetJSRuntime();
|
|
|
|
data->mRuntime = nullptr;
|
|
|
|
} else {
|
|
|
|
data->mRuntime = nullptr;
|
|
|
|
delete data;
|
|
|
|
sCollectorData.set(nullptr);
|
|
|
|
}
|
2009-05-07 00:46:04 +04:00
|
|
|
}
|
|
|
|
|
2013-09-09 07:28:50 +04:00
|
|
|
/* static */ CycleCollectedJSRuntime*
|
|
|
|
CycleCollectedJSRuntime::Get()
|
2013-08-30 13:47:19 +04:00
|
|
|
{
|
|
|
|
CollectorData* data = sCollectorData.get();
|
|
|
|
if (data) {
|
|
|
|
return data->mRuntime;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-08-17 00:10:17 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace cyclecollector {
|
|
|
|
|
2013-06-18 23:01:26 +04:00
|
|
|
void
|
2013-08-17 00:10:17 +04:00
|
|
|
HoldJSObjectsImpl(void* aHolder, nsScriptObjectTracer* aTracer)
|
2013-06-18 23:01:26 +04:00
|
|
|
{
|
2013-08-17 00:10:17 +04:00
|
|
|
CollectorData* data = sCollectorData.get();
|
2013-06-18 23:01:26 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
|
|
|
// And we should have a runtime.
|
|
|
|
MOZ_ASSERT(data->mRuntime);
|
2013-06-18 23:01:26 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
data->mRuntime->AddJSHolder(aHolder, aTracer);
|
2013-06-18 23:01:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-17 00:10:17 +04:00
|
|
|
HoldJSObjectsImpl(nsISupports* aHolder)
|
2013-06-18 23:01:26 +04:00
|
|
|
{
|
2013-08-17 00:10:17 +04:00
|
|
|
nsXPCOMCycleCollectionParticipant* participant;
|
|
|
|
CallQueryInterface(aHolder, &participant);
|
|
|
|
MOZ_ASSERT(participant, "Failed to QI to nsXPCOMCycleCollectionParticipant!");
|
|
|
|
MOZ_ASSERT(participant->CheckForRightISupports(aHolder),
|
|
|
|
"The result of QIing a JS holder should be the same as ToSupports");
|
|
|
|
|
|
|
|
HoldJSObjectsImpl(aHolder, participant);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DropJSObjectsImpl(void* aHolder)
|
|
|
|
{
|
|
|
|
CollectorData* data = sCollectorData.get();
|
2013-06-18 23:01:26 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now, and not completely
|
|
|
|
// shut down.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
// And we should have a runtime.
|
|
|
|
MOZ_ASSERT(data->mRuntime);
|
2013-06-18 23:01:26 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
data->mRuntime->RemoveJSHolder(aHolder);
|
2013-06-18 23:01:26 +04:00
|
|
|
}
|
|
|
|
|
2013-08-17 00:10:17 +04:00
|
|
|
void
|
|
|
|
DropJSObjectsImpl(nsISupports* aHolder)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsXPCOMCycleCollectionParticipant* participant;
|
|
|
|
CallQueryInterface(aHolder, &participant);
|
|
|
|
MOZ_ASSERT(participant, "Failed to QI to nsXPCOMCycleCollectionParticipant!");
|
|
|
|
MOZ_ASSERT(participant->CheckForRightISupports(aHolder),
|
|
|
|
"The result of QIing a JS holder should be the same as ToSupports");
|
|
|
|
#endif
|
|
|
|
DropJSObjectsImpl(static_cast<void*>(aHolder));
|
|
|
|
}
|
|
|
|
|
2013-06-18 23:01:26 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool
|
2013-08-17 00:10:17 +04:00
|
|
|
IsJSHolder(void* aHolder)
|
2013-06-18 23:01:26 +04:00
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2013-06-18 23:01:26 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now, and not completely
|
|
|
|
// shut down.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
// And we should have a runtime.
|
|
|
|
MOZ_ASSERT(data->mRuntime);
|
2013-06-18 23:01:26 +04:00
|
|
|
|
2013-08-15 21:29:02 +04:00
|
|
|
return data->mRuntime->IsJSHolder(aHolder);
|
2013-06-18 23:01:26 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-09 18:28:15 +04:00
|
|
|
void
|
2013-08-17 00:10:17 +04:00
|
|
|
DeferredFinalize(nsISupports* aSupports)
|
2013-07-09 18:28:15 +04:00
|
|
|
{
|
|
|
|
CollectorData *data = sCollectorData.get();
|
|
|
|
|
|
|
|
// We should have started the cycle collector by now, and not completely
|
|
|
|
// shut down.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
// And we should have a runtime.
|
|
|
|
MOZ_ASSERT(data->mRuntime);
|
|
|
|
|
|
|
|
data->mRuntime->DeferredFinalize(aSupports);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-17 00:10:17 +04:00
|
|
|
DeferredFinalize(DeferredFinalizeAppendFunction aAppendFunc,
|
|
|
|
DeferredFinalizeFunction aFunc,
|
|
|
|
void* aThing)
|
2013-07-09 18:28:15 +04:00
|
|
|
{
|
|
|
|
CollectorData *data = sCollectorData.get();
|
|
|
|
|
|
|
|
// We should have started the cycle collector by now, and not completely
|
|
|
|
// shut down.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
// And we should have a runtime.
|
|
|
|
MOZ_ASSERT(data->mRuntime);
|
|
|
|
|
|
|
|
data->mRuntime->DeferredFinalize(aAppendFunc, aFunc, aThing);
|
|
|
|
}
|
|
|
|
|
2013-08-17 00:10:17 +04:00
|
|
|
} // namespace cyclecollector
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
|
2013-10-17 18:05:13 +04:00
|
|
|
MOZ_NEVER_INLINE static void
|
|
|
|
SuspectAfterShutdown(void* n, nsCycleCollectionParticipant* cp,
|
|
|
|
nsCycleCollectingAutoRefCnt* aRefCnt,
|
|
|
|
bool* aShouldDelete)
|
|
|
|
{
|
|
|
|
if (aRefCnt->get() == 0) {
|
|
|
|
if (!aShouldDelete) {
|
2013-12-06 22:17:20 +04:00
|
|
|
// The CC is shut down, so we can't be in the middle of an ICC.
|
2013-10-17 18:05:13 +04:00
|
|
|
CanonicalizeParticipant(&n, &cp);
|
|
|
|
aRefCnt->stabilizeForDeletion();
|
|
|
|
cp->DeleteCycleCollectable(n);
|
|
|
|
} else {
|
|
|
|
*aShouldDelete = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Make sure we'll get called again.
|
|
|
|
aRefCnt->RemoveFromPurpleBuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 21:30:58 +04:00
|
|
|
void
|
|
|
|
NS_CycleCollectorSuspect3(void *n, nsCycleCollectionParticipant *cp,
|
|
|
|
nsCycleCollectingAutoRefCnt *aRefCnt,
|
|
|
|
bool* aShouldDelete)
|
2010-11-12 01:52:30 +03:00
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2012-06-12 21:06:20 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-10-17 18:05:13 +04:00
|
|
|
if (MOZ_LIKELY(data->mCollector)) {
|
|
|
|
data->mCollector->Suspect(n, cp, aRefCnt);
|
2013-07-09 21:30:58 +04:00
|
|
|
return;
|
2010-11-12 01:52:30 +03:00
|
|
|
}
|
2013-10-17 18:05:13 +04:00
|
|
|
SuspectAfterShutdown(n, cp, aRefCnt, aShouldDelete);
|
2013-03-26 01:26:00 +04:00
|
|
|
}
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-03-26 01:26:00 +04:00
|
|
|
uint32_t
|
|
|
|
nsCycleCollector_suspectedCount()
|
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
|
|
|
|
if (!data->mCollector) {
|
2013-03-26 01:26:00 +04:00
|
|
|
return 0;
|
2010-11-12 01:52:30 +03:00
|
|
|
}
|
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
return data->mCollector->SuspectedCount();
|
2013-03-26 01:26:00 +04:00
|
|
|
}
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-03-26 01:26:00 +04:00
|
|
|
bool
|
|
|
|
nsCycleCollector_init()
|
2010-11-12 01:52:30 +03:00
|
|
|
{
|
2012-11-15 11:32:39 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
2013-06-18 23:02:16 +04:00
|
|
|
MOZ_ASSERT(!sCollectorData.initialized(), "Called twice!?");
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
return sCollectorData.init();
|
2013-03-26 01:26:00 +04:00
|
|
|
}
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-08-13 21:45:32 +04:00
|
|
|
void
|
|
|
|
nsCycleCollector_startup()
|
2013-03-26 01:26:00 +04:00
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
MOZ_ASSERT(sCollectorData.initialized(),
|
2013-03-26 01:26:00 +04:00
|
|
|
"Forgot to call nsCycleCollector_init!");
|
2013-06-18 23:02:16 +04:00
|
|
|
if (sCollectorData.get()) {
|
2013-03-26 01:26:00 +04:00
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-11-26 03:57:53 +04:00
|
|
|
CollectorData* data = new CollectorData;
|
|
|
|
data->mCollector = new nsCycleCollector();
|
2013-08-13 21:45:32 +04:00
|
|
|
data->mRuntime = nullptr;
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-11-26 03:57:53 +04:00
|
|
|
sCollectorData.set(data);
|
2010-11-12 01:52:30 +03:00
|
|
|
}
|
|
|
|
|
2012-01-14 20:58:05 +04:00
|
|
|
void
|
|
|
|
nsCycleCollector_setBeforeUnlinkCallback(CC_BeforeUnlinkCallback aCB)
|
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
data->mCollector->SetBeforeUnlinkCallback(aCB);
|
2012-01-14 20:58:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCycleCollector_setForgetSkippableCallback(CC_ForgetSkippableCallback aCB)
|
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
data->mCollector->SetForgetSkippableCallback(aCB);
|
2012-01-14 20:58:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-27 14:48:45 +04:00
|
|
|
nsCycleCollector_forgetSkippable(bool aRemoveChildlessNodes,
|
|
|
|
bool aAsyncSnowWhiteFreeing)
|
2012-01-14 20:58:05 +04:00
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
2013-03-26 01:26:00 +04:00
|
|
|
|
|
|
|
PROFILER_LABEL("CC", "nsCycleCollector_forgetSkippable");
|
|
|
|
TimeLog timeLog;
|
2013-07-27 14:48:45 +04:00
|
|
|
data->mCollector->ForgetSkippable(aRemoveChildlessNodes,
|
|
|
|
aAsyncSnowWhiteFreeing);
|
2013-03-26 01:26:00 +04:00
|
|
|
timeLog.Checkpoint("ForgetSkippable()");
|
2012-01-14 20:58:05 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 21:30:58 +04:00
|
|
|
void
|
2013-08-04 03:55:39 +04:00
|
|
|
nsCycleCollector_dispatchDeferredDeletion(bool aContinuation)
|
2013-07-09 21:30:58 +04:00
|
|
|
{
|
2013-08-04 03:55:39 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
|
|
|
|
|
|
|
if (!data || !data->mRuntime) {
|
|
|
|
return;
|
2013-07-27 14:48:45 +04:00
|
|
|
}
|
2013-08-04 03:55:39 +04:00
|
|
|
|
|
|
|
data->mRuntime->DispatchDeferredDeletion(aContinuation);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCycleCollector_doDeferredDeletion()
|
|
|
|
{
|
|
|
|
CollectorData *data = sCollectorData.get();
|
|
|
|
|
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
|
|
|
MOZ_ASSERT(data->mRuntime);
|
|
|
|
|
|
|
|
return data->mCollector->FreeSnowWhite(false);
|
2013-07-09 21:30:58 +04:00
|
|
|
}
|
|
|
|
|
2012-02-24 08:16:37 +04:00
|
|
|
void
|
2013-11-21 02:35:17 +04:00
|
|
|
nsCycleCollector_collect(nsICycleCollectorListener *aManualListener)
|
2010-11-12 01:52:30 +03:00
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
2013-03-26 01:26:00 +04:00
|
|
|
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("CC", "nsCycleCollector_collect");
|
2013-12-03 22:47:47 +04:00
|
|
|
SliceBudget unlimitedBudget;
|
|
|
|
data->mCollector->Collect(ManualCC, unlimitedBudget, aManualListener);
|
2013-11-21 02:35:17 +04:00
|
|
|
}
|
2011-01-14 13:06:09 +03:00
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
void
|
2013-12-20 01:57:55 +04:00
|
|
|
nsCycleCollector_scheduledCollect()
|
2013-11-21 02:35:17 +04:00
|
|
|
{
|
|
|
|
CollectorData *data = sCollectorData.get();
|
|
|
|
|
|
|
|
// We should have started the cycle collector by now.
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
2011-01-14 13:06:09 +03:00
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
PROFILER_LABEL("CC", "nsCycleCollector_scheduledCollect");
|
2013-12-20 01:57:55 +04:00
|
|
|
SliceBudget unlimitedBudget;
|
|
|
|
data->mCollector->Collect(ScheduledCC, unlimitedBudget, nullptr);
|
2010-11-12 01:52:30 +03:00
|
|
|
}
|
|
|
|
|
2013-12-06 22:17:20 +04:00
|
|
|
void
|
|
|
|
nsCycleCollector_prepareForGarbageCollection()
|
|
|
|
{
|
|
|
|
CollectorData *data = sCollectorData.get();
|
|
|
|
|
|
|
|
MOZ_ASSERT(data);
|
|
|
|
|
|
|
|
if (!data->mCollector) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->mCollector->PrepareForGarbageCollection();
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:52:30 +03:00
|
|
|
void
|
|
|
|
nsCycleCollector_shutdown()
|
|
|
|
{
|
2013-06-18 23:02:16 +04:00
|
|
|
CollectorData *data = sCollectorData.get();
|
2010-11-12 01:52:30 +03:00
|
|
|
|
2013-06-18 23:02:16 +04:00
|
|
|
if (data) {
|
|
|
|
MOZ_ASSERT(data->mCollector);
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("CC", "nsCycleCollector_shutdown");
|
2013-06-18 23:02:16 +04:00
|
|
|
data->mCollector->Shutdown();
|
|
|
|
data->mCollector = nullptr;
|
|
|
|
if (!data->mRuntime) {
|
|
|
|
delete data;
|
|
|
|
sCollectorData.set(nullptr);
|
|
|
|
}
|
2010-11-12 01:52:30 +03:00
|
|
|
}
|
|
|
|
}
|