1 /* mm_diff - Memory snapshooting and comparison */
3 /* Copyright (c) 2008-2013. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/ex_interface.h" /* internals of backtrace setup */
12 #include "xbt/mmalloc.h"
13 #include "mc/datatypes.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mm_diff, xbt,
16 "Logging specific to mm_diff in mmalloc");
18 xbt_dynar_t mc_heap_comparison_ignore;
19 xbt_dynar_t stacks_areas;
20 void *maestro_stack_start, *maestro_stack_end;
23 /********************************* Backtrace ***********************************/
24 /******************************************************************************/
26 static void mmalloc_backtrace_block_display(void* heapinfo, int block){
30 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
31 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
35 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
36 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
38 /* xbt_ex_setup_backtrace(&e); */
39 /* if (e.used == 0) { */
40 /* fprintf(stderr, "(backtrace not set)\n"); */
41 /* } else if (e.bt_strings == NULL) { */
42 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
46 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
47 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
48 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
53 static void mmalloc_backtrace_fragment_display(void* heapinfo, int block, int frag){
57 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
58 /* e.used = XBT_BACKTRACE_SIZE; */
60 /* xbt_ex_setup_backtrace(&e); */
61 /* if (e.used == 0) { */
62 /* fprintf(stderr, "(backtrace not set)\n"); */
63 /* } else if (e.bt_strings == NULL) { */
64 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
68 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
69 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
70 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
76 static void mmalloc_backtrace_display(void *addr){
78 /* size_t block, frag_nb; */
81 /* xbt_mheap_t heap = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); */
83 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
85 /* type = heap->heapinfo[block].type; */
88 /* case -1 : /\* Free block *\/ */
89 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
92 /* case 0: /\* Large block *\/ */
93 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
95 /* default: /\* Fragmented block *\/ */
96 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
97 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
98 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
101 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
107 static int compare_backtrace(int b1, int f1, int b2, int f2){
110 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
111 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
112 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
113 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
118 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
119 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
120 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
121 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
130 /*********************************** Heap comparison ***********************************/
131 /***************************************************************************************/
133 typedef char* type_name;
135 __thread void *s_heap = NULL, *heapbase1 = NULL, *heapbase2 = NULL;
136 __thread malloc_info *heapinfo1 = NULL, *heapinfo2 = NULL;
137 __thread size_t heaplimit = 0, heapsize1 = 0, heapsize2 = 0;
138 __thread xbt_dynar_t to_ignore1 = NULL, to_ignore2 = NULL;
139 __thread heap_area_t **equals_to1, **equals_to2;
140 __thread type_name **types1, **types2;
142 /*********************************** Free functions ************************************/
144 static void heap_area_pair_free(heap_area_pair_t pair){
149 static void heap_area_pair_free_voidp(void *d){
150 heap_area_pair_free((heap_area_pair_t) * (void **) d);
153 static void heap_area_free(heap_area_t area){
158 /************************************************************************************/
160 static heap_area_t new_heap_area(int block, int fragment){
161 heap_area_t area = NULL;
162 area = xbt_new0(s_heap_area_t, 1);
164 area->fragment = fragment;
169 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
171 unsigned int cursor = 0;
172 heap_area_pair_t current_pair;
174 xbt_dynar_foreach(list, cursor, current_pair){
175 if(current_pair->block1 == block1 && current_pair->block2 == block2 && current_pair->fragment1 == fragment1 && current_pair->fragment2 == fragment2)
182 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
184 if(is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)){
185 heap_area_pair_t pair = NULL;
186 pair = xbt_new0(s_heap_area_pair_t, 1);
187 pair->block1 = block1;
188 pair->fragment1 = fragment1;
189 pair->block2 = block2;
190 pair->fragment2 = fragment2;
192 xbt_dynar_push(list, &pair);
200 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list, void *address){
202 unsigned int cursor = 0;
204 int end = xbt_dynar_length(ignore_list) - 1;
205 mc_heap_ignore_region_t region;
208 cursor = (start + end) / 2;
209 region = (mc_heap_ignore_region_t)xbt_dynar_get_as(ignore_list, cursor, mc_heap_ignore_region_t);
210 if(region->address == address)
212 if(region->address < address)
214 if(region->address > address)
221 static int is_stack(void *address){
222 unsigned int cursor = 0;
223 stack_region_t stack;
225 xbt_dynar_foreach(stacks_areas, cursor, stack){
226 if(address == stack->address)
233 static int is_block_stack(int block){
234 unsigned int cursor = 0;
235 stack_region_t stack;
237 xbt_dynar_foreach(stacks_areas, cursor, stack){
238 if(block == stack->block)
245 static void match_equals(xbt_dynar_t list){
247 unsigned int cursor = 0;
248 heap_area_pair_t current_pair;
249 heap_area_t previous_area;
251 xbt_dynar_foreach(list, cursor, current_pair){
253 if(current_pair->fragment1 != -1){
255 if(equals_to1[current_pair->block1][current_pair->fragment1] != NULL){
256 previous_area = equals_to1[current_pair->block1][current_pair->fragment1];
257 heap_area_free(equals_to2[previous_area->block][previous_area->fragment]);
258 equals_to2[previous_area->block][previous_area->fragment] = NULL;
259 heap_area_free(previous_area);
261 if(equals_to2[current_pair->block2][current_pair->fragment2] != NULL){
262 previous_area = equals_to2[current_pair->block2][current_pair->fragment2];
263 heap_area_free(equals_to1[previous_area->block][previous_area->fragment]);
264 equals_to1[previous_area->block][previous_area->fragment] = NULL;
265 heap_area_free(previous_area);
268 equals_to1[current_pair->block1][current_pair->fragment1] = new_heap_area(current_pair->block2, current_pair->fragment2);
269 equals_to2[current_pair->block2][current_pair->fragment2] = new_heap_area(current_pair->block1, current_pair->fragment1);
273 if(equals_to1[current_pair->block1][0] != NULL){
274 previous_area = equals_to1[current_pair->block1][0];
275 heap_area_free(equals_to2[previous_area->block][0]);
276 equals_to2[previous_area->block][0] = NULL;
277 heap_area_free(previous_area);
279 if(equals_to2[current_pair->block2][0] != NULL){
280 previous_area = equals_to2[current_pair->block2][0];
281 heap_area_free(equals_to1[previous_area->block][0]);
282 equals_to1[previous_area->block][0] = NULL;
283 heap_area_free(previous_area);
286 equals_to1[current_pair->block1][0] = new_heap_area(current_pair->block2, current_pair->fragment2);
287 equals_to2[current_pair->block2][0] = new_heap_area(current_pair->block1, current_pair->fragment1);
294 static int equal_blocks(int b1, int b2){
296 if(equals_to1[b1][0]->block == b2 && equals_to2[b2][0]->block == b1)
302 static int equal_fragments(int b1, int f1, int b2, int f2){
304 if(equals_to1[b1][f1]->block == b2 && equals_to1[b1][f1]->fragment == f2 && equals_to2[b2][f2]->block == b1 && equals_to2[b2][f2]->fragment == f1)
310 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, xbt_dynar_t i2){
312 if((((struct mdesc *)heap1)->heaplimit != ((struct mdesc *)heap2)->heaplimit) || ((((struct mdesc *)heap1)->heapsize != ((struct mdesc *)heap2)->heapsize) ))
317 heaplimit = ((struct mdesc *)heap1)->heaplimit;
319 s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
321 heapbase1 = (char *)heap1 + BLOCKSIZE;
322 heapbase2 = (char *)heap2 + BLOCKSIZE;
324 heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)((struct mdesc *)heap1)->heapinfo - (char *)s_heap)));
325 heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)((struct mdesc *)heap2)->heapinfo - (char *)s_heap)));
327 heapsize1 = heap1->heapsize;
328 heapsize2 = heap2->heapsize;
333 equals_to1 = malloc(heaplimit * sizeof(heap_area_t *));
334 types1 = malloc(heaplimit * sizeof(type_name *));
335 for(i=0; i<=heaplimit; i++){
336 equals_to1[i] = malloc(MAX_FRAGMENT_PER_BLOCK * sizeof(heap_area_t));
337 types1[i] = malloc(MAX_FRAGMENT_PER_BLOCK * sizeof(type_name));
338 for(j=0; j<MAX_FRAGMENT_PER_BLOCK; j++){
339 equals_to1[i][j] = NULL;
344 equals_to2 = malloc(heaplimit * sizeof(heap_area_t *));
345 types2 = malloc(heaplimit * sizeof(type_name *));
346 for(i=0; i<=heaplimit; i++){
347 equals_to2[i] = malloc(MAX_FRAGMENT_PER_BLOCK * sizeof(heap_area_t));
348 types2[i] = malloc(MAX_FRAGMENT_PER_BLOCK * sizeof(type_name));
349 for(j=0; j<MAX_FRAGMENT_PER_BLOCK; j++){
350 equals_to2[i][j] = NULL;
356 MC_ignore_global_variable("heaplimit");
357 MC_ignore_global_variable("s_heap");
358 MC_ignore_global_variable("heapbase1");
359 MC_ignore_global_variable("heapbase2");
360 MC_ignore_global_variable("heapinfo1");
361 MC_ignore_global_variable("heapinfo2");
362 MC_ignore_global_variable("heapsize1");
363 MC_ignore_global_variable("heapsize2");
364 MC_ignore_global_variable("to_ignore1");
365 MC_ignore_global_variable("to_ignore2");
366 MC_ignore_global_variable("equals_to1");
367 MC_ignore_global_variable("equals_to2");
368 MC_ignore_global_variable("types1");
369 MC_ignore_global_variable("types2");
376 void reset_heap_information(){
380 for(i=0; i<=heaplimit; i++){
381 for(j=0; j<MAX_FRAGMENT_PER_BLOCK;j++){
382 heap_area_free(equals_to1[i][j]);
383 equals_to1[i][j] = NULL;
384 heap_area_free(equals_to2[i][j]);
385 equals_to2[i][j] = NULL;
386 xbt_free(types1[i][j]);
388 xbt_free(types2[i][j]);
402 s_heap = NULL, heapbase1 = NULL, heapbase2 = NULL;
403 heapinfo1 = NULL, heapinfo2 = NULL;
404 heaplimit = 0, heapsize1 = 0, heapsize2 = 0;
405 to_ignore1 = NULL, to_ignore2 = NULL;
406 equals_to1 = NULL, equals_to2 = NULL;
407 types1 = NULL, types2 = NULL;
411 int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dict_t all_types, xbt_dict_t other_types){
413 if(heap1 == NULL && heap2 == NULL){
414 XBT_DEBUG("Malloc descriptors null");
418 /* Start comparison */
419 size_t i1, i2, j1, j2, k;
420 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
421 int nb_diff1 = 0, nb_diff2 = 0;
423 xbt_dynar_t previous = xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
425 int equal, res_compare = 0;
427 /* Check busy blocks*/
431 while(i1 <= heaplimit){
433 if(heapinfo1[i1].type == -1){ /* Free block */
438 addr_block1 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
440 if(heapinfo1[i1].type == 0){ /* Large block */
442 if(is_stack(addr_block1)){
443 for(k=0; k < heapinfo1[i1].busy_block.size; k++)
444 equals_to1[i1+k][0] = new_heap_area(i1, -1);
445 for(k=0; k < heapinfo2[i1].busy_block.size; k++)
446 equals_to2[i1+k][0] = new_heap_area(i1, -1);
447 i1 += heapinfo1[i1].busy_block.size;
451 if(equals_to1[i1][0] != NULL){
460 /* Try first to associate to same block in the other heap */
461 if(heapinfo2[i1].type == heapinfo1[i1].type){
463 if(equals_to2[i1][0] == NULL){
465 addr_block2 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
467 res_compare = compare_heap_area(addr_block1, addr_block2, NULL, all_types, other_types, NULL, 0);
469 if(res_compare != 1){
470 for(k=1; k < heapinfo2[i1].busy_block.size; k++)
471 equals_to2[i1+k][0] = new_heap_area(i1, -1);
472 for(k=1; k < heapinfo1[i1].busy_block.size; k++)
473 equals_to1[i1+k][0] = new_heap_area(i1, -1);
475 i1 += heapinfo1[i1].busy_block.size;
478 xbt_dynar_reset(previous);
484 while(i2 <= heaplimit && !equal){
486 addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
493 if(heapinfo2[i2].type != 0){
498 if(equals_to2[i2][0] != NULL){
503 res_compare = compare_heap_area(addr_block1, addr_block2, NULL, all_types, other_types, NULL, 0);
505 if(res_compare != 1 ){
506 for(k=1; k < heapinfo2[i2].busy_block.size; k++)
507 equals_to2[i2+k][0] = new_heap_area(i1, -1);
508 for(k=1; k < heapinfo1[i1].busy_block.size; k++)
509 equals_to1[i1+k][0] = new_heap_area(i2, -1);
511 i1 += heapinfo1[i1].busy_block.size;
514 xbt_dynar_reset(previous);
521 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1, heapinfo1[i1].busy_block.busy_size, addr_block1);
527 }else{ /* Fragmented block */
529 for(j1=0; j1 < (size_t) (BLOCKSIZE >> heapinfo1[i1].type); j1++){
531 if(heapinfo1[i1].busy_frag.frag_size[j1] == -1) /* Free fragment */
534 if(equals_to1[i1][j1] != NULL)
537 addr_frag1 = (void*) ((char *)addr_block1 + (j1 << heapinfo1[i1].type));
542 /* Try first to associate to same fragment in the other heap */
543 if(heapinfo2[i1].type == heapinfo1[i1].type){
545 if(equals_to2[i1][j1] == NULL){
547 addr_block2 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
548 addr_frag2 = (void*) ((char *)addr_block2 + (j1 << ((xbt_mheap_t)s_heap)->heapinfo[i1].type));
550 res_compare = compare_heap_area(addr_frag1, addr_frag2, NULL, all_types, other_types, NULL, 0);
555 xbt_dynar_reset(previous);
561 while(i2 <= heaplimit && !equal){
563 if(heapinfo2[i2].type <= 0){
568 for(j2=0; j2 < (size_t) (BLOCKSIZE >> heapinfo2[i2].type); j2++){
570 if(i2 == i1 && j2 == j1)
573 if(equals_to2[i2][j2] != NULL)
576 addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
577 addr_frag2 = (void*) ((char *)addr_block2 + (j2 <<((xbt_mheap_t)s_heap)->heapinfo[i2].type));
579 res_compare = compare_heap_area(addr_frag1, addr_frag2, NULL, all_types, other_types, NULL, 0);
581 if(res_compare != 1){
583 xbt_dynar_reset(previous);
587 xbt_dynar_reset(previous);
596 XBT_DEBUG("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n", i1, j1, heapinfo1[i1].busy_frag.frag_size[j1], addr_frag1);
611 /* All blocks/fragments are equal to another block/fragment ? */
613 void *real_addr_frag1 = NULL, *real_addr_block1 = NULL, *real_addr_block2 = NULL, *real_addr_frag2 = NULL;
616 if(heapinfo1[i].type == 0){
618 if(heapinfo1[i].busy_block.busy_size > 0){
619 if(equals_to1[i][0] == NULL){
620 if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
621 addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
622 XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block1, heapinfo1[i].busy_block.busy_size);
623 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
630 if(heapinfo1[i].type > 0){
631 addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
632 real_addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)((struct mdesc *)s_heap)->heapbase));
633 for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo1[i].type); j++){
635 if(heapinfo1[i].busy_frag.frag_size[j] > 0){
636 if(equals_to1[i][j] == NULL){
637 if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
638 addr_frag1 = (void*) ((char *)addr_block1 + (j << heapinfo1[i].type));
639 real_addr_frag1 = (void*) ((char *)real_addr_block1 + (j << ((struct mdesc *)s_heap)->heapinfo[i].type));
640 XBT_DEBUG("Block %zu, Fragment %zu (%p - %p) not found (size used = %zd)", i, j, addr_frag1, real_addr_frag1, heapinfo1[i].busy_frag.frag_size[j]);
641 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
653 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
658 if(heapinfo2[i].type == 0){
660 if(heapinfo2[i].busy_block.busy_size > 0){
661 if(equals_to2[i][0] == NULL){
662 if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
663 addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
664 XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block2, heapinfo2[i].busy_block.busy_size);
665 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
672 if(heapinfo2[i].type > 0){
673 addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
674 real_addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)((struct mdesc *)s_heap)->heapbase));
675 for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo2[i].type); j++){
677 if(heapinfo2[i].busy_frag.frag_size[j] > 0){
678 if(equals_to2[i][j] == NULL){
679 if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
680 addr_frag2 = (void*) ((char *)addr_block2 + (j << heapinfo2[i].type));
681 real_addr_frag2 = (void*) ((char *)real_addr_block2 + (j << ((struct mdesc *)s_heap)->heapinfo[i].type));
682 XBT_DEBUG( "Block %zu, Fragment %zu (%p - %p) not found (size used = %zd)", i, j, addr_frag2, real_addr_frag2, heapinfo2[i].busy_frag.frag_size[j]);
683 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
695 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
697 xbt_dynar_free(&previous);
698 real_addr_frag1 = NULL, real_addr_block1 = NULL, real_addr_block2 = NULL, real_addr_frag2 = NULL;
700 return ((nb_diff1 > 0) || (nb_diff2 > 0));
703 static int compare_heap_area_without_type(void *real_area1, void *real_area2, void *area1, void *area2, xbt_dynar_t previous, xbt_dict_t all_types, xbt_dict_t other_types, int size, int check_ignore){
706 void *addr_pointed1, *addr_pointed2;
707 int pointer_align, ignore1, ignore2, res_compare;
711 if(check_ignore > 0){
712 if((ignore1 = heap_comparison_ignore_size(to_ignore1, (char *)real_area1 + i)) != -1){
713 if((ignore2 = heap_comparison_ignore_size(to_ignore2, (char *)real_area2 + i)) == ignore1){
726 if(memcmp(((char *)area1) + i, ((char *)area2) + i, 1) != 0){
728 pointer_align = (i / sizeof(void*)) * sizeof(void*);
729 addr_pointed1 = *((void **)((char *)area1 + pointer_align));
730 addr_pointed2 = *((void **)((char *)area2 + pointer_align));
732 if(addr_pointed1 > maestro_stack_start && addr_pointed1 < maestro_stack_end && addr_pointed2 > maestro_stack_start && addr_pointed2 < maestro_stack_end){
733 i = pointer_align + sizeof(void *);
735 }else if((addr_pointed1 > s_heap) && ((char *)addr_pointed1 < (char *)s_heap + STD_HEAP_SIZE)
736 && (addr_pointed2 > s_heap) && ((char *)addr_pointed2 < (char *)s_heap + STD_HEAP_SIZE)){
737 res_compare = compare_heap_area(addr_pointed1, addr_pointed2, previous, all_types, other_types, NULL, 0);
738 if(res_compare == 1){
741 i = pointer_align + sizeof(void *);
757 // area_size is either a byte_size or an elements_count?&
758 static int compare_heap_area_with_type(void *real_area1, void *real_area2, void *area1, void *area2,
759 xbt_dynar_t previous, xbt_dict_t all_types, xbt_dict_t other_types, char *type_id,
760 int area_size, int check_ignore, int pointer_level){
762 if(is_stack(real_area1) && is_stack(real_area2))
765 size_t ignore1, ignore2;
767 if((check_ignore > 0) && ((ignore1 = heap_comparison_ignore_size(to_ignore1, real_area1)) > 0) && ((ignore2 = heap_comparison_ignore_size(to_ignore2, real_area2)) == ignore1)){
771 dw_type_t type = xbt_dict_get_or_null(all_types, type_id);
772 dw_type_t subtype, subsubtype;
773 int res, elm_size, i, switch_types = 0;
774 unsigned int cursor = 0;
776 void *addr_pointed1, *addr_pointed2;;
780 case DW_TAG_base_type:
781 if(strcmp(type->name, "char") == 0){ /* String, hence random (arbitrary ?) size */
782 if(real_area1 == real_area2)
785 return (memcmp(area1, area2, area_size) != 0);
787 if(area_size != -1 && type->byte_size != area_size)
790 return (memcmp(area1, area2, type->byte_size) != 0);
794 case DW_TAG_enumeration_type:
795 if(area_size != -1 && type->byte_size != area_size)
798 return (memcmp(area1, area2, type->byte_size) != 0);
801 case DW_TAG_const_type:
802 case DW_TAG_volatile_type:
803 return compare_heap_area_with_type(real_area1, real_area2, area1, area2, previous, all_types, other_types, type->dw_type_id, area_size, check_ignore, pointer_level);
805 case DW_TAG_array_type:
806 subtype = xbt_dict_get_or_null(all_types, type->dw_type_id);
807 switch(subtype->type){
808 case DW_TAG_base_type:
809 case DW_TAG_enumeration_type:
810 case DW_TAG_pointer_type:
811 case DW_TAG_structure_type:
812 case DW_TAG_union_type:
813 if(subtype->byte_size == 0){ /*declaration of the type, need the complete description */
814 type_desc = get_type_description(all_types, subtype->name);
816 subtype = xbt_dict_get_or_null(all_types, type_desc);
818 subtype = xbt_dict_get_or_null(other_types, get_type_description(other_types, subtype->name));
822 elm_size = subtype->byte_size;
824 // TODO, just remove the type indirection?
825 case DW_TAG_const_type:
827 case DW_TAG_volatile_type:
828 subsubtype = xbt_dict_get_or_null(all_types, subtype->dw_type_id);
829 if(subsubtype->byte_size == 0){ /*declaration of the type, need the complete description */
830 type_desc = get_type_description(all_types, subsubtype->name);
832 subsubtype = xbt_dict_get_or_null(all_types, type_desc);
834 subsubtype = xbt_dict_get_or_null(other_types, get_type_description(other_types, subtype->name));
838 elm_size = subsubtype->byte_size;
844 for(i=0; i<type->element_count; i++){
845 // TODO, add support for variable stride (DW_AT_byte_stride)
847 res = compare_heap_area_with_type((char *)real_area1 + (i*elm_size), (char *)real_area2 + (i*elm_size), (char *)area1 + (i*elm_size), (char *)area2 + (i*elm_size), previous, other_types, all_types, type->dw_type_id, subtype->byte_size, check_ignore, pointer_level);
849 res = compare_heap_area_with_type((char *)real_area1 + (i*elm_size), (char *)real_area2 + (i*elm_size), (char *)area1 + (i*elm_size), (char *)area2 + (i*elm_size), previous, all_types, other_types, type->dw_type_id, subtype->byte_size, check_ignore, pointer_level);
854 case DW_TAG_pointer_type:
855 if(type->dw_type_id && ((dw_type_t)xbt_dict_get_or_null(all_types, type->dw_type_id))->type == DW_TAG_subroutine_type){
856 addr_pointed1 = *((void **)(area1));
857 addr_pointed2 = *((void **)(area2));
858 return (addr_pointed1 != addr_pointed2);;
861 if(pointer_level > 1){ /* Array of pointers */
862 for(i=0; i<(area_size/sizeof(void *)); i++){
863 addr_pointed1 = *((void **)((char *)area1 + (i*sizeof(void *))));
864 addr_pointed2 = *((void **)((char *)area2 + (i*sizeof(void *))));
865 if(addr_pointed1 > s_heap && (char *)addr_pointed1 < (char*) s_heap + STD_HEAP_SIZE && addr_pointed2 > s_heap && (char *)addr_pointed2 < (char*) s_heap + STD_HEAP_SIZE)
866 res = compare_heap_area(addr_pointed1, addr_pointed2, previous, all_types, other_types, type->dw_type_id, pointer_level);
868 res = (addr_pointed1 != addr_pointed2);
873 addr_pointed1 = *((void **)(area1));
874 addr_pointed2 = *((void **)(area2));
875 if(addr_pointed1 > s_heap && (char *)addr_pointed1 < (char*) s_heap + STD_HEAP_SIZE && addr_pointed2 > s_heap && (char *)addr_pointed2 < (char*) s_heap + STD_HEAP_SIZE)
876 return compare_heap_area(addr_pointed1, addr_pointed2, previous, all_types, other_types, type->dw_type_id, pointer_level);
878 return (addr_pointed1 != addr_pointed2);
882 case DW_TAG_structure_type:
883 if(type->byte_size == 0){ /*declaration of the structure, need the complete description */
884 type_desc = get_type_description(all_types, type->name);
886 type = xbt_dict_get_or_null(all_types, type_desc);
888 type = xbt_dict_get_or_null(other_types, get_type_description(other_types, type->name));
892 if(area_size != -1 && type->byte_size != area_size){
893 if(area_size>type->byte_size && area_size%type->byte_size == 0){
894 for(i=0; i<(area_size/type->byte_size); i++){
896 res = compare_heap_area_with_type((char *)real_area1 + (i*type->byte_size), (char *)real_area2 + (i*type->byte_size), (char *)area1 + (i*type->byte_size), (char *)area2 + (i*type->byte_size), previous, other_types, all_types, type_id, -1, check_ignore, 0);
898 res = compare_heap_area_with_type((char *)real_area1 + (i*type->byte_size), (char *)real_area2 + (i*type->byte_size), (char *)area1 + (i*type->byte_size), (char *)area2 + (i*type->byte_size), previous, all_types, other_types, type_id, -1, check_ignore, 0);
907 xbt_dynar_foreach(type->members, cursor, member){
909 res = compare_heap_area_with_type((char *)real_area1 + member->offset, (char *)real_area2 + member->offset, (char *)area1 + member->offset, (char *)area2 + member->offset, previous, other_types, all_types, member->dw_type_id, -1, check_ignore, 0);
911 res = compare_heap_area_with_type((char *)real_area1 + member->offset, (char *)real_area2 + member->offset, (char *)area1 + member->offset, (char *)area2 + member->offset, previous, all_types, other_types, member->dw_type_id, -1, check_ignore, 0);
918 case DW_TAG_union_type:
919 return compare_heap_area_without_type(real_area1, real_area2, area1, area2, previous, all_types, other_types, type->byte_size, check_ignore);
929 static char* get_offset_type(char* type_id, int offset, xbt_dict_t all_types, xbt_dict_t other_types, int area_size, int *switch_type){
930 dw_type_t type = xbt_dict_get_or_null(all_types, type_id);
932 type = xbt_dict_get_or_null(other_types, type_id);
937 case DW_TAG_structure_type :
938 if(type->byte_size == 0){ /*declaration of the structure, need the complete description */
939 if(*switch_type == 0){
940 type_desc = get_type_description(all_types, type->name);
942 type = xbt_dict_get_or_null(all_types, type_desc);
944 type = xbt_dict_get_or_null(other_types, get_type_description(other_types, type->name));
948 type_desc = get_type_description(other_types, type->name);
950 type = xbt_dict_get_or_null(other_types, type_desc);
952 type = xbt_dict_get_or_null(all_types, get_type_description(other_types, type->name));
958 if(area_size != -1 && type->byte_size != area_size){
959 if(area_size>type->byte_size && area_size%type->byte_size == 0)
964 unsigned int cursor = 0;
966 xbt_dynar_foreach(type->members, cursor, member){
967 if(member->offset == offset)
968 return member->dw_type_id;
974 /* FIXME : other cases ? */
980 int compare_heap_area(void *area1, void* area2, xbt_dynar_t previous, xbt_dict_t all_types, xbt_dict_t other_types, char *type_id, int pointer_level){
983 ssize_t block1, frag1, block2, frag2;
985 int check_ignore = 0;
987 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2, *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
988 void *area1_to_compare, *area2_to_compare;
989 dw_type_t type = NULL;
992 int offset1 =0, offset2 = 0;
993 int new_size1 = -1, new_size2 = -1;
994 char *new_type_id1 = NULL, *new_type_id2 = NULL;
999 if(previous == NULL){
1000 previous = xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1004 block1 = ((char*)area1 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
1005 block2 = ((char*)area2 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
1007 if(is_block_stack((int)block1) && is_block_stack((int)block2)){
1008 add_heap_area_pair(previous, block1, -1, block2, -1);
1010 match_equals(previous);
1011 xbt_dynar_free(&previous);
1016 if(((char *)area1 < (char*)((xbt_mheap_t)s_heap)->heapbase) || (block1 > heapsize1) || (block1 < 1) || ((char *)area2 < (char*)((xbt_mheap_t)s_heap)->heapbase) || (block2 > heapsize2) || (block2 < 1)){
1018 xbt_dynar_free(&previous);
1023 addr_block1 = ((void*) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE + (char*)heapbase1));
1024 addr_block2 = ((void*) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE + (char*)heapbase2));
1026 real_addr_block1 = ((void*) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
1027 real_addr_block2 = ((void*) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
1030 type = xbt_dict_get_or_null(all_types, type_id);
1031 if(type->byte_size == 0){
1032 if(type->dw_type_id == NULL){
1033 type_desc = get_type_description(all_types, type->name);
1035 type = xbt_dict_get_or_null(all_types, type_desc);
1037 type = xbt_dict_get_or_null(other_types, get_type_description(other_types, type->name));
1039 type = xbt_dict_get_or_null(all_types, type->dw_type_id);
1042 if((type->byte_size == DW_TAG_pointer_type) || ((type->type == DW_TAG_base_type) && (!strcmp(type->name, "char"))))
1045 type_size = type->byte_size;
1048 if((heapinfo1[block1].type == -1) && (heapinfo2[block2].type == -1)){ /* Free block */
1051 match_equals(previous);
1052 xbt_dynar_free(&previous);
1056 }else if((heapinfo1[block1].type == 0) && (heapinfo2[block2].type == 0)){ /* Complete block */
1058 if(equals_to1[block1][0] != NULL && equals_to2[block2][0] != NULL){
1059 if(equal_blocks(block1, block2)){
1061 match_equals(previous);
1062 xbt_dynar_free(&previous);
1068 if(type_size != -1){
1069 if(type_size != heapinfo1[block1].busy_block.busy_size && type_size != heapinfo2[block2].busy_block.busy_size && !strcmp(type->name, "s_smx_context")){
1071 match_equals(previous);
1072 xbt_dynar_free(&previous);
1078 if(heapinfo1[block1].busy_block.size != heapinfo2[block2].busy_block.size){
1080 xbt_dynar_free(&previous);
1085 if(heapinfo1[block1].busy_block.busy_size != heapinfo2[block2].busy_block.busy_size){
1087 xbt_dynar_free(&previous);
1092 if(!add_heap_area_pair(previous, block1, -1, block2, -1)){
1094 match_equals(previous);
1095 xbt_dynar_free(&previous);
1100 size = heapinfo1[block1].busy_block.busy_size;
1102 if(type_id != NULL){
1103 xbt_free(types1[block1][0]);
1104 xbt_free(types2[block2][0]);
1105 types1[block1][0] = strdup(type_id);
1106 types2[block2][0] = strdup(type_id);
1111 match_equals(previous);
1112 xbt_dynar_free(&previous);
1120 area1_to_compare = addr_block1;
1121 area2_to_compare = addr_block2;
1123 if((heapinfo1[block1].busy_block.ignore > 0) && (heapinfo2[block2].busy_block.ignore == heapinfo1[block1].busy_block.ignore))
1124 check_ignore = heapinfo1[block1].busy_block.ignore;
1126 }else if((heapinfo1[block1].type > 0) && (heapinfo2[block2].type > 0)){ /* Fragmented block */
1128 frag1 = ((uintptr_t) (ADDR2UINT (area1) % (BLOCKSIZE))) >> heapinfo1[block1].type;
1129 frag2 = ((uintptr_t) (ADDR2UINT (area2) % (BLOCKSIZE))) >> heapinfo2[block2].type;
1131 addr_frag1 = (void*) ((char *)addr_block1 + (frag1 << heapinfo1[block1].type));
1132 addr_frag2 = (void*) ((char *)addr_block2 + (frag2 << heapinfo2[block2].type));
1134 real_addr_frag1 = (void*) ((char *)real_addr_block1 + (frag1 << ((xbt_mheap_t)s_heap)->heapinfo[block1].type));
1135 real_addr_frag2 = (void*) ((char *)real_addr_block2 + (frag2 << ((xbt_mheap_t)s_heap)->heapinfo[block2].type));
1137 if(type_size != -1){
1138 if(heapinfo1[block1].busy_frag.frag_size[frag1] == -1 || heapinfo2[block2].busy_frag.frag_size[frag2] == -1){
1140 match_equals(previous);
1141 xbt_dynar_free(&previous);
1145 if(type_size != heapinfo1[block1].busy_frag.frag_size[frag1] || type_size != heapinfo2[block2].busy_frag.frag_size[frag2]){
1147 match_equals(previous);
1148 xbt_dynar_free(&previous);
1154 if(equals_to1[block1][frag1] != NULL && equals_to2[block2][frag2] != NULL){
1155 if(equal_fragments(block1, frag1, block2, frag2)){
1157 match_equals(previous);
1158 xbt_dynar_free(&previous);
1164 if(heapinfo1[block1].busy_frag.frag_size[frag1] != heapinfo2[block2].busy_frag.frag_size[frag2]){
1165 if(type_size == -1){
1167 match_equals(previous);
1168 xbt_dynar_free(&previous);
1173 xbt_dynar_free(&previous);
1179 size = heapinfo1[block1].busy_frag.frag_size[frag1];
1181 if(type_id != NULL){
1182 xbt_free(types1[block1][frag1]);
1183 xbt_free(types2[block2][frag2]);
1184 types1[block1][frag1] = strdup(type_id);
1185 types2[block2][frag2] = strdup(type_id);
1188 if(real_addr_frag1 != area1 || real_addr_frag2 != area2){
1189 offset1 = (char *)area1 - (char *)real_addr_frag1;
1190 offset2 = (char *)area2 - (char *)real_addr_frag2;
1191 if(types1[block1][frag1] != NULL && types2[block2][frag2] != NULL){
1192 new_type_id1 = get_offset_type(types1[block1][frag1], offset1, all_types, other_types, size, &switch_type);
1193 new_type_id2 = get_offset_type(types2[block2][frag2], offset1, all_types, other_types, size, &switch_type);
1194 }else if(types1[block1][frag1] != NULL){
1195 new_type_id1 = get_offset_type(types1[block1][frag1], offset1, all_types, other_types, size, &switch_type);
1196 new_type_id2 = get_offset_type(types1[block1][frag1], offset2, all_types, other_types, size, &switch_type);
1197 }else if(types2[block2][frag2] != NULL){
1198 new_type_id1 = get_offset_type(types2[block2][frag2], offset1, all_types, other_types, size, &switch_type);
1199 new_type_id2 = get_offset_type(types2[block2][frag2], offset2, all_types, other_types, size, &switch_type);
1202 match_equals(previous);
1203 xbt_dynar_free(&previous);
1208 if(new_type_id1 != NULL && new_type_id2 != NULL && !strcmp(new_type_id1, new_type_id2)){
1210 type = xbt_dict_get_or_null(other_types, new_type_id1);
1211 while(type->byte_size == 0 && type->dw_type_id != NULL)
1212 type = xbt_dict_get_or_null(other_types, type->dw_type_id);
1213 new_size1 = type->byte_size;
1214 type = xbt_dict_get_or_null(other_types, new_type_id2);
1215 while(type->byte_size == 0 && type->dw_type_id != NULL)
1216 type = xbt_dict_get_or_null(other_types, type->dw_type_id);
1217 new_size2 = type->byte_size;
1219 type = xbt_dict_get_or_null(all_types, new_type_id1);
1220 while(type->byte_size == 0 && type->dw_type_id != NULL)
1221 type = xbt_dict_get_or_null(all_types, type->dw_type_id);
1222 new_size1 = type->byte_size;
1223 type = xbt_dict_get_or_null(all_types, new_type_id2);
1224 while(type->byte_size == 0 && type->dw_type_id != NULL)
1225 type = xbt_dict_get_or_null(all_types, type->dw_type_id);
1226 new_size2 = type->byte_size;
1230 match_equals(previous);
1231 xbt_dynar_free(&previous);
1237 area1_to_compare = (char *)addr_frag1 + offset1;
1238 area2_to_compare = (char *)addr_frag2 + offset2;
1240 if(new_size1 > 0 && new_size1 == new_size2){
1241 type_id = new_type_id1;
1245 if(offset1 == 0 && offset2 == 0){
1246 if(!add_heap_area_pair(previous, block1, frag1, block2, frag2)){
1248 match_equals(previous);
1249 xbt_dynar_free(&previous);
1257 match_equals(previous);
1258 xbt_dynar_free(&previous);
1263 if((heapinfo1[block1].busy_frag.ignore[frag1] > 0) && ( heapinfo2[block2].busy_frag.ignore[frag2] == heapinfo1[block1].busy_frag.ignore[frag1]))
1264 check_ignore = heapinfo1[block1].busy_frag.ignore[frag1];
1269 xbt_dynar_free(&previous);
1276 /* Start comparison*/
1277 if(type_id != NULL){
1279 res_compare = compare_heap_area_with_type(area1, area2, area1_to_compare, area2_to_compare, previous, other_types, all_types, type_id, size, check_ignore, pointer_level);
1281 res_compare = compare_heap_area_with_type(area1, area2, area1_to_compare, area2_to_compare, previous, all_types, other_types, type_id, size, check_ignore, pointer_level);
1282 if(res_compare == 1){
1284 xbt_dynar_free(&previous);
1289 res_compare = compare_heap_area_without_type(area1, area2, area1_to_compare, area2_to_compare, previous, other_types, all_types, size, check_ignore);
1291 res_compare = compare_heap_area_without_type(area1, area2, area1_to_compare, area2_to_compare, previous, all_types, other_types, size, check_ignore);
1292 if(res_compare == 1){
1294 xbt_dynar_free(&previous);
1300 match_equals(previous);
1301 xbt_dynar_free(&previous);
1307 /*********************************************** Miscellaneous ***************************************************/
1308 /****************************************************************************************************************/
1311 int get_pointed_area_size(void *area, int heap){
1314 malloc_info *heapinfo;
1317 heapinfo = heapinfo1;
1319 heapinfo = heapinfo2;
1321 block = ((char*)area - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
1323 if(((char *)area < (char*)((xbt_mheap_t)s_heap)->heapbase) || (block > heapsize1) || (block < 1))
1326 if(heapinfo[block].type == -1){ /* Free block */
1328 }else if(heapinfo[block].type == 0){ /* Complete block */
1329 return (int)heapinfo[block].busy_block.busy_size;
1331 frag = ((uintptr_t) (ADDR2UINT (area) % (BLOCKSIZE))) >> heapinfo[block].type;
1332 return (int)heapinfo[block].busy_frag.frag_size[frag];
1337 char *get_type_description(xbt_dict_t types, char *type_name){
1339 xbt_dict_cursor_t dict_cursor;
1343 xbt_dict_foreach(types, dict_cursor, type_origin, type){
1344 if(type->name && (strcmp(type->name, type_name) == 0) && type->byte_size > 0){
1345 xbt_dict_cursor_free(&dict_cursor);
1350 xbt_dict_cursor_free(&dict_cursor);
1356 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1359 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
1361 if(heap1 == NULL && heap1 == NULL){
1362 XBT_DEBUG("Malloc descriptors null");
1366 if(heap1->heaplimit != heap2->heaplimit){
1367 XBT_DEBUG("Different limit of valid info table indices");
1371 /* Heap information */
1372 heaplimit = ((struct mdesc *)heap1)->heaplimit;
1374 s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
1376 heapbase1 = (char *)heap1 + BLOCKSIZE;
1377 heapbase2 = (char *)heap2 + BLOCKSIZE;
1379 heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)heap1->heapinfo - (char *)s_heap)));
1380 heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)heap2->heapinfo - (char *)s_heap)));
1382 heapsize1 = heap1->heapsize;
1383 heapsize2 = heap2->heapsize;
1385 /* Start comparison */
1387 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1391 /* Check busy blocks*/
1395 while(i <= heaplimit){
1397 addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
1398 addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
1400 if(heapinfo1[i].type != heapinfo2[i].type){
1402 distance += BLOCKSIZE;
1403 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i, heapinfo1[i].type, heapinfo2[i].type, distance);
1408 if(heapinfo1[i].type == -1){ /* Free block */
1413 if(heapinfo1[i].type == 0){ /* Large block */
1415 if(heapinfo1[i].busy_block.size != heapinfo2[i].busy_block.size){
1416 distance += BLOCKSIZE * max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1417 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1418 XBT_DEBUG("Different larger of cluster at block %zu : %zu - %zu -> distance = %d", i, heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size, distance);
1422 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1423 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1424 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1425 XBT_DEBUG("Different size used oin large cluster at block %zu : %zu - %zu -> distance = %d", i, heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size, distance);
1431 //while(k < (heapinfo1[i].busy_block.busy_size)){
1432 while(k < heapinfo1[i].busy_block.size * BLOCKSIZE){
1433 if(memcmp((char *)addr_block1 + k, (char *)addr_block2 + k, 1) != 0){
1441 }else { /* Fragmented block */
1443 for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo1[i].type); j++){
1445 addr_frag1 = (void*) ((char *)addr_block1 + (j << heapinfo1[i].type));
1446 addr_frag2 = (void*) ((char *)addr_block2 + (j << heapinfo2[i].type));
1448 if(heapinfo1[i].busy_frag.frag_size[j] == 0 && heapinfo2[i].busy_frag.frag_size[j] == 0){
1453 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1454 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1455 XBT_DEBUG("Different size used in fragment %zu in block %zu : %d - %d -> distance = %d", j, i, heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j], distance);
1461 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1462 while(k < (BLOCKSIZE / (BLOCKSIZE >> heapinfo1[i].type))){
1463 if(memcmp((char *)addr_frag1 + k, (char *)addr_frag2 + k, 1) != 0){