Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dotnet/runtime into gs-cookie-bb
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Oct 15, 2023
2 parents 19ec2c0 + 3e0afa6 commit 2a51d98
Show file tree
Hide file tree
Showing 498 changed files with 6,473 additions and 3,107 deletions.
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Design Docs

- [.NET Globalization Invariant Mode](design/features/globalization-invariant-mode.md)
- [WASM Globalization Icu](design/features/globalization-icu-wasm.md)
- [Cross-Platform Cryptography](design/features/cross-platform-cryptography.md)
- Many more under [design/features](design/features/)

The Book of the Runtime is a set of chapters that go in depth into various
Expand Down
35 changes: 10 additions & 25 deletions docs/workflow/building/libraries/webassembly-instructions.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
# Build for WebAssembly
# Build libraries for WebAssembly

## Prerequisites

If you haven't already done so, please read [this document](../../README.md#Build_Requirements) to understand the build requirements for your operating system.

The **correct version** of Emscripten SDK (emsdk) needs to be installed.
* Run `make -C src/mono/wasm provision-wasm` to install emsdk into `src/mono/wasm/emsdk`.
* Alternatively follow the [installation guide](https://emscripten.org/docs/getting_started/downloads.html#sdk-download-and-install).
Do not install `latest` but rather specific version e.g. `./emsdk install 2.0.23`. See [emscripten-version.txt](../../../../src/mono/wasm/emscripten-version.txt)
## Building

Once installed the `EMSDK_PATH` environment variable needs to be set:

On Linux and macOS:

```bash
export EMSDK_PATH=<FULL_PATH_TO_SDK_INSTALL>/emsdk
```

## Building everything

At this time no other build dependencies are necessary to start building for WebAssembly.
At this time no other build dependencies are necessary to start building for WebAssembly. Emscripten will be downloaded and installed automatically in the build process. To read how to build on specific platforms, see [Building](../../../../src/mono/wasm/README.md#building).

This document explains how to work on the runtime or libraries. If you haven't already done so, please read [this document](../../README.md#Configurations) to understand configurations.

For Linux and macOS:

```bash
./build.sh -os browser -configuration Release
```

Artifacts will be placed in `artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/`. When rebuilding with `build.sh` after a code change, you need to ensure that the `mono.wasmruntime` and `libs.pretest` subsets are included even for a Mono-only change or this directory will not be updated (details below).
When rebuilding with `build.sh` after a code change, you need to ensure that the `mono.wasmruntime` and `libs.pretest` subsets are included even for a Mono-only change or this directory will not be updated (details below).

### Note: do not mix runtime and library configurations

At this time, it is not possible to specify different configurations for the runtime and libraries. That is mixing a Release `-runtimeConfiguration` with a Debug `-libraryConfiguration` (or `-configuration`), or vice versa will not work.
At this time, it is not possible to specify different configurations for the runtime and libraries. That is mixing a Release `-runtimeConfiguration` with a Debug `-libraryConfiguration` (or `-configuration`), or vice versa will not work. The same applies to single and multithreaded configurations.

Please only use the `-configuration` option with `Debug` or `Release`, and do not specify a `-runtimeConfiguration` and `-libraryConfiguration`.

Expand Down Expand Up @@ -68,7 +49,7 @@ Building both Mono/System.Private.CoreLib and the managed libraries:

## Building the WebAssembly runtime files

The WebAssembly implementation files are built after the libraries source build and made available in the artifacts folder. If you are working on the code base and need to compile just these modules then building the `Mono.WasmRuntime` subset will allow one to do that:
The WebAssembly implementation files are built after the libraries source build and made available in the artifacts folder. If you are working on the code base and need to compile just these modules then building the `Mono.WasmRuntime` subset will allow one to do that:

```bash
./build.sh mono.wasmruntime -os browser -c Debug|Release
Expand Down Expand Up @@ -174,3 +155,7 @@ container:
```

Open a PR request with the new image.

# Test libraries

You can read about running library tests in [Libraries tests](../../../../src/mono/wasm/README.md#libraries-tests).
2 changes: 1 addition & 1 deletion docs/workflow/building/mono/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The build has a number of options that you can learn about using build -?.

### WebAssembly

See the instructions for [Building WebAssembly](../../building/libraries/webassembly-instructions.md).
See the instructions for [Building WebAssembly](../../../../src/mono/wasm/README.md).

### Android

Expand Down
84 changes: 84 additions & 0 deletions docs/workflow/debugging/mono/wasm-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,87 @@ C @ blazor.webassembly.js:1
dispatchGlobalEventToAllElements @ blazor.webassembly.js:1
onGlobalEvent @ blazor.webassembly.js:1
```

# Enabling additional logging in Blazor

In .NET 8+, Blazor startup can be controlled by setting the `autostart="false"` attribute on the
`<script>` tag that loads the blazor webassembly framework. After that, a call to the
`globalThis.Blazor.start()` JavaScript function can be passed additional configuration options,
including setting mono environment variables, or additional command line arguments.

The name of the script and the location of the `<script>` tag depends on whether the project was a
Blazor WebAssembly project (template `blazorwasm`) or a Blazor project (template `blazor`).

See the runtime `DotnetHostBuilder` interface in
[dotnet.d.ts](../../../../src/mono/wasm/runtime/dotnet.d.ts) for additional configuration functions.

## Blazor WebAssembly

In a `blazorwasm` project, the script is `_framework/blazor.webassembly.js` and it is loaded in `wwwroot/index.html`:

```html
<body>
<div id="app">
...
</div>

<div id="blazor-error-ui">
...
</div>
<script src="_framework/blazor.webassembly.js"></script>
</body>
```

Replace it with this:

```html
<body>
<div id="app">
...
</div>

<div id="blazor-error-ui">
...
</div>
<script src="_framework/blazor.webassembly.js" autostart="false"></script>

<script>
Blazor.start({
configureRuntime: dotnet => {
dotnet.withEnvironmentVariable("MONO_LOG_LEVEL", "debug");
dotnet.withEnvironmentVariable("MONO_LOG_MASK", "all");
}
});
</script></body>
```

## Blazor

In a `blazor` project, the script is `_framework/blazor.web.js` and it is loaded by `Components/App.razor` in the server-side project:

```html
<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>
```

Replace it with this (note that for a `blazor` project, `Blazor.start` needs an extra dictionary with a `webAssembly` key):

```html
<body>
<Routes />
<script src="_framework/blazor.web.js" autostart="false"></script>
<script>
Blazor.start({
webAssembly: {
configureRuntime: dotnet => {
console.log("in configureRuntime");
dotnet.withEnvironmentVariable("MONO_LOG_LEVEL", "debug");
dotnet.withEnvironmentVariable("MONO_LOG_MASK", "all");
}
}
});
</script>
</body>
```
4 changes: 2 additions & 2 deletions eng/testing/performance/performance-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ if [[ "$physicalpromotion" == "true" ]]; then
configurations="$configurations PhysicalPromotionType=physicalpromotion"
fi

if [[ "${hybridglobalization,,}" == "true" ]]; then # convert to lowercase to test
if [[ "$(echo "$hybridglobalization" | tr '[:upper:]' '[:lower:]')" == "true" ]]; then # convert to lowercase to test
configurations="$configurations HybridGlobalization=True" # Force True for consistency
fi

Expand Down Expand Up @@ -421,7 +421,7 @@ if [[ -n "$wasm_bundle_directory" ]]; then
using_wasm=true
wasm_bundle_directory_path=$payload_directory
mv $wasm_bundle_directory/* $wasm_bundle_directory_path
wasm_args="--experimental-wasm-eh --expose_wasm"
wasm_args="--expose_wasm"
if [ "$javascript_engine" == "v8" ]; then
# for es6 module support
wasm_args="$wasm_args --module"
Expand Down
87 changes: 75 additions & 12 deletions src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,6 @@ void BasicBlock::dspFlags()
{
printf("failV ");
}
if (bbFlags & BBF_TRY_BEG)
{
printf("try ");
}
if (bbFlags & BBF_RUN_RARELY)
{
printf("rare ");
Expand Down Expand Up @@ -613,15 +609,35 @@ void BasicBlock::dspJumpKind()
switch (bbJumpKind)
{
case BBJ_EHFINALLYRET:
{
printf(" ->");

// Early in compilation, we display the jump kind before the BBJ_EHFINALLYRET successors have been set.
if (bbJumpEhf == nullptr)
{
printf(" ????");
}
else
{
const unsigned jumpCnt = bbJumpEhf->bbeCount;
BasicBlock** const jumpTab = bbJumpEhf->bbeSuccs;

for (unsigned i = 0; i < jumpCnt; i++)
{
printf("%c" FMT_BB, (i == 0) ? ' ' : ',', jumpTab[i]->bbNum);
}
}

printf(" (finret)");
break;
}

case BBJ_EHFAULTRET:
printf(" (falret)");
break;

case BBJ_EHFILTERRET:
printf(" (fltret)");
printf(" -> " FMT_BB " (fltret)", bbJumpDest->bbNum);
break;

case BBJ_EHCATCHRET:
Expand Down Expand Up @@ -1065,14 +1081,13 @@ unsigned BasicBlock::NumSucc() const
{
case BBJ_THROW:
case BBJ_RETURN:
case BBJ_EHFINALLYRET:
case BBJ_EHFAULTRET:
case BBJ_EHFILTERRET:
return 0;

case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
case BBJ_EHCATCHRET:
case BBJ_EHFILTERRET:
case BBJ_LEAVE:
case BBJ_NONE:
return 1;
Expand All @@ -1087,6 +1102,23 @@ unsigned BasicBlock::NumSucc() const
return 2;
}

case BBJ_EHFINALLYRET:
// We may call this method before we realize we have invalid IL. Tolerate.
//
if (!hasHndIndex())
{
return 0;
}

// We may call this before we've computed the BBJ_EHFINALLYRET successors in the importer. Tolerate.
//
if (bbJumpEhf == nullptr)
{
return 0;
}

return bbJumpEhf->bbeCount;

case BBJ_SWITCH:
return bbJumpSwt->bbsCount;

Expand All @@ -1112,6 +1144,7 @@ BasicBlock* BasicBlock::GetSucc(unsigned i) const
case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
case BBJ_EHCATCHRET:
case BBJ_EHFILTERRET:
case BBJ_LEAVE:
return bbJumpDest;

Expand All @@ -1126,9 +1159,13 @@ BasicBlock* BasicBlock::GetSucc(unsigned i) const
else
{
assert(i == 1);
assert(bbNext != bbJumpDest);
return bbJumpDest;
}

case BBJ_EHFINALLYRET:
return bbJumpEhf->bbeSuccs[i];

case BBJ_SWITCH:
return bbJumpSwt->bbsDstTab[i];

Expand Down Expand Up @@ -1164,7 +1201,15 @@ unsigned BasicBlock::NumSucc(Compiler* comp)
{
return 0;
}
return comp->fgNSuccsOfFinallyRet(this);

// We may call this before we've computed the BBJ_EHFINALLYRET successors in the importer. Tolerate.
//
if (bbJumpEhf == nullptr)
{
return 0;
}

return bbJumpEhf->bbeCount;

case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
Expand Down Expand Up @@ -1213,15 +1258,14 @@ BasicBlock* BasicBlock::GetSucc(unsigned i, Compiler* comp)
switch (bbJumpKind)
{
case BBJ_EHFILTERRET:
{
// Handler is the (sole) normal successor of the filter.
assert(comp->fgFirstBlockOfHandler(this) == bbJumpDest);
return bbJumpDest;
}

case BBJ_EHFINALLYRET:
// Note: the following call is expensive.
return comp->fgSuccOfFinallyRet(this, i);
assert(bbJumpEhf != nullptr);
assert(i < bbJumpEhf->bbeCount);
return bbJumpEhf->bbeSuccs[i];

case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
Expand All @@ -1240,6 +1284,7 @@ BasicBlock* BasicBlock::GetSucc(unsigned i, Compiler* comp)
else
{
assert(i == 1);
assert(bbNext != bbJumpDest);
return bbJumpDest;
}

Expand Down Expand Up @@ -1645,6 +1690,24 @@ BBswtDesc::BBswtDesc(Compiler* comp, const BBswtDesc* other)
}
}

//------------------------------------------------------------------------
// BBehfDesc copy ctor: copy a EHFINALLYRET descriptor
//
// Arguments:
// comp - compiler instance
// other - existing descriptor to copy
//
BBehfDesc::BBehfDesc(Compiler* comp, const BBehfDesc* other) : bbeCount(other->bbeCount)
{
// Allocate and fill in a new dst tab
//
bbeSuccs = new (comp, CMK_BasicBlock) BasicBlock*[bbeCount];
for (unsigned i = 0; i < bbeCount; i++)
{
bbeSuccs[i] = other->bbeSuccs[i];
}
}

//------------------------------------------------------------------------
// unmarkLoopAlign: Unmarks the LOOP_ALIGN flag from the block and reduce the
// loop alignment count.
Expand Down
Loading

0 comments on commit 2a51d98

Please sign in to comment.