![]() * 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. |
||
---|---|---|
.config | ||
.devcontainer | ||
.github | ||
docs | ||
eng | ||
src | ||
.clang-format | ||
.clang-tidy | ||
.CodeQL.yml | ||
.dockerignore | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.markdownlint.json | ||
.vsconfig | ||
build.cmd | ||
Build.proj | ||
build.sh | ||
CODE-OF-CONDUCT.md | ||
CONTRIBUTING.md | ||
Directory.Build.props | ||
Directory.Build.rsp | ||
Directory.Build.targets | ||
Directory.Solution.props | ||
dotnet.cmd | ||
dotnet.sh | ||
github-merge-flow.jsonc | ||
global.json | ||
LICENSE.TXT | ||
NuGet.config | ||
PATENTS.TXT | ||
README.md | ||
SECURITY.md | ||
THIRD-PARTY-NOTICES.TXT |
.NET Runtime
- What is .NET?
- How can I contribute?
- Reporting security issues and security bugs
- Filing issues
- Useful Links
- .NET Foundation
- License
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 to use .NET (with VS, VS Code, command-line CLI)
- Install official releases
- Documentation (Get Started, Tutorials, Porting from .NET Framework, API reference, ...)
- Support (Releases, OS Versions, ...)
- Roadmap
How can I contribute?
We welcome contributions! Many people all over the world have helped make this project better.
- Contributing explains what kinds of contributions we welcome
- Workflow Instructions explains how to build and test
- Dogfooding .NET explains how to get nightly builds of the runtime and its libraries to test them in your own projects.
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.
Useful Links
- .NET source index / .NET Framework source index
- API Reference docs
- .NET API Catalog (incl. APIs from daily builds and API usage info)
- API docs writing guidelines - useful when writing /// comments
- .NET Discord Server - a place to discuss the development of .NET and its ecosystem
.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.