1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef nsCycleCollector_h__ 8 #define nsCycleCollector_h__ 9 10 class nsICycleCollectorListener; 11 class nsICycleCollectorLogSink; 12 class nsISupports; 13 template <class T> 14 struct already_AddRefed; 15 16 #include <cstdint> 17 #include "mozilla/Attributes.h" 18 19 namespace js { 20 class SliceBudget; 21 } 22 23 namespace mozilla { 24 class CycleCollectedJSContext; 25 } // namespace mozilla 26 27 bool nsCycleCollector_init(); 28 29 void nsCycleCollector_startup(); 30 31 typedef void (*CC_BeforeUnlinkCallback)(void); 32 void nsCycleCollector_setBeforeUnlinkCallback(CC_BeforeUnlinkCallback aCB); 33 34 typedef void (*CC_ForgetSkippableCallback)(void); 35 void nsCycleCollector_setForgetSkippableCallback( 36 CC_ForgetSkippableCallback aCB); 37 38 void nsCycleCollector_forgetSkippable(js::SliceBudget& aBudget, 39 bool aRemoveChildlessNodes = false, 40 bool aAsyncSnowWhiteFreeing = false); 41 42 void nsCycleCollector_prepareForGarbageCollection(); 43 44 // If an incremental cycle collection is in progress, finish it. 45 void nsCycleCollector_finishAnyCurrentCollection(); 46 47 void nsCycleCollector_dispatchDeferredDeletion(bool aContinuation = false, 48 bool aPurge = false); 49 bool nsCycleCollector_doDeferredDeletion(); 50 bool nsCycleCollector_doDeferredDeletionWithBudget(js::SliceBudget& aBudget); 51 52 already_AddRefed<nsICycleCollectorLogSink> nsCycleCollector_createLogSink(); 53 already_AddRefed<nsICycleCollectorListener> nsCycleCollector_createLogger(); 54 55 // Run a cycle collection and return whether anything was collected. 56 bool nsCycleCollector_collect(nsICycleCollectorListener* aManualListener); 57 58 void nsCycleCollector_collectSlice(js::SliceBudget& budget, 59 bool aPreferShorterSlices = false); 60 61 uint32_t nsCycleCollector_suspectedCount(); 62 63 // If aDoCollect is true, then run the GC and CC a few times before 64 // shutting down the CC completely. 65 MOZ_CAN_RUN_SCRIPT 66 void nsCycleCollector_shutdown(bool aDoCollect = true); 67 68 // Helpers for interacting with JS 69 void nsCycleCollector_registerJSContext(mozilla::CycleCollectedJSContext* aCx); 70 void nsCycleCollector_forgetJSContext(); 71 72 #endif // nsCycleCollector_h__ 73