Commit a9e0e5eb authored by Chris Toshok's avatar Chris Toshok

add a PRECISE and HIDDEN_CLASS GCKind, with special visit behavior (visitRange...

add a PRECISE and HIDDEN_CLASS GCKind, with special visit behavior (visitRange for PRECISE, and HiddenClass::gc_visit for HIDDEN_CLASS).  don't scan HiddenClasses or HCAttrs conservatively.
parent 6982eabf
......@@ -349,17 +349,17 @@ namespace gc {
enum class GCKind : uint8_t {
PYTHON = 1,
CONSERVATIVE = 2,
UNTRACKED = 3,
PRECISE = 3,
UNTRACKED = 4,
HIDDEN_CLASS = 5,
};
extern "C" void* gc_alloc(size_t nbytes, GCKind kind);
}
class ConservativeGCObject {
template <gc::GCKind gc_kind> class GCAllocated {
public:
void* operator new(size_t size) __attribute__((visibility("default"))) {
return gc_alloc(size, gc::GCKind::CONSERVATIVE);
}
void* operator new(size_t size) __attribute__((visibility("default"))) { return gc_alloc(size, gc_kind); }
void operator delete(void* ptr) __attribute__((visibility("default"))) { abort(); }
};
......@@ -372,7 +372,7 @@ struct DelattrRewriteArgs;
struct HCAttrs {
public:
struct AttrList : ConservativeGCObject {
struct AttrList : public GCAllocated<gc::GCKind::PRECISE> {
Box* attrs[0];
};
......
......@@ -256,6 +256,9 @@ static void markPhase() {
} else if (kind_id == GCKind::CONSERVATIVE) {
uint32_t bytes = al->kind_data;
visitor.visitPotentialRange((void**)p, (void**)((char*)p + bytes));
} else if (kind_id == GCKind::PRECISE) {
uint32_t bytes = al->kind_data;
visitor.visitRange((void**)p, (void**)((char*)p + bytes));
} else if (kind_id == GCKind::PYTHON) {
Box* b = reinterpret_cast<Box*>(p);
BoxedClass* cls = b->cls;
......@@ -268,6 +271,9 @@ static void markPhase() {
ASSERT(cls->gc_visit, "%s", getTypeName(b)->c_str());
cls->gc_visit(&visitor, b);
}
} else if (kind_id == GCKind::HIDDEN_CLASS) {
HiddenClass* hcls = reinterpret_cast<HiddenClass*>(p);
hcls->gc_visit(&visitor);
} else {
RELEASE_ASSERT(0, "Unhandled kind: %d", (int)kind_id);
}
......
......@@ -255,7 +255,7 @@ static_assert(offsetof(pyston::BoxedHeapClass, as_buffer) == offsetof(PyHeapType
static_assert(sizeof(pyston::BoxedHeapClass) == sizeof(PyHeapTypeObject), "");
class HiddenClass : public ConservativeGCObject {
class HiddenClass : public GCAllocated<gc::GCKind::HIDDEN_CLASS> {
private:
HiddenClass() {}
HiddenClass(const HiddenClass* parent) : attr_offsets(parent->attr_offsets) {}
......@@ -270,8 +270,8 @@ public:
return new HiddenClass();
}
conservative_unordered_map<std::string, int> attr_offsets;
conservative_unordered_map<std::string, HiddenClass*> children;
std::unordered_map<std::string, int> attr_offsets;
std::unordered_map<std::string, HiddenClass*> children;
HiddenClass* getOrMakeChild(const std::string& attr);
......@@ -282,6 +282,12 @@ public:
return it->second;
}
HiddenClass* delAttrToMakeHC(const std::string& attr);
void gc_visit(GCVisitor* visitor) {
for (const auto& p : children) {
visitor->visit(p.second);
}
}
};
class BoxedInt : public Box {
......
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