Commit 3d9bca6b authored by Kevin Modzelewski's avatar Kevin Modzelewski

Make the GCVisitor non-virtual for a small speedup

parent 873de691
...@@ -21,15 +21,18 @@ class Function; ...@@ -21,15 +21,18 @@ class Function;
namespace pyston { namespace pyston {
namespace gc {
class GCVisitor;
}
class Box; class Box;
class BoxedDict; class BoxedDict;
class GCVisitor;
class LineInfo; class LineInfo;
Box* interpretFunction(llvm::Function* f, int nargs, Box* closure, Box* generator, Box* arg1, Box* arg2, Box* arg3, Box* interpretFunction(llvm::Function* f, int nargs, Box* closure, Box* generator, Box* arg1, Box* arg2, Box* arg3,
Box** args); Box** args);
void gatherInterpreterRoots(GCVisitor* visitor); void gatherInterpreterRoots(gc::GCVisitor* visitor);
const LineInfo* getLineInfoForInterpretedFrame(void* frame_ptr); const LineInfo* getLineInfoForInterpretedFrame(void* frame_ptr);
BoxedDict* localsForInterpretedFrame(void* frame_ptr, bool only_user_visible); BoxedDict* localsForInterpretedFrame(void* frame_ptr, bool only_user_visible);
} }
......
...@@ -72,16 +72,26 @@ struct ArgPassSpec { ...@@ -72,16 +72,26 @@ struct ArgPassSpec {
}; };
static_assert(sizeof(ArgPassSpec) <= sizeof(void*), "ArgPassSpec doesn't fit in register!"); static_assert(sizeof(ArgPassSpec) <= sizeof(void*), "ArgPassSpec doesn't fit in register!");
namespace gc {
class TraceStack;
class GCVisitor { class GCVisitor {
private:
bool isValid(void* p);
public: public:
virtual ~GCVisitor() {} TraceStack* stack;
virtual void visit(void* p) = 0; GCVisitor(TraceStack* stack) : stack(stack) {}
virtual void visitRange(void* const* start, void* const* end) = 0;
virtual void visitPotential(void* p) = 0; // These all work on *user* pointers, ie pointers to the user_data section of GCAllocations
virtual void visitPotentialRange(void* const* start, void* const* end) = 0; void visit(void* p);
void visitRange(void* const* start, void* const* end);
void visitPotential(void* p);
void visitPotentialRange(void* const* start, void* const* end);
}; };
} // namespace gc
using gc::GCVisitor;
namespace EffortLevel { namespace EffortLevel {
enum EffortLevel { enum EffortLevel {
......
...@@ -86,11 +86,11 @@ GCRootHandle::~GCRootHandle() { ...@@ -86,11 +86,11 @@ GCRootHandle::~GCRootHandle() {
bool TraceStackGCVisitor::isValid(void* p) { bool GCVisitor::isValid(void* p) {
return global_heap.getAllocationFromInteriorPointer(p) != NULL; return global_heap.getAllocationFromInteriorPointer(p) != NULL;
} }
void TraceStackGCVisitor::visit(void* p) { void GCVisitor::visit(void* p) {
if (isNonheapRoot(p)) { if (isNonheapRoot(p)) {
return; return;
} else { } else {
...@@ -99,21 +99,21 @@ void TraceStackGCVisitor::visit(void* p) { ...@@ -99,21 +99,21 @@ void TraceStackGCVisitor::visit(void* p) {
} }
} }
void TraceStackGCVisitor::visitRange(void* const* start, void* const* end) { void GCVisitor::visitRange(void* const* start, void* const* end) {
while (start < end) { while (start < end) {
visit(*start); visit(*start);
start++; start++;
} }
} }
void TraceStackGCVisitor::visitPotential(void* p) { void GCVisitor::visitPotential(void* p) {
GCAllocation* a = global_heap.getAllocationFromInteriorPointer(p); GCAllocation* a = global_heap.getAllocationFromInteriorPointer(p);
if (a) { if (a) {
visit(a->user_data); visit(a->user_data);
} }
} }
void TraceStackGCVisitor::visitPotentialRange(void* const* start, void* const* end) { void GCVisitor::visitPotentialRange(void* const* start, void* const* end) {
while (start < end) { while (start < end) {
visitPotential(*start); visitPotential(*start);
start++; start++;
...@@ -130,7 +130,7 @@ static void markPhase() { ...@@ -130,7 +130,7 @@ static void markPhase() {
TraceStack stack(roots); TraceStack stack(roots);
collectStackRoots(&stack); collectStackRoots(&stack);
TraceStackGCVisitor visitor(&stack); GCVisitor visitor(&stack);
for (void* p : nonheap_roots) { for (void* p : nonheap_roots) {
Box* b = reinterpret_cast<Box*>(p); Box* b = reinterpret_cast<Box*>(p);
......
...@@ -45,21 +45,6 @@ public: ...@@ -45,21 +45,6 @@ public:
} }
}; };
class TraceStackGCVisitor : public GCVisitor {
private:
bool isValid(void* p);
public:
TraceStack* stack;
TraceStackGCVisitor(TraceStack* stack) : stack(stack) {}
// These all work on *user* pointers, ie pointers to the user_data section of GCAllocations
void visit(void* p) override;
void visitRange(void* const* start, void* const* end) override;
void visitPotential(void* p) override;
void visitPotentialRange(void* const* start, void* const* end) override;
};
// 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)
......
...@@ -42,7 +42,7 @@ void collectRoots(void* start, void* end, TraceStack* stack) { ...@@ -42,7 +42,7 @@ void collectRoots(void* start, void* end, TraceStack* stack) {
ASSERT((char*)end - (char*)start <= 1000000000, "Asked to scan %.1fGB -- a bug?", ASSERT((char*)end - (char*)start <= 1000000000, "Asked to scan %.1fGB -- a bug?",
((char*)end - (char*)start) * 1.0 / (1 << 30)); ((char*)end - (char*)start) * 1.0 / (1 << 30));
TraceStackGCVisitor(stack).visitPotentialRange((void**)start, (void**)end); GCVisitor(stack).visitPotentialRange((void**)start, (void**)end);
} }
...@@ -81,7 +81,7 @@ void collectStackRoots(TraceStack* stack) { ...@@ -81,7 +81,7 @@ void collectStackRoots(TraceStack* stack) {
collectLocalStack(stack); collectLocalStack(stack);
collectOtherThreadsStacks(stack); collectOtherThreadsStacks(stack);
TraceStackGCVisitor visitor(stack); GCVisitor visitor(stack);
gatherInterpreterRoots(&visitor); gatherInterpreterRoots(&visitor);
} }
} }
......
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