1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * The Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsCycleCollector_h__
39 #define nsCycleCollector_h__
41 // NOTE: If you use header files to define DEBUG_CC, you must do so here
42 // *and* in nsCycleCollectionParticipant.h
46 class nsCycleCollectionParticipant
;
47 class nsCycleCollectionTraversalCallback
;
49 // An nsCycleCollectionLanguageRuntime is a per-language object that
50 // implements language-specific aspects of the cycle collection task.
52 struct nsCycleCollectionLanguageRuntime
54 virtual nsresult
BeginCycleCollection(nsCycleCollectionTraversalCallback
&cb
) = 0;
55 virtual nsresult
FinishCycleCollection() = 0;
56 virtual nsCycleCollectionParticipant
*ToParticipant(void *p
) = 0;
58 virtual void PrintAllReferencesTo(void *p
) = 0;
62 nsresult
nsCycleCollector_startup();
63 // Returns the number of collected nodes.
64 NS_COM PRUint32
nsCycleCollector_collect();
65 NS_COM PRUint32
nsCycleCollector_suspectedCount();
66 void nsCycleCollector_shutdown();
68 // The JS runtime is special, it needs to call cycle collection during its GC.
69 // If the JS runtime is registered nsCycleCollector_collect will call
70 // nsCycleCollectionJSRuntime::Collect which will call
71 // nsCycleCollector_doCollect, else nsCycleCollector_collect will call
72 // nsCycleCollector_doCollect directly.
73 struct nsCycleCollectionJSRuntime
: public nsCycleCollectionLanguageRuntime
76 * Runs cycle collection and returns whether cycle collection collected
79 virtual PRBool
Collect() = 0;
81 // Returns PR_TRUE if cycle collection was started.
82 NS_COM PRBool
nsCycleCollector_beginCollection();
83 // Returns PR_TRUE if some nodes were collected. Should only be called after
84 // nsCycleCollector_beginCollection() returned PR_TRUE.
85 NS_COM PRBool
nsCycleCollector_finishCollection();
88 NS_COM
void nsCycleCollector_DEBUG_shouldBeFreed(nsISupports
*n
);
89 NS_COM
void nsCycleCollector_DEBUG_wasFreed(nsISupports
*n
);
92 // Helpers for interacting with language-identified scripts
94 NS_COM
void nsCycleCollector_registerRuntime(PRUint32 langID
, nsCycleCollectionLanguageRuntime
*rt
);
95 NS_COM
void nsCycleCollector_forgetRuntime(PRUint32 langID
);
97 #endif // nsCycleCollector_h__