Skip to content

Commit 5d177d1

Browse files
aykevldeadprogram
authored andcommitted
runtime: be able to deal with a very small heap
See the comment in the source for details. Also see the discussion in #2755, which originally triggered this bug. Somewhat surprising, this results in a slight code size decrease for ARM targets of a few bytes.
1 parent 9eb4a62 commit 5d177d1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/runtime/gc_conservative.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
310310
index = 0
311311
// Reset numFreeBlocks as allocations cannot wrap.
312312
numFreeBlocks = 0
313+
// In rare cases, the initial heap might be so small that there are
314+
// no blocks at all. In this case, it's better to jump back to the
315+
// start of the loop and try again, until the GC realizes there is
316+
// no memory and grows the heap.
317+
// This can sometimes happen on WebAssembly, where the initial heap
318+
// is created by whatever is left on the last memory page.
319+
continue
313320
}
314321

315322
// Is the block we're looking at free?

0 commit comments

Comments
 (0)