From a33f96b899555706d3bbd29047edc488cf4df6d5 Mon Sep 17 00:00:00 2001 From: lax1dude Date: Sat, 9 Nov 2024 16:57:15 -0800 Subject: [PATCH] Fix initial heap grow --- core/src/main/java/org/teavm/runtime/LaxMalloc.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/teavm/runtime/LaxMalloc.java b/core/src/main/java/org/teavm/runtime/LaxMalloc.java index c3867c258..88836caa1 100644 --- a/core/src/main/java/org/teavm/runtime/LaxMalloc.java +++ b/core/src/main/java/org/teavm/runtime/LaxMalloc.java @@ -63,7 +63,7 @@ public final class LaxMalloc { private static native Address addrHeap(int offset); // Intrinsic function to grow the heap segment - private static native int growHeapOuter(int bytes); + private static native int growHeapOuter(int chunks); // Intrinsic function to get the minimum direct malloc heap segment ending address private static native Address getHeapMinAddr(); @@ -81,8 +81,11 @@ public final class LaxMalloc { addrHeap(ADDR_HEAP_INNER_LIMIT).putAddress(addrHeap(ADDR_HEAP_DATA_START)); addrHeap(ADDR_HEAP_OUTER_LIMIT).putAddress(getHeapMinAddr()); - //TODO: Need to handle error setting the heap to its initial size - growHeapOuter(getHeapMinAddr().toInt() >> 16); + int initialGrowAmount = getHeapMinAddr().toInt() >>> 16 - 1; + if (initialGrowAmount > 0) { + //TODO: Need to handle error setting the heap to its initial size + growHeapOuter(initialGrowAmount); + } } /**