Expose GC_setStackBottom (#7885)
This commit is contained in:
parent
4a88c245d3
commit
395b7506cf
5 changed files with 17 additions and 13 deletions
|
|
@ -1523,7 +1523,6 @@ const hasAlloc = (hostOS != "standalone" or not defined(nogc)) and not defined(n
|
||||||
when not defined(JS) and not defined(nimscript) and hostOS != "standalone":
|
when not defined(JS) and not defined(nimscript) and hostOS != "standalone":
|
||||||
include "system/cgprocs"
|
include "system/cgprocs"
|
||||||
when not defined(JS) and not defined(nimscript) and hasAlloc:
|
when not defined(JS) and not defined(nimscript) and hasAlloc:
|
||||||
proc setStackBottom(theStackBottom: pointer) {.compilerRtl, noinline, benign.}
|
|
||||||
proc addChar(s: NimString, c: char): NimString {.compilerProc, benign.}
|
proc addChar(s: NimString, c: char): NimString {.compilerProc, benign.}
|
||||||
|
|
||||||
proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}
|
proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}
|
||||||
|
|
@ -2639,6 +2638,11 @@ when not defined(nimscript) and hasAlloc:
|
||||||
proc GC_unref*(x: string) {.magic: "GCunref", benign.}
|
proc GC_unref*(x: string) {.magic: "GCunref", benign.}
|
||||||
## see the documentation of `GC_ref`.
|
## see the documentation of `GC_ref`.
|
||||||
|
|
||||||
|
when not defined(JS) and not defined(nimscript) and hasAlloc:
|
||||||
|
proc nimGC_setStackBottom*(theStackBottom: pointer) {.compilerRtl, noinline, benign.}
|
||||||
|
## Expands operating GC stack range to `theStackBottom`. Does nothing
|
||||||
|
## if current stack bottom is already lower than `theStackBottom`.
|
||||||
|
|
||||||
else:
|
else:
|
||||||
template GC_disable* =
|
template GC_disable* =
|
||||||
{.warning: "GC_disable is a no-op in JavaScript".}
|
{.warning: "GC_disable is a no-op in JavaScript".}
|
||||||
|
|
@ -2898,16 +2902,16 @@ when not defined(JS): #and not defined(nimscript):
|
||||||
# WARNING: This is very fragile! An array size of 8 does not work on my
|
# WARNING: This is very fragile! An array size of 8 does not work on my
|
||||||
# Linux 64bit system. -- That's because the stack direction is the other
|
# Linux 64bit system. -- That's because the stack direction is the other
|
||||||
# way round.
|
# way round.
|
||||||
when declared(setStackBottom):
|
when declared(nimGC_setStackBottom):
|
||||||
var locals {.volatile.}: pointer
|
var locals {.volatile.}: pointer
|
||||||
locals = addr(locals)
|
locals = addr(locals)
|
||||||
setStackBottom(locals)
|
nimGC_setStackBottom(locals)
|
||||||
|
|
||||||
proc initStackBottomWith(locals: pointer) {.inline, compilerproc.} =
|
proc initStackBottomWith(locals: pointer) {.inline, compilerproc.} =
|
||||||
# We need to keep initStackBottom around for now to avoid
|
# We need to keep initStackBottom around for now to avoid
|
||||||
# bootstrapping problems.
|
# bootstrapping problems.
|
||||||
when declared(setStackBottom):
|
when declared(nimGC_setStackBottom):
|
||||||
setStackBottom(locals)
|
nimGC_setStackBottom(locals)
|
||||||
|
|
||||||
{.push profiler: off.}
|
{.push profiler: off.}
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ when declared(threadType):
|
||||||
if threadType == ThreadType.None:
|
if threadType == ThreadType.None:
|
||||||
initAllocator()
|
initAllocator()
|
||||||
var stackTop {.volatile.}: pointer
|
var stackTop {.volatile.}: pointer
|
||||||
setStackBottom(addr(stackTop))
|
nimGC_setStackBottom(addr(stackTop))
|
||||||
initGC()
|
initGC()
|
||||||
threadType = ThreadType.ForeignThread
|
threadType = ThreadType.ForeignThread
|
||||||
|
|
||||||
|
|
@ -257,7 +257,7 @@ when nimCoroutines:
|
||||||
gch.activeStack.setPosition(addr(sp))
|
gch.activeStack.setPosition(addr(sp))
|
||||||
|
|
||||||
when not defined(useNimRtl):
|
when not defined(useNimRtl):
|
||||||
proc setStackBottom(theStackBottom: pointer) =
|
proc nimGC_setStackBottom(theStackBottom: pointer) =
|
||||||
# Initializes main stack of the thread.
|
# Initializes main stack of the thread.
|
||||||
when nimCoroutines:
|
when nimCoroutines:
|
||||||
if gch.stack.next == nil:
|
if gch.stack.next == nil:
|
||||||
|
|
|
||||||
|
|
@ -401,7 +401,7 @@ proc getFreeMem*(r: MemRegion): int = r.remaining
|
||||||
proc getTotalMem*(r: MemRegion): int =
|
proc getTotalMem*(r: MemRegion): int =
|
||||||
result = r.totalSize
|
result = r.totalSize
|
||||||
|
|
||||||
proc setStackBottom(theStackBottom: pointer) = discard
|
proc nimGC_setStackBottom(theStackBottom: pointer) = discard
|
||||||
|
|
||||||
proc nimGCref(x: pointer) {.compilerProc.} = discard
|
proc nimGCref(x: pointer) {.compilerProc.} = discard
|
||||||
proc nimGCunref(x: pointer) {.compilerProc.} = discard
|
proc nimGCunref(x: pointer) {.compilerProc.} = discard
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ when defined(boehmgc):
|
||||||
proc getFreeMem(): int = return boehmGetFreeBytes()
|
proc getFreeMem(): int = return boehmGetFreeBytes()
|
||||||
proc getTotalMem(): int = return boehmGetHeapSize()
|
proc getTotalMem(): int = return boehmGetHeapSize()
|
||||||
|
|
||||||
proc setStackBottom(theStackBottom: pointer) = discard
|
proc nimGC_setStackBottom(theStackBottom: pointer) = discard
|
||||||
|
|
||||||
proc initGC() =
|
proc initGC() =
|
||||||
boehmGCinit()
|
boehmGCinit()
|
||||||
|
|
@ -305,7 +305,7 @@ elif defined(gogc):
|
||||||
goRuntime_ReadMemStats(addr mstats)
|
goRuntime_ReadMemStats(addr mstats)
|
||||||
result = int(mstats.sys)
|
result = int(mstats.sys)
|
||||||
|
|
||||||
proc setStackBottom(theStackBottom: pointer) = discard
|
proc nimGC_setStackBottom(theStackBottom: pointer) = discard
|
||||||
|
|
||||||
proc alloc(size: Natural): pointer =
|
proc alloc(size: Natural): pointer =
|
||||||
result = c_malloc(size)
|
result = c_malloc(size)
|
||||||
|
|
@ -449,7 +449,7 @@ elif defined(nogc) and defined(useMalloc):
|
||||||
proc getFreeMem(): int = discard
|
proc getFreeMem(): int = discard
|
||||||
proc getTotalMem(): int = discard
|
proc getTotalMem(): int = discard
|
||||||
|
|
||||||
proc setStackBottom(theStackBottom: pointer) = discard
|
proc nimGC_setStackBottom(theStackBottom: pointer) = discard
|
||||||
|
|
||||||
proc initGC() = discard
|
proc initGC() = discard
|
||||||
|
|
||||||
|
|
@ -523,7 +523,7 @@ elif defined(nogc):
|
||||||
proc growObj(old: pointer, newsize: int): pointer =
|
proc growObj(old: pointer, newsize: int): pointer =
|
||||||
result = realloc(old, newsize)
|
result = realloc(old, newsize)
|
||||||
|
|
||||||
proc setStackBottom(theStackBottom: pointer) = discard
|
proc nimGC_setStackBottom(theStackBottom: pointer) = discard
|
||||||
proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
|
proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
|
||||||
proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
|
proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -440,7 +440,7 @@ proc threadProcWrapStackFrame[TArg](thrd: ptr Thread[TArg]) =
|
||||||
threadProcWrapDispatch[TArg]
|
threadProcWrapDispatch[TArg]
|
||||||
when not hasSharedHeap:
|
when not hasSharedHeap:
|
||||||
# init the GC for refc/markandsweep
|
# init the GC for refc/markandsweep
|
||||||
setStackBottom(addr(p))
|
nimGC_setStackBottom(addr(p))
|
||||||
initGC()
|
initGC()
|
||||||
when declared(threadType):
|
when declared(threadType):
|
||||||
threadType = ThreadType.NimThread
|
threadType = ThreadType.NimThread
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue