Commit a9176ef7 authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Simple 'why is this object alive' helpers

Based on what Rudi says he was doing (sorry rudi)
parent 6a6dc30e
......@@ -35,6 +35,8 @@
//#undef VERBOSITY
//#define VERBOSITY(x) 2
#define DEBUG_MARK_PHASE 0
#ifndef NDEBUG
#define DEBUG 1
#else
......@@ -44,6 +46,13 @@
namespace pyston {
namespace gc {
#if DEBUG_MARK_PHASE
FILE* trace_fp;
#define TRACE_LOG(...) fprintf(trace_fp, __VA_ARGS__)
#else
#define TRACE_LOG(...)
#endif
class TraceStack {
private:
const int CHUNK_SIZE = 256;
......@@ -91,6 +100,7 @@ public:
}
void push(void* p) {
TRACE_LOG("Pushing %p\n", p);
GCAllocation* al = GCAllocation::fromUserData(p);
if (isMarked(al))
return;
......@@ -273,21 +283,31 @@ void markPhase() {
VALGRIND_DISABLE_ERROR_REPORTING;
#endif
#if DEBUG_MARK_PHASE
trace_fp = fopen("gc_trace.txt", "w");
#endif
TRACE_LOG("Starting collection\n");
TRACE_LOG("Looking at roots\n");
TraceStack stack(roots);
GCVisitor visitor(&stack);
TRACE_LOG("Looking at the stack\n");
threading::visitAllStacks(&visitor);
TRACE_LOG("Looking at root handles\n");
for (auto h : *getRootHandles()) {
visitor.visit(h->value);
}
TRACE_LOG("Looking at potential root ranges\n");
for (auto& e : potential_root_ranges) {
visitor.visitPotentialRange((void* const*)e.first, (void* const*)e.second);
}
// if (VERBOSITY()) printf("Found %d roots\n", stack.size());
while (void* p = stack.pop()) {
TRACE_LOG("Looking at heap object %p\n", p);
assert(((intptr_t)p) % 8 == 0);
GCAllocation* al = GCAllocation::fromUserData(p);
......@@ -336,6 +356,11 @@ void markPhase() {
}
}
#if DEBUG_MARK_PHASE
fclose(trace_fp);
trace_fp = NULL;
#endif
#ifndef NVALGRIND
VALGRIND_ENABLE_ERROR_REPORTING;
#endif
......
import os
import sys
if __name__ == "__main__":
look_at = sys.argv[1]
why = {}
cur = None
for l in open("gc_trace.txt"):
if l.startswith("Pushing "):
ptr = l.split()[1]
why.setdefault(ptr, []).append(cur)
else:
cur = l
def investigate(ptr):
l = why.get(ptr)
if not l:
print "Not sure why %s is alive!" % ptr
else:
print ptr, "is alive from '%s'" % l[0].strip(),
if len(l) > 1:
print "and %d more entries" % (len(l) - 1)
else:
print
if l[0].startswith("Looking at heap object"):
prev_ptr = l[0].split()[-1]
investigate(prev_ptr)
investigate(look_at)
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