Skip to content

Commit

Permalink
[wasm] Implement MINT_NEWARR in jiterpreter (dotnet#107430)
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Sep 9, 2024
1 parent 176754d commit 67e5768
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/mono/browser/runtime/jiterpreter-trace-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,21 @@ export function generateWasmBody (
break;
}

case MintOpcode.MINT_NEWARR: {
builder.block();
append_ldloca(builder, getArgU16(ip, 1), 4);
const vtable = get_imethod_data(frame, getArgU16(ip, 3));
builder.i32_const(vtable);
append_ldloc(builder, getArgU16(ip, 2), WasmOpcode.i32_load);
builder.callImport("newarr");
// If the newarr operation succeeded, continue, otherwise bailout
builder.appendU8(WasmOpcode.br_if);
builder.appendULeb(0);
append_bailout(builder, ip, BailoutReason.AllocFailed);
builder.endBlock();
break;
}

case MintOpcode.MINT_NEWOBJ_INLINED: {
builder.block();
// MonoObject *o = mono_gc_alloc_obj (vtable, m_class_get_instance_size (vtable->klass));
Expand Down
10 changes: 10 additions & 0 deletions src/mono/browser/runtime/jiterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ function getTraceImports () {
["ckovr_u4", "overflow_check_i4", getRawCwrap("mono_jiterp_overflow_check_u4")],
importDef("newobj_i", getRawCwrap("mono_jiterp_try_newobj_inlined")),
importDef("newstr", getRawCwrap("mono_jiterp_try_newstr")),
importDef("newarr", getRawCwrap("mono_jiterp_try_newarr")),
importDef("ld_del_ptr", getRawCwrap("mono_jiterp_ld_delegate_method_ptr")),
importDef("ldtsflda", getRawCwrap("mono_jiterp_ldtsflda")),
importDef("conv", getRawCwrap("mono_jiterp_conv")),
Expand Down Expand Up @@ -465,6 +466,15 @@ function initialize_builder (builder: WasmBuilder) {
},
WasmValtype.i32, true
);
builder.defineType(
"newarr",
{
"ppDestination": WasmValtype.i32,
"vtable": WasmValtype.i32,
"length": WasmValtype.i32,
},
WasmValtype.i32, true
);
builder.defineType(
"localloc",
{
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/interp/jiterpreter-opcode-values.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ OP(MINT_BOX, NORMAL)
OP(MINT_BOX_VT, NORMAL)
OP(MINT_UNBOX, NORMAL)
OP(MINT_NEWSTR, NORMAL)
OP(MINT_NEWARR, NORMAL)
OP(MINT_LD_DELEGATE_METHOD_PTR, NORMAL)
OP(MINT_LDTSFLDA, NORMAL)
OP(MINT_ADD_MUL_I4_IMM, NORMAL)
Expand Down
12 changes: 12 additions & 0 deletions src/mono/mono/mini/interp/jiterpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ mono_jiterp_try_newstr (MonoString **destination, int length) {
return *destination != 0;
}

EMSCRIPTEN_KEEPALIVE int
mono_jiterp_try_newarr (MonoArray **destination, MonoVTable *vtable, int length) {
if (length < 0)
return 0;
ERROR_DECL(error);
*destination = mono_array_new_specific_checked (vtable, length, error);
if (!is_ok (error))
*destination = 0;
mono_error_cleanup (error); // FIXME: do not swallow the error
return *destination != 0;
}

EMSCRIPTEN_KEEPALIVE int
mono_jiterp_gettype_ref (
MonoObject **destination, MonoObject **source
Expand Down

0 comments on commit 67e5768

Please sign in to comment.