mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
Fixing bugs in GC
This commit is contained in:
parent
d76598ab68
commit
593dafdd73
|
@ -244,9 +244,10 @@ public final class WasmRuntime {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Address allocStack(int size) {
|
public static Address allocStack(int size) {
|
||||||
Address result = stack;
|
Address result = stack.add(4);
|
||||||
stack = stack.add((size + 1) << 2);
|
stack = result.add(size << 2);
|
||||||
stack.add(-4).putInt(size);
|
fillZero(result, size << 2);
|
||||||
|
stack.putInt(size);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +257,11 @@ public final class WasmRuntime {
|
||||||
|
|
||||||
public static Address getNextStackRoots(Address address) {
|
public static Address getNextStackRoots(Address address) {
|
||||||
int size = address.getInt() + 1;
|
int size = address.getInt() + 1;
|
||||||
return address.add(-size * 4);
|
Address result = address.add(-size * 4);
|
||||||
|
if (result == initStack()) {
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStackRootCount(Address address) {
|
public static int getStackRootCount(Address address) {
|
||||||
|
|
|
@ -906,8 +906,10 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
int offset = classGenerator.getFieldOffset(new FieldReference(WasmRuntime.class.getName(), "stack"));
|
int offset = classGenerator.getFieldOffset(new FieldReference(WasmRuntime.class.getName(), "stack"));
|
||||||
result = new WasmStoreInt32(4, new WasmInt32Constant(offset), new WasmGetLocal(stackVariable),
|
WasmExpression oldValue = new WasmGetLocal(stackVariable);
|
||||||
WasmInt32Subtype.INT32);
|
oldValue = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SUB, oldValue,
|
||||||
|
new WasmInt32Constant(4));
|
||||||
|
result = new WasmStoreInt32(4, new WasmInt32Constant(offset), oldValue, WasmInt32Subtype.INT32);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateRegisterGcRoot(Expr slotExpr, Expr gcRootExpr) {
|
private void generateRegisterGcRoot(Expr slotExpr, Expr gcRootExpr) {
|
||||||
|
|
|
@ -98,8 +98,7 @@ public class ClassInitializerTransformer {
|
||||||
|
|
||||||
InvokeInstruction checkInitialized = new InvokeInstruction();
|
InvokeInstruction checkInitialized = new InvokeInstruction();
|
||||||
checkInitialized.setType(InvocationType.SPECIAL);
|
checkInitialized.setType(InvocationType.SPECIAL);
|
||||||
checkInitialized.setMethod(new MethodReference(Allocator.class, "isInitialized",
|
checkInitialized.setMethod(new MethodReference(Allocator.class, "isInitialized", Class.class, boolean.class));
|
||||||
Class.class, boolean.class));
|
|
||||||
checkInitialized.getArguments().add(clsVariable);
|
checkInitialized.getArguments().add(clsVariable);
|
||||||
checkInitialized.setReceiver(initializedVariable);
|
checkInitialized.setReceiver(initializedVariable);
|
||||||
block.getInstructions().add(checkInitialized);
|
block.getInstructions().add(checkInitialized);
|
||||||
|
|
|
@ -33,7 +33,9 @@ public final class Allocator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Address allocateArray(RuntimeClass tag, int size) {
|
public static Address allocateArray(RuntimeClass tag, int size) {
|
||||||
int sizeInBytes = tag.itemType.size * size + Structure.sizeOf(RuntimeArray.class);
|
int itemSize = (tag.itemType.flags & RuntimeClass.PRIMITIVE) != 0 ? tag.itemType.size : 4;
|
||||||
|
int sizeInBytes = Address.align(Address.fromInt(Structure.sizeOf(RuntimeArray.class)), itemSize).toInt();
|
||||||
|
sizeInBytes += itemSize * size;
|
||||||
sizeInBytes = Address.align(Address.fromInt(sizeInBytes), 4).toInt();
|
sizeInBytes = Address.align(Address.fromInt(sizeInBytes), 4).toInt();
|
||||||
Address result = GC.alloc(sizeInBytes).toAddress();
|
Address result = GC.alloc(sizeInBytes).toAddress();
|
||||||
fillZero(result, sizeInBytes);
|
fillZero(result, sizeInBytes);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user