1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-09 09:34:49 +09:00
Experimenting with dotnet runtime.
Find a file
Jan Vorlicek dd2120b9f8
Remove global spinlock for EH stacktrace (#103076)
* Remove global spinlock for EH stacktrace

The global spinlock that was used to ensure that stack trace and the
associated dynamic methods array were updated and read atomically.
However, for the new EH, it has shown to cause a high contention in case
many threads were handling exceptions at the same time.

This change replaces the two arrays by one object member in the
exception class. It contains reference to either the byte[] of the
stack trace (when there are no dynamic methods on the stack trace) or an
object[] where the first element contains the stack trace byte[]
reference and the following elements contain what used to be in the
dynamic array. That allows atomic updates and reads of the stack trace
and dynamic method keepalive references without a need of a lock.

The original code was quite convoluted, it was difficult to reason about
and it had some races in it that were hidden behind the global lock. So
I have decided to rewrite the whole thing from scratch.

The way it ensures that it is race free is that whenever it updates the
exception stack trace and the one that's on the exception was created by
a different thread, it creates a deep copy of both the stack trace and
the keepalive array. When making the copy, it also handles a case when
a frame that needs a keepalive entry is on the stack trace part, but the
keepalive array extracted from the exception is stale (the other thread
needed to resize the keepalive array, but not the stack trace). In that
case, the stack trace is trimmed at first such entry found.

Since the case when multiple threads are throwing the same exception and
so they are modifying its stack trace in parallel is pathological
anyways, I believe the extra work spent on creating the clones of the arrays
is a good tradeoff for ensuring easy to reason about thread safety.

I have also removed a dead code path from the
StackTraceInfo::SaveStackTrace.

Finally, since with the previous iteration of this change, a bug in
building the stack trace was found, I have added a coreclr test to
verify stack trace for an exception matches the expectations.

* Fix MUSL build

* Fix x86 build

* Fix several issues

* Missing calls to IsOverflow at few places
* Added a flag on StackTraceElement to indicate that the element needs a
  keepalive entry. It removes the need to call IsLCGMethod / Collectible
  check on the method table stored in the element and eliminates a
  possible problem with the method being collected in one place.
* Returned missing call to StackFrameInfo::Init to the x86 code path
* Removed obsolete comment and code line

* Few changes based on feedback

* Add keep alive items count to the stack trace header.
* Implement the concept of frozen stack traces to eliminate copies in
  the ExceptionDispatchInfo storing / restoring exceptions.

* Rename keepalive to keepAlive

* Handle possible array size overflow

In the StackTraceArray::Allocate

* Fix typo

* Change the size / keepAlive fields in stack trace to uint32_t

Plus a build break fix

* Remove SaveStackTracesFromDeepCopy

Also rename GetStackTracesDeepCopy to GetFrozenStackTrace and move the
return argument to return value.

* Remove dummy field and an unused function

* Cleanup based on feedback

* Move the race handling into GetStackTrace only

Plus an unused method removal and a little naming / contract cleanup

* Add VolatileLoad/Store around the size / keep alive count

Also remove the memory barrier from the StackTraceArray::Append since it
is not needed after that change.

* Add comment on why trimming the stack trace by keep alive is needed

I have also realized that when we need to trim, the keepAlive array is
always fully populated, so we don't need to check for cases where there
would be NULL in an entry of the array.
2024-07-08 21:52:13 +02:00
.config [main] Update dependencies from 8 repositories (#103574) 2024-06-29 00:41:36 +02:00
.devcontainer Remove explicit EMSDK_PATH in devcontainer.json (#102598) 2024-05-23 13:47:29 +02:00
.github jit-format job fixes (#103910) 2024-06-24 15:36:37 -07:00
docs [cdac] RuntimeTypeSystem contract; rename ContainsPointers -> ContainsGCPointers (#103444) 2024-07-08 09:09:23 -04:00
eng [main] Update dependencies from dotnet/roslyn (#104363) 2024-07-08 20:44:59 +02:00
src Remove global spinlock for EH stacktrace (#103076) 2024-07-08 21:52:13 +02:00
.clang-format Move clang-format download into dotnet/runtime and add docs for setting up auto-formatting in the repository (#59374) 2021-09-23 14:34:00 -07:00
.clang-tidy Move JIT's clang-tidy flags into configuration files and add a root clang-tidy config that disables all checks. (#93951) 2023-10-25 15:16:22 -07:00
.CodeQL.yml Move CodeQL config file to root (#99575) 2024-03-11 21:31:02 -07:00
.dockerignore [HTTP/SSL] Fix stress (#93135) 2023-10-09 11:54:41 +02:00
.editorconfig Set csharp_indent_case_contents_when_block to false (#103091) 2024-06-13 14:14:47 -07:00
.gitattributes Update .gitattributes (#100736) 2024-05-22 09:50:38 -07:00
.gitignore Add the autocreated .mono/ folder to .gitignore (#102054) 2024-05-14 20:49:43 -06:00
.markdownlint.json Enable markdownlint rule (MD009) (#40887) 2021-02-08 10:43:40 -08:00
.vsconfig Bump Windows SDK version in .vsconfig (#103217) 2024-06-10 07:09:34 -07:00
build.cmd Print help for -? and /? cross-plat (#42396) 2020-09-24 14:27:24 +02:00
Build.proj Update unified build controls (#98330) 2024-02-15 18:48:18 +01:00
build.sh Add windows support for build.sh (#94) 2019-11-18 16:41:36 +01:00
CODE-OF-CONDUCT.md Initial runtime repository structure 2019-11-14 01:26:19 +01:00
CONTRIBUTING.md Fix maui link (#97509) 2024-01-25 09:51:34 -06:00
Directory.Build.props Revert "Migrate to zlib-ng, part 2: consume it in runtime (#102403)" (#104414) 2024-07-04 15:47:50 +02:00
Directory.Build.rsp Disable msbuild terminal logger (#97309) 2024-01-22 13:08:28 -05:00
Directory.Build.targets Keep our System.Text.Json version used in HostModel in sync with MSBuild (#101199) 2024-04-17 13:33:40 -07:00
Directory.Solution.props Fix solution restore in libraries (#38294) 2020-06-23 22:35:40 +02:00
dotnet.cmd Move dotnet.cmd/sh helper scripts into the repo root (#672) 2019-12-11 21:01:58 +01:00
dotnet.sh Move dotnet.cmd/sh helper scripts into the repo root (#672) 2019-12-11 21:01:58 +01:00
github-merge-flow.jsonc Onboard new inter-branch merge flow [Configuration] (#103805) 2024-07-03 11:29:56 -07:00
global.json [main] Update dependencies from dotnet/arcade (#103412) 2024-06-29 00:45:45 +02:00
LICENSE.TXT Revert "Update "LICENSE.txt" so that it's recognized as MIT" (#37626) 2020-06-08 22:22:27 -04:00
NuGet.config Remove dotnet8 feeds from NuGet.config (#95860) 2023-12-15 23:25:08 +01:00
PATENTS.TXT Update repo link to dotnet/runtime (#1781) 2020-01-15 21:16:56 -05:00
README.md Link to general support page from repo readme (#104188) 2024-06-29 15:57:56 -07:00
SECURITY.md Fix trailing whitespaces (#40891) 2020-08-19 17:29:01 -07:00
THIRD-PARTY-NOTICES.TXT Add user_events support for the native runtime events (#102523) 2024-06-19 09:41:10 -07:00

.NET Runtime

Build Status Help Wanted Good First Issue Gitter Discord

This repo contains the code to build the .NET runtime, libraries and shared host (dotnet) installers for all supported platforms, as well as the sources to .NET runtime and libraries.

What is .NET?

Official Starting Page: https://dotnet.microsoft.com

How can I contribute?

We welcome contributions! Many people all over the world have helped make this project better.

Reporting security issues and security bugs

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter. You can also find these instructions in this repo's Security doc.

Also see info about related Microsoft .NET Bounty Program.

Filing issues

This repo should contain issues that are tied to the runtime, the class libraries and frameworks, the installation of the dotnet binary (sometimes known as the muxer) and the installation of the .NET runtime and libraries.

For other issues, please file them to their appropriate sibling repos. We have links to many of them on our new issue page.

.NET Foundation

.NET Runtime is a .NET Foundation project.

There are many .NET related projects on GitHub.

  • .NET home repo - links to 100s of .NET projects, from Microsoft and the community.
  • ASP.NET Core home - the best place to start learning about ASP.NET Core.

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.

General .NET OSS discussions: .NET Foundation Discussions

License

.NET (including the runtime repo) is licensed under the MIT license.