Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion AGENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ mvn surefire:test -pl runtime-tests -Dtest=SpecV1GcStructTest
- `ImportFunction.java` — imported function representation with cross-module type validation
- `ConstantEvaluators.java` — constant expression evaluation (globals, element/data segments)
- `WasmStruct.java`, `WasmArray.java`, `WasmI31Ref.java` — GC object types
- `internal/GcRefStore.java` — auto-keyed store for Wasm GC references with mark-sweep collection

### `compiler` module
- `MachineFactoryCompiler.java` — entry point for the JVM bytecode compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ private CompilerUtil() {}
public static Class<?> jvmType(ValType type) {
switch (type.opcode()) {
case ValType.ID.I32:
case ValType.ID.ExnRef:
return int.class;
case ValType.ID.Ref:
case ValType.ID.RefNull:
Expand All @@ -79,7 +78,6 @@ public static Class<?> jvmType(ValType type) {
public static Type asmType(ValType type) {
switch (type.opcode()) {
case ValType.ID.I32:
case ValType.ID.ExnRef:
return INT_TYPE;
case ValType.ID.Ref:
case ValType.ID.RefNull:
Expand All @@ -106,7 +104,6 @@ public static ValType localType(FunctionType type, FunctionBody body, int localI
public static void emitLongToJvm(MethodVisitor asm, ValType type) {
switch (type.opcode()) {
case ValType.ID.I32:
case ValType.ID.ExnRef:
asm.visitInsn(Opcodes.L2I);
return;
case ValType.ID.Ref:
Expand Down Expand Up @@ -134,7 +131,6 @@ public static void emitLongToJvm(MethodVisitor asm, ValType type) {
public static void emitJvmToLong(MethodVisitor asm, ValType type) {
switch (type.opcode()) {
case ValType.ID.I32:
case ValType.ID.ExnRef:
asm.visitInsn(Opcodes.I2L);
return;
case ValType.ID.Ref:
Expand Down Expand Up @@ -225,8 +221,6 @@ public static Object defaultValue(ValType type) {
return null; // GC refs use null as their default
}
return REF_NULL_VALUE;
case ValType.ID.ExnRef:
return REF_NULL_VALUE;
default:
throw new IllegalArgumentException("Unsupported ValType: " + type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.InstructionAdapter;
import run.endive.runtime.Instance;
import run.endive.runtime.OpCodeIdentifier;
import run.endive.runtime.WasmException;
import run.endive.wasm.WasmEngineException;
Expand Down Expand Up @@ -1565,11 +1564,8 @@ public static void THROW(Context ctx, CompilerInstruction ins, InstructionAdapte
}

public static void THROW_REF(Context ctx, CompilerInstruction ins, InstructionAdapter asm) {
// The exception reference is already on the stack as an integer
// Get the instance and retrieve the exception
asm.load(ctx.instanceSlot(), OBJECT_TYPE);
asm.swap(); // Swap instance and exception reference
emitInvokeVirtual(asm, ShadedRefs.INSTANCE_GET_EXCEPTION);
// Narrow the exnref on the stack, trapping if it is null
emitInvokeStatic(asm, ShadedRefs.WASM_EXCEPTION_CHECKED);
asm.athrow();
}

Expand Down Expand Up @@ -1703,15 +1699,8 @@ public static void CATCH_COMPARE_TAG(

public static void CATCH_REGISTER_EXCEPTION(
Context ctx, CompilerInstruction ins, InstructionAdapter asm) {
// Register exception and push its
// index
asm.load(ctx.instanceSlot(), OBJECT_TYPE);
// Push the caught exception, already stored as an object by CATCH_START
asm.load(ctx.tempSlot(), OBJECT_TYPE);
asm.invokevirtual(
getInternalName(Instance.class),
"registerException",
getMethodDescriptor(INT_TYPE, getType(WasmException.class)),
false);
}

// ========= GC Operations =========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ public static WasmException createWasmException(long[] args, int tagNumber, Inst
}
WasmException e =
WasmException.builder().instance(instance).tagIdx(tagNumber).args(args).build();
instance.registerException(e);
return e;
}

Expand All @@ -538,7 +537,6 @@ public static WasmException createWasmExceptionGc(
.args(args)
.refArgs(refArgs)
.build();
instance.registerException(e);
return e;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final class ShadedRefs {
// Exception handling methods
static final Method CREATE_WASM_EXCEPTION;
static final Method CREATE_WASM_EXCEPTION_GC;
static final Method INSTANCE_GET_EXCEPTION;
static final Method WASM_EXCEPTION_CHECKED;
static final Method EXCEPTION_MATCHES;

static final Method MEMORY_ATOMIC_INT_WRITE;
Expand Down Expand Up @@ -398,7 +398,7 @@ public final class ShadedRefs {
Object[].class,
int.class,
Instance.class);
INSTANCE_GET_EXCEPTION = Instance.class.getMethod("exn", int.class);
WASM_EXCEPTION_CHECKED = WasmException.class.getMethod("checked", Object.class);
EXCEPTION_MATCHES =
Shaded.class.getMethod(
"exceptionMatches", WasmException.class, int.class, Instance.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ public void verifyExceptions() {
verifyGeneratedBytecode("exceptions.wat.wasm", (name) -> !name.contains("FuncGroup"));
}

/** Pins the bytecode for catch_ref / catch_all_ref / throw_ref. */
@Test
public void verifyExceptionRefs() {
verifyGeneratedBytecode(
"catch_ref_non_null.wat.wasm", (name) -> !name.contains("FuncGroup"));
}

@Test
public void verifyTailCall() {
verifyGeneratedBytecode("tail_call_return_call.wat.wasm");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
final class run/endive/$gen/CompiledMachineFuncGroup_0 {

public static func_0(ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)V
ILOAD 0
ISTORE 3
ICONST_1
NEWARRAY T_LONG
DUP
ICONST_0
ILOAD 3
I2L
LASTORE
ICONST_0
ALOAD 2
INVOKESTATIC run/endive/$gen/CompiledMachineShaded.createWasmException ([JILrun/endive/runtime/Instance;)Lrun/endive/runtime/WasmException;
ATHROW
L0
ATHROW

public static call_0(Lrun/endive/runtime/Instance;Lrun/endive/runtime/Memory;[J[Ljava/lang/Object;)[J
ALOAD 2
ICONST_0
LALOAD
L2I
ALOAD 1
ALOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_0 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)V
ACONST_NULL
ARETURN

public static func_1(ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)I
TRYCATCHBLOCK L0 L1 L2 run/endive/runtime/WasmException
L0
ILOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineShaded.checkInterruption ()V
ALOAD 1
ALOAD 2
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_0 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)V
ICONST_0
L1
GOTO L3
L2
ASTORE 3
ALOAD 3
ICONST_0
ALOAD 2
INVOKESTATIC run/endive/$gen/CompiledMachineShaded.exceptionMatches (Lrun/endive/runtime/WasmException;ILrun/endive/runtime/Instance;)Z
IFEQ L4
ALOAD 3
INVOKEVIRTUAL run/endive/runtime/WasmException.args ()[J
ASTORE 4
ALOAD 4
ICONST_0
LALOAD
L2I
ALOAD 3
GOTO L5
L4
ALOAD 3
ATHROW
L3
IRETURN
L5
POP
IRETURN

public static call_1(Lrun/endive/runtime/Instance;Lrun/endive/runtime/Memory;[J[Ljava/lang/Object;)[J
ALOAD 2
ICONST_0
LALOAD
L2I
ALOAD 1
ALOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_1 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)I
I2L
LSTORE 4
ICONST_1
NEWARRAY T_LONG
DUP
ICONST_0
LLOAD 4
LASTORE
ARETURN

public static func_2(ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)I
TRYCATCHBLOCK L0 L1 L2 run/endive/runtime/WasmException
L0
ILOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineShaded.checkInterruption ()V
ALOAD 1
ALOAD 2
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_0 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)V
L1
GOTO L3
L2
ASTORE 3
ALOAD 3
GOTO L4
L5
NOP
ATHROW
L3
ICONST_0
IRETURN
L4
POP
ILOAD 0
IRETURN

public static call_2(Lrun/endive/runtime/Instance;Lrun/endive/runtime/Memory;[J[Ljava/lang/Object;)[J
ALOAD 2
ICONST_0
LALOAD
L2I
ALOAD 1
ALOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_2 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)I
I2L
LSTORE 4
ICONST_1
NEWARRAY T_LONG
DUP
ICONST_0
LLOAD 4
LASTORE
ARETURN

public static func_3(ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)I
TRYCATCHBLOCK L0 L1 L2 run/endive/runtime/WasmException
TRYCATCHBLOCK L3 L4 L5 run/endive/runtime/WasmException
ACONST_NULL
ASTORE 3
L3
ILOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineShaded.checkInterruption ()V
ALOAD 1
ALOAD 2
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_0 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)V
L4
GOTO L6
L5
ASTORE 4
ALOAD 4
GOTO L7
L8
NOP
NOP
ATHROW
L6
ICONST_0
IRETURN
L7
ASTORE 3
L0
ALOAD 3
INVOKESTATIC run/endive/runtime/WasmException.checked (Ljava/lang/Object;)Lrun/endive/runtime/WasmException;
ATHROW
L1
NOP
NOP
ATHROW
L2
ASTORE 4
ALOAD 4
ICONST_0
ALOAD 2
INVOKESTATIC run/endive/$gen/CompiledMachineShaded.exceptionMatches (Lrun/endive/runtime/WasmException;ILrun/endive/runtime/Instance;)Z
IFEQ L9
ALOAD 4
INVOKEVIRTUAL run/endive/runtime/WasmException.args ()[J
ASTORE 5
ALOAD 5
ICONST_0
LALOAD
L2I
ALOAD 4
GOTO L10
L9
ALOAD 4
ATHROW
L11
ATHROW
L10
POP
IRETURN

public static call_3(Lrun/endive/runtime/Instance;Lrun/endive/runtime/Memory;[J[Ljava/lang/Object;)[J
ALOAD 2
ICONST_0
LALOAD
L2I
ALOAD 1
ALOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_3 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)I
I2L
LSTORE 4
ICONST_1
NEWARRAY T_LONG
DUP
ICONST_0
LLOAD 4
LASTORE
ARETURN

public static func_4(ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)I
TRYCATCHBLOCK L0 L1 L2 run/endive/runtime/WasmException
L0
ILOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineShaded.checkInterruption ()V
ALOAD 1
ALOAD 2
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_0 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)V
ICONST_0
L1
GOTO L3
L2
ASTORE 3
ALOAD 3
ICONST_0
ALOAD 2
INVOKESTATIC run/endive/$gen/CompiledMachineShaded.exceptionMatches (Lrun/endive/runtime/WasmException;ILrun/endive/runtime/Instance;)Z
IFEQ L4
ALOAD 3
INVOKEVIRTUAL run/endive/runtime/WasmException.args ()[J
ASTORE 4
ALOAD 4
ICONST_0
LALOAD
L2I
ALOAD 3
GOTO L5
L4
ALOAD 3
ATHROW
L3
IRETURN
L5
POP
IRETURN

public static call_4(Lrun/endive/runtime/Instance;Lrun/endive/runtime/Memory;[J[Ljava/lang/Object;)[J
ALOAD 2
ICONST_0
LALOAD
L2I
ALOAD 1
ALOAD 0
INVOKESTATIC run/endive/$gen/CompiledMachineFuncGroup_0.func_4 (ILrun/endive/runtime/Memory;Lrun/endive/runtime/Instance;)I
I2L
LSTORE 4
ICONST_1
NEWARRAY T_LONG
DUP
ICONST_0
LLOAD 4
LASTORE
ARETURN
}
Loading
Loading