summary refs log tree commit diff stats
path: root/lib/system/alloc.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-08-05 14:17:24 +0200
committerAraq <rumpf_a@web.de>2018-08-05 14:17:24 +0200
commit7ac6462cbd30bcdb1c3805fbb06be13b3346ce2a (patch)
tree2e79c210ccd19a7065b36992e19ab74ff061f5df /lib/system/alloc.nim
parent282c4f3d0a72fbb4c49df51048e2e13fafcd8659 (diff)
parent74842ed4a981b6ff168d67d05ee92dce350549cb (diff)
downloadNim-7ac6462cbd30bcdb1c3805fbb06be13b3346ce2a.tar.gz
make at least bootstrapping work
Diffstat (limited to 'lib/system/alloc.nim')
-rw-r--r--lib/system/alloc.nim16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index 95becde22..ffb7aaf86 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -116,6 +116,8 @@ type
     nextChunkSize: int
     bottomData: AvlNode
     heapLinks: HeapLinks
+    when defined(nimTypeNames):
+      allocCounter, deallocCounter: int
 
 const
   fsLookupTable: array[byte, int8] = [
@@ -434,8 +436,9 @@ proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
         a.nextChunkSize = PageSize*4
       else:
         a.nextChunkSize = min(roundup(usedMem shr 2, PageSize), a.nextChunkSize * 2)
-  var size = size
+        a.nextChunkSize = min(a.nextChunkSize, MaxBigChunkSize)
 
+  var size = size
   if size > a.nextChunkSize:
     result = cast[PBigChunk](osAllocPages(size))
   else:
@@ -737,6 +740,8 @@ when false:
         result = nil
 
 proc rawAlloc(a: var MemRegion, requestedSize: int): pointer =
+  when defined(nimTypeNames):
+    inc(a.allocCounter)
   sysAssert(allocInv(a), "rawAlloc: begin")
   sysAssert(roundup(65, 8) == 72, "rawAlloc: roundup broken")
   sysAssert(requestedSize >= sizeof(FreeCell), "rawAlloc: requested size too small")
@@ -810,6 +815,8 @@ proc rawAlloc0(a: var MemRegion, requestedSize: int): pointer =
   zeroMem(result, requestedSize)
 
 proc rawDealloc(a: var MemRegion, p: pointer) =
+  when defined(nimTypeNames):
+    inc(a.deallocCounter)
   #sysAssert(isAllocatedPtr(a, p), "rawDealloc: no allocated pointer")
   sysAssert(allocInv(a), "rawDealloc: begin")
   var c = pageAddr(p)
@@ -975,6 +982,10 @@ proc getOccupiedMem(a: MemRegion): int {.inline.} =
   result = a.occ
   # a.currMem - a.freeMem
 
+when defined(nimTypeNames):
+  proc getMemCounters(a: MemRegion): (int, int) {.inline.} =
+    (a.allocCounter, a.deallocCounter)
+
 # ---------------------- thread memory region -------------------------------
 
 template instantiateForRegion(allocator: untyped) =
@@ -1018,6 +1029,9 @@ template instantiateForRegion(allocator: untyped) =
   proc getOccupiedMem(): int = return allocator.occ #getTotalMem() - getFreeMem()
   proc getMaxMem*(): int = return getMaxMem(allocator)
 
+  when defined(nimTypeNames):
+    proc getMemCounters*(): (int, int) = getMemCounters(allocator)
+
   # -------------------- shared heap region ----------------------------------
   when hasThreadSupport:
     var sharedHeap: MemRegion