10 #include <sys/types.h>
11 #include <sys/times.h>
18 #define nextbuddy(p) ((bpointer)((int)p+(buddy[p->h.bix].size<<2)))
19 #define marked(p) (p->h.mark)
20 #define markon(p) p->h.mark=1
21 #define markoff(p) p->h.mark=0
37 register struct chunk *cp;
38 if (k<DEFAULTCHUNKINDEX) k=DEFAULTCHUNKINDEX;
39 if (
QDEBUG && debug) fprintf(stderr,
";; newchunk: k=%d\n",k);
43 if (cp==
NULL)
return(ERR);
77 b1->
h.
b=0; b1->
h.
bix= k-1; b2->
h.
b=1;
97 for (k=req;
buddy[k].
bp==0; ) k++;}
101 while (req<k) {
splitheap(k--);
if (k>req) k--;}
116 {
register int i=1,ss;
121 if (i>=MAXBUDDY)
return(
NULL);
125 while (nils<
s)
v[nils++]=
NIL;
143 if (marked(
bp))
return;
145 if (pisclosure(p))
return;
146 if (
bp->h.elmtype==ELM_FIXED) {
149 if ((
int)p>(
int)
_end && (
int)p<0x20000000 && ispointer(p))
mark(p);
151 if ((
int)p>(
int)
_end && (
int)p<0x20000000 && ispointer(p))
goto markagain;
157 if (ispointer(p))
mark(p);}}}
158 else if (
bp->h.elmtype==ELM_POINTER) {
162 if (ispointer(p))
mark(p);}
173 for (i=0; i<MAXTHREAD; i++) {
177 for (p=ctx->
stack; p<ctx->vsp; p++)
181 for (i=0; i<MAXCLASS; i++) {
188 {
register int rbix,stat;
191 if (pisfilestream(
s)) {
192 if (!isint(
s->c.fstream.fname) &&
s->c.fstream.direction!=
NIL) {
194 fprintf(stderr,
";; gc! bogus stream at %x fd=%d\n",
197 fprintf(stderr,
";; gc: dangling stream(address=%x fd=%d) is closed\n",
198 (
int)
s,
intval(
s->c.fstream.fd)); } }
212 while (p->
h.
b==0 && (
int)p->
h.
bix<cbix) {
213 if (marked(np))
return(np);
237 if (marked(p)) { markoff(p); p=nextbuddy(p);}
250 register struct chunk *chp;
252 for (i=0; i<MAXBUDDY-1; i++)
buddy[i].
bp=0;
259 {
if (debug) fprintf(stderr,
"\n;; gc:");
265 fprintf(stderr,
" free/total=%d/%d stack=%d ",
272 {
struct tms tbuf1,tbuf2,tbuf3;
274 if (debug) fprintf(stderr,
"\n;; gc:");
281 marktime+=(tbuf2.tms_utime-tbuf1.tms_utime);
284 sweeptime+=(tbuf3.tms_utime-tbuf2.tms_utime);
286 fprintf(stderr,
" thread=%d free/total=%d/%d stack=%d ",