diff --git a/aot/src/main/java/com/dylibso/chicory/aot/AotEmitters.java b/aot/src/main/java/com/dylibso/chicory/aot/AotEmitters.java index 741a345b2..cd29ae251 100644 --- a/aot/src/main/java/com/dylibso/chicory/aot/AotEmitters.java +++ b/aot/src/main/java/com/dylibso/chicory/aot/AotEmitters.java @@ -34,6 +34,7 @@ import static com.dylibso.chicory.aot.AotUtil.StackSize; import static com.dylibso.chicory.aot.AotUtil.callIndirectMethodName; import static com.dylibso.chicory.aot.AotUtil.callIndirectMethodType; +import static com.dylibso.chicory.aot.AotUtil.emitInvokeFunction; import static com.dylibso.chicory.aot.AotUtil.emitInvokeStatic; import static com.dylibso.chicory.aot.AotUtil.emitInvokeVirtual; import static com.dylibso.chicory.aot.AotUtil.emitJvmToLong; @@ -42,8 +43,6 @@ import static com.dylibso.chicory.aot.AotUtil.jvmType; import static com.dylibso.chicory.aot.AotUtil.loadTypeOpcode; import static com.dylibso.chicory.aot.AotUtil.localType; -import static com.dylibso.chicory.aot.AotUtil.methodNameFor; -import static com.dylibso.chicory.aot.AotUtil.methodTypeFor; import static com.dylibso.chicory.aot.AotUtil.stackSize; import static com.dylibso.chicory.aot.AotUtil.storeTypeOpcode; import static com.dylibso.chicory.aot.AotUtil.validateArgumentType; @@ -54,7 +53,6 @@ import com.dylibso.chicory.wasm.types.FunctionType; import com.dylibso.chicory.wasm.types.OpCode; import com.dylibso.chicory.wasm.types.ValueType; -import java.lang.invoke.MethodType; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Parameter; @@ -128,18 +126,12 @@ public static void SELECT(AotContext ctx, AnnotatedInstruction ins, MethodVisito public static void CALL(AotContext ctx, AnnotatedInstruction ins, MethodVisitor asm) { int funcId = (int) ins.operand(0); FunctionType functionType = ctx.functionTypes().get(funcId); - MethodType methodType = methodTypeFor(functionType); emitInvokeStatic(asm, CHECK_INTERRUPTION); asm.visitVarInsn(Opcodes.ALOAD, ctx.memorySlot()); asm.visitVarInsn(Opcodes.ALOAD, ctx.instanceSlot()); - asm.visitMethodInsn( - Opcodes.INVOKESTATIC, - ctx.internalClassName(), - methodNameFor(funcId), - methodType.toMethodDescriptorString(), - false); + emitInvokeFunction(asm, ctx.internalClassName(), funcId, functionType); if (functionType.returns().size() > 1) { emitUnboxResult(asm, ctx, functionType.returns()); @@ -153,17 +145,16 @@ public static void CALL_INDIRECT(AotContext ctx, AnnotatedInstruction ins, Metho int tableIdx = (int) ins.operand(1); FunctionType functionType = ctx.types()[typeId]; - MethodType methodType = callIndirectMethodType(functionType); - asm.visitLdcInsn(tableIdx); + asm.visitVarInsn(Opcodes.ALOAD, ctx.memorySlot()); asm.visitVarInsn(Opcodes.ALOAD, ctx.instanceSlot()); - // stack: arguments, funcTableIdx, tableIdx, instance + // stack: arguments, funcTableIdx, tableIdx, memory, instance asm.visitMethodInsn( Opcodes.INVOKESTATIC, ctx.internalClassName(), callIndirectMethodName(typeId), - methodType.toMethodDescriptorString(), + callIndirectMethodType(functionType).toMethodDescriptorString(), false); if (functionType.returns().size() > 1) { diff --git a/aot/src/main/java/com/dylibso/chicory/aot/AotMachine.java b/aot/src/main/java/com/dylibso/chicory/aot/AotMachine.java index 6a391b66e..06d62d950 100644 --- a/aot/src/main/java/com/dylibso/chicory/aot/AotMachine.java +++ b/aot/src/main/java/com/dylibso/chicory/aot/AotMachine.java @@ -2,10 +2,15 @@ import static com.dylibso.chicory.aot.AotMethods.CHECK_INTERRUPTION; import static com.dylibso.chicory.aot.AotMethods.INSTANCE_CALL_HOST_FUNCTION; +import static com.dylibso.chicory.aot.AotMethods.INSTANCE_TABLE; +import static com.dylibso.chicory.aot.AotMethods.TABLE_INSTANCE; +import static com.dylibso.chicory.aot.AotMethods.TABLE_REF; +import static com.dylibso.chicory.aot.AotMethods.THROW_INDIRECT_CALL_TYPE_MISMATCH; import static com.dylibso.chicory.aot.AotMethods.THROW_TRAP_EXCEPTION; import static com.dylibso.chicory.aot.AotUtil.callIndirectMethodName; import static com.dylibso.chicory.aot.AotUtil.callIndirectMethodType; import static com.dylibso.chicory.aot.AotUtil.defaultValue; +import static com.dylibso.chicory.aot.AotUtil.emitInvokeFunction; import static com.dylibso.chicory.aot.AotUtil.emitInvokeStatic; import static com.dylibso.chicory.aot.AotUtil.emitInvokeVirtual; import static com.dylibso.chicory.aot.AotUtil.emitJvmToLong; @@ -57,6 +62,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; import java.util.ArrayDeque; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -444,7 +450,7 @@ private byte[] compileClass(String className, FunctionSection functions) { classWriter, callIndirectMethodName(typeId), callIndirectMethodType(type), - asm -> compileCallIndirect(asm, typeId, type)); + asm -> compileCallIndirect(internalClassName, typeId, type, asm)); } var returnTypes = @@ -560,15 +566,95 @@ private static void emitConstructor(ClassVisitor writer) { cons.visitEnd(); } - private static void compileCallIndirect(MethodVisitor asm, int typeId, FunctionType type) { - int slot = type.params().stream().mapToInt(AotUtil::slotCount).sum(); + private void compileCallIndirect( + String internalClassName, int typeId, FunctionType type, MethodVisitor asm) { + int slots = type.params().stream().mapToInt(AotUtil::slotCount).sum(); + int funcTableIdx = slots; + int tableIdx = slots + 1; + int memory = slots + 2; + int instance = slots + 3; + int table = slots + 4; + int funcId = slots + 5; + int refInstance = slots + 6; + + emitInvokeStatic(asm, CHECK_INTERRUPTION); + + // TableInstance table = instance.table(tableIdx); + asm.visitVarInsn(Opcodes.ALOAD, instance); + asm.visitVarInsn(Opcodes.ILOAD, tableIdx); + emitInvokeVirtual(asm, INSTANCE_TABLE); + asm.visitVarInsn(Opcodes.ASTORE, table); + + // int funcId = table.ref(funcTableIdx); + // if (funcId == REF_NULL_VALUE) throw new ChicoryException(...); + asm.visitVarInsn(Opcodes.ALOAD, table); + asm.visitVarInsn(Opcodes.ILOAD, funcTableIdx); + emitInvokeStatic(asm, TABLE_REF); + asm.visitVarInsn(Opcodes.ISTORE, funcId); + + // Instance refInstance = table.instance(funcTableIdx); + asm.visitVarInsn(Opcodes.ALOAD, table); + asm.visitVarInsn(Opcodes.ILOAD, funcTableIdx); + emitInvokeVirtual(asm, TABLE_INSTANCE); + asm.visitVarInsn(Opcodes.ASTORE, refInstance); + + Label local = new Label(); + Label other = new Label(); + + // if (refInstance == null || refInstance == instance) + asm.visitVarInsn(Opcodes.ALOAD, refInstance); + asm.visitJumpInsn(Opcodes.IFNULL, local); + asm.visitVarInsn(Opcodes.ALOAD, refInstance); + asm.visitVarInsn(Opcodes.ALOAD, instance); + asm.visitJumpInsn(Opcodes.IF_ACMPNE, other); + + // local: call function in this module + asm.visitLabel(local); + + System.out.println("compiling " + callIndirectMethodName(typeId) + ": " + type); + int slot = 0; + for (ValueType param : type.params()) { + asm.visitVarInsn(loadTypeOpcode(param), slot); + slot += slotCount(param); + } + asm.visitVarInsn(Opcodes.ALOAD, memory); + asm.visitVarInsn(Opcodes.ALOAD, instance); + + List validIds = new ArrayList<>(); + for (int i = 0; i < functionTypes.size(); i++) { + if (type.equals(functionTypes.get(i))) { + validIds.add(i); + } + } + + Label invalid = new Label(); + int[] keys = validIds.stream().mapToInt(x -> x).toArray(); + Label[] labels = validIds.stream().map(x -> new Label()).toArray(Label[]::new); + + asm.visitVarInsn(Opcodes.ILOAD, funcId); + asm.visitLookupSwitchInsn(invalid, keys, labels); + + Label done = new Label(); + for (int i = 0; i < validIds.size(); i++) { + asm.visitLabel(labels[i]); + emitInvokeFunction(asm, internalClassName, keys[i], type); + asm.visitJumpInsn(Opcodes.GOTO, done); + } + + asm.visitLabel(invalid); + emitInvokeStatic(asm, THROW_INDIRECT_CALL_TYPE_MISMATCH); + asm.visitInsn(Opcodes.ATHROW); + + asm.visitLabel(done); + asm.visitInsn(returnTypeOpcode(type)); + + // other: call function in another module + asm.visitLabel(other); - // parameters: arguments, funcTableIdx, tableIdx, instance emitBoxArguments(asm, type.params()); asm.visitLdcInsn(typeId); - asm.visitVarInsn(Opcodes.ILOAD, slot); // funcTableIdx - asm.visitVarInsn(Opcodes.ILOAD, slot + 1); // tableIdx - asm.visitVarInsn(Opcodes.ALOAD, slot + 2); // instance + asm.visitVarInsn(Opcodes.ILOAD, funcId); + asm.visitVarInsn(Opcodes.ALOAD, refInstance); emitInvokeStatic(asm, AotMethods.CALL_INDIRECT); diff --git a/aot/src/main/java/com/dylibso/chicory/aot/AotMethods.java b/aot/src/main/java/com/dylibso/chicory/aot/AotMethods.java index dc50fb633..469c19ff4 100644 --- a/aot/src/main/java/com/dylibso/chicory/aot/AotMethods.java +++ b/aot/src/main/java/com/dylibso/chicory/aot/AotMethods.java @@ -1,7 +1,6 @@ package com.dylibso.chicory.aot; import static com.dylibso.chicory.wasm.types.Value.REF_NULL_VALUE; -import static java.util.Objects.requireNonNullElse; import com.dylibso.chicory.runtime.Instance; import com.dylibso.chicory.runtime.Memory; @@ -23,6 +22,7 @@ public final class AotMethods { static final Method INSTANCE_READ_GLOBAL; static final Method WRITE_GLOBAL; static final Method INSTANCE_SET_ELEMENT; + static final Method INSTANCE_TABLE; static final Method MEMORY_COPY; static final Method MEMORY_FILL; static final Method MEMORY_INIT; @@ -49,7 +49,10 @@ public final class AotMethods { static final Method TABLE_FILL; static final Method TABLE_COPY; static final Method TABLE_INIT; + static final Method TABLE_REF; + static final Method TABLE_INSTANCE; static final Method VALIDATE_BASE; + static final Method THROW_INDIRECT_CALL_TYPE_MISMATCH; static final Method THROW_OUT_OF_BOUNDS_MEMORY_ACCESS; static final Method THROW_TRAP_EXCEPTION; @@ -58,12 +61,7 @@ public final class AotMethods { CHECK_INTERRUPTION = AotMethods.class.getMethod("checkInterruption"); CALL_INDIRECT = AotMethods.class.getMethod( - "callIndirect", - long[].class, - int.class, - int.class, - int.class, - Instance.class); + "callIndirect", long[].class, int.class, int.class, Instance.class); INSTANCE_CALL_HOST_FUNCTION = Instance.class.getMethod("callHostFunction", int.class, long[].class); INSTANCE_READ_GLOBAL = Instance.class.getMethod("readGlobal", int.class); @@ -71,6 +69,7 @@ public final class AotMethods { AotMethods.class.getMethod( "writeGlobal", long.class, int.class, Instance.class); INSTANCE_SET_ELEMENT = Instance.class.getMethod("setElement", int.class, Element.class); + INSTANCE_TABLE = Instance.class.getMethod("table", int.class); MEMORY_COPY = AotMethods.class.getMethod( "memoryCopy", int.class, int.class, int.class, Memory.class); @@ -154,7 +153,11 @@ public final class AotMethods { int.class, int.class, Instance.class); + TABLE_REF = AotMethods.class.getMethod("tableRef", TableInstance.class, int.class); + TABLE_INSTANCE = TableInstance.class.getMethod("instance", int.class); VALIDATE_BASE = AotMethods.class.getMethod("validateBase", int.class); + THROW_INDIRECT_CALL_TYPE_MISMATCH = + AotMethods.class.getMethod("throwIndirectCallTypeMismatch"); THROW_OUT_OF_BOUNDS_MEMORY_ACCESS = AotMethods.class.getMethod("throwOutOfBoundsMemoryAccess"); THROW_TRAP_EXCEPTION = AotMethods.class.getMethod("throwTrapException"); @@ -166,24 +169,12 @@ public final class AotMethods { private AotMethods() {} @UsedByGeneratedCode - public static long[] callIndirect( - long[] args, int typeId, int funcTableIdx, int tableIdx, Instance instance) { - TableInstance table = instance.table(tableIdx); - - instance = requireNonNullElse(table.instance(funcTableIdx), instance); - - int funcId = table.ref(funcTableIdx); - if (funcId == REF_NULL_VALUE) { - throw new ChicoryException("uninitialized element " + funcTableIdx); - } - + public static long[] callIndirect(long[] args, int typeId, int funcId, Instance instance) { FunctionType expectedType = instance.type(typeId); FunctionType actualType = instance.type(instance.functionType(funcId)); if (!actualType.typesMatch(expectedType)) { - throw new ChicoryException("indirect call type mismatch"); + throw throwIndirectCallTypeMismatch(); } - - checkInterruption(); return instance.getMachine().call(funcId, args); } @@ -230,6 +221,15 @@ public static void tableInit( OpcodeImpl.TABLE_INIT(instance, tableidx, elementidx, size, elemidx, offset); } + @UsedByGeneratedCode + public static int tableRef(TableInstance table, int index) { + int funcId = table.ref(index); + if (funcId == REF_NULL_VALUE) { + throw new ChicoryException("uninitialized element " + index); + } + return funcId; + } + @UsedByGeneratedCode public static void memoryCopy(int destination, int offset, int size, Memory memory) { memory.copy(destination, offset, size); @@ -326,6 +326,11 @@ public static void validateBase(int base) { } } + @UsedByGeneratedCode + public static ChicoryException throwIndirectCallTypeMismatch() { + return new ChicoryException("indirect call type mismatch"); + } + @UsedByGeneratedCode public static RuntimeException throwOutOfBoundsMemoryAccess() { throw new WASMRuntimeException("out of bounds memory access"); diff --git a/aot/src/main/java/com/dylibso/chicory/aot/AotUtil.java b/aot/src/main/java/com/dylibso/chicory/aot/AotUtil.java index 2df3ef63f..a2a95f9b6 100644 --- a/aot/src/main/java/com/dylibso/chicory/aot/AotUtil.java +++ b/aot/src/main/java/com/dylibso/chicory/aot/AotUtil.java @@ -201,7 +201,7 @@ public static MethodHandle jvmToLongHandle(ValueType type) { public static MethodType callIndirectMethodType(FunctionType functionType) { return rawMethodTypeFor(functionType) - .appendParameterTypes(int.class, int.class, Instance.class); + .appendParameterTypes(int.class, int.class, Memory.class, Instance.class); } public static MethodType methodTypeFor(FunctionType type) { @@ -319,6 +319,16 @@ public static void emitInvokeVirtual(MethodVisitor asm, Method method) { false); } + public static void emitInvokeFunction( + MethodVisitor asm, String internalClassName, int funcId, FunctionType functionType) { + asm.visitMethodInsn( + Opcodes.INVOKESTATIC, + internalClassName, + methodNameFor(funcId), + methodTypeFor(functionType).toMethodDescriptorString(), + false); + } + public static String methodNameFor(int funcId) { return "func_" + funcId; } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyBrTable.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyBrTable.approved.txt index b881bbdae..b5616232d 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyBrTable.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyBrTable.approved.txt @@ -57,7 +57,47 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 3 // access flags 0x9 - public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Instance;)I + public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 4 + ILOAD 2 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 5 + ALOAD 5 + ILOAD 1 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 6 + ALOAD 5 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 7 + ALOAD 7 + IFNULL L0 + ALOAD 7 + ALOAD 4 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ILOAD 0 + ALOAD 3 + ALOAD 4 + ILOAD 6 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (ILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + GOTO L4 + L3 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME1 I + IRETURN + L1 + FRAME SAME ICONST_1 NEWARRAY T_LONG DUP @@ -66,14 +106,13 @@ public final class com/dylibso/chicory/$gen/CompiledModule { I2L LASTORE ICONST_0 - ILOAD 1 - ILOAD 2 - ALOAD 3 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 6 + ALOAD 7 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J ICONST_0 LALOAD L2I IRETURN MAXSTACK = 5 - MAXLOCALS = 4 + MAXLOCALS = 8 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyBranching.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyBranching.approved.txt index c5634f1ef..dd2dfd0e5 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyBranching.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyBranching.approved.txt @@ -50,7 +50,47 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 4 // access flags 0x9 - public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Instance;)I + public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 4 + ILOAD 2 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 5 + ALOAD 5 + ILOAD 1 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 6 + ALOAD 5 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 7 + ALOAD 7 + IFNULL L0 + ALOAD 7 + ALOAD 4 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ILOAD 0 + ALOAD 3 + ALOAD 4 + ILOAD 6 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (ILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + GOTO L4 + L3 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME1 I + IRETURN + L1 + FRAME SAME ICONST_1 NEWARRAY T_LONG DUP @@ -59,14 +99,13 @@ public final class com/dylibso/chicory/$gen/CompiledModule { I2L LASTORE ICONST_0 - ILOAD 1 - ILOAD 2 - ALOAD 3 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 6 + ALOAD 7 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J ICONST_0 LALOAD L2I IRETURN MAXSTACK = 5 - MAXLOCALS = 4 + MAXLOCALS = 8 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyFloat.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyFloat.approved.txt index 1bf42c678..600c3e909 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyFloat.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyFloat.approved.txt @@ -24,15 +24,53 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 2 // access flags 0x9 - public static call_indirect_0(IILcom/dylibso/chicory/runtime/Instance;)V + public static call_indirect_0(IILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 3 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 4 + ALOAD 4 + ILOAD 0 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 5 + ALOAD 4 + ILOAD 0 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 6 + ALOAD 6 + IFNULL L0 + ALOAD 6 + ALOAD 3 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ALOAD 2 + ALOAD 3 + ILOAD 5 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (Lcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L4 + L3 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME + RETURN + L1 + FRAME SAME ICONST_0 NEWARRAY T_LONG ICONST_0 - ILOAD 0 - ILOAD 1 - ALOAD 2 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 5 + ALOAD 6 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J RETURN - MAXSTACK = 5 - MAXLOCALS = 3 + MAXSTACK = 4 + MAXLOCALS = 7 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyHelloWasi.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyHelloWasi.approved.txt index 3025330eb..e92dab3ec 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyHelloWasi.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyHelloWasi.approved.txt @@ -73,7 +73,50 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 2 // access flags 0x9 - public static call_indirect_0(IIIIIILcom/dylibso/chicory/runtime/Instance;)I + public static call_indirect_0(IIIIIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 7 + ILOAD 5 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 8 + ALOAD 8 + ILOAD 4 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 9 + ALOAD 8 + ILOAD 4 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 10 + ALOAD 10 + IFNULL L0 + ALOAD 10 + ALOAD 7 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ILOAD 0 + ILOAD 1 + ILOAD 2 + ILOAD 3 + ALOAD 6 + ALOAD 7 + ILOAD 9 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I I I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (IIIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + GOTO L4 + L3 + FRAME FULL [I I I I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME1 I + IRETURN + L1 + FRAME SAME ICONST_4 NEWARRAY T_LONG DUP @@ -97,27 +140,64 @@ public final class com/dylibso/chicory/$gen/CompiledModule { I2L LASTORE ICONST_0 - ILOAD 4 - ILOAD 5 - ALOAD 6 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 9 + ALOAD 10 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J ICONST_0 LALOAD L2I IRETURN - MAXSTACK = 5 - MAXLOCALS = 7 + MAXSTACK = 7 + MAXLOCALS = 11 // access flags 0x9 - public static call_indirect_1(IILcom/dylibso/chicory/runtime/Instance;)V + public static call_indirect_1(IILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 3 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 4 + ALOAD 4 + ILOAD 0 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 5 + ALOAD 4 + ILOAD 0 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 6 + ALOAD 6 + IFNULL L0 + ALOAD 6 + ALOAD 3 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ALOAD 2 + ALOAD 3 + ILOAD 5 + LOOKUPSWITCH + 1: L2 + default: L3 + L2 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_1 (Lcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L4 + L3 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME + RETURN + L1 + FRAME SAME ICONST_0 NEWARRAY T_LONG ICONST_1 - ILOAD 0 - ILOAD 1 - ALOAD 2 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 5 + ALOAD 6 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J RETURN - MAXSTACK = 5 - MAXLOCALS = 3 + MAXSTACK = 4 + MAXLOCALS = 7 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyI32.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyI32.approved.txt index 8853701ea..a9d6a5513 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyI32.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyI32.approved.txt @@ -48,15 +48,53 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 2 // access flags 0x9 - public static call_indirect_0(IILcom/dylibso/chicory/runtime/Instance;)V + public static call_indirect_0(IILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 3 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 4 + ALOAD 4 + ILOAD 0 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 5 + ALOAD 4 + ILOAD 0 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 6 + ALOAD 6 + IFNULL L0 + ALOAD 6 + ALOAD 3 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ALOAD 2 + ALOAD 3 + ILOAD 5 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (Lcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L4 + L3 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME + RETURN + L1 + FRAME SAME ICONST_0 NEWARRAY T_LONG ICONST_0 - ILOAD 0 - ILOAD 1 - ALOAD 2 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 5 + ALOAD 6 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J RETURN - MAXSTACK = 5 - MAXLOCALS = 3 + MAXSTACK = 4 + MAXLOCALS = 7 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyI32Renamed.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyI32Renamed.approved.txt index 161c6a6ac..b5d9e7496 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyI32Renamed.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyI32Renamed.approved.txt @@ -48,15 +48,53 @@ public final class FOO { MAXLOCALS = 2 // access flags 0x9 - public static call_indirect_0(IILcom/dylibso/chicory/runtime/Instance;)V + public static call_indirect_0(IILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 3 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 4 + ALOAD 4 + ILOAD 0 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 5 + ALOAD 4 + ILOAD 0 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 6 + ALOAD 6 + IFNULL L0 + ALOAD 6 + ALOAD 3 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ALOAD 2 + ALOAD 3 + ILOAD 5 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC FOO.func_0 (Lcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L4 + L3 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME + RETURN + L1 + FRAME SAME ICONST_0 NEWARRAY T_LONG ICONST_0 - ILOAD 0 - ILOAD 1 - ALOAD 2 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 5 + ALOAD 6 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J RETURN - MAXSTACK = 5 - MAXLOCALS = 3 + MAXSTACK = 4 + MAXLOCALS = 7 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyIterFact.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyIterFact.approved.txt index 6b6002f28..933dee87c 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyIterFact.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyIterFact.approved.txt @@ -49,7 +49,47 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 4 // access flags 0x9 - public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Instance;)I + public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 4 + ILOAD 2 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 5 + ALOAD 5 + ILOAD 1 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 6 + ALOAD 5 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 7 + ALOAD 7 + IFNULL L0 + ALOAD 7 + ALOAD 4 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ILOAD 0 + ALOAD 3 + ALOAD 4 + ILOAD 6 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (ILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + GOTO L4 + L3 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME1 I + IRETURN + L1 + FRAME SAME ICONST_1 NEWARRAY T_LONG DUP @@ -58,14 +98,13 @@ public final class com/dylibso/chicory/$gen/CompiledModule { I2L LASTORE ICONST_0 - ILOAD 1 - ILOAD 2 - ALOAD 3 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 6 + ALOAD 7 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J ICONST_0 LALOAD L2I IRETURN MAXSTACK = 5 - MAXLOCALS = 4 + MAXLOCALS = 8 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyKitchenSink.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyKitchenSink.approved.txt index 35b83c0b4..79545f466 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyKitchenSink.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyKitchenSink.approved.txt @@ -44,7 +44,47 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 3 // access flags 0x9 - public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Instance;)I + public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 4 + ILOAD 2 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 5 + ALOAD 5 + ILOAD 1 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 6 + ALOAD 5 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 7 + ALOAD 7 + IFNULL L0 + ALOAD 7 + ALOAD 4 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ILOAD 0 + ALOAD 3 + ALOAD 4 + ILOAD 6 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (ILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + GOTO L4 + L3 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME1 I + IRETURN + L1 + FRAME SAME ICONST_1 NEWARRAY T_LONG DUP @@ -53,14 +93,13 @@ public final class com/dylibso/chicory/$gen/CompiledModule { I2L LASTORE ICONST_0 - ILOAD 1 - ILOAD 2 - ALOAD 3 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 6 + ALOAD 7 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J ICONST_0 LALOAD L2I IRETURN MAXSTACK = 5 - MAXLOCALS = 4 + MAXLOCALS = 8 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyMemory.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyMemory.approved.txt index f166d4abf..b7fb63987 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyMemory.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyMemory.approved.txt @@ -50,7 +50,47 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 4 // access flags 0x9 - public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Instance;)I + public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 4 + ILOAD 2 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 5 + ALOAD 5 + ILOAD 1 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 6 + ALOAD 5 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 7 + ALOAD 7 + IFNULL L0 + ALOAD 7 + ALOAD 4 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ILOAD 0 + ALOAD 3 + ALOAD 4 + ILOAD 6 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (ILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)I + GOTO L4 + L3 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME1 I + IRETURN + L1 + FRAME SAME ICONST_1 NEWARRAY T_LONG DUP @@ -59,19 +99,58 @@ public final class com/dylibso/chicory/$gen/CompiledModule { I2L LASTORE ICONST_0 - ILOAD 1 - ILOAD 2 - ALOAD 3 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 6 + ALOAD 7 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J ICONST_0 LALOAD L2I IRETURN MAXSTACK = 5 - MAXLOCALS = 4 + MAXLOCALS = 8 // access flags 0x9 - public static call_indirect_1(JIILcom/dylibso/chicory/runtime/Instance;)J + public static call_indirect_1(JIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)J + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 5 + ILOAD 3 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 6 + ALOAD 6 + ILOAD 2 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 7 + ALOAD 6 + ILOAD 2 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 8 + ALOAD 8 + IFNULL L0 + ALOAD 8 + ALOAD 5 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + LLOAD 0 + ALOAD 4 + ALOAD 5 + ILOAD 7 + LOOKUPSWITCH + 1: L2 + default: L3 + L2 + FRAME FULL [J I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [J com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_1 (JLcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)J + GOTO L4 + L3 + FRAME FULL [J I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [J com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME1 J + LRETURN + L1 + FRAME SAME ICONST_1 NEWARRAY T_LONG DUP @@ -79,13 +158,12 @@ public final class com/dylibso/chicory/$gen/CompiledModule { LLOAD 0 LASTORE ICONST_1 - ILOAD 2 - ILOAD 3 - ALOAD 4 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 7 + ALOAD 8 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J ICONST_0 LALOAD LRETURN MAXSTACK = 5 - MAXLOCALS = 5 + MAXLOCALS = 9 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyStart.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyStart.approved.txt index 2440aac35..8634ab1d2 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyStart.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyStart.approved.txt @@ -41,7 +41,47 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 2 // access flags 0x9 - public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Instance;)V + public static call_indirect_0(IIILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 4 + ILOAD 2 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 5 + ALOAD 5 + ILOAD 1 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 6 + ALOAD 5 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 7 + ALOAD 7 + IFNULL L0 + ALOAD 7 + ALOAD 4 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ILOAD 0 + ALOAD 3 + ALOAD 4 + ILOAD 6 + LOOKUPSWITCH + 0: L2 + default: L3 + L2 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (ILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L4 + L3 + FRAME FULL [I I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME + RETURN + L1 + FRAME SAME ICONST_1 NEWARRAY T_LONG DUP @@ -50,24 +90,61 @@ public final class com/dylibso/chicory/$gen/CompiledModule { I2L LASTORE ICONST_0 - ILOAD 1 - ILOAD 2 - ALOAD 3 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 6 + ALOAD 7 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J RETURN MAXSTACK = 5 - MAXLOCALS = 4 + MAXLOCALS = 8 // access flags 0x9 - public static call_indirect_1(IILcom/dylibso/chicory/runtime/Instance;)V + public static call_indirect_1(IILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 3 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 4 + ALOAD 4 + ILOAD 0 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 5 + ALOAD 4 + ILOAD 0 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 6 + ALOAD 6 + IFNULL L0 + ALOAD 6 + ALOAD 3 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ALOAD 2 + ALOAD 3 + ILOAD 5 + LOOKUPSWITCH + 1: L2 + default: L3 + L2 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_1 (Lcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L4 + L3 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L4 + FRAME SAME + RETURN + L1 + FRAME SAME ICONST_0 NEWARRAY T_LONG ICONST_1 - ILOAD 0 - ILOAD 1 - ALOAD 2 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 5 + ALOAD 6 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J RETURN - MAXSTACK = 5 - MAXLOCALS = 3 + MAXSTACK = 4 + MAXLOCALS = 7 } diff --git a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyTrap.approved.txt b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyTrap.approved.txt index 68321dc5b..58a0700b3 100644 --- a/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyTrap.approved.txt +++ b/aot/src/test/resources/com/dylibso/chicory/approvals/ApprovalTest.verifyTrap.approved.txt @@ -44,15 +44,63 @@ public final class com/dylibso/chicory/$gen/CompiledModule { MAXLOCALS = 2 // access flags 0x9 - public static call_indirect_0(IILcom/dylibso/chicory/runtime/Instance;)V + public static call_indirect_0(IILcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.checkInterruption ()V + ALOAD 3 + ILOAD 1 + INVOKEVIRTUAL com/dylibso/chicory/runtime/Instance.table (I)Lcom/dylibso/chicory/runtime/TableInstance; + ASTORE 4 + ALOAD 4 + ILOAD 0 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.tableRef (Lcom/dylibso/chicory/runtime/TableInstance;I)I + ISTORE 5 + ALOAD 4 + ILOAD 0 + INVOKEVIRTUAL com/dylibso/chicory/runtime/TableInstance.instance (I)Lcom/dylibso/chicory/runtime/Instance; + ASTORE 6 + ALOAD 6 + IFNULL L0 + ALOAD 6 + ALOAD 3 + IF_ACMPNE L1 + L0 + FRAME APPEND [com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] + ALOAD 2 + ALOAD 3 + ILOAD 5 + LOOKUPSWITCH + 0: L2 + 1: L3 + 2: L4 + default: L5 + L2 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_0 (Lcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L6 + L3 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_1 (Lcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L6 + L4 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/$gen/CompiledModule.func_2 (Lcom/dylibso/chicory/runtime/Memory;Lcom/dylibso/chicory/runtime/Instance;)V + GOTO L6 + L5 + FRAME FULL [I I com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance com/dylibso/chicory/runtime/TableInstance I com/dylibso/chicory/runtime/Instance] [com/dylibso/chicory/runtime/Memory com/dylibso/chicory/runtime/Instance] + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.throwIndirectCallTypeMismatch ()Lcom/dylibso/chicory/wasm/exceptions/ChicoryException; + ATHROW + L6 + FRAME SAME + RETURN + L1 + FRAME SAME ICONST_0 NEWARRAY T_LONG ICONST_0 - ILOAD 0 - ILOAD 1 - ALOAD 2 - INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIIILcom/dylibso/chicory/runtime/Instance;)[J + ILOAD 5 + ALOAD 6 + INVOKESTATIC com/dylibso/chicory/aot/AotMethods.callIndirect ([JIILcom/dylibso/chicory/runtime/Instance;)[J RETURN - MAXSTACK = 5 - MAXLOCALS = 3 + MAXSTACK = 4 + MAXLOCALS = 7 }