diff options
author | Sergiy Kuryata <sergeyk@microsoft.com> | 2016-12-09 06:52:13 +0300 |
---|---|---|
committer | Sergiy Kuryata <sergeyk@microsoft.com> | 2016-12-09 07:26:15 +0300 |
commit | c84bb4e535e8268bbeb14f256a8764df932bd48d (patch) | |
tree | 30a9c2f3f21e4a18357112a673bbde9574dcc569 /src/Test.CoreLib | |
parent | e80f0a3604a3073e896d19b76ca3f803307a687c (diff) |
Implement basic support for thread static fields
This change implements basic support for thread static fields. Most things
are already functional, performance could definitely be improved in the
future but it should be sufficient to get things off the ground.
This code passes CoreRT and Top200 CoreCLR tests on Windows. The
BasicThreading test in this change verifies that thread static fields work
for both non-generic and generic types in the single-threaded and
multi-thread environment (using Tasks).
One thing that does not work yet is multi-module compilation because the
driver creates a separate ReadyToRun helper for a type in every module
that accesses thread statics of the type. I am currently working on fixing
this.
The existing code has already implemented a good chuck of required
functionality so this simply builds on top of that.
Each module has a ThreadStatic region. Each entry in the region points to
an EEType that represents a GC map for the thread static fields of a given
type. The index of the entry in the region is the TLS index of the type.
The TypeManager indirection node of the module has been extended to
contain the index of the module in addition to a pointer to the type
manager (which is also used for initialization on first access).
The generated ReadyToRun helpers (that return thread static base for a
type) look like this:
__GetThreadStaticBase_System_Private_CoreLib_System_Threading_ManagedThreadId:
48 8D 0D BD E0 39 00 lea rcx,[__typemanager_indirection
(07FF70D68AD58h)] <= module information (type manager, module index)
BA 03 00 00 00 mov edx,3 <= TLS index of the type
E9 33 FB E4 FF jmp
System_Private_CoreLib_Internal_Runtime_ThreadStatics__GetThreadStaticBaseForType
(07FF70D13C7D8h)
Diffstat (limited to 'src/Test.CoreLib')
-rw-r--r-- | src/Test.CoreLib/src/System/Runtime/RuntimeImports.cs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/Test.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/Test.CoreLib/src/System/Runtime/RuntimeImports.cs index e240db0a2..f32429fcc 100644 --- a/src/Test.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/Test.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -6,6 +6,7 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; +using Internal.Runtime; namespace System.Runtime { @@ -44,6 +45,10 @@ namespace System.Runtime [RuntimeImport(RuntimeLibrary, "RhpRegisterFrozenSegment")] internal static extern bool RhpRegisterFrozenSegment(IntPtr pSegmentStart, int length); + [RuntimeImport(RuntimeLibrary, "RhpGetModuleSection")] + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern IntPtr RhGetModuleSection(IntPtr module, ReadyToRunSectionType section, out int length); + // // calls to runtime for allocation // These calls are needed in types which cannot use "new" to allocate and need to do it manually |