home *** CD-ROM | disk | FTP | other *** search
- /**
- GRAB Graph Layout and Browser System
-
- Copyright (c) 1989, Tera Computer Company
- **/
-
- #define DEBUG /* Some run-time consistency checks */
- #undef DEBUG
- #define VERBOSE
- #undef VERBOSE
-
- #include <stdio.h>
- #include <signal.h>
- #include "runtime.h"
-
- int dont_gc = 0;
- extern long mem_found;
-
- /* allocate lb bytes of atomic data */
- struct obj * gc_malloc_atomic(lb)
- int lb;
- {
- register struct obj *op;
- register struct obj **opp;
- register int lw = BYTES_TO_WORDS(lb + (sizeof (word)) -1);
-
- # ifdef VERBOSE
- printf("Here we are in gc_malloc_atomic(%d)\n",lw);
- # endif
- if( lw <= MAXAOBJSZ ) {
- opp = &(aobjfreelist[lw]);
- if( (op = *opp) == ((struct obj *)0) ) {
- op = allocaobj(lw);
- }
- # ifdef DEBUG
- if ((op -> obj_link != ((struct obj *) 0)
- && (((unsigned)(op -> obj_link)) > ((unsigned) HEAPLIM)
- || ((unsigned)(op -> obj_link)) < ((unsigned) HEAPSTART)))) {
- fprintf(stderr, "Bad free list in gc_malloc_atomic\n");
- abort(op);
- }
- # endif
- *opp = op->obj_link;
- op->obj_link = (struct obj *)0;
- } else {
- register struct hblk * h;
- if (!sufficient_hb(-lw) && !dont_gc) {
- gcollect();
- }
- # ifdef VERBOSE
- printf("gc_malloc_atomic calling allochblk(%x)\n",lw);
- # endif
- h = allochblk(-lw);
- add_hblklist(h);
- op = (struct obj *) (h -> hb_body);
- }
- return(op);
- }
-
- /* allocate lw bytes of possibly composite data */
- struct obj * gc_malloc(lb)
- int lb;
- {
- register struct obj *op;
- register struct obj **opp;
- register int lw = BYTES_TO_WORDS(lb + (sizeof (word)) -1);
-
- if( lw <= MAXOBJSZ ) {
- void gc_init() ;
- if(heaplim == 0) gc_init() ;
- if(lw == 0) lw = 1 ; /* bugfix: cdc */
- opp = &(objfreelist[lw]);
- if( (op = *opp) == ((struct obj *)0) ) {
- op = allocobj(lw);
- }
- # ifdef DEBUG
- if ((op -> obj_link != ((struct obj *) 0)
- && (((unsigned)(op -> obj_link)) > ((unsigned) HEAPLIM)
- || ((unsigned)(op -> obj_link)) < ((unsigned) HEAPSTART)))) {
- fprintf(stderr, "Bad free list in gc_malloc\n");
- abort(op);
- }
- # endif
- *opp = op->obj_link;
- op->obj_link = (struct obj *)0;
- } else {
- register struct hblk * h;
-
- if (!sufficient_hb(lw) && !dont_gc) {
- gcollect();
- }
- # ifdef VERBOSE
- printf("ralloc_comp calling allochblk(%x)\n",lw);
- # endif
- h = allochblk(lw);
- add_hblklist(h);
- op = (struct obj *) (h -> hb_body);
- }
- return(op);
- }
-
- /* Explicitly deallocate an object p */
- gc_free(p)
- struct obj *p;
- {
- register struct hblk *h;
- register int sz;
- register int i;
-
- h = HBLKPTR(p);
- sz = h -> hb_sz;
- if (sz < 0) {
- sz = -sz;
- if (sz > MAXAOBJSZ) {
- h -> hb_uninit = 1;
- del_hblklist(h);
- freehblk(h);
- } else {
- p -> obj_link = aobjfreelist[sz];
- aobjfreelist[sz] = p;
- }
- } else {
- /* Clear the object, other than link field */
- for (i = 1; i < sz; i++) {
- p -> obj_component[i] = 0;
- }
- if (sz > MAXOBJSZ) {
- p -> obj_link = 0;
- h -> hb_uninit = 0;
- del_hblklist(h);
- freehblk(h);
- } else {
- p -> obj_link = objfreelist[sz];
- objfreelist[sz] = p;
- }
- }
- /* Add it to mem_found to prevent anomalous heap expansion */
- /* in the event of repeated explicit frees of objects of */
- /* varying sizes. */
- mem_found += sz;
- }
-
-
- /*
- * Disable non-urgent signals
- */
- int holdsigs()
- {
- unsigned mask = 0xffffffff;
-
- mask &= ~(1<<(SIGSEGV-1));
- mask &= ~(1<<(SIGILL-1));
- mask &= ~(1<<(SIGBUS-1));
- mask &= ~(1<<(SIGIOT-1));
- mask &= ~(1<<(SIGEMT-1));
- mask &= ~(1<<(SIGTRAP-1));
- mask &= ~(1<<(SIGQUIT-1));
- return(sigsetmask(mask));
- }
-
- void gc_init()
- {
- heaplim = &end;
- hincr = HINCR;
- expand_hp(hincr);
- init_hblklist();
- }
-
- char * gc_realloc(p,i)
- struct obj * p ;
- int i ;
- {
- register struct hblk *h;
- register int sz;
- register char * temp = (char*) gc_malloc(i) ;
-
- h = HBLKPTR(p);
- sz = h -> hb_sz;
- if(sz < 0) sz = - sz ;
- if(sz < i) sz = i ;
- memcpy(temp,p,sz) ;
- gc_free(p) ;
- return temp ;
- }
-
-
-