[m-rev.] more agc fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jun 7 02:35:00 AEST 2002


Estimated hours taken: 4
Branches: main

Some more improvements for accurate GC.

library/std_util.m:
	Don't do heap reclamation on failure in builtin_aggregate
	and builtin_do_while if accurate GC is enabled, since
	accurate GC currently doesn't support heap reclamation
	on failure (for reasons explained in the comments in
	compiler/ml_elim_nested.m).

	Also, define the `heap_pointer' type here as equivalent to
	the one in private_builtin, rather than using c_pointer,
	so that it gets the correct RTTI for a heap pointer.

runtime/mercury_deep_copy_body.h:
	Don't complain about saved heap pointers unless they actually
	point into the Mercury heap.  This is needed to handle the
	null values used for saved heap pointers in std_util.m when GC
	is enabled.

Workspace: /home/ceres/fjh/mercury
diff -u library/std_util.m library/std_util.m
--- library/std_util.m
+++ library/std_util.m
@@ -749,6 +749,7 @@
 
 :- import_module require, set, int, string, bool.
 :- import_module construct, deconstruct.
+:- use_module private_builtin. % for the `heap_pointer' type.
 
 % XXX This should not be necessary, but the current compiler is broken in that
 % it puts foreign_proc clauses into deconstruct.opt without also putting the
@@ -1005,7 +1006,7 @@
 		(pred(M::out, di, uo) is cc_multi --> P(X, M)),
 		More, Acc0, Acc).
 
-:- type heap_ptr ---> heap_ptr(c_pointer).
+:- type heap_ptr == private_builtin__heap_pointer.
 :- type trail_ptr ---> trail_ptr(c_pointer).
 
 %
@@ -1018,12 +1019,18 @@
 :- impure pred get_registers(heap_ptr::out, heap_ptr::out, trail_ptr::out)
 	is det.
 
+:- pragma foreign_decl("C", "
+#if !defined(MR_CONSERVATIVE_GC) && !defined(MR_NATIVE_GC)
+  #define MR_RECLAIM_HP_ON_FAILURE
+#endif
+").
+
 :- pragma foreign_proc("C", 
 	get_registers(HeapPtr::out, SolutionsHeapPtr::out, TrailPtr::out),
 	[will_not_call_mercury, thread_safe],
 "
 	/* save heap states */
-#ifndef MR_CONSERVATIVE_GC
+#ifdef MR_RECLAIM_HP_ON_FAILURE
  	HeapPtr = (MR_Word) MR_hp;
  	SolutionsHeapPtr = (MR_Word) MR_sol_hp;
 #else
@@ -1110,7 +1117,7 @@
 	swap_heap_and_solutions_heap,
 	[will_not_call_mercury, thread_safe],
 "{
-#ifndef MR_CONSERVATIVE_GC
+#ifdef MR_RECLAIM_HP_ON_FAILURE
 	MR_MemoryZone *temp_zone;
 	MR_Word *temp_hp;
 
@@ -1148,7 +1155,7 @@
 
 #include ""mercury_deep_copy.h""
 
-#ifdef MR_CONSERVATIVE_GC
+#ifndef MR_RECLAIM_HP_ON_FAILURE
   /* for conservative GC, shallow copies suffice */
   #define MR_PARTIAL_DEEP_COPY(SolutionsHeapPtr,			\\
   		OldVar, NewVal, TypeInfo_for_T)				\\
@@ -1228,7 +1235,7 @@
 	reset_solutions_heap(SolutionsHeapPtr::in),
 	[will_not_call_mercury, thread_safe, promise_pure],
 "
-#ifndef MR_CONSERVATIVE_GC
+#ifdef MR_RECLAIM_HP_ON_FAILURE
 	MR_sol_hp = (MR_Word *) SolutionsHeapPtr;
 #endif
 ").
diff -u runtime/mercury_deep_copy_body.h runtime/mercury_deep_copy_body.h
--- runtime/mercury_deep_copy_body.h
+++ runtime/mercury_deep_copy_body.h
@@ -593,7 +595,12 @@
         break;
 
     case MR_TYPECTOR_REP_HP:
-        MR_fatal_error("Sorry, not implemented: copying saved heap pointer");
+        assert(MR_tag(data) == 0);
+        if (in_range((MR_Word *) data)) {
+            MR_fatal_error("Sorry, not implemented: copying saved heap pointer");
+        } else {
+            new_data = data;
+        }
 
     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