* Access CanCompareBits from MethodTableAuxiliaryData
* Switch to QCall
* Fast path of GetHashCode
* Call for RegularGetValueTypeHashCode
* Cleanup unused FCall
* Use HashCode type
* Handle recursive case inside native code
* Remove Double and Single from CoreLibBinder
* Apply suggestions from code review
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
---------
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
* Remove HELPER_METHOD_FRAME from MngdNativeArrayMarshaler
* Mechanically convert the fixed array marshaller to QCalls.
* Move MngdFixedArrayMarshaler.ConvertSpaceToNative to managed code.
* Move the ICustomMarshaler-based marshalling to be written primarily in managed code instead of FCALLs
* Convert SafeArray marshaller to QCalls
* PR feedback and move CreateMarshaler implementations to manged code for marshalers that already have the state type defined in managed code.
* Remove some unused parameters, make some test failures more diagnosable, fix test failures.
* Instead of passing around an IntPtr to the helper, just pass around the custom marshaler object itself.
* Swallow exceptions from CleanUpNativeData like how the old implementation used to.
* Fix two edge cases.
* Fix null ref check
* Use `in` in more cases to make things clearer
* Don't call CleanUpManagedData for null managed values
* One more case I missed
* Apply suggestions from code review
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
* PR feedback
* Apply suggestions from code review
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
---------
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
* Improved uninitialized object creation performance
* Remove duplicate GenericCache getter call, revert to direct throw
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
---------
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
* Body of CopySlow and setup QCall for CanAssignArrayType
* UnBoxEachElement
* BoxEachElement
* CastCheckEachElement
* Move Unbox_Nullable to RuntimeHelpers
---------
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
* Remove FCall in interop code
* Convert DisableComObjectEagerCleanup to QCall.
* Convert the following to QCalls.
Thread.SleepWorker
Thread.GetIsBackground
Thread.SetIsBackground
Thread.Interrupt
* Feedback
* New exception handling diagnostic fixes
This change
* Adds debugger and profiler events in the right places and order
* Adds debugger exception interception implementation
* Ensures that the new managed exceptino handling frames are not visible
to the debugger stack trace
* Fixes some missing frames on stack traces (coming from
HelperMethodFrame)
* Moves first chance exception handling to the native code. It is
necessary to ensure that the exception stack trace contains frames
from the explicit frames that have MethodDesc at the time the event
fires.
* Makes some refactoring around the ExInfo - the CONTEXT and REGDISPLAY
are now in the ExInfo, the ExInfo contains the original exception pointers.
* Fixes one case when an UnhandledException at the boundary of managed
and native code was not handled correctly.
* Changes the way an unhandled exception in exception filter is
swallowed. The stack frame iterator was having issues with the fact
that the exception "leaked" from the actual filter and was caught by
another filter in the managed EH. Now the exception is always
swallowed at the filter.
* Fix bad merge
* Fix win x86 build break
* Reflect PR feedback
* Fix Watson not being triggered on unhandled exception
* Modify the unhandled exception processing
Slight modification of the code enables second pass for unhandled
exceptions. That makes finallys get called the same way as without the
new exception handling.
* Fix accidental edit
* InterfaceMarshaler.ConvertToManaged,ConvertToNative
* Fix handling of unmanaged CALLI in StubHelpers by the JIT
The free pass for CALLI inlining in IL stubs should not apply to inlined StubHelpers. The inlined StubHelpers need to pass inlining legality checks.
* Create array from array type
* InternalCreateFromArrayType
* code review:
- add missing comments for new public APIs
- use the new API in DataTypeImplementation (and solve a TODO)
- fix typo
- remove code that was commented out
- improve test name
* Fix perf and corner-case behaviors
* Delete superfluous validation
* Skip handling of void arrays for this PR
---------
Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
* Include info about system call errors in some exceptions from operating on named mutexes
- Added new PAL APIs for creating and opening mutexes that take a string buffer for system call error info. These are called with a stack-allocated buffer and upon error the system call errors are appended to the exception message.
- When there is a system call failure that leads to the PAL API failing, some info is appended to the error string, including the system call, relevant arguments, return value, and `errno`
- `chmod` on OSX seemingly can be interrupted by signals, fixed to retry. Also fixed a couple other small things.
Fixes https://github.com/dotnet/runtime/issues/89090
* Port NativeAOT exception handling to CoreCLR
This change ports NativeAOT exception handling to CoreCLR, resulting in
3.5..4 times speedup in exception handling. Due to time constraints and
various complexities, thread abort and debugger support is not
completed yet, so this change is enabled only when
`DOTNET_EnableNewExceptionHandling` env variable is set. By default,
the old way is used.
This change supports all OSes and targets we support except of x86
Windows. That may be doable too in the future, but the difference in
exception handling on x86 Windows adds quite a lot of complexity into
the picture.
Notes for the PR:
* I have left the `ExceptionHandling.cs` and `StackFrameIterator.cs` in
the nativeaot folder to simplify the review. I can move it to some
common location after the change is reviewed. Also it was not clear to
me where that should be, so advise would be welcome here.
* Naming of the native helpers like `RhpCallCatchFunclet` was left the
same as in the NativeAOT for now.
* There are still some little things I'd like to eventually clean up,
like `ExInfo` encapsulation and possibly moving `REGDISPLAY` and
`CONTEXT` it uses into the `ExInfo` itself or moving debug members of
`StackFrameIterator` and `REGDISPLAY` to the end of those structures
so that the `AsmOffsets.cs` can be simplified. It also may be possible
to unify the exception handling callback that's used for ObjectiveC to
use the managed version. I've tried and there were some ugly
complications, so I've left it separated.
* There are two bug fixes for bugs unrelated to this PR and a removal of
unused parameter in existing code that could be made as separate PRs
before this PR.
* `ProfilerEnter` and `ProfilerLeave` for the case of
`UnmanagedCallersOnly` method were being called in preemptive mode.
* NativeAOT code for rethrowing exception was incorrectly calling
`DispatchEx` with last argument set to `activeExInfo._idxCurClause`
to start at the last clause processed when the rethrown exception
was originally thrown instead of starting from the first one again.
I have a accidentally came with a simple test that discovered this
bug and causes failures in the original NativeAOT too.
* Changes in the stackwalk.cpp add support for
* Usage of `ExInfo` instead of `ExceptionTracker`
* Handling of case when GC runs while finally funclet is on the stack
and then again when the code is back in the new exception handling
code in managed code before other finally or catch funclet is
called. The NativeAOT solves that by disabling GC for the 2nd pass
of EH, for this change it would not be reasonable.
* Handling the GC reporting when funclet is found while walking the
stack. It needs to scan frames of the managed code that handles the
exception too, since it contains live references. The old EH way
doesn't have this case.
* I needed to add `GCFrame::Remove` method that can remove the `GCFrame`
from any location in the chain. There is a managed runtime method that
calls `GCReporting::Unregister` that was popping it with my changes
out of order due to the exception handling code being managed.
Fix context initialization after rebase
* Remove Rhp prefix from the native helpers
* Fix handling of exceptions from JIT
The `UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE` in the
`EE_TO_JIT_TRANSITION` needs to rethrow an exception (if any) using native
exception handling mechanism instead of calling the new managed
exception handling, as the native exception needs to propagate through
some native code layers from there.
This change adds parameter to the
`UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE` macro to select whether
to rethrow the exception as native or to invoke the new managed
exception handling.
This problem didn't show up until I ran the coreclr tests with tiered
compilation disabled.
* Update UNINSTALL_UNWIND_AND_CONTINUE_HANDLER usage
There were three places where the UNINSTALL_UNWIND_AND_CONTINUE_HANDLER
needed to be replaced by
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE(true).
* Rename INSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE
To INSTALL_UNWIND_AND_CONTINUE_HANDLER_EX, as the old name is obsolete
* Add managed entry points for raising Contention events
- Added the events similarly to how the PortableThreadPool events are currently set up. They may need further tweaking to make them work from NativeAOT.
- The events are not raised anywhere from the managed side yet, it's expected that they will eventually be raised by a new Lock type and at least by NativeAOT's Lock
Contributes to #72833 and #77868
The performance effect of this change on typical use of `Type.GetType` like `Type.GetType("MyType, MyAssembly")` is in the noise range. The typical use of `Type.GetType` spends most of the time in assembly loader and type loader. The time spent by parsing the type name is small fraction of the total and the performance improvement is hardly noticeable.
When the type name parser performance is measured in isolation, it is several times faster compared to the existing unmanaged CoreCLR type name parser. For example:
```
Type.GetType("System.Object, System.Private.CoreLib",
assemblyResolver: (an) => typeof(object).Assembly,
typeResolver: (assembly, name, ignoreCase) => typeof(object));
```
is about 3x faster with this change on CoreCLR.
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
* Remove fragile NGen logic for precomputed hashcodes
Hashing was confirmed to offer minor performance wins
but not with lazy hash code generation. Pre hashing was needed
to have a benefit on start-up but even then it was minor.
* Add TryGetComInstance and TryGetObject APIs
The ComWrappers API is being expanded to enable
users to get the underlying managed or unmanaged
object from the created wrappers.
* Add tagged interface for certainty in identifying
a wrapper is a ComWrappers impl.
Co-authored-by: Jeremy Koritzinsky <jkoritzinsky@gmail.com>