mirror of
https://github.com/konsoletyper/teavm.git
synced 2024-11-27 01:30:35 +08:00
wasm gc: always emit java.lang.Class, fix issue with recursive types
This commit is contained in:
parent
0cda737dca
commit
ba08fb395c
@ -30,6 +30,7 @@ public class WasmGCDependencies {
|
||||
}
|
||||
|
||||
public void contribute() {
|
||||
analyzer.linkClass("java.lang.Class");
|
||||
contributeWasmRuntime();
|
||||
contributeMathUtils();
|
||||
contributeExceptionUtils();
|
||||
|
@ -296,31 +296,37 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||
}
|
||||
|
||||
public int getClassTagOffset() {
|
||||
standardClasses.classClass().getStructure().init();
|
||||
return classTagOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClassArrayItemOffset() {
|
||||
standardClasses.classClass().getStructure().init();
|
||||
return classArrayItemOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClassSupertypeFunctionOffset() {
|
||||
standardClasses.classClass().getStructure().init();
|
||||
return classSupertypeFunctionOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClassNameOffset() {
|
||||
standardClasses.classClass().getStructure().init();
|
||||
return classNameOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewArrayFunctionOffset() {
|
||||
standardClasses.classClass().getStructure().init();
|
||||
return classNewArrayOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVirtualMethodsOffset() {
|
||||
standardClasses.classClass().getStructure().init();
|
||||
return virtualTableFieldOffset;
|
||||
}
|
||||
|
||||
@ -387,6 +393,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||
}
|
||||
}
|
||||
classInfo.initializer = target -> {
|
||||
standardClasses.classClass().getStructure().init();
|
||||
var ranges = tagRegistry.getRanges(name);
|
||||
int tag = ranges.stream().mapToInt(range -> range.lower).min().orElse(0);
|
||||
target.add(setClassField(classInfo, classTagOffset, new WasmInt32Constant(tag)));
|
||||
@ -770,6 +777,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||
function.add(nameVar);
|
||||
function.add(kindVar);
|
||||
|
||||
standardClasses.classClass().getStructure().getFields().size();
|
||||
var flagsExpr = new WasmIntBinary(
|
||||
WasmIntType.INT32,
|
||||
WasmIntBinaryOperation.SHL,
|
||||
@ -824,6 +832,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||
var itemVar = new WasmLocal(standardClasses.classClass().getType(), "item");
|
||||
function.add(targetVar);
|
||||
function.add(itemVar);
|
||||
standardClasses.classClass().getStructure().init();
|
||||
|
||||
function.getBody().add(new WasmStructSet(
|
||||
standardClasses.classClass().getStructure(),
|
||||
|
@ -18,7 +18,6 @@ package org.teavm.backend.wasm.model;
|
||||
public abstract class WasmCompositeType extends WasmEntity {
|
||||
private String name;
|
||||
private WasmType.CompositeReference reference;
|
||||
int indexInRecursiveType = -1;
|
||||
int recursiveTypeCount = -1;
|
||||
|
||||
WasmCompositeType(String name) {
|
||||
@ -36,10 +35,6 @@ public abstract class WasmCompositeType extends WasmEntity {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public int getIndexInRecursiveType() {
|
||||
return indexInRecursiveType;
|
||||
}
|
||||
|
||||
public int getRecursiveTypeCount() {
|
||||
return recursiveTypeCount;
|
||||
}
|
||||
|
@ -107,12 +107,7 @@ public class WasmModule {
|
||||
var sccsByIndex = new int[types.size()][];
|
||||
for (var scc : sccs) {
|
||||
sccsByIndex[scc[0]] = scc;
|
||||
var firstType = types.get(scc[0]);
|
||||
firstType.recursiveTypeCount = scc.length;
|
||||
for (var i = 0; i < scc.length; i++) {
|
||||
var index = scc[i];
|
||||
var type = types.get(index);
|
||||
type.indexInRecursiveType = i;
|
||||
sccStartNode[scc[i]] = sccStartNode[scc[0]];
|
||||
}
|
||||
}
|
||||
@ -162,9 +157,11 @@ public class WasmModule {
|
||||
visit(outgoing);
|
||||
}
|
||||
}
|
||||
var indexOfFirst = sorted.size();
|
||||
for (var index : scc) {
|
||||
visitScc(index, typeIndex);
|
||||
}
|
||||
sorted.get(indexOfFirst).recursiveTypeCount = scc.length;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user