Skip to content

Commit

Permalink
*allocShared implementations for boehm and go allocators now depend o…
Browse files Browse the repository at this point in the history
…n the proper *allocImpl procs
  • Loading branch information
Ico Doornekamp committed Jan 21, 2020
1 parent 00742d2 commit 693f87e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 33 deletions.
10 changes: 5 additions & 5 deletions lib/system/alloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1050,10 +1050,10 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
result = alloc(sharedHeap, size)
releaseSys(heapLock)
else:
result = alloc(size)
result = allocImpl(size)

proc allocShared0Impl(size: Natural): pointer =
result = allocShared(size)
result = allocSharedImpl(size)
zeroMem(result, size)

proc deallocSharedImpl(p: pointer) =
Expand All @@ -1062,23 +1062,23 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
dealloc(sharedHeap, p)
releaseSys(heapLock)
else:
dealloc(p)
deallocImpl(p)

proc reallocSharedImpl(p: pointer, newSize: Natural): pointer =
when hasThreadSupport:
acquireSys(heapLock)
result = realloc(sharedHeap, p, newSize)
releaseSys(heapLock)
else:
result = realloc(p, newSize)
result = reallocImpl(p, newSize)

proc reallocShared0Impl(p: pointer, oldSize, newSize: Natural): pointer =
when hasThreadSupport:
acquireSys(heapLock)
result = realloc0(sharedHeap, p, oldSize, newSize)
releaseSys(heapLock)
else:
result = realloc0(p, oldSize, newSize)
result = realloc0Impl(p, oldSize, newSize)

when hasThreadSupport:
template sharedMemStatsShared(v: int) =
Expand Down
28 changes: 10 additions & 18 deletions lib/system/mmdisp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ when defined(boehmgc):
zeroMem(cast[pointer](cast[int](result) + oldsize), newsize - oldsize)
proc deallocImpl(p: pointer) = boehmDealloc(p)

proc allocSharedImpl(size: Natural): pointer = alloc(size)
proc allocShared0Impl(size: Natural): pointer = alloc(size)
proc reallocSharedImpl(p: pointer, newSize: Natural): pointer = realloc(p, newSize)
proc reallocShared0Impl(p: pointer, oldSize, newSize: Natural): pointer = realloc0Impl(p, newSize, oldSize)
proc deallocSharedImpl(p: pointer) = dealloc(p)
proc allocSharedImpl(size: Natural): pointer = allocImpl(size)
proc allocShared0Impl(size: Natural): pointer = alloc0Impl(size)
proc reallocSharedImpl(p: pointer, newsize: Natural): pointer = reallocImpl(p, newsize)
proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer = realloc0Impl(p, oldsize, newsize)
proc deallocSharedImpl(p: pointer) = deallocImpl(p)

when hasThreadSupport:
proc getFreeSharedMem(): int =
Expand Down Expand Up @@ -281,19 +281,11 @@ elif defined(gogc):
proc deallocImpl(p: pointer) =
discard

proc allocSharedImpl(size: Natural): pointer =
result = alloc(size)

proc allocShared0Impl(size: Natural): pointer =
result = alloc0(size)

proc reallocSharedImpl(p: pointer, newsize: Natural): pointer =
result = realloc(p, newsize)

proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer =
result = realloc0(p, oldsize, newsize)

proc deallocSharedImpl(p: pointer) = dealloc(p)
proc allocSharedImpl(size: Natural): pointer = allocImpl(size)
proc allocShared0Impl(size: Natural): pointer = alloc0Impl(size)
proc reallocSharedImpl(p: pointer, newsize: Natural): pointer = reallocImpl(p, newsize)
proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer = realloc0Impl(p, oldsize, newsize)
proc deallocSharedImpl(p: pointer) = deallocImpl(p)

when hasThreadSupport:
proc getFreeSharedMem(): int = discard
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/tbintree2.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
discard """
cmd: '''nim c -d:allocStats --newruntime $file'''
output: '''0
(allocCount: 12, deallocCount: 9)'''
(allocCount: 6, deallocCount: 6)'''
"""

import system / ansi_c
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/tgcdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ a: @[4, 2, 3]
0
30
true
(allocCount: 123, deallocCount: 82)'''
(allocCount: 41, deallocCount: 41)'''
"""

include system / ansi_c
Expand Down
10 changes: 6 additions & 4 deletions tests/destructor/tnewruntime_misc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ axc
...
destroying GenericObj[T] GenericObj[system.int]
test
(allocCount: 34, deallocCount: 15)'''
(allocCount: 7, deallocCount: 5)'''
"""

import system / ansi_c
Expand All @@ -22,8 +22,6 @@ type
import os
putEnv("HEAPTRASHING", "Indeed")

let s1 = getAllocStats()

proc main =
var w = newTable[string, owned Node]()
w["key"] = Node(field: "value")
Expand All @@ -37,6 +35,8 @@ proc main =

main()

let s1 = getAllocStats()

# bug #11745

type
Expand Down Expand Up @@ -131,4 +131,6 @@ proc xx(xml: string): MyObject =


discard xx("test")
echo getAllocStats() - s1

let s2 = getAllocStats()
echo $(s2-s1)
2 changes: 1 addition & 1 deletion tests/destructor/tsimpleclosure.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ discard """
hello
hello
hello
(allocCount: 8, deallocCount: 6)'''
(allocCount: 4, deallocCount: 4)'''
"""

import system / ansi_c
Expand Down
3 changes: 2 additions & 1 deletion tests/destructor/tv2_raise.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
discard """
valgrind: true
cmd: '''nim c -d:allocStats --newruntime $file'''
output: '''OK 3
(allocCount: 18, deallocCount: 5)'''
(allocCount: 8, deallocCount: 3)'''
"""

import strutils, math
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/twidgets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
cmd: '''nim c -d:allocstats --newruntime $file'''
output: '''button
clicked!
(allocCount: 6, deallocCount: 5)'''
(allocCount: 4, deallocCount: 4)'''
"""

import system / ansi_c
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/twidgets_unown.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
cmd: '''nim c -d:allocStats --newruntime $file'''
output: '''button
clicked!
(allocCount: 21, deallocCount: 15)'''
(allocCount: 9, deallocCount: 9)'''
"""

import system / ansi_c
Expand Down

0 comments on commit 693f87e

Please sign in to comment.