[m-rev.] diff: accurate GC: support --reclaim-heap-on-failure

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 5 19:48:51 AEDT 2002


Estimated hours taken: 4
Branches: main

Support `--reclaim-heap-on-failure' in grade hlc.agc.

runtime/mercury_accurate_gc.h:
runtime/mercury_accurate_gc.c:
runtime/mercury_deep_copy.c:
runtime/mercury_deep_copy_body.h:
	Handle copying of saved heap pointers.
	We do this by building a list of them while traversing the roots,
	and then once we've finished copying all the other data,
	we reset them all to point to the new heap pointer.

runtime/mercury_conf_param.h:
	Document the new configuration macro MR_DEBUG_AGC_SAVED_HPS.

Workspace: /home/ceres/fjh/mercury
Index: runtime/mercury_accurate_gc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.c,v
retrieving revision 1.17
diff -u -d -r1.17 mercury_accurate_gc.c
--- runtime/mercury_accurate_gc.c	4 Mar 2002 15:17:18 -0000	1.17
+++ runtime/mercury_accurate_gc.c	5 Mar 2002 08:14:43 -0000
@@ -60,6 +60,39 @@
 /* The last root on the list */
 static MR_RootList last_root = NULL;
 
+/*
+** During garbage collection, when traversing from the roots, we may
+** encounter saved heap pointers.  We want to handle these by just
+** resetting them to point to the first free byte of the new heap,
+** but until the collection has finished, we don't know much of the
+** new heap will be used.  So when traversing saved heap pointers,
+** we just put them onto a list; when we've finished traversing
+** all the roots, we can then fill in the correct values for the
+** saved heap pointers.
+**
+** To avoid the need for dynamic allocation,
+** the list is stored in saved heap pointers themselves.
+** We represent the list by just chaining the saved heap pointers
+** together, so that each saved heap pointer points to the next one.
+** The `MR_saved_heap_pointers_list' variable points to the start of
+** this list.
+*/
+MR_Word *MR_saved_heap_pointers_list;
+
+static void
+fixup_saved_heap_pointers(MR_Word *new_hp)
+{
+	MR_Word *p;
+	MR_Word next;
+
+	for (p = MR_saved_heap_pointers_list; p != NULL; p = (MR_Word *) next)
+	{
+		next = *p;
+		*p = (MR_Word) new_hp;
+	}
+	MR_saved_heap_pointers_list = NULL;
+}
+
 #ifdef MR_HIGHLEVEL_CODE
 
 /*
@@ -124,11 +157,13 @@
     */
     garbage_collect_roots();
 
+    fixup_saved_heap_pointers(MR_virtual_hp);
+
 #ifdef MR_DEBUG_AGC_COLLECTION
     fprintf(stderr, "Clearing old heap:\n");
 
     {
-	Word *tmp_hp;
+	MR_Word *tmp_hp;
 
 	for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
 		*tmp_hp = 1;
Index: runtime/mercury_accurate_gc.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.h,v
retrieving revision 1.12
diff -u -d -r1.12 mercury_accurate_gc.h
--- runtime/mercury_accurate_gc.h	28 Jan 2002 05:30:32 -0000	1.12
+++ runtime/mercury_accurate_gc.h	5 Mar 2002 07:23:52 -0000
@@ -60,5 +60,11 @@
 
 extern	void	MR_agc_add_root(MR_Word *root_addr, MR_TypeInfo type_info);
 
+/*
+** A list of the saved heap pointers.
+** See documentation in mercury_accurate_gc.c.
+*/
+extern MR_Word *MR_saved_heap_pointers_list;
+
 /*---------------------------------------------------------------------------*/
 #endif /* not MERCURY_ACCURATE_GC_H */
Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.54
diff -u -d -r1.54 mercury_conf_param.h
--- runtime/mercury_conf_param.h	20 Feb 2002 10:28:17 -0000	1.54
+++ runtime/mercury_conf_param.h	5 Mar 2002 08:10:08 -0000
@@ -245,6 +245,10 @@
 **	Display debugging information when leaving or finding forwarding
 **	pointers during accurate garbage collection.
 **
+** MR_DEBUG_AGC_SAVED_HPS
+**	Display debugging information about saved heap pointers
+**	during accurate garbage collection.
+**
 ** MR_DEBUG_AGC_PRINT_VARS
 **	Display the values of live variables during accurate garbage
 **	collection.
@@ -286,6 +290,7 @@
   #define MR_DEBUG_AGC_SCHEDULING
   #define MR_DEBUG_AGC_COLLECTION
   #define MR_DEBUG_AGC_FORWARDING
+  #define MR_DEBUG_AGC_SAVED_HPS
   #define MR_DEBUG_AGC_PRINT_VARS
   #define MR_DEBUG_AGC_SMALL_HEAP
 #endif
Index: runtime/mercury_deep_copy.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy.c,v
retrieving revision 1.27
diff -u -d -r1.27 mercury_deep_copy.c
--- runtime/mercury_deep_copy.c	18 Feb 2002 07:01:14 -0000	1.27
+++ runtime/mercury_deep_copy.c	5 Mar 2002 07:49:17 -0000
@@ -18,6 +18,7 @@
 #include "mercury_ho_call.h"
 #include "mercury_layout_util.h"
 #include "mercury_memory.h"
+#include "mercury_accurate_gc.h"
 
 
 /*
@@ -52,6 +53,9 @@
 #undef	found_forwarding_pointer
 #define found_forwarding_pointer(Data)
 
+#undef handle_saved_heap_pointers
+#define handle_saved_heap_pointers MR_FALSE
+
 #include "mercury_deep_copy_body.h"
 
 
@@ -101,6 +105,9 @@
 #undef  found_forwarding_pointer
 #define found_forwarding_pointer(Data)	\
 		FORWARD_DEBUG_MSG("not on this heap: %lx\n", (long) Data);
+
+#undef handle_saved_heap_pointers
+#define handle_saved_heap_pointers MR_TRUE
 
 #include "mercury_deep_copy_body.h"
 
Index: runtime/mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.48
diff -u -d -r1.48 mercury_deep_copy_body.h
--- runtime/mercury_deep_copy_body.h	3 Mar 2002 13:45:39 -0000	1.48
+++ runtime/mercury_deep_copy_body.h	5 Mar 2002 08:43:17 -0000
@@ -670,12 +670,33 @@
         break;
 
     case MR_TYPECTOR_REP_HP:
+#if handle_saved_heap_pointers
         /*
-        ** Tyson hasn't yet moved the code for copying saved heap pointers
-        ** here.
+        ** We can't copy saved heap pointer values now,
+        ** since we don't know what the new heap pointer will be
+        ** after garbage collection has finished.
+        ** Instead we just push the saved heap pointer onto a list,
+        ** and fill in the correct value later.
+        ** See fixup_saved_heap_pointers() in mercury_accurate_gc.c.
         */
-        MR_fatal_error("Sorry, not implemented: copying saved heap pointers");
+  #ifdef MR_DEBUG_AGC_SAVED_HPS
+        fprintf(stderr, "found saved heap pointer: "
+                        "addr = %p, val = %p, chain = %p\n",
+                        (void *) data_ptr, (void *) data,
+                        (void *) MR_saved_heap_pointers_list);
+  #endif
+        /* insert this pointer at the start of the list */
+        new_data = *data_ptr = (MR_Word) MR_saved_heap_pointers_list;
+        MR_saved_heap_pointers_list = data_ptr;
         break;
+#else
+        /*
+        ** Copying of saved heap pointers should only occur in native GC
+        ** grades.  For `--gc none', there can be saved heap pointers,
+        ** but they should never be copied.
+        */
+        MR_fatal_error("Unexpected: copying saved heap pointer");
+#endif
 
     case MR_TYPECTOR_REP_CURFR: /* fallthru */
     case MR_TYPECTOR_REP_MAXFR:
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list