4 #include "multicoreruntime.h"
5 #include "runtime_arch.h"
6 #include "GenericHashtable.h"
7 #include "structdefs.h"
8 #include "methodheaders.h"
16 #define INLINE inline __attribute__((always_inline))
17 #endif // #ifndef INLINE
19 extern int classsize[];
20 extern int typearray[];
21 extern int typearray2[];
22 extern int* supertypes[];
25 extern struct genhashtable * activetasks;
29 extern unsigned int gcmem_mixed_threshold;
30 extern unsigned int gcmem_mixed_usedmem;
32 #endif // MULTICORE_GC
39 int instanceofif(int otype, int type) {
46 int num = supertypes[otype][0];
47 for(int i = 1; i < num + 1; i++) {
48 int t = supertypes[otype][i];
49 if(instanceofif(t, type) == 1) {
56 int instanceof(struct ___Object___ *ptr, int type) {
61 if(instanceofif(i, type) == 1) {
68 i=typearray2[i-NUMCLASSES];
74 void initializeexithandler() {
77 /* This function inject failures */
79 void injectinstructionfailure() {
80 // not supported in MULTICORE version
84 #ifdef D___Double______nativeparsedouble____L___String___
85 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
86 int length=VAR(___str___)->___count___;
87 int maxlength=(length>60) ? 60 : length;
88 char str[maxlength+1];
89 struct ArrayObject * chararray=VAR(___str___)->___value___;
91 int offset=VAR(___str___)->___offset___;
92 for(i=0; i<maxlength; i++) {
93 str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
96 double d=0.0; //atof(str); TODO Unimplemented nativeparsedoulbe
101 #ifdef D___Double______nativeparsedouble_____AR_B_I_I
102 double CALL23(___Double______nativeparsedouble_____AR_B_I_I, int start, int length,int start,int length,struct ArrayObject * ___str___) {
103 int maxlength=(length>60)?60:length;
104 char str[maxlength+1];
105 struct ArrayObject * bytearray=VAR(___str___);
107 for(i=0; i<maxlength; i++) {
108 str[i]=(((char *)&bytearray->___length___)+sizeof(int))[i+start];
111 double d=0.0; //atof(str); TODO Unimplemented nativeparsedouble
127 #ifdef D___Double______doubleToRawLongBits____D
128 long long CALL11(___Double______doubleToRawLongBits____D, double ___value___, double ___value___) {
132 #if defined(__IEEE_BYTES_LITTLE_ENDIAN)
133 /* On little endian ARM processors when using FPA, word order of
134 doubles is still big endian. So take that into account here. When
135 using VFP, word order of doubles follows byte order. */
137 #define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff))
139 val.j = SWAP_DOUBLE(val.j);
146 #ifdef D___Double______longBitsToDouble____J
147 double CALL11(___Double______longBitsToDouble____J, long long ___bits___, long long ___bits___) {
151 #if defined(__IEEE_BYTES_LITTLE_ENDIAN)
153 #define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff))
155 val.j = SWAP_DOUBLE(val.j);
162 #ifdef D___String______convertdoubletochar____D__AR_C
163 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject * ___chararray___) {
164 int length=VAR(___chararray___)->___length___;
167 int num=snprintf(str, length, "%f",___val___);
170 for(i=0; i<length; i++) {
171 ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
176 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
181 #ifdef D___System______deepArrayCopy____L___Object____L___Object___
182 void deepArrayCopy(struct ___Object___ * dst, struct ___Object___ * src) {
183 int dsttype=((int *)dst)[0];
184 int srctype=((int *)src)[0];
185 if (dsttype<NUMCLASSES||srctype<NUMCLASSES||srctype!=dsttype)
187 struct ArrayObject *aodst=(struct ArrayObject *)dst;
188 struct ArrayObject *aosrc=(struct ArrayObject *)src;
189 int dstlength=aodst->___length___;
190 int srclength=aosrc->___length___;
191 if (dstlength!=srclength)
193 unsigned INTPTR *pointer=pointerarray[srctype];
195 int elementsize=classsize[srctype];
196 int size=srclength*elementsize;
198 memcpy(((char *)&aodst->___length___)+sizeof(int) , ((char *)&aosrc->___length___)+sizeof(int), size);
202 for(i=0;i<srclength;i++) {
203 struct ___Object___ * ptr=((struct ___Object___**)(((char*) &aosrc->___length___)+sizeof(int)))[i];
204 int ptrtype=((int *)ptr)[0];
205 if (ptrtype>=NUMCLASSES) {
206 struct ___Object___ * dstptr=((struct ___Object___**)(((char*) &aodst->___length___)+sizeof(int)))[i];
207 deepArrayCopy(dstptr,ptr);
210 ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i]=ptr;
216 void CALL02(___System______deepArrayCopy____L___Object____L___Object___, struct ___Object___ * ___dst___, struct ___Object___ * ___src___) {
217 deepArrayCopy(VAR(___dst___), VAR(___src___));
221 #ifdef D___System______arraycopy____L___Object____I_L___Object____I_I
222 void arraycopy(struct ___Object___ *src, int srcPos, struct ___Object___ *dst, int destPos, int length) {
223 int dsttype=((int *)dst)[0];
224 int srctype=((int *)src)[0];
226 //not an array or type mismatch
227 if (dsttype<NUMCLASSES||srctype<NUMCLASSES/*||srctype!=dsttype*/)
230 struct ArrayObject *aodst=(struct ArrayObject *)dst;
231 struct ArrayObject *aosrc=(struct ArrayObject *)src;
232 int dstlength=aodst->___length___;
233 int srclength=aosrc->___length___;
237 if (srcPos+length>srclength)
239 if (destPos+length>dstlength)
242 unsigned INTPTR *pointer=pointerarray[srctype];
244 int elementsize=classsize[srctype];
245 int size=length*elementsize;
247 memcpy(((char *)&aodst->___length___)+sizeof(int)+destPos*elementsize, ((char *)&aosrc->___length___)+sizeof(int)+srcPos*elementsize, size);
251 for(i=0;i<length;i++) {
252 struct ___Object___ * ptr=((struct ___Object___**)(((char*) &aosrc->___length___)+sizeof(int)))[i+srcPos];
253 int ptrtype=((int *)ptr)[0];
255 ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i+destPos]=ptr;
260 void CALL35(___System______arraycopy____L___Object____I_L___Object____I_I, int ___srcPos___, int ___destPos___, int ___length___, struct ___Object___ * ___src___, int ___srcPos___, struct ___Object___ * ___dst___, int ___destPos___, int ___length___) {
261 arraycopy(VAR(___src___), ___srcPos___, VAR(___dst___), ___destPos___, ___length___);
265 void CALL11(___System______exit____I,int ___status___, int ___status___) {
266 BAMBOO_EXIT(___status___);
269 #ifdef D___Vector______removeElement_____AR_L___Object____I_I
270 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
271 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
272 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
276 void CALL11(___System______printI____I,int ___status___, int ___status___) {
277 BAMBOO_DEBUGPRINT(0x1111);
278 BAMBOO_DEBUGPRINT_REG(___status___);
281 long long CALL00(___System______currentTimeMillis____) {
282 // not supported in MULTICORE version
286 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
289 struct ArrayObject * chararray=VAR(___s___)->___value___;
291 int offset=VAR(___s___)->___offset___;
293 for(i=0; i<VAR(___s___)->___count___; i++) {
295 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
302 /* Object allocation function */
305 void * allocate_new(void * ptr, int type) {
306 struct ___Object___ * v=
307 (struct ___Object___*)FREEMALLOC((struct garbagelist*) ptr,classsize[type]);
316 extern unsigned int gc_num_obj;
322 /* Array allocation function */
324 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
325 struct ArrayObject * v=(struct ArrayObject *)
326 FREEMALLOC((struct garbagelist*)ptr,
327 sizeof(struct ArrayObject)+length*classsize[type]);
336 v->___length___=length;
339 extern unsigned int gc_num_obj;
346 void * allocate_new(int type) {
347 struct ___Object___ * v=FREEMALLOC(classsize[type]);
357 /* Array allocation function */
359 struct ArrayObject * allocate_newarray(int type, int length) {
360 struct ArrayObject * v=
361 FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
367 v->___length___=length;
374 /* Converts C character arrays into Java strings */
376 struct ___String___ * NewString(void * ptr, const char *str,int length) {
378 struct ___String___ * NewString(const char *str,int length) {
382 struct ArrayObject * chararray=
383 allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
384 int ptrarray[]={1, (int) ptr, (int) chararray};
385 struct ___String___ * strobj=
386 allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
387 chararray=(struct ArrayObject *) ptrarray[2];
389 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
390 struct ___String___ * strobj=allocate_new(STRINGTYPE);
392 strobj->___value___=chararray;
393 strobj->___count___=length;
394 strobj->___offset___=0;
396 for(i=0; i<length; i++) {
397 ((short*)(((char*)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
402 /* Generated code calls this if we fail a bounds check */
404 void failedboundschk(int num) {
406 printf("Array out of bounds\n");
410 BAMBOO_EXIT(0xa0000000 + num);
416 printf("Array out of bounds\n");
417 longjmp(error_handler,2);
419 BAMBOO_EXIT(0xa0000000 + num);
424 /* Generated code calls this if we fail null ptr chk */
425 void failednullptr(void * ptr) {
428 //print out current stack
431 struct garbagelist * stackptr = (struct garbagelist *)ptr;
432 while(stackptr!=NULL) {
433 GC_BAMBOO_DEBUGPRINT(0xa501);
434 GC_BAMBOO_DEBUGPRINT_REG(stackptr->size);
435 GC_BAMBOO_DEBUGPRINT_REG(stackptr->next);
436 GC_BAMBOO_DEBUGPRINT_REG(stackptr->array[0]);
437 tprintf("Stack %d: \n\t", j);
438 for(i=0; i<stackptr->size; i++) {
439 if(stackptr->array[i] != NULL) {
440 tprintf("%x, ", stackptr->array[i]);
446 stackptr=stackptr->next;
451 printf("NULL ptr\n");
461 printf("NULL ptr\n");
462 longjmp(error_handler,2);
469 /* Abort task call */
473 printf("Aborting\n");
474 longjmp(error_handler,4);
477 printf("Aborting\n");
482 INLINE void initruntimedata() {
484 // initialize the arrays
485 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
486 // startup core to initialize corestatus[]
487 for(i = 0; i < NUMCORESACTIVE; ++i) {
490 numreceiveobjs[i] = 0;
493 gcnumsendobjs[0][i] = gcnumsendobjs[1][i] = 0;
494 gcnumreceiveobjs[0][i] = gcnumreceiveobjs[1][i] = 0;
496 } // for(i = 0; i < NUMCORESACTIVE; ++i)
498 for(i = 0; i < NUMCORES4GC; ++i) {
500 gcrequiredmems[i] = 0;
502 gcfilledblocks[i] = 0;
503 } // for(i = 0; i < NUMCORES4GC; ++i)
506 gc_infoOverflow = false;
507 gc_num_livespace = 0;
508 gc_num_freespace = 0;
516 self_numsendobjs = 0;
517 self_numreceiveobjs = 0;
519 for(i = 0; i < BAMBOO_MSG_BUF_LENGTH; ++i) {
524 msglength = BAMBOO_MSG_BUF_LENGTH;
526 for(i = 0; i < BAMBOO_OUT_BUF_LENGTH; ++i) {
532 isMsgHanging = false;
535 bamboo_cur_msp = NULL;
536 bamboo_smem_size = 0;
539 bamboo_smem_zero_top = NULL;
541 gcprocessing = false;
542 gcphase = FINISHPHASE;
545 gcself_numsendobjs = 0;
546 gcself_numreceiveobjs = 0;
547 gcmarkedptrbound = 0;
548 /*#ifdef LOCALHASHTBL_TEST
549 gcpointertbl = allocateRuntimeHash_I(20);
551 gcpointertbl = mgchashCreate_I(2000, 0.75);
553 gcforwardobjtbl = allocateMGCHash_I(20, 3);
565 gcmem_mixed_threshold = (unsigned int)((BAMBOO_SHARED_MEM_SIZE
566 -bamboo_reserved_smem*BAMBOO_SMEM_SIZE)*0.8);
567 gcmem_mixed_usedmem = 0;
572 gc_num_forwardobj = 0;
573 gc_num_profiles = NUMCORESACTIVE - 1;
576 gc_num_flush_dtlb = 0;
578 //gc_localheap_s = false;
579 #ifdef GC_CACHE_ADAPT
580 gccachestage = false;
581 #endif // GC_CACHE_ADAPT
582 #endif // MULTICORE_GC
589 bamboo_current_thread = NULL;
597 INLINE void disruntimedata() {
599 freeMGCHash(gcforwardobjtbl);
600 #endif // MULTICORE_GC
604 BAMBOO_LOCAL_MEM_CLOSE();
605 BAMBOO_SHARE_MEM_CLOSE();
608 INLINE void checkCoreStatus() {
609 bool allStall = false;
613 (waitconfirm && (numconfirm == 0))) {
614 BAMBOO_DEBUGPRINT(0xee04);
615 BAMBOO_DEBUGPRINT_REG(waitconfirm);
616 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
617 BAMBOO_DEBUGPRINT(0xf001);
618 corestatus[BAMBOO_NUM_OF_CORE] = 0;
619 numsendobjs[BAMBOO_NUM_OF_CORE] = self_numsendobjs;
620 numreceiveobjs[BAMBOO_NUM_OF_CORE] = self_numreceiveobjs;
621 // check the status of all cores
623 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
624 for(i = 0; i < NUMCORESACTIVE; ++i) {
625 BAMBOO_DEBUGPRINT(0xe000 + corestatus[i]);
626 if(corestatus[i] != 0) {
630 } // for(i = 0; i < NUMCORESACTIVE; ++i)
632 // check if the sum of send objs and receive obj are the same
633 // yes->check if the info is the latest; no->go on executing
635 for(i = 0; i < NUMCORESACTIVE; ++i) {
636 sumsendobj += numsendobjs[i];
637 BAMBOO_DEBUGPRINT(0xf000 + numsendobjs[i]);
638 } // for(i = 0; i < NUMCORESACTIVE; ++i)
639 for(i = 0; i < NUMCORESACTIVE; ++i) {
640 sumsendobj -= numreceiveobjs[i];
641 BAMBOO_DEBUGPRINT(0xf000 + numreceiveobjs[i]);
642 } // for(i = 0; i < NUMCORESACTIVE; ++i)
643 if(0 == sumsendobj) {
645 // the first time found all cores stall
646 // send out status confirm msg to all other cores
647 // reset the corestatus array too
648 BAMBOO_DEBUGPRINT(0xee05);
649 corestatus[BAMBOO_NUM_OF_CORE] = 1;
651 numconfirm = NUMCORESACTIVE - 1;
652 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
653 for(i = 1; i < NUMCORESACTIVE; ++i) {
655 // send status confirm msg to core i
656 send_msg_1(i, STATUSCONFIRM, false);
657 } // for(i = 1; i < NUMCORESACTIVE; ++i)
660 // all the core status info are the latest
661 // terminate; for profiling mode, send request to all
662 // other cores to pour out profiling data
663 BAMBOO_DEBUGPRINT(0xee06);
666 totalexetime = BAMBOO_GET_EXE_TIME() - bamboo_start_time;
669 BAMBOO_PRINT(BAMBOO_GET_EXE_TIME() - bamboo_start_time);
670 //BAMBOO_DEBUGPRINT_REG(total_num_t6); // TODO for test
672 BAMBOO_PRINT_REG(gc_num_flush_dtlb);
674 #ifndef BAMBOO_MEMPROF
675 BAMBOO_PRINT(0xbbbbbbbb);
678 // profile mode, send msgs to other cores to request pouring
679 // out progiling data
681 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
682 BAMBOO_DEBUGPRINT(0xf000);
683 for(i = 1; i < NUMCORESACTIVE; ++i) {
684 // send profile request msg to core i
685 send_msg_2(i, PROFILEOUTPUT, totalexetime, false);
686 } // for(i = 1; i < NUMCORESACTIVE; ++i)
688 // pour profiling data on startup core
692 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
693 BAMBOO_DEBUGPRINT(0xf001);
694 profilestatus[BAMBOO_NUM_OF_CORE] = 0;
695 // check the status of all cores
697 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
698 for(i = 0; i < NUMCORESACTIVE; ++i) {
699 BAMBOO_DEBUGPRINT(0xe000 + profilestatus[i]);
700 if(profilestatus[i] != 0) {
704 } // for(i = 0; i < NUMCORESACTIVE; ++i)
707 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
708 BAMBOO_DEBUGPRINT(0xf000);
712 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
718 // gc_profile mode, output gc prfiling data
720 #ifdef GC_CACHE_ADAPT
721 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
722 #endif // GC_CACHE_ADAPT
724 gc_outputProfileData();
725 #endif // #ifdef GC_PROFILE
726 #endif // #ifdef MULTICORE_GC
728 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
729 terminate(); // All done.
730 } // if(!waitconfirm)
732 // still some objects on the fly on the network
733 // reset the waitconfirm and numconfirm
734 BAMBOO_DEBUGPRINT(0xee07);
737 } // if(0 == sumsendobj)
739 // not all cores are stall, keep on waiting
740 BAMBOO_DEBUGPRINT(0xee08);
744 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
745 BAMBOO_DEBUGPRINT(0xf000);
746 } // if((!waitconfirm) ||
749 // main function for each core
750 inline void run(int argc, char** argv) {
752 bool sendStall = false;
754 bool tocontinue = false;
756 corenum = BAMBOO_GET_NUM_OF_CORE();
757 BAMBOO_DEBUGPRINT(0xeeee);
758 BAMBOO_DEBUGPRINT_REG(corenum);
759 BAMBOO_DEBUGPRINT(STARTUPCORE);
761 // initialize runtime data structures
764 // other architecture related initialization
768 #ifdef GC_CACHE_ADAPT
769 // enable the timer interrupt
770 #ifdef GC_CACHE_SAMPLING
771 bamboo_tile_timer_set_next_event(GC_TILE_TIMER_EVENT_SETTING); // TODO
772 bamboo_unmask_timer_intr();
773 bamboo_dtlb_sampling_process();
774 #endif // GC_CACHE_SAMPLING
775 #endif // GC_CACHE_ADAPT
777 initializeexithandler();
779 // main process of the execution module
780 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
782 // non-executing cores, only processing communications
788 /* Create queue of active tasks */
790 genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
791 (int (*)(void *,void *)) &comparetpd);
793 /* Process task information */
796 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
797 /* Create startup object */
798 createstartupobject(argc, argv);
801 BAMBOO_DEBUGPRINT(0xee00);
804 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
806 // run the initStaticAndGlobal method to initialize the static blocks and
808 initStaticAndGlobal();
810 // run the main method in the specified mainclass
811 mgc_main(argc, argv);
818 // check if need to do GC
822 #endif // MULTICORE_GC
825 // check if there are new active tasks can be executed
832 while(receiveObject() != -1) {
836 BAMBOO_DEBUGPRINT(0xee01);
838 // check if there are some pending objects,
839 // if yes, enqueue them and executetasks again
840 tocontinue = checkObjQueue();
842 tocontinue = trystartthread();
850 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
852 BAMBOO_DEBUGPRINT(0xee03);
858 BAMBOO_DEBUGPRINT(0xee09);
863 // wait for some time
865 BAMBOO_DEBUGPRINT(0xee0a);
870 // send StallMsg to startup core
871 BAMBOO_DEBUGPRINT(0xee0b);
873 send_msg_4(STARTUPCORE, TRANSTALL, BAMBOO_NUM_OF_CORE,
874 self_numsendobjs, self_numreceiveobjs, false);
885 BAMBOO_DEBUGPRINT(0xee0c);
887 } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE)
890 } // if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)
894 INLINE int checkMsgLength_I(int size) {
896 BAMBOO_DEBUGPRINT(0xcccc);
898 int type = msgdata[msgdataindex];
910 #ifdef GC_CACHE_ADAPT
912 #endif // GC_CACHE_ADAPT
913 #endif // MULTICORE_GC
928 #ifdef GC_CACHE_ADAPT
930 #endif // GC_CACHE_ADAPT
931 #endif // MULTICORE_GC
951 case REDIRECTRELEASE:
971 case GCFINISHCOMPACT:
988 case TRANSOBJ: // nonfixed size
995 msglength = msgdata[(msgdataindex+1)&(BAMBOO_MSG_BUF_MASK)];
1004 BAMBOO_DEBUGPRINT_REG(type);
1005 BAMBOO_DEBUGPRINT_REG(size);
1006 BAMBOO_DEBUGPRINT_REG(msgdataindex);
1007 BAMBOO_DEBUGPRINT_REG(msgdatalast);
1008 BAMBOO_DEBUGPRINT_REG(msgdatafull);
1011 BAMBOO_DEBUGPRINT(msgdata[msgdataindex+i]);
1013 BAMBOO_EXIT(0xe004);
1018 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex]);
1019 BAMBOO_DEBUGPRINT(0xffff);
1024 INLINE void processmsg_transtall_I() {
1025 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1026 // non startup core can not receive stall msg
1028 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
1030 BAMBOO_EXIT(0xe006);
1032 int num_core = msgdata[msgdataindex]; //[1]
1034 int data2 = msgdata[msgdataindex]; //[2];
1036 int data3 = msgdata[msgdataindex]; //[3];
1038 if(num_core < NUMCORESACTIVE) {
1040 BAMBOO_DEBUGPRINT(0xe881);
1042 corestatus[num_core] = 0;
1043 numsendobjs[num_core] = data2; //[2];
1044 numreceiveobjs[num_core] = data3; //[3];
1048 INLINE void processmsg_statusconfirm_I() {
1049 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
1050 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
1051 // wrong core to receive such msg
1052 BAMBOO_EXIT(0xe011);
1054 // send response msg
1056 BAMBOO_DEBUGPRINT(0xe887);
1058 // cache the msg first
1059 if(BAMBOO_CHECK_SEND_MODE()) {
1060 cache_msg_5(STARTUPCORE, STATUSREPORT,
1061 busystatus ? 1 : 0, BAMBOO_NUM_OF_CORE,
1062 self_numsendobjs, self_numreceiveobjs);
1064 send_msg_5(STARTUPCORE, STATUSREPORT, busystatus?1:0,
1065 BAMBOO_NUM_OF_CORE, self_numsendobjs,
1066 self_numreceiveobjs, true);
1071 INLINE void processmsg_statusreport_I() {
1072 int data1 = msgdata[msgdataindex];
1074 int data2 = msgdata[msgdataindex];
1076 int data3 = msgdata[msgdataindex];
1078 int data4 = msgdata[msgdataindex];
1080 // receive a status confirm info
1081 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1082 // wrong core to receive such msg
1084 BAMBOO_DEBUGPRINT_REG(data2);
1086 BAMBOO_EXIT(0xe012);
1089 BAMBOO_DEBUGPRINT(0xe888);
1094 corestatus[data2] = data1;
1095 numsendobjs[data2] = data3;
1096 numreceiveobjs[data2] = data4;
1100 INLINE void processmsg_terminate_I() {
1102 BAMBOO_DEBUGPRINT(0xe889);
1106 #ifdef GC_CACHE_ADAPT
1107 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
1108 #endif // GC_CACHE_ADAPT
1109 #endif // MULTICORE_GC
1113 INLINE void processmsg_memrequest_I() {
1114 int data1 = msgdata[msgdataindex];
1116 int data2 = msgdata[msgdataindex];
1118 // receive a shared memory request msg
1119 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1120 // wrong core to receive such msg
1122 BAMBOO_DEBUGPRINT_REG(data2);
1124 BAMBOO_EXIT(0xe013);
1127 BAMBOO_DEBUGPRINT(0xe88a);
1133 // is currently doing gc, dump this msg
1134 if(INITPHASE == gcphase) {
1135 // if still in the initphase of gc, send a startinit msg again,
1136 // cache the msg first
1137 if(BAMBOO_CHECK_SEND_MODE()) {
1138 cache_msg_1(data2, GCSTARTINIT);
1140 send_msg_1(data2, GCSTARTINIT, true);
1145 mem = smemalloc_I(data2, data1, &allocsize);
1147 // send the start_va to request core, cache the msg first
1148 if(BAMBOO_CHECK_SEND_MODE()) {
1149 cache_msg_3(data2, MEMRESPONSE, mem, allocsize);
1151 send_msg_3(data2, MEMRESPONSE, mem, allocsize, true);
1154 // if mem == NULL, the gcflag of the startup core has been set
1155 // and all the other cores have been informed to start gc
1162 INLINE void processmsg_memresponse_I() {
1163 int data1 = msgdata[msgdataindex];
1165 int data2 = msgdata[msgdataindex];
1167 // receive a shared memory response msg
1169 BAMBOO_DEBUGPRINT(0xe88b);
1172 // if is currently doing gc, dump this msg
1176 bamboo_smem_size = 0;
1179 bamboo_smem_zero_top = 0;
1183 // fill header to store the size of this mem block
1184 BAMBOO_MEMSET_WH(data1, '\0', BAMBOO_CACHE_LINE_SIZE);
1185 (*((int*)data1)) = data2;
1186 bamboo_smem_size = data2 - BAMBOO_CACHE_LINE_SIZE;
1187 bamboo_cur_msp = data1 + BAMBOO_CACHE_LINE_SIZE;
1188 bamboo_smem_zero_top = bamboo_cur_msp;
1190 bamboo_smem_size = data2;
1191 bamboo_cur_msp =(void*)(data1);
1201 INLINE void processmsg_gcstartpre_I() {
1203 // already stall for gc
1204 // send a update pregc information msg to the master core
1205 /*if(BAMBOO_CHECK_SEND_MODE()) {
1206 cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
1207 self_numsendobjs, self_numreceiveobjs);
1209 send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
1210 self_numsendobjs, self_numreceiveobjs, true);
1213 // the first time to be informed to start gc
1216 // is waiting for response of mem request
1217 // let it return NULL and start gc
1218 bamboo_smem_size = 0;
1219 bamboo_cur_msp = NULL;
1221 bamboo_smem_zero_top = NULL;
1226 INLINE void processmsg_gcstartinit_I() {
1227 gcphase = INITPHASE;
1230 INLINE void processmsg_gcstart_I() {
1232 BAMBOO_DEBUGPRINT(0xe88c);
1235 gcphase = MARKPHASE;
1238 INLINE void processmsg_gcstartcompact_I() {
1239 gcblock2fill = msgdata[msgdataindex];
1240 MSG_INDEXINC_I(); //msgdata[1];
1241 gcphase = COMPACTPHASE;
1244 INLINE void processmsg_gcstartflush_I() {
1245 gcphase = FLUSHPHASE;
1248 INLINE void processmsg_gcfinishpre_I() {
1249 int data1 = msgdata[msgdataindex];
1251 int data2 = msgdata[msgdataindex];
1253 int data3 = msgdata[msgdataindex];
1255 // received a init phase finish msg
1256 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1257 // non startup core can not receive this msg
1259 BAMBOO_DEBUGPRINT_REG(data1);
1261 BAMBOO_EXIT(0xe014);
1263 // All cores should do init GC
1267 gccorestatus[data1] = 0;
1268 gcnumsendobjs[0][data1] = data2;
1269 gcnumreceiveobjs[0][data1] = data3;
1272 INLINE void processmsg_gcfinishinit_I() {
1273 int data1 = msgdata[msgdataindex];
1275 // received a init phase finish msg
1276 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1277 // non startup core can not receive this msg
1279 BAMBOO_DEBUGPRINT_REG(data1);
1281 BAMBOO_EXIT(0xe015);
1284 BAMBOO_DEBUGPRINT(0xe88c);
1285 BAMBOO_DEBUGPRINT_REG(data1);
1287 // All cores should do init GC
1288 if(data1 < NUMCORESACTIVE) {
1289 gccorestatus[data1] = 0;
1293 INLINE void processmsg_gcfinishmark_I() {
1294 int data1 = msgdata[msgdataindex];
1296 int data2 = msgdata[msgdataindex];
1298 int data3 = msgdata[msgdataindex];
1300 // received a mark phase finish msg
1301 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1302 // non startup core can not receive this msg
1304 BAMBOO_DEBUGPRINT_REG(data1);
1306 BAMBOO_EXIT(0xe016);
1308 // all cores should do mark
1309 if(data1 < NUMCORESACTIVE) {
1310 gccorestatus[data1] = 0;
1311 int entry_index = 0;
1314 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1317 entry_index = gcnumsrobjs_index;
1319 gcnumsendobjs[entry_index][data1] = data2;
1320 gcnumreceiveobjs[entry_index][data1] = data3;
1324 INLINE void processmsg_gcfinishcompact_I() {
1325 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1326 // non startup core can not receive this msg
1329 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
1331 BAMBOO_EXIT(0xe017);
1333 int cnum = msgdata[msgdataindex];
1334 MSG_INDEXINC_I(); //msgdata[1];
1335 int filledblocks = msgdata[msgdataindex];
1336 MSG_INDEXINC_I(); //msgdata[2];
1337 int heaptop = msgdata[msgdataindex];
1338 MSG_INDEXINC_I(); //msgdata[3];
1339 int data4 = msgdata[msgdataindex];
1340 MSG_INDEXINC_I(); //msgdata[4];
1341 // only gc cores need to do compact
1342 if(cnum < NUMCORES4GC) {
1343 if(COMPACTPHASE == gcphase) {
1344 gcfilledblocks[cnum] = filledblocks;
1345 gcloads[cnum] = heaptop;
1352 if(gcfindSpareMem_I(&startaddr, &tomove, &dstcore, data4, cnum)) {
1353 // cache the msg first
1354 if(BAMBOO_CHECK_SEND_MODE()) {
1355 cache_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove);
1357 send_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove, true);
1361 gccorestatus[cnum] = 0;
1363 } // if(cnum < NUMCORES4GC)
1366 INLINE void processmsg_gcfinishflush_I() {
1367 int data1 = msgdata[msgdataindex];
1369 // received a flush phase finish msg
1370 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1371 // non startup core can not receive this msg
1373 BAMBOO_DEBUGPRINT_REG(data1);
1375 BAMBOO_EXIT(0xe019);
1377 // all cores should do flush
1378 if(data1 < NUMCORESACTIVE) {
1379 gccorestatus[data1] = 0;
1383 INLINE void processmsg_gcmarkconfirm_I() {
1384 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
1385 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
1386 // wrong core to receive such msg
1387 BAMBOO_EXIT(0xe01a);
1389 // send response msg, cahce the msg first
1390 if(BAMBOO_CHECK_SEND_MODE()) {
1391 cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1392 gcbusystatus, gcself_numsendobjs,
1393 gcself_numreceiveobjs);
1395 send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1396 gcbusystatus, gcself_numsendobjs,
1397 gcself_numreceiveobjs, true);
1402 INLINE void processmsg_gcmarkreport_I() {
1403 int data1 = msgdata[msgdataindex];
1405 int data2 = msgdata[msgdataindex];
1407 int data3 = msgdata[msgdataindex];
1409 int data4 = msgdata[msgdataindex];
1411 // received a marked phase finish confirm response msg
1412 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1413 // wrong core to receive such msg
1415 BAMBOO_DEBUGPRINT_REG(data2);
1417 BAMBOO_EXIT(0xe01b);
1419 int entry_index = 0;
1423 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1425 // can never reach here
1427 entry_index = gcnumsrobjs_index;
1429 gccorestatus[data1] = data2;
1430 gcnumsendobjs[entry_index][data1] = data3;
1431 gcnumreceiveobjs[entry_index][data1] = data4;
1435 INLINE void processmsg_gcmarkedobj_I() {
1436 int data1 = msgdata[msgdataindex];
1438 // received a markedObj msg
1439 if(((int *)data1)[BAMBOOMARKBIT] == INIT) {
1440 // this is the first time that this object is discovered,
1441 // set the flag as DISCOVERED
1442 ((int *)data1)[BAMBOOMARKBIT] = DISCOVERED;
1443 gc_enqueue_I(data1);
1445 // set the remote flag
1446 ((int *)data1)[BAMBOOMARKBIT] |= REMOTEM;
1447 gcself_numreceiveobjs++;
1448 gcbusystatus = true;
1451 INLINE void processmsg_gcmovestart_I() {
1453 gcdstcore = msgdata[msgdataindex];
1454 MSG_INDEXINC_I(); //msgdata[1];
1455 gcmovestartaddr = msgdata[msgdataindex];
1456 MSG_INDEXINC_I(); //msgdata[2];
1457 gcblock2fill = msgdata[msgdataindex];
1458 MSG_INDEXINC_I(); //msgdata[3];
1461 INLINE void processmsg_gclobjinfo_I() {
1464 int data1 = msgdata[msgdataindex];
1466 int data2 = msgdata[msgdataindex];
1468 if(BAMBOO_NUM_OF_CORE > NUMCORES4GC - 1) {
1470 BAMBOO_DEBUGPRINT_REG(data2);
1472 BAMBOO_EXIT(0xe01d);
1474 // store the mark result info
1476 gcloads[cnum] = msgdata[msgdataindex];
1477 MSG_INDEXINC_I(); // msgdata[3];
1478 int data4 = msgdata[msgdataindex];
1480 if(gcheaptop < data4) {
1483 // large obj info here
1484 for(int k = 5; k < data1; k+=2) {
1485 int lobj = msgdata[msgdataindex];
1486 MSG_INDEXINC_I(); //msgdata[k++];
1487 int length = msgdata[msgdataindex];
1488 MSG_INDEXINC_I(); //msgdata[k++];
1489 gc_lobjenqueue_I(lobj, length, cnum);
1491 } // for(int k = 5; k < msgdata[1];)
1495 INLINE void processmsg_gcprofiles_I() {
1496 int data1 = msgdata[msgdataindex];
1498 int data2 = msgdata[msgdataindex];
1500 int data3 = msgdata[msgdataindex];
1502 gc_num_obj += data1;
1503 gc_num_liveobj += data2;
1504 gc_num_forwardobj += data3;
1507 #endif // GC_PROFILE
1509 #ifdef GC_CACHE_ADAPT
1510 INLINE void processmsg_gcstartpref_I() {
1511 gcphase = PREFINISHPHASE;
1514 INLINE void processmsg_gcfinishpref_I() {
1515 int data1 = msgdata[msgdataindex];
1517 // received a flush phase finish msg
1518 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1519 // non startup core can not receive this msg
1521 BAMBOO_DEBUGPRINT_REG(data1);
1523 BAMBOO_EXIT(0xe01e);
1525 // all cores should do flush
1526 if(data1 < NUMCORESACTIVE) {
1527 gccorestatus[data1] = 0;
1530 #endif // GC_CACHE_ADAPT
1531 #endif // #ifdef MULTICORE_GC
1533 // receive object transferred from other cores
1534 // or the terminate message from other cores
1535 // Should be invoked in critical sections!!
1536 // NOTICE: following format is for threadsimulate version only
1537 // RAW version please see previous description
1538 // format: type + object
1539 // type: -1--stall msg
1541 // return value: 0--received an object
1542 // 1--received nothing
1543 // 2--received a Stall Msg
1544 // 3--received a lock Msg
1545 // RAW version: -1 -- received nothing
1546 // otherwise -- received msg type
1547 int receiveObject(int send_port_pending) {
1549 #ifdef PROFILE_INTERRUPT
1550 if(!interruptInfoOverflow) {
1551 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
1552 interruptInfoArray[interruptInfoIndex] = intInfo;
1553 intInfo->startTime = BAMBOO_GET_EXE_TIME();
1554 intInfo->endTime = -1;
1556 #endif // PROFILE_INTERRUPT
1559 // get the incoming msgs
1560 if(receiveMsg(send_port_pending) == -1) {
1564 // processing received msgs
1566 MSG_REMAINSIZE_I(&size);
1567 if((size == 0) || (checkMsgLength_I(size) == -1)) {
1569 // have new coming msg
1570 if((BAMBOO_MSG_AVAIL() != 0) && !msgdatafull) {
1577 if(msglength <= size) {
1578 // have some whole msg
1580 type = msgdata[msgdataindex]; //[0]
1582 msgdatafull = false;
1586 // receive a object transfer msg
1587 processmsg_transobj_I();
1593 // receive a stall msg
1594 processmsg_transtall_I();
1599 // GC version have no lock msgs
1600 #ifndef MULTICORE_GC
1602 // receive lock request msg, handle it right now
1603 processmsg_lockrequest_I();
1605 } // case LOCKREQUEST
1608 // receive lock grount msg
1609 processmsg_lockgrount_I();
1611 } // case LOCKGROUNT
1614 // receive lock deny msg
1615 processmsg_lockdeny_I();
1620 processmsg_lockrelease_I();
1622 } // case LOCKRELEASE
1623 #endif // #ifndef MULTICORE_GC
1626 case PROFILEOUTPUT: {
1627 // receive an output profile data request msg
1628 processmsg_profileoutput_I();
1630 } // case PROFILEOUTPUT
1632 case PROFILEFINISH: {
1633 // receive a profile output finish msg
1634 processmsg_profilefinish_I();
1636 } // case PROFILEFINISH
1637 #endif // #ifdef PROFILE
1639 // GC version has no lock msgs
1640 #ifndef MULTICORE_GC
1641 case REDIRECTLOCK: {
1642 // receive a redirect lock request msg, handle it right now
1643 processmsg_redirectlock_I();
1645 } // case REDIRECTLOCK
1647 case REDIRECTGROUNT: {
1648 // receive a lock grant msg with redirect info
1649 processmsg_redirectgrount_I();
1651 } // case REDIRECTGROUNT
1653 case REDIRECTDENY: {
1654 // receive a lock deny msg with redirect info
1655 processmsg_redirectdeny_I();
1657 } // case REDIRECTDENY
1659 case REDIRECTRELEASE: {
1660 // receive a lock release msg with redirect info
1661 processmsg_redirectrelease_I();
1663 } // case REDIRECTRELEASE
1664 #endif // #ifndef MULTICORE_GC
1667 case STATUSCONFIRM: {
1668 // receive a status confirm info
1669 processmsg_statusconfirm_I();
1671 } // case STATUSCONFIRM
1673 case STATUSREPORT: {
1674 processmsg_statusreport_I();
1676 } // case STATUSREPORT
1679 // receive a terminate msg
1680 processmsg_terminate_I();
1685 processmsg_memrequest_I();
1687 } // case MEMREQUEST
1690 processmsg_memresponse_I();
1692 } // case MEMRESPONSE
1697 processmsg_gcstartpre_I();
1699 } // case GCSTARTPRE
1702 processmsg_gcstartinit_I();
1704 } // case GCSTARTINIT
1707 // receive a start GC msg
1708 processmsg_gcstart_I();
1712 case GCSTARTCOMPACT: {
1713 // a compact phase start msg
1714 processmsg_gcstartcompact_I();
1716 } // case GCSTARTCOMPACT
1718 case GCSTARTFLUSH: {
1719 // received a flush phase start msg
1720 processmsg_gcstartflush_I();
1722 } // case GCSTARTFLUSH
1725 processmsg_gcfinishpre_I();
1727 } // case GCFINISHPRE
1729 case GCFINISHINIT: {
1730 processmsg_gcfinishinit_I();
1732 } // case GCFINISHINIT
1734 case GCFINISHMARK: {
1735 processmsg_gcfinishmark_I();
1737 } // case GCFINISHMARK
1739 case GCFINISHCOMPACT: {
1740 // received a compact phase finish msg
1741 processmsg_gcfinishcompact_I();
1743 } // case GCFINISHCOMPACT
1745 case GCFINISHFLUSH: {
1746 processmsg_gcfinishflush_I();
1748 } // case GCFINISHFLUSH
1751 // received a GC finish msg
1752 gcphase = FINISHPHASE;
1754 gcprocessing = false;
1758 case GCMARKCONFIRM: {
1759 // received a marked phase finish confirm request msg
1760 // all cores should do mark
1761 processmsg_gcmarkconfirm_I();
1763 } // case GCMARKCONFIRM
1765 case GCMARKREPORT: {
1766 processmsg_gcmarkreport_I();
1768 } // case GCMARKREPORT
1771 processmsg_gcmarkedobj_I();
1773 } // case GCMARKEDOBJ
1776 // received a start moving objs msg
1777 processmsg_gcmovestart_I();
1779 } // case GCMOVESTART
1781 case GCLOBJREQUEST: {
1782 // received a large objs info request msg
1783 transferMarkResults_I();
1785 } // case GCLOBJREQUEST
1788 // received a large objs info response msg
1789 processmsg_gclobjinfo_I();
1791 } // case GCLOBJINFO
1795 // received a gcprofiles msg
1796 processmsg_gcprofiles_I();
1799 #endif // GC_PROFILE
1801 #ifdef GC_CACHE_ADAPT
1803 // received a gcstartpref msg
1804 processmsg_gcstartpref_I();
1808 case GCFINISHPREF: {
1809 // received a gcfinishpref msg
1810 processmsg_gcfinishpref_I();
1813 #endif // GC_CACHE_ADAPT
1814 #endif // #ifdef MULTICORE_GC
1819 msglength = BAMBOO_MSG_BUF_LENGTH;
1821 if((msgdataindex != msgdatalast) || (msgdatafull)) {
1822 // still have available msg
1826 BAMBOO_DEBUGPRINT(0xe88d);
1829 // have new coming msg
1830 if(BAMBOO_MSG_AVAIL() != 0) {
1835 #ifdef PROFILE_INTERRUPT
1836 if(!interruptInfoOverflow) {
1837 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
1838 interruptInfoIndex++;
1839 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
1840 interruptInfoOverflow = true;
1849 BAMBOO_DEBUGPRINT(0xe88e);