GC performance - was Re: [gclist] GC topics

Chris Reedy creedy@mitre.org
Fri, 23 Feb 1996 15:22:27 -0500


At  1:19 PM 2/23/96 -0500, David Chase wrote:
> [Prior discussion]
>
>For instance, suppose you have a piece of Modula-3 that takes
>two vectors and computes the distance between them
>
>  TYPE coord = OBJECT
>     x : REF ARRAY OF REAL;
>     ...
>  END;
>
> [Modula-3 code]
>
>This could be compiled to a piece of C that looks
>something like this, applying a few obvious optimizations.
>
>  float dist(coord * a, coord * b) {
>    float * bx = a -> x.mem;
>    float * ax = b -> x.mem;
>    int l = min (a -> x.len, b -> x.len) - 1;
>    int i;
>    float sum = 0;
>    float d1;
>
>    /* Use some auto-increment addressing mode to
>       reference the arrays. */
>    for (i = 0; i <= l; i++) {
>       d1 = *ax - *bx;
>       ax++; bx++;
>       sum = sum + d1 * d1;
>    }
>    
>    return sqrt(sum); /* Should be tail-call optimized. */
>  }
>
>Do note that after the first iteration of the loop, there's no longer 
>an obvious pointer to a, or b, or to either array (the registers 
>ought to be reused, if the compiler is any good).  A conservative 
>collector is still happy with this code -- I didn't have to do anything 
>to protect my pointers, because it will still find them (but, see 
>note).
>
> [Further discussion]

I suspect I'm missing something ... But, it would seem that the presence of
a and b as arguments would guarantee the existence of pointers to a and b
either within the stack or within the caller of dist.  Or are compilers so
clever that they can optimize away all the obvious references.  (Apologies
if this is discussed in your thesis).

  Chris

This is an informal message and not an official Mitretek Systems position.
Dr. Christopher L. Reedy, Mail Stop Z667
Mitretek Systems, 7525 Colshire Drive, McLean, VA 22102-3481
Email: creedy@mitretek.org  Phone: (703) 883-7183  FAX: (703) 883-6991