X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b8d73e39d7ad879522cdb542e4ed69e2077a6f9e..3b83099adfbb07a89843ad15c9c1b8f8a62c4893:/src/xbt/mmalloc/mm_diff.c?ds=sidebyside diff --git a/src/xbt/mmalloc/mm_diff.c b/src/xbt/mmalloc/mm_diff.c index 7258e6f1b3..a079804c63 100644 --- a/src/xbt/mmalloc/mm_diff.c +++ b/src/xbt/mmalloc/mm_diff.c @@ -134,16 +134,27 @@ static int compare_backtrace(int b1, int f1, int b2, int f2){ typedef char* type_name; struct s_mm_diff { - void *s_heap, *heapbase1, *heapbase2; + /** \brief Base address of the real heap */ + void *s_heap; + /** \brief Base address of the first heap snapshot */ + void *heapbase1; + /** \brief Base address of the second heap snapshot */ + void *heapbase2; malloc_info *heapinfo1, *heapinfo2; size_t heaplimit; // Number of blocks in the heaps: size_t heapsize1, heapsize2; xbt_dynar_t to_ignore1, to_ignore2; - heap_area_t **equals_to1, **equals_to2; - dw_type_t **types1, **types2; + s_heap_area_t *equals_to1, *equals_to2; + dw_type_t *types1, *types2; + size_t available; }; +#define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)] +#define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)] +#define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)] +#define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)] + __thread struct s_mm_diff* mm_diff_info = NULL; /*********************************** Free functions ************************************/ @@ -164,11 +175,11 @@ static void heap_area_free(heap_area_t area){ /************************************************************************************/ -static heap_area_t new_heap_area(int block, int fragment){ - heap_area_t area = NULL; - area = xbt_new0(s_heap_area_t, 1); - area->block = block; - area->fragment = fragment; +static s_heap_area_t make_heap_area(int block, int fragment){ + s_heap_area_t area; + area.valid = 1; + area.block = block; + area.fragment = fragment; return area; } @@ -253,45 +264,18 @@ static void match_equals(struct s_mm_diff *state, xbt_dynar_t list){ unsigned int cursor = 0; heap_area_pair_t current_pair; - heap_area_t previous_area; xbt_dynar_foreach(list, cursor, current_pair){ if(current_pair->fragment1 != -1){ - if(state->equals_to1[current_pair->block1][current_pair->fragment1] != NULL){ - previous_area = state->equals_to1[current_pair->block1][current_pair->fragment1]; - heap_area_free(state->equals_to2[previous_area->block][previous_area->fragment]); - state->equals_to2[previous_area->block][previous_area->fragment] = NULL; - heap_area_free(previous_area); - } - if(state->equals_to2[current_pair->block2][current_pair->fragment2] != NULL){ - previous_area = state->equals_to2[current_pair->block2][current_pair->fragment2]; - heap_area_free(state->equals_to1[previous_area->block][previous_area->fragment]); - state->equals_to1[previous_area->block][previous_area->fragment] = NULL; - heap_area_free(previous_area); - } - - state->equals_to1[current_pair->block1][current_pair->fragment1] = new_heap_area(current_pair->block2, current_pair->fragment2); - state->equals_to2[current_pair->block2][current_pair->fragment2] = new_heap_area(current_pair->block1, current_pair->fragment1); + state->equals_to1_(current_pair->block1,current_pair->fragment1) = make_heap_area(current_pair->block2, current_pair->fragment2); + state->equals_to2_(current_pair->block2,current_pair->fragment2) = make_heap_area(current_pair->block1, current_pair->fragment1); }else{ - if(state->equals_to1[current_pair->block1][0] != NULL){ - previous_area = state->equals_to1[current_pair->block1][0]; - heap_area_free(state->equals_to2[previous_area->block][0]); - state->equals_to2[previous_area->block][0] = NULL; - heap_area_free(previous_area); - } - if(state->equals_to2[current_pair->block2][0] != NULL){ - previous_area = state->equals_to2[current_pair->block2][0]; - heap_area_free(state->equals_to1[previous_area->block][0]); - state->equals_to1[previous_area->block][0] = NULL; - heap_area_free(previous_area); - } - - state->equals_to1[current_pair->block1][0] = new_heap_area(current_pair->block2, current_pair->fragment2); - state->equals_to2[current_pair->block2][0] = new_heap_area(current_pair->block1, current_pair->fragment1); + state->equals_to1_(current_pair->block1,0) = make_heap_area(current_pair->block2, current_pair->fragment2); + state->equals_to2_(current_pair->block2,0) = make_heap_area(current_pair->block1, current_pair->fragment1); } @@ -307,7 +291,7 @@ static void match_equals(struct s_mm_diff *state, xbt_dynar_t list){ */ static int equal_blocks(struct s_mm_diff *state, int b1, int b2){ - if(state->equals_to1[b1][0]->block == b2 && state->equals_to2[b2][0]->block == b1) + if(state->equals_to1_(b1,0).block == b2 && state->equals_to2_(b2,0).block == b1) return 1; return 0; @@ -324,10 +308,10 @@ static int equal_blocks(struct s_mm_diff *state, int b1, int b2){ */ static int equal_fragments(struct s_mm_diff *state, int b1, int f1, int b2, int f2){ - if(state->equals_to1[b1][f1]->block == b2 - && state->equals_to1[b1][f1]->fragment == f2 - && state->equals_to2[b2][f2]->block == b1 - && state->equals_to2[b2][f2]->fragment == f1) + if(state->equals_to1_(b1,f1).block == b2 + && state->equals_to1_(b1,f1).fragment == f2 + && state->equals_to2_(b2,f2).block == b1 + && state->equals_to2_(b2,f2).fragment == f1) return 1; return 0; @@ -336,6 +320,10 @@ static int equal_fragments(struct s_mm_diff *state, int b1, int f1, int b2, int int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, xbt_dynar_t i2){ if(mm_diff_info==NULL) { mm_diff_info = xbt_new0(struct s_mm_diff, 1); + mm_diff_info->equals_to1 = NULL; + mm_diff_info->equals_to2 = NULL; + mm_diff_info->types1 = NULL; + mm_diff_info->types2 = NULL; } struct s_mm_diff *state = mm_diff_info; @@ -343,10 +331,11 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, || ((((struct mdesc *)heap1)->heapsize != ((struct mdesc *)heap2)->heapsize) )) return -1; - int i, j; - state->heaplimit = ((struct mdesc *)heap1)->heaplimit; + // Mamailloute in order to find the base address of the main heap: + // This heavily depends on the structure of MC: we need to move this code into MC. + // (STD_HEAP_SIZE comes from mc.h anyway) state->s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize; state->heapbase1 = (char *)heap1 + BLOCKSIZE; @@ -361,27 +350,18 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, state->to_ignore1 = i1; state-> to_ignore2 = i2; - state->equals_to1 = malloc(state->heaplimit * sizeof(heap_area_t *)); - state->types1 = malloc(state->heaplimit * sizeof(type_name *)); - for(i=0; i<=state->heaplimit; i++){ - state->equals_to1[i] = malloc(MAX_FRAGMENT_PER_BLOCK * sizeof(heap_area_t)); - state->types1[i] = malloc(MAX_FRAGMENT_PER_BLOCK * sizeof(type_name)); - for(j=0; jequals_to1[i][j] = NULL; - state->types1[i][j] = NULL; - } + if(state->heaplimit > state->available) { + state->equals_to1 = realloc(state->equals_to1, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); + state->types1 = realloc(state->types1, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); + state->equals_to2 = realloc(state->equals_to2, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); + state->types2 = realloc(state->types2, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); + state->available = state->heaplimit; } - state->equals_to2 = malloc(state->heaplimit * sizeof(heap_area_t *)); - state->types2 = malloc(state->heaplimit * sizeof(type_name *)); - for(i=0; i<=state->heaplimit; i++){ - state->equals_to2[i] = malloc(MAX_FRAGMENT_PER_BLOCK * sizeof(heap_area_t)); - state->types2[i] = malloc(MAX_FRAGMENT_PER_BLOCK * sizeof(type_name)); - for(j=0; jequals_to2[i][j] = NULL; - state->types2[i][j] = NULL; - } - } + memset(state->equals_to1, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); + memset(state->equals_to2, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); + memset(state->types1, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); + memset(state->types2, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); if(MC_is_active()){ MC_ignore_global_variable("mm_diff_info"); @@ -393,37 +373,6 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, void reset_heap_information(){ - struct s_mm_diff *state = mm_diff_info; - - size_t i = 0, j; - - for(i=0; i<=state->heaplimit; i++){ - for(j=0; jequals_to1[i][j]); - state->equals_to1[i][j] = NULL; - heap_area_free(state->equals_to2[i][j]); - state-> equals_to2[i][j] = NULL; - state->types1[i][j] = NULL; - state->types2[i][j] = NULL; - } - free(state->equals_to1[i]); - free(state->equals_to2[i]); - free(state->types1[i]); - free(state->types2[i]); - } - - free(state->equals_to1); - free(state->equals_to2); - free(state->types1); - free(state->types2); - - state->s_heap = NULL, state->heapbase1 = NULL, state->heapbase2 = NULL; - state->heapinfo1 = NULL, state->heapinfo2 = NULL; - state->heaplimit = 0, state->heapsize1 = 0, state->heapsize2 = 0; - state->to_ignore1 = NULL, state->to_ignore2 = NULL; - state->equals_to1 = NULL, state->equals_to2 = NULL; - state->types1 = NULL, state->types2 = NULL; - } int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_mheap_t heap1, xbt_mheap_t heap2){ @@ -461,14 +410,14 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m if(is_stack(addr_block1)){ for(k=0; k < state->heapinfo1[i1].busy_block.size; k++) - state->equals_to1[i1+k][0] = new_heap_area(i1, -1); + state->equals_to1_(i1+k,0) = make_heap_area(i1, -1); for(k=0; k < state->heapinfo2[i1].busy_block.size; k++) - state->equals_to2[i1+k][0] = new_heap_area(i1, -1); + state->equals_to2_(i1+k,0) = make_heap_area(i1, -1); i1 += state->heapinfo1[i1].busy_block.size; continue; } - if(state->equals_to1[i1][0] != NULL){ + if(state->equals_to1_(i1,0).valid){ i1++; continue; } @@ -480,7 +429,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m /* Try first to associate to same block in the other heap */ if(state->heapinfo2[i1].type == state->heapinfo1[i1].type){ - if(state->equals_to2[i1][0] == NULL){ + if(state->equals_to2_(i1,0).valid == 0){ addr_block2 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase)); @@ -488,9 +437,9 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m if(res_compare != 1){ for(k=1; k < state->heapinfo2[i1].busy_block.size; k++) - state->equals_to2[i1+k][0] = new_heap_area(i1, -1); + state->equals_to2_(i1+k,0) = make_heap_area(i1, -1); for(k=1; k < state->heapinfo1[i1].busy_block.size; k++) - state->equals_to1[i1+k][0] = new_heap_area(i1, -1); + state->equals_to1_(i1+k,0) = make_heap_area(i1, -1); equal = 1; i1 += state->heapinfo1[i1].busy_block.size; } @@ -515,7 +464,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m continue; } - if(state->equals_to2[i2][0] != NULL){ + if(state->equals_to2_(i2,0).valid){ i2++; continue; } @@ -524,9 +473,9 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m if(res_compare != 1 ){ for(k=1; k < state->heapinfo2[i2].busy_block.size; k++) - state->equals_to2[i2+k][0] = new_heap_area(i1, -1); + state->equals_to2_(i2+k,0) = make_heap_area(i1, -1); for(k=1; k < state->heapinfo1[i1].busy_block.size; k++) - state->equals_to1[i1+k][0] = new_heap_area(i2, -1); + state->equals_to1_(i1+k,0) = make_heap_area(i2, -1); equal = 1; i1 += state->heapinfo1[i1].busy_block.size; } @@ -551,7 +500,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m if(state->heapinfo1[i1].busy_frag.frag_size[j1] == -1) /* Free fragment */ continue; - if(state->equals_to1[i1][j1] != NULL) + if(state->equals_to1_(i1,j1).valid) continue; addr_frag1 = (void*) ((char *)addr_block1 + (j1 << state->heapinfo1[i1].type)); @@ -562,7 +511,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m /* Try first to associate to same fragment in the other heap */ if(state->heapinfo2[i1].type == state->heapinfo1[i1].type){ - if(state->equals_to2[i1][j1] == NULL){ + if(state->equals_to2_(i1,j1).valid == 0){ addr_block2 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase)); addr_frag2 = (void*) ((char *)addr_block2 + (j1 << ((xbt_mheap_t)state->s_heap)->heapinfo[i1].type)); @@ -590,7 +539,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m if(i2 == i1 && j2 == j1) continue; - if(state->equals_to2[i2][j2] != NULL) + if(state->equals_to2_(i2,j2).valid) continue; addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)state->s_heap)->heapbase)); @@ -636,7 +585,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m if(state->heapinfo1[i].type == 0){ if(i1 == state->heaplimit){ if(state->heapinfo1[i].busy_block.busy_size > 0){ - if(state->equals_to1[i][0] == NULL){ + if(state->equals_to1_(i,0).valid == 0){ if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){ addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)state->heapbase1)); XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block1, state->heapinfo1[i].busy_block.busy_size); @@ -653,7 +602,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m for(j=0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++){ if(i1== state->heaplimit){ if(state->heapinfo1[i].busy_frag.frag_size[j] > 0){ - if(state->equals_to1[i][j] == NULL){ + if(state->equals_to1_(i,j).valid == 0){ if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){ addr_frag1 = (void*) ((char *)addr_block1 + (j << state->heapinfo1[i].type)); real_addr_frag1 = (void*) ((char *)real_addr_block1 + (j << ((struct mdesc *)state->s_heap)->heapinfo[i].type)); @@ -678,7 +627,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m if(state->heapinfo2[i].type == 0){ if(i1 == state->heaplimit){ if(state->heapinfo2[i].busy_block.busy_size > 0){ - if(state->equals_to2[i][0] == NULL){ + if(state->equals_to2_(i,0).valid == 0){ if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){ addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)state->heapbase2)); XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block2, state->heapinfo2[i].busy_block.busy_size); @@ -695,7 +644,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2, xbt_m for(j=0; j < (size_t) (BLOCKSIZE >> state->heapinfo2[i].type); j++){ if(i1 == state->heaplimit){ if(state->heapinfo2[i].busy_frag.frag_size[j] > 0){ - if(state->equals_to2[i][j] == NULL){ + if(state->equals_to2_(i,j).valid == 0){ if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){ addr_frag2 = (void*) ((char *)addr_block2 + (j << state->heapinfo2[i].type)); real_addr_frag2 = (void*) ((char *)real_addr_block2 + (j << ((struct mdesc *)state->s_heap)->heapinfo[i].type)); @@ -1108,7 +1057,7 @@ int compare_heap_area(void *area1, void* area2, mc_snapshot_t snapshot1, mc_snap // TODO, lookup variable type from block type as done for fragmented blocks - if(state->equals_to1[block1][0] != NULL && state->equals_to2[block2][0] != NULL){ + if(state->equals_to1_(block1,0).valid && state->equals_to2_(block2,0).valid){ if(equal_blocks(state, block1, block2)){ if(match_pairs){ match_equals(state, previous); @@ -1157,12 +1106,10 @@ int compare_heap_area(void *area1, void* area2, mc_snapshot_t snapshot1, mc_snap // Remember (basic) type inference. // The current data structure only allows us to do this for the whole block. if (type != NULL && area1==real_addr_block1) { - xbt_free(state->types1[block1][0]); - state->types1[block1][0] = type; + state->types1_(block1,0) = type; } if (type != NULL && area2==real_addr_block2) { - xbt_free(state->types2[block2][0]); - state->types2[block2][0] = type; + state->types2_(block2,0) = type; } if(size <= 0){ @@ -1215,7 +1162,7 @@ int compare_heap_area(void *area1, void* area2, mc_snapshot_t snapshot1, mc_snap } // Check if the blocks are already matched together: - if(state->equals_to1[block1][frag1] != NULL && state->equals_to2[block2][frag2] != NULL){ + if(state->equals_to1_(block1,frag1).valid && state->equals_to2_(block2,frag2).valid){ if(equal_fragments(state, block1, frag1, block2, frag2)){ if(match_pairs){ match_equals(state, previous); @@ -1247,10 +1194,10 @@ int compare_heap_area(void *area1, void* area2, mc_snapshot_t snapshot1, mc_snap // Remember (basic) type inference. // The current data structure only allows us to do this for the whole block. if(type != NULL && area1==real_addr_frag1){ - state->types1[block1][frag1] = type; + state->types1_(block1,frag1) = type; } if(type != NULL && area2==real_addr_frag2) { - state->types2[block2][frag2] = type; + state->types2_(block2,frag2) = type; } // The type of the variable is already known: @@ -1260,20 +1207,20 @@ int compare_heap_area(void *area1, void* area2, mc_snapshot_t snapshot1, mc_snap } // Type inference from the block type. - else if(state->types1[block1][frag1] != NULL || state->types2[block2][frag2] != NULL) { + else if(state->types1_(block1,frag1) != NULL || state->types2_(block2,frag2) != NULL) { offset1 = (char *)area1 - (char *)real_addr_frag1; offset2 = (char *)area2 - (char *)real_addr_frag2; - if(state->types1[block1][frag1] != NULL && state->types2[block2][frag2] != NULL){ - new_type1 = get_offset_type(real_addr_frag1, state->types1[block1][frag1], offset1, size, snapshot1); - new_type2 = get_offset_type(real_addr_frag2, state->types2[block2][frag2], offset1, size, snapshot2); - }else if(state->types1[block1][frag1] != NULL){ - new_type1 = get_offset_type(real_addr_frag1, state->types1[block1][frag1], offset1, size, snapshot1); - new_type2 = get_offset_type(real_addr_frag2, state->types1[block1][frag1], offset2, size, snapshot2); - }else if(state->types2[block2][frag2] != NULL){ - new_type1 = get_offset_type(real_addr_frag1, state->types2[block2][frag2], offset1, size, snapshot1); - new_type2 = get_offset_type(real_addr_frag2, state->types2[block2][frag2], offset2, size, snapshot2); + if(state->types1_(block1,frag1) != NULL && state->types2_(block2,frag2) != NULL){ + new_type1 = get_offset_type(real_addr_frag1, state->types1_(block1,frag1), offset1, size, snapshot1); + new_type2 = get_offset_type(real_addr_frag2, state->types2_(block2,frag2), offset1, size, snapshot2); + }else if(state->types1_(block1,frag1) != NULL){ + new_type1 = get_offset_type(real_addr_frag1, state->types1_(block1,frag1), offset1, size, snapshot1); + new_type2 = get_offset_type(real_addr_frag2, state->types1_(block1,frag1), offset2, size, snapshot2); + }else if(state->types2_(block2,frag2) != NULL){ + new_type1 = get_offset_type(real_addr_frag1, state->types2_(block2,frag2), offset1, size, snapshot1); + new_type2 = get_offset_type(real_addr_frag2, state->types2_(block2,frag2), offset2, size, snapshot2); }else{ if(match_pairs){ match_equals(state, previous);