C code gen: generate even better code for the GC
This commit is contained in:
parent
4487b614e1
commit
e8376067ef
4 changed files with 41 additions and 15 deletions
|
|
@ -230,7 +230,8 @@ proc decRef(c: PCell) {.inline.} =
|
|||
if --c.refcount:
|
||||
rtlAddZCT(c)
|
||||
elif canBeCycleRoot(c):
|
||||
# XXX if 'incRef' does this check, it should be unnecessary in 'decRef'
|
||||
# unfortunately this is necessary here too, because a cycle might just
|
||||
# have been broken up and we could recycle it.
|
||||
rtlAddCycleRoot(c)
|
||||
|
||||
proc incRef(c: PCell) {.inline.} =
|
||||
|
|
@ -241,6 +242,11 @@ proc incRef(c: PCell) {.inline.} =
|
|||
proc nimGCref(p: pointer) {.compilerProc, inline.} = incRef(usrToCell(p))
|
||||
proc nimGCunref(p: pointer) {.compilerProc, inline.} = decRef(usrToCell(p))
|
||||
|
||||
proc nimGCunrefNoCycle(p: pointer) {.compilerProc, inline.} =
|
||||
var c = usrToCell(p)
|
||||
if --c.refcount:
|
||||
rtlAddZCT(c)
|
||||
|
||||
proc asgnRef(dest: ppointer, src: pointer) {.compilerProc, inline.} =
|
||||
# the code generator calls this proc!
|
||||
sysAssert(not isOnStack(dest), "asgnRef")
|
||||
|
|
@ -252,7 +258,7 @@ proc asgnRef(dest: ppointer, src: pointer) {.compilerProc, inline.} =
|
|||
proc asgnRefNoCycle(dest: ppointer, src: pointer) {.compilerProc, inline.} =
|
||||
# the code generator calls this proc if it is known at compile time that no
|
||||
# cycle is possible.
|
||||
if src != nil:
|
||||
if src != nil:
|
||||
var c = usrToCell(src)
|
||||
++c.refcount
|
||||
if dest[] != nil:
|
||||
|
|
@ -761,7 +767,7 @@ proc collectCT(gch: var TGcHeap) =
|
|||
inc(gch.stat.stackScans)
|
||||
collectZCT(gch)
|
||||
when cycleGC:
|
||||
if getOccupiedMem() >= gch.cycleThreshold or stressGC:
|
||||
if getOccupiedMem(gch.region) >= gch.cycleThreshold or stressGC:
|
||||
collectCycles(gch)
|
||||
collectZCT(gch)
|
||||
inc(gch.stat.cycleCollections)
|
||||
|
|
|
|||
|
|
@ -72,6 +72,20 @@ proc copyString(src: NimString): NimString {.compilerProc.} =
|
|||
result.len = src.len
|
||||
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(Char))
|
||||
|
||||
proc copyStringRC1(src: NimString): NimString {.compilerProc.} =
|
||||
if src != nil:
|
||||
var s = src.space
|
||||
if s < 8: s = 7
|
||||
when defined(newObjRC1):
|
||||
result = cast[NimString](newObjRC1(addr(strDesc), sizeof(TGenericSeq) +
|
||||
(s+1) * sizeof(char)))
|
||||
else:
|
||||
result = cast[NimString](newObj(addr(strDesc), sizeof(TGenericSeq) +
|
||||
(s+1) * sizeof(char)))
|
||||
result.space = s
|
||||
result.len = src.len
|
||||
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(Char))
|
||||
|
||||
proc hashString(s: string): int {.compilerproc.} =
|
||||
# the compiler needs exactly the same hash function!
|
||||
# this used to be used for efficient generation of string case statements
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue