3 #include "structdefs.h"
5 #include "checkpoint.h"
7 #include "SimpleHash.h"
8 #include "GenericHashtable.h"
9 #include <sys/select.h>
10 #include <sys/types.h>
15 extern int injectfailures;
16 extern float failurechance;
21 #include "instrument.h"
24 struct genhashtable * activetasks;
26 struct parameterwrapper * objectqueues[NUMCLASSES];
28 struct genhashtable * failedtasks;
29 struct taskparamdescriptor * currtpd;
30 struct RuntimeHash * forward;
31 struct RuntimeHash * reverse;
33 int main(int argc, char **argv) {
35 GC_init(); // Initialize the garbage collector
41 initializeexithandler();
42 /* Create table for failed tasks */
43 failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
44 (int (*)(void *,void *)) &comparetpd);
45 /* Create queue of active tasks */
46 activetasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
47 (int (*)(void *,void *)) &comparetpd);
49 /* Process task information */
52 /* Create startup object */
53 createstartupobject(argc, argv);
55 /* Start executing the tasks */
59 void createstartupobject(int argc, char ** argv) {
62 /* Allocate startup object */
64 struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(NULL, STARTUPTYPE);
65 struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);
67 struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE);
68 struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);
70 /* Build array of strings */
71 startupobject->___parameters___=stringarray;
73 int length=strlen(argv[i]);
75 struct ___String___ *newstring=NewString(NULL, argv[i],length);
77 struct ___String___ *newstring=NewString(argv[i],length);
79 ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;
82 /* Set initialized flag for startup object */
84 flagorand(startupobject,1,0xFFFFFFFF,NULL,0);
85 enqueueObject(startupobject, objq4startupobj[corenum], numqueues4startupobj[corenum]);
87 flagorand(startupobject,1,0xFFFFFFFF);
88 enqueueObject(startupobject);
92 int hashCodetpd(struct taskparamdescriptor *ftd) {
93 int hash=(int)ftd->task;
95 for(i=0;i<ftd->numParameters;i++){
96 hash^=(int)ftd->parameterArray[i];
101 int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd2) {
103 if (ftd1->task!=ftd2->task)
105 for(i=0;i<ftd1->numParameters;i++)
106 if(ftd1->parameterArray[i]!=ftd2->parameterArray[i])
109 for(i=0;i<ftd1->numParameters;i++) {
110 if(ftd1->failed[i]!=ftd2->failed[i])
117 /* This function sets a tag. */
119 void tagset(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
121 void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
123 struct ___Object___ * tagptr=obj->___tags___;
125 obj->___tags___=(struct ___Object___ *)tagd;
127 /* Have to check if it is already set */
128 if (tagptr->type==TAGTYPE) {
129 struct ___TagDescriptor___ * td=(struct ___TagDescriptor___ *) tagptr;
133 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
134 struct ArrayObject * ao=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL);
135 obj=(struct ___Object___ *)ptrarray[2];
136 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
137 td=(struct ___TagDescriptor___ *) obj->___tags___;
139 struct ArrayObject * ao=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL);
141 ARRAYSET(ao, struct ___TagDescriptor___ *, 0, td);
142 ARRAYSET(ao, struct ___TagDescriptor___ *, 1, tagd);
143 obj->___tags___=(struct ___Object___ *) ao;
144 ao->___cachedCode___=2;
148 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
149 for(i=0;i<ao->___cachedCode___;i++) {
150 struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___*, i);
154 if (ao->___cachedCode___<ao->___length___) {
155 ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, tagd);
156 ao->___cachedCode___++;
159 int ptrarray[]={2,(int) ptr, (int) obj, (int) tagd};
160 struct ArrayObject * aonew=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
161 obj=(struct ___Object___ *)ptrarray[2];
162 tagd=(struct ___TagDescriptor___ *) ptrarray[3];
163 ao=(struct ArrayObject *)obj->___tags___;
165 struct ArrayObject * aonew=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
167 aonew->___cachedCode___=ao->___length___+1;
168 for(i=0;i<ao->___length___;i++) {
169 ARRAYSET(aonew, struct ___TagDescriptor___*, i, ARRAYGET(ao, struct ___TagDescriptor___*, i));
171 ARRAYSET(aonew, struct ___TagDescriptor___ *, ao->___length___, tagd);
177 struct ___Object___ * tagset=tagd->flagptr;
180 } else if (tagset->type!=OBJECTARRAYTYPE) {
182 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
183 struct ArrayObject * ao=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
184 obj=(struct ___Object___ *)ptrarray[2];
185 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
187 struct ArrayObject * ao=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
189 ARRAYSET(ao, struct ___Object___ *, 0, tagd->flagptr);
190 ARRAYSET(ao, struct ___Object___ *, 1, obj);
191 ao->___cachedCode___=2;
192 tagd->flagptr=(struct ___Object___ *)ao;
194 struct ArrayObject *ao=(struct ArrayObject *) tagset;
195 if (ao->___cachedCode___<ao->___length___) {
196 ARRAYSET(ao, struct ___Object___*, ao->___cachedCode___++, obj);
200 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
201 struct ArrayObject * aonew=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL+ao->___length___);
202 obj=(struct ___Object___ *)ptrarray[2];
203 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
204 ao=(struct ArrayObject *)tagd->flagptr;
206 struct ArrayObject * aonew=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
208 aonew->___cachedCode___=ao->___cachedCode___+1;
209 for(i=0;i<ao->___length___;i++) {
210 ARRAYSET(aonew, struct ___Object___*, i, ARRAYGET(ao, struct ___Object___*, i));
212 ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj);
213 tagd->flagptr=(struct ___Object___ *) aonew;
219 /* This function clears a tag. */
221 void tagclear(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
223 void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
225 /* We'll assume that tag is alway there.
226 Need to statically check for this of course. */
227 struct ___Object___ * tagptr=obj->___tags___;
229 if (tagptr->type==TAGTYPE) {
230 if ((struct ___TagDescriptor___ *)tagptr==tagd)
231 obj->___tags___=NULL;
233 printf("ERROR 1 in tagclear\n");
235 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
237 for(i=0;i<ao->___cachedCode___;i++) {
238 struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___ *, i);
240 ao->___cachedCode___--;
241 if (i<ao->___cachedCode___)
242 ARRAYSET(ao, struct ___TagDescriptor___ *, i, ARRAYGET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___));
243 ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, NULL);
244 if (ao->___cachedCode___==0)
245 obj->___tags___=NULL;
249 printf("ERROR 2 in tagclear\n");
253 struct ___Object___ *tagset=tagd->flagptr;
254 if (tagset->type!=OBJECTARRAYTYPE) {
258 printf("ERROR 3 in tagclear\n");
260 struct ArrayObject *ao=(struct ArrayObject *) tagset;
262 for(i=0;i<ao->___cachedCode___;i++) {
263 struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, i);
265 ao->___cachedCode___--;
266 if (i<ao->___cachedCode___)
267 ARRAYSET(ao, struct ___Object___ *, i, ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
268 ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL);
269 if (ao->___cachedCode___==0)
274 printf("ERROR 4 in tagclear\n");
281 /* This function allocates a new tag. */
283 struct ___TagDescriptor___ * allocate_tag(void *ptr, int index) {
284 struct ___TagDescriptor___ * v=(struct ___TagDescriptor___ *) mygcmalloc((struct garbagelist *) ptr, classsize[TAGTYPE]);
286 struct ___TagDescriptor___ * allocate_tag(int index) {
287 struct ___TagDescriptor___ * v=FREEMALLOC(classsize[TAGTYPE]);
296 /* This function updates the flag for object ptr. It or's the flag
297 with the or mask and and's it with the andmask. */
300 void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** queues, int length);
302 void flagbody(struct ___Object___ *ptr, int flag);
305 void enqueueoptional(struct ___Object___ * currobj, int numfailedfses, int * failedfses, struct taskdescriptor * task, int index);
308 int flagcomp(const int *val1, const int *val2) {
309 return (*val1)-(*val2);
313 void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length) {
315 void flagorand(void * ptr, int ormask, int andmask) {
318 struct ___Object___ * obj = (struct ___Object___ *)ptr;
319 if(obj->numfses){/*store the information about fses*/
320 int flag, i, j,counter, offset=0;
321 for(i=0;i<obj->numfses;i++) {
323 counter=obj->fses[offset++];
325 for(j=0;j<counter;j++) {
326 flag=obj->fses[offset];
327 obj->fses[offset++]=(flag|ormask)&andmask;
329 qsort(&obj->fses[oldoffset], sizeof(int), counter, (int (*)(const void *, const void *)) &flagcomp);
331 enqueueoptional(obj, 0, NULL, NULL, 0);
336 int oldflag=((int *)ptr)[1];
337 int flag=ormask|oldflag;
340 flagbody(ptr, flag, queues, length);
347 bool intflagorand(void * ptr, int ormask, int andmask) {
349 struct ___Object___ * obj = (struct ___Object___ *)ptr;
350 if(obj->numfses) {/*store the information about fses*/
351 int flag, i, j,counter, offset=0;
352 for(i=0;i<obj->numfses;i++) {
354 counter=obj->fses[offset++];
356 for(j=0;j<counter;j++) {
357 flag=obj->fses[offset];
358 obj->fses[offset++]=(flag|ormask)&andmask;
360 qsort(&obj->fses[oldoffset], sizeof(int), counter, (int (*)(const void *, const void *)) &flagcomp);
362 enqueueoptional(obj, 0, NULL, NULL, 0);
367 int oldflag=((int *)ptr)[1];
368 int flag=ormask|oldflag;
370 if (flag==oldflag) /* Don't do anything */
374 flagbody(ptr, flag, NULL, 0);
383 void flagorandinit(void * ptr, int ormask, int andmask) {
384 int oldflag=((int *)ptr)[1];
385 int flag=ormask|oldflag;
388 flagbody(ptr,flag,NULL,0);
395 void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** queues, int length) {
397 void flagbody(struct ___Object___ *ptr, int flag) {
400 struct parameterwrapper * flagptr = NULL;
403 struct parameterwrapper *flagptr=(struct parameterwrapper *)ptr->flagptr;
407 /*Remove object from all queues */
409 for(i = 0; i < length; ++i) {
412 while(flagptr!=NULL) {
417 struct parameterwrapper *next;
421 ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2);
422 ObjectHashremove(flagptr->objectset, (int)ptr);
423 if (enterflags!=NULL)
434 void enqueueObject(void * vptr, struct parameterwrapper ** queues, int length) {
436 void enqueueObject(void *vptr) {
438 struct ___Object___ *ptr = (struct ___Object___ *)vptr;
441 struct QueueItem *tmpptr;
443 struct parameterwrapper * parameter=NULL;
446 struct parameterwrapper * parameter=objectqueues[ptr->type];
449 struct parameterwrapper * prevptr=NULL;
450 struct ___Object___ *tagptr=ptr->___tags___;
452 /* Outer loop iterates through all parameter queues an object of
453 this type could be in. */
456 for(j = 0; j < length; ++j) {
457 parameter = queues[j];
459 while(parameter!=NULL) {
462 if (parameter->numbertags>0) {
464 goto nextloop;//that means the object has no tag but that param needs tag
465 else if(tagptr->type==TAGTYPE) {//one tag
466 struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr;
467 for(i=0;i<parameter->numbertags;i++) {
468 //slotid is parameter->tagarray[2*i];
469 int tagid=parameter->tagarray[2*i+1];
470 if (tagid!=tagptr->flag)
471 goto nextloop; /*We don't have this tag */
473 } else {//multiple tags
474 struct ArrayObject * ao=(struct ArrayObject *) tagptr;
475 for(i=0;i<parameter->numbertags;i++) {
476 //slotid is parameter->tagarray[2*i];
477 int tagid=parameter->tagarray[2*i+1];
479 for(j=0;j<ao->___cachedCode___;j++) {
480 if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag)
491 for(i=0;i<parameter->numberofterms;i++) {
492 int andmask=parameter->intarray[i*2];
493 int checkmask=parameter->intarray[i*2+1];
494 if ((ptr->flag&andmask)==checkmask) {
495 enqueuetasks(parameter, prevptr, ptr, NULL, 0);
504 parameter=parameter->next;
508 /*if(prevptr != NULL) {
509 ptr->flagptr=prevptr->arrayindex;
514 ptr->flagptr=prevptr;
521 void transferObject(void * obj, int targetcore) {
522 int type=((int *)obj)[0];
523 // if (type<NUMCLASSES) {
524 /* We have a normal object */
525 int size=classsize[type];
530 //struct ___Object___ * newobj=FREEMALLOC(size);
531 //memcpy(newobj, obj, size);
532 //obj->___localcopy___=newobj;
534 /* We have an array */
535 /*struct ArrayObject *ao=(struct ArrayObject *)obj;
536 int elementsize=classsize[type];
537 int length=ao->___length___;
538 int size=sizeof(struct ArrayObject)+length*elementsize;
539 struct ___Object___ * newobj=FREEMALLOC(size);
540 memcpy(newobj, obj, size);
541 obj->___localcopy___=newobj;
549 int checktags(struct ___Object___ * currobj, struct fsanalysiswrapper * fswrapper) {
551 struct ___Object___ * tagptr = currobj->___tags___;
552 if(fswrapper->numtags>0){
554 return 0; //that means the object has no tag but that param
556 else if(tagptr->type==TAGTYPE) {//one tag
557 if(fswrapper->numtags!=1)
558 return 0; //we don't have the right number of tags
559 struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr;
560 if (fswrapper->tags[0]!=tagptr->flag)
562 } else { //multiple tags
563 struct ArrayObject * ao=(struct ArrayObject *) tagptr;
567 if(ao->___length___!=fswrapper->numtags)
568 return 0;//we don't have the right number of tags
569 for(tag_counter=0;tag_counter<fswrapper->numtags;tag_counter++) {
570 int tagid=fswrapper->tags[tag_counter];
572 for(j=0;j<ao->___cachedCode___;j++) {
573 if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, tag_counter)->flag)
583 int getlength(int *flist, int len) {
587 int size=flist[count];
593 int * domergeor(int *flist1, int len1, int *flist2, int len2) {
594 int size1=getlength(flist1, len1);
595 int size2=getlength(flist2, len2);
596 int *merge=RUNMALLOC((size1+size2)*sizeof(int));
597 memcpy(merge, flist1, size1*sizeof(int));
598 memcpy(&merge[size1], flist2, size2*sizeof(int));
602 int domerge(int * flist1, int len1, int *flist2, int len2, int *merge) {
606 while(i<len1||j<len2) {
607 if (i<len1&&(j==len2||flist1[i]<flist2[j])) {
609 merge[count]=flist1[i];
613 } else if (j<len2&&(i==len1||flist2[j]<flist1[i])) {
615 merge[count]=flist2[j];
619 } else if (i<len1&&j<len2&&flist1[i]==flist2[j]) {
621 merge[count]=flist1[i];
631 /* Merge flags from ftlmerge into ftl. */
632 void mergeitems(struct failedtasklist *ftl, struct failedtasklist *ftlmerge) {
637 for(i=0;i<ftl->numflags;i++) {
638 int len=ftl->flags[offset++];
640 for(j=0;j<ftlmerge->numflags;j++) {
641 int lenmerge=ftlmerge->flags[offsetmerge++];
642 length+=1+domerge(&ftl->flags[offset],len,&ftlmerge->flags[offsetmerge],lenmerge, NULL);
643 offsetmerge+=lenmerge;
647 mergedlist=RUNMALLOC(sizeof(int)*length);
651 for(i=0;i<ftl->numflags;i++) {
652 int len=ftl->flags[offset++];
654 for(j=0;j<ftlmerge->numflags;j++) {
655 int lenmerge=ftlmerge->flags[offsetmerge++];
656 int size=domerge(&ftl->flags[offset],len,&ftlmerge->flags[offsetmerge],lenmerge,&mergedlist[length+1]);
657 mergedlist[length]=size;
662 ftl->flags=mergedlist;
663 ftl->numflags*=ftlmerge->numflags;
666 void mergefailedlists(struct failedtasklist **andlist, struct failedtasklist *list) {
667 struct failedtasklist *tmpptr;
668 while((*andlist)!=NULL) {
669 struct failedtasklist *searchftl=list;
670 while(searchftl!=NULL) {
671 if ((*andlist)->task==searchftl->task&&
672 (*andlist)->index==searchftl->index) {
673 mergeitems(*andlist, searchftl);
676 searchftl=searchftl->next;
678 if (searchftl==NULL) {
679 //didn't find andlist
681 *andlist=(*andlist)->next;//splice item out of list
682 RUNFREE(tmpptr->flags); //free the item
685 andlist=&((*andlist)->next); //iterate to next item
688 //free the list we're searching
691 RUNFREE(list->flags);
697 struct failedtasklist * processfailstate(struct classanalysiswrapper * classwrapper, struct taskdescriptor *task, int index, struct ___Object___ * currobj, int flagstate) {
698 struct failedtasklist *list=NULL;
700 struct fsanalysiswrapper *fswrapper=NULL;
701 for(h=0;h<classwrapper->numfsanalysiswrappers;h++) {
702 struct fsanalysiswrapper * tmp=classwrapper->fsanalysiswrapperarray[h];
703 if (tmp->flags==flagstate&&checktags(currobj, tmp)) {
704 //we only match exactly here
711 for(i=0;i<fswrapper->numtaskfailures;i++) {
713 struct taskfailure * taskfail=fswrapper->taskfailurearray[i];
714 if (taskfail->task==task&&taskfail->index==index) {
716 while(start<taskfail->numoptionaltaskdescriptors) {
717 struct taskdescriptor *currtask=NULL;
718 struct failedtasklist *tmpftl;
722 int numenterflags, offset;
723 struct parameterwrapper *pw;
724 for(j=start;j<taskfail->numoptionaltaskdescriptors;j++) {
725 struct optionaltaskdescriptor *otd=taskfail->optionaltaskdescriptorarray[j];
728 currindex=otd->index;
729 } else if (currtask!=otd->task||currindex!=otd->index)
731 totallength+=otd->numenterflags;
733 pw=currtask->descriptorarray[currindex]->queue;
734 enterflags=RUNMALLOC(totallength*sizeof(int));
735 numenterflags=j-start;
737 for(start;start<j;start++) {
738 struct optionaltaskdescriptor *otd=taskfail->optionaltaskdescriptorarray[start];
739 enterflags[offset++]=otd->numenterflags;
740 memcpy(&enterflags[offset], otd->enterflags, otd->numenterflags*sizeof(int));
741 offset+=otd->numenterflags;
743 tmpftl=RUNMALLOC(sizeof(struct failedtasklist));
745 tmpftl->task=currtask;
746 tmpftl->numflags=numenterflags;
747 tmpftl->flags=enterflags;
755 struct failedtasklist * processnormfailstate(struct classanalysiswrapper * classwrapper, struct ___Object___ * currobj, int flagstate) {
756 struct failedtasklist *list=NULL;
759 struct fsanalysiswrapper *fswrapper=NULL;
760 for(h=0;h<classwrapper->numfsanalysiswrappers;h++) {
761 struct fsanalysiswrapper * tmp=classwrapper->fsanalysiswrapperarray[h];
762 if (tmp->flags==flagstate&&checktags(currobj, tmp)) {
763 //we only match exactly here
771 while(start<fswrapper->numoptionaltaskdescriptors) {
772 struct taskdescriptor *currtask=NULL;
773 struct failedtasklist *tmpftl;
778 int numenterflags, offset;
779 struct parameterwrapper *pw;
780 for(j=start;j<fswrapper->numoptionaltaskdescriptors;j++) {
781 struct optionaltaskdescriptor *otd=fswrapper->optionaltaskdescriptorarray[j];
784 currindex=otd->index;
785 } else if (currtask!=otd->task||currindex!=otd->index)
787 totallength+=otd->numenterflags;
789 pw=currtask->descriptorarray[currindex]->queue;
790 enterflags=RUNMALLOC(totallength*sizeof(int));
791 numenterflags=j-start;
793 for(start;start<j;start++) {
794 struct optionaltaskdescriptor *otd=fswrapper->optionaltaskdescriptorarray[start];
795 enterflags[offset++]=otd->numenterflags;
796 memcpy(&enterflags[offset], otd->enterflags, otd->numenterflags*sizeof(int));
797 offset+=otd->numenterflags;
799 tmpftl=RUNMALLOC(sizeof(struct failedtasklist));
801 tmpftl->task=currtask;
802 tmpftl->numflags=numenterflags;
803 tmpftl->flags=enterflags;
811 void enqueuelist(struct ___Object___ * currobj, struct failedtasklist * andlist) {
812 while(andlist!=NULL) {
813 struct failedtasklist *tmp=andlist;
814 struct parameterwrapper *pw=andlist->task->descriptorarray[andlist->index]->queue;
815 struct parmaeterwrapper *next;
820 if (enqueuetasks(pw, currobj->flagptr, currobj, tmp->flags, tmp->numflags))
823 andlist=andlist->next;
828 void enqueueoptional(struct ___Object___ * currobj, int numfailedfses, int * failedfses, struct taskdescriptor * task, int index) {
829 struct classanalysiswrapper * classwrapper=NULL;
831 /*test what optionaltaskdescriptors are available, find the class
833 if (classanalysiswrapperarray[currobj->type]!=NULL) {
834 classwrapper = classanalysiswrapperarray[currobj->type];
839 /* We have a failure */
840 if (failedfses==NULL) {
841 /* Failed in normal state */
842 /*first time the method is invoked*/
844 struct fsanalysiswrapper *fswrapper=NULL;
846 for(h=0;h<classwrapper->numfsanalysiswrappers;h++) {
847 struct fsanalysiswrapper * tmp=classwrapper->fsanalysiswrapperarray[h];
848 if (tmp->flags==currobj->flag&&checktags(currobj, tmp)) {
849 //we only match exactly here
854 if(fswrapper==NULL) //nothing to do in this state
856 for(i=0;i<fswrapper->numtaskfailures;i++) {
858 struct taskfailure * taskfail=fswrapper->taskfailurearray[i];
859 if (taskfail->task==task&&taskfail->index==index) {
861 while(start<taskfail->numoptionaltaskdescriptors) {
862 struct taskdescriptor *currtask=NULL;
866 int numenterflags, offset;
867 struct parameterwrapper *pw;
868 for(j=start;j<taskfail->numoptionaltaskdescriptors;j++) {
869 struct optionaltaskdescriptor *otd=taskfail->optionaltaskdescriptorarray[j];
872 currindex=otd->index;
873 } else if (currtask!=otd->task||currindex!=otd->index)
875 totallength+=otd->numenterflags;//1 is to store the lengths
877 pw=currtask->descriptorarray[currindex]->queue;
878 enterflags=RUNMALLOC((totallength+numenterflags)*sizeof(int));
879 numenterflags=j-start;
882 for(start;start<j;start++) {
883 struct optionaltaskdescriptor *otd=taskfail->optionaltaskdescriptorarray[start];
884 enterflags[offset++]=otd->numenterflags;
885 memcpy(&enterflags[offset], otd->enterflags, otd->numenterflags*sizeof(int));
886 offset+=otd->numenterflags;
889 if (enqueuetasks(pw, currobj->flagptr, currobj, enterflags, numenterflags))
895 /* Failed in failed state */
898 for(i=0;i<numfailedfses;i++) {
899 int numfses=failedfses[offset++];
901 struct failedtasklist *andlist=NULL;
902 for(j=0;j<numfses;j++) {
903 int flagstate=failedfses[offset++];
904 struct failedtasklist *currlist=processfailstate(classwrapper, task, index, currobj, flagstate);
908 mergefailedlists(&andlist, currlist);
910 enqueuelist(currobj, andlist);
914 /* No failure, but we are in a failed state */
915 struct parameterwrapper *flagptr=(struct parameterwrapper *)currobj->flagptr;
917 /*Remove object from all queues */
918 while(flagptr!=NULL) {
919 struct parameterwrapper *next;
922 ObjectHashget(flagptr->objectset, (int) currobj, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2);
923 ObjectHashremove(flagptr->objectset, (int)currobj);
924 if (enterflags!=NULL)
929 /* Failed in failed state */
932 for(i=0;i<currobj->numfses;i++) {
933 int numfses=currobj->fses[offset++];
935 struct failedtasklist *andlist=NULL;
936 for(j=0;j<numfses;j++) {
937 int flagstate=currobj->fses[offset++];
938 struct failedtasklist *currlist=processnormfailstate(classwrapper, currobj, flagstate);
942 mergefailedlists(&andlist, currlist);
944 enqueuelist(currobj, andlist);
952 int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags) {
953 void * taskpointerarray[MAXTASKPARAMS];
955 int failed[MAXTASKPARAMS];
958 int numparams=parameter->task->numParameters;
959 int numiterators=parameter->task->numTotal-1;
964 struct taskdescriptor * task=parameter->task;
967 if (ObjectHashcontainskey(parameter->objectset, (int) ptr)) {
968 /* The object is already here...or it with the existing item */
974 ObjectHashget(parameter->objectset, (int) ptr, & oldptr, (int *) &oldflags, &oldnumflags, &oldstatus);
975 mergedflags=domergeor(oldflags, oldnumflags, enterflags, numenterflags);
976 ObjectHashupdate(parameter->objectset, (int) ptr, oldptr, mergedflags, oldnumflags+numenterflags, oldstatus||(enterflags==NULL));
981 //only add if truly needed
991 /*int arrayindex = 0;
992 if(prevptr != NULL) {
993 arrayindex = prevptr->arrayindex;
995 ObjectHashadd(parameter->objectset, (int) ptr, 0, (int) enterflags, numenterflags, enterflags==NULL);//this add the object to parameterwrapper
997 ObjectHashadd(parameter->objectset, (int) ptr, (int) prevptr, (int) enterflags, numenterflags, enterflags==NULL);//this add the object to parameterwrapper
1003 /* Add enqueued object to parameter vector */
1004 taskpointerarray[parameter->slot]=ptr;
1006 failed[parameter->slot]=(enterflags!=NULL);
1009 /* Reset iterators */
1010 for(j=0;j<numiterators;j++) {
1011 toiReset(¶meter->iterators[j]);
1014 /* Find initial state */
1015 for(j=0;j<numiterators;j++) {
1017 if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)))
1018 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
1020 /* Need to backtrack */
1021 toiReset(¶meter->iterators[j]);
1025 /* Nothing to enqueue */
1032 /* Enqueue current state */
1034 struct taskparamdescriptor *tpd=RUNMALLOC(sizeof(struct taskparamdescriptor));
1036 tpd->numParameters=numiterators+1;
1037 tpd->parameterArray=RUNMALLOC(sizeof(void *)*(numiterators+1));
1039 tpd->failed=RUNMALLOC(sizeof(int)*(numiterators+1));
1041 for(j=0;j<=numiterators;j++){
1042 tpd->parameterArray[j]=taskpointerarray[j];//store the actual parameters
1044 tpd->failed[j]=failed[j];
1045 if (failed[j]!=0&&failed[j]!=1) {
1051 if ((!gencontains(failedtasks, tpd)&&!gencontains(activetasks,tpd))) {
1052 genputtable(activetasks, tpd, tpd);
1054 RUNFREE(tpd->parameterArray);
1056 RUNFREE(tpd->failed);
1061 /* This loop iterates to the next parameter combination */
1062 if (numiterators==0)
1065 for(j=numiterators-1; j<numiterators;j++) {
1067 if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)))
1068 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
1070 /* Need to backtrack */
1071 toiReset(¶meter->iterators[j]);
1075 /* Nothing more to enqueue */
1083 /* Handler for signals. The signals catch null pointer errors and
1084 arithmatic errors. */
1086 void myhandler(int sig, siginfo_t *info, void *uap) {
1089 printf("sig=%d\n",sig);
1092 sigemptyset(&toclear);
1093 sigaddset(&toclear, sig);
1094 sigprocmask(SIG_UNBLOCK, &toclear,NULL);
1095 longjmp(error_handler,1);
1100 struct RuntimeHash *fdtoobject;
1102 void addreadfd(int fd) {
1105 FD_SET(fd, &readfds);
1108 void removereadfd(int fd) {
1109 FD_CLR(fd, &readfds);
1110 if (maxreadfd==(fd+1)) {
1112 while(maxreadfd>0&&!FD_ISSET(maxreadfd-1, &readfds))
1124 int * fsescopy(int *src, int len) {
1128 dst=RUNMALLOC(len*sizeof(int));
1129 memcpy(dst, src, len*sizeof(int));
1134 void executetasks() {
1135 void * taskpointerarray[MAXTASKPARAMS+OFFSET];
1137 int * fsesarray[MAXTASKPARAMS];
1138 int * oldfsesarray[MAXTASKPARAMS];
1139 int numfsesarray[MAXTASKPARAMS];
1142 /* Set up signal handlers */
1143 struct sigaction sig;
1144 sig.sa_sigaction=&myhandler;
1145 sig.sa_flags=SA_SIGINFO;
1146 sigemptyset(&sig.sa_mask);
1148 /* Catch bus errors, segmentation faults, and floating point exceptions*/
1149 sigaction(SIGBUS,&sig,0);
1150 sigaction(SIGSEGV,&sig,0);
1151 sigaction(SIGFPE,&sig,0);
1152 sigaction(SIGPIPE,&sig,0);
1157 fdtoobject=allocateRuntimeHash(100);
1159 /* Map first block of memory to protected, anonymous page */
1160 mmap(0, 0x1000, 0, MAP_SHARED|MAP_FIXED|MAP_ANON, -1, 0);
1163 while((hashsize(activetasks)>0)||(maxreadfd>0)) {
1165 /* Check if any filedescriptors have IO pending */
1168 struct timeval timeout={0,0};
1172 numselect=select(maxreadfd, &tmpreadfds, NULL, NULL, &timeout);
1174 /* Process ready fd's */
1176 for(fd=0;fd<maxreadfd;fd++) {
1177 if (FD_ISSET(fd, &tmpreadfds)) {
1178 /* Set ready flag on object */
1180 // printf("Setting fd %d\n",fd);
1181 if (RuntimeHashget(fdtoobject, fd,(int *) &objptr)) {
1182 if(intflagorand(objptr,1,0xFFFFFFFF)) { /* Set the first flag to 1 */
1184 enqueueObject(objptr, NULL, 0);
1186 enqueueObject(objptr);
1195 /* See if there are any active tasks */
1196 if (hashsize(activetasks)>0) {
1198 currtpd=(struct taskparamdescriptor *) getfirstkey(activetasks);
1199 genfreekey(activetasks, currtpd);
1201 /* Check if this task has failed, allow a task that contains optional objects to fire */
1202 if (gencontains(failedtasks, currtpd)) {
1203 // Free up task parameter descriptor
1204 RUNFREE(currtpd->parameterArray);
1206 RUNFREE(currtpd->failed);
1211 int numparams=currtpd->task->numParameters;
1212 int numtotal=currtpd->task->numTotal;
1214 /* Make sure that the parameters are still in the queues */
1215 for(i=0;i<numparams;i++) {
1216 void * parameter=currtpd->parameterArray[i];
1217 struct parameterdescriptor * pd=currtpd->task->descriptorarray[i];
1218 struct parameterwrapper *pw=(struct parameterwrapper *) pd->queue;
1220 /* Check that object is still in queue */
1223 int UNUSED, UNUSED2;
1225 int numflags, isnonfailed;
1226 int failed=currtpd->failed[i];
1227 if (!ObjectHashget(pw->objectset, (int) parameter, &UNUSED, (int *) &flags, &numflags, &isnonfailed)) {
1228 RUNFREE(currtpd->parameterArray);
1229 RUNFREE(currtpd->failed);
1233 if (failed&&(flags!=NULL)) {
1236 numfsesarray[i]=numflags;
1237 } else if (!failed && isnonfailed) {
1238 //Non-failed parameter
1242 RUNFREE(currtpd->parameterArray);
1243 RUNFREE(currtpd->failed);
1251 if (!ObjectHashcontainskey(pw->objectset, (int) parameter)) {
1252 RUNFREE(currtpd->parameterArray);
1260 /* Check that object still has necessary tags */
1261 for(j=0;j<pd->numbertags;j++) {
1262 int slotid=pd->tagarray[2*j]+numparams;
1263 struct ___TagDescriptor___ *tagd=currtpd->parameterArray[slotid];
1264 if (!containstag(parameter, tagd)) {
1265 RUNFREE(currtpd->parameterArray);
1267 RUNFREE(currtpd->failed);
1274 taskpointerarray[i+OFFSET]=parameter;
1277 for(;i<numtotal;i++) {
1278 taskpointerarray[i+OFFSET]=currtpd->parameterArray[i];
1282 /* Checkpoint the state */
1283 forward=allocateRuntimeHash(100);
1284 reverse=allocateRuntimeHash(100);
1285 void ** checkpoint=makecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, forward, reverse);
1287 if (x=setjmp(error_handler)) {
1291 printf("Fatal Error=%d, Recovering!\n",x);
1293 genputtable(failedtasks,currtpd,currtpd);
1294 restorecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, checkpoint, forward, reverse);
1297 for(counter=0; counter<currtpd->task->numParameters; counter++){
1299 enqueueoptional(currtpd->parameterArray[counter], numfsesarray[counter], fsesarray[counter], currtpd->task, counter);
1302 if (fsesarray[counter]!=NULL)
1303 RUNFREE(fsesarray[counter]);
1306 freeRuntimeHash(forward);
1307 freeRuntimeHash(reverse);
1312 if (injectfailures) {
1313 if ((((double)random())/RAND_MAX)<failurechance) {
1314 printf("\nINJECTING TASK FAILURE to %s\n", currtpd->task->name);
1315 longjmp(error_handler,10);
1318 /* Actually call task */
1320 ((int *)taskpointerarray)[0]=currtpd->numParameters;
1321 taskpointerarray[1]=NULL;
1324 //get the task flags set
1325 for(i=0;i<numparams;i++) {
1326 oldfsesarray[i]=((struct ___Object___ *)taskpointerarray[i+OFFSET])->fses;
1327 fsesarray[i]=fsescopy(fsesarray[i], numfsesarray[i]);
1328 ((struct ___Object___ *)taskpointerarray[i+OFFSET])->fses=fsesarray[i];
1332 printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
1333 ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray);
1334 printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
1336 ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray);
1339 for(i=0;i<numparams;i++) {
1341 if(oldfsesarray[i]!=NULL)
1342 RUNFREE(oldfsesarray[i]);
1346 freeRuntimeHash(forward);
1347 freeRuntimeHash(reverse);
1349 // Free up task parameter descriptor
1350 RUNFREE(currtpd->parameterArray);
1352 RUNFREE(currtpd->failed);
1363 /* This function processes an objects tags */
1364 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams) {
1367 for(i=0;i<pd->numbertags;i++) {
1368 int slotid=pd->tagarray[2*i];
1369 int tagid=pd->tagarray[2*i+1];
1371 if (statusarray[slotid+numparams]==0) {
1372 parameter->iterators[*iteratorcount].istag=1;
1373 parameter->iterators[*iteratorcount].tagid=tagid;
1374 parameter->iterators[*iteratorcount].slot=slotid+numparams;
1375 parameter->iterators[*iteratorcount].tagobjectslot=index;
1376 statusarray[slotid+numparams]=1;
1383 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams) {
1386 struct ObjectHash * objectset=((struct parameterwrapper *)pd->queue)->objectset;
1388 parameter->iterators[*iteratorcount].istag=0;
1389 parameter->iterators[*iteratorcount].slot=index;
1390 parameter->iterators[*iteratorcount].objectset=objectset;
1391 statusarray[index]=1;
1393 for(i=0;i<pd->numbertags;i++) {
1394 int slotid=pd->tagarray[2*i];
1395 int tagid=pd->tagarray[2*i+1];
1396 if (statusarray[slotid+numparams]!=0) {
1397 /* This tag has already been enqueued, use it to narrow search */
1398 parameter->iterators[*iteratorcount].tagbindings[tagcount]=slotid+numparams;
1402 parameter->iterators[*iteratorcount].numtags=tagcount;
1407 /* This function builds the iterators for a task & parameter */
1409 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter) {
1410 int statusarray[MAXTASKPARAMS];
1412 int numparams=task->numParameters;
1413 int iteratorcount=0;
1414 for(i=0;i<MAXTASKPARAMS;i++) statusarray[i]=0;
1416 statusarray[index]=1; /* Initial parameter */
1417 /* Process tags for initial iterator */
1419 processtags(task->descriptorarray[index], index, parameter, & iteratorcount, statusarray, numparams);
1423 /* Check for objects with existing tags */
1424 for(i=0;i<numparams;i++) {
1425 if (statusarray[i]==0) {
1426 struct parameterdescriptor *pd=task->descriptorarray[i];
1428 for(j=0;j<pd->numbertags;j++) {
1429 int slotid=pd->tagarray[2*j];
1430 if(statusarray[slotid+numparams]!=0) {
1431 processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
1432 processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
1439 /* Next do objects w/ unbound tags*/
1441 for(i=0;i<numparams;i++) {
1442 if (statusarray[i]==0) {
1443 struct parameterdescriptor *pd=task->descriptorarray[i];
1444 if (pd->numbertags>0) {
1445 processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
1446 processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
1452 /* Nothing with a tag enqueued */
1454 for(i=0;i<numparams;i++) {
1455 if (statusarray[i]==0) {
1456 struct parameterdescriptor *pd=task->descriptorarray[i];
1457 processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
1458 processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
1472 for(i=0;i<numtasks[corenum];i++) {
1473 struct taskdescriptor * task=taskarray[corenum][i];
1475 for(i=0;i<numtasks;i++) {
1476 struct taskdescriptor * task=taskarray[i];
1478 printf("%s\n", task->name);
1479 for(j=0;j<task->numParameters;j++) {
1480 struct parameterdescriptor *param=task->descriptorarray[j];
1481 struct parameterwrapper *parameter=param->queue;
1482 struct ObjectHash * set=parameter->objectset;
1483 struct ObjectIterator objit;
1484 printf(" Parameter %d\n", j);
1485 ObjectHashiterator(set, &objit);
1486 while(ObjhasNext(&objit)) {
1487 struct ___Object___ * obj=(struct ___Object___ *)Objkey(&objit);
1488 struct ___Object___ * tagptr=obj->___tags___;
1489 int nonfailed=Objdata4(&objit);
1490 int numflags=Objdata3(&objit);
1491 int flags=Objdata2(&objit);
1493 printf(" Contains %lx\n", obj);
1494 printf(" flag=%d\n", obj->flag);
1496 printf(" flagsstored=%x\n",flags);
1497 printf(" numflags=%d\n", numflags);
1498 printf(" nonfailed=%d\n",nonfailed);
1501 } else if (tagptr->type==TAGTYPE) {
1502 printf(" tag=%lx\n",tagptr);
1505 struct ArrayObject *ao=(struct ArrayObject *)tagptr;
1506 for(;tagindex<ao->___cachedCode___;tagindex++) {
1507 printf(" tag=%lx\n",ARRAYGET(ao, struct ___TagDescriptor___*, tagindex));
1516 /* This function processes the task information to create queues for
1517 each parameter type. */
1519 void processtasks() {
1522 for(i=0;i<numtasks[corenum];i++) {
1523 struct taskdescriptor * task=taskarray[corenum][i];
1525 for(i=0;i<numtasks;i++) {
1526 struct taskdescriptor * task=taskarray[i];
1531 for(j=0;j<task->numParameters;j++) {
1532 struct parameterdescriptor *param=task->descriptorarray[j];
1533 struct parameterwrapper * parameter=RUNMALLOC(sizeof(struct parameterwrapper));
1534 struct parameterwrapper ** ptr=&objectqueues[param->type];
1536 param->queue=parameter;
1537 parameter->objectset=allocateObjectHash(10);
1538 parameter->numberofterms=param->numberterms;
1539 parameter->intarray=param->intarray;
1540 parameter->numbertags=param->numbertags;
1541 parameter->tagarray=param->tagarray;
1542 parameter->task=task;
1544 /* Link new queue in */
1546 ptr=&((*ptr)->next);
1551 /* Build iterators for parameters */
1552 for(j=0;j<task->numParameters;j++) {
1553 struct parameterdescriptor *param=task->descriptorarray[j];
1554 struct parameterwrapper *parameter=param->queue;
1556 parameter->objectset=allocateObjectHash(10);
1557 parameter->task=task;
1559 builditerators(task, j, parameter);
1564 void toiReset(struct tagobjectiterator * it) {
1567 } else if (it->numtags>0) {
1573 ObjectHashiterator(it->objectset, &it->it);
1580 int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed)) {
1583 /* Get object with tags */
1584 struct ___Object___ *obj=objectarray[it->tagobjectslot];
1585 struct ___Object___ *tagptr=obj->___tags___;
1586 if (tagptr->type==TAGTYPE) {
1587 if ((it->tagobjindex==0)&& /* First object */
1588 (it->tagid==((struct ___TagDescriptor___ *)tagptr)->flag)) /* Right tag type */
1593 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
1594 int tagindex=it->tagobjindex;
1595 for(;tagindex<ao->___cachedCode___;tagindex++) {
1596 struct ___TagDescriptor___ *td=ARRAYGET(ao, struct ___TagDescriptor___ *, tagindex);
1597 if (td->flag==it->tagid) {
1598 it->tagobjindex=tagindex; /* Found right type of tag */
1604 } else if (it->numtags>0) {
1605 /* Use tags to locate appropriate objects */
1606 struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
1607 struct ___Object___ *objptr=tag->flagptr;
1609 if (objptr->type!=OBJECTARRAYTYPE) {
1610 if (it->tagobjindex>0)
1612 if (!ObjectHashcontainskey(it->objectset, (int) objptr))
1614 for(i=1;i<it->numtags;i++) {
1615 struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]];
1616 if (!containstag(objptr,tag2))
1620 if (it->failedstate==1) {
1621 int UNUSED, UNUSED2;
1624 ObjectHashget(it->objectset, (int) objptr, &UNUSED, (int *) &flags, &UNUSED2, &isnonfailed);
1633 int UNUSED, UNUSED2;
1636 ObjectHashget(it->objectset, (int) objptr, &UNUSED, (int *) &flags, &UNUSED2, &isnonfailed);
1645 struct ArrayObject *ao=(struct ArrayObject *) objptr;
1649 if (it->failedstate==1) {
1650 int UNUSED, UNUSED2;
1653 struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, it->tagobjindex);
1654 ObjectHashget(it->objectset, (int) objptr, &UNUSED, (int *) &flags, &UNUSED2, &isnonfailed);
1663 for(tagindex=it->tagobjindex;tagindex<ao->___cachedCode___;tagindex++) {
1664 struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, tagindex);
1665 if (!ObjectHashcontainskey(it->objectset, (int) objptr))
1667 for(i=1;i<it->numtags;i++) {
1668 struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]];
1669 if (!containstag(objptr,tag2))
1674 int UNUSED, UNUSED2;
1675 int flags, isnonfailed;
1676 struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, tagindex);
1677 ObjectHashget(it->objectset, (int) objptr, &UNUSED, &flags, &UNUSED2, &isnonfailed);
1683 it->tagobjindex=tagindex;
1688 it->tagobjindex=tagindex;
1693 if (it->failedstate==1) {
1694 if (Objdata2(&it->it))
1701 if (ObjhasNext(&it->it)) {
1702 if (!Objdata4(&it->it)) {
1710 return ObjhasNext(&it->it);
1715 int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag) {
1717 struct ___Object___ * objptr=tag->flagptr;
1718 if (objptr->type==OBJECTARRAYTYPE) {
1719 struct ArrayObject *ao=(struct ArrayObject *)objptr;
1720 for(j=0;j<ao->___cachedCode___;j++) {
1721 if (ptr==ARRAYGET(ao, struct ___Object___*, j))
1729 void toiNext(struct tagobjectiterator *it , void ** objectarray OPTARG(int * failed)) {
1730 /* hasNext has all of the intelligence */
1733 /* Get object with tags */
1734 struct ___Object___ *obj=objectarray[it->tagobjectslot];
1735 struct ___Object___ *tagptr=obj->___tags___;
1737 failed[it->slot]=0; //have to set it to something
1739 if (tagptr->type==TAGTYPE) {
1741 objectarray[it->slot]=tagptr;
1743 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
1744 objectarray[it->slot]=ARRAYGET(ao, struct ___TagDescriptor___ *, it->tagobjindex++);
1746 } else if (it->numtags>0) {
1747 /* Use tags to locate appropriate objects */
1748 struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
1749 struct ___Object___ *objptr=tag->flagptr;
1750 if (objptr->type!=OBJECTARRAYTYPE) {
1752 failed[it->slot]=it->failedstate;
1753 objectarray[it->slot]=objptr;
1754 if (it->failedstate==0) {
1762 objectarray[it->slot]=objptr;
1765 struct ArrayObject *ao=(struct ArrayObject *) objptr;
1767 failed[it->slot]=it->failedstate;
1768 objectarray[it->slot]=ARRAYGET(ao, struct ___Object___ *, it->tagobjindex);
1769 if (it->failedstate==0) {
1776 objectarray[it->slot]=ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++);
1780 /* Iterate object */
1781 objectarray[it->slot]=(void *)Objkey(&it->it);
1783 failed[it->slot]=it->failedstate;
1784 if (it->failedstate==0) {