Commit 56f07b13 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Set the mark-bit when pushing onto the stack, instead of when popping off

Good for a 10-15% speedup

I still feel like we can do much better here though
parent b7837499
......@@ -42,15 +42,22 @@ private:
public:
TraceStack() {}
TraceStack(const TraceStack& rhs) {
for (void* p : rhs.v) {
TraceStack(const std::vector<void*>& rhs) {
for (void* p : rhs) {
assert(!isMarked(GCAllocation::fromUserData(p)));
push(p);
}
}
void push(void* p) {
GCAllocation* al = GCAllocation::fromUserData(p);
if (!isMarked(al)) {
setMark(al);
v.push_back(p);
}
}
int size() { return v.size(); }
......@@ -66,10 +73,10 @@ public:
}
};
static TraceStack roots;
static std::vector<void*> roots;
void registerPermanentRoot(void* obj) {
assert(global_heap.getAllocationFromInteriorPointer(obj));
roots.push(obj);
roots.push_back(obj);
#ifndef NDEBUG
// Check for double-registers. Wouldn't cause any problems, but we probably shouldn't be doing them.
......@@ -181,14 +188,10 @@ static void markPhase() {
assert(((intptr_t)p) % 8 == 0);
GCAllocation* al = GCAllocation::fromUserData(p);
if (isMarked(al)) {
continue;
}
assert(isMarked(al));
// printf("Marking + scanning %p\n", p);
setMark(al);
GCKind kind_id = al->kind_id;
if (kind_id == GCKind::UNTRACKED) {
continue;
......
......@@ -43,18 +43,20 @@ static_assert(sizeof(GCAllocation) <= sizeof(void*),
#define MARK_BIT 0x1
inline bool isMarked(GCAllocation* header) {
return (header->gc_flags & MARK_BIT) != 0;
}
inline void setMark(GCAllocation* header) {
assert(!isMarked(header));
header->gc_flags |= MARK_BIT;
}
inline void clearMark(GCAllocation* header) {
assert(isMarked(header));
header->gc_flags &= ~MARK_BIT;
}
inline bool isMarked(GCAllocation* header) {
return (header->gc_flags & MARK_BIT) != 0;
}
#undef MARK_BIT
......
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