Skip to content

Commit

Permalink
Merge branch 'main' into browser_mt_disable_jiterp
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf authored Mar 23, 2024
2 parents 0dd10d6 + a264a7e commit fabec2b
Show file tree
Hide file tree
Showing 71 changed files with 5,622 additions and 3,579 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"microsoft.dotnet.xharness.cli": {
"version": "9.0.0-prerelease.24161.1",
"version": "9.0.0-prerelease.24168.2",
"commands": [
"xharness"
]
Expand Down
42 changes: 21 additions & 21 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,43 @@

/src/mono @marek-safar

/src/mono/llvm @vargaz @steveisok
/src/mono/llvm @lambdageek @steveisok

/src/mono/mono/arch @vargaz
/src/mono/mono/eglib @vargaz @lambdageek
/src/mono/mono/arch @lambdageek @steveisok
/src/mono/mono/eglib @lambdageek @steveisok

/src/mono/mono/metadata @vargaz @lambdageek @thaystg
/src/mono/mono/metadata @lambdageek @thaystg
/src/mono/mono/metadata/*-win* @lateralusX @lambdageek
/src/mono/mono/metadata/handle* @lambdageek @vargaz
/src/mono/mono/metadata/monitor* @brzvlad @vargaz
/src/mono/mono/metadata/sgen* @brzvlad @vargaz @lambdageek
/src/mono/mono/metadata/handle* @lambdageek @steveisok
/src/mono/mono/metadata/monitor* @brzvlad @steveisok
/src/mono/mono/metadata/sgen* @brzvlad @lambdageek
/src/mono/mono/metadata/thread* @lateralusX @lambdageek
/src/mono/mono/metadata/w32* @lateralusX @lambdageek

/src/mono/mono/eventpipe @lateralusX @lambdageek

/src/mono/mono/mini @vargaz @lambdageek @steveisok
/src/mono/mono/mini/*cfgdump* @vargaz
/src/mono/mono/mini/*exceptions* @vargaz @BrzVlad
/src/mono/mono/mini/*llvm* @vargaz @fanyang-mono
/src/mono/mono/mini/*ppc* @vargaz
/src/mono/mono/mini @lambdageek @steveisok
/src/mono/mono/mini/*cfgdump* @lambdageek
/src/mono/mono/mini/*exceptions* @BrzVlad
/src/mono/mono/mini/*llvm* @fanyang-mono @steveisok
/src/mono/mono/mini/*ppc* @lambdageek
/src/mono/mono/mini/*profiler* @BrzVlad @lambdageek
/src/mono/mono/mini/*riscv* @vargaz @lambdageek
/src/mono/mono/mini/*type-check* @lambdageek
/src/mono/mono/mini/debugger-agent.c @vargaz @thaystg @lambdageek
/src/mono/mono/mini/interp/* @BrzVlad @vargaz @kotlarmilos
/src/mono/mono/mini/*riscv* @lambdageek @steveisok
/src/mono/mono/mini/*type-check* @lambdageek @steveisok
/src/mono/mono/mini/debugger-agent.c @thaystg @lambdageek
/src/mono/mono/mini/interp/* @BrzVlad @kotlarmilos
/src/mono/mono/mini/interp/*jiterp* @kg
/src/mono/mono/mini/*simd* @fanyang-mono

/src/mono/mono/profiler @BrzVlad @lambdageek
/src/mono/mono/sgen @BrzVlad @lambdageek

/src/mono/mono/utils @vargaz @lambdageek
/src/mono/mono/utils @lambdageek @steveisok
/src/mono/mono/utils/*-win* @lateralusX @lambdageek
/src/mono/mono/utils/atomic* @vargaz
/src/mono/mono/utils/mono-hwcap* @vargaz
/src/mono/mono/utils/mono-mem* @vargaz
/src/mono/mono/utils/mono-threads* @lambdageek @vargaz
/src/mono/mono/utils/atomic* @lambdageek @steveisok
/src/mono/mono/utils/mono-hwcap* @lambdageek
/src/mono/mono/utils/mono-mem* @lambdageek @steveisok
/src/mono/mono/utils/mono-threads* @lambdageek

/src/mono/dlls @thaystg @lambdageek

Expand Down
13 changes: 6 additions & 7 deletions .github/policies/resourceManagement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ configuration:
then:
- mentionUsers:
mentionees:
- SamMonoRT
- vargaz
- lambdageek
- steveisok
replyTemplate: >-
Tagging subscribers to this area: ${mentionees}
Expand All @@ -187,8 +187,8 @@ configuration:
then:
- mentionUsers:
mentionees:
- SamMonoRT
- vargaz
- lambdageek
- steveisok
replyTemplate: >-
Tagging subscribers to this area: ${mentionees}
Expand All @@ -200,8 +200,8 @@ configuration:
then:
- mentionUsers:
mentionees:
- SamMonoRT
- fanyang-mono
- steveisok
replyTemplate: >-
Tagging subscribers to this area: ${mentionees}
Expand All @@ -213,8 +213,7 @@ configuration:
then:
- mentionUsers:
mentionees:
- SamMonoRT
- vargaz
- steveisok
- lambdageek
replyTemplate: >-
Tagging subscribers to this area: ${mentionees}
Expand Down
12 changes: 6 additions & 6 deletions docs/area-owners.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Note: Editing this file doesn't update the mapping used by `@msftbot` for area-s
| area-AssemblyLoader-mono | @agocke | @agocke @elinor-fung | |
| area-Build-mono | @lewing | @akoeplinger | |
| area-Codeflow | @dotnet/dnr-codeflow | @dotnet/dnr-codeflow | Used for automated PRs that ingest code from other repos |
| area-Codegen-AOT-mono | @steveisok | @vargaz @kotlarmilos | |
| area-Codegen-AOT-mono | @steveisok | @kotlarmilos | |
| area-CodeGen-coreclr | @JulieLeeMSFT | @BruceForstall @dotnet/jit-contrib | |
| area-Codegen-Interpreter-mono | @vitek-karas | @BrzVlad @kotlarmilos | |
| area-Codegen-Intrinsics-mono | @steveisok | @fanyang-mono | |
| area-Codegen-JIT-mono | @steveisok | @vargaz | |
| area-Codegen-LLVM-mono | @steveisok | @vargaz | |
| area-Codegen-meta-mono | @steveisok | @vargaz | |
| area-Codegen-JIT-mono | @steveisok | | |
| area-Codegen-LLVM-mono | @steveisok | | |
| area-Codegen-meta-mono | @steveisok | | |
| area-CrossGen/NGEN-coreclr | @steveisok | @dotnet/crossgen-contrib | |
| area-crossgen2-coreclr | @steveisok | @dotnet/crossgen-contrib | |
| area-Debugger-mono | @tommcdon | @thaystg | |
Expand Down Expand Up @@ -167,9 +167,9 @@ Note: Editing this file doesn't update the mapping used by `@msftbot` for area-s
| os-android | @vitek-karas | @akoeplinger | |
| os-freebsd | | @wfurt @Thefrank @sec | |
| os-maccatalyst | @vitek-karas | @kotlarmilos | |
| os-ios | @vitek-karas | @vargaz, @kotlarmilos | |
| os-ios | @vitek-karas | @kotlarmilos | |
| os-tizen | @gbalykov | @dotnet/samsung | |
| os-tvos | @vitek-karas | @vargaz, @kotlarmilos | |
| os-tvos | @vitek-karas | @kotlarmilos | |
| os-wasi | @lewing | @pavelsavara | |
| os-browser | @lewing | @pavelsavara | |

Expand Down
144 changes: 144 additions & 0 deletions docs/design/mono/aot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Ahead of Time Compilation

## Introduction

The mono Ahead of Time (AOT) compiler enables the compilation of the IL code in a .NET assembly to
a native object file. This file is called an AOT image. This AOT image can be used by the runtime to avoid
having to JIT the IL code.

## Usage

The AOT compiler is integrated into the mono runtime executable, and can be run using the `--aot` command
line argument, i.e.
`<mono-executable> --aot HelloWorld.dll`

## Source code structure

- `aot-compiler.c`: The AOT compiler
- `aot-runtime.c`: Code used at runtime to load AOT images
- `image-writer.c`: Support code for emitting textual assembly
- `dwarfwriter.c`: Support code for emitting DWARF debug info

## Configurations

### Desktop AOT

In this mode, the AOT compiler creates a platform shared object file (.so/.dylib), i.e. `HelloWorld.dll.so`. During execution, when
an assembly is loaded, the runtime loads the corresponding shared object and uses it to avoid having to AOT the methods in the
assembly.

Emission of the native code is done by first emitting an assembly (.s) file, then compiling and linking it with the system tools
(`as`/`ld`, or `clang`).

### Static AOT

In this mode, the AOT compiler creates a platform object file (.o). This file needs to be linked into the application and registered
with the runtime.

Static compilation is enabled by using the `static` aot option, i.e. `--aot=static,...`. The resulting object file contains a linking
symbol named `mono_aot_module_<assembly name>_info`. This symbol needs to be passed to the a runtime function before the
runtime is initialized, i.e.:
`mono_aot_register_module (mono_aot_module_HelloWorld_info);`

### Full AOT

In this mode, which can be combined with the other modes, the compiler generates additional code which enables the runtime to
function without any code being generated at runtime. This includes 2 types of code:
- code for 'extra' methods, i.e. generic instances, runtime generated wrappers methods, etc.
- trampolines

This is enabled by using `full` aot option, i.e. `--aot=full,...`. At runtime, all assemblies need to have a full-aot-ed AOT image
present in order for the app to work. This is used on platforms which don't allow runtime code generation like IOS.

### LLVM support

LLVM support can be enabled using the `llvm` aot option, i.e. `--aot=llvm`. In this mode, instead of generating native code,
the AOT compiler generates an LLVM bitcode (.bc), file, then compiles it to native code using the `opt`/`llc` LLVM tools. The
various AOT data structures are also emitted into the .bc file instead of as assembly.
Since the LLVM backend currently doesn't support all .net methods, a smaller assembly file is still emitted, and linked together
with the `opt`/`llc` compiled object file into the final shared object file.

## Versioning

The generated AOT images have a dependency on the exact version input assembly used to generate them and the versions of all the
referenced assemblies. This means the GUIDs of the assemblies have to match. If there is a mismatch, the AOT image will fail to load.

## File structure

The AOT images exports one symbol named `mono_aot_module_<assembly name>_info` which points to a `MonoAotFileInfo` structure,
which contains pointers to the tables/structures. The AOT image contains:
- the native code
- data structures required to load the code
- cached data intended to speed up runtime operation

The AOT image contains serialized versions of many .NET objects like methods/types etc. This uses ad-hoc binary encodings.

## Runtime support

The `aot-runtime.c` file contains the runtime support for loading AOT images.

### Loading AOT images

When an assembly is loaded, the corresponding AOT images is either loaded using the system dynamic linker (`dlopen`), or
found among the statically linked AOT images.

### Loading methods

Every method in the AOT image is assigned an index. The AOT methods corresponding to 'normal' .NET methods are assigned
an index corresponding to their metadata token index, while the 'extra' methods are assigned subsequent indexes. There is
a hash table inside the AOT image mapping extra methods to their AOT indexes. Loading a method consists of
- finding its method index
- finding the method code/data corresponding to the method index

The mapping from method index to the code is done in an architecture specific way, designed to minimize the amount of
runtime relocations in the AOT image. In some cases, this involves generating an extra table with assembly call instructions to
all the methods, then disassembling this table at runtime.



### Runtime constants

The generated code needs to access data which is only available at runtime. For example, for an `ldstr "Hello"` instruction, the
`"Hello"` string is a runtime constant.

These constants are stored in a global table called the GOT which is modelled after the Global Offset Table in ELF images. The GOT
table contains pointers to runtime objects. The AOT image contains descriptions of these runtime objects so the AOT runtime can
compute them. The entries in the GOT are initialized either when the AOT image is loaded (for frequently used entries), or before
the method which uses them is first executed.

### Initializing methods

Before an AOTed method can be executed, it might need some initialization. This involves:
- executing its class cctor
- initializing the GOT slots used by the method

For methods compiled by the mono JIT, initialization is done when the method is loaded. This means that its not possible to
have direct calls between methods. Instead, calls between methods go through small pieces of generated code called PLT
(Program Linkage Table) entries, which transfer control to the runtime which loads the called method before executing it.
For methods compiled by LLVM, the method entry contains a call to the runtime which initializes the method.

## Trampolines

In full-aot mode, the AOT compiler needs to emit all the trampolines which will be used at runtime. This is done in
the following way:
- For most trampolines, the AOT compiler calls the normal trampoline creation function with the `aot` argument set
to TRUE, then saves the returned native code into the AOT image, along with some relocation information like the
GOT slots used by the trampolines.
- For some small trampolines, the AOT compiler directly emits platform specific assembly.

The runtime might require an unbounded number of certain trampolines, but the AOT image can only contain a fixed
number of them. To solve this problem, on some platforms (IOS), its possible to have infinite trampolines. This is
implemented by emitting a different version of these trampolines which reference their corresponding data using
relative addressing. At runtime, a page of these trampolines is mapped using `mmap` next to a writable page
which contains their corresponding data. The same page of trampolines is mapped multiple times at multiple
addresses.

## Cross compilation

Its possible to use the AOT compiler to target a platform different than the host. This requires a separate cross compiler
build of the runtime.
The generated code depends on offsets inside runtime structures like `MonoClass`/`MonoVTable` etc. which could
differ between the host and the target. This is handled by having a tool called the offsets-tool, which is a python
script which uses the clang python interface to compute and emit a C header file containing these offsets. The header
file is passed as a cmake argument during the runtime build. Inside the runtime code, the `MONO_STRUCT_OFFSET`
C macro reads the data from the offsets file to produce the offset corresponding to the target platform.
Loading

0 comments on commit fabec2b

Please sign in to comment.