1 #ifndef BAMBOO_MULTICORE_GC_PROFILE_H
2 #define BAMBOO_MULTICORE_GC_PROFILE_H
3 #if defined(MULTICORE_GC)||defined(PMC_GC)
5 #include "runtime_arch.h"
6 #include "structdefs.h"
9 #define GCINFOLENGTH 100
12 #define GC_PROFILE_NUM_FIELD 15
14 #define GC_PROFILE_NUM_FIELD 15
16 #define GC_PROFILE_NUM_FIELD 14
17 #endif // GC_CACHE_ADAPT
19 typedef struct gc_info {
20 unsigned long long time[GC_PROFILE_NUM_FIELD];
24 // the following data are supposed to be only valid on the master core
25 // the other cores should not maintain them
26 GCInfo * gc_infoArray[GCINFOLENGTH];
27 unsigned int gc_infoIndex;
29 unsigned int gc_num_profiles;
30 unsigned int gc_size_allocatedobj;
31 unsigned long long gc_num_livespace;
32 unsigned long long gc_num_freespace;
33 unsigned long long gc_num_lobjspace;
34 unsigned int gc_num_lobj;
36 // these data should be maintained by all gc cores
37 unsigned int gc_num_liveobj;
38 unsigned int gc_num_forwardobj;
42 volatile bool gc_profile_flag;
45 void initmulticoregcprofiledata(void);
46 void gc_outputProfileData();
47 void gc_outputProfileDataReadable();
49 INLINE static void gc_profileInit() {
55 gc_num_forwardobj = 0;
56 gc_num_profiles = NUMCORESACTIVE - 1;
59 // these *_master function can only be invoked by the master core
60 INLINE static void gc_profileStart_master(void) {
61 if(!gc_infoOverflow) {
62 GCInfo* gcInfo = RUNMALLOC(sizeof(struct gc_info));
63 gc_infoArray[gc_infoIndex] = gcInfo;
65 gcInfo->time[0] = BAMBOO_GET_EXE_TIME();
69 INLINE static void gc_profileItem_master(void) {
70 if(!gc_infoOverflow) {
71 GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
72 gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
76 INLINE static void gc_profileEnd_master(void) {
77 if(!gc_infoOverflow) {
78 GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
79 gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
80 gcInfo->time[gcInfo->index++] = gc_num_livespace;
81 gcInfo->time[gcInfo->index++] = gc_num_freespace;
82 gcInfo->time[gcInfo->index++] = gc_num_lobj;
83 gcInfo->time[gcInfo->index++] = gc_num_lobjspace;
84 gcInfo->time[gcInfo->index++] = gc_size_allocatedobj;
85 gcInfo->time[gcInfo->index++] = gc_num_liveobj;
86 gcInfo->time[gcInfo->index++] = gc_num_forwardobj;
88 gc_size_allocatedobj = 0; // reset the counter of allocated obj
89 if(gc_infoIndex == GCINFOLENGTH) {
90 gc_infoOverflow = true;
95 #define INIT_MULTICORE_GCPROFILE_DATA() initmulticoregcprofiledata()
96 #define GC_OUTPUT_PROFILE_DATA() gc_outputProfileData()
97 // send the num of obj/liveobj/forwardobj to the startupcore
98 #define GCPROFILE_INFO_2_MASTER() \
100 if(STARTUPCORE != BAMBOO_NUM_OF_CORE) { \
101 send_msg_3(STARTUPCORE,GCPROFILES,gc_num_liveobj,gc_num_forwardobj); \
106 // record allocated obj info
107 #define GCPROFILE_RECORD_ALLOCATED_OBJ(size) \
109 if(gc_profile_flag) {\
110 gc_size_allocatedobj += size; \
114 #define GCPROFILE_RECORD_LOBJ() \
118 // record lobj space info
119 #define GCPROFILE_RECORD_LOBJSPACE() \
121 if(gc_profile_flag) { \
122 gc_num_lobjspace = sumsize; \
126 // check the live/free space info
127 #define GCPROFILE_RECORD_SPACE_MASTER() \
129 if(gc_profile_flag) { \
130 gc_num_freespace = 0; \
131 for(int i=0;i<NUMCORES4GC;i+=2) { \
132 void *startptr=pmc_heapptr->regions[i].lastptr; \
133 void *finishptr=(i+1)<NUMCORES4GC?pmc_heapptr->regions[i+1].lastptr:pmc_heapptr->regions[i].endptr; \
134 gc_num_freespace += finishptr-startptr; \
136 gc_num_livespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_freespace; \
140 // check the live/free space info
141 #define GCPROFILE_RECORD_SPACE_MASTER() \
143 if(gc_profile_flag) { \
144 gc_num_freespace = 0; \
145 block_t lowestblock=allocationinfo.lowestfreeblock; \
146 for(block_t searchblock=lowestblock;searchblock<GCNUMBLOCK;searchblock++) { \
147 struct blockrecord * block=&allocationinfo.blocktable[searchblock]; \
148 if (block->status==BS_FREE) { \
149 gc_num_freespace+=block->freespace&~BAMBOO_CACHE_LINE_MASK; \
152 gc_num_livespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_freespace; \
156 // record forward obj info
157 #define GCPROFILE_RECORD_FORWARD_OBJ() \
159 gc_num_forwardobj++; \
161 // record live obj info
162 #define GCPROFILE_RECORD_LIVE_OBJ() \
166 #define GCPROFILE_START_MASTER() \
168 if(gc_profile_flag) { \
169 gc_profileStart_master(); \
172 #define GCPROFILE_ITEM_MASTER() \
174 if(gc_profile_flag) { \
175 gc_profileItem_master(); \
178 #define GCPROFILE_END_MASTER() \
180 if(gc_profile_flag) { \
181 gc_profileEnd_master(); \
185 // record allocated obj info
186 #define GCPROFILE_RECORD_ALLOCATED_OBJ(size) \
188 gc_size_allocatedobj += size; \
190 #define GCPROFILE_RECORD_LOBJ() (gc_num_lobj++)
191 #define GCPROFILE_RECORD_LOBJSPACE() (gc_num_lobjspace = sumsize)
193 // check the live/free space info
194 #define GCPROFILE_RECORD_SPACE_MASTER() \
196 gc_num_freespace = 0; \
197 for(int i=0;i<NUMCORES4GC;i+=2) { \
198 void *startptr=pmc_heapptr->regions[i].lastptr; \
199 void *finishptr=(i+1)<NUMCORES4GC?pmc_heapptr->regions[i+1].lastptr:pmc_heapptr->regions[i].endptr; \
200 gc_num_freespace += finishptr-startptr; \
202 gc_num_livespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_freespace; \
205 #define GCPROFILE_RECORD_SPACE_MASTER() \
207 gc_num_freespace = 0; \
208 block_t lowestblock=allocationinfo.lowestfreeblock; \
209 for(block_t searchblock=lowestblock;searchblock<GCNUMBLOCK;searchblock++) { \
210 struct blockrecord * block=&allocationinfo.blocktable[searchblock]; \
211 if (block->status==BS_FREE) { \
212 gc_num_freespace+=block->freespace&~BAMBOO_CACHE_LINE_MASK; \
215 gc_num_livespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_freespace; \
218 #define GCPROFILE_RECORD_FORWARD_OBJ() (gc_num_forwardobj++)
219 #define GCPROFILE_RECORD_LIVE_OBJ() (gc_num_liveobj++)
220 #define GCPROFILE_START_MASTER() gc_profileStart_master()
221 #define GCPROFILE_ITEM_MASTER() gc_profileItem_master()
222 #define GCPROFILE_END_MASTER() gc_profileEnd_master()
225 #define GCPROFILE_INIT() gc_profileInit()
228 #define GCPROFILE_RECORD_ALLOCATED_OBJ(size)
229 #define INIT_MULTICORE_GCPROFILE_DATA()
230 #define GC_OUTPUT_PROFILE_DATA()
231 #define GCPROFILE_INFO_2_MASTER()
232 #define GCPROFILE_RECORD_LOBJ()
233 #define GCPROFILE_RECORD_LOBJSPACE()
234 #define GCPROFILE_RECORD_SPACE()
235 #define GCPROFILE_RECORD_FORWARD_OBJ()
236 #define GCPROFILE_RECORD_LIVE_OBJ()
237 #define GCPROFILE_START_MASTER()
238 #define GCPROFILE_ITEM_MASTER()
239 #define GCPROFILE_END_MASTER()
240 #define GCPROFILE_INIT()
243 #endif // MULTICORE_GC
244 #endif // BAMBOO_MULTICORE_GC_PROFILE_H