1 /* mc_diff - Memory snapshooting and comparison */
3 /* Copyright (c) 2008-2014. 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_object_info.h"
14 #include "mc/datatypes.h"
15 #include "mc/mc_private.h"
16 #include "mc/mc_snapshot.h"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
19 "Logging specific to mc_diff in mc");
21 xbt_dynar_t mc_heap_comparison_ignore;
22 xbt_dynar_t stacks_areas;
23 void *maestro_stack_start, *maestro_stack_end;
26 /********************************* Backtrace ***********************************/
27 /******************************************************************************/
29 static void mmalloc_backtrace_block_display(void *heapinfo, int block)
34 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
35 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
39 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
40 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
42 /* xbt_ex_setup_backtrace(&e); */
43 /* if (e.used == 0) { */
44 /* fprintf(stderr, "(backtrace not set)\n"); */
45 /* } else if (e.bt_strings == NULL) { */
46 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
50 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
51 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
52 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
57 static void mmalloc_backtrace_fragment_display(void *heapinfo, int block,
63 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
64 /* e.used = XBT_BACKTRACE_SIZE; */
66 /* xbt_ex_setup_backtrace(&e); */
67 /* if (e.used == 0) { */
68 /* fprintf(stderr, "(backtrace not set)\n"); */
69 /* } else if (e.bt_strings == NULL) { */
70 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
74 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
75 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
76 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
82 static void mmalloc_backtrace_display(void *addr)
85 /* size_t block, frag_nb; */
88 /* xbt_mheap_t heap = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); */
90 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
92 /* type = heap->heapinfo[block].type; */
95 /* case MMALLOC_TYPE_HEAPINFO : */
96 /* case MMALLOC_TYPE_FREE : /\* Free block *\/ */
97 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
100 /* case 0: /\* Large block *\/ */
101 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
103 /* default: /\* Fragmented block *\/ */
104 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
105 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
106 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
109 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
115 static int compare_backtrace(int b1, int f1, int b2, int f2)
119 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
120 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
121 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
122 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
127 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
128 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
129 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
130 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
139 /*********************************** Heap comparison ***********************************/
140 /***************************************************************************************/
142 typedef char *type_name;
145 /** \brief Base address of the real heap */
148 // Number of blocks in the heaps:
149 size_t heapsize1, heapsize2;
150 xbt_dynar_t to_ignore1, to_ignore2;
151 s_heap_area_t *equals_to1, *equals_to2;
152 dw_type_t *types1, *types2;
156 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
157 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
158 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
159 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
161 __thread struct s_mc_diff *mc_diff_info = NULL;
163 /*********************************** Free functions ************************************/
165 static void heap_area_pair_free(heap_area_pair_t pair)
171 static void heap_area_pair_free_voidp(void *d)
173 heap_area_pair_free((heap_area_pair_t) * (void **) d);
176 static void heap_area_free(heap_area_t area)
182 /************************************************************************************/
184 static s_heap_area_t make_heap_area(int block, int fragment)
189 area.fragment = fragment;
194 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
195 int block2, int fragment2)
198 unsigned int cursor = 0;
199 heap_area_pair_t current_pair;
201 xbt_dynar_foreach(list, cursor, current_pair) {
202 if (current_pair->block1 == block1 && current_pair->block2 == block2
203 && current_pair->fragment1 == fragment1
204 && current_pair->fragment2 == fragment2)
211 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
212 int block2, int fragment2)
215 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
216 heap_area_pair_t pair = NULL;
217 pair = xbt_new0(s_heap_area_pair_t, 1);
218 pair->block1 = block1;
219 pair->fragment1 = fragment1;
220 pair->block2 = block2;
221 pair->fragment2 = fragment2;
223 xbt_dynar_push(list, &pair);
231 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
235 unsigned int cursor = 0;
237 int end = xbt_dynar_length(ignore_list) - 1;
238 mc_heap_ignore_region_t region;
240 while (start <= end) {
241 cursor = (start + end) / 2;
243 (mc_heap_ignore_region_t) xbt_dynar_get_as(ignore_list, cursor,
244 mc_heap_ignore_region_t);
245 if (region->address == address)
247 if (region->address < address)
249 if (region->address > address)
256 static int is_stack(void *address)
258 unsigned int cursor = 0;
259 stack_region_t stack;
261 xbt_dynar_foreach(stacks_areas, cursor, stack) {
262 if (address == stack->address)
269 // TODO, this should depend on the snapshot?
270 static int is_block_stack(int block)
272 unsigned int cursor = 0;
273 stack_region_t stack;
275 xbt_dynar_foreach(stacks_areas, cursor, stack) {
276 if (block == stack->block)
283 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
286 unsigned int cursor = 0;
287 heap_area_pair_t current_pair;
289 xbt_dynar_foreach(list, cursor, current_pair) {
291 if (current_pair->fragment1 != -1) {
293 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
294 make_heap_area(current_pair->block2, current_pair->fragment2);
295 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
296 make_heap_area(current_pair->block1, current_pair->fragment1);
300 state->equals_to1_(current_pair->block1, 0) =
301 make_heap_area(current_pair->block2, current_pair->fragment2);
302 state->equals_to2_(current_pair->block2, 0) =
303 make_heap_area(current_pair->block1, current_pair->fragment1);
310 /** Check whether two blocks are known to be matching
312 * @param state State used
313 * @param b1 Block of state 1
314 * @param b2 Block of state 2
315 * @return if the blocks are known to be matching
317 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
320 if (state->equals_to1_(b1, 0).block == b2
321 && state->equals_to2_(b2, 0).block == b1)
327 /** Check whether two fragments are known to be matching
329 * @param state State used
330 * @param b1 Block of state 1
331 * @param f1 Fragment of state 1
332 * @param b2 Block of state 2
333 * @param f2 Fragment of state 2
334 * @return if the fragments are known to be matching
336 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
340 if (state->equals_to1_(b1, f1).block == b2
341 && state->equals_to1_(b1, f1).fragment == f2
342 && state->equals_to2_(b2, f2).block == b1
343 && state->equals_to2_(b2, f2).fragment == f1)
349 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
352 if (mc_diff_info == NULL) {
353 mc_diff_info = xbt_new0(struct s_mc_diff, 1);
354 mc_diff_info->equals_to1 = NULL;
355 mc_diff_info->equals_to2 = NULL;
356 mc_diff_info->types1 = NULL;
357 mc_diff_info->types2 = NULL;
359 struct s_mc_diff *state = mc_diff_info;
361 if ((((struct mdesc *) heap1)->heaplimit !=
362 ((struct mdesc *) heap2)->heaplimit)
364 ((((struct mdesc *) heap1)->heapsize !=
365 ((struct mdesc *) heap2)->heapsize)))
368 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
370 // Mamailloute in order to find the base address of the main heap:
372 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
374 state->heapsize1 = heap1->heapsize;
375 state->heapsize2 = heap2->heapsize;
377 state->to_ignore1 = i1;
378 state->to_ignore2 = i2;
380 if (state->heaplimit > state->available) {
382 realloc(state->equals_to1,
383 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
384 sizeof(s_heap_area_t));
386 realloc(state->types1,
387 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
388 sizeof(type_name *));
390 realloc(state->equals_to2,
391 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
392 sizeof(s_heap_area_t));
394 realloc(state->types2,
395 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
396 sizeof(type_name *));
397 state->available = state->heaplimit;
400 memset(state->equals_to1, 0,
401 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
402 memset(state->equals_to2, 0,
403 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
404 memset(state->types1, 0,
405 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
406 memset(state->types2, 0,
407 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
413 void reset_heap_information()
418 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
421 struct s_mc_diff *state = mc_diff_info;
423 /* Start comparison */
424 size_t i1, i2, j1, j2, k;
425 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
426 int nb_diff1 = 0, nb_diff2 = 0;
428 int equal, res_compare = 0;
430 /* Check busy blocks */
434 malloc_info heapinfo_temp1, heapinfo_temp2;
435 malloc_info heapinfo_temp2b;
437 mc_mem_region_t heap_region1 = snapshot1->regions[0];
438 mc_mem_region_t heap_region2 = snapshot2->regions[0];
440 // This is in snapshot do not use them directly:
441 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, MC_NO_PROCESS_INDEX);
442 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, MC_NO_PROCESS_INDEX);
444 while (i1 <= state->heaplimit) {
446 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
447 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i1], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
449 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
454 if (heapinfo1->type < 0) {
455 fprintf(stderr, "Unkown mmalloc block type.\n");
460 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
461 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
463 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
465 if (is_stack(addr_block1)) {
466 for (k = 0; k < heapinfo1->busy_block.size; k++)
467 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
468 for (k = 0; k < heapinfo2->busy_block.size; k++)
469 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
470 i1 += heapinfo1->busy_block.size;
474 if (state->equals_to1_(i1, 0).valid) {
483 /* Try first to associate to same block in the other heap */
484 if (heapinfo2->type == heapinfo1->type) {
486 if (state->equals_to2_(i1, 0).valid == 0) {
489 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
490 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
493 compare_heap_area(MC_NO_PROCESS_INDEX, addr_block1, addr_block2, snapshot1, snapshot2,
496 if (res_compare != 1) {
497 for (k = 1; k < heapinfo2->busy_block.size; k++)
498 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
499 for (k = 1; k < heapinfo1->busy_block.size; k++)
500 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
502 i1 += heapinfo1->busy_block.size;
509 while (i2 <= state->heaplimit && !equal) {
512 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
513 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
520 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
522 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
527 if (state->equals_to2_(i2, 0).valid) {
533 compare_heap_area(MC_NO_PROCESS_INDEX, addr_block1, addr_block2, snapshot1, snapshot2,
536 if (res_compare != 1) {
537 for (k = 1; k < heapinfo2b->busy_block.size; k++)
538 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
539 for (k = 1; k < heapinfo1->busy_block.size; k++)
540 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
542 i1 += heapinfo1->busy_block.size;
550 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
551 heapinfo1->busy_block.busy_size, addr_block1);
552 i1 = state->heaplimit + 1;
557 } else { /* Fragmented block */
559 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
561 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
564 if (state->equals_to1_(i1, j1).valid)
568 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
573 /* Try first to associate to same fragment in the other heap */
574 if (heapinfo2->type == heapinfo1->type) {
576 if (state->equals_to2_(i1, j1).valid == 0) {
579 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
580 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
582 (void *) ((char *) addr_block2 +
583 (j1 << heapinfo2->type));
586 compare_heap_area(MC_NO_PROCESS_INDEX, addr_frag1, addr_frag2, snapshot1, snapshot2,
589 if (res_compare != 1)
596 while (i2 <= state->heaplimit && !equal) {
598 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
600 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
605 // We currently do not match fragments with unfragmented blocks (maybe we should).
606 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
611 if (heapinfo2b->type < 0) {
612 fprintf(stderr, "Unkown mmalloc block type.\n");
616 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
619 if (i2 == i1 && j2 == j1)
622 if (state->equals_to2_(i2, j2).valid)
626 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
627 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
629 (void *) ((char *) addr_block2 +
630 (j2 << heapinfo2b->type));
633 compare_heap_area(MC_NO_PROCESS_INDEX, addr_frag1, addr_frag2, snapshot2, snapshot2,
636 if (res_compare != 1) {
649 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
650 i1, j1, heapinfo1->busy_frag.frag_size[j1],
652 i2 = state->heaplimit + 1;
653 i1 = state->heaplimit + 1;
666 /* All blocks/fragments are equal to another block/fragment ? */
669 for(i = 1; i <= state->heaplimit; i++) {
670 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
671 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
672 if (i1 == state->heaplimit) {
673 if (heapinfo1->busy_block.busy_size > 0) {
674 if (state->equals_to1_(i, 0).valid == 0) {
675 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
677 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
678 heapinfo1->busy_block.busy_size);
679 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
686 if (heapinfo1->type > 0) {
687 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
688 if (i1 == state->heaplimit) {
689 if (heapinfo1->busy_frag.frag_size[j] > 0) {
690 if (state->equals_to1_(i, j).valid == 0) {
691 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
692 // TODO, print fragment address
694 ("Block %zu, Fragment %zu not found (size used = %zd)",
696 heapinfo1->busy_frag.frag_size[j]);
697 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
707 if (i1 == state->heaplimit)
708 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
710 for (i=1; i <= state->heaplimit; i++) {
711 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
712 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
713 if (i1 == state->heaplimit) {
714 if (heapinfo2->busy_block.busy_size > 0) {
715 if (state->equals_to2_(i, 0).valid == 0) {
716 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
717 // TODO, print address of the block
718 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
719 heapinfo2->busy_block.busy_size);
720 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
727 if (heapinfo2->type > 0) {
728 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
729 if (i1 == state->heaplimit) {
730 if (heapinfo2->busy_frag.frag_size[j] > 0) {
731 if (state->equals_to2_(i, j).valid == 0) {
732 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
733 // TODO, print address of the block
735 ("Block %zu, Fragment %zu not found (size used = %zd)",
737 heapinfo2->busy_frag.frag_size[j]);
738 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
748 if (i1 == state->heaplimit)
749 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
751 return ((nb_diff1 > 0) || (nb_diff2 > 0));
757 * @param real_area1 Process address for state 1
758 * @param real_area2 Process address for state 2
759 * @param snapshot1 Snapshot of state 1
760 * @param snapshot2 Snapshot of state 2
763 * @param check_ignore
765 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
766 void *real_area1, void *real_area2,
767 mc_snapshot_t snapshot1,
768 mc_snapshot_t snapshot2,
769 xbt_dynar_t previous, int size,
774 void *addr_pointed1, *addr_pointed2;
775 int pointer_align, res_compare;
776 ssize_t ignore1, ignore2;
778 mc_mem_region_t heap_region1 = snapshot1->regions[0];
779 mc_mem_region_t heap_region2 = snapshot2->regions[0];
783 if (check_ignore > 0) {
785 heap_comparison_ignore_size(state->to_ignore1,
786 (char *) real_area1 + i)) != -1) {
788 heap_comparison_ignore_size(state->to_ignore2,
789 (char *) real_area2 + i)) == ignore1) {
802 if (mc_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
804 pointer_align = (i / sizeof(void *)) * sizeof(void *);
805 addr_pointed1 = mc_snapshot_read_pointer((char *) real_area1 + pointer_align, snapshot1, process_index);
806 addr_pointed2 = mc_snapshot_read_pointer((char *) real_area2 + pointer_align, snapshot2, process_index);
808 if (addr_pointed1 > maestro_stack_start
809 && addr_pointed1 < maestro_stack_end
810 && addr_pointed2 > maestro_stack_start
811 && addr_pointed2 < maestro_stack_end) {
812 i = pointer_align + sizeof(void *);
814 } else if (addr_pointed1 > state->s_heap
815 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
816 && addr_pointed2 > state->s_heap
817 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
818 // Both addreses are in the heap:
820 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
821 snapshot2, previous, NULL, 0);
822 if (res_compare == 1) {
825 i = pointer_align + sizeof(void *);
844 * @param real_area1 Process address for state 1
845 * @param real_area2 Process address for state 2
846 * @param snapshot1 Snapshot of state 1
847 * @param snapshot2 Snapshot of state 2
850 * @param area_size either a byte_size or an elements_count (?)
851 * @param check_ignore
852 * @param pointer_level
853 * @return 0 (same), 1 (different), -1 (unknown)
855 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
856 void *real_area1, void *real_area2,
857 mc_snapshot_t snapshot1,
858 mc_snapshot_t snapshot2,
859 xbt_dynar_t previous, dw_type_t type,
860 int area_size, int check_ignore,
864 if (is_stack(real_area1) && is_stack(real_area2))
867 ssize_t ignore1, ignore2;
869 if ((check_ignore > 0)
870 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
872 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
877 dw_type_t subtype, subsubtype;
878 int res, elm_size, i;
879 unsigned int cursor = 0;
881 void *addr_pointed1, *addr_pointed2;;
883 mc_mem_region_t heap_region1 = snapshot1->regions[0];
884 mc_mem_region_t heap_region2 = snapshot2->regions[0];
886 switch (type->type) {
887 case DW_TAG_unspecified_type:
890 case DW_TAG_base_type:
891 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
892 if (real_area1 == real_area2)
895 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
897 if (area_size != -1 && type->byte_size != area_size)
900 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
904 case DW_TAG_enumeration_type:
905 if (area_size != -1 && type->byte_size != area_size)
908 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
911 case DW_TAG_const_type:
912 case DW_TAG_volatile_type:
914 type = type->subtype;
917 case DW_TAG_array_type:
918 subtype = type->subtype;
919 switch (subtype->type) {
920 case DW_TAG_unspecified_type:
923 case DW_TAG_base_type:
924 case DW_TAG_enumeration_type:
925 case DW_TAG_pointer_type:
926 case DW_TAG_reference_type:
927 case DW_TAG_rvalue_reference_type:
928 case DW_TAG_structure_type:
929 case DW_TAG_class_type:
930 case DW_TAG_union_type:
931 if (subtype->full_type)
932 subtype = subtype->full_type;
933 elm_size = subtype->byte_size;
935 // TODO, just remove the type indirection?
936 case DW_TAG_const_type:
938 case DW_TAG_volatile_type:
939 subsubtype = subtype->subtype;
940 if (subsubtype->full_type)
941 subsubtype = subsubtype->full_type;
942 elm_size = subsubtype->byte_size;
948 for (i = 0; i < type->element_count; i++) {
949 // TODO, add support for variable stride (DW_AT_byte_stride)
951 compare_heap_area_with_type(state, process_index,
952 (char *) real_area1 + (i * elm_size),
953 (char *) real_area2 + (i * elm_size),
954 snapshot1, snapshot2, previous,
955 type->subtype, subtype->byte_size,
956 check_ignore, pointer_level);
961 case DW_TAG_reference_type:
962 case DW_TAG_rvalue_reference_type:
963 case DW_TAG_pointer_type:
964 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
965 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
966 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
967 return (addr_pointed1 != addr_pointed2);;
970 if (pointer_level > 1) { /* Array of pointers */
971 for (i = 0; i < (area_size / sizeof(void *)); i++) {
972 addr_pointed1 = mc_snapshot_read_pointer((char*) real_area1 + i * sizeof(void *), snapshot1, process_index);
973 addr_pointed2 = mc_snapshot_read_pointer((char*) real_area2 + i * sizeof(void *), snapshot2, process_index);
974 if (addr_pointed1 > state->s_heap
975 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
976 && addr_pointed2 > state->s_heap
977 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
979 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
980 snapshot2, previous, type->subtype,
983 res = (addr_pointed1 != addr_pointed2);
988 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
989 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
990 if (addr_pointed1 > state->s_heap
991 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
992 && addr_pointed2 > state->s_heap
993 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
994 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
995 snapshot2, previous, type->subtype,
998 return (addr_pointed1 != addr_pointed2);
1002 case DW_TAG_structure_type:
1003 case DW_TAG_class_type:
1004 if (type->full_type)
1005 type = type->full_type;
1006 if (area_size != -1 && type->byte_size != area_size) {
1007 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1008 for (i = 0; i < (area_size / type->byte_size); i++) {
1010 compare_heap_area_with_type(state, process_index,
1011 (char *) real_area1 + i * type->byte_size,
1012 (char *) real_area2 + i * type->byte_size,
1013 snapshot1, snapshot2, previous, type, -1,
1023 xbt_dynar_foreach(type->members, cursor, member) {
1024 // TODO, optimize this? (for the offset case)
1025 char *real_member1 =
1026 mc_member_resolve(real_area1, type, member, snapshot1, process_index);
1027 char *real_member2 =
1028 mc_member_resolve(real_area2, type, member, snapshot2, process_index);
1030 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1031 snapshot1, snapshot2,
1032 previous, member->subtype, -1,
1040 case DW_TAG_union_type:
1041 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1042 snapshot1, snapshot2, previous,
1043 type->byte_size, check_ignore);
1053 /** Infer the type of a part of the block from the type of the block
1055 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1057 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1059 * @param type_id DWARF type ID of the root address
1061 * @return DWARF type ID for given offset
1063 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1064 int offset, int area_size,
1065 mc_snapshot_t snapshot, int process_index)
1068 // Beginning of the block, the infered variable type if the type of the block:
1072 switch (type->type) {
1073 case DW_TAG_structure_type:
1074 case DW_TAG_class_type:
1075 if (type->full_type)
1076 type = type->full_type;
1078 if (area_size != -1 && type->byte_size != area_size) {
1079 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1084 unsigned int cursor = 0;
1086 xbt_dynar_foreach(type->members, cursor, member) {
1088 if (!member->location.size) {
1089 // We have the offset, use it directly (shortcut):
1090 if (member->offset == offset)
1091 return member->subtype;
1094 mc_member_resolve(real_base_address, type, member, snapshot, process_index);
1095 if (real_member - (char *) real_base_address == offset)
1096 return member->subtype;
1104 /* FIXME : other cases ? */
1112 * @param area1 Process address for state 1
1113 * @param area2 Process address for state 2
1114 * @param snapshot1 Snapshot of state 1
1115 * @param snapshot2 Snapshot of state 2
1116 * @param previous Pairs of blocks already compared on the current path (or NULL)
1117 * @param type_id Type of variable
1118 * @param pointer_level
1119 * @return 0 (same), 1 (different), -1
1121 int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t snapshot1,
1122 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1123 dw_type_t type, int pointer_level)
1126 struct s_mc_diff *state = mc_diff_info;
1129 ssize_t block1, frag1, block2, frag2;
1131 int check_ignore = 0;
1133 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1135 int offset1 = 0, offset2 = 0;
1136 int new_size1 = -1, new_size2 = -1;
1137 dw_type_t new_type1 = NULL, new_type2 = NULL;
1139 int match_pairs = 0;
1141 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, process_index);
1142 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, process_index);
1144 malloc_info heapinfo_temp1, heapinfo_temp2;
1146 if (previous == NULL) {
1148 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1151 // Get block number:
1154 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1157 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1159 // If either block is a stack block:
1160 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1161 add_heap_area_pair(previous, block1, -1, block2, -1);
1163 match_equals(state, previous);
1164 xbt_dynar_free(&previous);
1168 // If either block is not in the expected area of memory:
1169 if (((char *) area1 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1170 || (block1 > state->heapsize1) || (block1 < 1)
1171 || ((char *) area2 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1172 || (block2 > state->heapsize2) || (block2 < 1)) {
1174 xbt_dynar_free(&previous);
1179 // Process address of the block:
1181 ((void *) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE +
1182 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1184 ((void *) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE +
1185 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1189 if (type->full_type)
1190 type = type->full_type;
1192 // This assume that for "boring" types (volatile ...) byte_size is absent:
1193 while (type->byte_size == 0 && type->subtype != NULL)
1194 type = type->subtype;
1197 if ((type->type == DW_TAG_pointer_type)
1198 || ((type->type == DW_TAG_base_type) && type->name != NULL
1199 && (!strcmp(type->name, "char"))))
1202 type_size = type->byte_size;
1206 mc_mem_region_t heap_region1 = snapshot1->regions[0];
1207 mc_mem_region_t heap_region2 = snapshot2->regions[0];
1209 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[block1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
1210 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[block2], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
1212 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1213 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1217 match_equals(state, previous);
1218 xbt_dynar_free(&previous);
1222 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1223 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1224 /* Complete block */
1226 // TODO, lookup variable type from block type as done for fragmented blocks
1228 offset1 = (char *) area1 - (char *) real_addr_block1;
1229 offset2 = (char *) area2 - (char *) real_addr_block2;
1231 if (state->equals_to1_(block1, 0).valid
1232 && state->equals_to2_(block2, 0).valid) {
1233 if (equal_blocks(state, block1, block2)) {
1235 match_equals(state, previous);
1236 xbt_dynar_free(&previous);
1242 if (type_size != -1) {
1243 if (type_size != heapinfo1->busy_block.busy_size
1244 && type_size != heapinfo2->busy_block.busy_size
1245 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1247 match_equals(state, previous);
1248 xbt_dynar_free(&previous);
1254 if (heapinfo1->busy_block.size !=
1255 heapinfo2->busy_block.size) {
1257 xbt_dynar_free(&previous);
1262 if (heapinfo1->busy_block.busy_size !=
1263 heapinfo2->busy_block.busy_size) {
1265 xbt_dynar_free(&previous);
1270 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1272 match_equals(state, previous);
1273 xbt_dynar_free(&previous);
1278 size = heapinfo1->busy_block.busy_size;
1280 // Remember (basic) type inference.
1281 // The current data structure only allows us to do this for the whole block.
1282 if (type != NULL && area1 == real_addr_block1) {
1283 state->types1_(block1, 0) = type;
1285 if (type != NULL && area2 == real_addr_block2) {
1286 state->types2_(block2, 0) = type;
1291 match_equals(state, previous);
1292 xbt_dynar_free(&previous);
1300 if ((heapinfo1->busy_block.ignore > 0)
1301 && (heapinfo2->busy_block.ignore ==
1302 heapinfo1->busy_block.ignore))
1303 check_ignore = heapinfo1->busy_block.ignore;
1305 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1309 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1311 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1313 // Process address of the fragment:
1315 (void *) ((char *) real_addr_block1 +
1316 (frag1 << heapinfo1->type));
1318 (void *) ((char *) real_addr_block2 +
1319 (frag2 << heapinfo2->type));
1321 // Check the size of the fragments against the size of the type:
1322 if (type_size != -1) {
1323 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1324 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1326 match_equals(state, previous);
1327 xbt_dynar_free(&previous);
1332 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1333 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1335 match_equals(state, previous);
1336 xbt_dynar_free(&previous);
1342 // Check if the blocks are already matched together:
1343 if (state->equals_to1_(block1, frag1).valid
1344 && state->equals_to2_(block2, frag2).valid) {
1345 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1347 match_equals(state, previous);
1348 xbt_dynar_free(&previous);
1353 // Compare the size of both fragments:
1354 if (heapinfo1->busy_frag.frag_size[frag1] !=
1355 heapinfo2->busy_frag.frag_size[frag2]) {
1356 if (type_size == -1) {
1358 match_equals(state, previous);
1359 xbt_dynar_free(&previous);
1364 xbt_dynar_free(&previous);
1370 // Size of the fragment:
1371 size = heapinfo1->busy_frag.frag_size[frag1];
1373 // Remember (basic) type inference.
1374 // The current data structure only allows us to do this for the whole fragment.
1375 if (type != NULL && area1 == real_addr_frag1) {
1376 state->types1_(block1, frag1) = type;
1378 if (type != NULL && area2 == real_addr_frag2) {
1379 state->types2_(block2, frag2) = type;
1381 // The type of the variable is already known:
1386 // Type inference from the block type.
1387 else if (state->types1_(block1, frag1) != NULL
1388 || state->types2_(block2, frag2) != NULL) {
1390 offset1 = (char *) area1 - (char *) real_addr_frag1;
1391 offset2 = (char *) area2 - (char *) real_addr_frag2;
1393 if (state->types1_(block1, frag1) != NULL
1394 && state->types2_(block2, frag2) != NULL) {
1396 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1397 offset1, size, snapshot1, process_index);
1399 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1400 offset1, size, snapshot2, process_index);
1401 } else if (state->types1_(block1, frag1) != NULL) {
1403 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1404 offset1, size, snapshot1, process_index);
1406 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1407 offset2, size, snapshot2, process_index);
1408 } else if (state->types2_(block2, frag2) != NULL) {
1410 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1411 offset1, size, snapshot1, process_index);
1413 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1414 offset2, size, snapshot2, process_index);
1417 match_equals(state, previous);
1418 xbt_dynar_free(&previous);
1423 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1426 while (type->byte_size == 0 && type->subtype != NULL)
1427 type = type->subtype;
1428 new_size1 = type->byte_size;
1431 while (type->byte_size == 0 && type->subtype != NULL)
1432 type = type->subtype;
1433 new_size2 = type->byte_size;
1437 match_equals(state, previous);
1438 xbt_dynar_free(&previous);
1444 if (new_size1 > 0 && new_size1 == new_size2) {
1449 if (offset1 == 0 && offset2 == 0) {
1450 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1452 match_equals(state, previous);
1453 xbt_dynar_free(&previous);
1461 match_equals(state, previous);
1462 xbt_dynar_free(&previous);
1467 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1468 && (heapinfo2->busy_frag.ignore[frag2] ==
1469 heapinfo1->busy_frag.ignore[frag1]))
1470 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1475 xbt_dynar_free(&previous);
1482 /* Start comparison */
1485 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1486 previous, type, size, check_ignore,
1490 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1491 previous, size, check_ignore);
1493 if (res_compare == 1) {
1495 xbt_dynar_free(&previous);
1500 match_equals(state, previous);
1501 xbt_dynar_free(&previous);
1507 /*********************************************** Miscellaneous ***************************************************/
1508 /****************************************************************************************************************/
1510 // Not used and broken code:
1514 static int get_pointed_area_size(void *area, int heap)
1517 struct s_mc_diff *state = mc_diff_info;
1520 malloc_info *heapinfo;
1523 heapinfo = state->heapinfo1;
1525 heapinfo = state->heapinfo2;
1529 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1531 if (((char *) area < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1532 || (block > state->heapsize1) || (block < 1))
1535 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1537 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1538 return (int) heapinfo[block].busy_block.busy_size;
1541 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1542 return (int) heapinfo[block].busy_frag.frag_size[frag];
1547 char *get_type_description(mc_object_info_t info, char *type_name)
1550 xbt_dict_cursor_t dict_cursor;
1554 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1555 if (type->name && (strcmp(type->name, type_name) == 0)
1556 && type->byte_size > 0) {
1557 xbt_dict_cursor_free(&dict_cursor);
1562 xbt_dict_cursor_free(&dict_cursor);
1568 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1572 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1575 struct s_mc_diff *state = mc_diff_info;
1577 if (heap1 == NULL && heap1 == NULL) {
1578 XBT_DEBUG("Malloc descriptors null");
1582 if (heap1->heaplimit != heap2->heaplimit) {
1583 XBT_DEBUG("Different limit of valid info table indices");
1587 /* Heap information */
1588 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1591 // Mamailloute in order to find the base address of the main heap:
1593 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
1595 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1596 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1599 (malloc_info *) ((char *) heap1 +
1601 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1603 (malloc_info *) ((char *) heap2 +
1605 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1607 state->heapsize1 = heap1->heapsize;
1608 state->heapsize2 = heap2->heapsize;
1610 /* Start comparison */
1612 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1616 /* Check busy blocks */
1620 while (i <= state->heaplimit) {
1623 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1624 (char *) state->heapbase1));
1626 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1627 (char *) state->heapbase2));
1629 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1631 distance += BLOCKSIZE;
1632 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1633 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1638 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1639 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1644 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1646 if (state->heapinfo1[i].busy_block.size !=
1647 state->heapinfo2[i].busy_block.size) {
1649 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1650 state->heapinfo2[i].busy_block.size);
1651 i += max(state->heapinfo1[i].busy_block.size,
1652 state->heapinfo2[i].busy_block.size);
1654 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1655 i, state->heapinfo1[i].busy_block.size,
1656 state->heapinfo2[i].busy_block.size, distance);
1660 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1661 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1662 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1663 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);
1669 //while(k < (heapinfo1[i].busy_block.busy_size)){
1670 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1671 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1680 } else { /* Fragmented block */
1682 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1685 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1687 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1689 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1690 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1695 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1696 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1697 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);
1703 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1704 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1705 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=