4 #include "multicoreruntime.h"
5 #include "runtime_arch.h"
6 #include "GenericHashtable.h"
7 #include "structdefs.h"
17 #define INLINE inline __attribute__((always_inline))
18 #endif // #ifndef INLINE
20 extern int classsize[];
21 extern int typearray[];
22 extern int typearray2[];
25 extern struct genhashtable * activetasks;
29 extern unsigned int gcmem_mixed_threshold;
30 extern unsigned int gcmem_mixed_usedmem;
32 #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 /* Object allocation function */
125 void * allocate_new(void * ptr, int type) {
126 struct ___Object___ * v=
127 (struct ___Object___*)FREEMALLOC((struct garbagelist*) ptr,classsize[type]);
134 extern unsigned int gc_num_obj;
140 /* Array allocation function */
142 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
143 struct ArrayObject * v=(struct ArrayObject *)
144 FREEMALLOC((struct garbagelist*)ptr,
145 sizeof(struct ArrayObject)+length*classsize[type]);
152 v->___length___=length;
155 extern unsigned int gc_num_obj;
162 void * allocate_new(int type) {
163 struct ___Object___ * v=FREEMALLOC(classsize[type]);
171 /* Array allocation function */
173 struct ArrayObject * allocate_newarray(int type, int length) {
174 struct ArrayObject * v=
175 FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
179 v->___length___=length;
186 /* Converts C character arrays into Java strings */
188 struct ___String___ * NewString(void * ptr, const char *str,int length) {
190 struct ___String___ * NewString(const char *str,int length) {
194 struct ArrayObject * chararray=
195 allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
196 int ptrarray[]={1, (int) ptr, (int) chararray};
197 struct ___String___ * strobj=
198 allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
199 chararray=(struct ArrayObject *) ptrarray[2];
201 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
202 struct ___String___ * strobj=allocate_new(STRINGTYPE);
204 strobj->___value___=chararray;
205 strobj->___count___=length;
206 strobj->___offset___=0;
208 for(i=0; i<length; i++) {
209 ((short*)(((char*)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
214 /* Generated code calls this if we fail a bounds check */
216 void failedboundschk() {
218 printf("Array out of bounds\n");
226 printf("Array out of bounds\n");
227 longjmp(error_handler,2);
234 /* Abort task call */
238 printf("Aborting\n");
239 longjmp(error_handler,4);
242 printf("Aborting\n");
247 INLINE void initruntimedata() {
249 // initialize the arrays
250 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
251 // startup core to initialize corestatus[]
252 for(i = 0; i < NUMCORESACTIVE; ++i) {
255 numreceiveobjs[i] = 0;
258 gcnumsendobjs[0][i] = gcnumsendobjs[1][i] = 0;
259 gcnumreceiveobjs[0][i] = gcnumreceiveobjs[1][i] = 0;
261 } // for(i = 0; i < NUMCORESACTIVE; ++i)
263 for(i = 0; i < NUMCORES4GC; ++i) {
265 gcrequiredmems[i] = 0;
267 gcfilledblocks[i] = 0;
268 } // for(i = 0; i < NUMCORES4GC; ++i)
271 gc_infoOverflow = false;
272 gc_num_livespace = 0;
273 gc_num_freespace = 0;
281 self_numsendobjs = 0;
282 self_numreceiveobjs = 0;
284 for(i = 0; i < BAMBOO_MSG_BUF_LENGTH; ++i) {
289 msglength = BAMBOO_MSG_BUF_LENGTH;
291 for(i = 0; i < BAMBOO_OUT_BUF_LENGTH; ++i) {
297 isMsgHanging = false;
300 bamboo_cur_msp = NULL;
301 bamboo_smem_size = 0;
304 bamboo_smem_zero_top = NULL;
306 gcprocessing = false;
307 gcphase = FINISHPHASE;
310 gcself_numsendobjs = 0;
311 gcself_numreceiveobjs = 0;
312 gcmarkedptrbound = 0;
313 #ifdef LOCALHASHTBL_TEST
314 gcpointertbl = allocateRuntimeHash_I(20);
316 gcpointertbl = mgchashCreate_I(2000, 0.75);
318 gcforwardobjtbl = allocateMGCHash_I(20, 3);
329 gcsbstarttbl = BAMBOO_BASE_VA;
330 bamboo_smemtbl = (void *)gcsbstarttbl
331 + (BAMBOO_SHARED_MEM_SIZE/BAMBOO_SMEM_SIZE)*sizeof(INTPTR);
332 if(BAMBOO_NUM_OF_CORE < NUMCORES4GC) {
333 int t_size = ((BAMBOO_RMSP_SIZE)-sizeof(mgcsharedhashtbl_t)*2
334 -128*sizeof(size_t))/sizeof(mgcsharedhashlistnode_t)-2;
336 unsigned int tmp_k = 1 << (sizeof(int)*8 -1);
337 while(((t_size & tmp_k) == 0) && (kk < sizeof(int)*8)) {
338 t_size = t_size << 1;
341 t_size = tmp_k >> kk;
342 gcsharedptbl = mgcsharedhashCreate_I(t_size,0.30);
346 BAMBOO_MEMSET_WH(gcrpointertbls, 0,
347 sizeof(mgcsharedhashtbl_t *)*NUMCORES4GC);
349 gcmem_mixed_threshold = (unsigned int)((BAMBOO_SHARED_MEM_SIZE
350 -bamboo_reserved_smem*BAMBOO_SMEM_SIZE)*0.8);
351 gcmem_mixed_usedmem = 0;
356 gc_num_forwardobj = 0;
357 gc_num_profiles = NUMCORESACTIVE - 1;
360 gc_num_flush_dtlb = 0;
362 gc_localheap_s = false;
363 #ifdef GC_CACHE_ADAPT
364 gccachestage = false;
365 #endif // GC_CACHE_ADAPT
366 #endif // MULTICORE_GC
381 INLINE void disruntimedata() {
383 #ifdef LOCALHASHTBL_TEST
384 freeRuntimeHash(gcpointertbl);
386 mgchashDelete(gcpointertbl);
388 freeMGCHash(gcforwardobjtbl);
389 #endif // MULTICORE_GC
393 BAMBOO_LOCAL_MEM_CLOSE();
394 BAMBOO_SHARE_MEM_CLOSE();
397 INLINE void checkCoreStatus() {
398 bool allStall = false;
402 (waitconfirm && (numconfirm == 0))) {
403 BAMBOO_DEBUGPRINT(0xee04);
404 BAMBOO_DEBUGPRINT_REG(waitconfirm);
405 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
406 BAMBOO_DEBUGPRINT(0xf001);
407 corestatus[BAMBOO_NUM_OF_CORE] = 0;
408 numsendobjs[BAMBOO_NUM_OF_CORE] = self_numsendobjs;
409 numreceiveobjs[BAMBOO_NUM_OF_CORE] = self_numreceiveobjs;
410 // check the status of all cores
412 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
413 for(i = 0; i < NUMCORESACTIVE; ++i) {
414 BAMBOO_DEBUGPRINT(0xe000 + corestatus[i]);
415 if(corestatus[i] != 0) {
419 } // for(i = 0; i < NUMCORESACTIVE; ++i)
421 // check if the sum of send objs and receive obj are the same
422 // yes->check if the info is the latest; no->go on executing
424 for(i = 0; i < NUMCORESACTIVE; ++i) {
425 sumsendobj += numsendobjs[i];
426 BAMBOO_DEBUGPRINT(0xf000 + numsendobjs[i]);
427 } // for(i = 0; i < NUMCORESACTIVE; ++i)
428 for(i = 0; i < NUMCORESACTIVE; ++i) {
429 sumsendobj -= numreceiveobjs[i];
430 BAMBOO_DEBUGPRINT(0xf000 + numreceiveobjs[i]);
431 } // for(i = 0; i < NUMCORESACTIVE; ++i)
432 if(0 == sumsendobj) {
434 // the first time found all cores stall
435 // send out status confirm msg to all other cores
436 // reset the corestatus array too
437 BAMBOO_DEBUGPRINT(0xee05);
438 corestatus[BAMBOO_NUM_OF_CORE] = 1;
440 numconfirm = NUMCORESACTIVE - 1;
441 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
442 for(i = 1; i < NUMCORESACTIVE; ++i) {
444 // send status confirm msg to core i
445 send_msg_1(i, STATUSCONFIRM, false);
446 } // for(i = 1; i < NUMCORESACTIVE; ++i)
449 // all the core status info are the latest
450 // terminate; for profiling mode, send request to all
451 // other cores to pour out profiling data
452 BAMBOO_DEBUGPRINT(0xee06);
455 totalexetime = BAMBOO_GET_EXE_TIME() - bamboo_start_time;
458 BAMBOO_PRINT(BAMBOO_GET_EXE_TIME() - bamboo_start_time);
459 //BAMBOO_DEBUGPRINT_REG(total_num_t6); // TODO for test
461 BAMBOO_PRINT_REG(gc_num_flush_dtlb);
463 #ifndef BAMBOO_MEMPROF
464 BAMBOO_PRINT(0xbbbbbbbb);
467 // profile mode, send msgs to other cores to request pouring
468 // out progiling data
470 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
471 BAMBOO_DEBUGPRINT(0xf000);
472 for(i = 1; i < NUMCORESACTIVE; ++i) {
473 // send profile request msg to core i
474 send_msg_2(i, PROFILEOUTPUT, totalexetime, false);
475 } // for(i = 1; i < NUMCORESACTIVE; ++i)
477 // pour profiling data on startup core
481 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
482 BAMBOO_DEBUGPRINT(0xf001);
483 profilestatus[BAMBOO_NUM_OF_CORE] = 0;
484 // check the status of all cores
486 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
487 for(i = 0; i < NUMCORESACTIVE; ++i) {
488 BAMBOO_DEBUGPRINT(0xe000 + profilestatus[i]);
489 if(profilestatus[i] != 0) {
493 } // for(i = 0; i < NUMCORESACTIVE; ++i)
496 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
497 BAMBOO_DEBUGPRINT(0xf000);
501 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
507 // gc_profile mode, output gc prfiling data
509 #ifdef GC_CACHE_ADAPT
510 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
511 #endif // GC_CACHE_ADAPT
513 gc_outputProfileData();
514 #endif // #ifdef GC_PROFILE
515 #endif // #ifdef MULTICORE_GC
517 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
518 terminate(); // All done.
519 } // if(!waitconfirm)
521 // still some objects on the fly on the network
522 // reset the waitconfirm and numconfirm
523 BAMBOO_DEBUGPRINT(0xee07);
526 } // if(0 == sumsendobj)
528 // not all cores are stall, keep on waiting
529 BAMBOO_DEBUGPRINT(0xee08);
533 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
534 BAMBOO_DEBUGPRINT(0xf000);
535 } // if((!waitconfirm) ||
538 // main function for each core
539 inline void run(void * arg) {
543 bool sendStall = false;
545 bool tocontinue = false;
547 corenum = BAMBOO_GET_NUM_OF_CORE();
548 BAMBOO_DEBUGPRINT(0xeeee);
549 BAMBOO_DEBUGPRINT_REG(corenum);
550 BAMBOO_DEBUGPRINT(STARTUPCORE);
552 // initialize runtime data structures
555 // other architecture related initialization
559 #ifdef GC_CACHE_ADAPT
560 // enable the timer interrupt
561 #ifdef GC_CACHE_SAMPLING
562 bamboo_tile_timer_set_next_event(GC_TILE_TIMER_EVENT_SETTING); // TODO
563 bamboo_unmask_timer_intr();
564 bamboo_dtlb_sampling_process();
565 #endif // GC_CACHE_SAMPLING
566 #endif // GC_CACHE_ADAPT
568 initializeexithandler();
570 // main process of the execution module
571 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
573 // non-executing cores, only processing communications
579 /* Create queue of active tasks */
581 genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
582 (int (*)(void *,void *)) &comparetpd);
584 /* Process task information */
587 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
588 /* Create startup object */
589 createstartupobject(argc, argv);
592 BAMBOO_DEBUGPRINT(0xee00);
598 // check if need to do GC
602 #endif // MULTICORE_GC
605 // check if there are new active tasks can be executed
612 while(receiveObject() != -1) {
616 BAMBOO_DEBUGPRINT(0xee01);
618 // check if there are some pending objects,
619 // if yes, enqueue them and executetasks again
620 tocontinue = checkObjQueue();
627 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
629 BAMBOO_DEBUGPRINT(0xee03);
635 BAMBOO_DEBUGPRINT(0xee09);
640 // wait for some time
642 BAMBOO_DEBUGPRINT(0xee0a);
647 // send StallMsg to startup core
648 BAMBOO_DEBUGPRINT(0xee0b);
650 send_msg_4(STARTUPCORE, TRANSTALL, BAMBOO_NUM_OF_CORE,
651 self_numsendobjs, self_numreceiveobjs, false);
662 BAMBOO_DEBUGPRINT(0xee0c);
664 } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE)
667 } // if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)
671 INLINE int checkMsgLength_I(int size) {
673 BAMBOO_DEBUGPRINT(0xcccc);
675 int type = msgdata[msgdataindex];
688 #ifdef GC_CACHE_ADAPT
690 #endif // GC_CACHE_ADAPT
691 #endif // MULTICORE_GC
705 case GCFINISHMAPINFO:
707 #ifdef GC_CACHE_ADAPT
709 #endif // GC_CACHE_ADAPT
710 #endif // MULTICORE_GC
736 case REDIRECTRELEASE:
756 case GCFINISHCOMPACT:
773 case TRANSOBJ: // nonfixed size
780 msglength = msgdata[(msgdataindex+1)&(BAMBOO_MSG_BUF_MASK)];
789 BAMBOO_DEBUGPRINT_REG(type);
790 BAMBOO_DEBUGPRINT_REG(size);
791 BAMBOO_DEBUGPRINT_REG(msgdataindex);
792 BAMBOO_DEBUGPRINT_REG(msgdatalast);
793 BAMBOO_DEBUGPRINT_REG(msgdatafull);
796 BAMBOO_DEBUGPRINT(msgdata[msgdataindex+i]);
803 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex]);
804 BAMBOO_DEBUGPRINT(0xffff);
809 INLINE void processmsg_transtall_I() {
810 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
811 // non startup core can not receive stall msg
813 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
817 int num_core = msgdata[msgdataindex]; //[1]
819 int data2 = msgdata[msgdataindex]; //[2];
821 int data3 = msgdata[msgdataindex]; //[3];
823 if(num_core < NUMCORESACTIVE) {
825 BAMBOO_DEBUGPRINT(0xe881);
827 corestatus[num_core] = 0;
828 numsendobjs[num_core] = data2; //[2];
829 numreceiveobjs[num_core] = data3; //[3];
833 INLINE void processmsg_statusconfirm_I() {
834 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
835 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
836 // wrong core to receive such msg
841 BAMBOO_DEBUGPRINT(0xe887);
843 // cache the msg first
844 if(BAMBOO_CHECK_SEND_MODE()) {
845 cache_msg_5(STARTUPCORE, STATUSREPORT,
846 busystatus ? 1 : 0, BAMBOO_NUM_OF_CORE,
847 self_numsendobjs, self_numreceiveobjs);
849 send_msg_5(STARTUPCORE, STATUSREPORT, busystatus?1:0,
850 BAMBOO_NUM_OF_CORE, self_numsendobjs,
851 self_numreceiveobjs, true);
856 INLINE void processmsg_statusreport_I() {
857 int data1 = msgdata[msgdataindex];
859 int data2 = msgdata[msgdataindex];
861 int data3 = msgdata[msgdataindex];
863 int data4 = msgdata[msgdataindex];
865 // receive a status confirm info
866 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
867 // wrong core to receive such msg
869 BAMBOO_DEBUGPRINT_REG(data2);
874 BAMBOO_DEBUGPRINT(0xe888);
879 corestatus[data2] = data1;
880 numsendobjs[data2] = data3;
881 numreceiveobjs[data2] = data4;
885 INLINE void processmsg_terminate_I() {
887 BAMBOO_DEBUGPRINT(0xe889);
891 #ifdef GC_CACHE_ADAPT
892 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
893 #endif // GC_CACHE_ADAPT
894 #endif // MULTICORE_GC
898 INLINE void processmsg_memrequest_I() {
899 int data1 = msgdata[msgdataindex];
901 int data2 = msgdata[msgdataindex];
903 // receive a shared memory request msg
904 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
905 // wrong core to receive such msg
907 BAMBOO_DEBUGPRINT_REG(data2);
912 BAMBOO_DEBUGPRINT(0xe88a);
918 // is currently doing gc, dump this msg
919 if(INITPHASE == gcphase) {
920 // if still in the initphase of gc, send a startinit msg again,
921 // cache the msg first
922 if(BAMBOO_CHECK_SEND_MODE()) {
923 cache_msg_1(data2, GCSTARTINIT);
925 send_msg_1(data2, GCSTARTINIT, true);
930 mem = smemalloc_I(data2, data1, &allocsize);
932 // send the start_va to request core, cache the msg first
933 if(BAMBOO_CHECK_SEND_MODE()) {
934 cache_msg_3(data2, MEMRESPONSE, mem, allocsize);
936 send_msg_3(data2, MEMRESPONSE, mem, allocsize, true);
939 // if mem == NULL, the gcflag of the startup core has been set
940 // and all the other cores have been informed to start gc
947 INLINE void processmsg_memresponse_I() {
948 int data1 = msgdata[msgdataindex];
950 int data2 = msgdata[msgdataindex];
952 // receive a shared memory response msg
954 BAMBOO_DEBUGPRINT(0xe88b);
957 // if is currently doing gc, dump this msg
961 bamboo_smem_size = 0;
964 bamboo_smem_zero_top = 0;
968 // fill header to store the size of this mem block
969 BAMBOO_MEMSET_WH(data1, '\0', BAMBOO_CACHE_LINE_SIZE);
970 (*((int*)data1)) = data2;
971 bamboo_smem_size = data2 - BAMBOO_CACHE_LINE_SIZE;
972 bamboo_cur_msp = data1 + BAMBOO_CACHE_LINE_SIZE;
973 bamboo_smem_zero_top = bamboo_cur_msp;
975 bamboo_smem_size = data2;
976 bamboo_cur_msp =(void*)(data1);
986 INLINE void processmsg_gcstartpre_I() {
988 // already stall for gc
989 // send a update pregc information msg to the master core
990 if(BAMBOO_CHECK_SEND_MODE()) {
991 cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
992 self_numsendobjs, self_numreceiveobjs);
994 send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
995 self_numsendobjs, self_numreceiveobjs, true);
998 // the first time to be informed to start gc
1001 // is waiting for response of mem request
1002 // let it return NULL and start gc
1003 bamboo_smem_size = 0;
1004 bamboo_cur_msp = NULL;
1006 bamboo_smem_zero_top = NULL;
1011 INLINE void processmsg_gcstartinit_I() {
1012 gcphase = INITPHASE;
1015 INLINE void processmsg_gcstart_I() {
1017 BAMBOO_DEBUGPRINT(0xe88c);
1020 gcphase = MARKPHASE;
1023 INLINE void processmsg_gcstartcompact_I() {
1024 gcblock2fill = msgdata[msgdataindex];
1025 MSG_INDEXINC_I(); //msgdata[1];
1026 gcphase = COMPACTPHASE;
1029 INLINE void processmsg_gcstartmapinfo_I() {
1033 INLINE void processmsg_gcstartflush_I() {
1034 gcphase = FLUSHPHASE;
1037 INLINE void processmsg_gcfinishpre_I() {
1038 int data1 = msgdata[msgdataindex];
1040 int data2 = msgdata[msgdataindex];
1042 int data3 = msgdata[msgdataindex];
1044 // received a init phase finish msg
1045 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1046 // non startup core can not receive this msg
1048 BAMBOO_DEBUGPRINT_REG(data1);
1050 BAMBOO_EXIT(0xe014);
1052 // All cores should do init GC
1056 gccorestatus[data1] = 0;
1057 gcnumsendobjs[0][data1] = data2;
1058 gcnumreceiveobjs[0][data1] = data3;
1061 INLINE void processmsg_gcfinishinit_I() {
1062 int data1 = msgdata[msgdataindex];
1064 // received a init phase finish msg
1065 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1066 // non startup core can not receive this msg
1068 BAMBOO_DEBUGPRINT_REG(data1);
1070 BAMBOO_EXIT(0xe015);
1073 BAMBOO_DEBUGPRINT(0xe88c);
1074 BAMBOO_DEBUGPRINT_REG(data1);
1076 // All cores should do init GC
1077 if(data1 < NUMCORESACTIVE) {
1078 gccorestatus[data1] = 0;
1082 INLINE void processmsg_gcfinishmark_I() {
1083 int data1 = msgdata[msgdataindex];
1085 int data2 = msgdata[msgdataindex];
1087 int data3 = msgdata[msgdataindex];
1089 // received a mark phase finish msg
1090 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1091 // non startup core can not receive this msg
1093 BAMBOO_DEBUGPRINT_REG(data1);
1095 BAMBOO_EXIT(0xe016);
1097 // all cores should do mark
1098 if(data1 < NUMCORESACTIVE) {
1099 gccorestatus[data1] = 0;
1100 int entry_index = 0;
1103 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1106 entry_index = gcnumsrobjs_index;
1108 gcnumsendobjs[entry_index][data1] = data2;
1109 gcnumreceiveobjs[entry_index][data1] = data3;
1113 INLINE void processmsg_gcfinishcompact_I() {
1114 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1115 // non startup core can not receive this msg
1118 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
1120 BAMBOO_EXIT(0xe017);
1122 int cnum = msgdata[msgdataindex];
1123 MSG_INDEXINC_I(); //msgdata[1];
1124 int filledblocks = msgdata[msgdataindex];
1125 MSG_INDEXINC_I(); //msgdata[2];
1126 int heaptop = msgdata[msgdataindex];
1127 MSG_INDEXINC_I(); //msgdata[3];
1128 int data4 = msgdata[msgdataindex];
1129 MSG_INDEXINC_I(); //msgdata[4];
1130 // only gc cores need to do compact
1131 if(cnum < NUMCORES4GC) {
1132 if(COMPACTPHASE == gcphase) {
1133 gcfilledblocks[cnum] = filledblocks;
1134 gcloads[cnum] = heaptop;
1141 if(gcfindSpareMem_I(&startaddr, &tomove, &dstcore, data4, cnum)) {
1142 // cache the msg first
1143 if(BAMBOO_CHECK_SEND_MODE()) {
1144 cache_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove);
1146 send_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove, true);
1150 gccorestatus[cnum] = 0;
1152 } // if(cnum < NUMCORES4GC)
1155 INLINE void processmsg_gcfinishmapinfo_I() {
1156 int data1 = msgdata[msgdataindex];
1158 // received a map phase finish msg
1159 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1160 // non startup core can not receive this msg
1162 BAMBOO_DEBUGPRINT_REG(data1);
1164 BAMBOO_EXIT(0xe018);
1166 // all cores should do flush
1167 if(data1 < NUMCORES4GC) {
1168 gccorestatus[data1] = 0;
1173 INLINE void processmsg_gcfinishflush_I() {
1174 int data1 = msgdata[msgdataindex];
1176 // received a flush phase finish msg
1177 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1178 // non startup core can not receive this msg
1180 BAMBOO_DEBUGPRINT_REG(data1);
1182 BAMBOO_EXIT(0xe019);
1184 // all cores should do flush
1185 if(data1 < NUMCORESACTIVE) {
1186 gccorestatus[data1] = 0;
1190 INLINE void processmsg_gcmarkconfirm_I() {
1191 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
1192 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
1193 // wrong core to receive such msg
1194 BAMBOO_EXIT(0xe01a);
1196 // send response msg, cahce the msg first
1197 if(BAMBOO_CHECK_SEND_MODE()) {
1198 cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1199 gcbusystatus, gcself_numsendobjs,
1200 gcself_numreceiveobjs);
1202 send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
1203 gcbusystatus, gcself_numsendobjs,
1204 gcself_numreceiveobjs, true);
1209 INLINE void processmsg_gcmarkreport_I() {
1210 int data1 = msgdata[msgdataindex];
1212 int data2 = msgdata[msgdataindex];
1214 int data3 = msgdata[msgdataindex];
1216 int data4 = msgdata[msgdataindex];
1218 // received a marked phase finish confirm response msg
1219 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1220 // wrong core to receive such msg
1222 BAMBOO_DEBUGPRINT_REG(data2);
1224 BAMBOO_EXIT(0xe01b);
1226 int entry_index = 0;
1230 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
1232 // can never reach here
1234 entry_index = gcnumsrobjs_index;
1236 gccorestatus[data1] = data2;
1237 gcnumsendobjs[entry_index][data1] = data3;
1238 gcnumreceiveobjs[entry_index][data1] = data4;
1242 INLINE void processmsg_gcmarkedobj_I() {
1243 int data1 = msgdata[msgdataindex];
1245 // received a markedObj msg
1246 if(((int *)data1)[6] == INIT) {
1247 // this is the first time that this object is discovered,
1248 // set the flag as DISCOVERED
1249 ((int *)data1)[6] = DISCOVERED;
1250 gc_enqueue_I(data1);
1252 // set the remote flag
1253 ((int *)data1)[6] |= REMOTEM;
1254 gcself_numreceiveobjs++;
1255 gcbusystatus = true;
1258 INLINE void processmsg_gcmovestart_I() {
1260 gcdstcore = msgdata[msgdataindex];
1261 MSG_INDEXINC_I(); //msgdata[1];
1262 gcmovestartaddr = msgdata[msgdataindex];
1263 MSG_INDEXINC_I(); //msgdata[2];
1264 gcblock2fill = msgdata[msgdataindex];
1265 MSG_INDEXINC_I(); //msgdata[3];
1268 INLINE void processmsg_gcmaprequest_I() {
1269 void * dstptr = NULL;
1270 int data1 = msgdata[msgdataindex];
1272 int data2 = msgdata[msgdataindex];
1274 #ifdef LOCALHASHTBL_TEST
1275 RuntimeHashget(gcpointertbl, data1, &dstptr);
1277 dstptr = mgchashSearch(gcpointertbl, data1);
1279 if(NULL == dstptr) {
1280 // no such pointer in this core, something is wrong
1282 BAMBOO_DEBUGPRINT_REG(data1);
1283 BAMBOO_DEBUGPRINT_REG(data2);
1285 BAMBOO_EXIT(0xe01c);
1287 // send back the mapping info, cache the msg first
1288 if(BAMBOO_CHECK_SEND_MODE()) {
1289 cache_msg_3(data2, GCMAPINFO, data1, (int)dstptr);
1291 send_msg_3(data2, GCMAPINFO, data1, (int)dstptr, true);
1296 INLINE void processmsg_gcmapinfo_I() {
1297 int data1 = msgdata[msgdataindex];
1299 gcmappedobj = msgdata[msgdataindex]; // [2]
1301 #ifdef LOCALHASHTBL_TEST
1302 RuntimeHashadd_I(gcpointertbl, data1, gcmappedobj);
1304 mgchashInsert_I(gcpointertbl, data1, gcmappedobj);
1306 if(data1 == gcobj2map) {
1311 INLINE void processmsg_gcmaptbl_I() {
1312 int data1 = msgdata[msgdataindex];
1314 int data2 = msgdata[msgdataindex];
1316 gcrpointertbls[data2] = (mgcsharedhashtbl_t *)data1;
1319 INLINE void processmsg_gclobjinfo_I() {
1322 int data1 = msgdata[msgdataindex];
1324 int data2 = msgdata[msgdataindex];
1326 if(BAMBOO_NUM_OF_CORE > NUMCORES4GC - 1) {
1328 BAMBOO_DEBUGPRINT_REG(data2);
1330 BAMBOO_EXIT(0xe01d);
1332 // store the mark result info
1334 gcloads[cnum] = msgdata[msgdataindex];
1335 MSG_INDEXINC_I(); // msgdata[3];
1336 int data4 = msgdata[msgdataindex];
1338 if(gcheaptop < data4) {
1341 // large obj info here
1342 for(int k = 5; k < data1; k+=2) {
1343 int lobj = msgdata[msgdataindex];
1344 MSG_INDEXINC_I(); //msgdata[k++];
1345 int length = msgdata[msgdataindex];
1346 MSG_INDEXINC_I(); //msgdata[k++];
1347 gc_lobjenqueue_I(lobj, length, cnum);
1349 } // for(int k = 5; k < msgdata[1];)
1352 INLINE void processmsg_gclobjmapping_I() {
1353 int data1 = msgdata[msgdataindex];
1355 int data2 = msgdata[msgdataindex];
1357 #ifdef LOCALHASHTBL_TEST
1358 RuntimeHashadd_I(gcpointertbl, data1, data2);
1360 mgchashInsert_I(gcpointertbl, data1, data2);
1362 mgcsharedhashInsert_I(gcsharedptbl, data1, data2);
1366 INLINE void processmsg_gcprofiles_I() {
1367 int data1 = msgdata[msgdataindex];
1369 int data2 = msgdata[msgdataindex];
1371 int data3 = msgdata[msgdataindex];
1373 gc_num_obj += data1;
1374 gc_num_liveobj += data2;
1375 gc_num_forwardobj += data3;
1378 #endif // GC_PROFILE
1380 #ifdef GC_CACHE_ADAPT
1381 INLINE void processmsg_gcstartpref_I() {
1382 gcphase = PREFINISHPHASE;
1385 INLINE void processmsg_gcfinishpref_I() {
1386 int data1 = msgdata[msgdataindex];
1388 // received a flush phase finish msg
1389 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
1390 // non startup core can not receive this msg
1392 BAMBOO_DEBUGPRINT_REG(data1);
1394 BAMBOO_EXIT(0xe01e);
1396 // all cores should do flush
1397 if(data1 < NUMCORESACTIVE) {
1398 gccorestatus[data1] = 0;
1401 #endif // GC_CACHE_ADAPT
1402 #endif // #ifdef MULTICORE_GC
1404 // receive object transferred from other cores
1405 // or the terminate message from other cores
1406 // Should be invoked in critical sections!!
1407 // NOTICE: following format is for threadsimulate version only
1408 // RAW version please see previous description
1409 // format: type + object
1410 // type: -1--stall msg
1412 // return value: 0--received an object
1413 // 1--received nothing
1414 // 2--received a Stall Msg
1415 // 3--received a lock Msg
1416 // RAW version: -1 -- received nothing
1417 // otherwise -- received msg type
1418 int receiveObject(int send_port_pending) {
1420 #ifdef PROFILE_INTERRUPT
1421 if(!interruptInfoOverflow) {
1422 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
1423 interruptInfoArray[interruptInfoIndex] = intInfo;
1424 intInfo->startTime = BAMBOO_GET_EXE_TIME();
1425 intInfo->endTime = -1;
1427 #endif // PROFILE_INTERRUPT
1430 // get the incoming msgs
1431 if(receiveMsg(send_port_pending) == -1) {
1435 // processing received msgs
1437 MSG_REMAINSIZE_I(&size);
1438 if((size == 0) || (checkMsgLength_I(size) == -1)) {
1440 // have new coming msg
1441 if((BAMBOO_MSG_AVAIL() != 0) && !msgdatafull) {
1448 if(msglength <= size) {
1449 // have some whole msg
1451 type = msgdata[msgdataindex]; //[0]
1453 msgdatafull = false;
1457 // receive a object transfer msg
1458 processmsg_transobj_I();
1464 // receive a stall msg
1465 processmsg_transtall_I();
1470 // GC version have no lock msgs
1471 #ifndef MULTICORE_GC
1473 // receive lock request msg, handle it right now
1474 processmsg_lockrequest_I();
1476 } // case LOCKREQUEST
1479 // receive lock grount msg
1480 processmsg_lockgrount_I();
1482 } // case LOCKGROUNT
1485 // receive lock deny msg
1486 processmsg_lockdeny_I();
1491 processmsg_lockrelease_I();
1493 } // case LOCKRELEASE
1494 #endif // #ifndef MULTICORE_GC
1497 case PROFILEOUTPUT: {
1498 // receive an output profile data request msg
1499 processmsg_profileoutput_I();
1501 } // case PROFILEOUTPUT
1503 case PROFILEFINISH: {
1504 // receive a profile output finish msg
1505 processmsg_profilefinish_I();
1507 } // case PROFILEFINISH
1508 #endif // #ifdef PROFILE
1510 // GC version has no lock msgs
1511 #ifndef MULTICORE_GC
1512 case REDIRECTLOCK: {
1513 // receive a redirect lock request msg, handle it right now
1514 processmsg_redirectlock_I();
1516 } // case REDIRECTLOCK
1518 case REDIRECTGROUNT: {
1519 // receive a lock grant msg with redirect info
1520 processmsg_redirectgrount_I();
1522 } // case REDIRECTGROUNT
1524 case REDIRECTDENY: {
1525 // receive a lock deny msg with redirect info
1526 processmsg_redirectdeny_I();
1528 } // case REDIRECTDENY
1530 case REDIRECTRELEASE: {
1531 // receive a lock release msg with redirect info
1532 processmsg_redirectrelease_I();
1534 } // case REDIRECTRELEASE
1535 #endif // #ifndef MULTICORE_GC
1538 case STATUSCONFIRM: {
1539 // receive a status confirm info
1540 processmsg_statusconfirm_I();
1542 } // case STATUSCONFIRM
1544 case STATUSREPORT: {
1545 processmsg_statusreport_I();
1547 } // case STATUSREPORT
1550 // receive a terminate msg
1551 processmsg_terminate_I();
1556 processmsg_memrequest_I();
1558 } // case MEMREQUEST
1561 processmsg_memresponse_I();
1563 } // case MEMRESPONSE
1568 processmsg_gcstartpre_I();
1570 } // case GCSTARTPRE
1573 processmsg_gcstartinit_I();
1575 } // case GCSTARTINIT
1578 // receive a start GC msg
1579 processmsg_gcstart_I();
1583 case GCSTARTCOMPACT: {
1584 // a compact phase start msg
1585 processmsg_gcstartcompact_I();
1587 } // case GCSTARTCOMPACT
1589 case GCSTARTMAPINFO: {
1590 // received a flush phase start msg
1591 processmsg_gcstartmapinfo_I();
1593 } // case GCSTARTFLUSH
1595 case GCSTARTFLUSH: {
1596 // received a flush phase start msg
1597 processmsg_gcstartflush_I();
1599 } // case GCSTARTFLUSH
1602 processmsg_gcfinishpre_I();
1604 } // case GCFINISHPRE
1606 case GCFINISHINIT: {
1607 processmsg_gcfinishinit_I();
1609 } // case GCFINISHINIT
1611 case GCFINISHMARK: {
1612 processmsg_gcfinishmark_I();
1614 } // case GCFINISHMARK
1616 case GCFINISHCOMPACT: {
1617 // received a compact phase finish msg
1618 processmsg_gcfinishcompact_I();
1620 } // case GCFINISHCOMPACT
1622 case GCFINISHMAPINFO: {
1623 processmsg_gcfinishmapinfo_I();
1625 } // case GCFINISHMAPINFO
1627 case GCFINISHFLUSH: {
1628 processmsg_gcfinishflush_I();
1630 } // case GCFINISHFLUSH
1633 // received a GC finish msg
1634 gcphase = FINISHPHASE;
1638 case GCMARKCONFIRM: {
1639 // received a marked phase finish confirm request msg
1640 // all cores should do mark
1641 processmsg_gcmarkconfirm_I();
1643 } // case GCMARKCONFIRM
1645 case GCMARKREPORT: {
1646 processmsg_gcmarkreport_I();
1648 } // case GCMARKREPORT
1651 processmsg_gcmarkedobj_I();
1653 } // case GCMARKEDOBJ
1656 // received a start moving objs msg
1657 processmsg_gcmovestart_I();
1659 } // case GCMOVESTART
1661 case GCMAPREQUEST: {
1662 // received a mapping info request msg
1663 processmsg_gcmaprequest_I();
1665 } // case GCMAPREQUEST
1668 // received a mapping info response msg
1669 processmsg_gcmapinfo_I();
1674 // received a mapping tbl response msg
1675 processmsg_gcmaptbl_I();
1679 case GCLOBJREQUEST: {
1680 // received a large objs info request msg
1681 transferMarkResults_I();
1683 } // case GCLOBJREQUEST
1686 // received a large objs info response msg
1687 processmsg_gclobjinfo_I();
1689 } // case GCLOBJINFO
1691 case GCLOBJMAPPING: {
1692 // received a large obj mapping info msg
1693 processmsg_gclobjmapping_I();
1695 } // case GCLOBJMAPPING
1699 // received a gcprofiles msg
1700 processmsg_gcprofiles_I();
1703 #endif // GC_PROFILE
1705 #ifdef GC_CACHE_ADAPT
1707 // received a gcstartpref msg
1708 processmsg_gcstartpref_I();
1712 case GCFINISHPREF: {
1713 // received a gcfinishpref msg
1714 processmsg_gcfinishpref_I();
1717 #endif // GC_CACHE_ADAPT
1718 #endif // #ifdef MULTICORE_GC
1723 msglength = BAMBOO_MSG_BUF_LENGTH;
1725 if((msgdataindex != msgdatalast) || (msgdatafull)) {
1726 // still have available msg
1730 BAMBOO_DEBUGPRINT(0xe88d);
1733 // have new coming msg
1734 if(BAMBOO_MSG_AVAIL() != 0) {
1739 #ifdef PROFILE_INTERRUPT
1740 if(!interruptInfoOverflow) {
1741 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
1742 interruptInfoIndex++;
1743 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
1744 interruptInfoOverflow = true;
1753 BAMBOO_DEBUGPRINT(0xe88e);