Skip to content

Commit

Permalink
[wasm] Implement MONO_MEMORY_BARRIER in jiterpreter & enable MT jiter…
Browse files Browse the repository at this point in the history
…p traces (#107325)

* Implement MONO_MEMORY_BARRIER in jiterpreter
* Enable jiterp traces for MT wasm
  • Loading branch information
kg committed Sep 6, 2024
1 parent 5428078 commit a349912
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/mono/browser/runtime/jiterpreter-trace-generator.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -9,7 +10,7 @@ import {
} from "./memory";
import {
WasmOpcode, WasmSimdOpcode, WasmValtype,
getOpcodeName, MintOpArgType
getOpcodeName, MintOpArgType, WasmAtomicOpcode
} from "./jiterpreter-opcodes";
import {
MintOpcode, SimdInfo,
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/interp/jiterpreter-opcode-values.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/interp/jiterpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ mono_jiterp_stelem_ref (
return 1;
}


// keep in sync with jiterpreter-enums.ts JiterpMember
enum {
JITERP_MEMBER_VT_INITIALIZED = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/utils/options-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a349912

Please sign in to comment.