Skip to content

Commit 67e5768

Browse files
authored
[wasm] Implement MINT_NEWARR in jiterpreter (#107430)
1 parent 176754d commit 67e5768

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

src/mono/browser/runtime/jiterpreter-trace-generator.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,21 @@ export function generateWasmBody (
12801280
break;
12811281
}
12821282

1283+
case MintOpcode.MINT_NEWARR: {
1284+
builder.block();
1285+
append_ldloca(builder, getArgU16(ip, 1), 4);
1286+
const vtable = get_imethod_data(frame, getArgU16(ip, 3));
1287+
builder.i32_const(vtable);
1288+
append_ldloc(builder, getArgU16(ip, 2), WasmOpcode.i32_load);
1289+
builder.callImport("newarr");
1290+
// If the newarr operation succeeded, continue, otherwise bailout
1291+
builder.appendU8(WasmOpcode.br_if);
1292+
builder.appendULeb(0);
1293+
append_bailout(builder, ip, BailoutReason.AllocFailed);
1294+
builder.endBlock();
1295+
break;
1296+
}
1297+
12831298
case MintOpcode.MINT_NEWOBJ_INLINED: {
12841299
builder.block();
12851300
// MonoObject *o = mono_gc_alloc_obj (vtable, m_class_get_instance_size (vtable->klass));

src/mono/browser/runtime/jiterpreter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ function getTraceImports () {
272272
["ckovr_u4", "overflow_check_i4", getRawCwrap("mono_jiterp_overflow_check_u4")],
273273
importDef("newobj_i", getRawCwrap("mono_jiterp_try_newobj_inlined")),
274274
importDef("newstr", getRawCwrap("mono_jiterp_try_newstr")),
275+
importDef("newarr", getRawCwrap("mono_jiterp_try_newarr")),
275276
importDef("ld_del_ptr", getRawCwrap("mono_jiterp_ld_delegate_method_ptr")),
276277
importDef("ldtsflda", getRawCwrap("mono_jiterp_ldtsflda")),
277278
importDef("conv", getRawCwrap("mono_jiterp_conv")),
@@ -465,6 +466,15 @@ function initialize_builder (builder: WasmBuilder) {
465466
},
466467
WasmValtype.i32, true
467468
);
469+
builder.defineType(
470+
"newarr",
471+
{
472+
"ppDestination": WasmValtype.i32,
473+
"vtable": WasmValtype.i32,
474+
"length": WasmValtype.i32,
475+
},
476+
WasmValtype.i32, true
477+
);
468478
builder.defineType(
469479
"localloc",
470480
{

src/mono/mono/mini/interp/jiterpreter-opcode-values.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ OP(MINT_BOX, NORMAL)
9898
OP(MINT_BOX_VT, NORMAL)
9999
OP(MINT_UNBOX, NORMAL)
100100
OP(MINT_NEWSTR, NORMAL)
101+
OP(MINT_NEWARR, NORMAL)
101102
OP(MINT_LD_DELEGATE_METHOD_PTR, NORMAL)
102103
OP(MINT_LDTSFLDA, NORMAL)
103104
OP(MINT_ADD_MUL_I4_IMM, NORMAL)

src/mono/mono/mini/interp/jiterpreter.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,18 @@ mono_jiterp_try_newstr (MonoString **destination, int length) {
202202
return *destination != 0;
203203
}
204204

205+
EMSCRIPTEN_KEEPALIVE int
206+
mono_jiterp_try_newarr (MonoArray **destination, MonoVTable *vtable, int length) {
207+
if (length < 0)
208+
return 0;
209+
ERROR_DECL(error);
210+
*destination = mono_array_new_specific_checked (vtable, length, error);
211+
if (!is_ok (error))
212+
*destination = 0;
213+
mono_error_cleanup (error); // FIXME: do not swallow the error
214+
return *destination != 0;
215+
}
216+
205217
EMSCRIPTEN_KEEPALIVE int
206218
mono_jiterp_gettype_ref (
207219
MonoObject **destination, MonoObject **source

0 commit comments

Comments
 (0)