gc:destructors progress
This commit is contained in:
parent
77c6425e65
commit
62aa1a3cfe
6 changed files with 72 additions and 8 deletions
|
|
@ -751,6 +751,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
message(tracked.config, arg.info, warnProveInit, $arg)
|
message(tracked.config, arg.info, warnProveInit, $arg)
|
||||||
|
createTypeBoundOps(tracked.graph, tracked.c, n[1].typ.lastSon, n.info)
|
||||||
for i in 0 ..< safeLen(n):
|
for i in 0 ..< safeLen(n):
|
||||||
track(tracked, n.sons[i])
|
track(tracked, n.sons[i])
|
||||||
of nkDotExpr:
|
of nkDotExpr:
|
||||||
|
|
|
||||||
|
|
@ -3226,7 +3226,7 @@ when not defined(nimscript) and hasAlloc:
|
||||||
gcOptimizeTime, ## optimize for speed
|
gcOptimizeTime, ## optimize for speed
|
||||||
gcOptimizeSpace ## optimize for memory footprint
|
gcOptimizeSpace ## optimize for memory footprint
|
||||||
|
|
||||||
when not defined(JS) and not defined(nimV2):
|
when not defined(JS) and not defined(gcDestructors):
|
||||||
proc GC_disable*() {.rtl, inl, benign.}
|
proc GC_disable*() {.rtl, inl, benign.}
|
||||||
## Disables the GC. If called `n` times, `n` calls to `GC_enable`
|
## Disables the GC. If called `n` times, `n` calls to `GC_enable`
|
||||||
## are needed to reactivate the GC.
|
## are needed to reactivate the GC.
|
||||||
|
|
@ -3589,7 +3589,7 @@ when not defined(JS): #and not defined(nimscript):
|
||||||
{.push stack_trace: off, profiler:off.}
|
{.push stack_trace: off, profiler:off.}
|
||||||
|
|
||||||
when hasAlloc:
|
when hasAlloc:
|
||||||
when not defined(gcRegions) and not defined(nimV2):
|
when not defined(gcRegions) and not defined(gcDestructors):
|
||||||
proc initGC() {.gcsafe.}
|
proc initGC() {.gcsafe.}
|
||||||
|
|
||||||
proc initStackBottom() {.inline, compilerproc.} =
|
proc initStackBottom() {.inline, compilerproc.} =
|
||||||
|
|
|
||||||
53
lib/system/gc_hooks.nim
Normal file
53
lib/system/gc_hooks.nim
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Nim's Runtime Library
|
||||||
|
# (c) Copyright 2019 Andreas Rumpf
|
||||||
|
#
|
||||||
|
# See the file "copying.txt", included in this
|
||||||
|
# distribution, for details about the copyright.
|
||||||
|
#
|
||||||
|
|
||||||
|
## Hooks for memory management. Can be used to implement custom garbage
|
||||||
|
## collectors etc.
|
||||||
|
|
||||||
|
type
|
||||||
|
GlobalMarkerProc = proc () {.nimcall, benign, raises: [], tags: [].}
|
||||||
|
var
|
||||||
|
globalMarkersLen: int
|
||||||
|
globalMarkers: array[0..3499, GlobalMarkerProc]
|
||||||
|
threadLocalMarkersLen: int
|
||||||
|
threadLocalMarkers: array[0..3499, GlobalMarkerProc]
|
||||||
|
|
||||||
|
proc nimRegisterGlobalMarker(markerProc: GlobalMarkerProc) {.compilerproc.} =
|
||||||
|
if globalMarkersLen <= high(globalMarkers):
|
||||||
|
globalMarkers[globalMarkersLen] = markerProc
|
||||||
|
inc globalMarkersLen
|
||||||
|
else:
|
||||||
|
cstderr.rawWrite("[GC] cannot register global variable; too many global variables")
|
||||||
|
quit 1
|
||||||
|
|
||||||
|
proc nimRegisterThreadLocalMarker(markerProc: GlobalMarkerProc) {.compilerproc.} =
|
||||||
|
if threadLocalMarkersLen <= high(threadLocalMarkers):
|
||||||
|
threadLocalMarkers[threadLocalMarkersLen] = markerProc
|
||||||
|
inc threadLocalMarkersLen
|
||||||
|
else:
|
||||||
|
cstderr.rawWrite("[GC] cannot register thread local variable; too many thread local variables")
|
||||||
|
quit 1
|
||||||
|
|
||||||
|
proc traverseGlobals*() =
|
||||||
|
for i in 0..globalMarkersLen-1:
|
||||||
|
globalMarkers[i]()
|
||||||
|
|
||||||
|
proc traverseThreadLocals*() =
|
||||||
|
for i in 0..threadLocalMarkersLen-1:
|
||||||
|
threadLocalMarkers[i]()
|
||||||
|
|
||||||
|
var
|
||||||
|
newObjHook*: proc (typ: PNimType, size: int): pointer {.nimcall, tags: [], raises: [], gcsafe.}
|
||||||
|
traverseObjHook*: proc (p: pointer, op: int) {.nimcall, tags: [], raises: [], gcsafe.}
|
||||||
|
|
||||||
|
proc nimGCvisit(p: pointer, op: int) {.inl, compilerRtl.} =
|
||||||
|
traverseObjHook(p, op)
|
||||||
|
|
||||||
|
proc newObj(typ: PNimType, size: int): pointer {.inl, compilerRtl.} =
|
||||||
|
result = newObjHook(typ, size)
|
||||||
|
|
@ -87,20 +87,28 @@ type
|
||||||
ntfEnumHole = 2 # enum has holes and thus `$` for them needs the slow
|
ntfEnumHole = 2 # enum has holes and thus `$` for them needs the slow
|
||||||
# version
|
# version
|
||||||
TNimType {.compilerproc.} = object
|
TNimType {.compilerproc.} = object
|
||||||
|
when defined(gcDestructors):
|
||||||
|
head*: pointer
|
||||||
size: int
|
size: int
|
||||||
kind: TNimKind
|
kind: TNimKind
|
||||||
flags: set[TNimTypeFlag]
|
flags: set[TNimTypeFlag]
|
||||||
base: ptr TNimType
|
base: ptr TNimType
|
||||||
node: ptr TNimNode # valid for tyRecord, tyObject, tyTuple, tyEnum
|
node: ptr TNimNode # valid for tyRecord, tyObject, tyTuple, tyEnum
|
||||||
finalizer: pointer # the finalizer for the type
|
finalizer*: pointer # the finalizer for the type
|
||||||
marker: proc (p: pointer, op: int) {.nimcall, benign.} # marker proc for GC
|
marker*: proc (p: pointer, op: int) {.nimcall, benign.} # marker proc for GC
|
||||||
deepcopy: proc (p: pointer): pointer {.nimcall, benign.}
|
deepcopy: proc (p: pointer): pointer {.nimcall, benign.}
|
||||||
when defined(nimTypeNames):
|
when defined(nimTypeNames):
|
||||||
name: cstring
|
name: cstring
|
||||||
nextType: ptr TNimType
|
nextType: ptr TNimType
|
||||||
instances: int # count the number of instances
|
instances: int # count the number of instances
|
||||||
sizes: int # sizes of all instances in bytes
|
sizes: int # sizes of all instances in bytes
|
||||||
PNimType = ptr TNimType
|
|
||||||
|
when defined(gcDestructors):
|
||||||
|
type
|
||||||
|
PNimType* = ptr TNimType
|
||||||
|
else:
|
||||||
|
type
|
||||||
|
PNimType = ptr TNimType
|
||||||
|
|
||||||
when defined(nimTypeNames):
|
when defined(nimTypeNames):
|
||||||
# Declare this variable only once in system.nim
|
# Declare this variable only once in system.nim
|
||||||
|
|
|
||||||
|
|
@ -505,10 +505,12 @@ else:
|
||||||
elif defined(gcRegions):
|
elif defined(gcRegions):
|
||||||
# XXX due to bootstrapping reasons, we cannot use compileOption("gc", "stack") here
|
# XXX due to bootstrapping reasons, we cannot use compileOption("gc", "stack") here
|
||||||
include "system/gc_regions"
|
include "system/gc_regions"
|
||||||
elif defined(nimV2):
|
elif defined(nimV2) or defined(gcDestructors):
|
||||||
var allocator {.rtlThreadVar.}: MemRegion
|
var allocator {.rtlThreadVar.}: MemRegion
|
||||||
instantiateForRegion(allocator)
|
instantiateForRegion(allocator)
|
||||||
elif defined(gcMarkAndSweep) or defined(gcDestructors):
|
when defined(gcDestructors):
|
||||||
|
include "system/gc_hooks"
|
||||||
|
elif defined(gcMarkAndSweep):
|
||||||
# XXX use 'compileOption' here
|
# XXX use 'compileOption' here
|
||||||
include "system/gc_ms"
|
include "system/gc_ms"
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ when not defined(useNimRtl):
|
||||||
cl: var ReprClosure) =
|
cl: var ReprClosure) =
|
||||||
# we know that p is not nil here:
|
# we know that p is not nil here:
|
||||||
when declared(CellSet):
|
when declared(CellSet):
|
||||||
when defined(boehmGC) or defined(gogc) or defined(nogc):
|
when defined(boehmGC) or defined(gogc) or defined(nogc) or defined(gcDestructors):
|
||||||
var cell = cast[PCell](p)
|
var cell = cast[PCell](p)
|
||||||
else:
|
else:
|
||||||
var cell = usrToCell(p)
|
var cell = usrToCell(p)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue