diff --git a/src/gc/collector.cpp b/src/gc/collector.cpp index ba65ad990..8f2035f22 100644 --- a/src/gc/collector.cpp +++ b/src/gc/collector.cpp @@ -48,6 +48,26 @@ namespace gc { FILE* trace_fp; #endif +static std::unordered_set roots; +static std::vector> potential_root_ranges; + +static std::unordered_set nonheap_roots; +// Track the highest-addressed nonheap root; the assumption is that the nonheap roots will +// typically all have lower addresses than the heap roots, so this can serve as a cheap +// way to verify it's not a nonheap root (the full check requires a hashtable lookup). +static void* max_nonheap_root = 0; +static void* min_nonheap_root = (void*)~0; + +static std::unordered_set* getRootHandles() { + static std::unordered_set root_handles; + return &root_handles; +} + +static int ncollections = 0; + +static bool gc_enabled = true; +static bool should_not_reenter_gc = false; + class TraceStack { private: const int CHUNK_SIZE = 256; @@ -129,8 +149,6 @@ class TraceStack { }; std::vector TraceStack::free_chunks; - -static std::unordered_set roots; void registerPermanentRoot(void* obj, bool allow_duplicates) { assert(global_heap.getAllocationFromInteriorPointer(obj)); @@ -147,7 +165,6 @@ void deregisterPermanentRoot(void* obj) { roots.erase(obj); } -static std::vector> potential_root_ranges; void registerPotentialRootRange(void* start, void* end) { potential_root_ranges.push_back(std::make_pair(start, end)); } @@ -161,12 +178,6 @@ extern "C" PyObject* PyGC_AddRoot(PyObject* obj) noexcept { return obj; } -static std::unordered_set nonheap_roots; -// Track the highest-addressed nonheap root; the assumption is that the nonheap roots will -// typically all have lower addresses than the heap roots, so this can serve as a cheap -// way to verify it's not a nonheap root (the full check requires a hashtable lookup). -static void* max_nonheap_root = 0; -static void* min_nonheap_root = (void*)~0; void registerNonheapRootObject(void* obj, int size) { // I suppose that things could work fine even if this were true, but why would it happen? assert(global_heap.getAllocationFromInteriorPointer(obj) == NULL); @@ -209,11 +220,6 @@ void setIsPythonObject(Box* b) { } } -static std::unordered_set* getRootHandles() { - static std::unordered_set root_handles; - return &root_handles; -} - GCRootHandle::GCRootHandle() { getRootHandles()->insert(this); } @@ -221,8 +227,6 @@ GCRootHandle::~GCRootHandle() { getRootHandles()->erase(this); } - - bool GCVisitor::isValid(void* p) { return global_heap.getAllocationFromInteriorPointer(p) != NULL; } @@ -283,8 +287,6 @@ void GCVisitor::visitPotentialRange(void* const* start, void* const* end) { } } -static int ncollections = 0; - static inline void visitByGCKind(void* p, GCVisitor& visitor) { assert(((intptr_t)p) % 8 == 0); @@ -419,19 +421,18 @@ static void sweepPhase(std::vector& weakly_referenced) { sc_us.log(us); } -static bool gc_enabled = true; bool gcIsEnabled() { return gc_enabled; } + void enableGC() { gc_enabled = true; } + void disableGC() { gc_enabled = false; } -static bool should_not_reenter_gc = false; - void startGCUnexpectedRegion() { RELEASE_ASSERT(!should_not_reenter_gc, ""); should_not_reenter_gc = true;