diff --git a/src/mono/browser/runtime/jiterpreter-trace-generator.ts b/src/mono/browser/runtime/jiterpreter-trace-generator.ts index 9ca8453e58a8c..da85d7ab02163 100644 --- a/src/mono/browser/runtime/jiterpreter-trace-generator.ts +++ b/src/mono/browser/runtime/jiterpreter-trace-generator.ts @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +import WasmEnableThreads from "consts:wasmEnableThreads"; import { MonoMethod } from "./types/internal"; import { NativePointer } from "./types/emscripten"; import { @@ -9,7 +10,7 @@ import { } from "./memory"; import { WasmOpcode, WasmSimdOpcode, WasmValtype, - getOpcodeName, MintOpArgType + getOpcodeName, MintOpArgType, WasmAtomicOpcode } from "./jiterpreter-opcodes"; import { MintOpcode, SimdInfo, @@ -3975,6 +3976,20 @@ function emit_simd_4 (builder: WasmBuilder, ip: MintOpcodePtr, index: SimdIntrin function emit_atomics ( builder: WasmBuilder, ip: MintOpcodePtr, opcode: number ) { + if (opcode === MintOpcode.MINT_MONO_MEMORY_BARRIER) { + if (WasmEnableThreads) { + // Mono memory barriers use sync_synchronize which generates atomic.fence on clang, + // provided you pass -pthread at compile time + builder.appendAtomic(WasmAtomicOpcode.atomic_fence); + // The text format and other parts of the spec say atomic.fence has no operands, + // but the binary encoding contains a byte specifying whether the barrier is + // sequentially consistent (0) or acquire-release (1) + // Mono memory barriers are sync_synchronize which is sequentially consistent. + builder.appendU8(0); + } + return true; + } + if (!builder.options.enableAtomics) return false; diff --git a/src/mono/mono/mini/interp/jiterpreter-opcode-values.h b/src/mono/mono/mini/interp/jiterpreter-opcode-values.h index 7d903e2aeefe1..a509b8471cfa9 100644 --- a/src/mono/mono/mini/interp/jiterpreter-opcode-values.h +++ b/src/mono/mono/mini/interp/jiterpreter-opcode-values.h @@ -187,6 +187,7 @@ OP(MINT_THROW, ABORT_OUTSIDE_BRANCH_BLOCK_NONE) OP(MINT_MOV_SRC_OFF, NORMAL) OP(MINT_MOV_DST_OFF, NORMAL) +OP(MINT_MONO_MEMORY_BARRIER, NORMAL) OPRANGE(MINT_MONO_EXCHANGE_U1, MINT_MONO_EXCHANGE_I8, HIGH) OPRANGE(MINT_MONO_CMPXCHG_U1, MINT_MONO_CMPXCHG_I8, HIGH) diff --git a/src/mono/mono/mini/interp/jiterpreter.c b/src/mono/mono/mini/interp/jiterpreter.c index 13d337b10c9fe..fa75f766cec02 100644 --- a/src/mono/mono/mini/interp/jiterpreter.c +++ b/src/mono/mono/mini/interp/jiterpreter.c @@ -1165,6 +1165,7 @@ mono_jiterp_stelem_ref ( return 1; } + // keep in sync with jiterpreter-enums.ts JiterpMember enum { JITERP_MEMBER_VT_INITIALIZED = 0, diff --git a/src/mono/mono/utils/options-def.h b/src/mono/mono/utils/options-def.h index fc7e403a2bbd0..4d3bdddaf7073 100644 --- a/src/mono/mono/utils/options-def.h +++ b/src/mono/mono/utils/options-def.h @@ -89,7 +89,7 @@ DEFINE_BOOL(jiterpreter_jit_call_enabled, "jiterpreter-jit-call-enabled", TRUE, DEFINE_BOOL(wasm_gc_safepoints, "wasm-gc-safepoints", FALSE, "Use GC safepoints on WASM") #else // traces_enabled controls whether the jiterpreter will JIT individual interpreter opcode traces -DEFINE_BOOL_READONLY(jiterpreter_traces_enabled, "jiterpreter-traces-enabled", FALSE, "JIT interpreter opcode traces into WASM") +DEFINE_BOOL(jiterpreter_traces_enabled, "jiterpreter-traces-enabled", TRUE, "JIT interpreter opcode traces into WASM") // interp_entry_enabled controls whether specialized interp_entry wrappers will be jitted DEFINE_BOOL_READONLY(jiterpreter_interp_entry_enabled, "jiterpreter-interp-entry-enabled", FALSE, "JIT specialized WASM interp_entry wrappers") // jit_call_enabled controls whether do_jit_call will use specialized trampolines for hot call sites