Pass CompAllocator by value (dotnet/coreclr#15025)
authormikedn <onemihaid@hotmail.com>
Sat, 30 Jun 2018 17:05:30 +0000 (20:05 +0300)
committerAndy Ayers <andya@microsoft.com>
Sat, 30 Jun 2018 17:05:30 +0000 (10:05 -0700)
commit7353f0411074954fc399fbe0f40dcfce6fff829d
treec0d90f7abe0cd676d97e7af83cff14f4c9a24127
parent1198f955539d6bf525d6b91ff9e73fd21ba221b3
Pass CompAllocator by value (dotnet/coreclr#15025)

Passing CompAllocator objects by value is advantageous because it no longer needs to be dynamically allocated and cached. CompAllocator instances can now be freely created, copied and stored, which makes adding new CompMemKind values easier.

Together with other cleanup this also improves memory allocation performance by removing some extra levels of indirection that were previously required - jitstd::allocator had a pointer to CompAllocator, CompAllocator had a pointer to Compiler and Compiler finally had a pointer to ArenaAllocator. Without MEASURE_MEM_ALLOC enabled, both jitstd::allocator and CompAllocator now just contain a pointer to ArenaAllocator. When MEASURE_MEM_ALLOC is enabled CompAllocator also contains a pointer but to a MemStatsAllocator object that holds the relevant memory kind. This way CompAllocator is always pointer sized so that enabling MEASURE_MEM_ALLOC does not result in increased memory usage due to objects that store a CompAllocator instance.

In order to implement this, 2 additional signficant changes have been made:
* MemStats has been moved to ArenaAllocator, it's after all the allocator's job to maintain statistics. This also fixes some issues related to memory statistics, such as not tracking the memory allocated by the inlinee compiler (since that one used its own MemStats instance).
* Extract the arena page pooling logic out of the allocator. It doesn't make sense to pool an allocator, it has very little state that can actually be reused and everyting else (including MemStats) needs to be reset on reuse. What really needs to be pooled is just a page of memory.

Since this was touching allocation code the opportunity has been used to perform additional cleanup:
* Remove unnecessary LSRA ListElementAllocator
* Remove compGetMem and compGetMemArray
* Make CompAllocator and HostAllocator more like the std allocator
* Update HashTable to use CompAllocator
* Update ArrayStack to use CompAllocator
* Move CompAllocator & friends to alloc.h

Commit migrated from https://github.com/dotnet/coreclr/commit/c2baf04cd2c2211334949ba12df2e49fd9109728
51 files changed:
docs/coreclr/coding-guidelines/clr-jit-coding-conventions.md
src/coreclr/src/jit/alloc.cpp
src/coreclr/src/jit/alloc.h
src/coreclr/src/jit/arraystack.h
src/coreclr/src/jit/bitset.cpp
src/coreclr/src/jit/bitset.h
src/coreclr/src/jit/block.cpp
src/coreclr/src/jit/codegencommon.cpp
src/coreclr/src/jit/compiler.cpp
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/compiler.hpp
src/coreclr/src/jit/compilerbitsettraits.hpp
src/coreclr/src/jit/copyprop.cpp
src/coreclr/src/jit/ee_il_dll.cpp
src/coreclr/src/jit/eeinterface.cpp
src/coreclr/src/jit/emit.cpp
src/coreclr/src/jit/flowgraph.cpp
src/coreclr/src/jit/gcencode.cpp
src/coreclr/src/jit/gentree.cpp
src/coreclr/src/jit/gentree.h
src/coreclr/src/jit/hostallocator.cpp
src/coreclr/src/jit/hostallocator.h
src/coreclr/src/jit/importer.cpp
src/coreclr/src/jit/jit.h
src/coreclr/src/jit/jitexpandarray.h
src/coreclr/src/jit/jithashtable.h
src/coreclr/src/jit/jitstd/allocator.h
src/coreclr/src/jit/jitstd/utility.h
src/coreclr/src/jit/lclvars.cpp
src/coreclr/src/jit/lir.cpp
src/coreclr/src/jit/loopcloning.cpp
src/coreclr/src/jit/loopcloning.h
src/coreclr/src/jit/lower.cpp
src/coreclr/src/jit/lsra.cpp
src/coreclr/src/jit/lsra.h
src/coreclr/src/jit/lsrabuild.cpp
src/coreclr/src/jit/morph.cpp
src/coreclr/src/jit/rangecheck.cpp
src/coreclr/src/jit/rangecheck.h
src/coreclr/src/jit/regset.cpp
src/coreclr/src/jit/scopeinfo.cpp
src/coreclr/src/jit/smallhash.h
src/coreclr/src/jit/ssabuilder.cpp
src/coreclr/src/jit/ssarenamestate.cpp
src/coreclr/src/jit/ssarenamestate.h
src/coreclr/src/jit/stacklevelsetter.cpp
src/coreclr/src/jit/unwind.cpp
src/coreclr/src/jit/utils.cpp
src/coreclr/src/jit/utils.h
src/coreclr/src/jit/valuenum.cpp
src/coreclr/src/jit/valuenum.h