Skip to content

Commit bf5e279

Browse files
committed
Merge in 'release/8.0' changes
2 parents eddf880 + a6e4834 commit bf5e279

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

src/coreclr/vm/ceemain.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,7 @@ struct TlsDestructionMonitor
17521752
GCX_COOP_NO_DTOR_END();
17531753
}
17541754
thread->DetachThread(TRUE);
1755+
DeleteThreadLocalMemory();
17551756
}
17561757

17571758
ThreadDetaching();
@@ -1768,6 +1769,35 @@ void EnsureTlsDestructionMonitor()
17681769
tls_destructionMonitor.Activate();
17691770
}
17701771

1772+
#ifdef _MSC_VER
1773+
__declspec(thread) ThreadStaticBlockInfo t_ThreadStatics;
1774+
#else
1775+
__thread ThreadStaticBlockInfo t_ThreadStatics;
1776+
#endif // _MSC_VER
1777+
1778+
// Delete the thread local memory only if we the current thread
1779+
// is the one executing this code. If we do not guard it, it will
1780+
// end up deleting the thread local memory of the calling thread.
1781+
void DeleteThreadLocalMemory()
1782+
{
1783+
t_NonGCThreadStaticBlocksSize = 0;
1784+
t_GCThreadStaticBlocksSize = 0;
1785+
1786+
t_ThreadStatics.NonGCMaxThreadStaticBlocks = 0;
1787+
t_ThreadStatics.GCMaxThreadStaticBlocks = 0;
1788+
1789+
if (t_ThreadStatics.NonGCThreadStaticBlocks != nullptr)
1790+
{
1791+
delete[] t_ThreadStatics.NonGCThreadStaticBlocks;
1792+
t_ThreadStatics.NonGCThreadStaticBlocks = nullptr;
1793+
}
1794+
if (t_ThreadStatics.GCThreadStaticBlocks != nullptr)
1795+
{
1796+
delete[] t_ThreadStatics.GCThreadStaticBlocks;
1797+
t_ThreadStatics.GCThreadStaticBlocks = nullptr;
1798+
}
1799+
}
1800+
17711801
#ifdef DEBUGGING_SUPPORTED
17721802
//
17731803
// InitializeDebugger initialized the Runtime-side COM+ Debugging Services

src/coreclr/vm/ceemain.h

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void ThreadDetaching();
4747

4848
void EnsureTlsDestructionMonitor();
4949

50+
void DeleteThreadLocalMemory();
51+
5052
void SetLatchedExitCode (INT32 code);
5153
INT32 GetLatchedExitCode (void);
5254

src/coreclr/vm/jithelpers.cpp

+5-16
Original file line numberDiff line numberDiff line change
@@ -1777,24 +1777,13 @@ HCIMPL1(void*, JIT_GetGCThreadStaticBase_Helper, MethodTable * pMT)
17771777
}
17781778
HCIMPLEND
17791779

1780-
struct ThreadStaticBlockInfo
1781-
{
1782-
uint32_t NonGCMaxThreadStaticBlocks;
1783-
void** NonGCThreadStaticBlocks;
1784-
1785-
uint32_t GCMaxThreadStaticBlocks;
1786-
void** GCThreadStaticBlocks;
1787-
};
1788-
17891780
#ifdef _MSC_VER
1790-
__declspec(selectany) __declspec(thread) ThreadStaticBlockInfo t_ThreadStatics;
1791-
__declspec(selectany) __declspec(thread) uint32_t t_NonGCThreadStaticBlocksSize;
1792-
__declspec(selectany) __declspec(thread) uint32_t t_GCThreadStaticBlocksSize;
1781+
__declspec(thread) uint32_t t_NonGCThreadStaticBlocksSize;
1782+
__declspec(thread) uint32_t t_GCThreadStaticBlocksSize;
17931783
#else
1794-
EXTERN_C __thread ThreadStaticBlockInfo t_ThreadStatics;
1795-
EXTERN_C __thread uint32_t t_NonGCThreadStaticBlocksSize;
1796-
EXTERN_C __thread uint32_t t_GCThreadStaticBlocksSize;
1797-
#endif
1784+
__thread uint32_t t_NonGCThreadStaticBlocksSize;
1785+
__thread uint32_t t_GCThreadStaticBlocksSize;
1786+
#endif // !_MSC_VER
17981787

17991788
// *** This helper corresponds to both CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE and
18001789
// CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR. Even though we always check

src/coreclr/vm/jitinterface.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,9 @@
6969
EXTERN_C uint32_t _tls_index;
7070
#endif
7171

72-
struct ThreadStaticBlockInfo
73-
{
74-
uint32_t NonGCMaxThreadStaticBlocks;
75-
void** NonGCThreadStaticBlocks;
76-
77-
uint32_t GCMaxThreadStaticBlocks;
78-
void** GCThreadStaticBlocks;
79-
};
80-
#ifdef _MSC_VER
81-
__declspec(selectany) __declspec(thread) ThreadStaticBlockInfo t_ThreadStatics;
82-
__declspec(selectany) __declspec(thread) uint32_t t_NonGCThreadStaticBlocksSize;
83-
__declspec(selectany) __declspec(thread) uint32_t t_GCThreadStaticBlocksSize;
84-
#else
72+
#ifndef _MSC_VER
8573
extern "C" void* __tls_get_addr(void* ti);
86-
__thread ThreadStaticBlockInfo t_ThreadStatics;
87-
__thread uint32_t t_NonGCThreadStaticBlocksSize;
88-
__thread uint32_t t_GCThreadStaticBlocksSize;
89-
#endif // _MSC_VER
74+
#endif // !_MSC_VER
9075

9176
// The Stack Overflow probe takes place in the COOPERATIVE_TRANSITION_BEGIN() macro
9277
//

src/coreclr/vm/jitinterface.h

+19
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ BOOL LoadDynamicInfoEntry(Module *currentModule,
101101

102102
#endif // TARGET_X86
103103

104+
// thread local struct to store the "thread static blocks"
105+
struct ThreadStaticBlockInfo
106+
{
107+
uint32_t NonGCMaxThreadStaticBlocks;
108+
void** NonGCThreadStaticBlocks;
109+
110+
uint32_t GCMaxThreadStaticBlocks;
111+
void** GCThreadStaticBlocks;
112+
};
113+
114+
#ifdef _MSC_VER
115+
EXTERN_C __declspec(thread) ThreadStaticBlockInfo t_ThreadStatics;
116+
EXTERN_C __declspec(thread) uint32_t t_NonGCThreadStaticBlocksSize;
117+
EXTERN_C __declspec(thread) uint32_t t_GCThreadStaticBlocksSize;
118+
#else
119+
EXTERN_C __thread ThreadStaticBlockInfo t_ThreadStatics;
120+
EXTERN_C __thread uint32_t t_NonGCThreadStaticBlocksSize;
121+
EXTERN_C __thread uint32_t t_GCThreadStaticBlocksSize;
122+
#endif // _MSC_VER
104123

105124
//
106125
// JIT HELPER ALIASING FOR PORTABILITY.

0 commit comments

Comments
 (0)