mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
Don't write Structure, Function and Address to GC roots
This commit is contained in:
parent
3370898a54
commit
d76598ab68
|
@ -36,6 +36,7 @@ public final class Example {
|
|||
testArrayCopy();
|
||||
testArrayIsObject();
|
||||
testIsAssignableFrom();
|
||||
testGC();
|
||||
}
|
||||
|
||||
private static void testFibonacci() {
|
||||
|
@ -142,6 +143,17 @@ public final class Example {
|
|||
println("Base.isAssignableFrom(A) = " + Base.class.isAssignableFrom(A.class));
|
||||
}
|
||||
|
||||
private static void testGC() {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (int i = 0; i < 100000; ++i) {
|
||||
list.add(i);
|
||||
if (list.size() == 1000) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
print("GC complete");
|
||||
}
|
||||
|
||||
private static Base instance(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
|
|
|
@ -226,7 +226,7 @@ public class WasmClassGenerator {
|
|||
private List<FieldReference> getReferenceFields(ClassReader cls) {
|
||||
return cls.getFields().stream()
|
||||
.filter(field -> !field.hasModifier(ElementModifier.STATIC))
|
||||
.filter(field -> !(field.getType() instanceof ValueType.Primitive))
|
||||
.filter(field -> isReferenceType(field.getType()))
|
||||
.map(field -> field.getReference())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
@ -234,11 +234,37 @@ public class WasmClassGenerator {
|
|||
private List<FieldReference> getStaticReferenceFields(ClassReader cls) {
|
||||
return cls.getFields().stream()
|
||||
.filter(field -> field.hasModifier(ElementModifier.STATIC))
|
||||
.filter(field -> !(field.getType() instanceof ValueType.Primitive))
|
||||
.filter(field -> isReferenceType(field.getType()))
|
||||
.map(field -> field.getReference())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean isReferenceType(ValueType type) {
|
||||
if (type instanceof ValueType.Primitive) {
|
||||
return false;
|
||||
} else if (type instanceof ValueType.Object) {
|
||||
ClassReader cls = classSource.get(((ValueType.Object) type).getClassName());
|
||||
if (cls == null) {
|
||||
return true;
|
||||
}
|
||||
if (cls.getName().equals(Address.class.getName())) {
|
||||
return true;
|
||||
}
|
||||
while (cls != null) {
|
||||
if (cls.getName().equals(Structure.class.getName()) || cls.getName().equals(Function.class.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (cls.getParent() == null || cls.getParent().equals(cls.getName())) {
|
||||
return true;
|
||||
}
|
||||
cls = classSource.get(cls.getParent());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void fillVirtualTable(VirtualTable vtable, DataValue array) {
|
||||
int index = 0;
|
||||
for (VirtualTableEntry vtableEntry : vtable.getEntries().values()) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user