mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 00:14:10 -08:00
C/Wasm: trying to fix GC (again)
This commit is contained in:
parent
84aa50e7eb
commit
150a613709
|
@ -32,10 +32,7 @@ public final class GC {
|
||||||
private static final byte CARD_YOUNG_GEN = 2;
|
private static final byte CARD_YOUNG_GEN = 2;
|
||||||
private static final byte CARD_GAP = 4;
|
private static final byte CARD_GAP = 4;
|
||||||
private static final byte CARD_RELOCATABLE = 8;
|
private static final byte CARD_RELOCATABLE = 8;
|
||||||
|
private static final int MIN_CHUNK_SIZE = 8;
|
||||||
// Add some value greater than 4 to size of last object in a chunk to avoid 4 bytes chunks
|
|
||||||
// that aren't denotable in heap
|
|
||||||
private static final byte GC_OBJECT_GAP = 5;
|
|
||||||
|
|
||||||
static Address currentChunkLimit;
|
static Address currentChunkLimit;
|
||||||
static FreeChunk currentChunk;
|
static FreeChunk currentChunk;
|
||||||
|
@ -117,8 +114,8 @@ public final class GC {
|
||||||
if (getNextChunkIfPossible(size)) {
|
if (getNextChunkIfPossible(size)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
collectGarbageImpl(size + GC_OBJECT_GAP);
|
collectGarbageImpl(size);
|
||||||
if (currentChunk.size < size + GC_OBJECT_GAP && !getNextChunkIfPossible(size)) {
|
if (currentChunk.size != size && currentChunk.size <= size + MIN_CHUNK_SIZE && !getNextChunkIfPossible(size)) {
|
||||||
ExceptionHandling.printStack();
|
ExceptionHandling.printStack();
|
||||||
outOfMemory();
|
outOfMemory();
|
||||||
}
|
}
|
||||||
|
@ -135,7 +132,7 @@ public final class GC {
|
||||||
}
|
}
|
||||||
currentChunkPointer = Structure.add(FreeChunkHolder.class, currentChunkPointer, 1);
|
currentChunkPointer = Structure.add(FreeChunkHolder.class, currentChunkPointer, 1);
|
||||||
currentChunk = currentChunkPointer.value;
|
currentChunk = currentChunkPointer.value;
|
||||||
if (currentChunk.size >= size + GC_OBJECT_GAP) {
|
if (currentChunk.size >= size + MIN_CHUNK_SIZE || currentChunk.size == size) {
|
||||||
currentChunkLimit = currentChunk.toAddress().add(currentChunk.size);
|
currentChunkLimit = currentChunk.toAddress().add(currentChunk.size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -214,7 +211,7 @@ public final class GC {
|
||||||
}
|
}
|
||||||
FreeChunkHolder ptr = currentChunkPointer;
|
FreeChunkHolder ptr = currentChunkPointer;
|
||||||
for (int i = 0; i < freeChunks; ++i) {
|
for (int i = 0; i < freeChunks; ++i) {
|
||||||
if (size <= ptr.value.size) {
|
if (size == ptr.value.size || size + MIN_CHUNK_SIZE <= ptr.value.size) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ptr = Structure.add(FreeChunkHolder.class, ptr, 1);
|
ptr = Structure.add(FreeChunkHolder.class, ptr, 1);
|
||||||
|
@ -790,7 +787,8 @@ public final class GC {
|
||||||
if (shouldRelocateObject) {
|
if (shouldRelocateObject) {
|
||||||
while (true) {
|
while (true) {
|
||||||
nextRelocationTarget = relocationTarget.add(size);
|
nextRelocationTarget = relocationTarget.add(size);
|
||||||
if (!relocationBlock.end.isLessThan(nextRelocationTarget.add(GC_OBJECT_GAP))) {
|
if (nextRelocationTarget == relocationBlock.end
|
||||||
|
|| nextRelocationTarget.add(MIN_CHUNK_SIZE - 1).isLessThan(relocationBlock.end)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user