С/wasm: don't include references metadata resource into GC stack roots and into class layout for GC.

This commit is contained in:
Alexey Andreev 2022-11-01 09:37:50 +01:00
parent 2c1bf6e270
commit 6c6d440ebb
5 changed files with 36 additions and 4 deletions

View File

@ -374,7 +374,6 @@ public class CTarget implements TeaVMTarget, TeaVMCHost {
TagRegistry tagRegistry = !incremental ? new TagRegistry(classes, hierarchy) : null; TagRegistry tagRegistry = !incremental ? new TagRegistry(classes, hierarchy) : null;
Decompiler decompiler = new Decompiler(classes, new HashSet<>(), controller.isFriendlyToDebugger()); Decompiler decompiler = new Decompiler(classes, new HashSet<>(), controller.isFriendlyToDebugger());
Characteristics characteristics = new Characteristics(controller.getUnprocessedClassSource());
NameProvider nameProvider = new NameProviderWithSpecialNames(rawNameProvider, NameProvider nameProvider = new NameProviderWithSpecialNames(rawNameProvider,
controller.getUnprocessedClassSource()); controller.getUnprocessedClassSource());

View File

@ -1131,6 +1131,7 @@ public class ClassGenerator {
String className = ((ValueType.Object) type).getClassName(); String className = ((ValueType.Object) type).getClassName();
return !context.getCharacteristics().isStructure(className) return !context.getCharacteristics().isStructure(className)
&& !context.getCharacteristics().isFunction(className) && !context.getCharacteristics().isFunction(className)
&& !context.getCharacteristics().isResource(className)
&& !className.equals(Address.class.getName()); && !className.equals(Address.class.getName());
} else { } else {
return type instanceof ValueType.Array; return type instanceof ValueType.Array;

View File

@ -32,6 +32,7 @@ public class Characteristics {
private ObjectByteMap<String> isStructure = new ObjectByteHashMap<>(); private ObjectByteMap<String> isStructure = new ObjectByteHashMap<>();
private ObjectByteMap<String> isStaticInit = new ObjectByteHashMap<>(); private ObjectByteMap<String> isStaticInit = new ObjectByteHashMap<>();
private ObjectByteMap<String> isFunction = new ObjectByteHashMap<>(); private ObjectByteMap<String> isFunction = new ObjectByteHashMap<>();
private ObjectByteMap<String> isResource = new ObjectByteHashMap<>();
private ObjectByteMap<MethodReference> isManaged = new ObjectByteHashMap<>(); private ObjectByteMap<MethodReference> isManaged = new ObjectByteHashMap<>();
public Characteristics(ClassReaderSource classSource) { public Characteristics(ClassReaderSource classSource) {
@ -56,6 +57,34 @@ public class Characteristics {
return result != 0; return result != 0;
} }
public boolean isResource(String className) {
byte result = isResource.getOrDefault(className, (byte) -1);
if (result < 0) {
if (className.equals("org/teavm/platform/metadata/Resource")) {
result = 1;
} else {
ClassReader cls = classSource.get(className);
if (cls != null) {
if (cls.getParent() != null) {
result = isResource(cls.getParent()) ? (byte) 1 : 0;
}
if (result == 0) {
for (String itf : cls.getInterfaces()) {
if (isResource(itf)) {
result = 1;
break;
}
}
}
} else {
result = 0;
}
}
isResource.put(className, result);
}
return result != 0;
}
public boolean isStaticInit(String className) { public boolean isStaticInit(String className) {
byte result = isStaticInit.getOrDefault(className, (byte) -1); byte result = isStaticInit.getOrDefault(className, (byte) -1);
if (result < 0) { if (result < 0) {

View File

@ -28,11 +28,14 @@ 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());
} }
@Override @Override
public boolean apply(MethodReference method) { public boolean apply(MethodReference method) {
return characteristics.isManaged(method.getClassName()) && characteristics.isManaged(method); return characteristics.isManaged(method.getClassName())
&& characteristics.isManaged(method)
&& !characteristics.isResource(method.getClassName());
} }
} }

View File

@ -120,6 +120,6 @@ public class NativePointerFinder {
} }
String className = ((ValueType.Object) type).getClassName(); String className = ((ValueType.Object) type).getClassName();
return characteristics.isStructure(className) || className.equals(Address.class.getName()) return characteristics.isStructure(className) || className.equals(Address.class.getName())
|| characteristics.isFunction(className); || characteristics.isFunction(className) || characteristics.isResource(className);
} }
} }