3 #include "multicoreruntime.h"
4 #include "runtime_arch.h"
5 #include "GenericHashtable.h"
7 // data structures for task invocation
8 struct genhashtable * activetasks;
9 struct taskparamdescriptor * currtpd;
11 // specific functions used inside critical sections
12 void enqueueObject_I(void * ptr,
13 struct parameterwrapper ** queues,
15 int enqueuetasks_I(struct parameterwrapper *parameter,
16 struct parameterwrapper *prevptr,
17 struct ___Object___ *ptr,
21 inline __attribute__((always_inline))
22 void initruntimedata() {
24 // initialize the arrays
25 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
26 // startup core to initialize corestatus[]
27 for(i = 0; i < NUMCORES; ++i) {
30 numreceiveobjs[i] = 0;
32 // initialize the profile data arrays
38 gcnumreceiveobjs[i] = 0;
40 gcrequiredmems[i] = 0;
42 gcfilledblocks[i] = 0;
44 } // for(i = 0; i < NUMCORES; ++i)
54 self_numreceiveobjs = 0;
56 for(i = 0; i < BAMBOO_MSG_BUF_LENGTH; ++i) {
61 msglength = BAMBOO_MSG_BUF_LENGTH;
62 for(i = 0; i < BAMBOO_OUT_BUF_LENGTH; ++i) {
72 bamboo_cur_msp = NULL;
74 totransobjqueue = createQueue();
79 gcphase = FINISHPHASE;
81 gcself_numsendobjs = 0;
82 gcself_numreceiveobjs = 0;
84 gcpointertbl = allocateRuntimeHash(20);
96 gcsbstarttbl = BAMBOO_BASE_VA;
98 // create the lock table, lockresult table and obj queue
101 (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*20);
102 /* Set allocation blocks*/
103 locktable.listhead=NULL;
104 locktable.listtail=NULL;
106 locktable.numelements = 0;
111 lockRedirectTbl = allocateRuntimeHash(20);
112 objRedirectLockTbl = allocateRuntimeHash(20);
117 objqueue.head = NULL;
118 objqueue.tail = NULL;
124 //isInterrupt = true;
127 taskInfoOverflow = false;
128 /*interruptInfoIndex = 0;
129 interruptInfoOverflow = false;*/
133 inline __attribute__((always_inline))
134 void disruntimedata() {
136 freeRuntimeHash(gcpointertbl);
138 freeRuntimeHash(lockRedirectTbl);
139 freeRuntimeHash(objRedirectLockTbl);
140 RUNFREE(locktable.bucket);
142 genfreehashtable(activetasks);
143 if(currtpd != NULL) {
144 RUNFREE(currtpd->parameterArray);
150 inline __attribute__((always_inline))
151 bool checkObjQueue() {
153 struct transObjInfo * objInfo = NULL;
157 #ifdef ACCURATEPROFILE
158 bool isChecking = false;
159 if(!isEmpty(&objqueue)) {
160 profileTaskStart("objqueue checking");
162 } // if(!isEmpty(&objqueue))
166 while(!isEmpty(&objqueue)) {
168 BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE();
170 BAMBOO_DEBUGPRINT(0xf001);
173 //isInterrupt = false;
176 BAMBOO_DEBUGPRINT(0xeee1);
179 objInfo = (struct transObjInfo *)getItem(&objqueue);
180 obj = objInfo->objptr;
182 BAMBOO_DEBUGPRINT_REG((int)obj);
184 // grab lock and flush the obj
188 BAMBOO_WAITING_FOR_LOCK();
189 } // while(!lockflag)
192 BAMBOO_DEBUGPRINT_REG(grount);
207 BAMBOO_CACHE_FLUSH_RANGE((int)obj,sizeof(int));
208 BAMBOO_CACHE_FLUSH_RANGE((int)obj,
209 classsize[((struct ___Object___ *)obj)->type]);
211 // enqueue the object
212 for(k = 0; k < objInfo->length; ++k) {
213 int taskindex = objInfo->queues[2 * k];
214 int paramindex = objInfo->queues[2 * k + 1];
215 struct parameterwrapper ** queues =
216 &(paramqueues[BAMBOO_NUM_OF_CORE][taskindex][paramindex]);
218 BAMBOO_DEBUGPRINT_REG(taskindex);
219 BAMBOO_DEBUGPRINT_REG(paramindex);
220 struct ___Object___ * tmpptr = (struct ___Object___ *)obj;
221 tprintf("Process %x(%d): receive obj %x(%lld), ptrflag %x\n",
222 BAMBOO_NUM_OF_CORE, BAMBOO_NUM_OF_CORE, (int)obj,
223 (long)obj, tmpptr->flag);
225 enqueueObject_I(obj, queues, 1);
227 BAMBOO_DEBUGPRINT_REG(hashsize(activetasks));
229 } // for(k = 0; k < objInfo->length; ++k)
230 releasewritelock_I(obj);
231 RUNFREE(objInfo->queues);
235 // put it at the end of the queue if no update version in the queue
236 struct QueueItem * qitem = getHead(&objqueue);
237 struct QueueItem * prev = NULL;
238 while(qitem != NULL) {
239 struct transObjInfo * tmpinfo =
240 (struct transObjInfo *)(qitem->objectptr);
241 if(tmpinfo->objptr == obj) {
242 // the same object in the queue, which should be enqueued
243 // recently. Current one is outdate, do not re-enqueue it
244 RUNFREE(objInfo->queues);
249 } // if(tmpinfo->objptr == obj)
250 qitem = getNextQueueItem(prev);
251 } // while(qitem != NULL)
252 // try to execute active tasks already enqueued first
253 addNewItem_I(&objqueue, objInfo);
255 //isInterrupt = true;
258 BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE();
260 BAMBOO_DEBUGPRINT(0xf000);
264 BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE();
266 BAMBOO_DEBUGPRINT(0xf000);
268 } // while(!isEmpty(&objqueue))
271 #ifdef ACCURATEPROFILE
279 BAMBOO_DEBUGPRINT(0xee02);
284 inline __attribute__((always_inline))
285 void checkCoreStatus() {
286 bool allStall = false;
290 (waitconfirm && (numconfirm == 0))) {
292 BAMBOO_DEBUGPRINT(0xee04);
293 BAMBOO_DEBUGPRINT_REG(waitconfirm);
295 BAMBOO_START_CRITICAL_SECTION_STATUS();
297 BAMBOO_DEBUGPRINT(0xf001);
299 corestatus[BAMBOO_NUM_OF_CORE] = 0;
300 numsendobjs[BAMBOO_NUM_OF_CORE] = self_numsendobjs;
301 numreceiveobjs[BAMBOO_NUM_OF_CORE] = self_numreceiveobjs;
302 // check the status of all cores
305 BAMBOO_DEBUGPRINT_REG(NUMCORES);
307 for(i = 0; i < NUMCORES; ++i) {
309 BAMBOO_DEBUGPRINT(0xe000 + corestatus[i]);
311 if(corestatus[i] != 0) {
315 } // for(i = 0; i < NUMCORES; ++i)
317 // check if the sum of send objs and receive obj are the same
318 // yes->check if the info is the latest; no->go on executing
320 for(i = 0; i < NUMCORES; ++i) {
321 sumsendobj += numsendobjs[i];
323 BAMBOO_DEBUGPRINT(0xf000 + numsendobjs[i]);
325 } // for(i = 0; i < NUMCORES; ++i)
326 for(i = 0; i < NUMCORES; ++i) {
327 sumsendobj -= numreceiveobjs[i];
329 BAMBOO_DEBUGPRINT(0xf000 + numreceiveobjs[i]);
331 } // for(i = 0; i < NUMCORES; ++i)
332 if(0 == sumsendobj) {
334 // the first time found all cores stall
335 // send out status confirm msg to all other cores
336 // reset the corestatus array too
338 BAMBOO_DEBUGPRINT(0xee05);
340 corestatus[BAMBOO_NUM_OF_CORE] = 1;
341 for(i = 1; i < NUMCORES; ++i) {
343 // send status confirm msg to core i
344 send_msg_1(i, STATUSCONFIRM);
345 } // for(i = 1; i < NUMCORES; ++i)
347 numconfirm = NUMCORES - 1;
349 // all the core status info are the latest
350 // terminate; for profiling mode, send request to all
351 // other cores to pour out profiling data
353 BAMBOO_DEBUGPRINT(0xee06);
357 totalexetime = BAMBOO_GET_EXE_TIME();
359 BAMBOO_DEBUGPRINT(BAMBOO_GET_EXE_TIME());
360 BAMBOO_DEBUGPRINT_REG(total_num_t6); // TODO for test
361 BAMBOO_DEBUGPRINT(0xbbbbbbbb);
363 // profile mode, send msgs to other cores to request pouring
364 // out progiling data
366 BAMBOO_CLOSE_CRITICAL_SECTION_STATUS();
368 BAMBOO_DEBUGPRINT(0xf000);
370 for(i = 1; i < NUMCORES; ++i) {
371 // send profile request msg to core i
372 send_msg_2(i, PROFILEOUTPUT, totalexetime);
373 } // for(i = 1; i < NUMCORES; ++i)
374 // pour profiling data on startup core
377 BAMBOO_START_CRITICAL_SECTION_STATUS();
379 BAMBOO_DEBUGPRINT(0xf001);
381 profilestatus[BAMBOO_NUM_OF_CORE] = 0;
382 // check the status of all cores
385 BAMBOO_DEBUGPRINT_REG(NUMCORES);
387 for(i = 0; i < NUMCORES; ++i) {
389 BAMBOO_DEBUGPRINT(0xe000 + profilestatus[i]);
391 if(profilestatus[i] != 0) {
395 } // for(i = 0; i < NUMCORES; ++i)
398 BAMBOO_CLOSE_CRITICAL_SECTION_STATUS();
400 BAMBOO_DEBUGPRINT(0xf000);
410 terminate(); // All done.
411 } // if(!waitconfirm)
413 // still some objects on the fly on the network
414 // reset the waitconfirm and numconfirm
416 BAMBOO_DEBUGPRINT(0xee07);
420 } // if(0 == sumsendobj)
422 // not all cores are stall, keep on waiting
424 BAMBOO_DEBUGPRINT(0xee08);
429 BAMBOO_CLOSE_CRITICAL_SECTION_STATUS();
431 BAMBOO_DEBUGPRINT(0xf000);
433 } // if((!waitconfirm) ||
436 // main function for each core
437 inline void run(void * arg) {
441 bool sendStall = false;
443 bool tocontinue = false;
445 corenum = BAMBOO_GET_NUM_OF_CORE();
447 BAMBOO_DEBUGPRINT(0xeeee);
448 BAMBOO_DEBUGPRINT_REG(corenum);
449 BAMBOO_DEBUGPRINT(STARTUPCORE);
452 // initialize runtime data structures
455 // other architecture related initialization
459 initializeexithandler();
461 // main process of the execution module
462 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
463 // non-executing cores, only processing communications
466 BAMBOO_DEBUGPRINT(0xee01);
467 BAMBOO_DEBUGPRINT_REG(taskInfoIndex);
468 BAMBOO_DEBUGPRINT_REG(taskInfoOverflow);
469 profileTaskStart("msg handling");
473 //isInterrupt = false;
477 /* Create queue of active tasks */
479 genallocatehashtable((unsigned int(*) (void *)) &hashCodetpd,
480 (int(*) (void *,void *)) &comparetpd);
482 /* Process task information */
485 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
486 /* Create startup object */
487 createstartupobject(argc, argv);
491 BAMBOO_DEBUGPRINT(0xee00);
496 // check if need to do GC
500 // check if there are new active tasks can be executed
507 while(receiveObject() != -1) {
512 BAMBOO_DEBUGPRINT(0xee01);
515 // check if there are some pending objects,
516 // if yes, enqueue them and executetasks again
517 tocontinue = checkObjQueue();
521 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
524 BAMBOO_DEBUGPRINT(0xee03);
532 BAMBOO_DEBUGPRINT(0xee09);
538 // wait for some time
541 BAMBOO_DEBUGPRINT(0xee0a);
547 // send StallMsg to startup core
549 BAMBOO_DEBUGPRINT(0xee0b);
552 send_msg_4(STARTUPCORE, TRANSTALL, BAMBOO_NUM_OF_CORE,
553 self_numsendobjs, self_numreceiveobjs);
565 BAMBOO_DEBUGPRINT(0xee0c);
568 } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE)
571 } // if(BAMBOO_NUM_OF_CORE > NUMCORES - 1)
575 struct ___createstartupobject____I_locals {
578 struct ___StartupObject___ * ___startupobject___;
579 struct ArrayObject * ___stringarray___;
580 }; // struct ___createstartupobject____I_locals
582 void createstartupobject(int argc,
586 /* Allocate startup object */
588 struct ___createstartupobject____I_locals ___locals___={2, NULL, NULL, NULL};
589 struct ___StartupObject___ *startupobject=
590 (struct ___StartupObject___*) allocate_new(&___locals___, STARTUPTYPE);
591 ___locals___.___startupobject___ = startupobject;
592 struct ArrayObject * stringarray=
593 allocate_newarray(&___locals___, STRINGARRAYTYPE, argc-1);
594 ___locals___.___stringarray___ = stringarray;
596 struct ___StartupObject___ *startupobject=
597 (struct ___StartupObject___*) allocate_new(STARTUPTYPE);
598 struct ArrayObject * stringarray=
599 allocate_newarray(STRINGARRAYTYPE, argc-1);
601 /* Build array of strings */
602 startupobject->___parameters___=stringarray;
603 for(i=1; i<argc; i++) {
604 int length=strlen(argv[i]);
606 struct ___String___ *newstring=NewString(&___locals___, argv[i],length);
608 struct ___String___ *newstring=NewString(argv[i],length);
610 ((void **)(((char *)&stringarray->___length___)+sizeof(int)))[i-1]=
614 startupobject->version = 0;
615 startupobject->lock = NULL;
617 /* Set initialized flag for startup object */
618 flagorandinit(startupobject,1,0xFFFFFFFF);
619 enqueueObject(startupobject, NULL, 0);
621 BAMBOO_CACHE_FLUSH_ALL();
625 int hashCodetpd(struct taskparamdescriptor *ftd) {
626 int hash=(int)ftd->task;
628 for(i=0; i<ftd->numParameters; i++) {
629 hash^=(int)ftd->parameterArray[i];
634 int comparetpd(struct taskparamdescriptor *ftd1,
635 struct taskparamdescriptor *ftd2) {
637 if (ftd1->task!=ftd2->task)
639 for(i=0; i<ftd1->numParameters; i++)
640 if(ftd1->parameterArray[i]!=ftd2->parameterArray[i])
645 /* This function sets a tag. */
647 void tagset(void *ptr,
648 struct ___Object___ * obj,
649 struct ___TagDescriptor___ * tagd) {
651 void tagset(struct ___Object___ * obj,
652 struct ___TagDescriptor___ * tagd) {
654 struct ArrayObject * ao=NULL;
655 struct ___Object___ * tagptr=obj->___tags___;
657 obj->___tags___=(struct ___Object___ *)tagd;
659 /* Have to check if it is already set */
660 if (tagptr->type==TAGTYPE) {
661 struct ___TagDescriptor___ * td=(struct ___TagDescriptor___ *) tagptr;
666 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
667 struct ArrayObject * ao=
668 allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL);
669 obj=(struct ___Object___ *)ptrarray[2];
670 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
671 td=(struct ___TagDescriptor___ *) obj->___tags___;
673 ao=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL);
676 ARRAYSET(ao, struct ___TagDescriptor___ *, 0, td);
677 ARRAYSET(ao, struct ___TagDescriptor___ *, 1, tagd);
678 obj->___tags___=(struct ___Object___ *) ao;
679 ao->___cachedCode___=2;
683 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
684 for(i=0; i<ao->___cachedCode___; i++) {
685 struct ___TagDescriptor___ * td=
686 ARRAYGET(ao, struct ___TagDescriptor___*, i);
691 if (ao->___cachedCode___<ao->___length___) {
692 ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, tagd);
693 ao->___cachedCode___++;
696 int ptrarray[]={2,(int) ptr, (int) obj, (int) tagd};
697 struct ArrayObject * aonew=
698 allocate_newarray(&ptrarray,TAGARRAYTYPE,
699 TAGARRAYINTERVAL+ao->___length___);
700 obj=(struct ___Object___ *)ptrarray[2];
701 tagd=(struct ___TagDescriptor___ *) ptrarray[3];
702 ao=(struct ArrayObject *)obj->___tags___;
704 struct ArrayObject * aonew=
705 allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
708 aonew->___cachedCode___=ao->___length___+1;
709 for(i=0; i<ao->___length___; i++) {
710 ARRAYSET(aonew, struct ___TagDescriptor___*, i,
711 ARRAYGET(ao, struct ___TagDescriptor___*, i));
713 ARRAYSET(aonew, struct ___TagDescriptor___ *, ao->___length___, tagd);
719 struct ___Object___ * tagset=tagd->flagptr;
722 } else if (tagset->type!=OBJECTARRAYTYPE) {
724 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
725 struct ArrayObject * ao=
726 allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
727 obj=(struct ___Object___ *)ptrarray[2];
728 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
730 struct ArrayObject * ao=
731 allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
733 ARRAYSET(ao, struct ___Object___ *, 0, tagd->flagptr);
734 ARRAYSET(ao, struct ___Object___ *, 1, obj);
735 ao->___cachedCode___=2;
736 tagd->flagptr=(struct ___Object___ *)ao;
738 struct ArrayObject *ao=(struct ArrayObject *) tagset;
739 if (ao->___cachedCode___<ao->___length___) {
740 ARRAYSET(ao, struct ___Object___*, ao->___cachedCode___++, obj);
744 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
745 struct ArrayObject * aonew=
746 allocate_newarray(&ptrarray,OBJECTARRAYTYPE,
747 OBJECTARRAYINTERVAL+ao->___length___);
748 obj=(struct ___Object___ *)ptrarray[2];
749 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
750 ao=(struct ArrayObject *)tagd->flagptr;
752 struct ArrayObject * aonew=
753 allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
755 aonew->___cachedCode___=ao->___cachedCode___+1;
756 for(i=0; i<ao->___length___; i++) {
757 ARRAYSET(aonew, struct ___Object___*, i,
758 ARRAYGET(ao, struct ___Object___*, i));
760 ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj);
761 tagd->flagptr=(struct ___Object___ *) aonew;
767 /* This function clears a tag. */
769 void tagclear(void *ptr,
770 struct ___Object___ * obj,
771 struct ___TagDescriptor___ * tagd) {
773 void tagclear(struct ___Object___ * obj,
774 struct ___TagDescriptor___ * tagd) {
776 /* We'll assume that tag is alway there.
777 Need to statically check for this of course. */
778 struct ___Object___ * tagptr=obj->___tags___;
780 if (tagptr->type==TAGTYPE) {
781 if ((struct ___TagDescriptor___ *)tagptr==tagd)
782 obj->___tags___=NULL;
784 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
786 for(i=0; i<ao->___cachedCode___; i++) {
787 struct ___TagDescriptor___ * td=
788 ARRAYGET(ao, struct ___TagDescriptor___ *, i);
790 ao->___cachedCode___--;
791 if (i<ao->___cachedCode___)
792 ARRAYSET(ao, struct ___TagDescriptor___ *, i,
793 ARRAYGET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___));
794 ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, NULL);
795 if (ao->___cachedCode___==0)
796 obj->___tags___=NULL;
803 struct ___Object___ *tagset=tagd->flagptr;
804 if (tagset->type!=OBJECTARRAYTYPE) {
808 struct ArrayObject *ao=(struct ArrayObject *) tagset;
810 for(i=0; i<ao->___cachedCode___; i++) {
811 struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, i);
813 ao->___cachedCode___--;
814 if (i<ao->___cachedCode___)
815 ARRAYSET(ao, struct ___Object___ *, i,
816 ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
817 ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL);
818 if (ao->___cachedCode___==0)
829 /* This function allocates a new tag. */
831 struct ___TagDescriptor___ * allocate_tag(void *ptr,
833 struct ___TagDescriptor___ * v=
834 (struct ___TagDescriptor___ *) FREEMALLOC((struct garbagelist *) ptr,
837 struct ___TagDescriptor___ * allocate_tag(int index) {
838 struct ___TagDescriptor___ * v=FREEMALLOC(classsize[TAGTYPE]);
847 /* This function updates the flag for object ptr. It or's the flag
848 with the or mask and and's it with the andmask. */
850 void flagbody(struct ___Object___ *ptr,
852 struct parameterwrapper ** queues,
856 int flagcomp(const int *val1, const int *val2) {
857 return (*val1)-(*val2);
860 void flagorand(void * ptr,
863 struct parameterwrapper ** queues,
866 int oldflag=((int *)ptr)[1];
867 int flag=ormask|oldflag;
869 flagbody(ptr, flag, queues, length, false);
873 bool intflagorand(void * ptr,
877 int oldflag=((int *)ptr)[1];
878 int flag=ormask|oldflag;
880 if (flag==oldflag) /* Don't do anything */
883 flagbody(ptr, flag, NULL, 0, false);
889 void flagorandinit(void * ptr,
892 int oldflag=((int *)ptr)[1];
893 int flag=ormask|oldflag;
895 flagbody(ptr,flag,NULL,0,true);
898 void flagbody(struct ___Object___ *ptr,
900 struct parameterwrapper ** vqueues,
903 struct parameterwrapper * flagptr = NULL;
905 struct parameterwrapper ** queues = vqueues;
906 int length = vlength;
909 int * enterflags = NULL;
910 if((!isnew) && (queues == NULL)) {
911 if(BAMBOO_NUM_OF_CORE < NUMCORES) {
912 queues = objectqueues[BAMBOO_NUM_OF_CORE][ptr->type];
913 length = numqueues[BAMBOO_NUM_OF_CORE][ptr->type];
920 /*Remove object from all queues */
921 for(i = 0; i < length; ++i) {
923 ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next,
924 (int *) &enterflags, &UNUSED, &UNUSED2);
925 ObjectHashremove(flagptr->objectset, (int)ptr);
926 if (enterflags!=NULL)
931 void enqueueObject(void * vptr,
932 struct parameterwrapper ** vqueues,
934 struct ___Object___ *ptr = (struct ___Object___ *)vptr;
937 //struct QueueItem *tmpptr;
938 struct parameterwrapper * parameter=NULL;
941 struct parameterwrapper * prevptr=NULL;
942 struct ___Object___ *tagptr=NULL;
943 struct parameterwrapper ** queues = vqueues;
944 int length = vlength;
945 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
949 queues = objectqueues[BAMBOO_NUM_OF_CORE][ptr->type];
950 length = numqueues[BAMBOO_NUM_OF_CORE][ptr->type];
952 tagptr=ptr->___tags___;
954 /* Outer loop iterates through all parameter queues an object of
955 this type could be in. */
956 for(j = 0; j < length; ++j) {
957 parameter = queues[j];
959 if (parameter->numbertags>0) {
961 goto nextloop; //that means the object has no tag
962 //but that param needs tag
963 else if(tagptr->type==TAGTYPE) { //one tag
964 //struct ___TagDescriptor___ * tag=
965 //(struct ___TagDescriptor___*) tagptr;
966 for(i=0; i<parameter->numbertags; i++) {
967 //slotid is parameter->tagarray[2*i];
968 int tagid=parameter->tagarray[2*i+1];
969 if (tagid!=tagptr->flag)
970 goto nextloop; /*We don't have this tag */
972 } else { //multiple tags
973 struct ArrayObject * ao=(struct ArrayObject *) tagptr;
974 for(i=0; i<parameter->numbertags; i++) {
975 //slotid is parameter->tagarray[2*i];
976 int tagid=parameter->tagarray[2*i+1];
978 for(j=0; j<ao->___cachedCode___; j++) {
979 if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag)
990 for(i=0; i<parameter->numberofterms; i++) {
991 int andmask=parameter->intarray[i*2];
992 int checkmask=parameter->intarray[i*2+1];
993 if ((ptr->flag&andmask)==checkmask) {
994 enqueuetasks(parameter, prevptr, ptr, NULL, 0);
1005 void enqueueObject_I(void * vptr,
1006 struct parameterwrapper ** vqueues,
1008 struct ___Object___ *ptr = (struct ___Object___ *)vptr;
1011 //struct QueueItem *tmpptr;
1012 struct parameterwrapper * parameter=NULL;
1015 struct parameterwrapper * prevptr=NULL;
1016 struct ___Object___ *tagptr=NULL;
1017 struct parameterwrapper ** queues = vqueues;
1018 int length = vlength;
1019 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
1022 if(queues == NULL) {
1023 queues = objectqueues[BAMBOO_NUM_OF_CORE][ptr->type];
1024 length = numqueues[BAMBOO_NUM_OF_CORE][ptr->type];
1026 tagptr=ptr->___tags___;
1028 /* Outer loop iterates through all parameter queues an object of
1029 this type could be in. */
1030 for(j = 0; j < length; ++j) {
1031 parameter = queues[j];
1033 if (parameter->numbertags>0) {
1035 goto nextloop; //that means the object has no tag
1036 //but that param needs tag
1037 else if(tagptr->type==TAGTYPE) { //one tag
1038 //struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr;
1039 for(i=0; i<parameter->numbertags; i++) {
1040 //slotid is parameter->tagarray[2*i];
1041 int tagid=parameter->tagarray[2*i+1];
1042 if (tagid!=tagptr->flag)
1043 goto nextloop; /*We don't have this tag */
1045 } else { //multiple tags
1046 struct ArrayObject * ao=(struct ArrayObject *) tagptr;
1047 for(i=0; i<parameter->numbertags; i++) {
1048 //slotid is parameter->tagarray[2*i];
1049 int tagid=parameter->tagarray[2*i+1];
1051 for(j=0; j<ao->___cachedCode___; j++) {
1052 if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag)
1063 for(i=0; i<parameter->numberofterms; i++) {
1064 int andmask=parameter->intarray[i*2];
1065 int checkmask=parameter->intarray[i*2+1];
1066 if ((ptr->flag&andmask)==checkmask) {
1067 enqueuetasks_I(parameter, prevptr, ptr, NULL, 0);
1079 int * getAliasLock(void ** ptrs,
1081 struct RuntimeHash * tbl) {
1083 return (int*)(RUNMALLOC(sizeof(int)));
1088 bool redirect = false;
1089 int redirectlock = 0;
1090 for(; i < length; i++) {
1091 struct ___Object___ * ptr = (struct ___Object___ *)(ptrs[i]);
1094 if(ptr->lock == NULL) {
1097 lock = (int)(ptr->lock);
1100 if(lock != redirectlock) {
1101 RuntimeHashadd(tbl, lock, redirectlock);
1104 if(RuntimeHashcontainskey(tbl, lock)) {
1105 // already redirected
1107 RuntimeHashget(tbl, lock, &redirectlock);
1108 for(; j < locklen; j++) {
1109 if(locks[j] != redirectlock) {
1110 RuntimeHashadd(tbl, locks[j], redirectlock);
1115 for(j = 0; j < locklen; j++) {
1116 if(locks[j] == lock) {
1119 } else if(locks[j] > lock) {
1126 locks[h] = locks[h-1];
1135 return (int *)redirectlock;
1137 return (int *)(locks[0]);
1142 void addAliasLock(void * ptr,
1144 struct ___Object___ * obj = (struct ___Object___ *)ptr;
1145 if(((int)ptr != lock) && (obj->lock != (int*)lock)) {
1146 // originally no alias lock associated or have a different alias lock
1147 // flush it as the new one
1148 obj->lock = (int *)lock;
1153 inline void setTaskExitIndex(int index) {
1154 taskInfoArray[taskInfoIndex]->exitIndex = index;
1157 inline void addNewObjInfo(void * nobj) {
1158 if(taskInfoArray[taskInfoIndex]->newObjs == NULL) {
1159 taskInfoArray[taskInfoIndex]->newObjs = createQueue();
1161 addNewItem(taskInfoArray[taskInfoIndex]->newObjs, nobj);
1165 void * smemalloc(int size,
1170 // go through free mem list for suitable blocks
1171 struct freeMemItem * freemem = bamboo_free_mem_list->head;
1172 struct freeMemItem * prev = NULL;
1174 if(freemem->size >= isize) {
1179 freemem = freemem->next;
1180 } while(freemem != NULL);
1181 if(freemem != NULL) {
1182 mem = (void *)(freemem->ptr);
1183 // check the remaining space in this block
1184 int remain = (int)(mem-(BAMBOO_BASE_VA));
1185 int bound = (BAMBOO_SMEM_SIZE);
1186 if(remain < BAMBOO_LARGE_SMEM_BOUND) {
1187 bound = (BAMBOO_SMEM_SIZE_L);
1189 remain = bound - remain%bound;
1190 if(remain < isize) {
1191 // this object acrosses blocks
1192 // try to align the block if required a block
1193 if((isize == BAMBOO_SMEM_SIZE) && (freemem->size >= isize + remain)) {
1198 freemem->ptr = ((void*)freemem->ptr) + isize;
1199 freemem->size -= isize;
1202 mem = mspace_calloc(bamboo_free_msp, 1, isize);
1206 // no enough shared global memory
1212 BAMBOO_DEBUGPRINT(0xa001);
1213 BAMBOO_EXIT(0xa001);
1219 // receive object transferred from other cores
1220 // or the terminate message from other cores
1221 // Should be invoked in critical sections!!
1222 // NOTICE: following format is for threadsimulate version only
1223 // RAW version please see previous description
1224 // format: type + object
1225 // type: -1--stall msg
1227 // return value: 0--received an object
1228 // 1--received nothing
1229 // 2--received a Stall Msg
1230 // 3--received a lock Msg
1231 // RAW version: -1 -- received nothing
1232 // otherwise -- received msg type
1233 int receiveObject() {
1237 if(receiveMsg() == -1) {
1241 if(msgdataindex == msglength) {
1242 // received a whole msg
1247 // receive a object transfer msg
1248 struct transObjInfo * transObj =
1249 RUNMALLOC_I(sizeof(struct transObjInfo));
1253 BAMBOO_DEBUGPRINT(0xe880);
1256 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
1258 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1260 BAMBOO_EXIT(0xa002);
1262 // store the object and its corresponding queue info, enqueue it later
1263 transObj->objptr = (void *)msgdata[2];
1264 transObj->length = (msglength - 3) / 2;
1265 transObj->queues = RUNMALLOC_I(sizeof(int)*(msglength - 3));
1266 for(k = 0; k < transObj->length; ++k) {
1267 transObj->queues[2*k] = msgdata[3+2*k];
1270 BAMBOO_DEBUGPRINT_REG(transObj->queues[2*k]);
1273 transObj->queues[2*k+1] = msgdata[3+2*k+1];
1276 BAMBOO_DEBUGPRINT_REG(transObj->queues[2*k+1]);
1280 // check if there is an existing duplicate item
1282 struct QueueItem * qitem = getHead(&objqueue);
1283 struct QueueItem * prev = NULL;
1284 while(qitem != NULL) {
1285 struct transObjInfo * tmpinfo =
1286 (struct transObjInfo *)(qitem->objectptr);
1287 if(tmpinfo->objptr == transObj->objptr) {
1288 // the same object, remove outdate one
1289 removeItem(&objqueue, qitem);
1295 qitem = getHead(&objqueue);
1297 qitem = getNextQueueItem(prev);
1300 addNewItem_I(&objqueue, (void *)transObj);
1302 ++(self_numreceiveobjs);
1307 // receive a stall msg
1308 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1309 // non startup core can not receive stall msg
1311 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1313 BAMBOO_EXIT(0xa003);
1315 if(msgdata[1] < NUMCORES) {
1318 BAMBOO_DEBUGPRINT(0xe881);
1321 corestatus[msgdata[1]] = 0;
1322 numsendobjs[msgdata[1]] = msgdata[2];
1323 numreceiveobjs[msgdata[1]] = msgdata[3];
1328 // GC version have no lock msgs
1329 #ifndef MULTICORE_GC
1331 // receive lock request msg, handle it right now
1332 // check to see if there is a lock exist for the required obj
1333 // msgdata[1] -> lock type
1334 int data2 = msgdata[2]; // obj pointer
1335 int data3 = msgdata[3]; // lock
1336 int data4 = msgdata[4]; // request core
1337 // -1: redirected, 0: approved, 1: denied
1338 deny = processlockrequest(msgdata[1], data3, data2,
1339 data4, data4, true);
1341 // this lock request is redirected
1344 // send response msg
1345 // for 32 bit machine, the size is always 4 words
1346 int tmp = deny==1?LOCKDENY:LOCKGROUNT;
1348 cache_msg_4(data4, tmp, msgdata[1], data2, data3);
1350 send_msg_4(data4, tmp, msgdata[1], data2, data3);
1357 // receive lock grount msg
1358 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
1360 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1362 BAMBOO_EXIT(0xa004);
1364 if((lockobj == msgdata[2]) && (lock2require == msgdata[3])) {
1367 BAMBOO_DEBUGPRINT(0xe882);
1376 // conflicts on lockresults
1378 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1380 BAMBOO_EXIT(0xa005);
1386 // receive lock deny msg
1387 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
1389 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1391 BAMBOO_EXIT(0xa006);
1393 if((lockobj == msgdata[2]) && (lock2require == msgdata[3])) {
1396 BAMBOO_DEBUGPRINT(0xe883);
1405 // conflicts on lockresults
1407 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1409 BAMBOO_EXIT(0xa007);
1415 // receive lock release msg
1416 processlockrelease(msgdata[1], msgdata[2], 0, false);
1422 case PROFILEOUTPUT: {
1423 // receive an output profile data request msg
1424 if(BAMBOO_NUM_OF_CORE == STARTUPCORE) {
1425 // startup core can not receive profile output finish msg
1426 BAMBOO_EXIT(0xa008);
1430 BAMBOO_DEBUGPRINT(0xe885);
1434 totalexetime = msgdata[1];
1435 outputProfileData();
1437 cache_msg_2(STARTUPCORE, PROFILEFINISH, BAMBOO_NUM_OF_CORE);
1439 send_msg_2(STARTUPCORE, PROFILEFINISH, BAMBOO_NUM_OF_CORE);
1444 case PROFILEFINISH: {
1445 // receive a profile output finish msg
1446 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1447 // non startup core can not receive profile output finish msg
1449 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1451 BAMBOO_EXIT(0xa009);
1455 BAMBOO_DEBUGPRINT(0xe886);
1458 profilestatus[msgdata[1]] = 0;
1463 // GC version has no lock msgs
1464 #ifndef MULTICORE_GC
1465 case REDIRECTLOCK: {
1466 // receive a redirect lock request msg, handle it right now
1467 // check to see if there is a lock exist for the required obj
1468 int data1 = msgdata[1]; // lock type
1469 int data2 = msgdata[2]; // obj pointer
1470 int data3 = msgdata[3]; // redirect lock
1471 int data4 = msgdata[4]; // root request core
1472 int data5 = msgdata[5]; // request core
1473 deny = processlockrequest(msgdata[1], data3, data2, data5, data4, true);
1475 // this lock request is redirected
1478 // send response msg
1479 // for 32 bit machine, the size is always 4 words
1481 cache_msg_4(data4, deny==1?REDIRECTDENY:REDIRECTGROUNT,
1482 data1, data2, data3);
1484 send_msg_4(data4, deny==1?REDIRECTDENY:REDIRECTGROUNT,
1485 data1, data2, data3);
1491 case REDIRECTGROUNT: {
1492 // receive a lock grant msg with redirect info
1493 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
1495 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1497 BAMBOO_EXIT(0xa00a);
1499 if(lockobj == msgdata[2]) {
1502 BAMBOO_DEBUGPRINT(0xe891);
1507 RuntimeHashadd_I(objRedirectLockTbl, lockobj, msgdata[3]);
1512 // conflicts on lockresults
1514 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1516 BAMBOO_EXIT(0xa00b);
1521 case REDIRECTDENY: {
1522 // receive a lock deny msg with redirect info
1523 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
1525 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1527 BAMBOO_EXIT(0xa00c);
1529 if(lockobj == msgdata[2]) {
1532 BAMBOO_DEBUGPRINT(0xe892);
1541 // conflicts on lockresults
1543 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1545 BAMBOO_EXIT(0xa00d);
1550 case REDIRECTRELEASE: {
1551 // receive a lock release msg with redirect info
1552 processlockrelease(msgdata[1], msgdata[2], msgdata[3], true);
1557 case STATUSCONFIRM: {
1558 // receive a status confirm info
1559 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
1560 || (BAMBOO_NUM_OF_CORE > NUMCORES - 1)) {
1561 // wrong core to receive such msg
1562 BAMBOO_EXIT(0xa00e);
1564 // send response msg
1567 BAMBOO_DEBUGPRINT(0xe887);
1571 cache_msg_5(STARTUPCORE, STATUSREPORT,
1572 busystatus?1:0, BAMBOO_NUM_OF_CORE,
1573 self_numsendobjs, self_numreceiveobjs);
1575 send_msg_5(STARTUPCORE, STATUSREPORT,
1576 busystatus?1:0, BAMBOO_NUM_OF_CORE,
1577 self_numsendobjs, self_numreceiveobjs);
1583 case STATUSREPORT: {
1584 // receive a status confirm info
1585 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1586 // wrong core to receive such msg
1588 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1590 BAMBOO_EXIT(0xa00f);
1594 BAMBOO_DEBUGPRINT(0xe888);
1600 corestatus[msgdata[2]] = msgdata[1];
1601 numsendobjs[msgdata[2]] = msgdata[3];
1602 numreceiveobjs[msgdata[2]] = msgdata[4];
1608 // receive a terminate msg
1611 BAMBOO_DEBUGPRINT(0xe889);
1620 // receive a shared memory request msg
1621 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1622 // wrong core to receive such msg
1624 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1626 BAMBOO_EXIT(0xa010);
1630 BAMBOO_DEBUGPRINT(0xe88a);
1635 // is currently doing gc, dump this msg
1640 void * mem = smemalloc(msgdata[1], &allocsize);
1644 // send the start_va to request core
1646 cache_msg_3(msgdata[2], MEMRESPONSE, mem, allocsize);
1648 send_msg_3( msgdata[2], MEMRESPONSE, mem, allocsize);
1655 // receive a shared memory response msg
1658 BAMBOO_DEBUGPRINT(0xe88b);
1663 // is currently doing gc, dump this msg
1667 if(msgdata[2] == 0) {
1668 bamboo_smem_size = 0;
1671 // fill header to store the size of this mem block
1672 (*((int*)msgdata[1])) = msgdata[2];
1673 bamboo_smem_size = msgdata[2] - BAMBOO_CACHE_LINE_SIZE;
1675 bamboo_cur_msp = msgdata[1] + BAMBOO_CACHE_LINE_SIZE;
1678 create_mspace_with_base((void*)(msgdata[1]+BAMBOO_CACHE_LINE_SIZE),
1679 msgdata[2]-BAMBOO_CACHE_LINE_SIZE,
1691 gcphase = INITPHASE;
1693 // is waiting for response of mem request
1694 // let it return NULL and start gc
1695 bamboo_smem_size = 0;
1696 bamboo_cur_msp = NULL;
1703 // receive a start GC msg
1706 BAMBOO_DEBUGPRINT(0xe88c);
1710 gcphase = MARKPHASE;
1714 case GCSTARTCOMPACT: {
1715 // a compact phase start msg
1716 gcblock2fill = msgdata[1];
1717 gcphase = COMPACTPHASE;
1721 case GCSTARTFLUSH: {
1722 // received a flush phase start msg
1723 gcphase = FLUSHPHASE;
1727 case GCFINISHINIT: {
1728 // received a init phase finish msg
1729 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1730 // non startup core can not receive this msg
1732 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1734 BAMBOO_EXIT(0xb001);
1737 BAMBOO_DEBUGPRINT(0xe88c);
1738 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1740 if(msgdata[1] < NUMCORES) {
1741 gccorestatus[msgdata[1]] = 0;
1745 case GCFINISHMARK: {
1746 // received a mark phase finish msg
1747 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1748 // non startup core can not receive this msg
1750 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1752 BAMBOO_EXIT(0xb002);
1754 if(msgdata[1] < NUMCORES) {
1755 gccorestatus[msgdata[1]] = 0;
1756 gcnumsendobjs[msgdata[1]] = msgdata[2];
1757 gcnumreceiveobjs[msgdata[1]] = msgdata[3];
1762 case GCFINISHCOMPACT: {
1763 // received a compact phase finish msg
1764 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1765 // non startup core can not receive this msg
1768 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1770 BAMBOO_EXIT(0xb003);
1772 int cnum = msgdata[1];
1773 int filledblocks = msgdata[2];
1774 int heaptop = msgdata[3];
1775 int data4 = msgdata[4];
1776 if(cnum < NUMCORES) {
1777 if(COMPACTPHASE == gcphase) {
1778 gcfilledblocks[cnum] = filledblocks;
1779 gcloads[cnum] = heaptop;
1786 if(gcfindSpareMem_I(&startaddr, &tomove, &dstcore, data4, cnum)) {
1788 cache_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove);
1790 send_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove);
1794 gccorestatus[cnum] = 0;
1795 // check if there is pending move request
1796 /*if(gcmovepending > 0) {
1798 for(j = 0; j < NUMCORES; j++) {
1799 if(gcrequiredmems[j]>0) {
1807 gcrequiredmems[j] = assignSpareMem_I(cnum,
1811 if(STARTUPCORE == j) {
1814 gcmovestartaddr = startaddr;
1815 gcblock2fill = tomove;
1818 cache_msg_4(j, GCMOVESTART, cnum, startaddr, tomove);
1820 send_msg_4(j, GCMOVESTART, cnum, startaddr, tomove);
1822 } // if(STARTUPCORE == j)
1823 if(gcrequiredmems[j] == 0) {
1826 } // if(j < NUMCORES)
1827 } // if(gcmovepending > 0) */
1829 } // if(cnum < NUMCORES)
1833 case GCFINISHFLUSH: {
1834 // received a flush phase finish msg
1835 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1836 // non startup core can not receive this msg
1839 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1841 BAMBOO_EXIT(0xb004);
1843 if(msgdata[1] < NUMCORES) {
1844 gccorestatus[msgdata[1]] = 0;
1850 // received a GC finish msg
1851 gcphase = FINISHPHASE;
1855 case GCMARKCONFIRM: {
1856 // received a marked phase finish confirm request msg
1857 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
1858 || (BAMBOO_NUM_OF_CORE > NUMCORES - 1)) {
1859 // wrong core to receive such msg
1860 BAMBOO_EXIT(0xb005);
1862 // send response msg
1864 cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1865 gcbusystatus, gcself_numsendobjs,
1866 gcself_numreceiveobjs);
1868 send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1869 gcbusystatus, gcself_numsendobjs, gcself_numreceiveobjs);
1875 case GCMARKREPORT: {
1876 // received a marked phase finish confirm response msg
1877 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1878 // wrong core to receive such msg
1880 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1882 BAMBOO_EXIT(0xb006);
1887 gccorestatus[msgdata[1]] = msgdata[2];
1888 gcnumsendobjs[msgdata[1]] = msgdata[3];
1889 gcnumreceiveobjs[msgdata[1]] = msgdata[4];
1895 // received a markedObj msg
1896 gc_enqueue_I(msgdata[1]);
1897 gcself_numreceiveobjs++;
1898 gcbusystatus = true;
1903 // received a start moving objs msg
1905 gcdstcore = msgdata[1];
1906 gcmovestartaddr = msgdata[2];
1907 gcblock2fill = msgdata[3];
1911 case GCMAPREQUEST: {
1912 // received a mapping info request msg
1913 void * dstptr = NULL;
1914 RuntimeHashget(gcpointertbl, msgdata[1], &dstptr);
1915 if(NULL == dstptr) {
1916 // no such pointer in this core, something is wrong
1918 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1919 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1921 BAMBOO_EXIT(0xb007);
1923 // send back the mapping info
1925 cache_msg_3(msgdata[2], GCMAPINFO, msgdata[1], (int)dstptr);
1927 send_msg_3(msgdata[2], GCMAPINFO, msgdata[1], (int)dstptr);
1934 // received a mapping info response msg
1935 if(msgdata[1] != gcobj2map) {
1936 // obj not matched, something is wrong
1938 BAMBOO_DEBUGPRINT_REG(gcobj2map);
1939 BAMBOO_DEBUGPRINT_REG(msgdata[1]);
1941 BAMBOO_EXIT(0xb008);
1943 gcmappedobj = msgdata[2];
1944 RuntimeHashadd_I(gcpointertbl, gcobj2map, gcmappedobj);
1950 case GCLOBJREQUEST: {
1951 // received a large objs info request msg
1952 transferMarkResults_I();
1957 // received a large objs info response msg
1960 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
1962 BAMBOO_DEBUGPRINT_REG(msgdata[2]);
1964 BAMBOO_EXIT(0xb009);
1966 // store the mark result info
1967 int cnum = msgdata[2];
1968 gcloads[cnum] = msgdata[3];
1969 if(gcheaptop < msgdata[4]) {
1970 gcheaptop = msgdata[4];
1972 // large obj info here
1973 for(int k = 5; k < msgdata[1];) {
1974 gc_lobjenqueue_I(msgdata[k++], msgdata[k++], cnum);
1976 } // for(int k = 5; k < msgdata[1];)
1980 case GCLOBJMAPPING: {
1981 // received a large obj mapping info msg
1982 RuntimeHashadd_I(gcpointertbl, msgdata[1], msgdata[2]);
1991 for(msgdataindex--; msgdataindex > 0; --msgdataindex) {
1992 msgdata[msgdataindex] = -1;
1998 BAMBOO_DEBUGPRINT(0xe88d);
2002 if(BAMBOO_MSG_AVAIL() != 0) {
2015 BAMBOO_DEBUGPRINT(0xe88e);
2019 /* if(isInterrupt) {
2027 int enqueuetasks(struct parameterwrapper *parameter,
2028 struct parameterwrapper *prevptr,
2029 struct ___Object___ *ptr,
2031 int numenterflags) {
2032 void * taskpointerarray[MAXTASKPARAMS];
2034 //int numparams=parameter->task->numParameters;
2035 int numiterators=parameter->task->numTotal-1;
2038 struct taskdescriptor * task=parameter->task;
2040 //this add the object to parameterwrapper
2041 ObjectHashadd(parameter->objectset, (int) ptr, 0, (int) enterflags,
2042 numenterflags, enterflags==NULL);
2044 /* Add enqueued object to parameter vector */
2045 taskpointerarray[parameter->slot]=ptr;
2047 /* Reset iterators */
2048 for(j=0; j<numiterators; j++) {
2049 toiReset(¶meter->iterators[j]);
2052 /* Find initial state */
2053 for(j=0; j<numiterators; j++) {
2055 if(toiHasNext(¶meter->iterators[j],taskpointerarray OPTARG(failed)))
2056 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
2058 /* Need to backtrack */
2059 toiReset(¶meter->iterators[j]);
2063 /* Nothing to enqueue */
2069 /* Enqueue current state */
2071 struct taskparamdescriptor *tpd=
2072 RUNMALLOC(sizeof(struct taskparamdescriptor));
2074 tpd->numParameters=numiterators+1;
2075 tpd->parameterArray=RUNMALLOC(sizeof(void *)*(numiterators+1));
2077 for(j=0; j<=numiterators; j++) {
2078 //store the actual parameters
2079 tpd->parameterArray[j]=taskpointerarray[j];
2082 if ((/*!gencontains(failedtasks, tpd)&&*/
2083 !gencontains(activetasks,tpd))) {
2084 genputtable(activetasks, tpd, tpd);
2086 RUNFREE(tpd->parameterArray);
2090 /* This loop iterates to the next parameter combination */
2091 if (numiterators==0)
2094 for(j=numiterators-1; j<numiterators; j++) {
2096 if(toiHasNext(¶meter->iterators[j],taskpointerarray OPTARG(failed)))
2097 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
2099 /* Need to backtrack */
2100 toiReset(¶meter->iterators[j]);
2104 /* Nothing more to enqueue */
2112 int enqueuetasks_I(struct parameterwrapper *parameter,
2113 struct parameterwrapper *prevptr,
2114 struct ___Object___ *ptr,
2116 int numenterflags) {
2117 void * taskpointerarray[MAXTASKPARAMS];
2119 //int numparams=parameter->task->numParameters;
2120 int numiterators=parameter->task->numTotal-1;
2125 struct taskdescriptor * task=parameter->task;
2127 //this add the object to parameterwrapper
2128 ObjectHashadd_I(parameter->objectset, (int) ptr, 0, (int) enterflags,
2129 numenterflags, enterflags==NULL);
2131 /* Add enqueued object to parameter vector */
2132 taskpointerarray[parameter->slot]=ptr;
2134 /* Reset iterators */
2135 for(j=0; j<numiterators; j++) {
2136 toiReset(¶meter->iterators[j]);
2139 /* Find initial state */
2140 for(j=0; j<numiterators; j++) {
2142 if(toiHasNext(¶meter->iterators[j],taskpointerarray OPTARG(failed)))
2143 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
2145 /* Need to backtrack */
2146 toiReset(¶meter->iterators[j]);
2150 /* Nothing to enqueue */
2156 /* Enqueue current state */
2158 struct taskparamdescriptor *tpd=
2159 RUNMALLOC_I(sizeof(struct taskparamdescriptor));
2161 tpd->numParameters=numiterators+1;
2162 tpd->parameterArray=RUNMALLOC_I(sizeof(void *)*(numiterators+1));
2164 for(j=0; j<=numiterators; j++) {
2165 //store the actual parameters
2166 tpd->parameterArray[j]=taskpointerarray[j];
2169 if ((/*!gencontains(failedtasks, tpd)&&*/
2170 !gencontains(activetasks,tpd))) {
2171 genputtable_I(activetasks, tpd, tpd);
2173 RUNFREE(tpd->parameterArray);
2177 /* This loop iterates to the next parameter combination */
2178 if (numiterators==0)
2181 for(j=numiterators-1; j<numiterators; j++) {
2183 if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)))
2184 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
2186 /* Need to backtrack */
2187 toiReset(¶meter->iterators[j]);
2191 /* Nothing more to enqueue */
2205 int containstag(struct ___Object___ *ptr,
2206 struct ___TagDescriptor___ *tag);
2208 #ifndef MULTICORE_GC
2209 void releasewritelock_r(void * lock, void * redirectlock) {
2211 int reallock = (int)lock;
2212 targetcore = (reallock >> 5) % BAMBOO_TOTALCORE;
2215 BAMBOO_DEBUGPRINT(0xe671);
2216 BAMBOO_DEBUGPRINT_REG((int)lock);
2217 BAMBOO_DEBUGPRINT_REG(reallock);
2218 BAMBOO_DEBUGPRINT_REG(targetcore);
2221 if(targetcore == BAMBOO_NUM_OF_CORE) {
2222 BAMBOO_START_CRITICAL_SECTION_LOCK();
2224 BAMBOO_DEBUGPRINT(0xf001);
2226 // reside on this core
2227 if(!RuntimeHashcontainskey(locktbl, reallock)) {
2228 // no locks for this object, something is wrong
2229 BAMBOO_EXIT(0xa011);
2232 struct LockValue * lockvalue = NULL;
2234 BAMBOO_DEBUGPRINT(0xe672);
2236 RuntimeHashget(locktbl, reallock, &rwlock_obj);
2237 lockvalue = (struct LockValue *)rwlock_obj;
2239 BAMBOO_DEBUGPRINT_REG(lockvalue->value);
2242 lockvalue->redirectlock = (int)redirectlock;
2244 BAMBOO_DEBUGPRINT_REG(lockvalue->value);
2247 BAMBOO_CLOSE_CRITICAL_SECTION_LOCK();
2249 BAMBOO_DEBUGPRINT(0xf000);
2253 // send lock release with redirect info msg
2254 // for 32 bit machine, the size is always 4 words
2255 send_msg_4(targetcore, REDIRECTRELEASE, 1, (int)lock, (int)redirectlock);
2260 void executetasks() {
2261 void * taskpointerarray[MAXTASKPARAMS+OFFSET];
2264 struct ___Object___ * tmpparam = NULL;
2265 struct parameterdescriptor * pd=NULL;
2266 struct parameterwrapper *pw=NULL;
2271 struct LockValue locks[MAXTASKPARAMS];
2279 while(hashsize(activetasks)>0) {
2284 BAMBOO_DEBUGPRINT(0xe990);
2287 /* See if there are any active tasks */
2288 if (hashsize(activetasks)>0) {
2291 #ifdef ACCURATEPROFILE
2292 profileTaskStart("tpd checking");
2296 currtpd=(struct taskparamdescriptor *) getfirstkey(activetasks);
2297 genfreekey(activetasks, currtpd);
2299 numparams=currtpd->task->numParameters;
2300 numtotal=currtpd->task->numTotal;
2302 // clear the lockRedirectTbl
2303 // (TODO, this table should be empty after all locks are released)
2305 for(j = 0; j < MAXTASKPARAMS; j++) {
2306 locks[j].redirectlock = 0;
2309 // get all required locks
2311 // check which locks are needed
2312 for(i = 0; i < numparams; i++) {
2313 void * param = currtpd->parameterArray[i];
2317 if(((struct ___Object___ *)param)->type == STARTUPTYPE) {
2319 taskpointerarray[i+OFFSET]=param;
2322 if(((struct ___Object___ *)param)->lock == NULL) {
2323 tmplock = (int)param;
2325 tmplock = (int)(((struct ___Object___ *)param)->lock);
2327 // insert into the locks array
2328 for(j = 0; j < locklen; j++) {
2329 if(locks[j].value == tmplock) {
2332 } else if(locks[j].value > tmplock) {
2339 locks[h].redirectlock = locks[h-1].redirectlock;
2340 locks[h].value = locks[h-1].value;
2342 locks[j].value = tmplock;
2343 locks[j].redirectlock = (int)param;
2346 } // line 2713: for(i = 0; i < numparams; i++)
2347 // grab these required locks
2349 BAMBOO_DEBUGPRINT(0xe991);
2351 for(i = 0; i < locklen; i++) {
2352 int * lock = (int *)(locks[i].redirectlock);
2354 // require locks for this parameter if it is not a startup object
2356 BAMBOO_DEBUGPRINT_REG((int)lock);
2357 BAMBOO_DEBUGPRINT_REG((int)(locks[i].value));
2360 BAMBOO_START_CRITICAL_SECTION();
2362 BAMBOO_DEBUGPRINT(0xf001);
2365 //isInterrupt = false;
2368 BAMBOO_WAITING_FOR_LOCK();
2372 while(BAMBOO_WAITING_FOR_LOCK() != -1) {
2376 grount = lockresult;
2386 //isInterrupt = true;
2388 BAMBOO_CLOSE_CRITICAL_SECTION();
2390 BAMBOO_DEBUGPRINT(0xf000);
2396 BAMBOO_DEBUGPRINT(0xe992);
2398 // can not get the lock, try later
2399 // releas all grabbed locks for previous parameters
2400 for(j = 0; j < i; ++j) {
2401 lock = (int*)(locks[j].redirectlock);
2402 releasewritelock(lock);
2404 genputtable(activetasks, currtpd, currtpd);
2405 if(hashsize(activetasks) == 1) {
2406 // only one task right now, wait a little while before next try
2412 #ifdef ACCURATEPROFILE
2413 // fail, set the end of the checkTaskInfo
2418 } // line 2794: if(grount == 0)
2419 } // line 2752: for(i = 0; i < locklen; i++)
2422 BAMBOO_DEBUGPRINT(0xe993);
2424 /* Make sure that the parameters are still in the queues */
2425 for(i=0; i<numparams; i++) {
2426 void * parameter=currtpd->parameterArray[i];
2430 BAMBOO_CACHE_FLUSH_RANGE((int)parameter,
2431 classsize[((struct ___Object___ *)parameter)->type]);
2433 tmpparam = (struct ___Object___ *)parameter;
2434 pd=currtpd->task->descriptorarray[i];
2435 pw=(struct parameterwrapper *) pd->queue;
2436 /* Check that object is still in queue */
2438 if (!ObjectHashcontainskey(pw->objectset, (int) parameter)) {
2440 BAMBOO_DEBUGPRINT(0xe994);
2442 // release grabbed locks
2443 for(j = 0; j < locklen; ++j) {
2444 int * lock = (int *)(locks[j].redirectlock);
2445 releasewritelock(lock);
2447 RUNFREE(currtpd->parameterArray);
2453 /* Check if the object's flags still meets requirements */
2457 for(tmpi = 0; tmpi < pw->numberofterms; ++tmpi) {
2458 andmask=pw->intarray[tmpi*2];
2459 checkmask=pw->intarray[tmpi*2+1];
2460 if((((struct ___Object___ *)parameter)->flag&andmask)==checkmask) {
2466 // flags are never suitable
2467 // remove this obj from the queue
2469 int UNUSED, UNUSED2;
2472 BAMBOO_DEBUGPRINT(0xe995);
2474 ObjectHashget(pw->objectset, (int) parameter, (int *) &next,
2475 (int *) &enterflags, &UNUSED, &UNUSED2);
2476 ObjectHashremove(pw->objectset, (int)parameter);
2477 if (enterflags!=NULL)
2478 RUNFREE(enterflags);
2479 // release grabbed locks
2480 for(j = 0; j < locklen; ++j) {
2481 int * lock = (int *)(locks[j].redirectlock);
2482 releasewritelock(lock);
2484 RUNFREE(currtpd->parameterArray);
2488 #ifdef ACCURATEPROFILE
2489 // fail, set the end of the checkTaskInfo
2494 } // line 2878: if (!ismet)
2498 /* Check that object still has necessary tags */
2499 for(j=0; j<pd->numbertags; j++) {
2500 int slotid=pd->tagarray[2*j]+numparams;
2501 struct ___TagDescriptor___ *tagd=currtpd->parameterArray[slotid];
2502 if (!containstag(parameter, tagd)) {
2504 BAMBOO_DEBUGPRINT(0xe996);
2507 // release grabbed locks
2509 for(tmpj = 0; tmpj < locklen; ++tmpj) {
2510 int * lock = (int *)(locks[tmpj].redirectlock);
2511 releasewritelock(lock);
2514 RUNFREE(currtpd->parameterArray);
2518 } // line2911: if (!containstag(parameter, tagd))
2519 } // line 2808: for(j=0; j<pd->numbertags; j++)
2521 taskpointerarray[i+OFFSET]=parameter;
2522 } // line 2824: for(i=0; i<numparams; i++)
2524 for(; i<numtotal; i++) {
2525 taskpointerarray[i+OFFSET]=currtpd->parameterArray[i];
2530 /* Actually call task */
2532 ((int *)taskpointerarray)[0]=currtpd->numParameters;
2533 taskpointerarray[1]=NULL;
2536 #ifdef ACCURATEPROFILE
2537 // check finish, set the end of the checkTaskInfo
2540 profileTaskStart(currtpd->task->name);
2544 BAMBOO_DEBUGPRINT(0xe997);
2546 ((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
2548 #ifdef ACCURATEPROFILE
2549 // task finish, set the end of the checkTaskInfo
2551 // new a PostTaskInfo for the post-task execution
2552 profileTaskStart("post task execution");
2556 BAMBOO_DEBUGPRINT(0xe998);
2557 BAMBOO_DEBUGPRINT_REG(islock);
2562 BAMBOO_DEBUGPRINT(0xe999);
2564 for(i = 0; i < locklen; ++i) {
2565 void * ptr = (void *)(locks[i].redirectlock);
2566 int * lock = (int *)(locks[i].value);
2568 BAMBOO_DEBUGPRINT_REG((int)ptr);
2569 BAMBOO_DEBUGPRINT_REG((int)lock);
2571 #ifndef MULTICORE_GC
2572 if(RuntimeHashcontainskey(lockRedirectTbl, (int)lock)) {
2574 RuntimeHashget(lockRedirectTbl, (int)lock, &redirectlock);
2575 RuntimeHashremovekey(lockRedirectTbl, (int)lock);
2576 releasewritelock_r(lock, (int *)redirectlock);
2581 releasewritelock(ptr);
2584 } // line 3015: if(islock)
2587 // post task execution finish, set the end of the postTaskInfo
2591 // Free up task parameter descriptor
2592 RUNFREE(currtpd->parameterArray);
2596 BAMBOO_DEBUGPRINT(0xe99a);
2599 } // if (hashsize(activetasks)>0)
2600 } // while(hashsize(activetasks)>0)
2602 BAMBOO_DEBUGPRINT(0xe99b);
2606 /* This function processes an objects tags */
2607 void processtags(struct parameterdescriptor *pd,
2609 struct parameterwrapper *parameter,
2610 int * iteratorcount,
2615 for(i=0; i<pd->numbertags; i++) {
2616 int slotid=pd->tagarray[2*i];
2617 int tagid=pd->tagarray[2*i+1];
2619 if (statusarray[slotid+numparams]==0) {
2620 parameter->iterators[*iteratorcount].istag=1;
2621 parameter->iterators[*iteratorcount].tagid=tagid;
2622 parameter->iterators[*iteratorcount].slot=slotid+numparams;
2623 parameter->iterators[*iteratorcount].tagobjectslot=index;
2624 statusarray[slotid+numparams]=1;
2631 void processobject(struct parameterwrapper *parameter,
2633 struct parameterdescriptor *pd,
2639 struct ObjectHash * objectset=
2640 ((struct parameterwrapper *)pd->queue)->objectset;
2642 parameter->iterators[*iteratorcount].istag=0;
2643 parameter->iterators[*iteratorcount].slot=index;
2644 parameter->iterators[*iteratorcount].objectset=objectset;
2645 statusarray[index]=1;
2647 for(i=0; i<pd->numbertags; i++) {
2648 int slotid=pd->tagarray[2*i];
2649 //int tagid=pd->tagarray[2*i+1];
2650 if (statusarray[slotid+numparams]!=0) {
2651 /* This tag has already been enqueued, use it to narrow search */
2652 parameter->iterators[*iteratorcount].tagbindings[tagcount]=
2657 parameter->iterators[*iteratorcount].numtags=tagcount;
2662 /* This function builds the iterators for a task & parameter */
2664 void builditerators(struct taskdescriptor * task,
2666 struct parameterwrapper * parameter) {
2667 int statusarray[MAXTASKPARAMS];
2669 int numparams=task->numParameters;
2670 int iteratorcount=0;
2671 for(i=0; i<MAXTASKPARAMS; i++) statusarray[i]=0;
2673 statusarray[index]=1; /* Initial parameter */
2674 /* Process tags for initial iterator */
2676 processtags(task->descriptorarray[index], index, parameter,
2677 &iteratorcount, statusarray, numparams);
2681 /* Check for objects with existing tags */
2682 for(i=0; i<numparams; i++) {
2683 if (statusarray[i]==0) {
2684 struct parameterdescriptor *pd=task->descriptorarray[i];
2686 for(j=0; j<pd->numbertags; j++) {
2687 int slotid=pd->tagarray[2*j];
2688 if(statusarray[slotid+numparams]!=0) {
2689 processobject(parameter, i, pd, &iteratorcount, statusarray,
2691 processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
2698 /* Next do objects w/ unbound tags*/
2700 for(i=0; i<numparams; i++) {
2701 if (statusarray[i]==0) {
2702 struct parameterdescriptor *pd=task->descriptorarray[i];
2703 if (pd->numbertags>0) {
2704 processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
2705 processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
2711 /* Nothing with a tag enqueued */
2713 for(i=0; i<numparams; i++) {
2714 if (statusarray[i]==0) {
2715 struct parameterdescriptor *pd=task->descriptorarray[i];
2716 processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
2717 processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
2730 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
2733 for(i=0; i<numtasks[BAMBOO_NUM_OF_CORE]; i++) {
2734 struct taskdescriptor * task=taskarray[BAMBOO_NUM_OF_CORE][i];
2736 printf("%s\n", task->name);
2738 for(j=0; j<task->numParameters; j++) {
2739 struct parameterdescriptor *param=task->descriptorarray[j];
2740 struct parameterwrapper *parameter=param->queue;
2741 struct ObjectHash * set=parameter->objectset;
2742 struct ObjectIterator objit;
2744 printf(" Parameter %d\n", j);
2746 ObjectHashiterator(set, &objit);
2747 while(ObjhasNext(&objit)) {
2748 struct ___Object___ * obj=(struct ___Object___ *)Objkey(&objit);
2749 struct ___Object___ * tagptr=obj->___tags___;
2750 int nonfailed=Objdata4(&objit);
2751 int numflags=Objdata3(&objit);
2752 int flags=Objdata2(&objit);
2755 printf(" Contains %lx\n", obj);
2756 printf(" flag=%d\n", obj->flag);
2759 } else if (tagptr->type==TAGTYPE) {
2761 printf(" tag=%lx\n",tagptr);
2767 struct ArrayObject *ao=(struct ArrayObject *)tagptr;
2768 for(; tagindex<ao->___cachedCode___; tagindex++) {
2770 printf(" tag=%lx\n",ARRAYGET(ao, struct ___TagDescriptor___*,
2783 /* This function processes the task information to create queues for
2784 each parameter type. */
2786 void processtasks() {
2788 if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
2791 for(i=0; i<numtasks[BAMBOO_NUM_OF_CORE]; i++) {
2792 struct taskdescriptor * task=taskarray[BAMBOO_NUM_OF_CORE][i];
2795 /* Build objectsets */
2796 for(j=0; j<task->numParameters; j++) {
2797 struct parameterdescriptor *param=task->descriptorarray[j];
2798 struct parameterwrapper *parameter=param->queue;
2799 parameter->objectset=allocateObjectHash(10);
2800 parameter->task=task;
2803 /* Build iterators for parameters */
2804 for(j=0; j<task->numParameters; j++) {
2805 struct parameterdescriptor *param=task->descriptorarray[j];
2806 struct parameterwrapper *parameter=param->queue;
2807 builditerators(task, j, parameter);
2812 void toiReset(struct tagobjectiterator * it) {
2815 } else if (it->numtags>0) {
2818 ObjectHashiterator(it->objectset, &it->it);
2822 int toiHasNext(struct tagobjectiterator *it,
2823 void ** objectarray OPTARG(int * failed)) {
2826 /* Get object with tags */
2827 struct ___Object___ *obj=objectarray[it->tagobjectslot];
2828 struct ___Object___ *tagptr=obj->___tags___;
2829 if (tagptr->type==TAGTYPE) {
2830 if ((it->tagobjindex==0)&& /* First object */
2831 (it->tagid==((struct ___TagDescriptor___ *)tagptr)->flag)) /* Right tag type */
2836 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
2837 int tagindex=it->tagobjindex;
2838 for(; tagindex<ao->___cachedCode___; tagindex++) {
2839 struct ___TagDescriptor___ *td=
2840 ARRAYGET(ao, struct ___TagDescriptor___ *, tagindex);
2841 if (td->flag==it->tagid) {
2842 it->tagobjindex=tagindex; /* Found right type of tag */
2848 } else if (it->numtags>0) {
2849 /* Use tags to locate appropriate objects */
2850 struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
2851 struct ___Object___ *objptr=tag->flagptr;
2853 if (objptr->type!=OBJECTARRAYTYPE) {
2854 if (it->tagobjindex>0)
2856 if (!ObjectHashcontainskey(it->objectset, (int) objptr))
2858 for(i=1; i<it->numtags; i++) {
2859 struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]];
2860 if (!containstag(objptr,tag2))
2865 struct ArrayObject *ao=(struct ArrayObject *) objptr;
2868 for(tagindex=it->tagobjindex;tagindex<ao->___cachedCode___;tagindex++) {
2869 struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, tagindex);
2870 if (!ObjectHashcontainskey(it->objectset, (int) objptr))
2872 for(i=1; i<it->numtags; i++) {
2873 struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]];
2874 if (!containstag(objptr,tag2))
2877 it->tagobjindex=tagindex;
2882 it->tagobjindex=tagindex;
2886 return ObjhasNext(&it->it);
2890 int containstag(struct ___Object___ *ptr,
2891 struct ___TagDescriptor___ *tag) {
2893 struct ___Object___ * objptr=tag->flagptr;
2894 if (objptr->type==OBJECTARRAYTYPE) {
2895 struct ArrayObject *ao=(struct ArrayObject *)objptr;
2896 for(j=0; j<ao->___cachedCode___; j++) {
2897 if (ptr==ARRAYGET(ao, struct ___Object___*, j))
2905 void toiNext(struct tagobjectiterator *it,
2906 void ** objectarray OPTARG(int * failed)) {
2907 /* hasNext has all of the intelligence */
2910 /* Get object with tags */
2911 struct ___Object___ *obj=objectarray[it->tagobjectslot];
2912 struct ___Object___ *tagptr=obj->___tags___;
2913 if (tagptr->type==TAGTYPE) {
2915 objectarray[it->slot]=tagptr;
2917 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
2918 objectarray[it->slot]=
2919 ARRAYGET(ao, struct ___TagDescriptor___ *, it->tagobjindex++);
2921 } else if (it->numtags>0) {
2922 /* Use tags to locate appropriate objects */
2923 struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
2924 struct ___Object___ *objptr=tag->flagptr;
2925 if (objptr->type!=OBJECTARRAYTYPE) {
2927 objectarray[it->slot]=objptr;
2929 struct ArrayObject *ao=(struct ArrayObject *) objptr;
2930 objectarray[it->slot]=
2931 ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++);
2934 /* Iterate object */
2935 objectarray[it->slot]=(void *)Objkey(&it->it);