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/Native/Runtime/thread.h | |
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/Native/Runtime/thread.h')
-rw-r--r-- | src/Native/Runtime/thread.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Native/Runtime/thread.h b/src/Native/Runtime/thread.h index 5d4d39fcf..5eada8318 100644 --- a/src/Native/Runtime/thread.h +++ b/src/Native/Runtime/thread.h @@ -91,6 +91,11 @@ struct ThreadBuffer // Thread Statics Storage for dynamic types UInt32 m_numDynamicTypesTlsCells; PTR_PTR_UInt8 m_pDynamicTypesTlsCells; + +#if CORERT + PTR_PTR_VOID m_pThreadLocalModuleStatics; + UInt32 m_numThreadLocalModuleStatics; +#endif // CORERT }; struct ReversePInvokeFrame @@ -248,6 +253,11 @@ public: bool InlineTryFastReversePInvoke(ReversePInvokeFrame * pFrame); void InlineReversePInvokeReturn(ReversePInvokeFrame * pFrame); + +#if CORERT + Object* GetThreadStaticStorageForModule(UInt32 moduleIndex); + Boolean SetThreadStaticStorageForModule(Object * pStorage, UInt32 moduleIndex); +#endif // CORERT }; #ifndef GCENV_INCLUDED |