Skip to content

Commit a349912

Browse files
authored
[wasm] Implement MONO_MEMORY_BARRIER in jiterpreter & enable MT jiterp traces (#107325)
* Implement MONO_MEMORY_BARRIER in jiterpreter * Enable jiterp traces for MT wasm
1 parent 5428078 commit a349912

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
import WasmEnableThreads from "consts:wasmEnableThreads";
45
import { MonoMethod } from "./types/internal";
56
import { NativePointer } from "./types/emscripten";
67
import {
@@ -9,7 +10,7 @@ import {
910
} from "./memory";
1011
import {
1112
WasmOpcode, WasmSimdOpcode, WasmValtype,
12-
getOpcodeName, MintOpArgType
13+
getOpcodeName, MintOpArgType, WasmAtomicOpcode
1314
} from "./jiterpreter-opcodes";
1415
import {
1516
MintOpcode, SimdInfo,
@@ -3975,6 +3976,20 @@ function emit_simd_4 (builder: WasmBuilder, ip: MintOpcodePtr, index: SimdIntrin
39753976
function emit_atomics (
39763977
builder: WasmBuilder, ip: MintOpcodePtr, opcode: number
39773978
) {
3979+
if (opcode === MintOpcode.MINT_MONO_MEMORY_BARRIER) {
3980+
if (WasmEnableThreads) {
3981+
// Mono memory barriers use sync_synchronize which generates atomic.fence on clang,
3982+
// provided you pass -pthread at compile time
3983+
builder.appendAtomic(WasmAtomicOpcode.atomic_fence);
3984+
// The text format and other parts of the spec say atomic.fence has no operands,
3985+
// but the binary encoding contains a byte specifying whether the barrier is
3986+
// sequentially consistent (0) or acquire-release (1)
3987+
// Mono memory barriers are sync_synchronize which is sequentially consistent.
3988+
builder.appendU8(0);
3989+
}
3990+
return true;
3991+
}
3992+
39783993
if (!builder.options.enableAtomics)
39793994
return false;
39803995

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ OP(MINT_THROW, ABORT_OUTSIDE_BRANCH_BLOCK_NONE)
187187
OP(MINT_MOV_SRC_OFF, NORMAL)
188188
OP(MINT_MOV_DST_OFF, NORMAL)
189189

190+
OP(MINT_MONO_MEMORY_BARRIER, NORMAL)
190191
OPRANGE(MINT_MONO_EXCHANGE_U1, MINT_MONO_EXCHANGE_I8, HIGH)
191192
OPRANGE(MINT_MONO_CMPXCHG_U1, MINT_MONO_CMPXCHG_I8, HIGH)
192193

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ mono_jiterp_stelem_ref (
11651165
return 1;
11661166
}
11671167

1168+
11681169
// keep in sync with jiterpreter-enums.ts JiterpMember
11691170
enum {
11701171
JITERP_MEMBER_VT_INITIALIZED = 0,

src/mono/mono/utils/options-def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ DEFINE_BOOL(jiterpreter_jit_call_enabled, "jiterpreter-jit-call-enabled", TRUE,
8989
DEFINE_BOOL(wasm_gc_safepoints, "wasm-gc-safepoints", FALSE, "Use GC safepoints on WASM")
9090
#else
9191
// traces_enabled controls whether the jiterpreter will JIT individual interpreter opcode traces
92-
DEFINE_BOOL_READONLY(jiterpreter_traces_enabled, "jiterpreter-traces-enabled", FALSE, "JIT interpreter opcode traces into WASM")
92+
DEFINE_BOOL(jiterpreter_traces_enabled, "jiterpreter-traces-enabled", TRUE, "JIT interpreter opcode traces into WASM")
9393
// interp_entry_enabled controls whether specialized interp_entry wrappers will be jitted
9494
DEFINE_BOOL_READONLY(jiterpreter_interp_entry_enabled, "jiterpreter-interp-entry-enabled", FALSE, "JIT specialized WASM interp_entry wrappers")
9595
// jit_call_enabled controls whether do_jit_call will use specialized trampolines for hot call sites

0 commit comments

Comments
 (0)