[m-rev.] diff: Setup an OOM callback with Boehm GC

Paul Bone paul at bone.id.au
Wed Jun 8 13:55:13 AEST 2016


Setup an OOM callback with Boehm GC

This is a simplier way to get an earlier abort when we run out of memory.
it also prints out the requested allocation size.

runtime/mercury_wrapper.c:
    As above.
---
 runtime/mercury_wrapper.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/runtime/mercury_wrapper.c b/runtime/mercury_wrapper.c
index 0afabc5..dccc785 100644
--- a/runtime/mercury_wrapper.c
+++ b/runtime/mercury_wrapper.c
@@ -831,6 +831,18 @@ mercury_runtime_init(int argc, char **argv)
     #error "MR_HIGHTAGS is incompatible with MR_CONSERVATIVE_GC"
   #endif
 
+/*
+ * Boehm will call this callback when it runs out of memory, We print an
+ * error and abort.  Our error is printed after Boehm GC's on error, so we
+ * don't need to say much.
+ */
+#ifdef MR_BOEHM_GC
+static void *MR_oom_func(size_t bytes)
+{
+    MR_fatal_error("Could not allocate %d bytes, exiting.\n", bytes);
+}
+#endif
+
 void
 MR_init_conservative_GC(void)
 {
@@ -898,6 +910,8 @@ MR_init_conservative_GC(void)
         }
     }
 
+    GC_set_oom_fn(MR_oom_func);
+
   #endif /* MR_BOEHM_GC */
 }
 #endif /* MR_CONSERVATIVE_GC */
-- 
2.8.1



More information about the reviews mailing list