wasm gc: initialize class initializer globals in global section

This commit is contained in:
Alexey Andreev 2024-08-30 20:54:46 +02:00
parent 638cc8ed15
commit 9b601ac002

View File

@ -390,8 +390,10 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
if (cls != null && cls.getMethod(CLINIT_METHOD_DESC) != null) { if (cls != null && cls.getMethod(CLINIT_METHOD_DESC) != null) {
var clinitType = functionTypes.of(null); var clinitType = functionTypes.of(null);
var wasmName = names.topLevel(names.suggestForClass(name) + "@initializer"); var wasmName = names.topLevel(names.suggestForClass(name) + "@initializer");
classInfo.initializerPointer = new WasmGlobal(wasmName, clinitType.getReference(), var initFunction = functionProvider.forStaticMethod(new MethodReference(name, CLINIT_METHOD_DESC));
new WasmNullConstant(clinitType.getReference())); initFunction.setReferenced(true);
var ref = new WasmFunctionReference(initFunction);
classInfo.initializerPointer = new WasmGlobal(wasmName, clinitType.getReference(), ref);
module.globals.add(classInfo.initializerPointer); module.globals.add(classInfo.initializerPointer);
} }
} }
@ -418,12 +420,6 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
if (virtualTable != null && virtualTable.isConcrete()) { if (virtualTable != null && virtualTable.isConcrete()) {
fillVirtualTableMethods(target, classStructure, classInfo.pointer, virtualTable); 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)));
}
}; };
} }