mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Fix bugs in GC and runtime
This commit is contained in:
parent
de299dda48
commit
67098a60ef
|
@ -23,6 +23,7 @@ import org.teavm.dependency.PluggableDependency;
|
||||||
import org.teavm.backend.javascript.spi.GeneratedBy;
|
import org.teavm.backend.javascript.spi.GeneratedBy;
|
||||||
import org.teavm.interop.Address;
|
import org.teavm.interop.Address;
|
||||||
import org.teavm.interop.DelegateTo;
|
import org.teavm.interop.DelegateTo;
|
||||||
|
import org.teavm.interop.Import;
|
||||||
import org.teavm.interop.NoGC;
|
import org.teavm.interop.NoGC;
|
||||||
import org.teavm.interop.Structure;
|
import org.teavm.interop.Structure;
|
||||||
import org.teavm.runtime.Allocator;
|
import org.teavm.runtime.Allocator;
|
||||||
|
@ -98,8 +99,16 @@ public final class TSystem extends TObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GeneratedBy(SystemNativeGenerator.class)
|
@GeneratedBy(SystemNativeGenerator.class)
|
||||||
|
@DelegateTo(("currentTimeMillisLowLevel"))
|
||||||
public static native long currentTimeMillis();
|
public static native long currentTimeMillis();
|
||||||
|
|
||||||
|
private static long currentTimeMillisLowLevel() {
|
||||||
|
return (long) currentTimeMillisImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Import(name = "currentTimeMillis", module = "runtime")
|
||||||
|
private static native double currentTimeMillisImpl();
|
||||||
|
|
||||||
public static TString getProperty(@SuppressWarnings("unused") TString key) {
|
public static TString getProperty(@SuppressWarnings("unused") TString key) {
|
||||||
// TODO: make implementation
|
// TODO: make implementation
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.wasm;
|
package org.teavm.backend.wasm;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -36,9 +37,33 @@ public final class Example {
|
||||||
testArrayCopy();
|
testArrayCopy();
|
||||||
testArrayIsObject();
|
testArrayIsObject();
|
||||||
testIsAssignableFrom();
|
testIsAssignableFrom();
|
||||||
|
testBigInteger();
|
||||||
testGC();
|
testGC();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void testBigInteger() {
|
||||||
|
BigInteger result = BigInteger.ONE;
|
||||||
|
for (int j = 0; j < 100; ++j) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
|
for (int k = 0; k < 5000; ++k) {
|
||||||
|
BigInteger a = BigInteger.ZERO;
|
||||||
|
BigInteger b = BigInteger.ONE;
|
||||||
|
for (int i = 0; i < 1000; ++i) {
|
||||||
|
BigInteger c = a.add(b);
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
}
|
||||||
|
result = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
|
||||||
|
println("Operation took " + (end - start) + " milliseconds");
|
||||||
|
}
|
||||||
|
println(result.toString());
|
||||||
|
}
|
||||||
|
|
||||||
private static void testFibonacci() {
|
private static void testFibonacci() {
|
||||||
int a = 0;
|
int a = 0;
|
||||||
int b = 1;
|
int b = 1;
|
||||||
|
|
|
@ -163,14 +163,14 @@ public class BinaryWriter {
|
||||||
|
|
||||||
private int writeLong(int offset, byte[] result, long v) {
|
private int writeLong(int offset, byte[] result, long v) {
|
||||||
offset = align(offset, 8);
|
offset = align(offset, 8);
|
||||||
result[offset++] = (byte) (v >> 56);
|
|
||||||
result[offset++] = (byte) (v >> 48);
|
|
||||||
result[offset++] = (byte) (v >> 40);
|
|
||||||
result[offset++] = (byte) (v >> 32);
|
|
||||||
result[offset++] = (byte) (v >> 24);
|
|
||||||
result[offset++] = (byte) (v >> 16);
|
|
||||||
result[offset++] = (byte) (v >> 8);
|
|
||||||
result[offset++] = (byte) v;
|
result[offset++] = (byte) v;
|
||||||
|
result[offset++] = (byte) (v >> 8);
|
||||||
|
result[offset++] = (byte) (v >> 16);
|
||||||
|
result[offset++] = (byte) (v >> 24);
|
||||||
|
result[offset++] = (byte) (v >> 32);
|
||||||
|
result[offset++] = (byte) (v >> 40);
|
||||||
|
result[offset++] = (byte) (v >> 48);
|
||||||
|
result[offset++] = (byte) (v >> 56);
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class WasmGenerator {
|
||||||
WasmType paramType = WasmGeneratorUtil.mapType(methodReference.parameterType(i));
|
WasmType paramType = WasmGeneratorUtil.mapType(methodReference.parameterType(i));
|
||||||
function.getParameters().add(paramType);
|
function.getParameters().add(paramType);
|
||||||
}
|
}
|
||||||
|
function.setResult(WasmGeneratorUtil.mapType(methodReference.getReturnType()));
|
||||||
|
|
||||||
WasmGenerationContext.ImportedMethod importedMethod = context.getImportedMethod(methodReference);
|
WasmGenerationContext.ImportedMethod importedMethod = context.getImportedMethod(methodReference);
|
||||||
if (importedMethod != null) {
|
if (importedMethod != null) {
|
||||||
|
|
|
@ -59,15 +59,18 @@ public final class GC {
|
||||||
public static RuntimeObject alloc(int size) {
|
public static RuntimeObject alloc(int size) {
|
||||||
FreeChunk current = currentChunk;
|
FreeChunk current = currentChunk;
|
||||||
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)).isLessThan(currentChunkLimit)) {
|
||||||
getAvailableChunk(size);
|
getAvailableChunk(size);
|
||||||
current = currentChunk;
|
current = currentChunk;
|
||||||
next = currentChunk.toAddress().add(size);
|
next = currentChunk.toAddress().add(size);
|
||||||
}
|
}
|
||||||
int oldSize = current.size;
|
int freeSize = current.size;
|
||||||
currentChunk = next.toStructure();
|
currentChunk = next.toStructure();
|
||||||
currentChunk.classReference = 0;
|
freeSize -= size;
|
||||||
currentChunk.size = oldSize - size;
|
if (freeSize > 0) {
|
||||||
|
currentChunk.classReference = 0;
|
||||||
|
currentChunk.size = freeSize;
|
||||||
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +83,13 @@ public final class GC {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getAvailableChunkIfPossible(int size) {
|
private static boolean getAvailableChunkIfPossible(int size) {
|
||||||
while (!currentChunk.toAddress().add(size).isLessThan(currentChunkLimit)) {
|
while (true) {
|
||||||
|
if (currentChunk.toAddress().add(size) == currentChunkLimit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (currentChunk.toAddress().add(size + Structure.sizeOf(FreeChunk.class)).isLessThan(currentChunkLimit)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (--freeChunks == 0) {
|
if (--freeChunks == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -104,10 +113,11 @@ public final class GC {
|
||||||
int staticCount = staticRoots.getInt();
|
int staticCount = staticRoots.getInt();
|
||||||
staticRoots.add(8);
|
staticRoots.add(8);
|
||||||
while (staticCount-- > 0) {
|
while (staticCount-- > 0) {
|
||||||
RuntimeObject object = staticRoots.getAddress().toStructure();
|
RuntimeObject object = staticRoots.getAddress().getAddress().toStructure();
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
mark(object);
|
mark(object);
|
||||||
}
|
}
|
||||||
|
staticRoots = staticRoots.add(Address.sizeOf());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Address stackRoots = Mutator.getStackGcRoots(); stackRoots != null;
|
for (Address stackRoots = Mutator.getStackGcRoots(); stackRoots != null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user