Commit ee5286c1 authored by Rudi Chen's avatar Rudi Chen

Add a notion of redudant visits, useful for moving collectors.

For marking collectors, the redudant visits no-op to avoid the
performance hit.
parent 0a8385c9
......@@ -318,10 +318,6 @@ GCRootHandle::~GCRootHandle() {
getRootHandles()->erase(this);
}
bool GCVisitor::isValid(void* p) {
return global_heap.getAllocationFromInteriorPointer(p) != NULL;
}
void GCVisitor::visit(void* p) {
if ((uintptr_t)p < SMALL_ARENA_START || (uintptr_t)p >= HUGE_ARENA_START + ARENA_SIZE) {
ASSERT(!p || isNonheapRoot(p), "%p", p);
......
......@@ -15,6 +15,8 @@
#ifndef PYSTON_GC_COLLECTOR_H
#define PYSTON_GC_COLLECTOR_H
#include "gc/gc.h"
namespace pyston {
class Box;
......@@ -58,6 +60,15 @@ void invalidateOrderedFinalizerList();
// assert rather than delaying of the next GC.
void startGCUnexpectedRegion();
void endGCUnexpectedRegion();
class GCVisitorNoRedundancy : public GCVisitor {
virtual ~GCVisitorNoRedundancy() {}
virtual void visitRedundant(void* p) { visit(p); }
virtual void visitRangeRedundant(void* const* start, void* const* end) { visitRange(start, end); }
virtual void visitPotentialRedundant(void* p) { visitPotential(p); }
virtual void visitPotentialRangeRedundant(void* const* start, void* const* end) { visitPotentialRange(start, end); }
};
}
}
......
......@@ -16,6 +16,8 @@
#define PYSTON_GC_GC_H
#include <deque>
#include <memory>
#include <stddef.h>
// Files outside of the gc/ folder should only import gc.h or gc_alloc.h
// which are the "public" memory management interface.
......@@ -42,11 +44,11 @@ namespace gc {
class TraceStack;
class GCVisitor {
private:
bool isValid(void* p);
TraceStack* stack;
public:
TraceStack* stack;
GCVisitor(TraceStack* stack) : stack(stack) {}
virtual ~GCVisitor() {}
// These all work on *user* pointers, ie pointers to the user_data section of GCAllocations
void visitIf(void* p) {
......@@ -57,6 +59,20 @@ public:
void visitRange(void* const* start, void* const* end);
void visitPotential(void* p);
void visitPotentialRange(void* const* start, void* const* end);
// Some object have fields with pointers to Pyston heap objects that we are confident are
// already being scanned elsewhere.
//
// In a mark-and-sweep collector, scanning those fields would be redundant because the mark
// phase only needs to visit each object once, so there would be a performance hit.
//
// In a moving collector, every reference needs to be visited since the pointer value could
// change. We don't have a moving collector yet, but it's good practice to call visit every
// pointer value and no-op to avoid the performance hit of the mark-and-sweep case.
virtual void visitRedundant(void* p) {}
virtual void visitRedundantRange(void** start, void** end) {}
virtual void visitPotentialRedundant(void* p) {}
virtual void visitPotentialRangeRedundant(void* const* start, void* const* end) {}
};
enum class GCKind : uint8_t {
......
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