[m-rev.] more LLDS accurate GC fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Oct 14 02:34:59 AEST 2003


Estimated hours taken: 3
Branches: main

More fixes for accurate GC in LLDS grades (i.e. asm_fast.agc).

runtime/mercury_deep_copy_body.h:
	Don't abort when trying to copy foreign types,
	unless the foreign type happens to point into the Mercury heap.

Index: mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.61
diff -u -d -u -r1.61 mercury_deep_copy_body.h
--- mercury_deep_copy_body.h	13 May 2003 08:52:06 -0000	1.61
+++ mercury_deep_copy_body.h	13 Oct 2003 16:23:21 -0000
@@ -628,9 +628,45 @@
         return new_data;
 
     case MR_TYPECTOR_REP_FOREIGN:
-        MR_fatal_error("Cannot copy foreign types");
+        {
+            MR_Word *data_value;
 
-    case MR_TYPECTOR_REP_UNKNOWN: /* fallthru */
+            data_value = (MR_Word *) MR_strip_tag(data);
+
+            /*
+            ** XXX It is bad that the behaviour here depends on
+            ** the value of the foreign type.  But I don't see any
+            ** better alternative at the moment.
+            */
+            if (!in_range(data_value)) {
+                /*
+                ** If the foreign value does not point into the heap,
+                ** then we know it is not a pointer, so it is safe to
+                ** leave it unchanged.  
+                **
+                ** It is important to allow these cases,
+                ** since they include the common cases of pointer types
+                ** that point to the C heap, global data, or stack data.
+                ** io__stream is a particularly important example.
+                */
+                new_data = data;
+            } else {
+                /*
+                ** The foreign value points into the Mercury heap.
+                ** It might be a foreign pointer to a Mercury heap
+                ** value; or it might be a pointer to a foreign struct
+                ** which MR_MAYBE_BOX_FOREIGN_TYPE() has copied to the
+                ** Mercury heap; or it might be a non-pointer type
+                ** whose bit pattern happens to point to the heap.
+                **
+                ** We don't know how to copy it, so we have to abort.
+                */
+                MR_fatal_error("Cannot copy foreign type");
+            }
+        }
+        return new_data;
+
+    case MR_TYPECTOR_REP_UNKNOWN:
         MR_fatal_error("Unknown layout type in deep copy");
     }
 


-- 
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