Skip to content

Commit

Permalink
Cleanup: move static variables to the top of the file.
Browse files Browse the repository at this point in the history
  • Loading branch information
rudi-c committed Jul 2, 2015
1 parent 75a5d98 commit b6579c0
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/gc/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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;
Expand Down Expand Up @@ -129,8 +149,6 @@ class TraceStack {
};
std::vector<void**> TraceStack::free_chunks;


static std::unordered_set<void*> roots;
void registerPermanentRoot(void* obj, bool allow_duplicates) {
assert(global_heap.getAllocationFromInteriorPointer(obj));

Expand All @@ -147,7 +165,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));
}
Expand All @@ -161,12 +178,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);
Expand Down Expand Up @@ -209,20 +220,13 @@ 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);
}
GCRootHandle::~GCRootHandle() {
getRootHandles()->erase(this);
}



bool GCVisitor::isValid(void* p) {
return global_heap.getAllocationFromInteriorPointer(p) != NULL;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -419,19 +421,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;
Expand Down

0 comments on commit b6579c0

Please sign in to comment.