[m-rev.] for review: fix nondet stack segments

Peter Wang novalazy at gmail.com
Thu Aug 7 11:17:47 AEST 2008


On 2008-08-06, Zoltan Somogyi <zs at csse.unimelb.edu.au> wrote:
> On 06-Aug-2008, Peter Wang <novalazy at gmail.com> wrote:
> > +    ** Pop off the nondet stack segments until maxfr is within the bounds of
> > +    ** the top segment.
> > +    ** XXX we could avoid rewinding all the way if we'll be needing to create a
> > +    ** new segment anyway
> > +    */
> > +    MR_rewind_nondetstack_segments(old_maxfr);
> 
> You could make this return a pointer to a zone to reuse, or NULL.
> 

Good idea.

> > +    for (;;) {
> > +        zone = MR_CONTEXT(MR_ctxt_nondetstack_zone);
> > +        /*
> > +        ** XXX why is maxfr sometimes slightly past MR_zone_extend_threshold?
> > +        ** That's why we test against MR_zone_redzone.
> > +        */
> 
> Is this executed before or after maxfr is incremented? If before, the only
> way to answer that question is to search the runtime and some representative
> compiler-generated code for assignments to MR_maxfr_word.
> 

Before maxfr is incremented.

> 
> Have you tested the diff on a SPARC, to check for any problems caused
> by register windows?

I don't have access to a SPARC.

Committed with the following changes.

Peter

diff --git a/runtime/mercury_stacks.c b/runtime/mercury_stacks.c
index cbb8aa8..897feb6 100644
--- a/runtime/mercury_stacks.c
+++ b/runtime/mercury_stacks.c
@@ -252,7 +252,7 @@ MR_Word *MR_new_detstack_segment(MR_Word *sp, int n)
     return MR_sp;
 }
 
-static  void     MR_rewind_nondetstack_segments(MR_Word *maxfr);
+static  MR_MemoryZone   *MR_rewind_nondetstack_segments(MR_Word *maxfr);
 
 void
 MR_nondetstack_segment_extend_slow_path(MR_Word *old_maxfr, int incr)
@@ -264,10 +264,8 @@ MR_nondetstack_segment_extend_slow_path(MR_Word *old_maxfr, int incr)
     /*
     ** Pop off the nondet stack segments until maxfr is within the bounds of
     ** the top segment.
-    ** XXX we could avoid rewinding all the way if we'll be needing to create a
-    ** new segment anyway
     */
-    MR_rewind_nondetstack_segments(old_maxfr);
+    new_zone = MR_rewind_nondetstack_segments(old_maxfr);
 
     /* Try to make a frame on the top segment. */
     new_maxfr = old_maxfr + incr;
@@ -275,12 +273,17 @@ MR_nondetstack_segment_extend_slow_path(MR_Word *old_maxfr, int incr)
         MR_zone_extend_threshold)
     {
         MR_maxfr_word = (MR_Word) new_maxfr;
+        if (new_zone != NULL) {
+            MR_unget_zone(new_zone);
+        }
         return;
     }
 
-    /* We perform explicit overflow checks so redzones just waste space. */
-    new_zone = MR_create_zone("nondetstack_segment", 0,
-        MR_nondetstack_size, 0, 0, MR_default_handler);
+    if (new_zone == NULL) {
+        /* We perform explicit overflow checks so redzones just waste space. */
+        new_zone = MR_create_zone("nondetstack_segment", 0,
+            MR_nondetstack_size, 0, 0, MR_default_handler);
+    }
 
     list = MR_GC_malloc_uncollectable(sizeof(MR_MemoryZones));
 
@@ -308,12 +311,15 @@ MR_nondetstack_segment_extend_slow_path(MR_Word *old_maxfr, int incr)
 #endif
 }
 
-static void
+static MR_MemoryZone *
 MR_rewind_nondetstack_segments(MR_Word *maxfr)
 {
+    MR_MemoryZone   *reusable_zone;
     MR_MemoryZone   *zone;
     MR_MemoryZones  *list;
 
+    reusable_zone = NULL;
+
     for (;;) {
         zone = MR_CONTEXT(MR_ctxt_nondetstack_zone);
         /*
@@ -326,14 +332,20 @@ MR_rewind_nondetstack_segments(MR_Word *maxfr)
             break;
         }
 
-        MR_unget_zone(zone);
+        if (reusable_zone == NULL) {
+            reusable_zone = zone;
+        } else {
+            MR_unget_zone(zone);
+        }
 
         list = MR_CONTEXT(MR_ctxt_prev_nondetstack_zones);
-        assert(list);
+        assert(list != NULL);
         MR_CONTEXT(MR_ctxt_nondetstack_zone) = list->MR_zones_head;
         MR_CONTEXT(MR_ctxt_prev_nondetstack_zones) = list->MR_zones_tail;
         MR_GC_free(list);
     }
+
+    return reusable_zone;
 }
 
 #endif  /* MR_STACK_SEGMENTS */


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list