From 6de830d5bd44762f6d2a8a255dae82487563bde2 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 22 Mar 2021 23:22:34 +0300 Subject: [PATCH] wasm: fix initialization order of system classes --- .../java/org/teavm/backend/wasm/WasmTarget.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 1f33f731d..64b9e60a3 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java @@ -160,6 +160,7 @@ import org.teavm.runtime.Allocator; import org.teavm.runtime.EventQueue; import org.teavm.runtime.ExceptionHandling; import org.teavm.runtime.Fiber; +import org.teavm.runtime.GC; import org.teavm.runtime.RuntimeArray; import org.teavm.runtime.RuntimeClass; import org.teavm.runtime.RuntimeObject; @@ -590,8 +591,18 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost { new WasmInt32Constant(heapAddress), new WasmInt32Constant(minHeapSize), new WasmInt32Constant(maxHeapSize), new WasmInt32Constant(WasmHeap.DEFAULT_STACK_SIZE))); + for (Class javaCls : new Class[] { GC.class }) { + ClassReader cls = classes.get(javaCls.getName()); + MethodReader clinit = cls.getMethod(new MethodDescriptor("", void.class)); + if (clinit == null) { + continue; + } + initFunction.getBody().add(new WasmCall(names.forClassInitializer(cls.getName()))); + } + for (String className : classes.getClassNames()) { - if (className.equals(WasmRuntime.class.getName()) || className.equals(WasmHeap.class.getName())) { + if (className.equals(WasmRuntime.class.getName()) || className.equals(WasmHeap.class.getName()) + || className.equals(GC.class.getName())) { continue; } ClassReader cls = classes.get(className);