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