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();
648 tocontinue = trystartthread();
656 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
658 BAMBOO_DEBUGPRINT(0xee03);
664 BAMBOO_DEBUGPRINT(0xee09);
669 // wait for some time
671 BAMBOO_DEBUGPRINT(0xee0a);
676 // send StallMsg to startup core
677 BAMBOO_DEBUGPRINT(0xee0b);
679 send_msg_4(STARTUPCORE, TRANSTALL, BAMBOO_NUM_OF_CORE,
680 self_numsendobjs, self_numreceiveobjs, false);
691 BAMBOO_DEBUGPRINT(0xee0c);
693 } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE)
696 } // if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)
700 INLINE int checkMsgLength_I(int size) {
702 BAMBOO_DEBUGPRINT(0xcccc);
704 int type = msgdata[msgdataindex];
717 #ifdef GC_CACHE_ADAPT
719 #endif // GC_CACHE_ADAPT
720 #endif // MULTICORE_GC
734 case GCFINISHMAPINFO:
736 #ifdef GC_CACHE_ADAPT
738 #endif // GC_CACHE_ADAPT
739 #endif // MULTICORE_GC
765 case REDIRECTRELEASE:
785 case GCFINISHCOMPACT:
802 case TRANSOBJ: // nonfixed size
809 msglength = msgdata[(msgdataindex+1)&(BAMBOO_MSG_BUF_MASK)];
818 BAMBOO_DEBUGPRINT_REG(type);
819 BAMBOO_DEBUGPRINT_REG(size);
820 BAMBOO_DEBUGPRINT_REG(msgdataindex);
821 BAMBOO_DEBUGPRINT_REG(msgdatalast);
822 BAMBOO_DEBUGPRINT_REG(msgdatafull);
825 BAMBOO_DEBUGPRINT(msgdata[msgdataindex+i]);
832 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex]);
833 BAMBOO_DEBUGPRINT(0xffff);
838 INLINE void processmsg_transtall_I() {
839 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
840 // non startup core can not receive stall msg
842 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
846 int num_core = msgdata[msgdataindex]; //[1]
848 int data2 = msgdata[msgdataindex]; //[2];
850 int data3 = msgdata[msgdataindex]; //[3];
852 if(num_core < NUMCORESACTIVE) {
854 BAMBOO_DEBUGPRINT(0xe881);
856 corestatus[num_core] = 0;
857 numsendobjs[num_core] = data2; //[2];
858 numreceiveobjs[num_core] = data3; //[3];
862 INLINE void processmsg_statusconfirm_I() {
863 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
864 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
865 // wrong core to receive such msg
870 BAMBOO_DEBUGPRINT(0xe887);
872 // cache the msg first
873 if(BAMBOO_CHECK_SEND_MODE()) {
874 cache_msg_5(STARTUPCORE, STATUSREPORT,
875 busystatus ? 1 : 0, BAMBOO_NUM_OF_CORE,
876 self_numsendobjs, self_numreceiveobjs);
878 send_msg_5(STARTUPCORE, STATUSREPORT, busystatus?1:0,
879 BAMBOO_NUM_OF_CORE, self_numsendobjs,
880 self_numreceiveobjs, true);
885 INLINE void processmsg_statusreport_I() {
886 int data1 = msgdata[msgdataindex];
888 int data2 = msgdata[msgdataindex];
890 int data3 = msgdata[msgdataindex];
892 int data4 = msgdata[msgdataindex];
894 // receive a status confirm info
895 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
896 // wrong core to receive such msg
898 BAMBOO_DEBUGPRINT_REG(data2);
903 BAMBOO_DEBUGPRINT(0xe888);
908 corestatus[data2] = data1;
909 numsendobjs[data2] = data3;
910 numreceiveobjs[data2] = data4;
914 INLINE void processmsg_terminate_I() {
916 BAMBOO_DEBUGPRINT(0xe889);
920 #ifdef GC_CACHE_ADAPT
921 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
922 #endif // GC_CACHE_ADAPT
923 #endif // MULTICORE_GC
927 INLINE void processmsg_memrequest_I() {
928 int data1 = msgdata[msgdataindex];
930 int data2 = msgdata[msgdataindex];
932 // receive a shared memory request msg
933 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
934 // wrong core to receive such msg
936 BAMBOO_DEBUGPRINT_REG(data2);
941 BAMBOO_DEBUGPRINT(0xe88a);
947 // is currently doing gc, dump this msg
948 if(INITPHASE == gcphase) {
949 // if still in the initphase of gc, send a startinit msg again,
950 // cache the msg first
951 if(BAMBOO_CHECK_SEND_MODE()) {
952 cache_msg_1(data2, GCSTARTINIT);
954 send_msg_1(data2, GCSTARTINIT, true);
959 mem = smemalloc_I(data2, data1, &allocsize);
961 // send the start_va to request core, cache the msg first
962 if(BAMBOO_CHECK_SEND_MODE()) {
963 cache_msg_3(data2, MEMRESPONSE, mem, allocsize);
965 send_msg_3(data2, MEMRESPONSE, mem, allocsize, true);
968 // if mem == NULL, the gcflag of the startup core has been set
969 // and all the other cores have been informed to start gc
976 INLINE void processmsg_memresponse_I() {
977 int data1 = msgdata[msgdataindex];
979 int data2 = msgdata[msgdataindex];
981 // receive a shared memory response msg
983 BAMBOO_DEBUGPRINT(0xe88b);
986 // if is currently doing gc, dump this msg
990 bamboo_smem_size = 0;
993 bamboo_smem_zero_top = 0;
997 // fill header to store the size of this mem block
998 BAMBOO_MEMSET_WH(data1, '\0', BAMBOO_CACHE_LINE_SIZE);
999 (*((int*)data1)) = data2;
1000 bamboo_smem_size = data2 - BAMBOO_CACHE_LINE_SIZE;
1001 bamboo_cur_msp = data1 + BAMBOO_CACHE_LINE_SIZE;
1002 bamboo_smem_zero_top = bamboo_cur_msp;
1004 bamboo_smem_size = data2;
1005 bamboo_cur_msp =(void*)(data1);
1015 INLINE void processmsg_gcstartpre_I() {
1017 // already stall for gc
1018 // send a update pregc information msg to the master core
1019 if(BAMBOO_CHECK_SEND_MODE()) {
1020 cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
1021 self_numsendobjs, self_numreceiveobjs);
1023 send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
1024 self_numsendobjs, self_numreceiveobjs, true);
1027 // the first time to be informed to start gc
1030 // is waiting for response of mem request
1031 // let it return NULL and start gc
1032 bamboo_smem_size = 0;
1033 bamboo_cur_msp = NULL;
1035 bamboo_smem_zero_top = NULL;
1040 INLINE void processmsg_gcstartinit_I() {
1041 gcphase = INITPHASE;
1044 INLINE void processmsg_gcstart_I() {
1046 BAMBOO_DEBUGPRINT(0xe88c);
1049 gcphase = MARKPHASE;
1052 INLINE void processmsg_gcstartcompact_I() {
1053 gcblock2fill = msgdata[msgdataindex];
1054 MSG_INDEXINC_I(); //msgdata[1];
1055 gcphase = COMPACTPHASE;
1058 INLINE void processmsg_gcstartmapinfo_I() {
1062 INLINE void processmsg_gcstartflush_I() {
1063 gcphase = FLUSHPHASE;
1066 INLINE void processmsg_gcfinishpre_I() {
1067 int data1 = msgdata[msgdataindex];
1069 int data2 = msgdata[msgdataindex];
1071 int data3 = msgdata[msgdataindex];
1073 // received a init phase finish msg
1074 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1075 // non startup core can not receive this msg
1077 BAMBOO_DEBUGPRINT_REG(data1);
1079 BAMBOO_EXIT(0xe014);
1081 // All cores should do init GC
1085 gccorestatus[data1] = 0;
1086 gcnumsendobjs[0][data1] = data2;
1087 gcnumreceiveobjs[0][data1] = data3;
1090 INLINE void processmsg_gcfinishinit_I() {
1091 int data1 = msgdata[msgdataindex];
1093 // received a init phase finish msg
1094 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1095 // non startup core can not receive this msg
1097 BAMBOO_DEBUGPRINT_REG(data1);
1099 BAMBOO_EXIT(0xe015);
1102 BAMBOO_DEBUGPRINT(0xe88c);
1103 BAMBOO_DEBUGPRINT_REG(data1);
1105 // All cores should do init GC
1106 if(data1 < NUMCORESACTIVE) {
1107 gccorestatus[data1] = 0;
1111 INLINE void processmsg_gcfinishmark_I() {
1112 int data1 = msgdata[msgdataindex];
1114 int data2 = msgdata[msgdataindex];
1116 int data3 = msgdata[msgdataindex];
1118 // received a mark phase finish msg
1119 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1120 // non startup core can not receive this msg
1122 BAMBOO_DEBUGPRINT_REG(data1);
1124 BAMBOO_EXIT(0xe016);
1126 // all cores should do mark
1127 if(data1 < NUMCORESACTIVE) {
1128 gccorestatus[data1] = 0;
1129 int entry_index = 0;
1132 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1135 entry_index = gcnumsrobjs_index;
1137 gcnumsendobjs[entry_index][data1] = data2;
1138 gcnumreceiveobjs[entry_index][data1] = data3;
1142 INLINE void processmsg_gcfinishcompact_I() {
1143 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1144 // non startup core can not receive this msg
1147 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
1149 BAMBOO_EXIT(0xe017);
1151 int cnum = msgdata[msgdataindex];
1152 MSG_INDEXINC_I(); //msgdata[1];
1153 int filledblocks = msgdata[msgdataindex];
1154 MSG_INDEXINC_I(); //msgdata[2];
1155 int heaptop = msgdata[msgdataindex];
1156 MSG_INDEXINC_I(); //msgdata[3];
1157 int data4 = msgdata[msgdataindex];
1158 MSG_INDEXINC_I(); //msgdata[4];
1159 // only gc cores need to do compact
1160 if(cnum < NUMCORES4GC) {
1161 if(COMPACTPHASE == gcphase) {
1162 gcfilledblocks[cnum] = filledblocks;
1163 gcloads[cnum] = heaptop;
1170 if(gcfindSpareMem_I(&startaddr, &tomove, &dstcore, data4, cnum)) {
1171 // cache the msg first
1172 if(BAMBOO_CHECK_SEND_MODE()) {
1173 cache_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove);
1175 send_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove, true);
1179 gccorestatus[cnum] = 0;
1181 } // if(cnum < NUMCORES4GC)
1184 INLINE void processmsg_gcfinishmapinfo_I() {
1185 int data1 = msgdata[msgdataindex];
1187 // received a map phase finish msg
1188 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1189 // non startup core can not receive this msg
1191 BAMBOO_DEBUGPRINT_REG(data1);
1193 BAMBOO_EXIT(0xe018);
1195 // all cores should do flush
1196 if(data1 < NUMCORES4GC) {
1197 gccorestatus[data1] = 0;
1202 INLINE void processmsg_gcfinishflush_I() {
1203 int data1 = msgdata[msgdataindex];
1205 // received a flush phase finish msg
1206 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1207 // non startup core can not receive this msg
1209 BAMBOO_DEBUGPRINT_REG(data1);
1211 BAMBOO_EXIT(0xe019);
1213 // all cores should do flush
1214 if(data1 < NUMCORESACTIVE) {
1215 gccorestatus[data1] = 0;
1219 INLINE void processmsg_gcmarkconfirm_I() {
1220 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
1221 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
1222 // wrong core to receive such msg
1223 BAMBOO_EXIT(0xe01a);
1225 // send response msg, cahce the msg first
1226 if(BAMBOO_CHECK_SEND_MODE()) {
1227 cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1228 gcbusystatus, gcself_numsendobjs,
1229 gcself_numreceiveobjs);
1231 send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1232 gcbusystatus, gcself_numsendobjs,
1233 gcself_numreceiveobjs, true);
1238 INLINE void processmsg_gcmarkreport_I() {
1239 int data1 = msgdata[msgdataindex];
1241 int data2 = msgdata[msgdataindex];
1243 int data3 = msgdata[msgdataindex];
1245 int data4 = msgdata[msgdataindex];
1247 // received a marked phase finish confirm response msg
1248 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1249 // wrong core to receive such msg
1251 BAMBOO_DEBUGPRINT_REG(data2);
1253 BAMBOO_EXIT(0xe01b);
1255 int entry_index = 0;
1259 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1261 // can never reach here
1263 entry_index = gcnumsrobjs_index;
1265 gccorestatus[data1] = data2;
1266 gcnumsendobjs[entry_index][data1] = data3;
1267 gcnumreceiveobjs[entry_index][data1] = data4;
1271 INLINE void processmsg_gcmarkedobj_I() {
1272 int data1 = msgdata[msgdataindex];
1274 // received a markedObj msg
1275 if(((int *)data1)[6] == INIT) {
1276 // this is the first time that this object is discovered,
1277 // set the flag as DISCOVERED
1278 ((int *)data1)[6] = DISCOVERED;
1279 gc_enqueue_I(data1);
1281 // set the remote flag
1282 ((int *)data1)[6] |= REMOTEM;
1283 gcself_numreceiveobjs++;
1284 gcbusystatus = true;
1287 INLINE void processmsg_gcmovestart_I() {
1289 gcdstcore = msgdata[msgdataindex];
1290 MSG_INDEXINC_I(); //msgdata[1];
1291 gcmovestartaddr = msgdata[msgdataindex];
1292 MSG_INDEXINC_I(); //msgdata[2];
1293 gcblock2fill = msgdata[msgdataindex];
1294 MSG_INDEXINC_I(); //msgdata[3];
1297 INLINE void processmsg_gcmaprequest_I() {
1298 void * dstptr = NULL;
1299 int data1 = msgdata[msgdataindex];
1301 int data2 = msgdata[msgdataindex];
1303 #ifdef LOCALHASHTBL_TEST
1304 RuntimeHashget(gcpointertbl, data1, &dstptr);
1306 dstptr = mgchashSearch(gcpointertbl, data1);
1308 if(NULL == dstptr) {
1309 // no such pointer in this core, something is wrong
1311 BAMBOO_DEBUGPRINT_REG(data1);
1312 BAMBOO_DEBUGPRINT_REG(data2);
1314 BAMBOO_EXIT(0xe01c);
1316 // send back the mapping info, cache the msg first
1317 if(BAMBOO_CHECK_SEND_MODE()) {
1318 cache_msg_3(data2, GCMAPINFO, data1, (int)dstptr);
1320 send_msg_3(data2, GCMAPINFO, data1, (int)dstptr, true);
1325 INLINE void processmsg_gcmapinfo_I() {
1326 int data1 = msgdata[msgdataindex];
1328 gcmappedobj = msgdata[msgdataindex]; // [2]
1330 #ifdef LOCALHASHTBL_TEST
1331 RuntimeHashadd_I(gcpointertbl, data1, gcmappedobj);
1333 mgchashInsert_I(gcpointertbl, data1, gcmappedobj);
1335 if(data1 == gcobj2map) {
1340 INLINE void processmsg_gcmaptbl_I() {
1341 int data1 = msgdata[msgdataindex];
1343 int data2 = msgdata[msgdataindex];
1345 gcrpointertbls[data2] = (mgcsharedhashtbl_t *)data1;
1348 INLINE void processmsg_gclobjinfo_I() {
1351 int data1 = msgdata[msgdataindex];
1353 int data2 = msgdata[msgdataindex];
1355 if(BAMBOO_NUM_OF_CORE > NUMCORES4GC - 1) {
1357 BAMBOO_DEBUGPRINT_REG(data2);
1359 BAMBOO_EXIT(0xe01d);
1361 // store the mark result info
1363 gcloads[cnum] = msgdata[msgdataindex];
1364 MSG_INDEXINC_I(); // msgdata[3];
1365 int data4 = msgdata[msgdataindex];
1367 if(gcheaptop < data4) {
1370 // large obj info here
1371 for(int k = 5; k < data1; k+=2) {
1372 int lobj = msgdata[msgdataindex];
1373 MSG_INDEXINC_I(); //msgdata[k++];
1374 int length = msgdata[msgdataindex];
1375 MSG_INDEXINC_I(); //msgdata[k++];
1376 gc_lobjenqueue_I(lobj, length, cnum);
1378 } // for(int k = 5; k < msgdata[1];)
1381 INLINE void processmsg_gclobjmapping_I() {
1382 int data1 = msgdata[msgdataindex];
1384 int data2 = msgdata[msgdataindex];
1386 #ifdef LOCALHASHTBL_TEST
1387 RuntimeHashadd_I(gcpointertbl, data1, data2);
1389 mgchashInsert_I(gcpointertbl, data1, data2);
1391 mgcsharedhashInsert_I(gcsharedptbl, data1, data2);
1395 INLINE void processmsg_gcprofiles_I() {
1396 int data1 = msgdata[msgdataindex];
1398 int data2 = msgdata[msgdataindex];
1400 int data3 = msgdata[msgdataindex];
1402 gc_num_obj += data1;
1403 gc_num_liveobj += data2;
1404 gc_num_forwardobj += data3;
1407 #endif // GC_PROFILE
1409 #ifdef GC_CACHE_ADAPT
1410 INLINE void processmsg_gcstartpref_I() {
1411 gcphase = PREFINISHPHASE;
1414 INLINE void processmsg_gcfinishpref_I() {
1415 int data1 = msgdata[msgdataindex];
1417 // received a flush phase finish msg
1418 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1419 // non startup core can not receive this msg
1421 BAMBOO_DEBUGPRINT_REG(data1);
1423 BAMBOO_EXIT(0xe01e);
1425 // all cores should do flush
1426 if(data1 < NUMCORESACTIVE) {
1427 gccorestatus[data1] = 0;
1430 #endif // GC_CACHE_ADAPT
1431 #endif // #ifdef MULTICORE_GC
1433 // receive object transferred from other cores
1434 // or the terminate message from other cores
1435 // Should be invoked in critical sections!!
1436 // NOTICE: following format is for threadsimulate version only
1437 // RAW version please see previous description
1438 // format: type + object
1439 // type: -1--stall msg
1441 // return value: 0--received an object
1442 // 1--received nothing
1443 // 2--received a Stall Msg
1444 // 3--received a lock Msg
1445 // RAW version: -1 -- received nothing
1446 // otherwise -- received msg type
1447 int receiveObject(int send_port_pending) {
1449 #ifdef PROFILE_INTERRUPT
1450 if(!interruptInfoOverflow) {
1451 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
1452 interruptInfoArray[interruptInfoIndex] = intInfo;
1453 intInfo->startTime = BAMBOO_GET_EXE_TIME();
1454 intInfo->endTime = -1;
1456 #endif // PROFILE_INTERRUPT
1459 // get the incoming msgs
1460 if(receiveMsg(send_port_pending) == -1) {
1464 // processing received msgs
1466 MSG_REMAINSIZE_I(&size);
1467 if((size == 0) || (checkMsgLength_I(size) == -1)) {
1469 // have new coming msg
1470 if((BAMBOO_MSG_AVAIL() != 0) && !msgdatafull) {
1477 if(msglength <= size) {
1478 // have some whole msg
1480 type = msgdata[msgdataindex]; //[0]
1482 msgdatafull = false;
1486 // receive a object transfer msg
1487 processmsg_transobj_I();
1493 // receive a stall msg
1494 processmsg_transtall_I();
1499 // GC version have no lock msgs
1500 #ifndef MULTICORE_GC
1502 // receive lock request msg, handle it right now
1503 processmsg_lockrequest_I();
1505 } // case LOCKREQUEST
1508 // receive lock grount msg
1509 processmsg_lockgrount_I();
1511 } // case LOCKGROUNT
1514 // receive lock deny msg
1515 processmsg_lockdeny_I();
1520 processmsg_lockrelease_I();
1522 } // case LOCKRELEASE
1523 #endif // #ifndef MULTICORE_GC
1526 case PROFILEOUTPUT: {
1527 // receive an output profile data request msg
1528 processmsg_profileoutput_I();
1530 } // case PROFILEOUTPUT
1532 case PROFILEFINISH: {
1533 // receive a profile output finish msg
1534 processmsg_profilefinish_I();
1536 } // case PROFILEFINISH
1537 #endif // #ifdef PROFILE
1539 // GC version has no lock msgs
1540 #ifndef MULTICORE_GC
1541 case REDIRECTLOCK: {
1542 // receive a redirect lock request msg, handle it right now
1543 processmsg_redirectlock_I();
1545 } // case REDIRECTLOCK
1547 case REDIRECTGROUNT: {
1548 // receive a lock grant msg with redirect info
1549 processmsg_redirectgrount_I();
1551 } // case REDIRECTGROUNT
1553 case REDIRECTDENY: {
1554 // receive a lock deny msg with redirect info
1555 processmsg_redirectdeny_I();
1557 } // case REDIRECTDENY
1559 case REDIRECTRELEASE: {
1560 // receive a lock release msg with redirect info
1561 processmsg_redirectrelease_I();
1563 } // case REDIRECTRELEASE
1564 #endif // #ifndef MULTICORE_GC
1567 case STATUSCONFIRM: {
1568 // receive a status confirm info
1569 processmsg_statusconfirm_I();
1571 } // case STATUSCONFIRM
1573 case STATUSREPORT: {
1574 processmsg_statusreport_I();
1576 } // case STATUSREPORT
1579 // receive a terminate msg
1580 processmsg_terminate_I();
1585 processmsg_memrequest_I();
1587 } // case MEMREQUEST
1590 processmsg_memresponse_I();
1592 } // case MEMRESPONSE
1597 processmsg_gcstartpre_I();
1599 } // case GCSTARTPRE
1602 processmsg_gcstartinit_I();
1604 } // case GCSTARTINIT
1607 // receive a start GC msg
1608 processmsg_gcstart_I();
1612 case GCSTARTCOMPACT: {
1613 // a compact phase start msg
1614 processmsg_gcstartcompact_I();
1616 } // case GCSTARTCOMPACT
1618 case GCSTARTMAPINFO: {
1619 // received a flush phase start msg
1620 processmsg_gcstartmapinfo_I();
1622 } // case GCSTARTFLUSH
1624 case GCSTARTFLUSH: {
1625 // received a flush phase start msg
1626 processmsg_gcstartflush_I();
1628 } // case GCSTARTFLUSH
1631 processmsg_gcfinishpre_I();
1633 } // case GCFINISHPRE
1635 case GCFINISHINIT: {
1636 processmsg_gcfinishinit_I();
1638 } // case GCFINISHINIT
1640 case GCFINISHMARK: {
1641 processmsg_gcfinishmark_I();
1643 } // case GCFINISHMARK
1645 case GCFINISHCOMPACT: {
1646 // received a compact phase finish msg
1647 processmsg_gcfinishcompact_I();
1649 } // case GCFINISHCOMPACT
1651 case GCFINISHMAPINFO: {
1652 processmsg_gcfinishmapinfo_I();
1654 } // case GCFINISHMAPINFO
1656 case GCFINISHFLUSH: {
1657 processmsg_gcfinishflush_I();
1659 } // case GCFINISHFLUSH
1662 // received a GC finish msg
1663 gcphase = FINISHPHASE;
1667 case GCMARKCONFIRM: {
1668 // received a marked phase finish confirm request msg
1669 // all cores should do mark
1670 processmsg_gcmarkconfirm_I();
1672 } // case GCMARKCONFIRM
1674 case GCMARKREPORT: {
1675 processmsg_gcmarkreport_I();
1677 } // case GCMARKREPORT
1680 processmsg_gcmarkedobj_I();
1682 } // case GCMARKEDOBJ
1685 // received a start moving objs msg
1686 processmsg_gcmovestart_I();
1688 } // case GCMOVESTART
1690 case GCMAPREQUEST: {
1691 // received a mapping info request msg
1692 processmsg_gcmaprequest_I();
1694 } // case GCMAPREQUEST
1697 // received a mapping info response msg
1698 processmsg_gcmapinfo_I();
1703 // received a mapping tbl response msg
1704 processmsg_gcmaptbl_I();
1708 case GCLOBJREQUEST: {
1709 // received a large objs info request msg
1710 transferMarkResults_I();
1712 } // case GCLOBJREQUEST
1715 // received a large objs info response msg
1716 processmsg_gclobjinfo_I();
1718 } // case GCLOBJINFO
1720 case GCLOBJMAPPING: {
1721 // received a large obj mapping info msg
1722 processmsg_gclobjmapping_I();
1724 } // case GCLOBJMAPPING
1728 // received a gcprofiles msg
1729 processmsg_gcprofiles_I();
1732 #endif // GC_PROFILE
1734 #ifdef GC_CACHE_ADAPT
1736 // received a gcstartpref msg
1737 processmsg_gcstartpref_I();
1741 case GCFINISHPREF: {
1742 // received a gcfinishpref msg
1743 processmsg_gcfinishpref_I();
1746 #endif // GC_CACHE_ADAPT
1747 #endif // #ifdef MULTICORE_GC
1752 msglength = BAMBOO_MSG_BUF_LENGTH;
1754 if((msgdataindex != msgdatalast) || (msgdatafull)) {
1755 // still have available msg
1759 BAMBOO_DEBUGPRINT(0xe88d);
1762 // have new coming msg
1763 if(BAMBOO_MSG_AVAIL() != 0) {
1768 #ifdef PROFILE_INTERRUPT
1769 if(!interruptInfoOverflow) {
1770 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
1771 interruptInfoIndex++;
1772 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
1773 interruptInfoOverflow = true;
1782 BAMBOO_DEBUGPRINT(0xe88e);