2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsCycleCollector_h__
|
|
|
|
#define nsCycleCollector_h__
|
|
|
|
|
|
|
|
class nsISupports;
|
2010-08-11 17:03:23 -07:00
|
|
|
class nsICycleCollectorListener;
|
2007-05-24 07:10:02 -07:00
|
|
|
class nsCycleCollectionParticipant;
|
2007-11-01 15:51:57 -07:00
|
|
|
class nsCycleCollectionTraversalCallback;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-23 20:16:37 -08:00
|
|
|
// Contains various stats about the cycle collection.
|
|
|
|
class nsCycleCollectorResults
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsCycleCollectorResults() :
|
|
|
|
mForcedGC(false), mVisitedRefCounted(0), mVisitedGCed(0),
|
|
|
|
mFreedRefCounted(0), mFreedGCed(0) {}
|
|
|
|
bool mForcedGC;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mVisitedRefCounted;
|
|
|
|
uint32_t mVisitedGCed;
|
|
|
|
uint32_t mFreedRefCounted;
|
|
|
|
uint32_t mFreedGCed;
|
2012-02-23 20:16:37 -08:00
|
|
|
};
|
|
|
|
|
2013-03-25 14:26:00 -07:00
|
|
|
bool nsCycleCollector_init();
|
|
|
|
|
|
|
|
enum CCThreadingModel {
|
|
|
|
CCSingleThread,
|
2013-04-05 10:03:56 -07:00
|
|
|
CCWithTraverseThread
|
2013-03-25 14:26:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult nsCycleCollector_startup(CCThreadingModel aThreadingModel);
|
2012-01-14 08:58:05 -08:00
|
|
|
|
|
|
|
typedef void (*CC_BeforeUnlinkCallback)(void);
|
|
|
|
void nsCycleCollector_setBeforeUnlinkCallback(CC_BeforeUnlinkCallback aCB);
|
|
|
|
|
|
|
|
typedef void (*CC_ForgetSkippableCallback)(void);
|
|
|
|
void nsCycleCollector_setForgetSkippableCallback(CC_ForgetSkippableCallback aCB);
|
|
|
|
|
2012-03-05 13:48:04 -08:00
|
|
|
void nsCycleCollector_forgetSkippable(bool aRemoveChildlessNodes = false);
|
2012-01-14 08:58:05 -08:00
|
|
|
|
2012-06-27 08:09:56 -07:00
|
|
|
void nsCycleCollector_collect(bool aMergeCompartments,
|
|
|
|
nsCycleCollectorResults *aResults,
|
2012-02-23 20:16:37 -08:00
|
|
|
nsICycleCollectorListener *aListener);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t nsCycleCollector_suspectedCount();
|
2010-11-11 14:52:30 -08:00
|
|
|
void nsCycleCollector_shutdownThreads();
|
2007-03-27 02:49:06 -07:00
|
|
|
void nsCycleCollector_shutdown();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-03 12:28:11 -07:00
|
|
|
// Various methods the cycle collector needs to deal with Javascript.
|
|
|
|
struct nsCycleCollectionJSRuntime
|
2007-11-01 15:51:57 -07:00
|
|
|
{
|
2012-05-03 12:28:11 -07:00
|
|
|
virtual nsresult BeginCycleCollection(nsCycleCollectionTraversalCallback &cb) = 0;
|
|
|
|
|
2011-07-01 14:11:31 -07:00
|
|
|
/**
|
|
|
|
* Called before/after transitioning to/from the main thread.
|
2011-07-18 14:54:48 -07:00
|
|
|
*
|
|
|
|
* NotifyLeaveMainThread may return 'false' to prevent the cycle collector
|
|
|
|
* from leaving the main thread.
|
2011-07-01 14:11:31 -07:00
|
|
|
*/
|
2011-07-18 14:54:48 -07:00
|
|
|
virtual bool NotifyLeaveMainThread() = 0;
|
2011-07-01 14:11:31 -07:00
|
|
|
virtual void NotifyEnterCycleCollectionThread() = 0;
|
|
|
|
virtual void NotifyLeaveCycleCollectionThread() = 0;
|
|
|
|
virtual void NotifyEnterMainThread() = 0;
|
|
|
|
|
2013-01-08 10:36:51 -08:00
|
|
|
/**
|
|
|
|
* Unmark gray any weak map values, as needed.
|
|
|
|
*/
|
|
|
|
virtual void FixWeakMappingGrayBits() = 0;
|
|
|
|
|
2011-06-03 13:08:21 -07:00
|
|
|
/**
|
|
|
|
* Should we force a JavaScript GC before a CC?
|
|
|
|
*/
|
|
|
|
virtual bool NeedCollect() = 0;
|
|
|
|
|
2007-11-01 15:51:57 -07:00
|
|
|
/**
|
2012-01-25 10:59:55 -08:00
|
|
|
* Runs the JavaScript GC. |reason| is a gcreason::Reason from jsfriendapi.h.
|
2007-11-01 15:51:57 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual void Collect(uint32_t reason) = 0;
|
2012-05-03 12:28:10 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the JS cycle collection participant.
|
|
|
|
*/
|
|
|
|
virtual nsCycleCollectionParticipant *GetParticipant() = 0;
|
2012-11-27 16:56:06 -08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
virtual void SetObjectToUnlink(void* aObject) = 0;
|
|
|
|
virtual void AssertNoObjectsToTrace(void* aPossibleJSHolder) = 0;
|
|
|
|
#endif
|
2007-11-01 15:51:57 -07:00
|
|
|
};
|
|
|
|
|
2012-05-03 12:28:11 -07:00
|
|
|
// Helpers for interacting with JS
|
|
|
|
void nsCycleCollector_registerJSRuntime(nsCycleCollectionJSRuntime *rt);
|
|
|
|
void nsCycleCollector_forgetJSRuntime();
|
|
|
|
|
2010-08-11 17:03:23 -07:00
|
|
|
#define NS_CYCLE_COLLECTOR_LOGGER_CID \
|
|
|
|
{ 0x58be81b4, 0x39d2, 0x437c, \
|
|
|
|
{ 0x94, 0xea, 0xae, 0xde, 0x2c, 0x62, 0x08, 0xd3 } }
|
|
|
|
|
|
|
|
extern nsresult
|
|
|
|
nsCycleCollectorLoggerConstructor(nsISupports* outer,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void* *aInstancePtr);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // nsCycleCollector_h__
|