Commit 7529462c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Make the TRACE_LOG helpers available to other files

and rename them to make it more clear that it's GC-related.
parent 085c18b9
...@@ -167,8 +167,10 @@ static void pushThreadState(ThreadStateInternal* thread_state, ucontext_t* conte ...@@ -167,8 +167,10 @@ static void pushThreadState(ThreadStateInternal* thread_state, ucontext_t* conte
#endif #endif
assert(stack_low < stack_high); assert(stack_low < stack_high);
GC_TRACE_LOG("Visiting other thread's stack\n");
cur_visitor->visitPotentialRange((void**)stack_low, (void**)stack_high); cur_visitor->visitPotentialRange((void**)stack_low, (void**)stack_high);
GC_TRACE_LOG("Visiting other thread's threadstate + generator stacks\n");
thread_state->accept(cur_visitor); thread_state->accept(cur_visitor);
} }
...@@ -195,8 +197,12 @@ static void visitLocalStack(gc::GCVisitor* v) { ...@@ -195,8 +197,12 @@ static void visitLocalStack(gc::GCVisitor* v) {
#endif #endif
assert(stack_low < stack_high); assert(stack_low < stack_high);
GC_TRACE_LOG("Visiting current stack from %p to %p\n", stack_low, stack_high);
v->visitPotentialRange((void**)stack_low, (void**)stack_high); v->visitPotentialRange((void**)stack_low, (void**)stack_high);
GC_TRACE_LOG("Visiting current thread's threadstate + generator stacks\n");
current_internal_thread_state->accept(v); current_internal_thread_state->accept(v);
} }
......
...@@ -35,8 +35,6 @@ ...@@ -35,8 +35,6 @@
//#undef VERBOSITY //#undef VERBOSITY
//#define VERBOSITY(x) 2 //#define VERBOSITY(x) 2
#define DEBUG_MARK_PHASE 0
#ifndef NDEBUG #ifndef NDEBUG
#define DEBUG 1 #define DEBUG 1
#else #else
...@@ -46,11 +44,8 @@ ...@@ -46,11 +44,8 @@
namespace pyston { namespace pyston {
namespace gc { namespace gc {
#if DEBUG_MARK_PHASE #if TRACE_GC_MARKING
FILE* trace_fp; FILE* trace_fp;
#define TRACE_LOG(...) fprintf(trace_fp, __VA_ARGS__)
#else
#define TRACE_LOG(...)
#endif #endif
class TraceStack { class TraceStack {
...@@ -100,7 +95,7 @@ public: ...@@ -100,7 +95,7 @@ public:
} }
void push(void* p) { void push(void* p) {
TRACE_LOG("Pushing %p\n", p); GC_TRACE_LOG("Pushing %p\n", p);
GCAllocation* al = GCAllocation::fromUserData(p); GCAllocation* al = GCAllocation::fromUserData(p);
if (isMarked(al)) if (isMarked(al))
return; return;
...@@ -271,11 +266,19 @@ void GCVisitor::visitPotentialRange(void* const* start, void* const* end) { ...@@ -271,11 +266,19 @@ void GCVisitor::visitPotentialRange(void* const* start, void* const* end) {
assert((uintptr_t)end % sizeof(void*) == 0); assert((uintptr_t)end % sizeof(void*) == 0);
while (start < end) { while (start < end) {
#if TRACE_GC_MARKING
if (global_heap.getAllocationFromInteriorPointer(*start)) {
GC_TRACE_LOG("Found conservative reference to %p from %p\n", *start, start);
}
#endif
visitPotential(*start); visitPotential(*start);
start++; start++;
} }
} }
static int ncollections = 0;
void markPhase() { void markPhase() {
#ifndef NVALGRIND #ifndef NVALGRIND
// Have valgrind close its eyes while we do the conservative stack and data scanning, // Have valgrind close its eyes while we do the conservative stack and data scanning,
...@@ -283,31 +286,37 @@ void markPhase() { ...@@ -283,31 +286,37 @@ void markPhase() {
VALGRIND_DISABLE_ERROR_REPORTING; VALGRIND_DISABLE_ERROR_REPORTING;
#endif #endif
#if DEBUG_MARK_PHASE #if TRACE_GC_MARKING
#if 1 // separate log file per collection
char tracefn_buf[80];
snprintf(tracefn_buf, sizeof(tracefn_buf), "gc_trace_%03d.txt", ncollections);
trace_fp = fopen(tracefn_buf, "w");
#else // overwrite previous log file with each collection
trace_fp = fopen("gc_trace.txt", "w"); trace_fp = fopen("gc_trace.txt", "w");
#endif #endif
TRACE_LOG("Starting collection\n"); #endif
GC_TRACE_LOG("Starting collection %d\n", ncollections);
TRACE_LOG("Looking at roots\n"); GC_TRACE_LOG("Looking at roots\n");
TraceStack stack(roots); TraceStack stack(roots);
GCVisitor visitor(&stack); GCVisitor visitor(&stack);
TRACE_LOG("Looking at the stack\n"); GC_TRACE_LOG("Looking at the stack\n");
threading::visitAllStacks(&visitor); threading::visitAllStacks(&visitor);
TRACE_LOG("Looking at root handles\n"); GC_TRACE_LOG("Looking at root handles\n");
for (auto h : *getRootHandles()) { for (auto h : *getRootHandles()) {
visitor.visit(h->value); visitor.visit(h->value);
} }
TRACE_LOG("Looking at potential root ranges\n"); GC_TRACE_LOG("Looking at potential root ranges\n");
for (auto& e : potential_root_ranges) { for (auto& e : potential_root_ranges) {
visitor.visitPotentialRange((void* const*)e.first, (void* const*)e.second); visitor.visitPotentialRange((void* const*)e.first, (void* const*)e.second);
} }
// if (VERBOSITY()) printf("Found %d roots\n", stack.size()); // if (VERBOSITY()) printf("Found %d roots\n", stack.size());
while (void* p = stack.pop()) { while (void* p = stack.pop()) {
TRACE_LOG("Looking at heap object %p\n", p); GC_TRACE_LOG("Looking at heap object %p\n", p);
assert(((intptr_t)p) % 8 == 0); assert(((intptr_t)p) % 8 == 0);
GCAllocation* al = GCAllocation::fromUserData(p); GCAllocation* al = GCAllocation::fromUserData(p);
...@@ -356,7 +365,7 @@ void markPhase() { ...@@ -356,7 +365,7 @@ void markPhase() {
} }
} }
#if DEBUG_MARK_PHASE #if TRACE_GC_MARKING
fclose(trace_fp); fclose(trace_fp);
trace_fp = NULL; trace_fp = NULL;
#endif #endif
...@@ -383,7 +392,6 @@ void disableGC() { ...@@ -383,7 +392,6 @@ void disableGC() {
gc_enabled = false; gc_enabled = false;
} }
static int ncollections = 0;
static bool should_not_reenter_gc = false; static bool should_not_reenter_gc = false;
void startGCUnexpectedRegion() { void startGCUnexpectedRegion() {
......
...@@ -22,6 +22,14 @@ ...@@ -22,6 +22,14 @@
namespace pyston { namespace pyston {
namespace gc { namespace gc {
#define TRACE_GC_MARKING 0
#if TRACE_GC_MARKING
extern FILE* trace_fp;
#define GC_TRACE_LOG(...) fprintf(pyston::gc::trace_fp, __VA_ARGS__)
#else
#define GC_TRACE_LOG(...)
#endif
// Mark this gc-allocated object as being a root, even if there are no visible references to it. // Mark this gc-allocated object as being a root, even if there are no visible references to it.
// (Note: this marks the gc allocation itself, not the pointer that points to one. For that, use // (Note: this marks the gc allocation itself, not the pointer that points to one. For that, use
// a GCRootHandle) // a GCRootHandle)
......
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