[commit: ghc] master: base: export allocation counter/limit API from System.Mem (453cdbf)

git at git.haskell.org git at git.haskell.org
Wed Sep 23 18:13:00 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/453cdbfcea6962d0a2b5f532b5cdf53d5f82143d/ghc

>---------------------------------------------------------------

commit 453cdbfcea6962d0a2b5f532b5cdf53d5f82143d
Author: Simon Marlow <marlowsd at gmail.com>
Date:   Wed Sep 23 13:13:28 2015 -0500

    base: export allocation counter/limit API from System.Mem
    
    Previously it was only available from GHC.Conc, but it makes sense for it to be
    available from a more official place where people might find it.
    
    While I was here, I improved the docs a little.
    
    Reviewed By: austin
    
    Differential Revision: https://phabricator.haskell.org/D1272


>---------------------------------------------------------------

453cdbfcea6962d0a2b5f532b5cdf53d5f82143d
 docs/users_guide/7.12.1-notes.xml  | 12 ++++++++++++
 libraries/base/GHC/Conc/Sync.hs    |  4 +++-
 libraries/base/GHC/IO/Exception.hs |  4 ++--
 libraries/base/System/Mem.hs       | 21 ++++++++++++++++-----
 4 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/docs/users_guide/7.12.1-notes.xml b/docs/users_guide/7.12.1-notes.xml
index b23e3d8..c71887f 100644
--- a/docs/users_guide/7.12.1-notes.xml
+++ b/docs/users_guide/7.12.1-notes.xml
@@ -324,6 +324,18 @@
                     (see Trac #9516).
                </para>
            </listitem>
+           <listitem>
+                <para>
+                    Per-thread allocation counters
+                    (<literal>setAllocationCounter</literal> and
+                    <literal>getAllocationCounter</literal>) and limits
+                    (<literal>enableAllocationLimit</literal>,
+                    <literal>disableAllocationLimit</literal> are now
+                    available from <literal>System.Mem</literal>.
+                    Previously this functionality was only available
+                    from <literal>GHC.Conc</literal>.
+                </para>
+           </listitem>
        </itemizedlist>
     </sect3>
 
diff --git a/libraries/base/GHC/Conc/Sync.hs b/libraries/base/GHC/Conc/Sync.hs
index 81ec7fa..db6f841 100644
--- a/libraries/base/GHC/Conc/Sync.hs
+++ b/libraries/base/GHC/Conc/Sync.hs
@@ -213,7 +213,9 @@ getAllocationCounter = do
 -- to 100K, but tunable with the @+RTS -xq@ option) so that it can handle
 -- the exception and perform any necessary clean up.  If it exhausts
 -- this additional allowance, another 'AllocationLimitExceeded' exception
--- is sent, and so forth.
+-- is sent, and so forth.  Like other asynchronous exceptions, the
+-- 'AllocationLimitExceeded' exception is deferred while the thread is inside
+-- 'mask' or an exception handler in 'catch'.
 --
 -- Note that memory allocation is unrelated to /live memory/, also
 -- known as /heap residency/.  A thread can allocate a large amount of
diff --git a/libraries/base/GHC/IO/Exception.hs b/libraries/base/GHC/IO/Exception.hs
index e723ebd..7e483de 100644
--- a/libraries/base/GHC/IO/Exception.hs
+++ b/libraries/base/GHC/IO/Exception.hs
@@ -98,8 +98,8 @@ instance Show Deadlock where
 -----
 
 -- |This thread has exceeded its allocation limit.  See
--- 'GHC.Conc.setAllocationCounter' and
--- 'GHC.Conc.enableAllocationLimit'.
+-- 'System.Mem.setAllocationCounter' and
+-- 'System.Mem.enableAllocationLimit'.
 --
 -- @since 4.8.0.0
 data AllocationLimitExceeded = AllocationLimitExceeded
diff --git a/libraries/base/System/Mem.hs b/libraries/base/System/Mem.hs
index a894f4d..c47a52d 100644
--- a/libraries/base/System/Mem.hs
+++ b/libraries/base/System/Mem.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE Safe #-}
-
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  System.Mem
@@ -14,17 +12,30 @@
 --
 -----------------------------------------------------------------------------
 
+{-# LANGUAGE Trustworthy #-}
+-- allocation counter stuff is safe, but GHC.Conc.Sync is Unsafe
+
 module System.Mem
-       ( performGC
+       (
+       -- * Garbage collection
+         performGC
        , performMajorGC
        , performMinorGC
+
+        -- * Allocation counter and limits
+        , setAllocationCounter
+        , getAllocationCounter
+        , enableAllocationLimit
+        , disableAllocationLimit
        ) where
 
--- | Triggers an immediate garbage collection.
+import GHC.Conc.Sync
+
+-- | Triggers an immediate major garbage collection.
 performGC :: IO ()
 performGC = performMajorGC
 
--- | Triggers an immediate garbage collection.
+-- | Triggers an immediate major garbage collection.
 --
 -- @since 4.7.0.0
 foreign import ccall "performMajorGC" performMajorGC :: IO ()



More information about the ghc-commits mailing list