From 9b601ac002eb49921f72a69425d32dd9e9589a78 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 30 Aug 2024 20:54:46 +0200 Subject: [PATCH] wasm gc: initialize class initializer globals in global section --- .../generate/gc/classes/WasmGCClassGenerator.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java index 9d13ce478..491f5a6e4 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java @@ -390,8 +390,10 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit if (cls != null && cls.getMethod(CLINIT_METHOD_DESC) != null) { var clinitType = functionTypes.of(null); var wasmName = names.topLevel(names.suggestForClass(name) + "@initializer"); - classInfo.initializerPointer = new WasmGlobal(wasmName, clinitType.getReference(), - new WasmNullConstant(clinitType.getReference())); + var initFunction = functionProvider.forStaticMethod(new MethodReference(name, CLINIT_METHOD_DESC)); + initFunction.setReferenced(true); + var ref = new WasmFunctionReference(initFunction); + classInfo.initializerPointer = new WasmGlobal(wasmName, clinitType.getReference(), ref); module.globals.add(classInfo.initializerPointer); } } @@ -418,12 +420,6 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit if (virtualTable != null && virtualTable.isConcrete()) { fillVirtualTableMethods(target, classStructure, classInfo.pointer, virtualTable); } - if (classInfo.initializerPointer != null) { - var initFunction = functionProvider.forStaticMethod(new MethodReference(name, - CLINIT_METHOD_DESC)); - initFunction.setReferenced(true); - target.add(new WasmSetGlobal(classInfo.initializerPointer, new WasmFunctionReference(initFunction))); - } }; }