diff options
author | jcosborn <jcosborn@users.noreply.github.com> | 2018-03-17 17:59:04 -0500 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-03-17 23:59:04 +0100 |
commit | e39f2a9283fc63f529d74acb0d50b0035d513e79 (patch) | |
tree | 006dd2ceee3c1f28c356e34145174d16681bd3eb /tests/system | |
parent | d20729e840af9c504ba6ca3726bf0e4ca8f47a99 (diff) | |
download | Nim-e39f2a9283fc63f529d74acb0d50b0035d513e79.tar.gz |
fix allocator corruption for large sizes (#7338)
* fix allocator corruption for large sizes * allow large chunks to coalesce and added test case * use correct constants in MaxBigChunkSize
Diffstat (limited to 'tests/system')
-rw-r--r-- | tests/system/talloc.nim (renamed from tests/system/alloc.nim) | 15 | ||||
-rw-r--r-- | tests/system/talloc2.nim | 37 | ||||
-rw-r--r-- | tests/system/tio.nim (renamed from tests/system/io.nim) | 0 | ||||
-rw-r--r-- | tests/system/tparams.nim (renamed from tests/system/params.nim) | 0 |
4 files changed, 47 insertions, 5 deletions
diff --git a/tests/system/alloc.nim b/tests/system/talloc.nim index 7abefec2a..18396041d 100644 --- a/tests/system/alloc.nim +++ b/tests/system/talloc.nim @@ -8,7 +8,7 @@ x.dealloc() x = createU(int, 3) assert x != nil -x.free() +x.dealloc() x = create(int, 4) assert cast[ptr array[4, int]](x)[0] == 0 @@ -18,7 +18,7 @@ assert cast[ptr array[4, int]](x)[3] == 0 x = x.resize(4) assert x != nil -x.free() +x.dealloc() x = cast[ptr int](allocShared(100)) assert x != nil @@ -26,7 +26,7 @@ deallocShared(x) x = createSharedU(int, 3) assert x != nil -x.freeShared() +x.deallocShared() x = createShared(int, 3) assert x != nil @@ -37,7 +37,7 @@ assert cast[ptr array[3, int]](x)[2] == 0 assert x != nil x = cast[ptr int](x.resizeShared(2)) assert x != nil -x.freeShared() +x.deallocShared() x = create(int, 10) assert x != nil @@ -49,4 +49,9 @@ x = createShared(int, 1) assert x != nil x = x.resizeShared(1) assert x != nil -x.freeShared() +x.deallocShared() + +x = cast[ptr int](alloc0(125 shl 23)) +dealloc(x) +x = cast[ptr int](alloc0(126 shl 23)) +dealloc(x) diff --git a/tests/system/talloc2.nim b/tests/system/talloc2.nim new file mode 100644 index 000000000..c8cab78a1 --- /dev/null +++ b/tests/system/talloc2.nim @@ -0,0 +1,37 @@ +const + nmax = 2*1024*1024*1024 + +proc test(n: int) = + var a = alloc0(9999) + var t = cast[ptr UncheckedArray[int8]](alloc(n)) + var b = alloc0(9999) + t[0] = 1 + t[1] = 2 + t[n-2] = 3 + t[n-1] = 4 + dealloc(a) + dealloc(t) + dealloc(b) + +# allocator adds 48 bytes to BigChunk +# BigChunk allocator edges at 2^n * (1 - s) for s = [1..32]/64 +proc test2(n: int) = + let d = n div 256 # cover edges and more + for i in countdown(128,1): + for j in [-4096, -64, -49, -48, -47, -32, 0, 4096]: + let b = n + j - i*d + if b>0 and b<=nmax: + test(b) + #echo b, ": ", getTotalMem(), " ", getOccupiedMem(), " ", getFreeMem() + +proc test3 = + var n = 1 + while n <= nmax: + test2(n) + n *= 2 + n = nmax + while n >= 1: + test2(n) + n = n div 2 + +test3() diff --git a/tests/system/io.nim b/tests/system/tio.nim index 3d4df806b..3d4df806b 100644 --- a/tests/system/io.nim +++ b/tests/system/tio.nim diff --git a/tests/system/params.nim b/tests/system/tparams.nim index 1358212f2..1358212f2 100644 --- a/tests/system/params.nim +++ b/tests/system/tparams.nim |