Commit d85c9893 authored by Chris Toshok's avatar Chris Toshok

add a comment about further work for realloc(), and factor out the duplicate...

add a comment about further work for realloc(), and factor out the duplicate list.forEach in large/huge arenas
parent 7cd29d79
......@@ -35,7 +35,7 @@ namespace gc {
void _doFree(GCAllocation* al);
// lots of linked lists around here, so let's just use template functions for them all
// lots of linked lists around here, so let's just use template functions for operations on them.
template <class ListT> inline void nullNextPrev(ListT* node) {
node->next = NULL;
node->prev = NULL;
......@@ -67,6 +67,13 @@ template <class ListT> inline void insertIntoLL(ListT** next_pointer, ListT* nex
next->prev = next_pointer;
}
template <class ListT, typename Func> inline void forEach(ListT* list, Func func) {
auto cur = list;
while (cur) {
func(cur);
cur = cur->next;
}
}
template <class ListT, typename Free> inline void sweepList(ListT* head, Free free_func) {
auto cur = head;
......@@ -576,13 +583,7 @@ void LargeArena::freeUnmarked() {
}
void LargeArena::getStatistics(HeapStatistics* stats) {
LargeObj* cur = head;
while (cur) {
GCAllocation* al = cur->data;
addStatistic(stats, al, cur->size);
cur = cur->next;
}
forEach(head, [stats](LargeObj* obj) { addStatistic(stats, obj->data, obj->size); });
}
......@@ -774,13 +775,7 @@ void HugeArena::freeUnmarked() {
}
void HugeArena::getStatistics(HeapStatistics* stats) {
HugeObj* cur = head;
while (cur) {
GCAllocation* al = cur->data;
addStatistic(stats, al, cur->capacity());
cur = cur->next;
}
forEach(head, [stats](HugeObj* obj) { addStatistic(stats, obj->data, obj->capacity()); });
}
void HugeArena::_freeHugeObj(HugeObj* lobj) {
......
......@@ -389,6 +389,12 @@ public:
Heap() : small_arena(this), large_arena(this), huge_arena(this) {}
GCAllocation* realloc(GCAllocation* alloc, size_t bytes) {
// TODO(toshok): there is duplicate code in each of the
// ::realloc methods to test whether the allocation can be
// reused. Would be nice to factor it all out here into this
// method.
if (large_arena.contains(alloc)) {
return large_arena.realloc(alloc, bytes);
} else if (huge_arena.contains(alloc)) {
......
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