diff options
author | Araq <rumpf_a@web.de> | 2011-12-22 15:04:00 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-12-22 15:04:00 +0100 |
commit | cd83cc81aa58922e0a8370ae5928d5b5aaa16f84 (patch) | |
tree | e3abff5b7a2cd46977e8435a4ebbfdde0c19ba07 /lib/system | |
parent | f19c1c0f6e93a561dc13ef57d136957edeba9ed4 (diff) | |
download | Nim-cd83cc81aa58922e0a8370ae5928d5b5aaa16f84.tar.gz |
code gen can generate code to keep alive stack roots
Diffstat (limited to 'lib/system')
-rwxr-xr-x | lib/system/alloc.nim | 19 | ||||
-rwxr-xr-x | lib/system/gc.nim | 7 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 6dee145c8..f33d40b0a 100755 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -171,7 +171,7 @@ proc getMaxMem(a: var TMemRegion): int = # Since we update maxPagesCount only when freeing pages, # maxPagesCount may not be up to date. Thus we use the # maximum of these both values here: - return max(a.currMem, a.maxMem) + result = max(a.currMem, a.maxMem) proc llAlloc(a: var TMemRegion, size: int): pointer = # *low-level* alloc for the memory managers data structures. Deallocation @@ -550,6 +550,23 @@ proc isAllocatedPtr(a: TMemRegion, p: pointer): bool = var c = cast[PBigChunk](c) result = p == addr(c.data) and cast[ptr TFreeCell](p).zeroField >% 1 +proc interiorAllocatedPtr(a: TMemRegion, p: pointer): pointer = + if isAccessible(a, p): + var c = pageAddr(p) + if not chunkUnused(c): + if isSmallChunk(c): + var c = cast[PSmallChunk](c) + var offset = (cast[TAddress](p) and (PageSize-1)) -% + smallChunkOverhead() + if c.acc >% offset: + var d = cast[ptr TFreeCell](cast[TAddress](addr(c.data)) +% + offset -% (offset %% c.size)) + if d.zeroField >% 1: result = d + else: + var c = cast[PBigChunk](c) + var d = addr(c.data) + if p >= d and cast[ptr TFreeCell](d).zeroField >% 1: result = d + proc ptrSize(p: pointer): int = var x = cast[pointer](cast[TAddress](p) -% sizeof(TFreeCell)) result = pageAddr(x).size - sizeof(TFreeCell) diff --git a/lib/system/gc.nim b/lib/system/gc.nim index caab22e34..f13015573 100755 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -579,6 +579,13 @@ proc nimKeepAlive(p: PGenericSeq) {.compilerRtl, noinline.} = if isAllocatedPtr(gch.region, c): c.refcount = c.refcount or rcMarked +proc nimGCFrame(p: pointer) {.compilerRtl, noinline.} = + # 'cast' is correct here! no offset to add: + var c = cast[PCell](p) + var x = cast[TAddress](c) + if x <% PageSize and (x and (MemAlign-1)) == 0: + c.refcount = c.refcount or rcMarked + proc markThreadStacks(gch: var TGcHeap) = when hasThreadSupport and hasSharedHeap: {.error: "not fully implemented".} |