platform/upstream/dotnet/runtime.git
17 months agoShrink hello world by 3.2% (#84463)
Michal Strehovský [Fri, 7 Apr 2023 06:04:01 +0000 (15:04 +0900)]
Shrink hello world by 3.2% (#84463)

* Get rid of the MethodTable for double/float
* Get rid of any `Array<T>` methods

17 months ago[NativeAOT] Using the same CastCache implementation as in CoreClr (#84430)
Vladimir Sadov [Fri, 7 Apr 2023 02:04:47 +0000 (19:04 -0700)]
[NativeAOT] Using the same CastCache implementation as in CoreClr (#84430)

* Getter

* different limits on debug/release

* tweaks

* remove now unnecessary CrstCastCache

* implement flushing

* move coreclr castcache to a separate file

* Unified CastCache implementation

* comments and cleanups

* couple more cleanups

* trivial implementation of the cast cache for the Test.Corlib

* use Numerics.BitOperations for bit math

17 months agoIntroducing Time abstraction Part2 (down-level support) (#84235)
Tarek Mahmoud Sayed [Fri, 7 Apr 2023 01:59:03 +0000 (18:59 -0700)]
Introducing Time abstraction Part2 (down-level support) (#84235)

17 months agoSimplify numasupport (#84207)
Adeel Mujahid [Thu, 6 Apr 2023 23:23:56 +0000 (02:23 +0300)]
Simplify numasupport (#84207)

* Simplify numasupport

* short-circuit

* Cleanup from QUIC readme

* Address CR feedback: early bail for < 2 NUMA nodes

* Fix node numbering, which is 0-based

17 months agoAdded the ability to specify a Spin Count Unit via a GC Configuration
Mukund Raghav Sharma (Moko) [Thu, 6 Apr 2023 22:56:05 +0000 (15:56 -0700)]
Added the ability to specify a Spin Count Unit via a GC Configuration

Added the ability to specify a Spin Count Unit via a GC Configuration and make use of this value in the SetYieldProcessorScalingFactor function if the value is valid. If this configuration is not specified, we default to 0 and fall back to the original logic.

17 months agoMove startup hook tests targeting `StartupHookProvider` out of hosting tests (#84338)
Elinor Fung [Thu, 6 Apr 2023 22:36:03 +0000 (15:36 -0700)]
Move startup hook tests targeting `StartupHookProvider` out of hosting tests (#84338)

17 months agoJIT: Set GTF_DEBUG_NODE_MORPHED properly in block morph (#84352)
Jakob Botsch Nielsen [Thu, 6 Apr 2023 22:05:19 +0000 (00:05 +0200)]
JIT: Set GTF_DEBUG_NODE_MORPHED properly in block morph (#84352)

With side effects that may go on top, it may be block morph's
responsibility to set this flag.

Also set the type of the reused GT_COMMA nodes; haven't actually seen
any issues here, but seems prudent to do this.

Fixes some stress issues seen over in #83771.

17 months agoFix eventpipe/enabledisable.cs test on Android (#84409)
Alexander Köplinger [Thu, 6 Apr 2023 21:51:02 +0000 (23:51 +0200)]
Fix eventpipe/enabledisable.cs test on Android (#84409)

It needs the same customization that we have in IpcTraceTest.cs

17 months agoCorrectly display the GCSettings specified in the runtimeconfig json via the GC Confi...
Mukund Raghav Sharma (Moko) [Thu, 6 Apr 2023 21:47:56 +0000 (14:47 -0700)]
Correctly display the GCSettings specified in the runtimeconfig json via the GC Configuration API Call  (#84201)

Fixes #84198 by honoring the user specified GC Configuration by appropriately setting the Configuration obtained from both the Environment Variables and the JSON Configuration.

17 months agoadded explanation to more GC data structures (#84162)
Maoni Stephens [Thu, 6 Apr 2023 21:19:36 +0000 (14:19 -0700)]
added explanation to more GC data structures (#84162)

+ added explanation to generation, dynamic_data and heap_segment, especially to mention which fields will need to be taken care of if we change the heap count
+ removed the unused pinned_allocated field from generation

17 months agoUnit tests should re-enable BinaryFormatter for compat testing (#84437)
Levi Broderick [Thu, 6 Apr 2023 21:09:21 +0000 (14:09 -0700)]
Unit tests should re-enable BinaryFormatter for compat testing (#84437)

17 months ago[mono][jit] Revert parts of '[mono] Remove the support for non r4fp, its not used...
Zoltan Varga [Thu, 6 Apr 2023 21:03:51 +0000 (17:03 -0400)]
[mono][jit] Revert parts of '[mono] Remove the support for non r4fp, its not used by any supported platforms. (#82005)' (#84418)

Some platforms don't support r4fp, so put back the general JIT support code.
Force r4fp on platforms that support it.

Fixes https://github.com/dotnet/runtime/issues/84401.

17 months ago[RISC-V] Port Mono for RISC-V 64 Arch (3/3) IL Lowering & Outputting (#83716)
VincentWu [Thu, 6 Apr 2023 21:02:41 +0000 (05:02 +0800)]
[RISC-V] Port Mono for RISC-V 64 Arch (3/3) IL Lowering & Outputting (#83716)

* IL lowering & output

* add blank line at end of file

* format

17 months agoReserving two diagnostic codes for serialization work (#84439)
Levi Broderick [Thu, 6 Apr 2023 21:01:00 +0000 (14:01 -0700)]
Reserving two diagnostic codes for serialization work (#84439)

17 months agoEnable building preview workload components (#84365)
Jacques Eloff [Thu, 6 Apr 2023 20:59:52 +0000 (13:59 -0700)]
Enable building preview workload components (#84365)

To support insertions of multiple SDKs into Visual Studio, the components associated with workloads need to have unique IDs. Currently there is a 1:1 mapping between VS components and .NET workloads. Inserting multiple SDKs into VS creates a conflict. The Aracde tasks used to create workloads were updated to produce two sets of components with the second set containing an additional .pre suffix.

The build would produce one additional artifact for VS

17 months agoFixes for BuildAsStandalone in tests (#84374)
Mark Plesko [Thu, 6 Apr 2023 20:39:50 +0000 (13:39 -0700)]
Fixes for BuildAsStandalone in tests (#84374)

This should fix test builds with `set BuildAsStandalone=true`.

- [Remove](https://github.com/dotnet/runtime/commit/5f14f058f4ed2f70633abea1bb59f34203e1718d) unconditional `<BuildAsStandalone>false</BuildAsStandalone>` from various HardwareIntrinsics tests. This is already the default via Directory.Build.props but interferes with `set BuildAsStandalone=true`.  (nit - also remove an empty `PropertyGroup` from GitHub_43569.csproj)
- [Remove `Main` methods](https://github.com/dotnet/runtime/commit/0a886f8ee12eff9abb6d52391a1c324da6add1e6). We might be able to pursue a strategy where the test author provides a `Main(args)` method for local custom execution. The test would either need a separate parameterless [Fact] method or a [Theory] plus data for `Main` for merged group to execute it. However, a RequiresProcessIsolation/BuildAsStandalone build would ignore that metadata, so I'd like to avoid that complexity. The Main methods here set a bool or parse an int, which can be added locally to any test as needed.
- [Add comment](https://github.com/dotnet/runtime/commit/e79a10c9e397caf90c8342dfea5707b8a35f3b3d) to Directory.Merged.props (addressing feedback on #83462)
- [Add the Methodical test back into the superpmi test](https://github.com/dotnet/runtime/commit/7c61de8574b0995fbd7779987a8eb6a35c059117) using RequiresProcessIsolation

Fixes #76421
Fixes #81984

17 months agoRemoving test case that is not working on chrome anymore (#84440)
Thays Grazia [Thu, 6 Apr 2023 19:14:22 +0000 (16:14 -0300)]
Removing test case that is not working on chrome anymore (#84440)

17 months agoDisable StackallocBlkTests test on Mono (#84408)
Egor Bogatov [Thu, 6 Apr 2023 18:57:59 +0000 (20:57 +0200)]
Disable StackallocBlkTests test on Mono (#84408)

* Disable StackallocBlkTests test on Mono

* trigger CI

17 months agoMicrosoft.NETCore.Platforms: support adding rids with '-' in the base part. (#84413)
Tom Deseyn [Thu, 6 Apr 2023 18:50:50 +0000 (20:50 +0200)]
Microsoft.NETCore.Platforms: support adding rids with '-' in the base part. (#84413)

* Microsoft.NETCore.Platforms: support adding rids with '-' in the base part.

Currently when trying to add a rid like 'linux-musl-x64'
the rid is not understood to be base = 'linux-musl', arch = 'x64'.

Instead the parser considers a potential optional qualifier.
This causes the rid to be parsed as base = 'linux', arch = 'musl',
and qualifier = 'x64'.

We know the rids being added won't have a qualifier. If we take
this into account while parsing, we can parse the rid correctly.

* Update src/libraries/Microsoft.NETCore.Platforms/src/RuntimeGroupCollection.cs

Co-authored-by: Eric StJohn <ericstj@microsoft.com>
---------

Co-authored-by: Eric StJohn <ericstj@microsoft.com>
18 months agoMove over all interop generator unit tests to use raw string literals (#84391)
Jeremy Koritzinsky [Thu, 6 Apr 2023 18:00:25 +0000 (11:00 -0700)]
Move over all interop generator unit tests to use raw string literals (#84391)

18 months agoAlways create loop pre headers (#83956)
Bruce Forstall [Thu, 6 Apr 2023 15:49:07 +0000 (08:49 -0700)]
Always create loop pre headers (#83956)

* Always create loop pre-header

As part of finding natural loops and creating the loop
table, create a loop pre-header for every loop. This
simplifies a lot of downstream phases, as the loop
pre-header will be guaranteed to exist, and will already
exist in the dominator tree.

Introduce code to preserve an empty pre-header block through
the optimization phases.

Remove now unnecessary code in hoisting and elsewhere.

Fixes #77033, #62665

* Fix loop unrolling to work with loop pre-headers

* Add `optLoopsRequirePreHeaders` variable

* Prevent removing pre-header blocks

* Allow removing unreachable pre-headers

Disallow creating pre-header after SSA is built

* Make optLoopCloningEnabled() static

* Teach loop cloning to expect and respect loop pre-headers

* Remove special case pre-header handling in hoisting

* Remove unused SSA update code in fgCreateLoopPreHeader

* Remove unneeded pre-header code from fgDominate

* Remove workaround to avoid extraneous LSRA diffs due to bbNum ordering

* Update comments

* Improve loop table rebuilding with pre-headers

When the loop table is built, it looks around for various loop patterns,
including looking for a guaranteed-executed, pre-loop constant initializer.
This is used in loop cloning and loop unrolling. It needs to look
"a little harder" in the case we created loop pre-headers, then
rebuild the loop table (currently, only due to loop unrolling of loops that
contain nested loops). The new code only allows for empty pre-headers. This
works since in our current phase ordering, no hoisting happens by the time
the loop table is rebuilt.

(Actually, it's currently not necessary to do this at all, since the constant
initializer info is only used by cloning and loop unrolling, both of which
have finished by the time the loop table is rebuilt. However, we might someday
choose to rebuild the loop table after cloning and before unrolling, at which
point it would be necessary.)

* Update comments

18 months ago[RISC-V] Port Mono for RISC-V 64 Arch (2/3) thunk & tramponlie (#83715)
VincentWu [Thu, 6 Apr 2023 15:08:32 +0000 (23:08 +0800)]
[RISC-V] Port Mono for RISC-V 64 Arch (2/3) thunk & tramponlie (#83715)

* thunk & tramponlie for riscv64, also exception call

* format

18 months agoUse better trimming message in ValidationContext (#84326)
Eric Erhardt [Thu, 6 Apr 2023 14:31:01 +0000 (09:31 -0500)]
Use better trimming message in ValidationContext (#84326)

* Use better trimming message in ValidationContext

Add more details about why ValidationContext requires unreferenced code.

Fix #84324

* Exclude RequiresUnreferencedCodeAttribute from baseline API compat

18 months agoDon't overwrite pinned assembly versions in servicing (#84079)
Viktor Hofer [Thu, 6 Apr 2023 14:30:38 +0000 (16:30 +0200)]
Don't overwrite pinned assembly versions in servicing (#84079)

* Don't overwrite pinned assembly versions in servicing

There are eight packable projects that pin their assembly version for .NET
Framework compatibility. The incremental package servicing
infrastructure didn't check if the assembly version is pinned and always
changed it.

As an example, System.Speech pins its assembly version to 4.0.0.0 but
that version gets overwritten during servicing. I.e. for .NET 7 the
version would then change to "7.0.0.$(ServicingVersion)" which is
incorrect.

Please find the full list of impacted assemblies below:
- System.ComponentModel.Composition
- System.DirectoryServices
- System.DirectoryServices.AccountManagement
- System.DirectoryServices.Protocols
- System.Management
- System.Reflection.Context
- System.Runtime.Caching
- System.Speech

* Only pin AssemblyVersion in netstandard2.0 assemblies

These assemblies pin their AssemblyVersion to be compatible with
.NETFramework where the same assembly is inbox.

The only TargetFramework we build that is compatible with .NETFramework
is netstandard2.0, so only pin the assembly on that framework.

* Override AssemblyVersion in Directory.Build.targets

Previously assemblies would set AssemblyVersion in Directory.Build.props
which was too early, because later packaging.targets could not distinguish
between a value that was explicitly set and the default value of the repo.

Instead override the value after the Servicing value is set, in
Directory.Build.targets

* Update comments

* Remove ValidateAssemblyVersionsInRefPack target

The only thing this target did was a redundant check that AssemblyVersion was
set for projects in the Targeting Pack.  That check was failing for
the NETStandard build of System.DirectoryServices.

This target was providing no value, instead we need to fix https://github.com/dotnet/runtime/issues/42961
which will be a proper check of our servicing version rules.

* Address feedback

---------

Co-authored-by: Eric StJohn <ericstj@microsoft.com>
18 months agoFix BeginReceiveMessageFromV4BoundToSpecificV6_NotReceived (#83463)
Anton Firszov [Thu, 6 Apr 2023 13:55:21 +0000 (15:55 +0200)]
Fix BeginReceiveMessageFromV4BoundToSpecificV6_NotReceived (#83463)

18 months ago[mono][interp] Remove MINT_LEAVE opcode (#84410)
Vlad Brezae [Thu, 6 Apr 2023 13:43:42 +0000 (16:43 +0300)]
[mono][interp] Remove MINT_LEAVE opcode (#84410)

It is identical to MINT_BR

18 months ago[mono][tests] Properly triage known GC failure (#84403)
Vlad Brezae [Thu, 6 Apr 2023 13:29:35 +0000 (16:29 +0300)]
[mono][tests] Properly triage known GC failure (#84403)

18 months ago[wasm] Implement LEAVE_CHECK in the jiterpreter (as a bailout) (#84387)
Katelyn Gadd [Thu, 6 Apr 2023 12:08:58 +0000 (05:08 -0700)]
[wasm] Implement LEAVE_CHECK in the jiterpreter (as a bailout) (#84387)

LEAVE_CHECK is a variant of LEAVE that only appears inside catch clauses, and catch clauses will not be running during normal optimized execution. So it's reasonable for the jiterpreter to compile them into bailouts, which will allow trace compilation to continue past the catch clause.

18 months agoAdd Utf8.TryWrite (#83852)
Stephen Toub [Thu, 6 Apr 2023 11:12:46 +0000 (07:12 -0400)]
Add Utf8.TryWrite (#83852)

* Add Utf8.TryWrite

Initial implementation of Utf8.TryWriteUtf8. The performance of this won't be great at present, but will improve as our cores types add implementation of IUtf8SpanFormattable. For tests, I copy/pasted the tests we had for MemoryExtensions.TryWrite and searched/replaced to make them work for Utf8.TryWrite.

* Address PR feedback

18 months agoFix Roslyn dependency version in source-build (#84366)
Jeremy Koritzinsky [Thu, 6 Apr 2023 06:23:49 +0000 (23:23 -0700)]
Fix Roslyn dependency version in source-build (#84366)

18 months agoDisable nullability checks in file shared between the managed type system and ILVerif...
Jeremy Koritzinsky [Thu, 6 Apr 2023 05:23:20 +0000 (22:23 -0700)]
Disable nullability checks in file shared between the managed type system and ILVerificationTests (#84382)

This file is shared between the managed type system and the ILVerificationTests suite.
The managed type system doesn't have nullable checks turned on, but ILVerificationTests does. This was causing build failures in PRs that build the ILVerificationTests.

We should enable nullable checking in the future in the managed type system as a whole at some point, but we aren't there yet.

18 months ago[mono][aot] Fix an assert. (#84385)
Zoltan Varga [Thu, 6 Apr 2023 05:20:31 +0000 (01:20 -0400)]
[mono][aot] Fix an assert. (#84385)

This is hit when AOTing GitHub_27678.dll.

18 months agoFix ThunkGenerator (#84390)
Michał Petryka [Thu, 6 Apr 2023 05:14:14 +0000 (07:14 +0200)]
Fix ThunkGenerator (#84390)

* Fix ThunkGenerator

Fixes:
```
 error CA1859: Change type of parameter 'tr' from 'System.IO.TextReader' to 'System.IO.StreamReader' for improved performance
 error CA1859: Change return type of method 'ParseInput' from 'System.Collections.Generic.IEnumerable<Thunkerator.FunctionDecl>' to 'System.Collections.ObjectModel.ReadOnlyCollection<Thunkerator.FunctionDecl>' for improved performance
```

* Fix typo

18 months agoMake WindowsServiceLifetime gracefully stop (#83892)
Eric StJohn [Thu, 6 Apr 2023 04:42:17 +0000 (21:42 -0700)]
Make WindowsServiceLifetime gracefully stop (#83892)

* Make WindowsServiceLifetime gracefully stop

WindowsServiceLifetime was not waiting for ServiceBase to stop the service.  As a result
we would sometimes end the process before notifying service control manager that the service
had stopped -- resulting in an error in the eventlog and sometimes a service restart.

We also were permitting multiple calls to Stop to occur - through SCM callbacks, and through
public API.  We must not call SetServiceStatus again once the service is marked as stopped.

* Alternate approach to ensuring we only ever set STATE_STOPPED once.

* Avoid calling ServiceBase.Stop on stopped service

I fixed double-calling STATE_STOPPED in ServiceBase, but this fix will
not be present on .NETFramework.  Workaround that by avoiding calling
ServiceBase.Stop when the service has already been stopped by SCM.

* Add tests for WindowsServiceLifetime

These tests leverage RemoteExecutor to avoid creating a separate service
assembly.

* Respond to feedback and add more tests.

This better integrates with the RemoteExecutor component as well,
by hooking up the service process and fetching its handle.

This gives us the correct logging and exitcode handling from
RemoteExecutor.

* Honor Cancellation in StopAsync

* Fix bindingRedirects in RemoteExecutor

* Use Async lambdas for service testing

* Fix issue on Win7 where duplicate service descriptions are disallowed

* Respond to feedback

* Fix comment and add timeout

18 months agoArm64: Optimize pairs of "str wzr" to "str xzr" (#84350)
SwapnilGaikwad [Thu, 6 Apr 2023 02:47:28 +0000 (03:47 +0100)]
Arm64: Optimize pairs of "str wzr" to "str xzr" (#84350)

Optimise following patterns

```
stp     wzr, wzr, [x2, #0x08]       =>     str     xzr, [x2, #0x08]
```

and

```
stp     wzr, wzr, [x14, #0x20]
str     xzr, [x14, #0x18]           =>     stp     xzr, xzr, [x14, #0x18]
```

18 months agoAdd ArgumentOutOfRangeException.ThrowIf{Not}Equal (#83853)
Stephen Toub [Thu, 6 Apr 2023 02:33:21 +0000 (22:33 -0400)]
Add ArgumentOutOfRangeException.ThrowIf{Not}Equal (#83853)

* Add ArgumentOutOfRangeException.ThrowIf{Not}Equal

* Address PR feedback

* Address PR feedback

18 months agoAdd back IComparable-based optimization to FrozenDictionary/Set (#84301)
Stephen Toub [Thu, 6 Apr 2023 02:32:36 +0000 (22:32 -0400)]
Add back IComparable-based optimization to FrozenDictionary/Set (#84301)

* Add back IComparable-based optimization to FrozenDictionary/Set

We previously had an optimization in FrozenDictionary/Set that special-cased a small number of value types when the default comparer is used... if that type was IComparable, we would sort the types, which would then a) enable us to immediately reject items larger than the known max, and b) enable us to stop searching once we hit an item larger than the one for which we were searching (which then implicitly also immediately rules out items smaller than the known min).

We removed that optimization in general because some prominent IComparable implementations don't always work, in particular container types like ValueTuple that implement IComparable but then it's only functional if the contained types are also comparable.  This commit puts it back for an allow-list of types.

* Address PR feedback

18 months agoSpeed up named type lookups in managed type system (#84285)
Michal Strehovský [Wed, 5 Apr 2023 23:58:06 +0000 (08:58 +0900)]
Speed up named type lookups in managed type system (#84285)

When the type system needs to resolve a named type in a module, it will do a `foreach` loop over all types in the module looking for the type. This can get mildly hot and I've seen it in CPU profiles but it never looked too important to address (despite the TODO).

But when MIBC files are passed to the compiler, this gets ridiculously hot. Compile Hello world by default: 0.98 seconds. Compile hello world with 5 MIBC files: 9.1 seconds.

This adds a hashtable to the lookup and drops the MIBC case to 1.4 seconds (we'll want to parallelize the MIBC loading on a background thread to get rid of the last mile, but first things first).

18 months ago[Android] Free up more disk space on CI builds (#84354)
Steve Pfister [Wed, 5 Apr 2023 22:32:04 +0000 (18:32 -0400)]
[Android] Free up more disk space on CI builds (#84354)

The android builds are running out of disk space when building the library test apps.  This change tries to recoup some of that space by deleting artifacts after each test was built.

18 months agoAdd missing step to native AOT dev workflow instructions (#84381)
Jan Kotas [Wed, 5 Apr 2023 21:55:43 +0000 (14:55 -0700)]
Add missing step to native AOT dev workflow instructions (#84381)

18 months agoRemoved pipeline dependencies and steps for running Maui-iOS as it has been moved...
Parker Bibus [Wed, 5 Apr 2023 20:56:55 +0000 (13:56 -0700)]
Removed pipeline dependencies and steps for running Maui-iOS as it has been moved to the performance repo. (#84363)

18 months agoAvoid scaning the used region if there are no free units (#81525)
Andrew Au [Wed, 5 Apr 2023 20:46:38 +0000 (13:46 -0700)]
Avoid scaning the used region if there are no free units (#81525)

18 months agoImplement the JsonSerializer.IsReflectionEnabledByDefault feature switch (#83844)
Eirik Tsarpalis [Wed, 5 Apr 2023 20:21:06 +0000 (21:21 +0100)]
Implement the JsonSerializer.IsReflectionEnabledByDefault feature switch (#83844)

* Implement the STJ.DisableDefaultReflection feature switch.

* Reinstate accidentally stripped attribute

* Address feedback.

* Address feedback.

* Add a trimming test for STJ

* Move trimming test to existing trimming tests folder.

* Add source gen serialization test case to Trimming test.

* Fix style.

* Expose the feature switch as a property on JsonSerializer -- rename feature switch to match namespace.

* Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
* Update src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/IsReflectionEnabledByDefaultFalse.cs

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
* Address feedback.

* Address feedback.

* Add entry to feature-switches.md

---------

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
18 months ago[JIT] X86/X64 - Eliminate redundant 'cmp' instructions (#82750)
Will Smith [Wed, 5 Apr 2023 20:07:04 +0000 (13:07 -0700)]
[JIT] X86/X64 - Eliminate redundant 'cmp' instructions (#82750)

* Fixed improper peephole zero-extension removal when cdq/cdqe/cwde instructions are involved

* Update regression test

* Formatting

* Handle cdq differently

* Handle cdq differently

* Handle cdq differently

* Initial commit to eliminate redundant 'cmp' instructions

* Take into account cmpxchg

* Take into account cmpxchg

* Feedback

* Temporarily disable cmp opt if we encounter a mov

* Allow checking for mov

* Allow regardless of targetReg

* Allow regardless of targetReg

* Checking if an instruction resets a flag.

* Remove useless comment

* Minor fix

* Abort are checking cmp

* Some refactoring. Taking into account any instruction that modifies flags.

* Minor cleanup

* Remove function from header

* Quick fix

* Sync

* Formatting

* Only look for 'cmp reg, reg'

* Added comment

* Update src/coreclr/jit/emitxarch.cpp

Co-authored-by: Bruce Forstall <brucefo@microsoft.com>
* Update src/coreclr/jit/emitxarch.cpp

Co-authored-by: Bruce Forstall <brucefo@microsoft.com>
---------

Co-authored-by: Bruce Forstall <brucefo@microsoft.com>
18 months ago[wasm][debugger] Retry after timeout on debugger tests on CI (#84080)
Thays Grazia [Wed, 5 Apr 2023 19:48:58 +0000 (16:48 -0300)]
[wasm][debugger] Retry after timeout on debugger tests on CI (#84080)

* retrying if timeout OpenSessionAsync.
* Update src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs

Co-authored-by: Larry Ewing <lewing@microsoft.com>
---------

Co-authored-by: Larry Ewing <lewing@microsoft.com>
18 months agoLocalized file check-in by OneLocBuild Task: Build definition ID 679: Build ID 214995...
dotnet bot [Wed, 5 Apr 2023 18:41:51 +0000 (11:41 -0700)]
Localized file check-in by OneLocBuild Task: Build definition ID 679: Build ID 2149956 (#84276)

18 months agoCaching settings.pause_mode to avoid deadlock (#84189)
Andrew Au [Wed, 5 Apr 2023 18:25:30 +0000 (11:25 -0700)]
Caching settings.pause_mode to avoid deadlock (#84189)

18 months ago[mono][aot] Fix an assert in the aot compiler. (#84343)
Zoltan Varga [Wed, 5 Apr 2023 18:15:03 +0000 (14:15 -0400)]
[mono][aot] Fix an assert in the aot compiler. (#84343)

Happens when AOT-ing Regression_1.dll from the JIT test suite.

18 months agoSwitch CustomAttributeTypeNameParser to use common type name parser (#84281)
Jan Kotas [Wed, 5 Apr 2023 17:36:38 +0000 (10:36 -0700)]
Switch CustomAttributeTypeNameParser to use common type name parser (#84281)

18 months agoAvoid clearing uncommitted mark array (#83623)
Andrew Au [Wed, 5 Apr 2023 17:35:59 +0000 (10:35 -0700)]
Avoid clearing uncommitted mark array (#83623)

18 months agoJIT: Ensure tail merging does not add preds to scratch block (#84353)
Jakob Botsch Nielsen [Wed, 5 Apr 2023 17:08:04 +0000 (19:08 +0200)]
JIT: Ensure tail merging does not add preds to scratch block (#84353)

Fix issue seen in #83388 where tail merging ended up adding new
predecessors to the scratch block, making adding more "initialization
IR" impossible for downstream phases.

18 months ago[wasm] Freeze the emscripten cache (#84356)
Radek Doulik [Wed, 5 Apr 2023 16:10:52 +0000 (18:10 +0200)]
[wasm] Freeze the emscripten cache (#84356)

This fixes https://github.com/dotnet/runtime/issues/83655

We prime the cache before packaging the emsdk cache package and also
in docker images, so we don't need to update the cache, which might be
in read-only location anyway.

The underlying issue was problem with the cache lock:

    "C:/helix/work/correlation/build/emsdk/upstream/bin\clang.exe" --version
    cache:WARNING: Accessing the Emscripten cache at "C:\helix\work\correlation\build\emsdk\upstream\emscripten\cache" (for "sanity") is taking a long time, another process should be writing to it. If there are none and you suspect this process has deadlocked, try deleting the lock file "C:\helix\work\correlation\build\emsdk\upstream\emscripten\cache\cache.lock" and try again. If this occurs deterministically, consider filing a bug.
    cache:WARNING: Accessing the Emscripten cache at "C:\helix\work\correlation\build\emsdk\upstream\emscripten\cache" (for "sanity") is taking a long time, another process should be writing to it. If there are none and you suspect this process has deadlocked, try deleting the lock file "C:\helix\work\correlation\build\emsdk\upstream\emscripten\cache\cache.lock" and try again. If this occurs deterministically, consider filing a bug.

18 months ago[wasm] Implement the ENDFINALLY opcode in the jiterpreter (#84273)
Katelyn Gadd [Wed, 5 Apr 2023 12:23:38 +0000 (05:23 -0700)]
[wasm] Implement the ENDFINALLY opcode in the jiterpreter (#84273)

* Mark the opcode following CALL_HANDLER interpreter opcodes as a back branch target
* In the jiterpreter, record each CALL_HANDLER location when compiling them
* Then when compiling an ENDFINALLY opcode check to see whether the branch target is one we recognize and if so do a branch, otherwise bail out
* Tweak CFG to filter out branch targets that are never used
* Add browser-bench measurement for try-finally

18 months ago[wasm] Simd refactoring (#84170)
Radek Doulik [Wed, 5 Apr 2023 11:16:13 +0000 (13:16 +0200)]
[wasm] Simd refactoring (#84170)

* [wasm] Simd refactoring

Rename few opcodes to contain `_SIMD_`.

Use more SimdIntrinsic fields to simplify the code.

* Fix build

* Fix narrowing intrinsics

* Verbose aot compilation

* Feedback

* Make it verbose on helix

* Do not set op for narrowing methods

Because `emit_hardware_intrinsics` doesn't call custom emit in such case
and so we endup with code emitted with wrong zero c0.

* Feedback

* Be quiet again :-)

18 months agoEnabled Sqrt and Abs intrinsics (#84011)
Vlad-Alexandru Ionescu [Wed, 5 Apr 2023 08:24:27 +0000 (10:24 +0200)]
Enabled Sqrt and Abs intrinsics (#84011)

* Enabled abs and sqrt intrinsics

---------

Signed-off-by: Vlad - Alexandru Ionescu <vlad-alexandruionescu@Vlads-MacBook-Pro-4.local>
Co-authored-by: Vlad - Alexandru Ionescu <vlad-alexandruionescu@Vlads-MacBook-Pro-4.local>
18 months agoOptimize stackalloc zeroing via BLK (#83255)
Egor Bogatov [Tue, 4 Apr 2023 23:36:00 +0000 (01:36 +0200)]
Optimize stackalloc zeroing via BLK (#83255)

Co-authored-by: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com>
18 months agoSuppress linker warnings properly (#84272)
Buyaa Namnan [Tue, 4 Apr 2023 23:22:03 +0000 (16:22 -0700)]
Suppress linker warnings properly (#84272)

* Suppress linker warnings properly

* Update core assembly types handling

* Update src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
18 months agoMark FirstCharInUInt32IsAscii with aggressiveinlining (#84306)
Egor Bogatov [Tue, 4 Apr 2023 23:04:13 +0000 (01:04 +0200)]
Mark FirstCharInUInt32IsAscii with aggressiveinlining (#84306)

18 months agoJIT: use synthesis to repair some reconstruction issues (#84312)
Andy Ayers [Tue, 4 Apr 2023 22:34:10 +0000 (15:34 -0700)]
JIT: use synthesis to repair some reconstruction issues (#84312)

In particular, run synthesis in repair mode for cases where there are profile
counts within the method but zero counts in `fgFirstBB`.

Recall that sparse profiling effectively probes return blocks to determine the
method entry count.

So the zero-entry but not zero-everywhere case can happen if we have a method
with a very long running loop plus sparse profiling plus OSR -- we will only
get profile counts from the instrumented Tier0 method, and it will never return
(instead it will always escape to an OSR version which will eventually return,
but that version won't be instrumented).

I originally was a bit more ambitious and ran repair for a broader set of
reconstruction issues, but lead to a large number of diffs, in part because
repair doesn't cope well with irreducible loops.

Leaving the entry count zero can have fairly disastrous impact on the quality
of optimizations done in the method.

Addresses quite a few of the worst-performing benchmarks in #84264.

18 months ago[NativeAOT] Remove unused native memcopy helpers. (#84314)
Vladimir Sadov [Tue, 4 Apr 2023 22:29:54 +0000 (15:29 -0700)]
[NativeAOT] Remove unused native memcopy helpers. (#84314)

* Remove unused (and in some cases broken) RhpCopy helpers.

* PR feedback

18 months agoJIT: Handle some "field offset computation" patterns (#81998)
Jakob Botsch Nielsen [Tue, 4 Apr 2023 22:26:03 +0000 (00:26 +0200)]
JIT: Handle some "field offset computation" patterns (#81998)

Both during local morph and during VN.

Fix #40021

Saves 3 KB on BasicMinimalApi after #84095 (there's 1111 __GetFieldHelper functions). About 0.04%. There's still a null check kept for each offset computation, which we cannot really get rid of, but NAOT could maybe emit the IL such that there is a dominating null check so that only one is emitted.

Example:
Base:
```
.managed:0000000140347CC0 loc_140347CC0:                          ; CODE XREF: S_P_CoreLib_System_Collections_Generic_KeyValuePair_2_System_Net_Security_System_Net_Security_SslSessionsCache_SslCredKey__System___Canon_____GetFieldHelper+23↑j
.managed:0000000140347CC0                                         ; DATA XREF: .rdata:__readonlydata_S_P_CoreLib_System_Collections_Generic_KeyValuePair_2_System_Net_Security_System_Net_Security_SslSessionsCache_SslCredKey__System___Canon_____GetFieldHelper↓o
.managed:0000000140347CC0                 lea     rax, ??_7Boxed_System_Net_Security_System_Net_Security_SslSessionsCache_SslCredKey@@6B@ ; jumptable 0000000140347CB3 case 0
.managed:0000000140347CC7                 mov     [r9], rax
.managed:0000000140347CCA                 cmp     [rcx], cl
.managed:0000000140347CCC                 lea     rax, [rcx+8]
.managed:0000000140347CD0                 sub     rax, rcx
.managed:0000000140347CD3                 add     rsp, 8
.managed:0000000140347CD7                 retn
```
Diff:

```
.managed:0000000140347AA0 loc_140347AA0:                          ; CODE XREF: S_P_CoreLib_System_Collections_Generic_KeyValuePair_2_System_Net_Security_System_Net_Security_SslSessionsCache_SslCredKey__System___Canon_____GetFieldHelper+23↑j
.managed:0000000140347AA0                                         ; DATA XREF: .rdata:__readonlydata_S_P_CoreLib_System_Collections_Generic_KeyValuePair_2_System_Net_Security_System_Net_Security_SslSessionsCache_SslCredKey__System___Canon_____GetFieldHelper↓o
.managed:0000000140347AA0                 lea     rax, ??_7Boxed_System_Net_Security_System_Net_Security_SslSessionsCache_SslCredKey@@6B@ ; jumptable 0000000140347A93 case 0
.managed:0000000140347AA7                 mov     [r9], rax
.managed:0000000140347AAA                 cmp     [rcx], cl
.managed:0000000140347AAC                 mov     eax, 8
.managed:0000000140347AB1                 add     rsp, 8
.managed:0000000140347AB5                 retn
```

Local morph changes handle the pattern for local structs -- VN changes handle the pattern for classes (and more complicated struct cases, like storing them in locals, which there are a few examples of in #40021).

18 months agoImprove XmlDictionaryWriter UTF8 encoding performance (#73336)
Daniel Svensson [Tue, 4 Apr 2023 22:11:10 +0000 (00:11 +0200)]
Improve XmlDictionaryWriter UTF8 encoding performance (#73336)

* Speed up text encoding

* Update implementation

* Add tests for binary xml strings

* limit counting code to 256 bit vectors

* reword comment

* rename test

* move bytesmax

* Fix bytesMax after moving variable initialization

* use unicode escape value in test

* fix test typo "*" -> "+"

* Update src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Remvoe vectorized code from UnsafeGetUTF8Length

* Fix overfload

* use for loop which seems faster

* remove vector loop

* make sealed encoding to allow devirtualisation

* back some changes

* use uint for UnsafeGetUTF8Chars comparison

* revert more changes

* Fix cutoff based on new measurements

* use BinaryPrimitives.ReverseEndianness as suggested

* Update cutoff from 24 to 32 chars before calling, due to regression for text based DataContractSerializer

* Remove sealed encoding since it only improves XmlConvert

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
18 months agoConvertIcuTimeFormatString: convert narrow no-break spaces to spaces too. (#83589)
Tom Deseyn [Tue, 4 Apr 2023 20:56:21 +0000 (22:56 +0200)]
ConvertIcuTimeFormatString: convert narrow no-break spaces to spaces too. (#83589)

18 months agoFast-path in String.Trim (#84300)
Egor Bogatov [Tue, 4 Apr 2023 20:55:52 +0000 (22:55 +0200)]
Fast-path in String.Trim (#84300)

18 months agoUse similar types for self-referential generics instead of the exact canonical type...
David Wrighton [Tue, 4 Apr 2023 20:16:00 +0000 (13:16 -0700)]
Use similar types for self-referential generics instead of the exact canonical type (#83995)

- Take advantage of work done a few years ago to simplify the interaction with the interop subsystem
- In the problematic case, simulate loads with two different types as instantiations which are unrelated in field layout, and see if they match up. Only enable this code in a few very small isolated parts of the runtime
- Filter more of the type loader logic through the byvalue class cache which should improve performance a bit
- Similarly when considering blittability, tweak the logic to use the special load path

- Support for self-recursive generics is not enabled for static fields, as that requires a somewhat different tweak, and there is less apparent demand. (For that scenario self-referential generics really should support having fields of type T.)
- Support for indirect self-recursive generics is also not enabled. The approach taken here is not practical for that, and there does not appear to be significant demand for that either.

Fixes #6924

18 months agoAdd error check for skipped tests in merged groups (#84284)
Mark Plesko [Tue, 4 Apr 2023 18:32:55 +0000 (11:32 -0700)]
Add error check for skipped tests in merged groups (#84284)

If I test is written in the old style (with a Main and OutputType==Exe without an attribute such as RequiresProcessIsolation) in a merged test group directory, it will be skipped. This change adds a check to detect those cases.

I have struggled with ways to automatically set OutputType. Directory.Build.props is too early (the test project file will override it). Directory.Build.targets is too late as the C# targets files will already have been processed and set other variables based on the value of OutputType. This Target doesn't execute until later, but since it is an error it doesn't matter how those additional properties were set.

Since this adds more boilerplate to each merged test directory, I created a src/tests/Directory.Merged.props to share all of that.

This catches 3 tests that aren't currently executing.

Unrelated:

- Use GetPathOfFileAbove in nearby locations for Directory.Build.props chaining rather than specific paths
- Fix two easy IL warnings that appeared in my local build of all tests

Resolves https://github.com/dotnet/runtime/issues/84182

18 months ago[JIT] Fix re-use val zero on GC tracking (#84051)
Will Smith [Tue, 4 Apr 2023 17:47:21 +0000 (10:47 -0700)]
[JIT] Fix re-use val zero on GC tracking (#84051)

* Initial work

* Added genCodeForReuseVal

* Only create a label if the current IG is not empty

18 months ago[JIT] ARM64/X64 - Add `IsVNNeverNegative` (#83694)
Will Smith [Tue, 4 Apr 2023 17:43:47 +0000 (10:43 -0700)]
[JIT] ARM64/X64 - Add `IsVNNeverNegative` (#83694)

* Initial work

* Handle arrlen case

* Added ifdef

* Additional cases

* Additional cases

* Add assert to IsVNNeverNegative

* Update src/coreclr/jit/valuenum.cpp

Co-authored-by: Bruce Forstall <brucefo@microsoft.com>
* Additional cases

---------

Co-authored-by: Bruce Forstall <brucefo@microsoft.com>
18 months agodon't load MsQuic unless needed by HttpClient (#83494)
Tomas Weinfurt [Tue, 4 Apr 2023 16:23:54 +0000 (09:23 -0700)]
don't load MsQuic unless needed by HttpClient (#83494)

* don't load MsQuic unless needed by HttpClient

* feedback from review

18 months agoFix parallel SuperPMI output handling (#84219)
Bruce Forstall [Tue, 4 Apr 2023 15:37:20 +0000 (08:37 -0700)]
Fix parallel SuperPMI output handling (#84219)

Previously, parallel SuperPMI parsed very few kinds of output from
the child processes, and ignored and discarded the rest. Change this
so all output from the child processes is output by the parent
process.

For example, this allows the child process JIT to print out statistics,
disasm, etc., and have it visible by the parent invoker.

18 months agoOnly call base.DisposeAsync on classes derived from FileStream (#82874)
David Cantú [Tue, 4 Apr 2023 15:22:42 +0000 (10:22 -0500)]
Only call base.DisposeAsync on classes derived from FileStream (#82874)

* Only call base.DisposeAsync on classes derived from FileStream

* Fix typo

18 months ago[mono][sgen] Remove old code associated with domain unload (#84242)
Vlad Brezae [Tue, 4 Apr 2023 15:07:50 +0000 (18:07 +0300)]
[mono][sgen] Remove old code associated with domain unload (#84242)

* [mono][sgen] Remove unused suspend finalizers functionality

* [mono][sgen] Remove threadpool shutdown logic

No longer used

* [mono][sgen] Remove logic associated with gc shutdown

* [mono][sgen] Remove logic for clearing handle stack during cleanup

* [mono][sgen] Remove code for xdomain checks

* [mono][sgen] Remove more code associated with finalization

* [mono][sgen] Remove code for freeing objects during domain unload

* [mono][sgen] Remove mono_gc_clear_domain

It is dead code

18 months agoFix FrozenDictionary/Set handling of ValueTuple keys (#84280)
Stephen Toub [Tue, 4 Apr 2023 11:20:58 +0000 (07:20 -0400)]
Fix FrozenDictionary/Set handling of ValueTuple keys (#84280)

For small collections of comparable value types, we were using an implementation that sorted the keys in order to a) quickly rule out values outside of the known contained range, and b) stop searching when we hit a value that was too small.  However, this can break for some well-known types. In particular, `ValueTuple<...>` implements `IComparable<ValueTuple<...>>`, but it might throw an exception if you actually try to use its `IComparable<>` implementation if any of the `T` types in the tuple are themselves not comparable.  Since we have no good way then to dynamically select an implementation based on whether it implements `IComparable<>`, I've simply removed those checks / calls from the implementation.

Testing this also highlighted that our existing shared set tests don't like being given non-comparable types, as they use SortedSet which itself suffers from effectively the same issue (but there you can choose to not use SortedSet if it doesn't work for your data, and "sort"ing is part of the name).

18 months agofix addrmode assert (#84252)
Egor Bogatov [Tue, 4 Apr 2023 10:50:11 +0000 (12:50 +0200)]
fix addrmode assert (#84252)

18 months ago[Mono]: Library mode enhancements. (#84165)
Johan Lorensson [Tue, 4 Apr 2023 10:16:59 +0000 (12:16 +0200)]
[Mono]: Library mode enhancements. (#84165)

Add support for direct pinvoke charset on Windows.

NativeAOT direct pinvoke support handles pinvoke charset on Windows,
this commit adds the same logic to Mono when targeting Windows,
so it will follow the same charset rules as NativeAOT.

Direct pinvoke wrappers on none full AOT builds.

Library mode builds will have option to create a self contained static
or shared library, including all needed resources, embedding assemblies
and static link all external dependencies (using direct pinvoke). Library mode
also exports UnamangedCallersOnly methods that can be called by application
loading the library. Currently the wrappers needed for UnmanagedCallersOnly
methods will be generated when doing none full AOT builds, but not
pinvoke wrappers. This PR adds support to generate the pinvoke wrappers, but
only for the methods described by direct pinvoke AOT compiler arguments,
so for none full AOT builds not using direct pinvoke arguments, no pinvoke
wrappers will be generated, inline with current none full AOT behavior.

Direct pinvoke wrappers on profiled AOT builds.

Enhanced the profile-only option doing profile AOT to emit managed-to-native
and native-to-managed wrappers. Needed in order for library build to work
together with profiled AOT builds.

Wrappers-only AOT option.

On platforms like Android, we still run majority of code using JIT. Since library
mode should produce a self contained library, including pinvokes
(for all direct pinvoked functions) as well as UnmanagedCallersOnly wrappers,
Android would need to at least run none full AOT build of all used assemblies.
By default, that will AOT a lot more methods that is really needed and there is
no way to reduce the AOT:ed code and still run as much as possible using JIT.
The profile-only option opens up ability to reduce what managed methods that
will be AOT:ed, but still generates a number of inflated methods not needed by
UnmanagedCallersOnly and direct pinvoke wrappers and piggy back on an
existing option with additional functionality is not optimal. This PR adds an
undocumented AOT option intended to be used by library builder, wrappers-only,
and that will only include wrappers in AOT object giving library builder the ability
to build a self contained library on Android that still runs majority of managed
code using JIT.

18 months ago[Mono] Support get_Count and get_AllBitsSet for mini JIT on Arm64 (#84180)
Fan Yang [Tue, 4 Apr 2023 10:01:44 +0000 (06:01 -0400)]
[Mono] Support get_Count and get_AllBitsSet for mini JIT on Arm64 (#84180)

* Support get_Count and get_AllBitsSet

* nint and nuint are 8 bytes on arm64 as well.

* Fix syntax

18 months agoStatic cctor analysis for reflection (#84089)
Vitek Karas [Tue, 4 Apr 2023 09:44:28 +0000 (02:44 -0700)]
Static cctor analysis for reflection (#84089)

This brings the NativeAOT behavior around static cctor analysis on part with illink.

Main change is to add checks for RUC/RAF/RDC on static cctor and produces a warning if there is one (as these are not allowed on static cctor).

The rest of the changes are just minor fixes and adjusting tests to the new behavior.

Contributes to https://github.com/dotnet/runtime/issues/82447.

18 months agoAdd issues.targets entry for known issue #84007 (#84268)
Tomáš Rylek [Tue, 4 Apr 2023 09:42:40 +0000 (11:42 +0200)]
Add issues.targets entry for known issue #84007 (#84268)

* Add issues.targets entry for known issue #84007

* Add handling for NEW_MDARR_RARE

---------

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
18 months agoJIT: Properly allocate shadow space for block op helpers on win-x64 (#84124)
Jakob Botsch Nielsen [Tue, 4 Apr 2023 08:04:31 +0000 (10:04 +0200)]
JIT: Properly allocate shadow space for block op helpers on win-x64 (#84124)

Move the accounting of the outgoing arg space size from simple lowering
to lowering and start accounting for the fact that some block ops may
turn into helper calls.

Fix #80140

18 months ago[browser][non-icu] `HybridGlobalization` change case (#84019)
Ilona Tomkowicz [Tue, 4 Apr 2023 07:07:04 +0000 (09:07 +0200)]
[browser][non-icu] `HybridGlobalization` change case (#84019)

* Enabled `HybridGlobalization` mode.

* Enabled non-icu change case.

* Tests.

* Revert not connected changes.

* Fix: Add the new file to the project.

* Fix: this PR is for Browser, so add it to condition.

* Fixed calls to js.

* Trying to fix CI.

* False is default, redundant lines.

* Trying to fix the CI.

* Remove redundant code.

* This PR is partial solution, this file will be added in a follow-up.

* Fix for EAT lib tests.

* We do not trim anything for Hybrid currently.

* Check if functions invoked only in specific modes.

* Change confusing name + move the common property to the main part of the class.

* Applied @mkhamoyan's suggestion.

* Fix previous commit: missing directive.

* Fix previous commit: missing directive.

* It's not IOS-connected.

* Move hybrid tests to correct dir + separate ios and wasm + update sln.

* Invariant and hybrid cannot be both true.

* Remove old version of hybrid tests proj.

* Applied @kg's review.

18 months agoFix reflection invoke file format issue for generic methods (#83438)
Michal Strehovský [Tue, 4 Apr 2023 03:37:16 +0000 (12:37 +0900)]
Fix reflection invoke file format issue for generic methods (#83438)

The file format that mapped reflection metadata to runtime artifacts had a limitation that required generic methods to be always instantiated over concrete types - we could not place canonical method bodies there. The limitation stemmed from the fact that the mapping table was placing a generic dictionary in it.

This switches the table to use NameAndSignature + an array of instantiation arguments.

The rest of this change is just deleting code that was working around the problem. The fixes in NativeLayoutVertexNode and NodeFactory.NativeLayout are fixing analysis holes that were exposed by our ability to be more lazy.

Also saves 0.4% on BasicWebApi, which is always nice.

18 months agoIntroduce a diagnostic switch to turn off the use of file mapping in PE loader. ...
Vladimir Sadov [Tue, 4 Apr 2023 03:29:57 +0000 (20:29 -0700)]
Introduce a diagnostic switch to turn off the use of file mapping in PE loader. (#84151)

* Introduce a diagnostic switch to turn off use of file mapping in PE loader.

* change default to off

* fix condition on Unix

18 months agoArm64: Implement VectorTableLookup/VectorTableLookupExtension intrinsinsic + Consecut...
Kunal Pathak [Tue, 4 Apr 2023 02:05:51 +0000 (19:05 -0700)]
Arm64: Implement VectorTableLookup/VectorTableLookupExtension intrinsinsic + Consecutive registers support (#80297)

* Add VectorTableLookup 2/3/4 in hwinstrinsiclistarm64.h

* Add VectorTableLookup

* fixes to libraries

* Prototype of simple tbl

* Some progress

* Some more updates

* working model

* Vector64<byte> support

* Add VectorTableLookup_3

* Add VectorTableLookup_4

* cleanup

* Remove regCount from LclVarDsc

* Some more cleanup

Some more cleanup

* setNextConsecutiveRegisterAssignment

* Some more cleanup

* TARGET_ARM64

* Use getNextConsecutiveRefPositions instead of nextConsecutiveRefPosition field

* jit format

* Move getNextConsecutiveRefPosition

* SA1141: Use tuple syntax

* Remove the unwanted field list code

* revert the flag that was mistakenly changed

* Add test cases

* FIELD_LIST

* Use FIELD_LIST approach

* jit format and fix arm build

* fix assert failure

* Add summary docs

Add summary docs in all the required files.

* Make APIs public again

* cleanup

* Handle case for reg mod 32

* Remove references from ref until API is approved

* Use generic getFreeCandidates()

* Add entries in ExtraAPis

* Set CLSCompliant=false

* Move in inner class

* Remove CLSCompliant flag

* Add a suppression file for System.Runtime.Intrinsics on the new APIs until it they go through API review

* Review feedback

* Add workaround for building tests

* review feedback

* TP: remove needsConsecutive parameter from BuildUse()

* TP: Remove pseudo intrinsic entries

* More fixes

* Add the missing csproj

* Fix test cases

* Add fake lib for AdvSimd.Arm64* as well

* Remove the workaround

* Use template to control if consecutive registers is needed or not

* jit format

* fix the workaround

* Revert "fix the workaround"

This reverts commit 1cb22d00d7159f40d33538ea29008e6764d52e45.

* Revert "Remove the workaround"

This reverts commit b0b6a5e9abea195bd6dc35c5a638d280f20d6ed2.

* Add VectorTableLookupExtensions  in libraries

* Add support for VectorTableLookupExtension

* WIP: available regs

* WIP: Remove test hacks

* Update getFreeCandidates() for consecutive registers

* Add missing resetRegState()

* Do not assume the current assigned register for consecutiveRegisters refposition is good.

If a refposition is marked as needConsecutive, then do not just assume that the existing register assigned
is good. We still go through the allocation for it to make sure that we allocate it a register such that the
consecutive registers are also free.

* Handle case for copyReg

For copyReg, if we assigned a different register, do not forget to free the existing register it was holding

* Update setNextConsecutiveRegister() with UPPER_VECTOR_RESTORE

* Update code around copyReg

Updated code such that if the refPosition is already assigned a register, then
check if assignedRegister satisfies are needs (for first / non-first refposition).
If not, performs copyReg.

TODO: Extract the code surrounding and including copyReg until where we `continue`.

* Create the VectorTableLookup fake CoreLib as a reference assembly

Make the AdvSimd.Arm64 tests reference the VectorTableLookup fake
CoreLib as reference assembly; and ensure that it is not included as a
ProjectReference by the toplevel HardwareIntrinsics merged test
runners.

The upshot is that the AdvSimd.Arm64 tests can call the extra APIs via
a direct reference to CoreLib (instead of through System.Runtime), but
the fake library is not copied into any test artifact directories, and
the Mono AOT compiler never sees it.

That said, after applying this, the test fails during AOT compilation
of the *real* CoreLib

```
Mono Ahead of Time compiler - compiling assembly /Users/alklig/work/dotnet-runtime/runtime-bugs2/artifacts/tests/coreclr/osx.arm64.Release/Tests/Core_Root/System.Private.CoreLib.dll
  AOTID EA8D702E-9736-3BD5-435B-A9D5EEADCC78
  %"System.ValueTuple`2<System.Runtime.Intrinsics.Vector128`1<byte>, System.Runtime.Intrinsics.Vector128`1<byte>>"* %arg_table
  <16 x i8>

  * Assertion: should not be reached at /Users/alklig/work/dotnet-runtime/runtime-bugs2/src/mono/mono/mini/mini-llvm.c:1455
```

* Rename VectorTableLookup to VectorTableLookup.RefOnly

* Start consecutive refpositions with RefTypeUse and never with RefTypeUpperVectorSave

* Add test cases for VectorTableLookupExtension

* Pass the missing defaultValues

* Use platform neutral BitScanForward

* jit format

* Remove the fake testlib workaround

* Fix mono failures

* Fix x64 TP regression

* Fix test cases

* fix some more tp regression

* Fix test build

* misc. changes

* Fix the bug where we were not freeing copyReg causing an assert in tier0

* Refactor little bit to reduce checks for VectorTableLookup

* Add template parameter for allocateReg/copyReg/select

* Comments

* Fix mono failures

* Added some more comments

* Call allocateReg/assignCopyReg/select methods only for refpositions that need consecutive registers

* Add heuristics to pick best possible set of registers which will need less spilling

* setNextConsecutiveRegisterAssignment() no longer checks for areNextConsecutiveRegistersFree()

* Rename getFreeCandidates() -> getConsecutiveCandidates()

* fix parameters to areNextConsecutiveRegistersFree()

* Rename and update canAssignNextConsecutiveRegisters()

* Add the missing setNextConsecutiveRegisterAssignment() calls

* Fix a condition for upperVector

* Update spill heurisitic to handle cases for jitstressregs

* Misc. remove popcount() check from getConsecutiveRegisters()

* jit format

* Fix a bug in canAssignNextConsecutiveRegisters()

* Add filterConsecutiveCandidates() and perform free/busy candidates scan

* Consume the new free/busy consecutive candidates method

* Handle case where 'copyReg == assignedReg'

* Misc. cleanup

* Include LsraExtraFPSetForConsecutive for stress regs

* handle case where 'assignedInterval == nullptr' for try_SPILL_COST()

* fix build error

* Call consecutiveCandidates() only for first refposition

* Only perform special handling for non-uppervectorrestore

* jit format

* Add impVectorTableLookup/impVectorTableLookupExtension

* Add the missing break

* Update assert

* Move definitions in GenTree, fix assert

* fix arm issue

* Remove common functions

* Rename info.needsConsecutiveRegisters to info.compNeedsConsecutiveRegisters

* Use needsConsecutiveRegisters template parameter for all configurations

* Handle case of round-robin in getConsecutiveRegisters()

* Disable tests for Mono

* Initialize outArray in test

* Add IsSupported checks for VectorLookup/VectorLookupExtension

* Fix the test cases for RunReflectionScenario_UnsafeRead()

* Review feedback

* wip

* fix a typo in test case

* Add filterConsecutiveCandidatesForSpill() to select range that needs fewer register spilling

* Add mono support.

* Delay free the registers for VectorTableLookupExtension

* fix mono build error

---------

Co-authored-by: Tanner Gooding <tagoo@outlook.com>
Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
Co-authored-by: Zoltan Varga <vargaz@gmail.com>
18 months agoFix debugger stack unwind AV (#84270)
Lee Culver [Tue, 4 Apr 2023 01:01:57 +0000 (18:01 -0700)]
Fix debugger stack unwind AV (#84270)

In the debugger we do not have in-memory pointers to the context record.  Stack unwinds are all concrete, and update pCurrentContext instead.  Due to this, this change https://github.com/dotnet/runtime/commit/60adacb2b7a4ab9dc1e5af6c71fdfce7ad87fac0 zeroed out the m_Ptrs variable for all callee saved registers.

This change wasn't sufficient, however, because we actually try to use pCurrentContextPointers in a variety of places while dealing with reporting GC references, leading to an AV when GcInfoDecoder::GetStackSlot attempts to report an offset to RBP for certain kinds of coreclr!Frames.

This change updates pCurrentContextPointers to point to pCurrentContext in the dac.

(This issue/change only applies to AMD64.)

18 months agoRefactor Interop.LocalAlloc follow-up (#84164)
xtqqczze [Mon, 3 Apr 2023 23:26:06 +0000 (00:26 +0100)]
Refactor Interop.LocalAlloc follow-up (#84164)

18 months agoPrepare ComInterfaceGenerator for going into the public API (#83894)
Jeremy Koritzinsky [Mon, 3 Apr 2023 23:06:26 +0000 (16:06 -0700)]
Prepare ComInterfaceGenerator for going into the public API (#83894)

18 months ago[PERF] Enable daily perf runs on cloud VMs (#84203)
Cameron Aavik [Mon, 3 Apr 2023 21:14:01 +0000 (07:14 +1000)]
[PERF] Enable daily perf runs on cloud VMs (#84203)

* Add perf run for cloud VMs

* Ensure x64 is built

* Use non-open queue for internal runs

18 months ago[mono] update sgen codewoners (#84255)
Aleksey Kliger (λgeek) [Mon, 3 Apr 2023 19:13:05 +0000 (15:13 -0400)]
[mono] update sgen codewoners (#84255)

18 months ago[RISC-V] Port Mono for RISC-V 64 Arch (1/3) lp64d ABI (#83714)
VincentWu [Mon, 3 Apr 2023 19:11:42 +0000 (03:11 +0800)]
[RISC-V] Port Mono for RISC-V 64 Arch (1/3) lp64d ABI (#83714)

* support abi lp64d for RISC-V 64

* format

18 months agoDelete `LCL_VAR_ADDR` (#84185)
SingleAccretion [Mon, 3 Apr 2023 19:00:36 +0000 (22:00 +0300)]
Delete `LCL_VAR_ADDR` (#84185)

* Delete GT_LCL_VAR_ADDR

The node is exactly equivalent to LCL_FLD_ADDR at offset zero.

There is no reason to have two representations for the same thing.

* Delete OperIsLocalAddr

No longer needed.

* GT_LCL_FLD_ADDR -> GT_LCL_ADDR

The generalized "local address" node.

* Help MSVC

Turns a 0.05% TP regression into a 0.05% TP win.

* gtNewLclFldAddrNode -> gtNewLclAddrNode

* Fix formatting

18 months ago[wasm] Don't publish the aot-instances.dll assembly, its not needed any more. (#84214)
Zoltan Varga [Mon, 3 Apr 2023 18:15:03 +0000 (14:15 -0400)]
[wasm] Don't publish the aot-instances.dll assembly, its not needed any more. (#84214)

The runtime creates a dummy version of it internally.

18 months ago[mono] Remove the support for non r4fp, its not used by any supported platforms....
Zoltan Varga [Mon, 3 Apr 2023 17:42:09 +0000 (13:42 -0400)]
[mono] Remove the support for non r4fp, its not used by any supported platforms. (#82005)

18 months ago[wasm] Re-enable jiterp null check optimization for mid-method traces (#84058)
Katelyn Gadd [Mon, 3 Apr 2023 17:30:32 +0000 (10:30 -0700)]
[wasm] Re-enable jiterp null check optimization for mid-method traces (#84058)

* Generate a bitset in the interpreter's codegen that identifies which spaces in the stack have had their address taken
* Use the interpreter bitset for jiterpreter null check optimization
* Enable null check optimization for all traces

18 months agoStop excluding existing files from CORE_ROOT generation (#84195)
Elinor Fung [Mon, 3 Apr 2023 16:54:00 +0000 (09:54 -0700)]
Stop excluding existing files from CORE_ROOT generation (#84195)

18 months agoLocalized file check-in by OneLocBuild Task: Build definition ID 679: Build ID 214955...
dotnet bot [Mon, 3 Apr 2023 16:18:48 +0000 (09:18 -0700)]
Localized file check-in by OneLocBuild Task: Build definition ID 679: Build ID 2149555 (#84102)

* Localized file check-in by OneLocBuild Task: Build definition ID 679: Build ID 2147000

* Localized file check-in by OneLocBuild Task: Build definition ID 679: Build ID 2147850

18 months agoSplit Rank1 MdArray allocation into a separate helper (#84205)
Michal Strehovský [Mon, 3 Apr 2023 16:01:24 +0000 (01:01 +0900)]
Split Rank1 MdArray allocation into a separate helper (#84205)

MdArray rank1 with all-zero lower bounds gets actually allocated as an SzArray. On Native AOT this means we need to spin up to the type loader to potentially load the new type. Split this expensive (and impossible-to-express-in-C#) thing into a separate helper so we can trim the type loader.

https://github.com/dotnet/runtime/pull/84156#issuecomment-1491402863

18 months ago[mono][llvm] Add a fastpath to calling mini_init_method_rgctx (). (#84226)
Zoltan Varga [Mon, 3 Apr 2023 15:22:06 +0000 (11:22 -0400)]
[mono][llvm] Add a fastpath to calling mini_init_method_rgctx (). (#84226)

* [mono][llvm] Add a fastpath to calling mini_init_method_rgctx ().

* Add arm64 JIT support.

18 months ago[mono] Futher cleanups to delegate invocation (#83705)
Zoltan Varga [Mon, 3 Apr 2023 15:21:45 +0000 (11:21 -0400)]
[mono] Futher cleanups to delegate invocation (#83705)

* [mono] Cache delegate->method_ptr in MonoDelegateTrampInfo instead of in delegate->method_code.

Repurpose the method_code field to store the MonoDelegateTrampInfo pointer
for future optimizations.

* Remove now unused MONO_PATCH_INFO_METHOD_CODE_SLOT.

* Remove unused mono_runtime_create_delegate_trampoline ().

* Reduce handle usage in mini_init_delegate ().

* Small cleanups to mono_delegate_trampoline ().

* Use the MonoDelegateTrampInfo from the delegate if possible.

18 months ago[main] Update dependencies from dotnet/arcade (#83882)
dotnet-maestro[bot] [Mon, 3 Apr 2023 14:49:36 +0000 (09:49 -0500)]
[main] Update dependencies from dotnet/arcade (#83882)

* Update dependencies from https://github.com/dotnet/arcade build 20230323.3

Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.23172.2 -> To Version 8.0.0-beta.23173.3

* Update dependencies from https://github.com/dotnet/arcade build 20230324.1

Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.23172.2 -> To Version 8.0.0-beta.23174.1

* Update dependencies from https://github.com/dotnet/arcade build 20230327.4

Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.23172.2 -> To Version 8.0.0-beta.23177.4

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Larry Ewing <lewing@microsoft.com>
18 months ago[main] Update dependencies from dotnet/roslyn (#84017)
dotnet-maestro[bot] [Mon, 3 Apr 2023 14:47:45 +0000 (09:47 -0500)]
[main] Update dependencies from dotnet/roslyn (#84017)

* Update dependencies from https://github.com/dotnet/roslyn build 20230328.1

Microsoft.CodeAnalysis , Microsoft.CodeAnalysis.CSharp , Microsoft.Net.Compilers.Toolset
 From Version 4.6.0-3.23175.1 -> To Version 4.6.0-3.23178.1

* Update dependencies from https://github.com/dotnet/roslyn build 20230328.17

Microsoft.CodeAnalysis , Microsoft.CodeAnalysis.CSharp , Microsoft.Net.Compilers.Toolset
 From Version 4.6.0-3.23175.1 -> To Version 4.7.0-1.23178.17

* Update dependencies from https://github.com/dotnet/roslyn build 20230329.16

Microsoft.CodeAnalysis , Microsoft.CodeAnalysis.CSharp , Microsoft.Net.Compilers.Toolset
 From Version 4.6.0-3.23175.1 -> To Version 4.7.0-1.23179.16

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>