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;
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,
772 mc_process_t process = &mc_model_checker->process;
775 void *addr_pointed1, *addr_pointed2;
776 int pointer_align, res_compare;
777 ssize_t ignore1, ignore2;
779 mc_mem_region_t heap_region1 = snapshot1->regions[0];
780 mc_mem_region_t heap_region2 = snapshot2->regions[0];
784 if (check_ignore > 0) {
786 heap_comparison_ignore_size(state->to_ignore1,
787 (char *) real_area1 + i)) != -1) {
789 heap_comparison_ignore_size(state->to_ignore2,
790 (char *) real_area2 + i)) == ignore1) {
803 if (mc_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
805 pointer_align = (i / sizeof(void *)) * sizeof(void *);
806 addr_pointed1 = mc_snapshot_read_pointer((char *) real_area1 + pointer_align, snapshot1, process_index);
807 addr_pointed2 = mc_snapshot_read_pointer((char *) real_area2 + pointer_align, snapshot2, process_index);
809 if (addr_pointed1 > process->maestro_stack_start
810 && addr_pointed1 < process->maestro_stack_end
811 && addr_pointed2 > process->maestro_stack_start
812 && addr_pointed2 < process->maestro_stack_end) {
813 i = pointer_align + sizeof(void *);
815 } else if (addr_pointed1 > state->s_heap
816 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
817 && addr_pointed2 > state->s_heap
818 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
819 // Both addreses are in the heap:
821 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
822 snapshot2, previous, NULL, 0);
823 if (res_compare == 1) {
826 i = pointer_align + sizeof(void *);
845 * @param real_area1 Process address for state 1
846 * @param real_area2 Process address for state 2
847 * @param snapshot1 Snapshot of state 1
848 * @param snapshot2 Snapshot of state 2
851 * @param area_size either a byte_size or an elements_count (?)
852 * @param check_ignore
853 * @param pointer_level
854 * @return 0 (same), 1 (different), -1 (unknown)
856 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
857 void *real_area1, void *real_area2,
858 mc_snapshot_t snapshot1,
859 mc_snapshot_t snapshot2,
860 xbt_dynar_t previous, dw_type_t type,
861 int area_size, int check_ignore,
865 if (is_stack(real_area1) && is_stack(real_area2))
868 ssize_t ignore1, ignore2;
870 if ((check_ignore > 0)
871 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
873 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
878 dw_type_t subtype, subsubtype;
879 int res, elm_size, i;
880 unsigned int cursor = 0;
882 void *addr_pointed1, *addr_pointed2;;
884 mc_mem_region_t heap_region1 = snapshot1->regions[0];
885 mc_mem_region_t heap_region2 = snapshot2->regions[0];
887 switch (type->type) {
888 case DW_TAG_unspecified_type:
891 case DW_TAG_base_type:
892 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
893 if (real_area1 == real_area2)
896 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
898 if (area_size != -1 && type->byte_size != area_size)
901 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
905 case DW_TAG_enumeration_type:
906 if (area_size != -1 && type->byte_size != area_size)
909 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
912 case DW_TAG_const_type:
913 case DW_TAG_volatile_type:
915 type = type->subtype;
918 case DW_TAG_array_type:
919 subtype = type->subtype;
920 switch (subtype->type) {
921 case DW_TAG_unspecified_type:
924 case DW_TAG_base_type:
925 case DW_TAG_enumeration_type:
926 case DW_TAG_pointer_type:
927 case DW_TAG_reference_type:
928 case DW_TAG_rvalue_reference_type:
929 case DW_TAG_structure_type:
930 case DW_TAG_class_type:
931 case DW_TAG_union_type:
932 if (subtype->full_type)
933 subtype = subtype->full_type;
934 elm_size = subtype->byte_size;
936 // TODO, just remove the type indirection?
937 case DW_TAG_const_type:
939 case DW_TAG_volatile_type:
940 subsubtype = subtype->subtype;
941 if (subsubtype->full_type)
942 subsubtype = subsubtype->full_type;
943 elm_size = subsubtype->byte_size;
949 for (i = 0; i < type->element_count; i++) {
950 // TODO, add support for variable stride (DW_AT_byte_stride)
952 compare_heap_area_with_type(state, process_index,
953 (char *) real_area1 + (i * elm_size),
954 (char *) real_area2 + (i * elm_size),
955 snapshot1, snapshot2, previous,
956 type->subtype, subtype->byte_size,
957 check_ignore, pointer_level);
962 case DW_TAG_reference_type:
963 case DW_TAG_rvalue_reference_type:
964 case DW_TAG_pointer_type:
965 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
966 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
967 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
968 return (addr_pointed1 != addr_pointed2);;
971 if (pointer_level > 1) { /* Array of pointers */
972 for (i = 0; i < (area_size / sizeof(void *)); i++) {
973 addr_pointed1 = mc_snapshot_read_pointer((char*) real_area1 + i * sizeof(void *), snapshot1, process_index);
974 addr_pointed2 = mc_snapshot_read_pointer((char*) real_area2 + i * sizeof(void *), snapshot2, process_index);
975 if (addr_pointed1 > state->s_heap
976 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
977 && addr_pointed2 > state->s_heap
978 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
980 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
981 snapshot2, previous, type->subtype,
984 res = (addr_pointed1 != addr_pointed2);
989 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
990 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
991 if (addr_pointed1 > state->s_heap
992 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
993 && addr_pointed2 > state->s_heap
994 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
995 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
996 snapshot2, previous, type->subtype,
999 return (addr_pointed1 != addr_pointed2);
1003 case DW_TAG_structure_type:
1004 case DW_TAG_class_type:
1005 if (type->full_type)
1006 type = type->full_type;
1007 if (area_size != -1 && type->byte_size != area_size) {
1008 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1009 for (i = 0; i < (area_size / type->byte_size); i++) {
1011 compare_heap_area_with_type(state, process_index,
1012 (char *) real_area1 + i * type->byte_size,
1013 (char *) real_area2 + i * type->byte_size,
1014 snapshot1, snapshot2, previous, type, -1,
1024 xbt_dynar_foreach(type->members, cursor, member) {
1025 // TODO, optimize this? (for the offset case)
1026 char *real_member1 =
1027 mc_member_resolve(real_area1, type, member, snapshot1, process_index);
1028 char *real_member2 =
1029 mc_member_resolve(real_area2, type, member, snapshot2, process_index);
1031 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1032 snapshot1, snapshot2,
1033 previous, member->subtype, -1,
1041 case DW_TAG_union_type:
1042 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1043 snapshot1, snapshot2, previous,
1044 type->byte_size, check_ignore);
1054 /** Infer the type of a part of the block from the type of the block
1056 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1058 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1060 * @param type_id DWARF type ID of the root address
1062 * @return DWARF type ID for given offset
1064 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1065 int offset, int area_size,
1066 mc_snapshot_t snapshot, int process_index)
1069 // Beginning of the block, the infered variable type if the type of the block:
1073 switch (type->type) {
1074 case DW_TAG_structure_type:
1075 case DW_TAG_class_type:
1076 if (type->full_type)
1077 type = type->full_type;
1079 if (area_size != -1 && type->byte_size != area_size) {
1080 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1085 unsigned int cursor = 0;
1087 xbt_dynar_foreach(type->members, cursor, member) {
1089 if (!member->location.size) {
1090 // We have the offset, use it directly (shortcut):
1091 if (member->offset == offset)
1092 return member->subtype;
1095 mc_member_resolve(real_base_address, type, member, snapshot, process_index);
1096 if (real_member - (char *) real_base_address == offset)
1097 return member->subtype;
1105 /* FIXME : other cases ? */
1113 * @param area1 Process address for state 1
1114 * @param area2 Process address for state 2
1115 * @param snapshot1 Snapshot of state 1
1116 * @param snapshot2 Snapshot of state 2
1117 * @param previous Pairs of blocks already compared on the current path (or NULL)
1118 * @param type_id Type of variable
1119 * @param pointer_level
1120 * @return 0 (same), 1 (different), -1
1122 int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t snapshot1,
1123 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1124 dw_type_t type, int pointer_level)
1127 struct s_mc_diff *state = mc_diff_info;
1130 ssize_t block1, frag1, block2, frag2;
1132 int check_ignore = 0;
1134 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1136 int offset1 = 0, offset2 = 0;
1137 int new_size1 = -1, new_size2 = -1;
1138 dw_type_t new_type1 = NULL, new_type2 = NULL;
1140 int match_pairs = 0;
1142 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, process_index);
1143 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, process_index);
1145 malloc_info heapinfo_temp1, heapinfo_temp2;
1147 if (previous == NULL) {
1149 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1152 // Get block number:
1155 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1158 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1160 // If either block is a stack block:
1161 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1162 add_heap_area_pair(previous, block1, -1, block2, -1);
1164 match_equals(state, previous);
1165 xbt_dynar_free(&previous);
1169 // If either block is not in the expected area of memory:
1170 if (((char *) area1 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1171 || (block1 > state->heapsize1) || (block1 < 1)
1172 || ((char *) area2 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1173 || (block2 > state->heapsize2) || (block2 < 1)) {
1175 xbt_dynar_free(&previous);
1180 // Process address of the block:
1182 ((void *) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE +
1183 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1185 ((void *) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE +
1186 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1190 if (type->full_type)
1191 type = type->full_type;
1193 // This assume that for "boring" types (volatile ...) byte_size is absent:
1194 while (type->byte_size == 0 && type->subtype != NULL)
1195 type = type->subtype;
1198 if ((type->type == DW_TAG_pointer_type)
1199 || ((type->type == DW_TAG_base_type) && type->name != NULL
1200 && (!strcmp(type->name, "char"))))
1203 type_size = type->byte_size;
1207 mc_mem_region_t heap_region1 = snapshot1->regions[0];
1208 mc_mem_region_t heap_region2 = snapshot2->regions[0];
1210 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[block1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
1211 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[block2], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
1213 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1214 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1218 match_equals(state, previous);
1219 xbt_dynar_free(&previous);
1223 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1224 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1225 /* Complete block */
1227 // TODO, lookup variable type from block type as done for fragmented blocks
1229 offset1 = (char *) area1 - (char *) real_addr_block1;
1230 offset2 = (char *) area2 - (char *) real_addr_block2;
1232 if (state->equals_to1_(block1, 0).valid
1233 && state->equals_to2_(block2, 0).valid) {
1234 if (equal_blocks(state, block1, block2)) {
1236 match_equals(state, previous);
1237 xbt_dynar_free(&previous);
1243 if (type_size != -1) {
1244 if (type_size != heapinfo1->busy_block.busy_size
1245 && type_size != heapinfo2->busy_block.busy_size
1246 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1248 match_equals(state, previous);
1249 xbt_dynar_free(&previous);
1255 if (heapinfo1->busy_block.size !=
1256 heapinfo2->busy_block.size) {
1258 xbt_dynar_free(&previous);
1263 if (heapinfo1->busy_block.busy_size !=
1264 heapinfo2->busy_block.busy_size) {
1266 xbt_dynar_free(&previous);
1271 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1273 match_equals(state, previous);
1274 xbt_dynar_free(&previous);
1279 size = heapinfo1->busy_block.busy_size;
1281 // Remember (basic) type inference.
1282 // The current data structure only allows us to do this for the whole block.
1283 if (type != NULL && area1 == real_addr_block1) {
1284 state->types1_(block1, 0) = type;
1286 if (type != NULL && area2 == real_addr_block2) {
1287 state->types2_(block2, 0) = type;
1292 match_equals(state, previous);
1293 xbt_dynar_free(&previous);
1301 if ((heapinfo1->busy_block.ignore > 0)
1302 && (heapinfo2->busy_block.ignore ==
1303 heapinfo1->busy_block.ignore))
1304 check_ignore = heapinfo1->busy_block.ignore;
1306 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1310 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1312 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1314 // Process address of the fragment:
1316 (void *) ((char *) real_addr_block1 +
1317 (frag1 << heapinfo1->type));
1319 (void *) ((char *) real_addr_block2 +
1320 (frag2 << heapinfo2->type));
1322 // Check the size of the fragments against the size of the type:
1323 if (type_size != -1) {
1324 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1325 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1327 match_equals(state, previous);
1328 xbt_dynar_free(&previous);
1333 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1334 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1336 match_equals(state, previous);
1337 xbt_dynar_free(&previous);
1343 // Check if the blocks are already matched together:
1344 if (state->equals_to1_(block1, frag1).valid
1345 && state->equals_to2_(block2, frag2).valid) {
1346 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1348 match_equals(state, previous);
1349 xbt_dynar_free(&previous);
1354 // Compare the size of both fragments:
1355 if (heapinfo1->busy_frag.frag_size[frag1] !=
1356 heapinfo2->busy_frag.frag_size[frag2]) {
1357 if (type_size == -1) {
1359 match_equals(state, previous);
1360 xbt_dynar_free(&previous);
1365 xbt_dynar_free(&previous);
1371 // Size of the fragment:
1372 size = heapinfo1->busy_frag.frag_size[frag1];
1374 // Remember (basic) type inference.
1375 // The current data structure only allows us to do this for the whole fragment.
1376 if (type != NULL && area1 == real_addr_frag1) {
1377 state->types1_(block1, frag1) = type;
1379 if (type != NULL && area2 == real_addr_frag2) {
1380 state->types2_(block2, frag2) = type;
1382 // The type of the variable is already known:
1387 // Type inference from the block type.
1388 else if (state->types1_(block1, frag1) != NULL
1389 || state->types2_(block2, frag2) != NULL) {
1391 offset1 = (char *) area1 - (char *) real_addr_frag1;
1392 offset2 = (char *) area2 - (char *) real_addr_frag2;
1394 if (state->types1_(block1, frag1) != NULL
1395 && state->types2_(block2, frag2) != NULL) {
1397 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1398 offset1, size, snapshot1, process_index);
1400 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1401 offset1, size, snapshot2, process_index);
1402 } else if (state->types1_(block1, frag1) != NULL) {
1404 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1405 offset1, size, snapshot1, process_index);
1407 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1408 offset2, size, snapshot2, process_index);
1409 } else if (state->types2_(block2, frag2) != NULL) {
1411 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1412 offset1, size, snapshot1, process_index);
1414 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1415 offset2, size, snapshot2, process_index);
1418 match_equals(state, previous);
1419 xbt_dynar_free(&previous);
1424 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1427 while (type->byte_size == 0 && type->subtype != NULL)
1428 type = type->subtype;
1429 new_size1 = type->byte_size;
1432 while (type->byte_size == 0 && type->subtype != NULL)
1433 type = type->subtype;
1434 new_size2 = type->byte_size;
1438 match_equals(state, previous);
1439 xbt_dynar_free(&previous);
1445 if (new_size1 > 0 && new_size1 == new_size2) {
1450 if (offset1 == 0 && offset2 == 0) {
1451 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1453 match_equals(state, previous);
1454 xbt_dynar_free(&previous);
1462 match_equals(state, previous);
1463 xbt_dynar_free(&previous);
1468 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1469 && (heapinfo2->busy_frag.ignore[frag2] ==
1470 heapinfo1->busy_frag.ignore[frag1]))
1471 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1476 xbt_dynar_free(&previous);
1483 /* Start comparison */
1486 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1487 previous, type, size, check_ignore,
1491 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1492 previous, size, check_ignore);
1494 if (res_compare == 1) {
1496 xbt_dynar_free(&previous);
1501 match_equals(state, previous);
1502 xbt_dynar_free(&previous);
1508 /*********************************************** Miscellaneous ***************************************************/
1509 /****************************************************************************************************************/
1511 // Not used and broken code:
1515 static int get_pointed_area_size(void *area, int heap)
1518 struct s_mc_diff *state = mc_diff_info;
1521 malloc_info *heapinfo;
1524 heapinfo = state->heapinfo1;
1526 heapinfo = state->heapinfo2;
1530 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1532 if (((char *) area < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1533 || (block > state->heapsize1) || (block < 1))
1536 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1538 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1539 return (int) heapinfo[block].busy_block.busy_size;
1542 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1543 return (int) heapinfo[block].busy_frag.frag_size[frag];
1548 char *get_type_description(mc_object_info_t info, char *type_name)
1551 xbt_dict_cursor_t dict_cursor;
1555 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1556 if (type->name && (strcmp(type->name, type_name) == 0)
1557 && type->byte_size > 0) {
1558 xbt_dict_cursor_free(&dict_cursor);
1563 xbt_dict_cursor_free(&dict_cursor);
1569 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1573 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1576 struct s_mc_diff *state = mc_diff_info;
1578 if (heap1 == NULL && heap1 == NULL) {
1579 XBT_DEBUG("Malloc descriptors null");
1583 if (heap1->heaplimit != heap2->heaplimit) {
1584 XBT_DEBUG("Different limit of valid info table indices");
1588 /* Heap information */
1589 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1592 // Mamailloute in order to find the base address of the main heap:
1594 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
1596 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1597 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1600 (malloc_info *) ((char *) heap1 +
1602 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1604 (malloc_info *) ((char *) heap2 +
1606 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1608 state->heapsize1 = heap1->heapsize;
1609 state->heapsize2 = heap2->heapsize;
1611 /* Start comparison */
1613 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1617 /* Check busy blocks */
1621 while (i <= state->heaplimit) {
1624 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1625 (char *) state->heapbase1));
1627 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1628 (char *) state->heapbase2));
1630 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1632 distance += BLOCKSIZE;
1633 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1634 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1639 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1640 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1645 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1647 if (state->heapinfo1[i].busy_block.size !=
1648 state->heapinfo2[i].busy_block.size) {
1650 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1651 state->heapinfo2[i].busy_block.size);
1652 i += max(state->heapinfo1[i].busy_block.size,
1653 state->heapinfo2[i].busy_block.size);
1655 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1656 i, state->heapinfo1[i].busy_block.size,
1657 state->heapinfo2[i].busy_block.size, distance);
1661 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1662 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1663 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1664 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);
1670 //while(k < (heapinfo1[i].busy_block.busy_size)){
1671 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1672 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1681 } else { /* Fragmented block */
1683 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1686 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1688 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1690 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1691 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1696 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1697 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1698 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);
1704 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1705 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1706 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=