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];
136 /* Object allocation function */
139 void * allocate_new(void * ptr, int type) {
140 struct ___Object___ * v=
141 (struct ___Object___*)FREEMALLOC((struct garbagelist*) ptr,classsize[type]);
150 extern unsigned int gc_num_obj;
156 /* Array allocation function */
158 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
159 struct ArrayObject * v=(struct ArrayObject *)
160 FREEMALLOC((struct garbagelist*)ptr,
161 sizeof(struct ArrayObject)+length*classsize[type]);
170 v->___length___=length;
173 extern unsigned int gc_num_obj;
180 void * allocate_new(int type) {
181 struct ___Object___ * v=FREEMALLOC(classsize[type]);
191 /* Array allocation function */
193 struct ArrayObject * allocate_newarray(int type, int length) {
194 struct ArrayObject * v=
195 FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
201 v->___length___=length;
208 /* Converts C character arrays into Java strings */
210 struct ___String___ * NewString(void * ptr, const char *str,int length) {
212 struct ___String___ * NewString(const char *str,int length) {
216 struct ArrayObject * chararray=
217 allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
218 int ptrarray[]={1, (int) ptr, (int) chararray};
219 struct ___String___ * strobj=
220 allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
221 chararray=(struct ArrayObject *) ptrarray[2];
223 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
224 struct ___String___ * strobj=allocate_new(STRINGTYPE);
226 strobj->___value___=chararray;
227 strobj->___count___=length;
228 strobj->___offset___=0;
230 for(i=0; i<length; i++) {
231 ((short*)(((char*)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
236 /* Generated code calls this if we fail a bounds check */
238 void failedboundschk() {
240 printf("Array out of bounds\n");
248 printf("Array out of bounds\n");
249 longjmp(error_handler,2);
256 /* Abort task call */
260 printf("Aborting\n");
261 longjmp(error_handler,4);
264 printf("Aborting\n");
269 INLINE void initruntimedata() {
271 // initialize the arrays
272 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
273 // startup core to initialize corestatus[]
274 for(i = 0; i < NUMCORESACTIVE; ++i) {
277 numreceiveobjs[i] = 0;
280 gcnumsendobjs[0][i] = gcnumsendobjs[1][i] = 0;
281 gcnumreceiveobjs[0][i] = gcnumreceiveobjs[1][i] = 0;
283 } // for(i = 0; i < NUMCORESACTIVE; ++i)
285 for(i = 0; i < NUMCORES4GC; ++i) {
287 gcrequiredmems[i] = 0;
289 gcfilledblocks[i] = 0;
290 } // for(i = 0; i < NUMCORES4GC; ++i)
293 gc_infoOverflow = false;
294 gc_num_livespace = 0;
295 gc_num_freespace = 0;
303 self_numsendobjs = 0;
304 self_numreceiveobjs = 0;
306 for(i = 0; i < BAMBOO_MSG_BUF_LENGTH; ++i) {
311 msglength = BAMBOO_MSG_BUF_LENGTH;
313 for(i = 0; i < BAMBOO_OUT_BUF_LENGTH; ++i) {
319 isMsgHanging = false;
322 bamboo_cur_msp = NULL;
323 bamboo_smem_size = 0;
326 bamboo_smem_zero_top = NULL;
328 gcprocessing = false;
329 gcphase = FINISHPHASE;
332 gcself_numsendobjs = 0;
333 gcself_numreceiveobjs = 0;
334 gcmarkedptrbound = 0;
335 #ifdef LOCALHASHTBL_TEST
336 gcpointertbl = allocateRuntimeHash_I(20);
338 gcpointertbl = mgchashCreate_I(2000, 0.75);
340 gcforwardobjtbl = allocateMGCHash_I(20, 3);
351 gcsbstarttbl = BAMBOO_BASE_VA;
352 bamboo_smemtbl = (void *)gcsbstarttbl
353 + (BAMBOO_SHARED_MEM_SIZE/BAMBOO_SMEM_SIZE)*sizeof(INTPTR);
354 if(BAMBOO_NUM_OF_CORE < NUMCORES4GC) {
355 int t_size = ((BAMBOO_RMSP_SIZE)-sizeof(mgcsharedhashtbl_t)*2
356 -128*sizeof(size_t))/sizeof(mgcsharedhashlistnode_t)-2;
358 unsigned int tmp_k = 1 << (sizeof(int)*8 -1);
359 while(((t_size & tmp_k) == 0) && (kk < sizeof(int)*8)) {
360 t_size = t_size << 1;
363 t_size = tmp_k >> kk;
364 gcsharedptbl = mgcsharedhashCreate_I(t_size,0.30);
368 BAMBOO_MEMSET_WH(gcrpointertbls, 0,
369 sizeof(mgcsharedhashtbl_t *)*NUMCORES4GC);
371 gcmem_mixed_threshold = (unsigned int)((BAMBOO_SHARED_MEM_SIZE
372 -bamboo_reserved_smem*BAMBOO_SMEM_SIZE)*0.8);
373 gcmem_mixed_usedmem = 0;
378 gc_num_forwardobj = 0;
379 gc_num_profiles = NUMCORESACTIVE - 1;
382 gc_num_flush_dtlb = 0;
384 gc_localheap_s = false;
385 #ifdef GC_CACHE_ADAPT
386 gccachestage = false;
387 #endif // GC_CACHE_ADAPT
388 #endif // MULTICORE_GC
395 bamboo_current_thread = NULL;
403 INLINE void disruntimedata() {
405 #ifdef LOCALHASHTBL_TEST
406 freeRuntimeHash(gcpointertbl);
408 mgchashDelete(gcpointertbl);
410 freeMGCHash(gcforwardobjtbl);
411 #endif // MULTICORE_GC
415 BAMBOO_LOCAL_MEM_CLOSE();
416 BAMBOO_SHARE_MEM_CLOSE();
419 INLINE void checkCoreStatus() {
420 bool allStall = false;
424 (waitconfirm && (numconfirm == 0))) {
425 BAMBOO_DEBUGPRINT(0xee04);
426 BAMBOO_DEBUGPRINT_REG(waitconfirm);
427 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
428 BAMBOO_DEBUGPRINT(0xf001);
429 corestatus[BAMBOO_NUM_OF_CORE] = 0;
430 numsendobjs[BAMBOO_NUM_OF_CORE] = self_numsendobjs;
431 numreceiveobjs[BAMBOO_NUM_OF_CORE] = self_numreceiveobjs;
432 // check the status of all cores
434 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
435 for(i = 0; i < NUMCORESACTIVE; ++i) {
436 BAMBOO_DEBUGPRINT(0xe000 + corestatus[i]);
437 if(corestatus[i] != 0) {
441 } // for(i = 0; i < NUMCORESACTIVE; ++i)
443 // check if the sum of send objs and receive obj are the same
444 // yes->check if the info is the latest; no->go on executing
446 for(i = 0; i < NUMCORESACTIVE; ++i) {
447 sumsendobj += numsendobjs[i];
448 BAMBOO_DEBUGPRINT(0xf000 + numsendobjs[i]);
449 } // for(i = 0; i < NUMCORESACTIVE; ++i)
450 for(i = 0; i < NUMCORESACTIVE; ++i) {
451 sumsendobj -= numreceiveobjs[i];
452 BAMBOO_DEBUGPRINT(0xf000 + numreceiveobjs[i]);
453 } // for(i = 0; i < NUMCORESACTIVE; ++i)
454 if(0 == sumsendobj) {
456 // the first time found all cores stall
457 // send out status confirm msg to all other cores
458 // reset the corestatus array too
459 BAMBOO_DEBUGPRINT(0xee05);
460 corestatus[BAMBOO_NUM_OF_CORE] = 1;
462 numconfirm = NUMCORESACTIVE - 1;
463 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
464 for(i = 1; i < NUMCORESACTIVE; ++i) {
466 // send status confirm msg to core i
467 send_msg_1(i, STATUSCONFIRM, false);
468 } // for(i = 1; i < NUMCORESACTIVE; ++i)
471 // all the core status info are the latest
472 // terminate; for profiling mode, send request to all
473 // other cores to pour out profiling data
474 BAMBOO_DEBUGPRINT(0xee06);
477 totalexetime = BAMBOO_GET_EXE_TIME() - bamboo_start_time;
480 BAMBOO_PRINT(BAMBOO_GET_EXE_TIME() - bamboo_start_time);
481 //BAMBOO_DEBUGPRINT_REG(total_num_t6); // TODO for test
483 BAMBOO_PRINT_REG(gc_num_flush_dtlb);
485 #ifndef BAMBOO_MEMPROF
486 BAMBOO_PRINT(0xbbbbbbbb);
489 // profile mode, send msgs to other cores to request pouring
490 // out progiling data
492 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
493 BAMBOO_DEBUGPRINT(0xf000);
494 for(i = 1; i < NUMCORESACTIVE; ++i) {
495 // send profile request msg to core i
496 send_msg_2(i, PROFILEOUTPUT, totalexetime, false);
497 } // for(i = 1; i < NUMCORESACTIVE; ++i)
499 // pour profiling data on startup core
503 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
504 BAMBOO_DEBUGPRINT(0xf001);
505 profilestatus[BAMBOO_NUM_OF_CORE] = 0;
506 // check the status of all cores
508 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
509 for(i = 0; i < NUMCORESACTIVE; ++i) {
510 BAMBOO_DEBUGPRINT(0xe000 + profilestatus[i]);
511 if(profilestatus[i] != 0) {
515 } // for(i = 0; i < NUMCORESACTIVE; ++i)
518 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
519 BAMBOO_DEBUGPRINT(0xf000);
523 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
529 // gc_profile mode, output gc prfiling data
531 #ifdef GC_CACHE_ADAPT
532 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
533 #endif // GC_CACHE_ADAPT
535 gc_outputProfileData();
536 #endif // #ifdef GC_PROFILE
537 #endif // #ifdef MULTICORE_GC
539 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
540 terminate(); // All done.
541 } // if(!waitconfirm)
543 // still some objects on the fly on the network
544 // reset the waitconfirm and numconfirm
545 BAMBOO_DEBUGPRINT(0xee07);
548 } // if(0 == sumsendobj)
550 // not all cores are stall, keep on waiting
551 BAMBOO_DEBUGPRINT(0xee08);
555 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
556 BAMBOO_DEBUGPRINT(0xf000);
557 } // if((!waitconfirm) ||
560 // main function for each core
561 inline void run(int argc, char** argv) {
563 bool sendStall = false;
565 bool tocontinue = false;
567 corenum = BAMBOO_GET_NUM_OF_CORE();
568 BAMBOO_DEBUGPRINT(0xeeee);
569 BAMBOO_DEBUGPRINT_REG(corenum);
570 BAMBOO_DEBUGPRINT(STARTUPCORE);
572 // initialize runtime data structures
575 // other architecture related initialization
579 #ifdef GC_CACHE_ADAPT
580 // enable the timer interrupt
581 #ifdef GC_CACHE_SAMPLING
582 bamboo_tile_timer_set_next_event(GC_TILE_TIMER_EVENT_SETTING); // TODO
583 bamboo_unmask_timer_intr();
584 bamboo_dtlb_sampling_process();
585 #endif // GC_CACHE_SAMPLING
586 #endif // GC_CACHE_ADAPT
588 initializeexithandler();
590 // main process of the execution module
591 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
593 // non-executing cores, only processing communications
599 /* Create queue of active tasks */
601 genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
602 (int (*)(void *,void *)) &comparetpd);
604 /* Process task information */
607 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
608 /* Create startup object */
609 createstartupobject(argc, argv);
612 BAMBOO_DEBUGPRINT(0xee00);
616 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
617 // run the main method in the specified mainclass
618 mgc_main(argc, argv);
625 // check if need to do GC
629 #endif // MULTICORE_GC
632 // check if there are new active tasks can be executed
639 while(receiveObject() != -1) {
643 BAMBOO_DEBUGPRINT(0xee01);
645 // check if there are some pending objects,
646 // if yes, enqueue them and executetasks again
647 tocontinue = checkObjQueue();
655 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
657 BAMBOO_DEBUGPRINT(0xee03);
663 BAMBOO_DEBUGPRINT(0xee09);
668 // wait for some time
670 BAMBOO_DEBUGPRINT(0xee0a);
675 // send StallMsg to startup core
676 BAMBOO_DEBUGPRINT(0xee0b);
678 send_msg_4(STARTUPCORE, TRANSTALL, BAMBOO_NUM_OF_CORE,
679 self_numsendobjs, self_numreceiveobjs, false);
690 BAMBOO_DEBUGPRINT(0xee0c);
692 } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE)
695 } // if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)
699 INLINE int checkMsgLength_I(int size) {
701 BAMBOO_DEBUGPRINT(0xcccc);
703 int type = msgdata[msgdataindex];
716 #ifdef GC_CACHE_ADAPT
718 #endif // GC_CACHE_ADAPT
719 #endif // MULTICORE_GC
733 case GCFINISHMAPINFO:
735 #ifdef GC_CACHE_ADAPT
737 #endif // GC_CACHE_ADAPT
738 #endif // MULTICORE_GC
764 case REDIRECTRELEASE:
784 case GCFINISHCOMPACT:
801 case TRANSOBJ: // nonfixed size
808 msglength = msgdata[(msgdataindex+1)&(BAMBOO_MSG_BUF_MASK)];
817 BAMBOO_DEBUGPRINT_REG(type);
818 BAMBOO_DEBUGPRINT_REG(size);
819 BAMBOO_DEBUGPRINT_REG(msgdataindex);
820 BAMBOO_DEBUGPRINT_REG(msgdatalast);
821 BAMBOO_DEBUGPRINT_REG(msgdatafull);
824 BAMBOO_DEBUGPRINT(msgdata[msgdataindex+i]);
831 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex]);
832 BAMBOO_DEBUGPRINT(0xffff);
837 INLINE void processmsg_transtall_I() {
838 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
839 // non startup core can not receive stall msg
841 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
845 int num_core = msgdata[msgdataindex]; //[1]
847 int data2 = msgdata[msgdataindex]; //[2];
849 int data3 = msgdata[msgdataindex]; //[3];
851 if(num_core < NUMCORESACTIVE) {
853 BAMBOO_DEBUGPRINT(0xe881);
855 corestatus[num_core] = 0;
856 numsendobjs[num_core] = data2; //[2];
857 numreceiveobjs[num_core] = data3; //[3];
861 INLINE void processmsg_statusconfirm_I() {
862 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
863 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
864 // wrong core to receive such msg
869 BAMBOO_DEBUGPRINT(0xe887);
871 // cache the msg first
872 if(BAMBOO_CHECK_SEND_MODE()) {
873 cache_msg_5(STARTUPCORE, STATUSREPORT,
874 busystatus ? 1 : 0, BAMBOO_NUM_OF_CORE,
875 self_numsendobjs, self_numreceiveobjs);
877 send_msg_5(STARTUPCORE, STATUSREPORT, busystatus?1:0,
878 BAMBOO_NUM_OF_CORE, self_numsendobjs,
879 self_numreceiveobjs, true);
884 INLINE void processmsg_statusreport_I() {
885 int data1 = msgdata[msgdataindex];
887 int data2 = msgdata[msgdataindex];
889 int data3 = msgdata[msgdataindex];
891 int data4 = msgdata[msgdataindex];
893 // receive a status confirm info
894 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
895 // wrong core to receive such msg
897 BAMBOO_DEBUGPRINT_REG(data2);
902 BAMBOO_DEBUGPRINT(0xe888);
907 corestatus[data2] = data1;
908 numsendobjs[data2] = data3;
909 numreceiveobjs[data2] = data4;
913 INLINE void processmsg_terminate_I() {
915 BAMBOO_DEBUGPRINT(0xe889);
919 #ifdef GC_CACHE_ADAPT
920 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
921 #endif // GC_CACHE_ADAPT
922 #endif // MULTICORE_GC
926 INLINE void processmsg_memrequest_I() {
927 int data1 = msgdata[msgdataindex];
929 int data2 = msgdata[msgdataindex];
931 // receive a shared memory request msg
932 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
933 // wrong core to receive such msg
935 BAMBOO_DEBUGPRINT_REG(data2);
940 BAMBOO_DEBUGPRINT(0xe88a);
946 // is currently doing gc, dump this msg
947 if(INITPHASE == gcphase) {
948 // if still in the initphase of gc, send a startinit msg again,
949 // cache the msg first
950 if(BAMBOO_CHECK_SEND_MODE()) {
951 cache_msg_1(data2, GCSTARTINIT);
953 send_msg_1(data2, GCSTARTINIT, true);
958 mem = smemalloc_I(data2, data1, &allocsize);
960 // send the start_va to request core, cache the msg first
961 if(BAMBOO_CHECK_SEND_MODE()) {
962 cache_msg_3(data2, MEMRESPONSE, mem, allocsize);
964 send_msg_3(data2, MEMRESPONSE, mem, allocsize, true);
967 // if mem == NULL, the gcflag of the startup core has been set
968 // and all the other cores have been informed to start gc
975 INLINE void processmsg_memresponse_I() {
976 int data1 = msgdata[msgdataindex];
978 int data2 = msgdata[msgdataindex];
980 // receive a shared memory response msg
982 BAMBOO_DEBUGPRINT(0xe88b);
985 // if is currently doing gc, dump this msg
989 bamboo_smem_size = 0;
992 bamboo_smem_zero_top = 0;
996 // fill header to store the size of this mem block
997 BAMBOO_MEMSET_WH(data1, '\0', BAMBOO_CACHE_LINE_SIZE);
998 (*((int*)data1)) = data2;
999 bamboo_smem_size = data2 - BAMBOO_CACHE_LINE_SIZE;
1000 bamboo_cur_msp = data1 + BAMBOO_CACHE_LINE_SIZE;
1001 bamboo_smem_zero_top = bamboo_cur_msp;
1003 bamboo_smem_size = data2;
1004 bamboo_cur_msp =(void*)(data1);
1014 INLINE void processmsg_gcstartpre_I() {
1016 // already stall for gc
1017 // send a update pregc information msg to the master core
1018 if(BAMBOO_CHECK_SEND_MODE()) {
1019 cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
1020 self_numsendobjs, self_numreceiveobjs);
1022 send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
1023 self_numsendobjs, self_numreceiveobjs, true);
1026 // the first time to be informed to start gc
1029 // is waiting for response of mem request
1030 // let it return NULL and start gc
1031 bamboo_smem_size = 0;
1032 bamboo_cur_msp = NULL;
1034 bamboo_smem_zero_top = NULL;
1039 INLINE void processmsg_gcstartinit_I() {
1040 gcphase = INITPHASE;
1043 INLINE void processmsg_gcstart_I() {
1045 BAMBOO_DEBUGPRINT(0xe88c);
1048 gcphase = MARKPHASE;
1051 INLINE void processmsg_gcstartcompact_I() {
1052 gcblock2fill = msgdata[msgdataindex];
1053 MSG_INDEXINC_I(); //msgdata[1];
1054 gcphase = COMPACTPHASE;
1057 INLINE void processmsg_gcstartmapinfo_I() {
1061 INLINE void processmsg_gcstartflush_I() {
1062 gcphase = FLUSHPHASE;
1065 INLINE void processmsg_gcfinishpre_I() {
1066 int data1 = msgdata[msgdataindex];
1068 int data2 = msgdata[msgdataindex];
1070 int data3 = msgdata[msgdataindex];
1072 // received a init phase finish msg
1073 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1074 // non startup core can not receive this msg
1076 BAMBOO_DEBUGPRINT_REG(data1);
1078 BAMBOO_EXIT(0xe014);
1080 // All cores should do init GC
1084 gccorestatus[data1] = 0;
1085 gcnumsendobjs[0][data1] = data2;
1086 gcnumreceiveobjs[0][data1] = data3;
1089 INLINE void processmsg_gcfinishinit_I() {
1090 int data1 = msgdata[msgdataindex];
1092 // received a init phase finish msg
1093 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1094 // non startup core can not receive this msg
1096 BAMBOO_DEBUGPRINT_REG(data1);
1098 BAMBOO_EXIT(0xe015);
1101 BAMBOO_DEBUGPRINT(0xe88c);
1102 BAMBOO_DEBUGPRINT_REG(data1);
1104 // All cores should do init GC
1105 if(data1 < NUMCORESACTIVE) {
1106 gccorestatus[data1] = 0;
1110 INLINE void processmsg_gcfinishmark_I() {
1111 int data1 = msgdata[msgdataindex];
1113 int data2 = msgdata[msgdataindex];
1115 int data3 = msgdata[msgdataindex];
1117 // received a mark phase finish msg
1118 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1119 // non startup core can not receive this msg
1121 BAMBOO_DEBUGPRINT_REG(data1);
1123 BAMBOO_EXIT(0xe016);
1125 // all cores should do mark
1126 if(data1 < NUMCORESACTIVE) {
1127 gccorestatus[data1] = 0;
1128 int entry_index = 0;
1131 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1134 entry_index = gcnumsrobjs_index;
1136 gcnumsendobjs[entry_index][data1] = data2;
1137 gcnumreceiveobjs[entry_index][data1] = data3;
1141 INLINE void processmsg_gcfinishcompact_I() {
1142 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1143 // non startup core can not receive this msg
1146 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
1148 BAMBOO_EXIT(0xe017);
1150 int cnum = msgdata[msgdataindex];
1151 MSG_INDEXINC_I(); //msgdata[1];
1152 int filledblocks = msgdata[msgdataindex];
1153 MSG_INDEXINC_I(); //msgdata[2];
1154 int heaptop = msgdata[msgdataindex];
1155 MSG_INDEXINC_I(); //msgdata[3];
1156 int data4 = msgdata[msgdataindex];
1157 MSG_INDEXINC_I(); //msgdata[4];
1158 // only gc cores need to do compact
1159 if(cnum < NUMCORES4GC) {
1160 if(COMPACTPHASE == gcphase) {
1161 gcfilledblocks[cnum] = filledblocks;
1162 gcloads[cnum] = heaptop;
1169 if(gcfindSpareMem_I(&startaddr, &tomove, &dstcore, data4, cnum)) {
1170 // cache the msg first
1171 if(BAMBOO_CHECK_SEND_MODE()) {
1172 cache_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove);
1174 send_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove, true);
1178 gccorestatus[cnum] = 0;
1180 } // if(cnum < NUMCORES4GC)
1183 INLINE void processmsg_gcfinishmapinfo_I() {
1184 int data1 = msgdata[msgdataindex];
1186 // received a map phase finish msg
1187 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1188 // non startup core can not receive this msg
1190 BAMBOO_DEBUGPRINT_REG(data1);
1192 BAMBOO_EXIT(0xe018);
1194 // all cores should do flush
1195 if(data1 < NUMCORES4GC) {
1196 gccorestatus[data1] = 0;
1201 INLINE void processmsg_gcfinishflush_I() {
1202 int data1 = msgdata[msgdataindex];
1204 // received a flush phase finish msg
1205 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1206 // non startup core can not receive this msg
1208 BAMBOO_DEBUGPRINT_REG(data1);
1210 BAMBOO_EXIT(0xe019);
1212 // all cores should do flush
1213 if(data1 < NUMCORESACTIVE) {
1214 gccorestatus[data1] = 0;
1218 INLINE void processmsg_gcmarkconfirm_I() {
1219 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
1220 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
1221 // wrong core to receive such msg
1222 BAMBOO_EXIT(0xe01a);
1224 // send response msg, cahce the msg first
1225 if(BAMBOO_CHECK_SEND_MODE()) {
1226 cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1227 gcbusystatus, gcself_numsendobjs,
1228 gcself_numreceiveobjs);
1230 send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1231 gcbusystatus, gcself_numsendobjs,
1232 gcself_numreceiveobjs, true);
1237 INLINE void processmsg_gcmarkreport_I() {
1238 int data1 = msgdata[msgdataindex];
1240 int data2 = msgdata[msgdataindex];
1242 int data3 = msgdata[msgdataindex];
1244 int data4 = msgdata[msgdataindex];
1246 // received a marked phase finish confirm response msg
1247 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1248 // wrong core to receive such msg
1250 BAMBOO_DEBUGPRINT_REG(data2);
1252 BAMBOO_EXIT(0xe01b);
1254 int entry_index = 0;
1258 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1260 // can never reach here
1262 entry_index = gcnumsrobjs_index;
1264 gccorestatus[data1] = data2;
1265 gcnumsendobjs[entry_index][data1] = data3;
1266 gcnumreceiveobjs[entry_index][data1] = data4;
1270 INLINE void processmsg_gcmarkedobj_I() {
1271 int data1 = msgdata[msgdataindex];
1273 // received a markedObj msg
1274 if(((int *)data1)[6] == INIT) {
1275 // this is the first time that this object is discovered,
1276 // set the flag as DISCOVERED
1277 ((int *)data1)[6] = DISCOVERED;
1278 gc_enqueue_I(data1);
1280 // set the remote flag
1281 ((int *)data1)[6] |= REMOTEM;
1282 gcself_numreceiveobjs++;
1283 gcbusystatus = true;
1286 INLINE void processmsg_gcmovestart_I() {
1288 gcdstcore = msgdata[msgdataindex];
1289 MSG_INDEXINC_I(); //msgdata[1];
1290 gcmovestartaddr = msgdata[msgdataindex];
1291 MSG_INDEXINC_I(); //msgdata[2];
1292 gcblock2fill = msgdata[msgdataindex];
1293 MSG_INDEXINC_I(); //msgdata[3];
1296 INLINE void processmsg_gcmaprequest_I() {
1297 void * dstptr = NULL;
1298 int data1 = msgdata[msgdataindex];
1300 int data2 = msgdata[msgdataindex];
1302 #ifdef LOCALHASHTBL_TEST
1303 RuntimeHashget(gcpointertbl, data1, &dstptr);
1305 dstptr = mgchashSearch(gcpointertbl, data1);
1307 if(NULL == dstptr) {
1308 // no such pointer in this core, something is wrong
1310 BAMBOO_DEBUGPRINT_REG(data1);
1311 BAMBOO_DEBUGPRINT_REG(data2);
1313 BAMBOO_EXIT(0xe01c);
1315 // send back the mapping info, cache the msg first
1316 if(BAMBOO_CHECK_SEND_MODE()) {
1317 cache_msg_3(data2, GCMAPINFO, data1, (int)dstptr);
1319 send_msg_3(data2, GCMAPINFO, data1, (int)dstptr, true);
1324 INLINE void processmsg_gcmapinfo_I() {
1325 int data1 = msgdata[msgdataindex];
1327 gcmappedobj = msgdata[msgdataindex]; // [2]
1329 #ifdef LOCALHASHTBL_TEST
1330 RuntimeHashadd_I(gcpointertbl, data1, gcmappedobj);
1332 mgchashInsert_I(gcpointertbl, data1, gcmappedobj);
1334 if(data1 == gcobj2map) {
1339 INLINE void processmsg_gcmaptbl_I() {
1340 int data1 = msgdata[msgdataindex];
1342 int data2 = msgdata[msgdataindex];
1344 gcrpointertbls[data2] = (mgcsharedhashtbl_t *)data1;
1347 INLINE void processmsg_gclobjinfo_I() {
1350 int data1 = msgdata[msgdataindex];
1352 int data2 = msgdata[msgdataindex];
1354 if(BAMBOO_NUM_OF_CORE > NUMCORES4GC - 1) {
1356 BAMBOO_DEBUGPRINT_REG(data2);
1358 BAMBOO_EXIT(0xe01d);
1360 // store the mark result info
1362 gcloads[cnum] = msgdata[msgdataindex];
1363 MSG_INDEXINC_I(); // msgdata[3];
1364 int data4 = msgdata[msgdataindex];
1366 if(gcheaptop < data4) {
1369 // large obj info here
1370 for(int k = 5; k < data1; k+=2) {
1371 int lobj = msgdata[msgdataindex];
1372 MSG_INDEXINC_I(); //msgdata[k++];
1373 int length = msgdata[msgdataindex];
1374 MSG_INDEXINC_I(); //msgdata[k++];
1375 gc_lobjenqueue_I(lobj, length, cnum);
1377 } // for(int k = 5; k < msgdata[1];)
1380 INLINE void processmsg_gclobjmapping_I() {
1381 int data1 = msgdata[msgdataindex];
1383 int data2 = msgdata[msgdataindex];
1385 #ifdef LOCALHASHTBL_TEST
1386 RuntimeHashadd_I(gcpointertbl, data1, data2);
1388 mgchashInsert_I(gcpointertbl, data1, data2);
1390 mgcsharedhashInsert_I(gcsharedptbl, data1, data2);
1394 INLINE void processmsg_gcprofiles_I() {
1395 int data1 = msgdata[msgdataindex];
1397 int data2 = msgdata[msgdataindex];
1399 int data3 = msgdata[msgdataindex];
1401 gc_num_obj += data1;
1402 gc_num_liveobj += data2;
1403 gc_num_forwardobj += data3;
1406 #endif // GC_PROFILE
1408 #ifdef GC_CACHE_ADAPT
1409 INLINE void processmsg_gcstartpref_I() {
1410 gcphase = PREFINISHPHASE;
1413 INLINE void processmsg_gcfinishpref_I() {
1414 int data1 = msgdata[msgdataindex];
1416 // received a flush phase finish msg
1417 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1418 // non startup core can not receive this msg
1420 BAMBOO_DEBUGPRINT_REG(data1);
1422 BAMBOO_EXIT(0xe01e);
1424 // all cores should do flush
1425 if(data1 < NUMCORESACTIVE) {
1426 gccorestatus[data1] = 0;
1429 #endif // GC_CACHE_ADAPT
1430 #endif // #ifdef MULTICORE_GC
1432 // receive object transferred from other cores
1433 // or the terminate message from other cores
1434 // Should be invoked in critical sections!!
1435 // NOTICE: following format is for threadsimulate version only
1436 // RAW version please see previous description
1437 // format: type + object
1438 // type: -1--stall msg
1440 // return value: 0--received an object
1441 // 1--received nothing
1442 // 2--received a Stall Msg
1443 // 3--received a lock Msg
1444 // RAW version: -1 -- received nothing
1445 // otherwise -- received msg type
1446 int receiveObject(int send_port_pending) {
1448 #ifdef PROFILE_INTERRUPT
1449 if(!interruptInfoOverflow) {
1450 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
1451 interruptInfoArray[interruptInfoIndex] = intInfo;
1452 intInfo->startTime = BAMBOO_GET_EXE_TIME();
1453 intInfo->endTime = -1;
1455 #endif // PROFILE_INTERRUPT
1458 // get the incoming msgs
1459 if(receiveMsg(send_port_pending) == -1) {
1463 // processing received msgs
1465 MSG_REMAINSIZE_I(&size);
1466 if((size == 0) || (checkMsgLength_I(size) == -1)) {
1468 // have new coming msg
1469 if((BAMBOO_MSG_AVAIL() != 0) && !msgdatafull) {
1476 if(msglength <= size) {
1477 // have some whole msg
1479 type = msgdata[msgdataindex]; //[0]
1481 msgdatafull = false;
1485 // receive a object transfer msg
1486 processmsg_transobj_I();
1492 // receive a stall msg
1493 processmsg_transtall_I();
1498 // GC version have no lock msgs
1499 #ifndef MULTICORE_GC
1501 // receive lock request msg, handle it right now
1502 processmsg_lockrequest_I();
1504 } // case LOCKREQUEST
1507 // receive lock grount msg
1508 processmsg_lockgrount_I();
1510 } // case LOCKGROUNT
1513 // receive lock deny msg
1514 processmsg_lockdeny_I();
1519 processmsg_lockrelease_I();
1521 } // case LOCKRELEASE
1522 #endif // #ifndef MULTICORE_GC
1525 case PROFILEOUTPUT: {
1526 // receive an output profile data request msg
1527 processmsg_profileoutput_I();
1529 } // case PROFILEOUTPUT
1531 case PROFILEFINISH: {
1532 // receive a profile output finish msg
1533 processmsg_profilefinish_I();
1535 } // case PROFILEFINISH
1536 #endif // #ifdef PROFILE
1538 // GC version has no lock msgs
1539 #ifndef MULTICORE_GC
1540 case REDIRECTLOCK: {
1541 // receive a redirect lock request msg, handle it right now
1542 processmsg_redirectlock_I();
1544 } // case REDIRECTLOCK
1546 case REDIRECTGROUNT: {
1547 // receive a lock grant msg with redirect info
1548 processmsg_redirectgrount_I();
1550 } // case REDIRECTGROUNT
1552 case REDIRECTDENY: {
1553 // receive a lock deny msg with redirect info
1554 processmsg_redirectdeny_I();
1556 } // case REDIRECTDENY
1558 case REDIRECTRELEASE: {
1559 // receive a lock release msg with redirect info
1560 processmsg_redirectrelease_I();
1562 } // case REDIRECTRELEASE
1563 #endif // #ifndef MULTICORE_GC
1566 case STATUSCONFIRM: {
1567 // receive a status confirm info
1568 processmsg_statusconfirm_I();
1570 } // case STATUSCONFIRM
1572 case STATUSREPORT: {
1573 processmsg_statusreport_I();
1575 } // case STATUSREPORT
1578 // receive a terminate msg
1579 processmsg_terminate_I();
1584 processmsg_memrequest_I();
1586 } // case MEMREQUEST
1589 processmsg_memresponse_I();
1591 } // case MEMRESPONSE
1596 processmsg_gcstartpre_I();
1598 } // case GCSTARTPRE
1601 processmsg_gcstartinit_I();
1603 } // case GCSTARTINIT
1606 // receive a start GC msg
1607 processmsg_gcstart_I();
1611 case GCSTARTCOMPACT: {
1612 // a compact phase start msg
1613 processmsg_gcstartcompact_I();
1615 } // case GCSTARTCOMPACT
1617 case GCSTARTMAPINFO: {
1618 // received a flush phase start msg
1619 processmsg_gcstartmapinfo_I();
1621 } // case GCSTARTFLUSH
1623 case GCSTARTFLUSH: {
1624 // received a flush phase start msg
1625 processmsg_gcstartflush_I();
1627 } // case GCSTARTFLUSH
1630 processmsg_gcfinishpre_I();
1632 } // case GCFINISHPRE
1634 case GCFINISHINIT: {
1635 processmsg_gcfinishinit_I();
1637 } // case GCFINISHINIT
1639 case GCFINISHMARK: {
1640 processmsg_gcfinishmark_I();
1642 } // case GCFINISHMARK
1644 case GCFINISHCOMPACT: {
1645 // received a compact phase finish msg
1646 processmsg_gcfinishcompact_I();
1648 } // case GCFINISHCOMPACT
1650 case GCFINISHMAPINFO: {
1651 processmsg_gcfinishmapinfo_I();
1653 } // case GCFINISHMAPINFO
1655 case GCFINISHFLUSH: {
1656 processmsg_gcfinishflush_I();
1658 } // case GCFINISHFLUSH
1661 // received a GC finish msg
1662 gcphase = FINISHPHASE;
1666 case GCMARKCONFIRM: {
1667 // received a marked phase finish confirm request msg
1668 // all cores should do mark
1669 processmsg_gcmarkconfirm_I();
1671 } // case GCMARKCONFIRM
1673 case GCMARKREPORT: {
1674 processmsg_gcmarkreport_I();
1676 } // case GCMARKREPORT
1679 processmsg_gcmarkedobj_I();
1681 } // case GCMARKEDOBJ
1684 // received a start moving objs msg
1685 processmsg_gcmovestart_I();
1687 } // case GCMOVESTART
1689 case GCMAPREQUEST: {
1690 // received a mapping info request msg
1691 processmsg_gcmaprequest_I();
1693 } // case GCMAPREQUEST
1696 // received a mapping info response msg
1697 processmsg_gcmapinfo_I();
1702 // received a mapping tbl response msg
1703 processmsg_gcmaptbl_I();
1707 case GCLOBJREQUEST: {
1708 // received a large objs info request msg
1709 transferMarkResults_I();
1711 } // case GCLOBJREQUEST
1714 // received a large objs info response msg
1715 processmsg_gclobjinfo_I();
1717 } // case GCLOBJINFO
1719 case GCLOBJMAPPING: {
1720 // received a large obj mapping info msg
1721 processmsg_gclobjmapping_I();
1723 } // case GCLOBJMAPPING
1727 // received a gcprofiles msg
1728 processmsg_gcprofiles_I();
1731 #endif // GC_PROFILE
1733 #ifdef GC_CACHE_ADAPT
1735 // received a gcstartpref msg
1736 processmsg_gcstartpref_I();
1740 case GCFINISHPREF: {
1741 // received a gcfinishpref msg
1742 processmsg_gcfinishpref_I();
1745 #endif // GC_CACHE_ADAPT
1746 #endif // #ifdef MULTICORE_GC
1751 msglength = BAMBOO_MSG_BUF_LENGTH;
1753 if((msgdataindex != msgdatalast) || (msgdatafull)) {
1754 // still have available msg
1758 BAMBOO_DEBUGPRINT(0xe88d);
1761 // have new coming msg
1762 if(BAMBOO_MSG_AVAIL() != 0) {
1767 #ifdef PROFILE_INTERRUPT
1768 if(!interruptInfoOverflow) {
1769 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
1770 interruptInfoIndex++;
1771 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
1772 interruptInfoOverflow = true;
1781 BAMBOO_DEBUGPRINT(0xe88e);