* wasm: add support for most of the conv_ovf operations
i and i_un still to do.
* correct comment
* remove masks, refactor
* address feedback. Refactor to remove some conditions. Change Dbl2ULngOvf to check for negative
* RhpNewArrayAlign8 use non-padded size when going to the slow path and RhpGcAlloc
* remove padding from slow path for RhpNewFastMisalign and RhpNewFastAlign8
* add overflow checks for 32bit host
* #if out align 8 methods for HOST_64BIT. Change overflow check for padding to not use 64 bit arithmetic
* when creating the unqualified mangled name, special case ValueTypeInstanceMethodWithHiddenParameter
* Use IMethodNode to get the physical function name
Reflection-accessing threadstatic fields didn't work.
I'm also deleting a bunch of .NET Native code that is not relevant to CoreRT.
The .NET Native approach to threadstatics (using TLS region) is Windows-specific
and not portable.
The type loader support is incomplete (the compiler side is ready but runtime side is
still going to fail with a MissingTemplateException). I got tired and this diff is already
too big.
Contributes to #5137.
This extends the static constructor interpreter with support for preinitializing delegates and support for reading readonly static fields declared by other types.
The readonly static fields can be accessed after interpreting the static constructor of the containing type. This opens us up to recursive dependencies. The interpreter will bail if recursive dependency is hit (we already have a test).
This significantly improves the interpreter's ability to run static constructors at compile time:
| | Eligible types | Preinitialized before | Preinitialized after |
| -------- | -------------- | --------------------- | -------------------- |
| WinForms | 1520 | 702 | 967 |
| WebApi | 2005 | 746 | 1278 |
About 60% of types now have their static constructor executed at compile time.
When possible, run static constructors at compile time and store the produced data blob in the executable. This eliminates the need to keep the static constructor code around if the type was statically constructed at compile time.
This runs a small interpreter to interpret the static constructor at compile time.
* Besides the easy things (preinitializing primitive-typed fields), this can also preinitialize reference types (classes, arrays). This builds on top of the GC's ability to deal with "frozen objects" (reference type instances allocated within the data section of the executable instead of on the GC heap). There's some limitations of course (e.g no finalizers - these never get garbage collected).
* Can also do things like non-recursive inlining
Of course there's limitations (the static constructor cannot have side effects, cannot do things like p/invoke, etc.), but it works pretty well.
Some results:
| | Types eligible for preinitialization | Types preinitialized |
|----------------------|--------------------------------------|----------------------|
| ASP.NET SampleWebApi | 1991 | 754 |
| Empty WinForms app | 1510 | 709 |
| Console Hello world | 317 | 149 |
Also results in about 0.2% size on disk improvement, but size improvement is not really the point of this optimization.
Current limitations that I want to lift eventually:
* No backwards branches - to avoids jokers putting `while (true) ;` in a static constructors (we can put an upper limit on number of instructions interpreted instead)
* Can't preinitialize delegates, but delegates to static methods should be doable and are pretty common in the ASP.NET codebase.
* Can't access static fields of types other than the one being preinitialized. We should be able to lift this limitations for readonly fields with some care (seems pretty common too).
* We might be able to model `typeof(Foo) == typeof(T)` that shows up sometimes.
* Update compiler from dotnet/runtime
Contains breaking change: NativeCallableAttribute was renamed to UnmanagedCallersOnlyAttribute as part of making it a public attribute.
* Update tests/src/Simple/HelloWasm/Program.cs
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
* reset commits
* add test and initial handling switch for invoke for GVM calls.
* add support for exceptions in GVM calls, and a test
* move wasm specific code to .wasm.cs
* Exclude wasm files from non-wasm platforms
This ensures we copy back byref args. It wasn't possible when this code was originally witten because the IL generator couldn't generate finallys.
Closes#2910.