3 #include "structdefs.h"
5 #include "SimpleHash.h"
7 #include "GenericHashtable.h"
9 #if defined(THREADS) || defined(DSTM) || defined(STM)
13 #include "workschedule.h"
14 extern struct QI * headqi;
15 extern struct QI * tailqi;
23 #include <DSTM/interface_recovery/dstm.h>
25 #include <DSTM/interface/dstm.h>
32 #include "delaycomp.h"
38 #define INITIALHEAPSIZE 256*1024*1024L
39 #define GCPOINT(x) ((INTPTR)((x)*0.99))
40 /* This define takes in how full the heap is initially and returns a new heap size to use */
41 #define HEAPSIZE(x,y) ((INTPTR)(x+y))*2
44 extern struct genhashtable * activetasks;
46 extern struct parameterwrapper * objectqueues[NUMCLASSES];
48 extern struct genhashtable * failedtasks;
49 extern struct taskparamdescriptor *currtpd;
50 extern struct ctable *forward;
51 extern struct ctable *reverse;
52 extern struct RuntimeHash *fdtoobject;
57 long garbagearray[MAXSTATS];
60 #if defined(THREADS) || defined(DSTM) || defined(STM)||defined(MLP)
62 struct listitem * list=NULL;
65 __thread struct listitem litem;
70 __thread SESEcommon* seseCommon;
73 //Need to check if pointers are transaction pointers
74 //this also catches the special flag value of 1 for local copies
76 #define ENQUEUE(orig, dst) \
77 if ((!(((unsigned int)orig)&0x1))) { \
78 if (orig>=curr_heapbase&&orig<curr_heaptop) { \
80 if (gc_createcopy(orig,©)) \
86 #define ENQUEUE(orig, dst) \
87 if (orig>=curr_heapbase&&orig<curr_heaptop) { \
89 if (gc_createcopy(orig,©)) \
93 #define SENQUEUE(orig, dst) \
96 if (gc_createcopy(orig,©)) \
100 #elif defined(FASTCHECK)
101 #define ENQUEUE(orig, dst) \
102 if (((unsigned int)orig)!=1) { \
104 if (gc_createcopy(orig,©)) \
108 #define ENQUEUE(orig, dst) \
109 if (orig>=curr_heapbase&&orig<curr_heaptop) { \
111 if (gc_createcopy(orig,©)) \
118 struct pointerblock {
119 void * ptrs[NUMPTRS];
120 struct pointerblock *next;
123 void * curr_heapbase=0;
124 void * curr_heapptr=0;
125 void * curr_heapgcpoint=0;
126 void * curr_heaptop=0;
128 void * to_heapbase=0;
134 struct pointerblock *head=NULL;
136 struct pointerblock *tail=NULL;
138 struct pointerblock *spare=NULL;
140 void enqueue(void *ptr) {
141 if (headindex==NUMPTRS) {
142 struct pointerblock * tmp;
146 } else tmp=malloc(sizeof(struct pointerblock));
151 head->ptrs[headindex++]=ptr;
155 if (tailindex==NUMPTRS) {
156 struct pointerblock *tmp=tail;
164 return tail->ptrs[tailindex++];
168 void fixobjlist(struct objlist * ptr) {
171 for(i=0;i<ptr->offset;i++) {
172 SENQUEUE(ptr->objs[i], ptr->objs[i]);
178 void fixtable(chashlistnode_t ** tc_table, chashlistnode_t **tc_list, cliststruct_t **cstr, unsigned int tc_size) {
179 unsigned int mask=(tc_size<<4)-1;
180 chashlistnode_t *node=calloc(tc_size, sizeof(chashlistnode_t));
181 chashlistnode_t *ptr=*tc_table;
182 chashlistnode_t *curr;
186 chashlistnode_t *newlist=NULL;
187 for(i=0;i<tc_size;i++) {
190 do { //Inner loop to go through linked lists
192 chashlistnode_t *tmp,*next;
194 if ((key=(void *)curr->key) == 0) { //Exit inner loop if there the first element is 0
195 break; //key = val =0 for element if not present within the hash table
198 if (curr->val>=curr_heapbase&&curr->val<curr_heaptop) {
199 SENQUEUE(curr->val, curr->val);
201 //rewrite transaction cache entry
202 void *vptr=curr->val;
203 int type=((int *)vptr)[0];
204 unsigned INTPTR *pointer=pointerarray[type];
206 //array of primitives - do nothing
207 struct ArrayObject *ao=(struct ArrayObject *) vptr;
208 SENQUEUE((void *)ao->___objlocation___, *((void **)&ao->___objlocation___));
209 } else if (((INTPTR)pointer)==1) {
211 struct ArrayObject *ao=(struct ArrayObject *) vptr;
212 int length=ao->___length___;
214 SENQUEUE((void *)ao->___objlocation___, *((void **)&ao->___objlocation___));
216 int lowindex=ao->lowindex;
217 int highindex=ao->highindex;
219 for(j=lowindex; j<=highindex; j++) {
220 unsigned int lockval;
221 GETLOCKVAL(lockval, ao, j);
222 if (lockval!=STMNONE) {
223 int lowi=(j<<INDEXSHIFT)/sizeof(void *);
224 int highi=lowi+(INDEXLENGTH/sizeof(void *));
225 for(i=lowi; i<highi;i++) {
227 for(i=0; i<length; i++) {
229 void *objptr=((void **)(((char *)&ao->___length___)+sizeof(int)))[i];
230 SENQUEUE(objptr, ((void **)(((char *)&ao->___length___)+sizeof(int)))[i]);
237 INTPTR size=pointer[0];
239 for(i=1; i<=size; i++) {
240 unsigned int offset=pointer[i];
241 void * objptr=*((void **)(((char *)vptr)+offset));
242 SENQUEUE(objptr, *((void **)(((char *)vptr)+offset)));
248 index = (((unsigned INTPTR)key) & mask) >>4;
252 // Insert into the new table
254 tmp->key = curr->key;
255 tmp->val = curr->val;
258 } else if (isfirst) {
259 chashlistnode_t *newnode;
260 if ((*cstr)->num<NUMCLIST) {
261 newnode=&(*cstr)->array[(*cstr)->num];
265 cliststruct_t *tcl=calloc(1,sizeof(cliststruct_t));
268 newnode=&tcl->array[0];
271 newnode->key = curr->key;
272 newnode->val = curr->val;
273 newnode->next = tmp->next;
274 newnode->lnext=newlist;
280 curr->next=tmp->next;
294 if ((head==tail)&&(tailindex==headindex))
300 struct pointerblock *taghead=NULL;
303 void enqueuetag(struct ___TagDescriptor___ *ptr) {
304 if (tagindex==NUMPTRS) {
305 struct pointerblock * tmp=malloc(sizeof(struct pointerblock));
310 taghead->ptrs[tagindex++]=ptr;
314 #if defined(STM)||defined(THREADS)||defined(MLP)
315 __thread char * memorybase=NULL;
316 __thread char * memorytop=NULL;
320 void collect(struct garbagelist * stackptr) {
321 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
323 pthread_mutex_lock(&gclistlock);
325 if ((listcount+1)==threadcount) {
326 break; /* Have all other threads stopped */
328 pthread_cond_wait(&gccond, &gclistlock);
332 ptrstack.prev=stackptr;
333 stackptr=(struct garbagelist *) &ptrstack;
334 #if defined(STMARRAY)&&!defined(DUALVIEW)
335 arraystack.prev=stackptr;
336 stackptr=(struct garbagelist *) &arraystack;
343 for(i=0;i<MAXSTATS;i++)
351 head=tail=malloc(sizeof(struct pointerblock));
357 taghead=malloc(sizeof(struct pointerblock));
364 fixtable(&c_table, &c_list, &c_structs, c_size);
367 fixobjlist(lockedobjs);
371 #if defined(STM)||defined(THREADS)||defined(MLP)
375 /* Check current stack */
376 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
378 struct listitem *listptr=list;
382 while(stackptr!=NULL) {
384 for(i=0; i<stackptr->size; i++) {
385 void * orig=stackptr->array[i];
386 ENQUEUE(orig, stackptr->array[i]);
388 stackptr=stackptr->next;
390 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
391 /* Go to next thread */
394 if (listptr==&litem) {
396 // update forward list & memory queue for the current SESE
397 updateForwardList(((SESEcommon*)listptr->seseCommon)->forwardList,FALSE);
398 updateMemoryQueue((SESEcommon*)(listptr->seseCommon));
400 listptr=listptr->next;
404 struct listitem *litem=pthread_getspecific(litemkey);
405 if (listptr==litem) {
406 listptr=listptr->next;
413 void * orig=listptr->locklist;
414 ENQUEUE(orig, listptr->locklist);
417 if ((*listptr->tc_table)!=NULL) {
418 fixtable(listptr->tc_table, listptr->tc_list, listptr->tc_structs, listptr->tc_size);
419 fixobjlist(listptr->objlist);
421 fixobjlist(listptr->lockedlist);
425 #if defined(STM)||defined(THREADS)||defined(MLP)
426 *(listptr->base)=NULL;
429 // update forward list & memory queue for all running SESEs.
430 updateForwardList(((SESEcommon*)listptr->seseCommon)->forwardList,FALSE);
431 updateMemoryQueue((SESEcommon*)(listptr->seseCommon));
433 stackptr=listptr->stackptr;
434 listptr=listptr->next;
442 ENQUEUE(___fcrevert___, ___fcrevert___);
447 /* Update objectsets */
449 for(i=0; i<NUMCLASSES; i++) {
450 #if !defined(MULTICORE)
451 struct parameterwrapper * p=objectqueues[i];
453 struct ObjectHash * set=p->objectset;
454 struct ObjectNode * ptr=set->listhead;
456 void *orig=(void *)ptr->key;
457 ENQUEUE(orig, *((void **)(&ptr->key)));
460 ObjectHashrehash(set); /* Rehash the table */
469 struct cnode * ptr=forward->listhead;
471 void * orig=(void *)ptr->key;
472 ENQUEUE(orig, *((void **)(&ptr->key)));
475 crehash(forward); /* Rehash the table */
479 struct cnode * ptr=reverse->listhead;
481 void *orig=(void *)ptr->val;
482 ENQUEUE(orig, *((void**)(&ptr->val)));
489 struct RuntimeNode * ptr=fdtoobject->listhead;
491 void *orig=(void *)ptr->data;
492 ENQUEUE(orig, *((void**)(&ptr->data)));
498 /* Update current task descriptor */
500 for(i=0; i<currtpd->numParameters; i++) {
501 void *orig=currtpd->parameterArray[i];
502 ENQUEUE(orig, currtpd->parameterArray[i]);
507 /* Update active tasks */
509 struct genpointerlist * ptr=activetasks->list;
511 struct taskparamdescriptor *tpd=ptr->src;
513 for(i=0; i<tpd->numParameters; i++) {
514 void * orig=tpd->parameterArray[i];
515 ENQUEUE(orig, tpd->parameterArray[i]);
519 genrehash(activetasks);
522 /* Update failed tasks */
524 struct genpointerlist * ptr=failedtasks->list;
526 struct taskparamdescriptor *tpd=ptr->src;
528 for(i=0; i<tpd->numParameters; i++) {
529 void * orig=tpd->parameterArray[i];
530 ENQUEUE(orig, tpd->parameterArray[i]);
534 genrehash(failedtasks);
540 // goes over ready-to-run SESEs
541 struct QI * qitem = headqi;
543 SESEcommon* common=(SESEcommon*)qitem->value;
544 if(common==seseCommon){
545 // skip the current running SESE
549 struct garbagelist * gl=(struct garbagelist *)&(((SESEcommon*)(qitem->value))[1]);
550 struct garbagelist * glroot=gl;
551 // update its ascendant SESEs
552 updateAscendantSESE(gl);
556 for(i=0; i<gl->size; i++) {
557 void * orig=gl->array[i];
558 ENQUEUE(orig, gl->array[i]);
569 void * ptr=dequeue();
571 int type=((int *)cpy)[0];
572 unsigned INTPTR * pointer;
576 /* Nothing is inside */
581 pointer=pointerarray[type];
583 /* Array of primitives */
585 #if defined(DSTM)||defined(FASTCHECK)
586 struct ArrayObject *ao=(struct ArrayObject *) ptr;
587 struct ArrayObject *ao_cpy=(struct ArrayObject *) cpy;
588 ENQUEUE((void *)ao->___nextobject___, *((void **)&ao_cpy->___nextobject___));
589 ENQUEUE((void *)ao->___localcopy___, *((void **)&ao_cpy->___localcopy___));
592 struct ArrayObject *ao=(struct ArrayObject *) ptr;
593 struct ArrayObject *ao_cpy=(struct ArrayObject *) cpy;
594 SENQUEUE((void *)ao->___objlocation___, *((void **)&ao_cpy->___objlocation___));
596 } else if (((INTPTR)pointer)==1) {
597 /* Array of pointers */
598 struct ArrayObject *ao=(struct ArrayObject *) ptr;
599 struct ArrayObject *ao_cpy=(struct ArrayObject *) cpy;
600 #if (defined(DSTM)||defined(FASTCHECK))
601 ENQUEUE((void *)ao->___nextobject___, *((void **)&ao_cpy->___nextobject___));
602 ENQUEUE((void *)ao->___localcopy___, *((void **)&ao_cpy->___localcopy___));
605 SENQUEUE((void *)ao->___objlocation___, *((void **)&ao_cpy->___objlocation___));
607 int length=ao->___length___;
609 for(i=0; i<length; i++) {
610 void *objptr=((void **)(((char *)&ao->___length___)+sizeof(int)))[i];
611 ENQUEUE(objptr, ((void **)(((char *)&ao_cpy->___length___)+sizeof(int)))[i]);
614 INTPTR size=pointer[0];
616 for(i=1; i<=size; i++) {
617 unsigned int offset=pointer[i];
618 void * objptr=*((void **)(((char *)ptr)+offset));
619 ENQUEUE(objptr, *((void **)(((char *)cpy)+offset)));
629 //rehash memory queues of current running SESEs
630 struct listitem *listptr=list;
631 while(listptr!=NULL){
632 rehashMemoryQueue((SESEcommon*)(listptr->seseCommon));
633 listptr=listptr->next;
638 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
640 pthread_mutex_unlock(&gclistlock);
645 /* Fix up the references from tags. This can't be done earlier,
646 because we don't want tags to keep objects alive */
648 while(taghead!=NULL) {
650 struct pointerblock *tmp=taghead->next;
651 for(i=0; i<tagindex; i++) {
652 struct ___TagDescriptor___ *tagd=taghead->ptrs[i];
653 struct ___Object___ *obj=tagd->flagptr;
654 struct ___TagDescriptor___ *copy=((struct ___TagDescriptor___**)tagd)[1];
656 /* Zero object case */
657 } else if (obj->type==-1) {
658 /* Single object case */
659 copy->flagptr=((struct ___Object___**)obj)[1];
660 } else if (obj->type==OBJECTARRAYTYPE) {
662 struct ArrayObject *ao=(struct ArrayObject *) obj;
666 struct ArrayObject *aonew;
668 /* Count live objects */
669 for(j=0; j<ao->___cachedCode___; j++) {
670 struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, j);
675 livecount=((livecount-1)/OBJECTARRAYINTERVAL+1)*OBJECTARRAYINTERVAL;
676 aonew=(struct ArrayObject *) tomalloc(sizeof(struct ArrayObject)+sizeof(struct ___Object___*)*livecount);
677 memcpy(aonew, ao, sizeof(struct ArrayObject));
678 aonew->type=OBJECTARRAYTYPE;
679 aonew->___length___=livecount;
681 for(j=0; j<ao->___cachedCode___; j++) {
682 struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, j);
683 if (tobj->type==-1) {
684 struct ___Object___ * tobjcpy=((struct ___Object___**)tobj)[1];
685 ARRAYSET(aonew, struct ___Object___*, k++,tobjcpy);
688 aonew->___cachedCode___=k;
689 for(; k<livecount; k++) {
690 ARRAYSET(aonew, struct ___Object___*, k, NULL);
693 /* No object live anymore */
704 void * tomalloc(int size) {
705 void * ptr=to_heapptr;
712 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
713 void checkcollect(void * ptr) {
714 stopforgc((struct garbagelist *)ptr);
719 void checkcollect2(void * ptr) {
720 int ptrarray[]={1, (int)ptr, (int) revertlist};
721 stopforgc((struct garbagelist *)ptrarray);
723 revertlist=(struct ___Object___*)ptrarray[2];
727 void stopforgc(struct garbagelist * ptr) {
729 //just append us to the list
731 ptr=(struct garbagelist *) &ptrstack;
732 #if defined(STMARRAY)&&!defined(DUALVIEW)
734 ptr=(struct garbagelist *) &arraystack;
740 litem.locklist=pthread_getspecific(threadlocks);
742 #if defined(STM)||defined(THREADS)||defined(MLP)
743 litem.base=&memorybase;
746 litem.tc_size=c_size;
747 litem.tc_table=&c_table;
748 litem.tc_list=&c_list;
749 litem.tc_structs=&c_structs;
750 litem.objlist=newobjs;
752 litem.lockedlist=lockedobjs;
757 struct listitem *litem=pthread_getspecific(litemkey);
760 litem->locklist=pthread_getspecific(threadlocks);
763 pthread_mutex_lock(&gclistlock);
765 if ((listcount+1)==threadcount) {
766 //only do wakeup if we are ready to GC
767 pthread_cond_signal(&gccond);
769 pthread_mutex_unlock(&gclistlock);
772 void restartaftergc() {
774 pthread_mutex_lock(&gclock); // Wait for GC
775 pthread_mutex_unlock(&gclock);
777 pthread_mutex_lock(&gclistlock);
779 pthread_mutex_unlock(&gclistlock);
783 #if defined(STM)||defined(THREADS)||defined(MLP)
784 #define MEMORYBLOCK 65536
785 void * helper(struct garbagelist *, int);
786 void * mygcmalloc(struct garbagelist * stackptr, int size) {
789 if (memorybase==NULL||size>(memorytop-memorybase)) {
790 int toallocate=(size>MEMORYBLOCK)?size:MEMORYBLOCK;
791 memorybase=helper(stackptr, toallocate);
792 bzero(memorybase, toallocate);
793 memorytop=memorybase+toallocate;
795 char *retvalue=memorybase;
800 void * helper(struct garbagelist * stackptr, int size) {
802 void * mygcmalloc(struct garbagelist * stackptr, int size) {
805 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
806 while (pthread_mutex_trylock(&gclock)!=0) {
815 if (curr_heapptr>curr_heapgcpoint||curr_heapptr<curr_heapbase) {
816 if (curr_heapbase==0) {
817 /* Need to allocate base heap */
818 curr_heapbase=malloc(INITIALHEAPSIZE);
819 if (curr_heapbase==NULL) {
820 printf("malloc failed. Garbage colletcor couldn't get enough memory. Try changing heap size.\n");
823 #if defined(STM)||defined(THREADS)||defined(MLP)
825 bzero(curr_heapbase, INITIALHEAPSIZE);
827 curr_heaptop=curr_heapbase+INITIALHEAPSIZE;
828 curr_heapgcpoint=((char *) curr_heapbase)+GCPOINT(INITIALHEAPSIZE);
829 curr_heapptr=curr_heapbase+size;
831 to_heapbase=malloc(INITIALHEAPSIZE);
832 if (to_heapbase==NULL) {
833 printf("malloc failed. Garbage collector couldn't get enough memory. Try changing heap size.\n");
837 to_heaptop=to_heapbase+INITIALHEAPSIZE;
838 to_heapptr=to_heapbase;
840 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
841 pthread_mutex_unlock(&gclock);
846 /* Grow the to heap if necessary */
848 INTPTR curr_heapsize=curr_heaptop-curr_heapbase;
849 INTPTR to_heapsize=to_heaptop-to_heapbase;
850 INTPTR last_heapsize=0;
852 last_heapsize=HEAPSIZE(lastgcsize, size);
853 if ((last_heapsize&7)!=0)
854 last_heapsize+=(8-(last_heapsize%8));
856 if (curr_heapsize>last_heapsize)
857 last_heapsize=curr_heapsize;
858 if (last_heapsize>to_heapsize) {
860 to_heapbase=malloc(last_heapsize);
861 if (to_heapbase==NULL) {
862 printf("Error Allocating enough memory\n");
865 to_heaptop=to_heapbase+last_heapsize;
866 to_heapptr=to_heapbase;
870 /* Do our collection */
873 /* Update stat on previous gc size */
874 lastgcsize=(to_heapptr-to_heapbase)+size;
877 printf("Garbage collected: Old bytes: %u\n", curr_heapptr-curr_heapbase);
878 printf("New space: %u\n", to_heapptr-to_heapbase);
879 printf("Total space: %u\n", to_heaptop-to_heapbase);
882 for(i=0;i<MAXSTATS;i++) {
883 if (garbagearray[i]!=0)
884 printf("Type=%d Size=%u\n", i, garbagearray[i]);
888 /* Flip to/curr heaps */
890 void * tmp=to_heapbase;
891 to_heapbase=curr_heapbase;
895 to_heaptop=curr_heaptop;
899 curr_heapptr=to_heapptr+size;
900 curr_heapgcpoint=((char *) curr_heapbase)+GCPOINT(curr_heaptop-curr_heapbase);
901 to_heapptr=to_heapbase;
903 /* Not enough room :(, redo gc */
904 if (curr_heapptr>curr_heapgcpoint) {
905 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
906 pthread_mutex_unlock(&gclock);
908 return mygcmalloc(stackptr, size);
911 bzero(tmp, curr_heaptop-tmp);
912 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
913 pthread_mutex_unlock(&gclock);
918 #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
919 pthread_mutex_unlock(&gclock);
925 int gc_createcopy(void * orig, void ** copy_ptr) {
930 int type=((int *)orig)[0];
932 *copy_ptr=((void **)orig)[1];
935 if (type<NUMCLASSES) {
936 /* We have a normal object */
938 int size=classsize[type]+sizeof(objheader_t);
939 void *newobj=tomalloc(size);
940 memcpy(newobj,((char *) orig)-sizeof(objheader_t), size);
941 newobj=((char *)newobj)+sizeof(objheader_t);
943 int size=classsize[type];
944 void *newobj=tomalloc(size);
945 memcpy(newobj, orig, size);
948 garbagearray[type]+=size;
951 ((void **)orig)[1]=newobj;
955 /* We have an array */
956 struct ArrayObject *ao=(struct ArrayObject *)orig;
957 int elementsize=classsize[type];
958 int length=ao->___length___;
961 int basesize=length*elementsize;
962 basesize=(basesize+LOWMASK)&HIGHMASK;
963 int versionspace=sizeof(int)*2*(basesize>>INDEXSHIFT);
964 int size=sizeof(struct ArrayObject)+basesize+sizeof(objheader_t)+versionspace;
965 void *newobj=tomalloc(size);
966 memcpy(newobj, ((char*)orig)-sizeof(objheader_t)-versionspace, size);
967 newobj=((char *)newobj)+sizeof(objheader_t)+versionspace;
969 int size=sizeof(struct ArrayObject)+length*elementsize+sizeof(objheader_t);
970 void *newobj=tomalloc(size);
971 memcpy(newobj, ((char*)orig)-sizeof(objheader_t), size);
972 newobj=((char *)newobj)+sizeof(objheader_t);
975 int size=sizeof(struct ArrayObject)+length*elementsize;
976 void *newobj=tomalloc(size);
977 memcpy(newobj, orig, size);
980 garbagearray[type]+=size;
983 ((void **)orig)[1]=newobj;
991 updateForwardList(struct Queue *forwardList, int prevUpdate){
993 struct QueueItem * fqItem=getHead(forwardList);
995 struct garbagelist * gl=(struct garbagelist *)&(((SESEcommon*)(fqItem->objectptr))[1]);
996 if(prevUpdate==TRUE){
997 updateAscendantSESE(gl);
1002 for(i=0; i<gl->size; i++) {
1003 void * orig=gl->array[i];
1004 ENQUEUE(orig, gl->array[i]);
1008 // iterate forwarding list of seseRec
1009 SESEcommon *common=(SESEcommon*)fqItem->objectptr;
1010 struct Queue* fList=common->forwardList;
1011 updateForwardList(fList,prevUpdate);
1012 fqItem=getNextQueueItem(fqItem);
1017 updateMemoryQueue(SESEcommon_p seseParent){
1018 // update memory queue
1020 for(i=0; i<seseParent->numMemoryQueue; i++){
1021 MemoryQueue *memoryQueue=seseParent->memoryQueueArray[i];
1022 MemoryQueueItem *memoryItem=memoryQueue->head;
1023 while(memoryItem!=NULL){
1024 if(memoryItem->type==HASHTABLE){
1025 Hashtable *ht=(Hashtable*)memoryItem;
1026 for(binidx=0; binidx<NUMBINS; binidx++){
1027 BinElement *bin=ht->array[binidx];
1028 BinItem *binItem=bin->head;
1029 while(binItem!=NULL){
1030 if(binItem->type==READBIN){
1031 ReadBinItem* readBinItem=(ReadBinItem*)binItem;
1033 for(ridx=0; ridx<readBinItem->index; ridx++){
1034 REntry *rentry=readBinItem->array[ridx];
1035 struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(rentry->seseRec))[1]);
1036 updateAscendantSESE(gl);
1039 for(i=0; i<gl->size; i++) {
1040 void * orig=gl->array[i];
1041 ENQUEUE(orig, gl->array[i]);
1047 REntry *rentry=((WriteBinItem*)binItem)->val;
1048 struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(rentry->seseRec))[1]);
1049 updateAscendantSESE(gl);
1052 for(i=0; i<gl->size; i++) {
1053 void * orig=gl->array[i];
1054 ENQUEUE(orig, gl->array[i]);
1059 binItem=binItem->next;
1062 }else if(memoryItem->type==VECTOR){
1063 Vector *vt=(Vector*)memoryItem;
1065 for(idx=0; idx<vt->index; idx++){
1066 REntry *rentry=vt->array[idx];
1067 struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(rentry->seseRec))[1]);
1068 updateAscendantSESE(gl);
1071 for(i=0; i<gl->size; i++) {
1072 void * orig=gl->array[i];
1073 ENQUEUE(orig, gl->array[i]);
1078 }else if(memoryItem->type==SINGLEITEM){
1079 SCC *scc=(SCC*)memoryItem;
1080 REntry *rentry=scc->val;
1081 struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(rentry->seseRec))[1]);
1082 updateAscendantSESE(gl);
1085 for(i=0; i<gl->size; i++) {
1086 void * orig=gl->array[i];
1087 ENQUEUE(orig, gl->array[i]);
1092 memoryItem=memoryItem->next;
1097 updateAscendantSESE(struct garbagelist *gl){
1098 int offsetsize=*((int*)((void*)gl-sizeof(int)));
1099 int prevSESECount=*((int*)((void*)gl+offsetsize));
1100 INTPTR tailaddr=(INTPTR)((void*)gl+offsetsize+sizeof(int));
1102 for(prevIdx=0; prevIdx<prevSESECount; prevIdx++){
1103 SESEcommon* prevSESE=(SESEcommon*)*((INTPTR*)(tailaddr+sizeof(void*)*prevIdx));
1105 struct garbagelist * prevgl=(struct garbagelist *)&(((SESEcommon*)(prevSESE))[1]);
1106 while(prevgl!=NULL) {
1108 for(i=0; i<prevgl->size; i++) {
1109 void * orig=prevgl->array[i];
1110 ENQUEUE(orig, prevgl->array[i]);
1112 prevgl=prevgl->next;
1119 int within(void *ptr){ //debug function
1120 if(ptr>curr_heapptr || ptr<curr_heapbase){
1121 __asm__ __volatile__ ("int $3"); // breakpoint