Removed lib/system/allocators.nim. seqs_v2 and strs_v2 now uses allocShared0. (#13190)

* Cleanup, remove lib/system/allocators.nim. seqs_v2 and strs_v2 now use
allocShared0 by default.

* Fixed -d:useMalloc allocShared / reallocShared / deallocShared. These now use the alloc/dealloc/realloc implementation that also takes care of zeroing memory at realloc.

* Removed debug printfs

* Removed unpairedEnvAllocs() from tests/destructor/tnewruntime_misc

* More mmdisp cleanups. The shared allocators do not need to zero memory or throw since the regular ones already do that

* Introduced realloc0 and reallocShared0, these procs are now used by
strs_v2 and seqs_v2. This also allowed the -d:useMalloc allocator to
drop the extra header with allocation length.

* Moved strs_v2/seqs_v2 'allocated' flag into 'cap' field

* Added 'getAllocStats()' to get low level alloc/dealloc counters. Enable with -d:allocStats

* *allocShared implementations for boehm and go allocators now depend on the proper *allocImpl procs
This commit is contained in:
Ico Doornekamp 2020-01-23 14:25:22 +01:00 • committed by Andreas Rumpf
commit b68eb1cad0
21 changed files with 275 additions and 312 deletions

View file

@ -377,16 +377,21 @@ proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
proc asgnRefNoCycle(dest: PPointer, src: pointer) {.compilerproc, inline,
deprecated: "old compiler compat".} = asgnRef(dest, src)
proc alloc(size: Natural): pointer =
proc allocImpl(size: Natural): pointer =
result = c_malloc(cast[csize_t](size))
if result == nil: raiseOutOfMem()
proc alloc0(size: Natural): pointer =
proc alloc0Impl(size: Natural): pointer =
result = alloc(size)
zeroMem(result, size)
proc realloc(p: pointer, newsize: Natural): pointer =
proc reallocImpl(p: pointer, newsize: Natural): pointer =
result = c_realloc(p, cast[csize_t](newsize))
if result == nil: raiseOutOfMem()
proc dealloc(p: pointer) = c_free(p)
proc realloc0Impl(p: pointer, oldsize, newsize: Natural): pointer =
result = c_realloc(p, cast[csize_t](newsize))
if result == nil: raiseOutOfMem()
if newsize > oldsize:
zeroMem(cast[pointer](cast[int](result) + oldsize), newsize - oldsize)
proc deallocImpl(p: pointer) = c_free(p)
proc alloc0(r: var MemRegion; size: Natural): pointer =
# ignore the region. That is correct for the channels module
@ -400,16 +405,21 @@ proc alloc(r: var MemRegion; size: Natural): pointer =
proc dealloc(r: var MemRegion; p: pointer) = dealloc(p)
proc allocShared(size: Natural): pointer =
proc allocSharedImpl(size: Natural): pointer =
result = c_malloc(cast[csize_t](size))
if result == nil: raiseOutOfMem()
proc allocShared0(size: Natural): pointer =
proc allocShared0Impl(size: Natural): pointer =
result = alloc(size)
zeroMem(result, size)
proc reallocShared(p: pointer, newsize: Natural): pointer =
proc reallocSharedImpl(p: pointer, newsize: Natural): pointer =
result = c_realloc(p, cast[csize_t](newsize))
if result == nil: raiseOutOfMem()
proc deallocShared(p: pointer) = c_free(p)
proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer =
result = c_realloc(p, cast[csize_t](newsize))
if result == nil: raiseOutOfMem()
if newsize > oldsize:
zeroMem(cast[pointer](cast[int](result) + oldsize), newsize - oldsize)
proc deallocSharedImpl(p: pointer) = c_free(p)
when hasThreadSupport:
proc getFreeSharedMem(): int = 0