Wasm: fix resource files getting into garbage collection metadata

This commit is contained in:
Alexey Andreev 2022-11-04 14:48:53 +01:00
parent 6c6d440ebb
commit 752ec040b0
3 changed files with 16 additions and 24 deletions

View File

@ -427,7 +427,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
ClassMetadataRequirements metadataRequirements = new ClassMetadataRequirements(controller.getDependencyInfo()); ClassMetadataRequirements metadataRequirements = new ClassMetadataRequirements(controller.getDependencyInfo());
WasmClassGenerator classGenerator = new WasmClassGenerator(classes, controller.getUnprocessedClassSource(), WasmClassGenerator classGenerator = new WasmClassGenerator(classes, controller.getUnprocessedClassSource(),
vtableProvider, tagRegistry, binaryWriter, names, metadataRequirements, vtableProvider, tagRegistry, binaryWriter, names, metadataRequirements,
controller.getClassInitializerInfo()); controller.getClassInitializerInfo(), characteristics);
Decompiler decompiler = new Decompiler(classes, new HashSet<>(), false); Decompiler decompiler = new Decompiler(classes, new HashSet<>(), false);
WasmStringPool stringPool = classGenerator.getStringPool(); WasmStringPool stringPool = classGenerator.getStringPool();

View File

@ -49,12 +49,14 @@ import org.teavm.model.classes.TagRegistry;
import org.teavm.model.classes.VirtualTable; import org.teavm.model.classes.VirtualTable;
import org.teavm.model.classes.VirtualTableEntry; import org.teavm.model.classes.VirtualTableEntry;
import org.teavm.model.classes.VirtualTableProvider; import org.teavm.model.classes.VirtualTableProvider;
import org.teavm.model.lowlevel.Characteristics;
import org.teavm.runtime.RuntimeClass; import org.teavm.runtime.RuntimeClass;
import org.teavm.runtime.RuntimeObject; import org.teavm.runtime.RuntimeObject;
public class WasmClassGenerator { public class WasmClassGenerator {
private ClassReaderSource processedClassSource; private ClassReaderSource processedClassSource;
private ClassReaderSource classSource; private ClassReaderSource classSource;
private Characteristics characteristics;
public final NameProvider names; public final NameProvider names;
private Map<ValueType, ClassBinaryData> binaryDataMap = new LinkedHashMap<>(); private Map<ValueType, ClassBinaryData> binaryDataMap = new LinkedHashMap<>();
private BinaryWriter binaryWriter; private BinaryWriter binaryWriter;
@ -115,7 +117,7 @@ public class WasmClassGenerator {
public WasmClassGenerator(ClassReaderSource processedClassSource, ClassReaderSource classSource, public WasmClassGenerator(ClassReaderSource processedClassSource, ClassReaderSource classSource,
VirtualTableProvider vtableProvider, TagRegistry tagRegistry, BinaryWriter binaryWriter, VirtualTableProvider vtableProvider, TagRegistry tagRegistry, BinaryWriter binaryWriter,
NameProvider names, ClassMetadataRequirements metadataRequirements, NameProvider names, ClassMetadataRequirements metadataRequirements,
ClassInitializerInfo classInitializerInfo) { ClassInitializerInfo classInitializerInfo, Characteristics characteristics) {
this.processedClassSource = processedClassSource; this.processedClassSource = processedClassSource;
this.classSource = classSource; this.classSource = classSource;
this.vtableProvider = vtableProvider; this.vtableProvider = vtableProvider;
@ -125,6 +127,7 @@ public class WasmClassGenerator {
this.names = names; this.names = names;
this.metadataRequirements = metadataRequirements; this.metadataRequirements = metadataRequirements;
this.classInitializerInfo = classInitializerInfo; this.classInitializerInfo = classInitializerInfo;
this.characteristics = characteristics;
} }
public WasmStringPool getStringPool() { public WasmStringPool getStringPool() {
@ -161,10 +164,12 @@ public class WasmClassGenerator {
break; break;
} }
binaryData.data = createPrimitiveClassData(size, type); binaryData.data = classStructure.createValue();
createPrimitiveClassData(binaryData.data, size, type);
binaryData.start = binaryWriter.append(binaryData.data); binaryData.start = binaryWriter.append(binaryData.data);
} else if (type == ValueType.VOID) { } else if (type == ValueType.VOID) {
binaryData.data = createPrimitiveClassData(0, type); binaryData.data = classStructure.createValue();
createPrimitiveClassData(binaryData.data, 0, type);
binaryData.start = binaryWriter.append(binaryData.data); binaryData.start = binaryWriter.append(binaryData.data);
} else if (type instanceof ValueType.Object) { } else if (type instanceof ValueType.Object) {
String className = ((ValueType.Object) type).getClassName(); String className = ((ValueType.Object) type).getClassName();
@ -207,8 +212,7 @@ public class WasmClassGenerator {
} }
} }
private DataValue createPrimitiveClassData(int size, ValueType type) { private DataValue createPrimitiveClassData(DataValue value, int size, ValueType type) {
DataValue value = classStructure.createValue();
value.setInt(CLASS_SIZE, size); value.setInt(CLASS_SIZE, size);
value.setInt(CLASS_FLAGS, RuntimeClass.PRIMITIVE); value.setInt(CLASS_FLAGS, RuntimeClass.PRIMITIVE);
value.setInt(CLASS_IS_INSTANCE, functionTable.size()); value.setInt(CLASS_IS_INSTANCE, functionTable.size());
@ -395,23 +399,11 @@ public class WasmClassGenerator {
if (type instanceof ValueType.Primitive) { if (type instanceof ValueType.Primitive) {
return false; return false;
} else if (type instanceof ValueType.Object) { } else if (type instanceof ValueType.Object) {
ClassReader cls = classSource.get(((ValueType.Object) type).getClassName()); String className = ((ValueType.Object) type).getClassName();
if (cls == null) { return !characteristics.isStructure(className)
return true; && !characteristics.isFunction(className)
} && !characteristics.isResource(className)
if (cls.getName().equals(Address.class.getName())) { && !className.equals(Address.class.getName());
return false;
}
while (cls != null) {
if (cls.getName().equals(Structure.class.getName()) || cls.getName().equals(Function.class.getName())) {
return false;
}
if (cls.getParent() == null) {
return true;
}
cls = classSource.get(cls.getParent());
}
return true;
} else { } else {
return true; return true;
} }

View File

@ -29,7 +29,7 @@ public class LowLevelNullCheckFilter implements NullCheckFilter {
@Override @Override
public boolean apply(FieldReference field) { public boolean apply(FieldReference field) {
return !characteristics.isStructure(field.getClassName()) return !characteristics.isStructure(field.getClassName())
&& !characteristics.isStructure(field.getClassName()); && !characteristics.isResource(field.getClassName());
} }
@Override @Override