Annotation of 43BSD/contrib/icon/rt/sweep.c, revision 1.1

1.1     ! root        1: #include "../h/rt.h"
        !             2: #include "../h/gc.h"
        !             3: #ifdef VAX
        !             4: /*
        !             5:  * sweep - sweep the stack, marking all descriptors there.  Method
        !             6:  *  is to start at a known point, specifically, the frame that the
        !             7:  *  fp points to, and then trace back along the stack looking for
        !             8:  *  descriptors and local variables, marking them when they are found.
        !             9:  *  The sp starts at the first frame, and then is moved up through
        !            10:  *  the stack.  Procedure, generator, and expression frames are
        !            11:  *  recognized when the sp is a certain distance from the fp, gfp,
        !            12:  *  and efp respectively.
        !            13:  *
        !            14:  * Sweeping problems can be manifested in a variety of ways due to
        !            15:  *  the "if it can't be identified it's a descriptor" methodology.
        !            16:  */
        !            17: #undef gfp
        !            18: #undef efp
        !            19: #undef fp
        !            20: sweep(fp)
        !            21: int *fp;
        !            22:    {
        !            23:    register int *sp, *gfp, *efp, *ap;
        !            24:    int *getap();
        !            25:    int nargs;
        !            26: 
        !            27:    ap = getap(fp);                     /* Get pointer to 0(ap) for frame
        !            28:                                            on top of stack. */
        !            29:    sp = fp - FRAMELIMIT;               /* Start sp at _file word of current
        !            30:                                            frame, the lowest word of it. */
        !            31:    nargs = 0;                          /* Nargs counter is 0 initially. */
        !            32:    while ((fp != 0 || nargs)) {                /* Keep going until current fp is
        !            33:                                            0 and no arguments are left. */
        !            34:       if (sp == fp - FRAMELIMIT) {     /* The sp has reached the lower
        !            35:                                            boundary of a procedure frame,
        !            36:                                            process the frame. */
        !            37:          efp = (int *) ap[-1];         /* Get saved efp out of frame, it's
        !            38:                                            the first word below 0(ap). */
        !            39:          gfp = (int *) ap[-2];         /* Saved gfp is second word below
        !            40:                                            0(ap). */
        !            41:          sp = ap + 2;                  /* First argument descriptor is
        !            42:                                            second word above 0(ap), point
        !            43:                                            sp at it. */
        !            44:          ap = (int *) fp[2];           /* Get saved ap */
        !            45:          fp = (int *) fp[3];           /*  and fp from frame. */
        !            46:          nargs = sp[-1];               /* Nargs is in word below first
        !            47:                                            argument descriptor. */
        !            48:          }
        !            49:       else if (sp == gfp - 3) {                /* The sp has reached the lower end
        !            50:                                            of a generator frame, process
        !            51:                                            the frame.*/
        !            52:          fp = (int *) gfp[0];          /* Get old fp, available as saved
        !            53:                                            boundary value in the frame. */
        !            54:          ap = getap(fp);               /* Find 0(ap) corresponding to just-
        !            55:                                            restored boundary value. */
        !            56:          sp = fp - FRAMELIMIT;         /* Set up to trigger recognition of
        !            57:                                            procedure frame next time around*/
        !            58:          }
        !            59:       else if (sp == efp - 2) {                /* The sp has reached the lower end
        !            60:                                            of a generator frame, process
        !            61:                                            the frame. */
        !            62:          gfp = (int *) efp[-1];                /* Restore gfp, */
        !            63:          efp = (int *) efp[0];         /*  and efp from frame. */
        !            64:          sp += 3;                      /* Move up past expression frame
        !            65:                                            marker. */
        !            66:          }
        !            67:       else {                           /* Assume the sp is pointing at a
        !            68:                                            descriptor. */
        !            69:          mark(sp);                     /* Mark it. */
        !            70:          sp += 2;                      /* Move past descriptor. */
        !            71:          if (nargs)                    /* Decrement argument count if in an*/
        !            72:             nargs--;                   /*  argument list. */
        !            73:          }
        !            74:       }
        !            75:    }
        !            76: /*
        !            77:  * getap - return ap of frame addressed by fp
        !            78:  */
        !            79: int *getap(fp)
        !            80: register int *fp;
        !            81:    {
        !            82:    register
        !            83:     int mask = fp[1]>>15 & 0x1ffe;     /* Get register mask out of saved
        !            84:                                            psw word. */
        !            85:    fp += 5;                            /* Point fp at where first saved
        !            86:                                            register (if any) is. */
        !            87:    while (mask >>= 1)                  /* Move fp up for each register  */
        !            88:       fp += mask & 1;                  /*  saved.  When done, fp points */
        !            89:    return fp;                          /*  at word where ap would point */
        !            90:    }
        !            91: #endif VAX
        !            92: 
        !            93: #ifdef PORT
        !            94: sweep()
        !            95:    {
        !            96:    syserr("Call to sweep() in garbage collector not implemented yet");
        !            97:    }
        !            98: #endif PORT
        !            99: 
        !           100: #ifdef PDP11
        !           101: /*
        !           102:  * sweep - sweep the stack, marking all descriptors there.
        !           103:  */
        !           104: 
        !           105: sweep(b)
        !           106: int *b;
        !           107:    {
        !           108:    register int *sp, *r5, *r4;
        !           109:    int *r3, nargs;
        !           110: 
        !           111:    r5 = b;                     /* start at last Icon/C boundary */
        !           112:    sp = r5 - 5;
        !           113:    nargs = 0;
        !           114:    while ((r5 != 0 || nargs) && sp < (int *)0177776) {
        !           115:       if (sp == r5 - 5) {  /* at a procedure frame */
        !           116:          r3 = r5[-2];
        !           117:         r4 = r5[-1];
        !           118:         r5 = r5[0];
        !           119:         sp += 8;
        !           120:         nargs = sp[-1];
        !           121:         }
        !           122:       else if (sp == r3 - 3) { /* at a generator frame */
        !           123:         r5 = r3[0];            /*   go to next boundary */
        !           124:         sp = r5 - 5;
        !           125:         }
        !           126:       else if (sp == r4 - 2) { /* at an expression frame */
        !           127:         r3 = r4[-1];
        !           128:         r4 = r4[0];
        !           129:         sp += 3;
        !           130:         }
        !           131:       else {                   /* must be a descriptor! */
        !           132:         mark(sp);
        !           133:         sp += 2;
        !           134:         if (nargs)
        !           135:            nargs--;
        !           136:         }
        !           137:       }
        !           138:    }
        !           139: #endif PDP11

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.