C/Wasm: fix issue in GC

This commit is contained in:
Alexey Andreev 2021-12-16 18:39:26 +03:00
parent 15466bad93
commit ce5e3bfeb7

View File

@ -115,12 +115,21 @@ public final class GC {
return; return;
} }
collectGarbageImpl(size); collectGarbageImpl(size);
if (currentChunk.size != size && currentChunk.size <= size + MIN_CHUNK_SIZE && !getNextChunkIfPossible(size)) { if (!hasAvailableMemory(size)) {
ExceptionHandling.printStack(); collectGarbageFullImpl(size);
outOfMemory(); if (!hasAvailableMemory(size)) {
ExceptionHandling.printStack();
outOfMemory();
}
} }
} }
private static boolean hasAvailableMemory(int size) {
return currentChunk.size == size
|| currentChunk.size > size + MIN_CHUNK_SIZE
|| getNextChunkIfPossible(size);
}
private static boolean getNextChunkIfPossible(int size) { private static boolean getNextChunkIfPossible(int size) {
while (true) { while (true) {
if (currentChunk.toAddress().isLessThan(currentChunkLimit)) { if (currentChunk.toAddress().isLessThan(currentChunkLimit)) {