summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorReimer Behrends <behrends@gmail.com>2019-01-15 19:00:02 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-01-15 19:00:02 +0100
commit06e3d3ab4dea4aa11a1728c849799ce6aeecb3a4 (patch)
tree50ce8781459aca1009d3f3985ae2f56e380e1f0c /lib/system
parent4355f23ee5fd53acfdaa8ecb5dbb50f9b43f98b2 (diff)
downloadNim-06e3d3ab4dea4aa11a1728c849799ce6aeecb3a4.tar.gz
Disable interior pointer checking by default for the Boehm GC. (#10316)
The Boehm GC only needs interior pointer checking if pointers in global
variables or on the heap point to the interior of an object rather than
the beginning. If this does not happen, then checking for interior
pointers causes additional overhead, in particular because any objects
whose sizes are an exact multiple of two words gain another two words of
padding, wasting memory.

If checking of interior pointers is still desired, this can be achieved
by setting the environment variable GC_ALL_INTERIOR_POINTERS.

Pointers on the stack will always be treated as potential interior
pointers, as compiler optimizations may advance the only live reference
to a point past the beginning of an object.
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/mmdisp.nim3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim
index 89bc11d2c..9cc7ab323 100644
--- a/lib/system/mmdisp.nim
+++ b/lib/system/mmdisp.nim
@@ -72,6 +72,8 @@ when defined(boehmgc):
   proc boehmGCincremental {.
     importc: "GC_enable_incremental", boehmGC.}
   proc boehmGCfullCollect {.importc: "GC_gcollect", boehmGC.}
+  proc boehmGC_set_all_interior_pointers(flag: cint) {.
+    importc: "GC_set_all_interior_pointers", boehmGC.}
   proc boehmAlloc(size: int): pointer {.importc: "GC_malloc", boehmGC.}
   proc boehmAllocAtomic(size: int): pointer {.
     importc: "GC_malloc_atomic", boehmGC.}
@@ -148,6 +150,7 @@ when defined(boehmgc):
     proc nimGC_setStackBottom(theStackBottom: pointer) = discard
 
   proc initGC() =
+    boehmGC_set_all_interior_pointers(0)
     boehmGCinit()
     when hasThreadSupport:
       boehmGC_allow_register_threads()