make the GCs more robust

This commit is contained in:
Andreas Rumpf 2017-07-20 18:42:00 +02:00
commit 6f89323385
2 changed files with 16 additions and 16 deletions

View file

@ -754,8 +754,8 @@ proc gcMark(gch: var GcHeap, p: pointer) {.inline.} =
#[ #[
This method is conditionally marked with an attribute so that it gets ignored by the LLVM ASAN This method is conditionally marked with an attribute so that it gets ignored by the LLVM ASAN
(Address SANitizer) intrumentation as it will raise false errors due to the implementation of (Address SANitizer) intrumentation as it will raise false errors due to the implementation of
garbage collection that is used by Nim. For more information, please see the documentation of garbage collection that is used by Nim. For more information, please see the documentation of
`CLANG_NO_SANITIZE_ADDRESS` in `lib/nimbase.h`. `CLANG_NO_SANITIZE_ADDRESS` in `lib/nimbase.h`.
]# ]#
proc markStackAndRegisters(gch: var GcHeap) {.noinline, cdecl, codegenDecl: "CLANG_NO_SANITIZE_ADDRESS $# $#$#".} = proc markStackAndRegisters(gch: var GcHeap) {.noinline, cdecl, codegenDecl: "CLANG_NO_SANITIZE_ADDRESS $# $#$#".} =
@ -920,11 +920,13 @@ when not defined(useNimRtl):
else: else:
inc(gch.recGcLock) inc(gch.recGcLock)
proc GC_enable() = proc GC_enable() =
if gch.recGcLock > 0: if gch.recGcLock <= 0:
when hasThreadSupport and hasSharedHeap: raise newException(AssertionError,
discard atomicDec(gch.recGcLock, 1) "API usage error: GC_enable called but GC is already enabled")
else: when hasThreadSupport and hasSharedHeap:
dec(gch.recGcLock) discard atomicDec(gch.recGcLock, 1)
else:
dec(gch.recGcLock)
proc GC_setStrategy(strategy: GC_Strategy) = proc GC_setStrategy(strategy: GC_Strategy) =
discard discard
@ -945,7 +947,6 @@ when not defined(useNimRtl):
release(gch) release(gch)
proc GC_getStatistics(): string = proc GC_getStatistics(): string =
GC_disable()
result = "[GC] total memory: " & $(getTotalMem()) & "\n" & result = "[GC] total memory: " & $(getTotalMem()) & "\n" &
"[GC] occupied memory: " & $(getOccupiedMem()) & "\n" & "[GC] occupied memory: " & $(getOccupiedMem()) & "\n" &
"[GC] stack scans: " & $gch.stat.stackScans & "\n" & "[GC] stack scans: " & $gch.stat.stackScans & "\n" &
@ -961,6 +962,5 @@ when not defined(useNimRtl):
result = result & "[GC] stack " & stack.bottom.repr & "[GC] max stack size " & cast[pointer](stack.maxStackSize).repr & "\n" result = result & "[GC] stack " & stack.bottom.repr & "[GC] max stack size " & cast[pointer](stack.maxStackSize).repr & "\n"
else: else:
result = result & "[GC] max stack size: " & $gch.stat.maxStackSize & "\n" result = result & "[GC] max stack size: " & $gch.stat.maxStackSize & "\n"
GC_enable()
{.pop.} # profiler: off, stackTrace: off {.pop.} # profiler: off, stackTrace: off

View file

@ -506,11 +506,13 @@ when not defined(useNimRtl):
else: else:
inc(gch.recGcLock) inc(gch.recGcLock)
proc GC_enable() = proc GC_enable() =
if gch.recGcLock > 0: if gch.recGcLock <= 0:
when hasThreadSupport and hasSharedHeap: raise newException(AssertionError,
atomicDec(gch.recGcLock, 1) "API usage error: GC_enable called but GC is already enabled")
else: when hasThreadSupport and hasSharedHeap:
dec(gch.recGcLock) atomicDec(gch.recGcLock, 1)
else:
dec(gch.recGcLock)
proc GC_setStrategy(strategy: GC_Strategy) = discard proc GC_setStrategy(strategy: GC_Strategy) = discard
@ -530,7 +532,6 @@ when not defined(useNimRtl):
release(gch) release(gch)
proc GC_getStatistics(): string = proc GC_getStatistics(): string =
GC_disable()
result = "[GC] total memory: " & $getTotalMem() & "\n" & result = "[GC] total memory: " & $getTotalMem() & "\n" &
"[GC] occupied memory: " & $getOccupiedMem() & "\n" & "[GC] occupied memory: " & $getOccupiedMem() & "\n" &
"[GC] collections: " & $gch.stat.collections & "\n" & "[GC] collections: " & $gch.stat.collections & "\n" &
@ -542,6 +543,5 @@ when not defined(useNimRtl):
result = result & "[GC] stack " & stack.bottom.repr & "[GC] max stack size " & $stack.maxStackSize & "\n" result = result & "[GC] stack " & stack.bottom.repr & "[GC] max stack size " & $stack.maxStackSize & "\n"
else: else:
result = result & "[GC] max stack size: " & $gch.stat.maxStackSize & "\n" result = result & "[GC] max stack size: " & $gch.stat.maxStackSize & "\n"
GC_enable()
{.pop.} {.pop.}