diff --git a/core/src/main/java/org/teavm/backend/wasm/Example.java b/core/src/main/java/org/teavm/backend/wasm/Example.java index 2eb198710..dd83958a2 100644 --- a/core/src/main/java/org/teavm/backend/wasm/Example.java +++ b/core/src/main/java/org/teavm/backend/wasm/Example.java @@ -145,7 +145,7 @@ public final class Example { private static void testGC() { List list = new ArrayList<>(); - for (int i = 0; i < 100000; ++i) { + for (int i = 0; i < 4000000; ++i) { list.add(i); if (list.size() == 1000) { list = new ArrayList<>(); diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java index d80815bf8..57e6a002c 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java @@ -629,7 +629,7 @@ public class WasmTarget implements TeaVMTarget { gcMemory -= regionCount * 2; address += regionCount * 2; gcIntrinsic.setHeapAddress(address); - gcIntrinsic.setAvailableBytes(address); + gcIntrinsic.setAvailableBytes(gcMemory); } private VirtualTableProvider createVirtualTableProvider(ListableClassHolderSource classes) { diff --git a/core/src/main/java/org/teavm/runtime/GC.java b/core/src/main/java/org/teavm/runtime/GC.java index 6d7d08a70..2f866ff20 100644 --- a/core/src/main/java/org/teavm/runtime/GC.java +++ b/core/src/main/java/org/teavm/runtime/GC.java @@ -61,13 +61,14 @@ public final class GC { Address next = currentChunk.toAddress().add(size); if (!next.add(Structure.sizeOf(FreeChunk.class) + 1).isLessThan(currentChunkLimit)) { getAvailableChunk(size); + current = currentChunk; + next = currentChunk.toAddress().add(size); } int oldSize = current.size; - Address result = current.toAddress(); currentChunk = next.toStructure(); currentChunk.classReference = 0; currentChunk.size = oldSize - size; - return result.toStructure(); + return current; } private static void getAvailableChunk(int size) { @@ -80,14 +81,14 @@ public final class GC { private static boolean getAvailableChunkIfPossible(int size) { while (!currentChunk.toAddress().add(size).isLessThan(currentChunkLimit)) { - if (--size == 0) { + if (--freeChunks == 0) { return false; } currentChunkPointer = currentChunkPointer.toAddress().add(FreeChunkHolder.class, 1).toStructure(); currentChunk = currentChunkPointer.value; currentChunkLimit = currentChunk.toAddress().add(currentChunk.size); } - return false; + return true; } private static boolean collectGarbage(int size) { @@ -152,7 +153,7 @@ public final class GC { while (fieldCount-- > 0) { layout = layout.add(2); int fieldOffset = layout.getShort(); - RuntimeObject reference = object.toAddress().add(fieldOffset).toStructure(); + RuntimeObject reference = object.toAddress().add(fieldOffset).getAddress().toStructure(); if (reference != null && !isMarked(reference)) { MarkQueue.enqueue(reference); }