Skip to content

Commit 59dddfd

Browse files
authored
[Jiterpreter] Add support for TryGetHashCode intrinsic (#81644)
#80520 added support in the Jiterpreter for the intrinsic that underlies RuntimeHelpers.GetHashCode. This PR adds similar support for the intrinsic that underlies RuntimeHelpers.TryGetHashCode. For reference RuntimeHelpers.TryGetHashCode was added in #80059. It is currently only used in ConditionalWeakTable.TryGetValue.
1 parent 5f6c7d6 commit 59dddfd

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ jiterp_should_abort_trace (InterpInst *ins, gboolean *inside_branch_block)
700700
case MINT_LDTSFLDA:
701701
case MINT_SAFEPOINT:
702702
case MINT_INTRINS_GET_HASHCODE:
703+
case MINT_INTRINS_TRY_GET_HASHCODE:
703704
case MINT_INTRINS_RUNTIMEHELPERS_OBJECT_HAS_COMPONENT_SIZE:
704705
case MINT_INTRINS_ENUM_HASFLAG:
705706
case MINT_ADD_MUL_I4_IMM:
@@ -1070,6 +1071,14 @@ mono_jiterp_get_hashcode (MonoObject ** ppObj)
10701071
return mono_object_hash_internal (obj);
10711072
}
10721073

1074+
EMSCRIPTEN_KEEPALIVE int
1075+
mono_jiterp_try_get_hashcode (MonoObject ** ppObj)
1076+
{
1077+
MonoObject *obj = *ppObj;
1078+
g_assert (obj);
1079+
return mono_object_try_get_hash_internal (obj);
1080+
}
1081+
10731082
EMSCRIPTEN_KEEPALIVE int
10741083
mono_jiterp_get_signature_has_this (MonoMethodSignature *sig)
10751084
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@ export function generate_wasm_body (
471471
builder.callImport("hashcode");
472472
append_stloc_tail(builder, getArgU16(ip, 1), WasmOpcode.i32_store);
473473
break;
474+
case MintOpcode.MINT_INTRINS_TRY_GET_HASHCODE:
475+
builder.local("pLocals");
476+
append_ldloca(builder, getArgU16(ip, 2));
477+
builder.callImport("try_hash");
478+
append_stloc_tail(builder, getArgU16(ip, 1), WasmOpcode.i32_store);
479+
break;
474480
case MintOpcode.MINT_INTRINS_RUNTIMEHELPERS_OBJECT_HAS_COMPONENT_SIZE:
475481
builder.local("pLocals");
476482
append_ldloca(builder, getArgU16(ip, 2));

src/mono/wasm/runtime/jiterpreter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ function getTraceImports () {
243243
["relop_fp", "relop_fp", getRawCwrap("mono_jiterp_relop_fp")],
244244
["safepoint", "safepoint", getRawCwrap("mono_jiterp_auto_safepoint")],
245245
["hashcode", "hashcode", getRawCwrap("mono_jiterp_get_hashcode")],
246+
["try_hash", "try_hash", getRawCwrap("mono_jiterp_try_get_hashcode")],
246247
["hascsize", "hascsize", getRawCwrap("mono_jiterp_object_has_component_size")],
247248
["hasflag", "hasflag", getRawCwrap("mono_jiterp_enum_hasflag")],
248249
["array_rank", "array_rank", getRawCwrap("mono_jiterp_get_array_rank")],
@@ -468,6 +469,11 @@ function initialize_builder (builder: WasmBuilder) {
468469
"ppObj": WasmValtype.i32,
469470
}, WasmValtype.i32, true
470471
);
472+
builder.defineType(
473+
"try_hash", {
474+
"ppObj": WasmValtype.i32,
475+
}, WasmValtype.i32, true
476+
);
471477
builder.defineType(
472478
"hascsize", {
473479
"ppObj": WasmValtype.i32,

0 commit comments

Comments
 (0)