mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Wasm: fix issue with attempt to shrink heap after GC
This commit is contained in:
parent
64ae44ee01
commit
df98b411d0
|
@ -39,6 +39,7 @@ public class GCIntrinsic implements Intrinsic {
|
||||||
case "resizeHeap":
|
case "resizeHeap":
|
||||||
case "cardTable":
|
case "cardTable":
|
||||||
case "writeBarrier":
|
case "writeBarrier":
|
||||||
|
case "canShrinkHeap":
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -60,6 +61,10 @@ public class GCIntrinsic implements Intrinsic {
|
||||||
context.writer().print(")");
|
context.writer().print(")");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "canShrinkHeap":
|
||||||
|
context.writer().print("1");
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
context.includes().includePath("heaptrace.h");
|
context.includes().includePath("heaptrace.h");
|
||||||
context.writer().print("teavm_gc_").print(invocation.getMethod().getName());
|
context.writer().print("teavm_gc_").print(invocation.getMethod().getName());
|
||||||
|
|
|
@ -72,6 +72,7 @@ public class GCIntrinsic implements WasmIntrinsic {
|
||||||
case "maxAvailableBytes":
|
case "maxAvailableBytes":
|
||||||
case "resizeHeap":
|
case "resizeHeap":
|
||||||
case "writeBarrier":
|
case "writeBarrier":
|
||||||
|
case "canShrinkHeap":
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -131,6 +132,12 @@ public class GCIntrinsic implements WasmIntrinsic {
|
||||||
cardIndex);
|
cardIndex);
|
||||||
return new WasmStoreInt32(1, card, new WasmInt32Constant(0), WasmInt32Subtype.INT8);
|
return new WasmStoreInt32(1, card, new WasmInt32Constant(0), WasmInt32Subtype.INT8);
|
||||||
}
|
}
|
||||||
|
case "canShrinkHeap": {
|
||||||
|
var expr = new WasmInt32Constant(0);
|
||||||
|
expr.setLocation(invocation.getLocation());
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException(invocation.getMethod().toString());
|
throw new IllegalArgumentException(invocation.getMethod().toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,8 @@ public final class GC {
|
||||||
|
|
||||||
public static native void resizeHeap(long size);
|
public static native void resizeHeap(long size);
|
||||||
|
|
||||||
|
public static native boolean canShrinkHeap();
|
||||||
|
|
||||||
private static native int regionSize();
|
private static native int regionSize();
|
||||||
|
|
||||||
public static native void writeBarrier(RuntimeObject object);
|
public static native void writeBarrier(RuntimeObject object);
|
||||||
|
@ -183,7 +185,8 @@ public final class GC {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFullGC) {
|
if (!isFullGC) {
|
||||||
if (++youngGCCount >= 8 && isAboutToExpand(minRequestedSize)) {
|
var youngGCLimit = canShrinkHeap() ? 2 : 8;
|
||||||
|
if (++youngGCCount >= youngGCLimit && isAboutToExpand(minRequestedSize)) {
|
||||||
triggerFullGC();
|
triggerFullGC();
|
||||||
doCollectGarbage();
|
doCollectGarbage();
|
||||||
youngGCCount = 0;
|
youngGCCount = 0;
|
||||||
|
@ -1387,7 +1390,7 @@ public final class GC {
|
||||||
freeChunks++;
|
freeChunks++;
|
||||||
totalChunks++;
|
totalChunks++;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (canShrinkHeap()) {
|
||||||
long minimumSize = lastChunk.toAddress().toLong() - heapAddress().toLong();
|
long minimumSize = lastChunk.toAddress().toLong() - heapAddress().toLong();
|
||||||
if (lastChunk.classReference != 0) {
|
if (lastChunk.classReference != 0) {
|
||||||
minimumSize += objectSize(lastChunk);
|
minimumSize += objectSize(lastChunk);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user