[Jiterpreter] Add support for TryGetHashCode intrinsic (#81644)
authorAustin Wise <AustinWise@gmail.com>
Tue, 7 Feb 2023 23:50:01 +0000 (15:50 -0800)
committerGitHub <noreply@github.com>
Tue, 7 Feb 2023 23:50:01 +0000 (15:50 -0800)
#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.

src/mono/mono/mini/interp/jiterpreter.c
src/mono/wasm/runtime/jiterpreter-trace-generator.ts
src/mono/wasm/runtime/jiterpreter.ts

index 60664b3..ef3c03c 100644 (file)
@@ -700,6 +700,7 @@ jiterp_should_abort_trace (InterpInst *ins, gboolean *inside_branch_block)
                case MINT_LDTSFLDA:
                case MINT_SAFEPOINT:
                case MINT_INTRINS_GET_HASHCODE:
+               case MINT_INTRINS_TRY_GET_HASHCODE:
                case MINT_INTRINS_RUNTIMEHELPERS_OBJECT_HAS_COMPONENT_SIZE:
                case MINT_INTRINS_ENUM_HASFLAG:
                case MINT_ADD_MUL_I4_IMM:
@@ -1071,6 +1072,14 @@ mono_jiterp_get_hashcode (MonoObject ** ppObj)
 }
 
 EMSCRIPTEN_KEEPALIVE int
+mono_jiterp_try_get_hashcode (MonoObject ** ppObj)
+{
+       MonoObject *obj = *ppObj;
+       g_assert (obj);
+       return mono_object_try_get_hash_internal (obj);
+}
+
+EMSCRIPTEN_KEEPALIVE int
 mono_jiterp_get_signature_has_this (MonoMethodSignature *sig)
 {
        return sig->hasthis;
index 5a607fe..be6e8b9 100644 (file)
@@ -471,6 +471,12 @@ export function generate_wasm_body (
                 builder.callImport("hashcode");
                 append_stloc_tail(builder, getArgU16(ip, 1), WasmOpcode.i32_store);
                 break;
+            case MintOpcode.MINT_INTRINS_TRY_GET_HASHCODE:
+                builder.local("pLocals");
+                append_ldloca(builder, getArgU16(ip, 2));
+                builder.callImport("try_hash");
+                append_stloc_tail(builder, getArgU16(ip, 1), WasmOpcode.i32_store);
+                break;
             case MintOpcode.MINT_INTRINS_RUNTIMEHELPERS_OBJECT_HAS_COMPONENT_SIZE:
                 builder.local("pLocals");
                 append_ldloca(builder, getArgU16(ip, 2));
index b236e2e..8e2cb68 100644 (file)
@@ -243,6 +243,7 @@ function getTraceImports () {
         ["relop_fp", "relop_fp", getRawCwrap("mono_jiterp_relop_fp")],
         ["safepoint", "safepoint", getRawCwrap("mono_jiterp_auto_safepoint")],
         ["hashcode", "hashcode", getRawCwrap("mono_jiterp_get_hashcode")],
+        ["try_hash", "try_hash", getRawCwrap("mono_jiterp_try_get_hashcode")],
         ["hascsize", "hascsize", getRawCwrap("mono_jiterp_object_has_component_size")],
         ["hasflag", "hasflag", getRawCwrap("mono_jiterp_enum_hasflag")],
         ["array_rank", "array_rank", getRawCwrap("mono_jiterp_get_array_rank")],
@@ -469,6 +470,11 @@ function initialize_builder (builder: WasmBuilder) {
         }, WasmValtype.i32, true
     );
     builder.defineType(
+        "try_hash", {
+            "ppObj": WasmValtype.i32,
+        }, WasmValtype.i32, true
+    );
+    builder.defineType(
         "hascsize", {
             "ppObj": WasmValtype.i32,
         }, WasmValtype.i32, true