WASM: bugfixes

This commit is contained in:
Alexey Andreev 2019-10-01 14:52:28 +03:00
parent e23293a8af
commit ae896f3d90
3 changed files with 14 additions and 4 deletions

View File

@ -256,9 +256,11 @@ public final class WasmRuntime {
}
public static Address allocStack(int size) {
Address result = WasmHeap.stack.add(4);
WasmHeap.stack = result.add((size << 2) + 4);
WasmHeap.stack.putInt(size);
Address stack = WasmHeap.stack;
Address result = stack.add(4);
stack = result.add((size << 2) + 4);
stack.putInt(size);
WasmHeap.stack = stack;
return result;
}

View File

@ -152,6 +152,11 @@ import org.teavm.vm.spi.TeaVMHostExtension;
public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
private static final MethodReference INIT_HEAP_REF = new MethodReference(WasmHeap.class, "initHeap",
Address.class, int.class, int.class, int.class, void.class);
private static final MethodReference RESIZE_HEAP_REF = new MethodReference(WasmHeap.class, "resizeHeap",
int.class, void.class);
private static final Set<MethodReference> VIRTUAL_METHODS = new HashSet<>(Arrays.asList(
new MethodReference(Object.class, "clone", Object.class)));
private TeaVMTargetController controller;
private boolean debugging;
private boolean wastEmitted;
@ -173,6 +178,8 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
classInitializerEliminator = new ClassInitializerEliminator(controller.getUnprocessedClassSource());
classInitializerTransformer = new ClassInitializerTransformer();
shadowStackTransformer = new ShadowStackTransformer(managedMethodRepository, true);
controller.addVirtualMethods(VIRTUAL_METHODS::contains);
}
@Override
@ -291,6 +298,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
void.class)).use();
dependencyAnalyzer.linkMethod(INIT_HEAP_REF).use();
dependencyAnalyzer.linkMethod(RESIZE_HEAP_REF).use();
dependencyAnalyzer.linkMethod(new MethodReference(Allocator.class, "allocate",
RuntimeClass.class, Address.class)).use();

View File

@ -37,7 +37,7 @@ public class GCIntrinsic implements WasmIntrinsic {
private static final MethodReference PRINT_OUT_OF_MEMORY = new MethodReference(
WasmRuntime.class, "printOutOfMemory", void.class);
private static final MethodReference RESIZE_HEAP = new MethodReference(
WasmHeap.class, "printOutOfMemory", void.class);
WasmHeap.class, "resizeHeap", int.class, void.class);
private List<WasmInt32Constant> regionSizeExpressions = new ArrayList<>();
public void setRegionSize(int regionSize) {