mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-24 15:24:51 -08:00
Fix bugs in GC
This commit is contained in:
parent
f2668b867d
commit
de299dda48
|
@ -145,7 +145,7 @@ public final class Example {
|
||||||
|
|
||||||
private static void testGC() {
|
private static void testGC() {
|
||||||
List<Integer> list = new ArrayList<>();
|
List<Integer> list = new ArrayList<>();
|
||||||
for (int i = 0; i < 100000; ++i) {
|
for (int i = 0; i < 4000000; ++i) {
|
||||||
list.add(i);
|
list.add(i);
|
||||||
if (list.size() == 1000) {
|
if (list.size() == 1000) {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
|
|
|
@ -629,7 +629,7 @@ public class WasmTarget implements TeaVMTarget {
|
||||||
gcMemory -= regionCount * 2;
|
gcMemory -= regionCount * 2;
|
||||||
address += regionCount * 2;
|
address += regionCount * 2;
|
||||||
gcIntrinsic.setHeapAddress(address);
|
gcIntrinsic.setHeapAddress(address);
|
||||||
gcIntrinsic.setAvailableBytes(address);
|
gcIntrinsic.setAvailableBytes(gcMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VirtualTableProvider createVirtualTableProvider(ListableClassHolderSource classes) {
|
private VirtualTableProvider createVirtualTableProvider(ListableClassHolderSource classes) {
|
||||||
|
|
|
@ -61,13 +61,14 @@ public final class GC {
|
||||||
Address next = currentChunk.toAddress().add(size);
|
Address next = currentChunk.toAddress().add(size);
|
||||||
if (!next.add(Structure.sizeOf(FreeChunk.class) + 1).isLessThan(currentChunkLimit)) {
|
if (!next.add(Structure.sizeOf(FreeChunk.class) + 1).isLessThan(currentChunkLimit)) {
|
||||||
getAvailableChunk(size);
|
getAvailableChunk(size);
|
||||||
|
current = currentChunk;
|
||||||
|
next = currentChunk.toAddress().add(size);
|
||||||
}
|
}
|
||||||
int oldSize = current.size;
|
int oldSize = current.size;
|
||||||
Address result = current.toAddress();
|
|
||||||
currentChunk = next.toStructure();
|
currentChunk = next.toStructure();
|
||||||
currentChunk.classReference = 0;
|
currentChunk.classReference = 0;
|
||||||
currentChunk.size = oldSize - size;
|
currentChunk.size = oldSize - size;
|
||||||
return result.toStructure();
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getAvailableChunk(int size) {
|
private static void getAvailableChunk(int size) {
|
||||||
|
@ -80,14 +81,14 @@ public final class GC {
|
||||||
|
|
||||||
private static boolean getAvailableChunkIfPossible(int size) {
|
private static boolean getAvailableChunkIfPossible(int size) {
|
||||||
while (!currentChunk.toAddress().add(size).isLessThan(currentChunkLimit)) {
|
while (!currentChunk.toAddress().add(size).isLessThan(currentChunkLimit)) {
|
||||||
if (--size == 0) {
|
if (--freeChunks == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
currentChunkPointer = currentChunkPointer.toAddress().add(FreeChunkHolder.class, 1).toStructure();
|
currentChunkPointer = currentChunkPointer.toAddress().add(FreeChunkHolder.class, 1).toStructure();
|
||||||
currentChunk = currentChunkPointer.value;
|
currentChunk = currentChunkPointer.value;
|
||||||
currentChunkLimit = currentChunk.toAddress().add(currentChunk.size);
|
currentChunkLimit = currentChunk.toAddress().add(currentChunk.size);
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean collectGarbage(int size) {
|
private static boolean collectGarbage(int size) {
|
||||||
|
@ -152,7 +153,7 @@ public final class GC {
|
||||||
while (fieldCount-- > 0) {
|
while (fieldCount-- > 0) {
|
||||||
layout = layout.add(2);
|
layout = layout.add(2);
|
||||||
int fieldOffset = layout.getShort();
|
int fieldOffset = layout.getShort();
|
||||||
RuntimeObject reference = object.toAddress().add(fieldOffset).toStructure();
|
RuntimeObject reference = object.toAddress().add(fieldOffset).getAddress().toStructure();
|
||||||
if (reference != null && !isMarked(reference)) {
|
if (reference != null && !isMarked(reference)) {
|
||||||
MarkQueue.enqueue(reference);
|
MarkQueue.enqueue(reference);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user