Enable thread statics for collectible classes (dotnet/coreclr#19944)
authorJan Vorlicek <janvorli@microsoft.com>
Thu, 4 Oct 2018 08:26:06 +0000 (10:26 +0200)
committerGitHub <noreply@github.com>
Thu, 4 Oct 2018 08:26:06 +0000 (10:26 +0200)
commit913823d5d066017ce2f4174bcf83b663534a8dd4
tree70c829b1245c338a367ee305093bf16ccbcdd48c
parenta29d4e6dc87e33e9b1d05e372bee5f74b989f622
Enable thread statics for collectible classes (dotnet/coreclr#19944)

* Enable thread statics for collectible classes

This change removes checks that were preventing usage of thread statics
in collectible classes and also implements all the necessary changes.
The handles that hold arrays with thread statics are allocated from
LoaderAllocator for collectible classes instead of using the global
strong handle like in the case of non-collectible classes.
The change very much mimics what is done for regular statics.

This change also adds ability to reuse freed handles to the
LoaderAllocator handle table. Freed handle indexes are stored into a
stack and when a new handle allocation is requested, the indices from
this stack are used first.
Due to the code path from which the FreeTLM that in turn frees the
handles is called, I had to modify the critical section flags and also
refactor the handle allocation so that the actual managed array
representing the handle table is allocated out of the critical section.
When I was touching the code, I have also moved the code that was
dealing with handles that are not stored in the LoaderAllocator handle
tables out of the critical section, since there is no point in having it
inside of it.

Commit migrated from https://github.com/dotnet/coreclr/commit/7559844bbe9e4230217a9a9cf4be8a857531c8c8
13 files changed:
src/coreclr/src/vm/ceeload.cpp
src/coreclr/src/vm/generics.cpp
src/coreclr/src/vm/jithelpers.cpp
src/coreclr/src/vm/loaderallocator.cpp
src/coreclr/src/vm/loaderallocator.hpp
src/coreclr/src/vm/loaderallocator.inl
src/coreclr/src/vm/methodtable.cpp
src/coreclr/src/vm/methodtablebuilder.cpp
src/coreclr/src/vm/threads.cpp
src/coreclr/src/vm/threads.h
src/coreclr/src/vm/threadstatics.cpp
src/coreclr/src/vm/threadstatics.h
src/coreclr/src/vm/typedesc.cpp