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