- Remove `GetDomain` functions on `MethodDesc`, `MethodTable`, `TypeDesc`, and `TypeHandle`. They always return the single current app domain.
- Remove `GetDomain` functions and variables on `Assembly`, `DomainAssembly`, and `Module`. The actual domain they are constructed with is always the single current app domain.
- Remove all IBC comments from the vm portion of the codebase
- Remove `m_GenericTypeDefToCanonMethodTableMap` and `m_MehtodDefToPropertyInfoMap` which were only filled in by NGen
- Remove a variety of flags enums which are never used
- Remove infra for testing Zap and IBC scenarios
- Remove ZapDisable as @egorbo suggested
* 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
* 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
* Remove DelegateInvokeStubManager
All Delegate Invoke scenarios now use the StubLinker.
This means there is an inherent confusion between the
two stub managers. Upon further inspection combining
these two by adding a new flag on the Stub class means
they can be combined logically and simplify the code
path by removing a StubManager.
* wip
* add __tls_get_addr() code in jitinterface
* working model
* linux rely on __tls_get_addr() value
* Add fields for both max/threadSTaticBlocks, have separate for GC/non-gc
* code cleanup
* code cleanup
* add comments
* jit format
* update guid
* review feedback
* fix the offset
* arm64: wip
* linux arm64 model
* arm64: offsetOfThreadStaticBlock adjustment
* Add mrs and tpid0 register
* arm64: use the new mrs/tpidr0
* fix arm64 build and offset calculation:
* arm64: working
* arm64: move to struct model
* arm64: fixed the struct model
* x64: move to struct model
* code refactoring
* #define for field access
* change mrs -> mrs_tpid0
* fix a bug
* remove unwanted method
* another fix
* Add entries in CorInfoType.cs
* Update the #ifdef
* fix the windows scenario:
* review feedback
* fix the data-type
* add osx-arm64 support
* fix osx-arm64 issues
* fix build error
* fix build error after merge
* add osx/x64 support
* fix errors
* fix the macos/x64
* disable for alpine linux
* Disable for R2R
* review feedback
* fix r2r check
* move windows to struct model
* review feedback
* fix the register clobbering in release bits
* Move the linux/x64 logic to .S file
* Use TargetOS::IsMacOS
* disable optimization for single file
* working for linux/x64
* fix some errors for osx/x64
* fix for osx x64/arm64
* fix for arm64 linux/osx
* try disable for musl/arm64
* rename variable
* Rename variable to tlsIndexObject
* Make offset variables as uint32_t
* change the type of indexObj/ftnAddr to void*
* replace ifdef(msc_ver) with ifdef(windows)
* Revert to JIT_TO_EE_TRANSITION_LEAF
* Move code to asmHelpers.S and rename method
* rename the methods per the platform
* fix osx builds
* fix build break
* fix some errors around osx
* rename some more methods
* review feedback
* review feedback
* delete the comment
* make methods static
* remove macos/x64 check
* fix the check for linux/x64
* detect early for single-file linux/x64
* move the assert
* review feedback
* misc fixup
* use fgMorphArgs()
* remove commented code
* Add CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED
* Working prototype
* Rename ThreadStaticBlock to NonGCThreadStaticBlock
* Add GCThreadStaticBlock
* fix linux build
* Restrict the optimization to non-generics
* Update the guid
* Add canOptimizeHelper check
* Rename and related methods from typeIDMap to NonGCTypeID
* Introduce GCTypeIDMap and getGCThreadLocalFieldInfo()
* Use GCThreadLocalFieldInfo()
* fix the bug about gc tracking
* resolve merge conflicts
* remove the commented code
* add comment
* Unify some of the non-gc/gc methods
* fix missing methods
* update the comments
* Track gc for derefernce of object handle
* fix the superpmi methods
* review feedback
* Update minipal with UTF-16 functions
* Remove function redefines from PAL header
* Remove need of PAL_wcslen from LTTNG
generator.
* Remove specified calling conventions for x86
* Add CORINFO_THREAD_LOCAL_FIELD_INFO and getThreadLocalFieldInfo()
* Implementation of getThreadLocalFieldInfo()
* Change the field types from CORINFO_CONST_LOOKUP to uint32_t
* Introduce CORINFO_FIELD_STATIC_TLS_MANAGED
* Introduce GTF_FLD_TLS_MANAGED
* Introduce eeGetThreadLocalFieldInfo()
* Fix the offsetOfThreadStaticBlocks, hardcode threadStaticBlockIndex for now
* Add impThreadLocalFieldAccess()
* Switch to GS segment register with a TODO
* Add reverse map `g_threadStaticBlockTypeIDMap` for type -> ID
* Fix GS segment register encoding
* Add comment for g_threadStaticBlockTypeIDMap
* Add extra parameter for typeIndex in JIT_GetSharedNonGCThreadStaticBase
* Update JIT_GetSharedNonGCThreadStaticBase to add logic for storing typeIndex in t_threadStaticBlocks
* Fix encoding of gs:[0x58]
* fix some bugs in importer to change size from 4 to 8
* add some printf in jithelpers
* To revert
* Update the helper to skip making re-entry for staticBlock
* Add impThreadLocalFieldWrite() for store
* Fix a issue for helper
* Use JITDUMP
* Just enable the optimization for primitive types
* Update the JITEE guid
* Fix an assert for volatile variables
* Mark helper block as cold block
* wip
* Fix the size of maxThreadStaticBlock
* fix a bug to insert the entry in cache
* Add #ifdef for HOST_WINDOWS / TARGET_WINDOWS
* Dynamic memory allocation for static block array
* Call InitTypeMap only if host == windows
* Add CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED
* Expand the TLS field access in late phase
* Move rarely ran block to the end
* wip
* Fix the bug to access the value from fastPath
* Remove code from importer
* Cleanup the code
* Moved CreateBlockFromTree to fgbasic.cpp
* Move fgExpandThreadLocalAccess() to flowgraph.cpp
* Add getThreadLocalStaticBlocksInfo() method
* Consume getThreadLocalStaticBlocksInfo() method
* Updated definition of getThreadLocalFieldInfo()
* Rename CORINFO_THREAD_LOCAL_FIELD_INFO to CORINFO_THREAD_STATIC_BLOCKS_INFO
* Add TARGET_WINDOWS
* Make TARGET_WINDOWS at some definitions
* Add dummy definition for unix
* jit format
* remote unnecessary code from morph
* Fix an issue on linux, add assert for tls_index != 0
* Convert from TARGET_WINDOWS to HOST_WINDOWS
* jit format
* fix the if-check
* fix gcc build error
* Added MethodHaveTlsFieldAccess()
* Handle the case for '_tls_index == 0'
* fix a typo
* Fix windows/arm64 issue
* fix encoding of teb loading for arm64
* Fix the condition in jitinterface to select correct helper
* fix the condition for other helper too
* fix the windows/x86 case
* jit format
* Use CORINFO_CONST_LOOKUP for _tls_index
* Move typeIdMap to BaseDomain class
* Introduce useFatPointerDispatch parameter for GetTypeID()
* jit format
* Do not pass classID and moduleID to the new helper
* fix build for non-windows
* fix superpmi methods
* review feedback
* fix linux build errors
* review feedback
* fix weight inherit
* inline JIT_GetNonGCThreadStaticBase_Helper to fix the contract error
* Remove dead code from helper
* Add GTF_CALL_M_EXP_TLS_ACCESS to check if we do not revisit the already expanded call node
* address feedback
* regenerate the files
* Introduce fgExpandHelper and fgExpandHelperForBlock and reuse it for various helper expansion
* fix the typo
* update the assert for runtimelookup
* check if we should skip rarely run blocks
* review feedback
* Remove GTF_IND_INVARIANT from `typeIndex` access because it produces nullptr 1st time and valid value 2nd time onwards
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>
* CoreCLR initialization failures logging
This change adds detecting and logging of failures during coreclr
initialization. For logging, it uses a new host API
`coreclr_set_error_writer` to register a callback to report the errors
to the host. The hosts have support for optional usage of this API so
that they can work with older runtime versions as well.
The logging checks and reports failures with:
* System.Private.CoreLib.dll
* GC initialization
* JIT initialization
* libSystem.Native.so/dylib on Unix
The logging messages should allow customers to self-diagnose the issues
causing the failures.
* Reflect PR feedback and a bit of cleanup
* revert the try_get_export to not to have the isOptional argument
* Unify the error logging in JIT loading to single variadic macro
* Also fixes Unix build, the code in gcenv.unix.cpp cannot use the GCToEEInterface
* Add single file host detection
* Fix libSystem.Native check location
* Add the coreclr_set_error_writer API to Mono
* Fix Mono x86 missing calling convention spec
* Fix error code returned when the S.P.C. is not found
* Delete managed CoreClr WR
* all but com works
* COM tests are passing
* HandleTagBits const for NativeAot
* Exclusive Set
* fix
* Use sign bit
* Platforms not supporting COM can mask only one bit.
* new approach
* fix mono build
* check for FEATURE_COMWRAPPERS too
* stub NativeAOT support (NYI).
* current
* moved handle tags on the managed side to one location
* Getter optimizations
* Optimizations for Setter
* accessibility of some members
* ensure identity of the rehydrated RCW
* make ComWeakRefToObject a QCall
* delete unused pWeakReferenceOfTCanonMT and pWeakReferenceMT
* byte-aligned
* cleanup unreachable code
* renamed WeakReferenceObject::m_Handle -> WeakReferenceObject::m_taggedHandle
* Apply suggestions from code review
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
* some PR feedback
* GetWeakHandle no longer cares about inlining.
* turn ObjectToComWeakRef into a QCall
* revert changes under coreclr\gc
* added a note to eventually remove HNDTYPE_WEAK_NATIVE_COM
* Update src/coreclr/gc/gcinterface.h
Co-authored-by: Maoni Stephens <Maoni0@users.noreply.github.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Maoni Stephens <Maoni0@users.noreply.github.com>
This PR reverts #76235 with a few manual modifications:
The main issue why the initial PRs (#75573 and #76135) were reverted has just been resolved via #76251:
GC could collect some associated (with frozen objects) objects as unreachable, e.g. it could collect a SyncBlock, WeakReferences and Dependent handles associated with frozen objects which could (e.g. for a short period of time) be indeed unreachable but return back to life after.
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>