From ae896f3d90609ccd5607c4e34d979b576476195e Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 1 Oct 2019 14:52:28 +0300 Subject: [PATCH] WASM: bugfixes --- .../src/main/java/org/teavm/backend/wasm/WasmRuntime.java | 8 +++++--- core/src/main/java/org/teavm/backend/wasm/WasmTarget.java | 8 ++++++++ .../org/teavm/backend/wasm/intrinsics/GCIntrinsic.java | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmRuntime.java b/core/src/main/java/org/teavm/backend/wasm/WasmRuntime.java index 84b77db4d..0ba488755 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmRuntime.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmRuntime.java @@ -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; } diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java index 9ea1c769e..3645f846d 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java @@ -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 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(); diff --git a/core/src/main/java/org/teavm/backend/wasm/intrinsics/GCIntrinsic.java b/core/src/main/java/org/teavm/backend/wasm/intrinsics/GCIntrinsic.java index e64b2a452..3ec7ea0e7 100644 --- a/core/src/main/java/org/teavm/backend/wasm/intrinsics/GCIntrinsic.java +++ b/core/src/main/java/org/teavm/backend/wasm/intrinsics/GCIntrinsic.java @@ -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 regionSizeExpressions = new ArrayList<>(); public void setRegionSize(int regionSize) {