Commit 624bb03b authored by Rudi Chen's avatar Rudi Chen

Cleanup: move static variables to the top of the file.

parent 44b261bf
......@@ -39,6 +39,26 @@ namespace gc {
FILE* trace_fp;
#endif
static std::unordered_set<void*> roots;
static std::vector<std::pair<void*, void*>> potential_root_ranges;
static std::unordered_set<void*> 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<GCRootHandle*>* getRootHandles() {
static std::unordered_set<GCRootHandle*> 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;
......@@ -120,8 +140,6 @@ public:
};
std::vector<void**> TraceStack::free_chunks;
static std::unordered_set<void*> roots;
void registerPermanentRoot(void* obj, bool allow_duplicates) {
assert(global_heap.getAllocationFromInteriorPointer(obj));
......@@ -138,7 +156,6 @@ void deregisterPermanentRoot(void* obj) {
roots.erase(obj);
}
static std::vector<std::pair<void*, void*>> potential_root_ranges;
void registerPotentialRootRange(void* start, void* end) {
potential_root_ranges.push_back(std::make_pair(start, end));
}
......@@ -152,12 +169,6 @@ extern "C" PyObject* PyGC_AddRoot(PyObject* obj) noexcept {
return obj;
}
static std::unordered_set<void*> 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);
......@@ -200,11 +211,6 @@ void setIsPythonObject(Box* b) {
}
}
static std::unordered_set<GCRootHandle*>* getRootHandles() {
static std::unordered_set<GCRootHandle*> root_handles;
return &root_handles;
}
GCRootHandle::GCRootHandle() {
getRootHandles()->insert(this);
}
......@@ -212,8 +218,6 @@ GCRootHandle::~GCRootHandle() {
getRootHandles()->erase(this);
}
bool GCVisitor::isValid(void* p) {
return global_heap.getAllocationFromInteriorPointer(p) != NULL;
}
......@@ -272,8 +276,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);
......@@ -402,19 +404,18 @@ static void sweepPhase(std::vector<Box*>& 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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment