4 #include "multicoreruntime.h"
5 #include "runtime_arch.h"
6 #include "GenericHashtable.h"
7 #include "structdefs.h"
14 #define INLINE inline __attribute__((always_inline))
15 #endif // #ifndef INLINE
17 extern int classsize[];
18 extern int typearray[];
19 extern int typearray2[];
22 extern struct genhashtable * activetasks;
26 extern unsigned int gcmem_mixed_threshold;
27 extern unsigned int gcmem_mixed_usedmem;
29 #endif // MULTICORE_GC
36 int instanceof(struct ___Object___ *ptr, int type) {
48 i=typearray2[i-NUMCLASSES];
54 void initializeexithandler() {
57 /* This function inject failures */
59 void injectinstructionfailure() {
60 // not supported in MULTICORE version
64 #ifdef D___Double______nativeparsedouble____L___String___
65 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
66 int length=VAR(___str___)->___count___;
67 int maxlength=(length>60) ? 60 : length;
68 char str[maxlength+1];
69 struct ArrayObject * chararray=VAR(___str___)->___value___;
71 int offset=VAR(___str___)->___offset___;
72 for(i=0; i<maxlength; i++) {
73 str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
81 #ifdef D___String______convertdoubletochar____D__AR_C
82 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
83 int length=VAR(___chararray___)->___length___;
86 int num=snprintf(str, length, "%f",___val___);
89 for(i=0; i<length; i++) {
90 ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
95 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
100 void CALL11(___System______exit____I,int ___status___, int ___status___) {
101 BAMBOO_EXIT(___status___);
104 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
105 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
106 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
109 void CALL11(___System______printI____I,int ___status___, int ___status___) {
110 BAMBOO_DEBUGPRINT(0x1111);
111 BAMBOO_DEBUGPRINT_REG(___status___);
114 long CALL00(___System______currentTimeMillis____) {
115 // not supported in MULTICORE version
119 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
122 struct ArrayObject * chararray=VAR(___s___)->___value___;
124 int offset=VAR(___s___)->___offset___;
126 for(i=0; i<VAR(___s___)->___count___; i++) {
128 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
135 /* Object allocation function */
138 void * allocate_new(void * ptr, int type) {
139 struct ___Object___ * v=
140 (struct ___Object___*)FREEMALLOC((struct garbagelist*) ptr,classsize[type]);
149 extern unsigned int gc_num_obj;
155 /* Array allocation function */
157 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
158 struct ArrayObject * v=(struct ArrayObject *)
159 FREEMALLOC((struct garbagelist*)ptr,
160 sizeof(struct ArrayObject)+length*classsize[type]);
169 v->___length___=length;
172 extern unsigned int gc_num_obj;
179 void * allocate_new(int type) {
180 struct ___Object___ * v=FREEMALLOC(classsize[type]);
190 /* Array allocation function */
192 struct ArrayObject * allocate_newarray(int type, int length) {
193 struct ArrayObject * v=
194 FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
200 v->___length___=length;
207 /* Converts C character arrays into Java strings */
209 struct ___String___ * NewString(void * ptr, const char *str,int length) {
211 struct ___String___ * NewString(const char *str,int length) {
215 struct ArrayObject * chararray=
216 allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
217 int ptrarray[]={1, (int) ptr, (int) chararray};
218 struct ___String___ * strobj=
219 allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
220 chararray=(struct ArrayObject *) ptrarray[2];
222 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
223 struct ___String___ * strobj=allocate_new(STRINGTYPE);
225 strobj->___value___=chararray;
226 strobj->___count___=length;
227 strobj->___offset___=0;
229 for(i=0; i<length; i++) {
230 ((short*)(((char*)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
235 /* Generated code calls this if we fail a bounds check */
237 void failedboundschk() {
239 printf("Array out of bounds\n");
247 printf("Array out of bounds\n");
248 longjmp(error_handler,2);
255 /* Abort task call */
259 printf("Aborting\n");
260 longjmp(error_handler,4);
263 printf("Aborting\n");
268 INLINE void initruntimedata() {
270 // initialize the arrays
271 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
272 // startup core to initialize corestatus[]
273 for(i = 0; i < NUMCORESACTIVE; ++i) {
276 numreceiveobjs[i] = 0;
279 gcnumsendobjs[0][i] = gcnumsendobjs[1][i] = 0;
280 gcnumreceiveobjs[0][i] = gcnumreceiveobjs[1][i] = 0;
282 } // for(i = 0; i < NUMCORESACTIVE; ++i)
284 for(i = 0; i < NUMCORES4GC; ++i) {
286 gcrequiredmems[i] = 0;
288 gcfilledblocks[i] = 0;
289 } // for(i = 0; i < NUMCORES4GC; ++i)
292 gc_infoOverflow = false;
293 gc_num_livespace = 0;
294 gc_num_freespace = 0;
302 self_numsendobjs = 0;
303 self_numreceiveobjs = 0;
305 for(i = 0; i < BAMBOO_MSG_BUF_LENGTH; ++i) {
310 msglength = BAMBOO_MSG_BUF_LENGTH;
312 for(i = 0; i < BAMBOO_OUT_BUF_LENGTH; ++i) {
318 isMsgHanging = false;
321 bamboo_cur_msp = NULL;
322 bamboo_smem_size = 0;
325 bamboo_smem_zero_top = NULL;
327 gcprocessing = false;
328 gcphase = FINISHPHASE;
331 gcself_numsendobjs = 0;
332 gcself_numreceiveobjs = 0;
333 gcmarkedptrbound = 0;
334 #ifdef LOCALHASHTBL_TEST
335 gcpointertbl = allocateRuntimeHash_I(20);
337 gcpointertbl = mgchashCreate_I(2000, 0.75);
339 gcforwardobjtbl = allocateMGCHash_I(20, 3);
350 gcsbstarttbl = BAMBOO_BASE_VA;
351 bamboo_smemtbl = (void *)gcsbstarttbl
352 + (BAMBOO_SHARED_MEM_SIZE/BAMBOO_SMEM_SIZE)*sizeof(INTPTR);
353 if(BAMBOO_NUM_OF_CORE < NUMCORES4GC) {
354 int t_size = ((BAMBOO_RMSP_SIZE)-sizeof(mgcsharedhashtbl_t)*2
355 -128*sizeof(size_t))/sizeof(mgcsharedhashlistnode_t)-2;
357 unsigned int tmp_k = 1 << (sizeof(int)*8 -1);
358 while(((t_size & tmp_k) == 0) && (kk < sizeof(int)*8)) {
359 t_size = t_size << 1;
362 t_size = tmp_k >> kk;
363 gcsharedptbl = mgcsharedhashCreate_I(t_size,0.30);
367 BAMBOO_MEMSET_WH(gcrpointertbls, 0,
368 sizeof(mgcsharedhashtbl_t *)*NUMCORES4GC);
370 gcmem_mixed_threshold = (unsigned int)((BAMBOO_SHARED_MEM_SIZE
371 -bamboo_reserved_smem*BAMBOO_SMEM_SIZE)*0.8);
372 gcmem_mixed_usedmem = 0;
377 gc_num_forwardobj = 0;
378 gc_num_profiles = NUMCORESACTIVE - 1;
381 gc_num_flush_dtlb = 0;
383 gc_localheap_s = false;
384 #ifdef GC_CACHE_ADAPT
385 gccachestage = false;
386 #endif // GC_CACHE_ADAPT
387 #endif // MULTICORE_GC
394 bamboo_current_thread = NULL;
402 INLINE void disruntimedata() {
404 #ifdef LOCALHASHTBL_TEST
405 freeRuntimeHash(gcpointertbl);
407 mgchashDelete(gcpointertbl);
409 freeMGCHash(gcforwardobjtbl);
410 #endif // MULTICORE_GC
414 BAMBOO_LOCAL_MEM_CLOSE();
415 BAMBOO_SHARE_MEM_CLOSE();
418 INLINE void checkCoreStatus() {
419 bool allStall = false;
423 (waitconfirm && (numconfirm == 0))) {
424 BAMBOO_DEBUGPRINT(0xee04);
425 BAMBOO_DEBUGPRINT_REG(waitconfirm);
426 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
427 BAMBOO_DEBUGPRINT(0xf001);
428 corestatus[BAMBOO_NUM_OF_CORE] = 0;
429 numsendobjs[BAMBOO_NUM_OF_CORE] = self_numsendobjs;
430 numreceiveobjs[BAMBOO_NUM_OF_CORE] = self_numreceiveobjs;
431 // check the status of all cores
433 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
434 for(i = 0; i < NUMCORESACTIVE; ++i) {
435 BAMBOO_DEBUGPRINT(0xe000 + corestatus[i]);
436 if(corestatus[i] != 0) {
440 } // for(i = 0; i < NUMCORESACTIVE; ++i)
442 // check if the sum of send objs and receive obj are the same
443 // yes->check if the info is the latest; no->go on executing
445 for(i = 0; i < NUMCORESACTIVE; ++i) {
446 sumsendobj += numsendobjs[i];
447 BAMBOO_DEBUGPRINT(0xf000 + numsendobjs[i]);
448 } // for(i = 0; i < NUMCORESACTIVE; ++i)
449 for(i = 0; i < NUMCORESACTIVE; ++i) {
450 sumsendobj -= numreceiveobjs[i];
451 BAMBOO_DEBUGPRINT(0xf000 + numreceiveobjs[i]);
452 } // for(i = 0; i < NUMCORESACTIVE; ++i)
453 if(0 == sumsendobj) {
455 // the first time found all cores stall
456 // send out status confirm msg to all other cores
457 // reset the corestatus array too
458 BAMBOO_DEBUGPRINT(0xee05);
459 corestatus[BAMBOO_NUM_OF_CORE] = 1;
461 numconfirm = NUMCORESACTIVE - 1;
462 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
463 for(i = 1; i < NUMCORESACTIVE; ++i) {
465 // send status confirm msg to core i
466 send_msg_1(i, STATUSCONFIRM, false);
467 } // for(i = 1; i < NUMCORESACTIVE; ++i)
470 // all the core status info are the latest
471 // terminate; for profiling mode, send request to all
472 // other cores to pour out profiling data
473 BAMBOO_DEBUGPRINT(0xee06);
476 totalexetime = BAMBOO_GET_EXE_TIME() - bamboo_start_time;
479 BAMBOO_PRINT(BAMBOO_GET_EXE_TIME() - bamboo_start_time);
480 //BAMBOO_DEBUGPRINT_REG(total_num_t6); // TODO for test
482 BAMBOO_PRINT_REG(gc_num_flush_dtlb);
484 #ifndef BAMBOO_MEMPROF
485 BAMBOO_PRINT(0xbbbbbbbb);
488 // profile mode, send msgs to other cores to request pouring
489 // out progiling data
491 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
492 BAMBOO_DEBUGPRINT(0xf000);
493 for(i = 1; i < NUMCORESACTIVE; ++i) {
494 // send profile request msg to core i
495 send_msg_2(i, PROFILEOUTPUT, totalexetime, false);
496 } // for(i = 1; i < NUMCORESACTIVE; ++i)
498 // pour profiling data on startup core
502 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
503 BAMBOO_DEBUGPRINT(0xf001);
504 profilestatus[BAMBOO_NUM_OF_CORE] = 0;
505 // check the status of all cores
507 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
508 for(i = 0; i < NUMCORESACTIVE; ++i) {
509 BAMBOO_DEBUGPRINT(0xe000 + profilestatus[i]);
510 if(profilestatus[i] != 0) {
514 } // for(i = 0; i < NUMCORESACTIVE; ++i)
517 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
518 BAMBOO_DEBUGPRINT(0xf000);
522 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
528 // gc_profile mode, output gc prfiling data
530 #ifdef GC_CACHE_ADAPT
531 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
532 #endif // GC_CACHE_ADAPT
534 gc_outputProfileData();
535 #endif // #ifdef GC_PROFILE
536 #endif // #ifdef MULTICORE_GC
538 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
539 terminate(); // All done.
540 } // if(!waitconfirm)
542 // still some objects on the fly on the network
543 // reset the waitconfirm and numconfirm
544 BAMBOO_DEBUGPRINT(0xee07);
547 } // if(0 == sumsendobj)
549 // not all cores are stall, keep on waiting
550 BAMBOO_DEBUGPRINT(0xee08);
554 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
555 BAMBOO_DEBUGPRINT(0xf000);
556 } // if((!waitconfirm) ||
559 // main function for each core
560 inline void run(int argc, char** argv) {
562 bool sendStall = false;
564 bool tocontinue = false;
566 corenum = BAMBOO_GET_NUM_OF_CORE();
567 BAMBOO_DEBUGPRINT(0xeeee);
568 BAMBOO_DEBUGPRINT_REG(corenum);
569 BAMBOO_DEBUGPRINT(STARTUPCORE);
571 // initialize runtime data structures
574 // other architecture related initialization
578 #ifdef GC_CACHE_ADAPT
579 // enable the timer interrupt
580 #ifdef GC_CACHE_SAMPLING
581 bamboo_tile_timer_set_next_event(GC_TILE_TIMER_EVENT_SETTING); // TODO
582 bamboo_unmask_timer_intr();
583 bamboo_dtlb_sampling_process();
584 #endif // GC_CACHE_SAMPLING
585 #endif // GC_CACHE_ADAPT
587 initializeexithandler();
589 // main process of the execution module
590 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
592 // non-executing cores, only processing communications
598 /* Create queue of active tasks */
600 genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
601 (int (*)(void *,void *)) &comparetpd);
603 /* Process task information */
606 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
607 /* Create startup object */
608 createstartupobject(argc, argv);
611 BAMBOO_DEBUGPRINT(0xee00);
615 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
616 // run the main method in the specified mainclass
617 mgc_main(argc, argv);
624 // check if need to do GC
628 #endif // MULTICORE_GC
631 // check if there are new active tasks can be executed
638 while(receiveObject() != -1) {
642 BAMBOO_DEBUGPRINT(0xee01);
644 // check if there are some pending objects,
645 // if yes, enqueue them and executetasks again
646 tocontinue = checkObjQueue();
654 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
656 BAMBOO_DEBUGPRINT(0xee03);
662 BAMBOO_DEBUGPRINT(0xee09);
667 // wait for some time
669 BAMBOO_DEBUGPRINT(0xee0a);
674 // send StallMsg to startup core
675 BAMBOO_DEBUGPRINT(0xee0b);
677 send_msg_4(STARTUPCORE, TRANSTALL, BAMBOO_NUM_OF_CORE,
678 self_numsendobjs, self_numreceiveobjs, false);
689 BAMBOO_DEBUGPRINT(0xee0c);
691 } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE)
694 } // if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)
698 INLINE int checkMsgLength_I(int size) {
700 BAMBOO_DEBUGPRINT(0xcccc);
702 int type = msgdata[msgdataindex];
715 #ifdef GC_CACHE_ADAPT
717 #endif // GC_CACHE_ADAPT
718 #endif // MULTICORE_GC
732 case GCFINISHMAPINFO:
734 #ifdef GC_CACHE_ADAPT
736 #endif // GC_CACHE_ADAPT
737 #endif // MULTICORE_GC
763 case REDIRECTRELEASE:
783 case GCFINISHCOMPACT:
800 case TRANSOBJ: // nonfixed size
807 msglength = msgdata[(msgdataindex+1)&(BAMBOO_MSG_BUF_MASK)];
816 BAMBOO_DEBUGPRINT_REG(type);
817 BAMBOO_DEBUGPRINT_REG(size);
818 BAMBOO_DEBUGPRINT_REG(msgdataindex);
819 BAMBOO_DEBUGPRINT_REG(msgdatalast);
820 BAMBOO_DEBUGPRINT_REG(msgdatafull);
823 BAMBOO_DEBUGPRINT(msgdata[msgdataindex+i]);
830 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex]);
831 BAMBOO_DEBUGPRINT(0xffff);
836 INLINE void processmsg_transtall_I() {
837 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
838 // non startup core can not receive stall msg
840 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
844 int num_core = msgdata[msgdataindex]; //[1]
846 int data2 = msgdata[msgdataindex]; //[2];
848 int data3 = msgdata[msgdataindex]; //[3];
850 if(num_core < NUMCORESACTIVE) {
852 BAMBOO_DEBUGPRINT(0xe881);
854 corestatus[num_core] = 0;
855 numsendobjs[num_core] = data2; //[2];
856 numreceiveobjs[num_core] = data3; //[3];
860 INLINE void processmsg_statusconfirm_I() {
861 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
862 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
863 // wrong core to receive such msg
868 BAMBOO_DEBUGPRINT(0xe887);
870 // cache the msg first
871 if(BAMBOO_CHECK_SEND_MODE()) {
872 cache_msg_5(STARTUPCORE, STATUSREPORT,
873 busystatus ? 1 : 0, BAMBOO_NUM_OF_CORE,
874 self_numsendobjs, self_numreceiveobjs);
876 send_msg_5(STARTUPCORE, STATUSREPORT, busystatus?1:0,
877 BAMBOO_NUM_OF_CORE, self_numsendobjs,
878 self_numreceiveobjs, true);
883 INLINE void processmsg_statusreport_I() {
884 int data1 = msgdata[msgdataindex];
886 int data2 = msgdata[msgdataindex];
888 int data3 = msgdata[msgdataindex];
890 int data4 = msgdata[msgdataindex];
892 // receive a status confirm info
893 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
894 // wrong core to receive such msg
896 BAMBOO_DEBUGPRINT_REG(data2);
901 BAMBOO_DEBUGPRINT(0xe888);
906 corestatus[data2] = data1;
907 numsendobjs[data2] = data3;
908 numreceiveobjs[data2] = data4;
912 INLINE void processmsg_terminate_I() {
914 BAMBOO_DEBUGPRINT(0xe889);
918 #ifdef GC_CACHE_ADAPT
919 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
920 #endif // GC_CACHE_ADAPT
921 #endif // MULTICORE_GC
925 INLINE void processmsg_memrequest_I() {
926 int data1 = msgdata[msgdataindex];
928 int data2 = msgdata[msgdataindex];
930 // receive a shared memory request msg
931 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
932 // wrong core to receive such msg
934 BAMBOO_DEBUGPRINT_REG(data2);
939 BAMBOO_DEBUGPRINT(0xe88a);
945 // is currently doing gc, dump this msg
946 if(INITPHASE == gcphase) {
947 // if still in the initphase of gc, send a startinit msg again,
948 // cache the msg first
949 if(BAMBOO_CHECK_SEND_MODE()) {
950 cache_msg_1(data2, GCSTARTINIT);
952 send_msg_1(data2, GCSTARTINIT, true);
957 mem = smemalloc_I(data2, data1, &allocsize);
959 // send the start_va to request core, cache the msg first
960 if(BAMBOO_CHECK_SEND_MODE()) {
961 cache_msg_3(data2, MEMRESPONSE, mem, allocsize);
963 send_msg_3(data2, MEMRESPONSE, mem, allocsize, true);
966 // if mem == NULL, the gcflag of the startup core has been set
967 // and all the other cores have been informed to start gc
974 INLINE void processmsg_memresponse_I() {
975 int data1 = msgdata[msgdataindex];
977 int data2 = msgdata[msgdataindex];
979 // receive a shared memory response msg
981 BAMBOO_DEBUGPRINT(0xe88b);
984 // if is currently doing gc, dump this msg
988 bamboo_smem_size = 0;
991 bamboo_smem_zero_top = 0;
995 // fill header to store the size of this mem block
996 BAMBOO_MEMSET_WH(data1, '\0', BAMBOO_CACHE_LINE_SIZE);
997 (*((int*)data1)) = data2;
998 bamboo_smem_size = data2 - BAMBOO_CACHE_LINE_SIZE;
999 bamboo_cur_msp = data1 + BAMBOO_CACHE_LINE_SIZE;
1000 bamboo_smem_zero_top = bamboo_cur_msp;
1002 bamboo_smem_size = data2;
1003 bamboo_cur_msp =(void*)(data1);
1013 INLINE void processmsg_gcstartpre_I() {
1015 // already stall for gc
1016 // send a update pregc information msg to the master core
1017 if(BAMBOO_CHECK_SEND_MODE()) {
1018 cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
1019 self_numsendobjs, self_numreceiveobjs);
1021 send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
1022 self_numsendobjs, self_numreceiveobjs, true);
1025 // the first time to be informed to start gc
1028 // is waiting for response of mem request
1029 // let it return NULL and start gc
1030 bamboo_smem_size = 0;
1031 bamboo_cur_msp = NULL;
1033 bamboo_smem_zero_top = NULL;
1038 INLINE void processmsg_gcstartinit_I() {
1039 gcphase = INITPHASE;
1042 INLINE void processmsg_gcstart_I() {
1044 BAMBOO_DEBUGPRINT(0xe88c);
1047 gcphase = MARKPHASE;
1050 INLINE void processmsg_gcstartcompact_I() {
1051 gcblock2fill = msgdata[msgdataindex];
1052 MSG_INDEXINC_I(); //msgdata[1];
1053 gcphase = COMPACTPHASE;
1056 INLINE void processmsg_gcstartmapinfo_I() {
1060 INLINE void processmsg_gcstartflush_I() {
1061 gcphase = FLUSHPHASE;
1064 INLINE void processmsg_gcfinishpre_I() {
1065 int data1 = msgdata[msgdataindex];
1067 int data2 = msgdata[msgdataindex];
1069 int data3 = msgdata[msgdataindex];
1071 // received a init phase finish msg
1072 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1073 // non startup core can not receive this msg
1075 BAMBOO_DEBUGPRINT_REG(data1);
1077 BAMBOO_EXIT(0xe014);
1079 // All cores should do init GC
1083 gccorestatus[data1] = 0;
1084 gcnumsendobjs[0][data1] = data2;
1085 gcnumreceiveobjs[0][data1] = data3;
1088 INLINE void processmsg_gcfinishinit_I() {
1089 int data1 = msgdata[msgdataindex];
1091 // received a init phase finish msg
1092 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1093 // non startup core can not receive this msg
1095 BAMBOO_DEBUGPRINT_REG(data1);
1097 BAMBOO_EXIT(0xe015);
1100 BAMBOO_DEBUGPRINT(0xe88c);
1101 BAMBOO_DEBUGPRINT_REG(data1);
1103 // All cores should do init GC
1104 if(data1 < NUMCORESACTIVE) {
1105 gccorestatus[data1] = 0;
1109 INLINE void processmsg_gcfinishmark_I() {
1110 int data1 = msgdata[msgdataindex];
1112 int data2 = msgdata[msgdataindex];
1114 int data3 = msgdata[msgdataindex];
1116 // received a mark phase finish msg
1117 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1118 // non startup core can not receive this msg
1120 BAMBOO_DEBUGPRINT_REG(data1);
1122 BAMBOO_EXIT(0xe016);
1124 // all cores should do mark
1125 if(data1 < NUMCORESACTIVE) {
1126 gccorestatus[data1] = 0;
1127 int entry_index = 0;
1130 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1133 entry_index = gcnumsrobjs_index;
1135 gcnumsendobjs[entry_index][data1] = data2;
1136 gcnumreceiveobjs[entry_index][data1] = data3;
1140 INLINE void processmsg_gcfinishcompact_I() {
1141 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1142 // non startup core can not receive this msg
1145 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
1147 BAMBOO_EXIT(0xe017);
1149 int cnum = msgdata[msgdataindex];
1150 MSG_INDEXINC_I(); //msgdata[1];
1151 int filledblocks = msgdata[msgdataindex];
1152 MSG_INDEXINC_I(); //msgdata[2];
1153 int heaptop = msgdata[msgdataindex];
1154 MSG_INDEXINC_I(); //msgdata[3];
1155 int data4 = msgdata[msgdataindex];
1156 MSG_INDEXINC_I(); //msgdata[4];
1157 // only gc cores need to do compact
1158 if(cnum < NUMCORES4GC) {
1159 if(COMPACTPHASE == gcphase) {
1160 gcfilledblocks[cnum] = filledblocks;
1161 gcloads[cnum] = heaptop;
1168 if(gcfindSpareMem_I(&startaddr, &tomove, &dstcore, data4, cnum)) {
1169 // cache the msg first
1170 if(BAMBOO_CHECK_SEND_MODE()) {
1171 cache_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove);
1173 send_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove, true);
1177 gccorestatus[cnum] = 0;
1179 } // if(cnum < NUMCORES4GC)
1182 INLINE void processmsg_gcfinishmapinfo_I() {
1183 int data1 = msgdata[msgdataindex];
1185 // received a map phase finish msg
1186 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1187 // non startup core can not receive this msg
1189 BAMBOO_DEBUGPRINT_REG(data1);
1191 BAMBOO_EXIT(0xe018);
1193 // all cores should do flush
1194 if(data1 < NUMCORES4GC) {
1195 gccorestatus[data1] = 0;
1200 INLINE void processmsg_gcfinishflush_I() {
1201 int data1 = msgdata[msgdataindex];
1203 // received a flush phase finish msg
1204 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1205 // non startup core can not receive this msg
1207 BAMBOO_DEBUGPRINT_REG(data1);
1209 BAMBOO_EXIT(0xe019);
1211 // all cores should do flush
1212 if(data1 < NUMCORESACTIVE) {
1213 gccorestatus[data1] = 0;
1217 INLINE void processmsg_gcmarkconfirm_I() {
1218 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
1219 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
1220 // wrong core to receive such msg
1221 BAMBOO_EXIT(0xe01a);
1223 // send response msg, cahce the msg first
1224 if(BAMBOO_CHECK_SEND_MODE()) {
1225 cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1226 gcbusystatus, gcself_numsendobjs,
1227 gcself_numreceiveobjs);
1229 send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1230 gcbusystatus, gcself_numsendobjs,
1231 gcself_numreceiveobjs, true);
1236 INLINE void processmsg_gcmarkreport_I() {
1237 int data1 = msgdata[msgdataindex];
1239 int data2 = msgdata[msgdataindex];
1241 int data3 = msgdata[msgdataindex];
1243 int data4 = msgdata[msgdataindex];
1245 // received a marked phase finish confirm response msg
1246 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1247 // wrong core to receive such msg
1249 BAMBOO_DEBUGPRINT_REG(data2);
1251 BAMBOO_EXIT(0xe01b);
1253 int entry_index = 0;
1257 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1259 // can never reach here
1261 entry_index = gcnumsrobjs_index;
1263 gccorestatus[data1] = data2;
1264 gcnumsendobjs[entry_index][data1] = data3;
1265 gcnumreceiveobjs[entry_index][data1] = data4;
1269 INLINE void processmsg_gcmarkedobj_I() {
1270 int data1 = msgdata[msgdataindex];
1272 // received a markedObj msg
1273 if(((int *)data1)[6] == INIT) {
1274 // this is the first time that this object is discovered,
1275 // set the flag as DISCOVERED
1276 ((int *)data1)[6] = DISCOVERED;
1277 gc_enqueue_I(data1);
1279 // set the remote flag
1280 ((int *)data1)[6] |= REMOTEM;
1281 gcself_numreceiveobjs++;
1282 gcbusystatus = true;
1285 INLINE void processmsg_gcmovestart_I() {
1287 gcdstcore = msgdata[msgdataindex];
1288 MSG_INDEXINC_I(); //msgdata[1];
1289 gcmovestartaddr = msgdata[msgdataindex];
1290 MSG_INDEXINC_I(); //msgdata[2];
1291 gcblock2fill = msgdata[msgdataindex];
1292 MSG_INDEXINC_I(); //msgdata[3];
1295 INLINE void processmsg_gcmaprequest_I() {
1296 void * dstptr = NULL;
1297 int data1 = msgdata[msgdataindex];
1299 int data2 = msgdata[msgdataindex];
1301 #ifdef LOCALHASHTBL_TEST
1302 RuntimeHashget(gcpointertbl, data1, &dstptr);
1304 dstptr = mgchashSearch(gcpointertbl, data1);
1306 if(NULL == dstptr) {
1307 // no such pointer in this core, something is wrong
1309 BAMBOO_DEBUGPRINT_REG(data1);
1310 BAMBOO_DEBUGPRINT_REG(data2);
1312 BAMBOO_EXIT(0xe01c);
1314 // send back the mapping info, cache the msg first
1315 if(BAMBOO_CHECK_SEND_MODE()) {
1316 cache_msg_3(data2, GCMAPINFO, data1, (int)dstptr);
1318 send_msg_3(data2, GCMAPINFO, data1, (int)dstptr, true);
1323 INLINE void processmsg_gcmapinfo_I() {
1324 int data1 = msgdata[msgdataindex];
1326 gcmappedobj = msgdata[msgdataindex]; // [2]
1328 #ifdef LOCALHASHTBL_TEST
1329 RuntimeHashadd_I(gcpointertbl, data1, gcmappedobj);
1331 mgchashInsert_I(gcpointertbl, data1, gcmappedobj);
1333 if(data1 == gcobj2map) {
1338 INLINE void processmsg_gcmaptbl_I() {
1339 int data1 = msgdata[msgdataindex];
1341 int data2 = msgdata[msgdataindex];
1343 gcrpointertbls[data2] = (mgcsharedhashtbl_t *)data1;
1346 INLINE void processmsg_gclobjinfo_I() {
1349 int data1 = msgdata[msgdataindex];
1351 int data2 = msgdata[msgdataindex];
1353 if(BAMBOO_NUM_OF_CORE > NUMCORES4GC - 1) {
1355 BAMBOO_DEBUGPRINT_REG(data2);
1357 BAMBOO_EXIT(0xe01d);
1359 // store the mark result info
1361 gcloads[cnum] = msgdata[msgdataindex];
1362 MSG_INDEXINC_I(); // msgdata[3];
1363 int data4 = msgdata[msgdataindex];
1365 if(gcheaptop < data4) {
1368 // large obj info here
1369 for(int k = 5; k < data1; k+=2) {
1370 int lobj = msgdata[msgdataindex];
1371 MSG_INDEXINC_I(); //msgdata[k++];
1372 int length = msgdata[msgdataindex];
1373 MSG_INDEXINC_I(); //msgdata[k++];
1374 gc_lobjenqueue_I(lobj, length, cnum);
1376 } // for(int k = 5; k < msgdata[1];)
1379 INLINE void processmsg_gclobjmapping_I() {
1380 int data1 = msgdata[msgdataindex];
1382 int data2 = msgdata[msgdataindex];
1384 #ifdef LOCALHASHTBL_TEST
1385 RuntimeHashadd_I(gcpointertbl, data1, data2);
1387 mgchashInsert_I(gcpointertbl, data1, data2);
1389 mgcsharedhashInsert_I(gcsharedptbl, data1, data2);
1393 INLINE void processmsg_gcprofiles_I() {
1394 int data1 = msgdata[msgdataindex];
1396 int data2 = msgdata[msgdataindex];
1398 int data3 = msgdata[msgdataindex];
1400 gc_num_obj += data1;
1401 gc_num_liveobj += data2;
1402 gc_num_forwardobj += data3;
1405 #endif // GC_PROFILE
1407 #ifdef GC_CACHE_ADAPT
1408 INLINE void processmsg_gcstartpref_I() {
1409 gcphase = PREFINISHPHASE;
1412 INLINE void processmsg_gcfinishpref_I() {
1413 int data1 = msgdata[msgdataindex];
1415 // received a flush phase finish msg
1416 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1417 // non startup core can not receive this msg
1419 BAMBOO_DEBUGPRINT_REG(data1);
1421 BAMBOO_EXIT(0xe01e);
1423 // all cores should do flush
1424 if(data1 < NUMCORESACTIVE) {
1425 gccorestatus[data1] = 0;
1428 #endif // GC_CACHE_ADAPT
1429 #endif // #ifdef MULTICORE_GC
1431 // receive object transferred from other cores
1432 // or the terminate message from other cores
1433 // Should be invoked in critical sections!!
1434 // NOTICE: following format is for threadsimulate version only
1435 // RAW version please see previous description
1436 // format: type + object
1437 // type: -1--stall msg
1439 // return value: 0--received an object
1440 // 1--received nothing
1441 // 2--received a Stall Msg
1442 // 3--received a lock Msg
1443 // RAW version: -1 -- received nothing
1444 // otherwise -- received msg type
1445 int receiveObject(int send_port_pending) {
1447 #ifdef PROFILE_INTERRUPT
1448 if(!interruptInfoOverflow) {
1449 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
1450 interruptInfoArray[interruptInfoIndex] = intInfo;
1451 intInfo->startTime = BAMBOO_GET_EXE_TIME();
1452 intInfo->endTime = -1;
1454 #endif // PROFILE_INTERRUPT
1457 // get the incoming msgs
1458 if(receiveMsg(send_port_pending) == -1) {
1462 // processing received msgs
1464 MSG_REMAINSIZE_I(&size);
1465 if((size == 0) || (checkMsgLength_I(size) == -1)) {
1467 // have new coming msg
1468 if((BAMBOO_MSG_AVAIL() != 0) && !msgdatafull) {
1475 if(msglength <= size) {
1476 // have some whole msg
1478 type = msgdata[msgdataindex]; //[0]
1480 msgdatafull = false;
1484 // receive a object transfer msg
1485 processmsg_transobj_I();
1491 // receive a stall msg
1492 processmsg_transtall_I();
1497 // GC version have no lock msgs
1498 #ifndef MULTICORE_GC
1500 // receive lock request msg, handle it right now
1501 processmsg_lockrequest_I();
1503 } // case LOCKREQUEST
1506 // receive lock grount msg
1507 processmsg_lockgrount_I();
1509 } // case LOCKGROUNT
1512 // receive lock deny msg
1513 processmsg_lockdeny_I();
1518 processmsg_lockrelease_I();
1520 } // case LOCKRELEASE
1521 #endif // #ifndef MULTICORE_GC
1524 case PROFILEOUTPUT: {
1525 // receive an output profile data request msg
1526 processmsg_profileoutput_I();
1528 } // case PROFILEOUTPUT
1530 case PROFILEFINISH: {
1531 // receive a profile output finish msg
1532 processmsg_profilefinish_I();
1534 } // case PROFILEFINISH
1535 #endif // #ifdef PROFILE
1537 // GC version has no lock msgs
1538 #ifndef MULTICORE_GC
1539 case REDIRECTLOCK: {
1540 // receive a redirect lock request msg, handle it right now
1541 processmsg_redirectlock_I();
1543 } // case REDIRECTLOCK
1545 case REDIRECTGROUNT: {
1546 // receive a lock grant msg with redirect info
1547 processmsg_redirectgrount_I();
1549 } // case REDIRECTGROUNT
1551 case REDIRECTDENY: {
1552 // receive a lock deny msg with redirect info
1553 processmsg_redirectdeny_I();
1555 } // case REDIRECTDENY
1557 case REDIRECTRELEASE: {
1558 // receive a lock release msg with redirect info
1559 processmsg_redirectrelease_I();
1561 } // case REDIRECTRELEASE
1562 #endif // #ifndef MULTICORE_GC
1565 case STATUSCONFIRM: {
1566 // receive a status confirm info
1567 processmsg_statusconfirm_I();
1569 } // case STATUSCONFIRM
1571 case STATUSREPORT: {
1572 processmsg_statusreport_I();
1574 } // case STATUSREPORT
1577 // receive a terminate msg
1578 processmsg_terminate_I();
1583 processmsg_memrequest_I();
1585 } // case MEMREQUEST
1588 processmsg_memresponse_I();
1590 } // case MEMRESPONSE
1595 processmsg_gcstartpre_I();
1597 } // case GCSTARTPRE
1600 processmsg_gcstartinit_I();
1602 } // case GCSTARTINIT
1605 // receive a start GC msg
1606 processmsg_gcstart_I();
1610 case GCSTARTCOMPACT: {
1611 // a compact phase start msg
1612 processmsg_gcstartcompact_I();
1614 } // case GCSTARTCOMPACT
1616 case GCSTARTMAPINFO: {
1617 // received a flush phase start msg
1618 processmsg_gcstartmapinfo_I();
1620 } // case GCSTARTFLUSH
1622 case GCSTARTFLUSH: {
1623 // received a flush phase start msg
1624 processmsg_gcstartflush_I();
1626 } // case GCSTARTFLUSH
1629 processmsg_gcfinishpre_I();
1631 } // case GCFINISHPRE
1633 case GCFINISHINIT: {
1634 processmsg_gcfinishinit_I();
1636 } // case GCFINISHINIT
1638 case GCFINISHMARK: {
1639 processmsg_gcfinishmark_I();
1641 } // case GCFINISHMARK
1643 case GCFINISHCOMPACT: {
1644 // received a compact phase finish msg
1645 processmsg_gcfinishcompact_I();
1647 } // case GCFINISHCOMPACT
1649 case GCFINISHMAPINFO: {
1650 processmsg_gcfinishmapinfo_I();
1652 } // case GCFINISHMAPINFO
1654 case GCFINISHFLUSH: {
1655 processmsg_gcfinishflush_I();
1657 } // case GCFINISHFLUSH
1660 // received a GC finish msg
1661 gcphase = FINISHPHASE;
1665 case GCMARKCONFIRM: {
1666 // received a marked phase finish confirm request msg
1667 // all cores should do mark
1668 processmsg_gcmarkconfirm_I();
1670 } // case GCMARKCONFIRM
1672 case GCMARKREPORT: {
1673 processmsg_gcmarkreport_I();
1675 } // case GCMARKREPORT
1678 processmsg_gcmarkedobj_I();
1680 } // case GCMARKEDOBJ
1683 // received a start moving objs msg
1684 processmsg_gcmovestart_I();
1686 } // case GCMOVESTART
1688 case GCMAPREQUEST: {
1689 // received a mapping info request msg
1690 processmsg_gcmaprequest_I();
1692 } // case GCMAPREQUEST
1695 // received a mapping info response msg
1696 processmsg_gcmapinfo_I();
1701 // received a mapping tbl response msg
1702 processmsg_gcmaptbl_I();
1706 case GCLOBJREQUEST: {
1707 // received a large objs info request msg
1708 transferMarkResults_I();
1710 } // case GCLOBJREQUEST
1713 // received a large objs info response msg
1714 processmsg_gclobjinfo_I();
1716 } // case GCLOBJINFO
1718 case GCLOBJMAPPING: {
1719 // received a large obj mapping info msg
1720 processmsg_gclobjmapping_I();
1722 } // case GCLOBJMAPPING
1726 // received a gcprofiles msg
1727 processmsg_gcprofiles_I();
1730 #endif // GC_PROFILE
1732 #ifdef GC_CACHE_ADAPT
1734 // received a gcstartpref msg
1735 processmsg_gcstartpref_I();
1739 case GCFINISHPREF: {
1740 // received a gcfinishpref msg
1741 processmsg_gcfinishpref_I();
1744 #endif // GC_CACHE_ADAPT
1745 #endif // #ifdef MULTICORE_GC
1750 msglength = BAMBOO_MSG_BUF_LENGTH;
1752 if((msgdataindex != msgdatalast) || (msgdatafull)) {
1753 // still have available msg
1757 BAMBOO_DEBUGPRINT(0xe88d);
1760 // have new coming msg
1761 if(BAMBOO_MSG_AVAIL() != 0) {
1766 #ifdef PROFILE_INTERRUPT
1767 if(!interruptInfoOverflow) {
1768 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
1769 interruptInfoIndex++;
1770 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
1771 interruptInfoOverflow = true;
1780 BAMBOO_DEBUGPRINT(0xe88e);