From 516602d32d52288f105dec3282c71cd0b709614a Mon Sep 17 00:00:00 2001 From: lax1dude Date: Mon, 2 Dec 2024 00:35:28 -0800 Subject: [PATCH] wasm gc: add support for string pools over 10000 strings (#977) Due to limit in spec that allows `ref.array_new_fixed` to take up to 10000 arguments --- .../wasm/generate/gc/strings/WasmGCStringPool.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/strings/WasmGCStringPool.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/strings/WasmGCStringPool.java index 3784b12ef..0204afead 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/strings/WasmGCStringPool.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/strings/WasmGCStringPool.java @@ -93,11 +93,17 @@ public class WasmGCStringPool implements WasmGCStringProvider, WasmGCInitializer void.class)); function.getBody().add(new WasmCall(internInit)); } - var array = new WasmArrayNewFixed(stringsArray); - for (var str : stringMap.values()) { - array.getElements().add(new WasmGetGlobal(str.global)); + var stringIterator = stringMap.values().iterator(); + while (stringIterator.hasNext()) { + var elementCount = 0; + var array = new WasmArrayNewFixed(stringsArray); + // WasmArrayNewFixed cannot be larger than 10000 elements + while (elementCount < 10000 && stringIterator.hasNext()) { + array.getElements().add(new WasmGetGlobal(stringIterator.next().global)); + ++elementCount; + } + function.getBody().add(new WasmCall(initStringsFunction, array)); } - function.getBody().add(new WasmCall(initStringsFunction, array)); } @Override