Allow stack to grow in gc

The previous bound was valid in each logical version of the map, but not
for the physical map's structure.
This commit is contained in:
2024-06-15 20:26:34 -07:00
parent 0af75f5e9c
commit e11ee26332

View File

@@ -285,9 +285,11 @@ struct MemManager {
void gc(const uint32_t *roots, int numRoots, int64_t oldestVersion) { void gc(const uint32_t *roots, int numRoots, int64_t oldestVersion) {
// Calculate reachable set // Calculate reachable set
BitSet reachable{next}; BitSet reachable{next};
// Each node has at most 3 children and nodes along the search path aren't Arena arena;
// in the stack, so we need 2 * kPathLengthUpperBound constexpr int kInitialStackCapacity = 128;
uint32_t stack[2 * kPathLengthUpperBound]; int64_t stackCapacity = kInitialStackCapacity;
uint32_t stackStack[kInitialStackCapacity];
uint32_t *stack = stackStack;
int stackIndex = 0; int stackIndex = 0;
auto tryPush = [&]([[maybe_unused]] uint32_t parent, uint32_t child) { auto tryPush = [&]([[maybe_unused]] uint32_t parent, uint32_t child) {
if (!reachable.set(child)) { if (!reachable.set(child)) {
@@ -296,7 +298,12 @@ struct MemManager {
printf(" GC: reach: %u (parent %u)\n", child, parent); printf(" GC: reach: %u (parent %u)\n", child, parent);
} }
#endif #endif
assert(stackIndex < int(sizeof(stack) / sizeof(stack[0]))); if (stackIndex == stackCapacity) [[unlikely]] {
auto *old = stack;
stackCapacity *= 2;
stack = new (arena) uint32_t[stackCapacity];
memcpy(stack, old, stackIndex * sizeof(stack[0]));
}
stack[stackIndex++] = child; stack[stackIndex++] = child;
} }
}; };