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:
parent
f500895efe
commit
b68eb1cad0
21 changed files with 275 additions and 312 deletions
|
|
@ -1,10 +1,9 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
||||
output: '''0
|
||||
3 3 alloc/dealloc pairs: 0'''
|
||||
(allocCount: 6, deallocCount: 6)'''
|
||||
"""
|
||||
|
||||
import system / allocators
|
||||
import system / ansi_c
|
||||
|
||||
import random
|
||||
|
|
@ -97,7 +96,6 @@ proc main() =
|
|||
discard
|
||||
echo res
|
||||
|
||||
main()
|
||||
dumpAllocStats:
|
||||
main()
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld alloc/dealloc pairs: %ld\n", a, d, system.allocs)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
||||
output: '''hi
|
||||
ho
|
||||
ha
|
||||
|
|
@ -10,10 +10,9 @@ a: @[4, 2, 3]
|
|||
0
|
||||
30
|
||||
true
|
||||
41 41'''
|
||||
(allocCount: 41, deallocCount: 41)'''
|
||||
"""
|
||||
|
||||
import system / allocators
|
||||
include system / ansi_c
|
||||
|
||||
proc main =
|
||||
|
|
@ -201,7 +200,4 @@ proc takeAinArray =
|
|||
takeAinArray()
|
||||
echo ga == "foo"
|
||||
|
||||
|
||||
#echo s
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld\n", a, d)
|
||||
echo getAllocStats()
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
discard """
|
||||
cmd: '''nim cpp --newruntime --threads:on $file'''
|
||||
cmd: '''nim cpp -d:allocStats --newruntime --threads:on $file'''
|
||||
output: '''(field: "value")
|
||||
Indeed
|
||||
axc
|
||||
(v: 10)
|
||||
0 new: 0
|
||||
...
|
||||
destroying GenericObj[T] GenericObj[system.int]
|
||||
test
|
||||
'''
|
||||
(allocCount: 17, deallocCount: 15)'''
|
||||
"""
|
||||
|
||||
import system / allocators
|
||||
import system / ansi_c
|
||||
|
||||
import tables
|
||||
|
|
@ -24,6 +22,8 @@ type
|
|||
import os
|
||||
putEnv("HEAPTRASHING", "Indeed")
|
||||
|
||||
let s1 = getAllocStats()
|
||||
|
||||
proc main =
|
||||
var w = newTable[string, owned Node]()
|
||||
w["key"] = Node(field: "value")
|
||||
|
|
@ -87,9 +87,6 @@ proc testWrongAt() =
|
|||
|
||||
testWrongAt()
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld new: %ld\n", a - unpairedEnvAllocs() - d, allocs)
|
||||
|
||||
#-------------------------------------------------
|
||||
type
|
||||
Table[A, B] = object
|
||||
|
|
@ -134,3 +131,4 @@ proc xx(xml: string): MyObject =
|
|||
|
||||
|
||||
discard xx("test")
|
||||
echo getAllocStats() - s1
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
discard """
|
||||
valgrind: true
|
||||
cmd: '''nim c --newruntime -d:useMalloc $file'''
|
||||
cmd: '''nim c -d:allocStats --newruntime -d:useMalloc $file'''
|
||||
output: '''
|
||||
@[(input: @["KXSC", "BGMC"]), (input: @["PXFX"]), (input: @["WXRQ", "ZSCZD"])]
|
||||
461 461'''
|
||||
@[(input: @["KXSC", "BGMC"]), (input: @["PXFX"]), (input: @["WXRQ", "ZSCZD"])]'''
|
||||
"""
|
||||
|
||||
import strutils, os, std / wordwrap
|
||||
|
||||
import system / allocators
|
||||
import system / ansi_c
|
||||
|
||||
# bug #11004
|
||||
|
|
@ -213,6 +211,3 @@ staticTests()
|
|||
# bug #12965
|
||||
let xaa = @[""].join()
|
||||
let xbb = @["", ""].join()
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld\n", a, d)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
||||
output: '''a b
|
||||
70
|
||||
hello
|
||||
hello
|
||||
hello
|
||||
2 2 alloc/dealloc pairs: 0'''
|
||||
(allocCount: 4, deallocCount: 4)'''
|
||||
"""
|
||||
|
||||
import system / allocators
|
||||
import system / ansi_c
|
||||
|
||||
proc main(): owned(proc()) =
|
||||
|
|
@ -60,5 +59,4 @@ when false:
|
|||
|
||||
stringIter()
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld alloc/dealloc pairs: %ld\n", a, d, system.allocs)
|
||||
echo getAllocStats()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
errormsg: "'=' is not available for type <owned Button>; requires a copy because it's not the last read of ':envAlt.b1'; another read is done here: tuse_ownedref_after_move.nim(53, 4)"
|
||||
line: 49
|
||||
errormsg: "'=' is not available for type <owned Button>; requires a copy because it's not the last read of ':envAlt.b1'; another read is done here: tuse_ownedref_after_move.nim(52, 4)"
|
||||
line: 48
|
||||
"""
|
||||
|
||||
import system / allocators
|
||||
import system / ansi_c
|
||||
|
||||
type
|
||||
|
|
@ -56,5 +55,3 @@ proc main =
|
|||
|
||||
main()
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld new: %ld\n", a, d, allocs)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
valgrind: true
|
||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
||||
output: '''OK 3
|
||||
5 2'''
|
||||
(allocCount: 8, deallocCount: 3)'''
|
||||
"""
|
||||
|
||||
import strutils, math
|
||||
import system / ansi_c
|
||||
import system / allocators
|
||||
|
||||
proc mainA =
|
||||
try:
|
||||
|
|
@ -50,6 +50,4 @@ except:
|
|||
inc ok
|
||||
|
||||
echo "OK ", ok
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld\n", a, d)
|
||||
echo getAllocStats()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
cmd: '''nim c -d:allocstats --newruntime $file'''
|
||||
output: '''button
|
||||
clicked!
|
||||
1 1 alloc/dealloc pairs: 0'''
|
||||
(allocCount: 4, deallocCount: 4)'''
|
||||
"""
|
||||
|
||||
import system / allocators
|
||||
import system / ansi_c
|
||||
|
||||
type
|
||||
|
|
@ -72,7 +71,6 @@ proc main =
|
|||
|
||||
w.draw()
|
||||
|
||||
main()
|
||||
dumpAllocstats:
|
||||
main()
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld alloc/dealloc pairs: %ld\n", a, d, allocs)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
||||
output: '''button
|
||||
clicked!
|
||||
6 6 alloc/dealloc pairs: 0'''
|
||||
(allocCount: 9, deallocCount: 9)'''
|
||||
"""
|
||||
|
||||
import system / allocators
|
||||
import system / ansi_c
|
||||
|
||||
type
|
||||
|
|
@ -69,7 +68,5 @@ proc main =
|
|||
if a != nil:
|
||||
a()
|
||||
|
||||
main()
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld alloc/dealloc pairs: %ld\n", a, d, allocs)
|
||||
dumpAllocStats:
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue