Changes between Initial Version and Version 1 of GMPMemoryManagement


Ignore:
Timestamp:
Apr 2, 2007 9:49:25 PM (12 years ago)
Author:
Stefan O'Rear
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GMPMemoryManagement

    v1 v1  
     1= Interaction between GMP and the Storage Manager =
     2
     3The Glasgow Haskell Compiler uses GMP to implement Integer.
     4GMP expects a storage model where pointers (newtyped as mpz_t) are explicitly allocated and freed.
     5However, Haskell requires Integers to be garbage collected.
     6This could be done with ForeignPtrs, however (presumably for performance reasons?) GHC uses ByteArray#s from the heap instead.
     7rts/sm/Storage.c `initStorage` sets three override functions to do this: `stgAllocForGMP`, `stgReallocForGMP`, and `stgDeallocForGMP`.
     8
     9This requires a fairly subtle interaction in order to work safely,
     10because heap ByteArray#s are normal objects and can be moved by garbage collection.
     11The important thing to note is that the GHC garbage collector is of the stop-the-world variety.
     12This means that all threads must reach a synchronization point before garbage collection can actually begin.
     13However, there are no such synchronization points inside the GMP-based primops.
     14Therefore, garbage collection, and consequent moving of Integers, can only occur when no GMP operations are executing.