mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 00:14:10 -08:00
Fix bugs in GC and runtime
This commit is contained in:
parent
43b0700c10
commit
fae2963900
|
@ -123,12 +123,12 @@ public class AddressIntrinsic implements WasmIntrinsic {
|
||||||
WasmExpression value = manager.generate(invocation.getArguments().get(1));
|
WasmExpression value = manager.generate(invocation.getArguments().get(1));
|
||||||
return new WasmStoreInt32(2, address, value, WasmInt32Subtype.INT16);
|
return new WasmStoreInt32(2, address, value, WasmInt32Subtype.INT16);
|
||||||
}
|
}
|
||||||
case "putAddress":
|
|
||||||
case "putChar": {
|
case "putChar": {
|
||||||
WasmExpression address = manager.generate(invocation.getArguments().get(0));
|
WasmExpression address = manager.generate(invocation.getArguments().get(0));
|
||||||
WasmExpression value = manager.generate(invocation.getArguments().get(1));
|
WasmExpression value = manager.generate(invocation.getArguments().get(1));
|
||||||
return new WasmStoreInt32(2, address, value, WasmInt32Subtype.UINT16);
|
return new WasmStoreInt32(2, address, value, WasmInt32Subtype.UINT16);
|
||||||
}
|
}
|
||||||
|
case "putAddress":
|
||||||
case "putInt": {
|
case "putInt": {
|
||||||
WasmExpression address = manager.generate(invocation.getArguments().get(0));
|
WasmExpression address = manager.generate(invocation.getArguments().get(0));
|
||||||
WasmExpression value = manager.generate(invocation.getArguments().get(1));
|
WasmExpression value = manager.generate(invocation.getArguments().get(1));
|
||||||
|
|
|
@ -97,7 +97,6 @@ public final class GC {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void mark() {
|
private static void mark() {
|
||||||
MarkQueue.init();
|
|
||||||
Allocator.fillZero(regionsAddress().toAddress(), regionMaxCount() * Structure.sizeOf(Region.class));
|
Allocator.fillZero(regionsAddress().toAddress(), regionMaxCount() * Structure.sizeOf(Region.class));
|
||||||
|
|
||||||
Address staticRoots = Mutator.getStaticGcRoots();
|
Address staticRoots = Mutator.getStaticGcRoots();
|
||||||
|
@ -127,6 +126,7 @@ public final class GC {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MarkQueue.init();
|
||||||
MarkQueue.enqueue(object);
|
MarkQueue.enqueue(object);
|
||||||
while (!MarkQueue.isEmpty()) {
|
while (!MarkQueue.isEmpty()) {
|
||||||
object = MarkQueue.dequeue();
|
object = MarkQueue.dequeue();
|
||||||
|
@ -144,20 +144,34 @@ public final class GC {
|
||||||
}
|
}
|
||||||
|
|
||||||
RuntimeClass cls = RuntimeClass.getClass(object);
|
RuntimeClass cls = RuntimeClass.getClass(object);
|
||||||
while (cls != null) {
|
if (cls.itemType == null) {
|
||||||
Address layout = cls.layout;
|
while (cls != null) {
|
||||||
if (layout != null) {
|
Address layout = cls.layout;
|
||||||
short fieldCount = layout.getShort();
|
if (layout != null) {
|
||||||
while (fieldCount-- > 0) {
|
short fieldCount = layout.getShort();
|
||||||
layout = layout.add(2);
|
while (fieldCount-- > 0) {
|
||||||
int fieldOffset = layout.getShort();
|
layout = layout.add(2);
|
||||||
RuntimeObject reference = object.toAddress().add(fieldOffset).toStructure();
|
int fieldOffset = layout.getShort();
|
||||||
|
RuntimeObject reference = object.toAddress().add(fieldOffset).toStructure();
|
||||||
|
if (reference != null && !isMarked(reference)) {
|
||||||
|
MarkQueue.enqueue(reference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cls = cls.parent;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((cls.itemType.flags & RuntimeClass.PRIMITIVE) == 0) {
|
||||||
|
RuntimeArray array = (RuntimeArray) object;
|
||||||
|
Address base = Address.align(array.toAddress().add(RuntimeArray.class, 1), 4);
|
||||||
|
for (int i = 0; i < array.size; ++i) {
|
||||||
|
RuntimeObject reference = base.getAddress().toStructure();
|
||||||
if (reference != null && !isMarked(reference)) {
|
if (reference != null && !isMarked(reference)) {
|
||||||
MarkQueue.enqueue(reference);
|
MarkQueue.enqueue(reference);
|
||||||
}
|
}
|
||||||
|
base = base.add(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cls = cls.parent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,8 +254,10 @@ public final class GC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentChunkPointer = heapAddress().toStructure();
|
currentChunkPointer = gcStorageAddress().toStructure();
|
||||||
sortFreeChunks(0, freeChunks - 1);
|
sortFreeChunks(0, freeChunks - 1);
|
||||||
|
currentChunk = currentChunkPointer.value;
|
||||||
|
currentChunkLimit = currentChunk.toAddress().add(currentChunk.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sortFreeChunks(int lower, int upper) {
|
private static void sortFreeChunks(int lower, int upper) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user