Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ else()
if(CLR_CMAKE_RUNTIME_CORECLR)
if(CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CROSS_COMPONENTS_BUILD)
add_link_options(-fwasm-exceptions)
add_link_options(-sWASM_LEGACY_EXCEPTIONS=1)
add_link_options(-sWASM_LEGACY_EXCEPTIONS=0)
add_link_options(-Wno-unused-command-line-argument)
add_link_options(-Wl,--error-limit=0)

Expand All @@ -512,12 +512,12 @@ else()
add_link_options(-lc)
add_link_options(-lmalloc)
add_link_options(-lcompiler_rt)
add_link_options(-lc++)
add_link_options(-lc++abi)
add_link_options(-lunwind)
add_link_options(-lc++-wasmexcept)
add_link_options(-lc++abi-wasmexcept)
add_link_options(-lunwind-wasmexcept)

add_compile_options(-fwasm-exceptions)
add_compile_options(-sWASM_LEGACY_EXCEPTIONS=1)
add_compile_options(-sWASM_LEGACY_EXCEPTIONS=0)
add_compile_options(-mbulk-memory)
add_compile_options(-msimd128)
endif()
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/common/templates/pipeline-with-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ extends:
image: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-stream-10-amd64@sha256:1849c00a1347f17dbdd167bc8d025b9e2c31273a1f8c2eddbfac3f2197932ee7

browser_wasm:
image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net11.0-webassembly-amd64@sha256:5ad583f9a503d9b5d71171ac27018db895f9b48f136d5d4fe3cdcf80bc28937e
image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net11.0-webassembly-amd64@sha256:0afc4daa90da131fd61de0751429a7dadf4cc2e4a159f0c60a0d24d02267bae8
env:
ROOTFS_DIR: /crossrootfs/x64

wasi_wasm:
image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net11.0-webassembly-amd64@sha256:5ad583f9a503d9b5d71171ac27018db895f9b48f136d5d4fe3cdcf80bc28937e
image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net11.0-webassembly-amd64@sha256:0afc4daa90da131fd61de0751429a7dadf4cc2e4a159f0c60a0d24d02267bae8
env:
ROOTFS_DIR: /crossrootfs/x64

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ parameters:
dependsOn: []
extraHelixArguments: ''
buildAllTestsAsStandalone: false
sendToHelix: true
#arcade-specific parameters
condition: always()
continueOnError: false
Expand Down Expand Up @@ -107,8 +108,9 @@ steps:
helixType: 'test/functional/cli/'

helixQueues: ${{ parameters.helixQueues }}
# This tests whether an array is empty
${{ if eq(join('', parameters.helixQueues), '') }}:
# Skip the Helix send (and thus test execution) when there are no queues, or when the caller
# disabled it via sendToHelix=false (e.g. the target JS engine can't run the tests yet).
${{ if or(eq(join('', parameters.helixQueues), ''), ne(parameters.sendToHelix, true)) }}:
condition: false
publishTestResults: true
timeoutPerTestInMinutes: $(timeoutPerTestInMinutes)
Expand Down
5 changes: 5 additions & 0 deletions eng/pipelines/common/templates/wasm-runtime-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ jobs:
creator: dotnet-bot
testRunNamePrefixSuffix: Mono_$(_BuildConfig)
testBuildArgs: /p:InstallV8ForTests=false
# Build the runtime tests for browser, but don't send them to Helix to run on V8: the
# V8 baked into the helix-webassembly container doesn't support --experimental-wasm-exnref
# yet, so the tests abort at startup. Re-enable the run once the new V8 image is
# available. See ActiveIssue https://github.com/dotnet/runtime/issues/129849
sendToHelix: false
extraVariablesTemplates:
- template: /eng/pipelines/common/templates/runtimes/test-variables.yml
14 changes: 5 additions & 9 deletions eng/pipelines/performance/runtime-wasm-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

trigger: none

pr:
branches:
include:
- main
paths:
include:
- eng/pipelines/performance/*
- eng/testing/performance/*
- eng/testing/BrowserVersions.props
# Disabled: the perf wasm v8 job installs V8 via jsvu, and the V8 binary it currently
# installs does not support --experimental-wasm-exnref yet, so the MicroBenchmarks Helix
# job aborts at startup. Re-enable once an exnref-capable V8 is pinned. See
# ActiveIssue https://github.com/dotnet/runtime/issues/129849
pr: none

resources:
repositories:
Expand Down
8 changes: 7 additions & 1 deletion eng/pipelines/runtime-linker-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,11 @@ extends:
postBuildSteps:
- template: /eng/pipelines/libraries/execute-trimming-tests-steps.yml
parameters:
extraTestArgs: '/p:WasmBuildNative=false /p:RuntimeFlavor=Mono /p:ToolsConfiguration=Debug'
# Publish the trimmed browser apps, but don't run them on V8: the V8 baked into
# the helix-webassembly container doesn't support --experimental-wasm-exnref yet,
# so run-v8.sh aborts at startup. SkipTrimmingTestsRun keeps the build/publish
# coverage and only skips ExecuteApplications. Re-enable the run once the new V8
# image is available. See
# ActiveIssue https://github.com/dotnet/runtime/issues/129849
extraTestArgs: '/p:WasmBuildNative=false /p:RuntimeFlavor=Mono /p:ToolsConfiguration=Debug /p:SkipTrimmingTestsRun=true'
runAotTests: false
1 change: 1 addition & 0 deletions eng/pipelines/runtime-llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pr:
- src/mono/mono/mini/mini-exceptions.*
- src/mono/mono/mini/exceptions-*.*
- src/mono/mono/mini/mini-runtime.*
- src/mono/mono/metadata/assembly-load-context.*

variables:
- template: /eng/pipelines/common/variables.yml
Expand Down
3 changes: 2 additions & 1 deletion eng/pipelines/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,8 @@ extends:
extraBuildArgs: /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS)
scenarios:
- WasmTestOnFirefox
- WasmTestOnV8
# ActiveIssue https://github.com/dotnet/runtime/issues/129849
# - WasmTestOnV8

# EAT Library tests - only run on linux
- template: /eng/pipelines/common/templates/wasm-library-aot-tests.yml
Expand Down
6 changes: 3 additions & 3 deletions eng/testing/BrowserVersions.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<linux_ChromeVersion>149.0.7827.53</linux_ChromeVersion>
<linux_ChromeRevision>1625079</linux_ChromeRevision>
<linux_ChromeBaseSnapshotUrl>https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1625084</linux_ChromeBaseSnapshotUrl>
<linux_V8Version>14.9.207</linux_V8Version>
<linux_V8Version>15.1.103</linux_V8Version>
<macos_ChromeVersion>143.0.7499.40</macos_ChromeVersion>
<macos_ChromeRevision>1536371</macos_ChromeRevision>
<macos_ChromeBaseSnapshotUrl>https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/1536376</macos_ChromeBaseSnapshotUrl>
<macos_V8Version>14.3.127</macos_V8Version>
<macos_V8Version>15.1.103</macos_V8Version>
<win_ChromeVersion>150.0.7871.24</win_ChromeVersion>
<win_ChromeRevision>1639810</win_ChromeRevision>
<win_ChromeBaseSnapshotUrl>https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/1639827</win_ChromeBaseSnapshotUrl>
<win_V8Version>15.0.245</win_V8Version>
<win_V8Version>15.1.103</win_V8Version>
<linux_FirefoxRevision>140.11.0esr</linux_FirefoxRevision>
<linux_GeckoDriverRevision>0.37.0</linux_GeckoDriverRevision>
<win_FirefoxRevision>140.11.0esr</win_FirefoxRevision>
Expand Down
2 changes: 1 addition & 1 deletion eng/testing/WasmRunnerTemplate.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if /I [%XHARNESS_COMMAND%] == [test] (
)

if [%JS_ENGINE_ARGS%] == [] (
set "JS_ENGINE_ARGS=--engine-arg^=--stack-trace-limit^=1000"
set "JS_ENGINE_ARGS=--engine-arg^=--stack-trace-limit^=1000 --engine-arg^=--experimental-wasm-exnref"
)
) else (
if /I [%SCENARIO%] == [WasmTestOnChrome] (
Expand Down
2 changes: 1 addition & 1 deletion eng/testing/WasmRunnerTemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then
fi

if [[ -z "$JS_ENGINE_ARGS" ]]; then
JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000"
JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000 --engine-arg=--experimental-wasm-exnref"
Comment thread
akoeplinger marked this conversation as resolved.
fi
else
if [[ "$SCENARIO" == "WasmTestOnChrome" || "$SCENARIO" == "wasmtestonchrome" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion eng/testing/linker/trimmingTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
DependsOnTargets="PublishTrimmedProjects"
Inputs="%(TestConsoleApps.Identity)"
Outputs="_unused"
Condition="'$(ArchiveTests)' != 'true'">
Condition="'$(ArchiveTests)' != 'true' and '$(SkipTrimmingTestsRun)' != 'true'">

<Message Importance="High" Text="[Trimming Tests] Running test: %(TestConsoleApps.ProjectCompileItems) ..." />
<Exec IgnoreExitCode="true" Command="%(TestConsoleApps.TestCommand)" StandardOutputImportance="Low" WorkingDirectory="%(TestConsoleApps.TestExecutionDirectory)">
Expand Down
4 changes: 2 additions & 2 deletions src/mono/browser/browser.proj
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@

<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -DDEBUG=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(WasmEnableExceptionHandling)' != 'false'">$(CMakeConfigurationEmccFlags) -fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(WasmEnableExceptionHandling)' != 'false'">$(CMakeConfigurationEmccFlags) -fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(WasmEnableExceptionHandling)' == 'false'">$(CMakeConfigurationEmccFlags) -fexceptions</CMakeConfigurationEmccFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags) -s ASSERTIONS=1 </CMakeConfigurationLinkFlags>
Expand All @@ -335,7 +335,7 @@
<CMakeConfigurationLinkFlags Condition="'$(WasmEnableSIMD)' == 'true'">$(CMakeConfigurationLinkFlags) -msimd128</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(WasmEnableThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(WasmEnableExceptionHandling)' != 'false'">$(CMakeConfigurationLinkFlags) -fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(WasmEnableExceptionHandling)' != 'false'">$(CMakeConfigurationLinkFlags) -fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(WasmEnableExceptionHandling)' == 'false'">$(CMakeConfigurationLinkFlags) -fexceptions</CMakeConfigurationLinkFlags>

<CMakeConfigurationEmsdkPath Condition="'$(Configuration)' == 'Release'"> -DEMSDK_PATH=&quot;$(EMSDK_PATH.TrimEnd('\/').Replace('\','/'))&quot;</CMakeConfigurationEmsdkPath>
Expand Down
3 changes: 2 additions & 1 deletion src/mono/browser/build/BrowserWasmApp.CoreCLR.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<WasmEnableSIMD>true</WasmEnableSIMD>
<WasmClang>emcc</WasmClang>

<_WasmDefaultFlags>-fwasm-exceptions -msimd128</_WasmDefaultFlags>
<_WasmDefaultFlags>-fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0 -msimd128</_WasmDefaultFlags>

<WasmBuildAppAfterThisTarget Condition="'$(WasmBuildAppAfterThisTarget)' == ''">Build</WasmBuildAppAfterThisTarget>
<WasmTriggerPublishAppAfterThisTarget Condition="'$(WasmTriggerPublishAppAfterThisTarget)' == ''">Publish</WasmTriggerPublishAppAfterThisTarget>
Expand Down Expand Up @@ -465,6 +465,7 @@
<_EmccCommonFlags Include="-v" Condition="'$(EmccVerbose)' == 'true'" />
<_EmccCommonFlags Include="-g" Condition="'$(WasmNativeDebugSymbols)' == 'true'" />
<_EmccCommonFlags Include="-fwasm-exceptions" />
<_EmccCommonFlags Include="-sWASM_LEGACY_EXCEPTIONS=0" />
<_EmccCommonFlags Include="-msimd128" />
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions src/mono/browser/build/BrowserWasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<WasmClang>emcc</WasmClang>

<_WasmDefaultFlags Condition="'$(WasmEnableExceptionHandling)' == 'false'">-fexceptions</_WasmDefaultFlags>
<_WasmDefaultFlags Condition="'$(WasmEnableExceptionHandling)' != 'false'">-fwasm-exceptions -s WASM_LEGACY_EXCEPTIONS=1</_WasmDefaultFlags>
<_WasmDefaultFlags Condition="'$(WasmEnableExceptionHandling)' != 'false'">-fwasm-exceptions -s WASM_LEGACY_EXCEPTIONS=0</_WasmDefaultFlags>
<_WasmDefaultFlags Condition="'$(WasmEnableSIMD)' == 'true'">$(_WasmDefaultFlags) -msimd128</_WasmDefaultFlags>

<_WasmOutputFileName Condition="'$(WasmSingleFileBundle)' != 'true'">dotnet.native.wasm</_WasmOutputFileName>
Expand Down Expand Up @@ -181,7 +181,7 @@
<_EmccCommonFlags Include="-fexceptions" Condition="'$(WasmEnableExceptionHandling)' == 'false'" />
<_EmccCommonFlags Include="-s DISABLE_EXCEPTION_CATCHING=0" Condition="'$(WasmEnableExceptionHandling)' == 'false'" />
<_EmccCommonFlags Include="-fwasm-exceptions" Condition="'$(WasmEnableExceptionHandling)' == 'true'" />
<_EmccCommonFlags Include="-s WASM_LEGACY_EXCEPTIONS=1" Condition="'$(WasmEnableExceptionHandling)' == 'true'" />
<_EmccCommonFlags Include="-s WASM_LEGACY_EXCEPTIONS=0" Condition="'$(WasmEnableExceptionHandling)' == 'true'" />
<_EmccCommonFlags Include="-s MAXIMUM_MEMORY=$(EmccMaximumHeapSize)" Condition="'$(EmccMaximumHeapSize)' != ''" />

<_EmccIncludePaths Include="$(_WasmIntermediateOutputPath.TrimEnd('\/'))" />
Expand Down Expand Up @@ -470,7 +470,7 @@

<WriteLinesToFile
File="$(WasmRunV8ScriptPath)"
Lines="$(V8ScriptShebang);v8 $(_WasmMainJSFileName) -- ${RUNTIME_ARGS} --run $(WasmMainAssemblyFileName) $*"
Lines="$(V8ScriptShebang);v8 --experimental-wasm-exnref $(_WasmMainJSFileName) -- ${RUNTIME_ARGS} --run $(WasmMainAssemblyFileName) $*"
Overwrite="true">
</WriteLinesToFile>

Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ set(ignoreMeEmsdkPath "${EMSDK_PATH}")

if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(TARGET dotnet.native
POST_BUILD COMMAND ${EMSDK_PATH}/bin/wasm-opt --enable-exception-handling --enable-multivalue --enable-simd --enable-bulk-memory --enable-nontrapping-float-to-int ${CONFIGURATION_WASM_OPT_FLAGS} --strip-dwarf ${NATIVE_BIN_DIR}/dotnet.native.wasm -o ${NATIVE_BIN_DIR}/dotnet.native.wasm
POST_BUILD COMMAND ${EMSDK_PATH}/bin/wasm-opt --enable-exception-handling --enable-reference-types --enable-multivalue --enable-simd --enable-bulk-memory --enable-nontrapping-float-to-int ${CONFIGURATION_WASM_OPT_FLAGS} --strip-dwarf ${NATIVE_BIN_DIR}/dotnet.native.wasm -o ${NATIVE_BIN_DIR}/dotnet.native.wasm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the connection between --enable-reference-types and exception handling?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebAssembly's exception handling final proposal uses an exnref value (a reference to an exception) to carry exception state

COMMENT "Stripping debug symbols from dotnet.native.wasm using wasm-opt")
endif()

Expand Down
33 changes: 21 additions & 12 deletions src/mono/browser/runtime/jiterpreter-jit-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ export function mono_interp_flush_jitcall_queue (): void {
return;
}

if (builder.options.enableWasmEh) {
if (!runtimeHelpers.featureWasmEh) {
if (builder.options.enableWasmFinalEh) {
if (!runtimeHelpers.featureWasmFinalEh) {
// The user requested to enable wasm EH but it's not supported, so turn the option back off
applyOptions(<any>{ enableWasmEh: false });
builder.options.enableWasmEh = false;
applyOptions(<any>{ enableWasmFinalEh: false });
builder.options.enableWasmFinalEh = false;
}
}

Expand Down Expand Up @@ -639,10 +639,16 @@ function generate_wasm_body (
): boolean {
let stack_index = 0;

// If wasm EH is enabled we will perform the call inside a catch-all block and set a flag
// if it throws any exception
if (builder.options.enableWasmEh)
builder.block(WasmValtype.void, WasmOpcode.try_);
// If wasm EH is enabled we perform the call inside a try_table (standardized exnref proposal)
// and set a flag if it throws a C++ exception. Structure:
// (block $outer (block $catch (result i32) (try_table (catch __cpp_exception $catch) <body>) br $outer) <handler>)
if (builder.options.enableWasmFinalEh) {
builder.block(WasmValtype.void); // $outer
builder.block(WasmValtype.i32); // $catch - receives the exception pointer
// try_table catch labels are resolved in the scope surrounding the try_table (its own
// block label is not counted), so depth 0 targets the immediately-enclosing $catch block.
builder.tryTable(WasmValtype.void, "__cpp_exception", 0); // catch __cpp_exception -> $catch
}

// Wrapper signature: [thisptr], [&retval], &arg0, ..., &funcdef
// Desired stack layout for direct calls: [&retval], [thisptr], arg0, ..., &rgctx
Expand Down Expand Up @@ -779,17 +785,20 @@ function generate_wasm_body (
}

// If the call threw a JS or wasm exception, set the thrown flag
if (builder.options.enableWasmEh) {
builder.appendU8(WasmOpcode.catch_);
builder.appendULeb(builder.getTypeIndex("__cpp_exception"));
if (builder.options.enableWasmFinalEh) {
builder.endBlock(); // end try_table
// Normal completion (no exception): skip the handler by branching out to $outer
builder.appendU8(WasmOpcode.br);
builder.appendULeb(1);
builder.endBlock(); // end $catch - reached only when caught, stack: [exception ptr]
builder.callImport("begin_catch");
builder.callImport("end_catch");
builder.local("thrown");
builder.i32_const(1);
builder.appendU8(WasmOpcode.i32_store);
builder.appendMemarg(0, 2);

builder.endBlock();
builder.endBlock(); // end $outer
}

builder.appendU8(WasmOpcode.return_);
Expand Down
7 changes: 2 additions & 5 deletions src/mono/browser/runtime/jiterpreter-opcodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ export const enum WasmOpcode {
if_,
else_,

try_ = 0x06,
catch_,
catch_all = 0x19,
throw_ = 0x08,
rethrow_ = 0x09,
throw_ref = 0x0a,
try_table = 0x1f,

end = 0x0b,
br,
Expand Down
Loading
Loading