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 // TODO, have a robust way to find it in O(1)
420 mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
422 size_t n = snapshot->snapshot_regions_count;
423 for (size_t i=0; i!=n; ++i) {
424 mc_mem_region_t region = snapshot->snapshot_regions[i];
425 if (region->region_type == MC_REGION_TYPE_HEAP)
428 xbt_die("No heap region");
431 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
433 struct s_mc_diff *state = mc_diff_info;
435 /* Start comparison */
436 size_t i1, i2, j1, j2, k;
437 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
438 int nb_diff1 = 0, nb_diff2 = 0;
440 int equal, res_compare = 0;
442 /* Check busy blocks */
446 malloc_info heapinfo_temp1, heapinfo_temp2;
447 malloc_info heapinfo_temp2b;
449 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
450 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
452 // This is in snapshot do not use them directly:
453 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, MC_NO_PROCESS_INDEX);
454 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, MC_NO_PROCESS_INDEX);
456 while (i1 <= state->heaplimit) {
458 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
459 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i1], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
461 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
466 if (heapinfo1->type < 0) {
467 fprintf(stderr, "Unkown mmalloc block type.\n");
472 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
473 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
475 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
477 if (is_stack(addr_block1)) {
478 for (k = 0; k < heapinfo1->busy_block.size; k++)
479 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
480 for (k = 0; k < heapinfo2->busy_block.size; k++)
481 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
482 i1 += heapinfo1->busy_block.size;
486 if (state->equals_to1_(i1, 0).valid) {
495 /* Try first to associate to same block in the other heap */
496 if (heapinfo2->type == heapinfo1->type) {
498 if (state->equals_to2_(i1, 0).valid == 0) {
501 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
502 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
505 compare_heap_area(MC_NO_PROCESS_INDEX, addr_block1, addr_block2, snapshot1, snapshot2,
508 if (res_compare != 1) {
509 for (k = 1; k < heapinfo2->busy_block.size; k++)
510 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
511 for (k = 1; k < heapinfo1->busy_block.size; k++)
512 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
514 i1 += heapinfo1->busy_block.size;
521 while (i2 <= state->heaplimit && !equal) {
524 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
525 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
532 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
534 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
539 if (state->equals_to2_(i2, 0).valid) {
545 compare_heap_area(MC_NO_PROCESS_INDEX, addr_block1, addr_block2, snapshot1, snapshot2,
548 if (res_compare != 1) {
549 for (k = 1; k < heapinfo2b->busy_block.size; k++)
550 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
551 for (k = 1; k < heapinfo1->busy_block.size; k++)
552 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
554 i1 += heapinfo1->busy_block.size;
562 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
563 heapinfo1->busy_block.busy_size, addr_block1);
564 i1 = state->heaplimit + 1;
569 } else { /* Fragmented block */
571 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
573 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
576 if (state->equals_to1_(i1, j1).valid)
580 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
585 /* Try first to associate to same fragment in the other heap */
586 if (heapinfo2->type == heapinfo1->type) {
588 if (state->equals_to2_(i1, j1).valid == 0) {
591 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
592 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
594 (void *) ((char *) addr_block2 +
595 (j1 << heapinfo2->type));
598 compare_heap_area(MC_NO_PROCESS_INDEX, addr_frag1, addr_frag2, snapshot1, snapshot2,
601 if (res_compare != 1)
608 while (i2 <= state->heaplimit && !equal) {
610 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
612 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
617 // We currently do not match fragments with unfragmented blocks (maybe we should).
618 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
623 if (heapinfo2b->type < 0) {
624 fprintf(stderr, "Unkown mmalloc block type.\n");
628 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
631 if (i2 == i1 && j2 == j1)
634 if (state->equals_to2_(i2, j2).valid)
638 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
639 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
641 (void *) ((char *) addr_block2 +
642 (j2 << heapinfo2b->type));
645 compare_heap_area(MC_NO_PROCESS_INDEX, addr_frag1, addr_frag2, snapshot2, snapshot2,
648 if (res_compare != 1) {
661 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
662 i1, j1, heapinfo1->busy_frag.frag_size[j1],
664 i2 = state->heaplimit + 1;
665 i1 = state->heaplimit + 1;
678 /* All blocks/fragments are equal to another block/fragment ? */
681 for(i = 1; i <= state->heaplimit; i++) {
682 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
683 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
684 if (i1 == state->heaplimit) {
685 if (heapinfo1->busy_block.busy_size > 0) {
686 if (state->equals_to1_(i, 0).valid == 0) {
687 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
689 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
690 heapinfo1->busy_block.busy_size);
691 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
698 if (heapinfo1->type > 0) {
699 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
700 if (i1 == state->heaplimit) {
701 if (heapinfo1->busy_frag.frag_size[j] > 0) {
702 if (state->equals_to1_(i, j).valid == 0) {
703 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
704 // TODO, print fragment address
706 ("Block %zu, Fragment %zu not found (size used = %zd)",
708 heapinfo1->busy_frag.frag_size[j]);
709 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
719 if (i1 == state->heaplimit)
720 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
722 for (i=1; i <= state->heaplimit; i++) {
723 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
724 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
725 if (i1 == state->heaplimit) {
726 if (heapinfo2->busy_block.busy_size > 0) {
727 if (state->equals_to2_(i, 0).valid == 0) {
728 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
729 // TODO, print address of the block
730 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
731 heapinfo2->busy_block.busy_size);
732 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
739 if (heapinfo2->type > 0) {
740 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
741 if (i1 == state->heaplimit) {
742 if (heapinfo2->busy_frag.frag_size[j] > 0) {
743 if (state->equals_to2_(i, j).valid == 0) {
744 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
745 // TODO, print address of the block
747 ("Block %zu, Fragment %zu not found (size used = %zd)",
749 heapinfo2->busy_frag.frag_size[j]);
750 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
760 if (i1 == state->heaplimit)
761 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
763 return ((nb_diff1 > 0) || (nb_diff2 > 0));
769 * @param real_area1 Process address for state 1
770 * @param real_area2 Process address for state 2
771 * @param snapshot1 Snapshot of state 1
772 * @param snapshot2 Snapshot of state 2
775 * @param check_ignore
777 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
778 void *real_area1, void *real_area2,
779 mc_snapshot_t snapshot1,
780 mc_snapshot_t snapshot2,
781 xbt_dynar_t previous, int size,
784 mc_process_t process = &mc_model_checker->process;
787 void *addr_pointed1, *addr_pointed2;
788 int pointer_align, res_compare;
789 ssize_t ignore1, ignore2;
791 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
792 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
796 if (check_ignore > 0) {
798 heap_comparison_ignore_size(state->to_ignore1,
799 (char *) real_area1 + i)) != -1) {
801 heap_comparison_ignore_size(state->to_ignore2,
802 (char *) real_area2 + i)) == ignore1) {
815 if (mc_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
817 pointer_align = (i / sizeof(void *)) * sizeof(void *);
818 addr_pointed1 = mc_snapshot_read_pointer((char *) real_area1 + pointer_align, snapshot1, process_index);
819 addr_pointed2 = mc_snapshot_read_pointer((char *) real_area2 + pointer_align, snapshot2, process_index);
821 if (addr_pointed1 > process->maestro_stack_start
822 && addr_pointed1 < process->maestro_stack_end
823 && addr_pointed2 > process->maestro_stack_start
824 && addr_pointed2 < process->maestro_stack_end) {
825 i = pointer_align + sizeof(void *);
827 } else if (addr_pointed1 > state->s_heap
828 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
829 && addr_pointed2 > state->s_heap
830 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
831 // Both addreses are in the heap:
833 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
834 snapshot2, previous, NULL, 0);
835 if (res_compare == 1) {
838 i = pointer_align + sizeof(void *);
857 * @param real_area1 Process address for state 1
858 * @param real_area2 Process address for state 2
859 * @param snapshot1 Snapshot of state 1
860 * @param snapshot2 Snapshot of state 2
863 * @param area_size either a byte_size or an elements_count (?)
864 * @param check_ignore
865 * @param pointer_level
866 * @return 0 (same), 1 (different), -1 (unknown)
868 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
869 void *real_area1, void *real_area2,
870 mc_snapshot_t snapshot1,
871 mc_snapshot_t snapshot2,
872 xbt_dynar_t previous, dw_type_t type,
873 int area_size, int check_ignore,
877 if (is_stack(real_area1) && is_stack(real_area2))
880 ssize_t ignore1, ignore2;
882 if ((check_ignore > 0)
883 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
885 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
890 dw_type_t subtype, subsubtype;
891 int res, elm_size, i;
892 unsigned int cursor = 0;
894 void *addr_pointed1, *addr_pointed2;;
896 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
897 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
899 switch (type->type) {
900 case DW_TAG_unspecified_type:
903 case DW_TAG_base_type:
904 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
905 if (real_area1 == real_area2)
908 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
910 if (area_size != -1 && type->byte_size != area_size)
913 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
917 case DW_TAG_enumeration_type:
918 if (area_size != -1 && type->byte_size != area_size)
921 return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
924 case DW_TAG_const_type:
925 case DW_TAG_volatile_type:
927 type = type->subtype;
930 case DW_TAG_array_type:
931 subtype = type->subtype;
932 switch (subtype->type) {
933 case DW_TAG_unspecified_type:
936 case DW_TAG_base_type:
937 case DW_TAG_enumeration_type:
938 case DW_TAG_pointer_type:
939 case DW_TAG_reference_type:
940 case DW_TAG_rvalue_reference_type:
941 case DW_TAG_structure_type:
942 case DW_TAG_class_type:
943 case DW_TAG_union_type:
944 if (subtype->full_type)
945 subtype = subtype->full_type;
946 elm_size = subtype->byte_size;
948 // TODO, just remove the type indirection?
949 case DW_TAG_const_type:
951 case DW_TAG_volatile_type:
952 subsubtype = subtype->subtype;
953 if (subsubtype->full_type)
954 subsubtype = subsubtype->full_type;
955 elm_size = subsubtype->byte_size;
961 for (i = 0; i < type->element_count; i++) {
962 // TODO, add support for variable stride (DW_AT_byte_stride)
964 compare_heap_area_with_type(state, process_index,
965 (char *) real_area1 + (i * elm_size),
966 (char *) real_area2 + (i * elm_size),
967 snapshot1, snapshot2, previous,
968 type->subtype, subtype->byte_size,
969 check_ignore, pointer_level);
974 case DW_TAG_reference_type:
975 case DW_TAG_rvalue_reference_type:
976 case DW_TAG_pointer_type:
977 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
978 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
979 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
980 return (addr_pointed1 != addr_pointed2);;
983 if (pointer_level > 1) { /* Array of pointers */
984 for (i = 0; i < (area_size / sizeof(void *)); i++) {
985 addr_pointed1 = mc_snapshot_read_pointer((char*) real_area1 + i * sizeof(void *), snapshot1, process_index);
986 addr_pointed2 = mc_snapshot_read_pointer((char*) real_area2 + i * sizeof(void *), snapshot2, process_index);
987 if (addr_pointed1 > state->s_heap
988 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
989 && addr_pointed2 > state->s_heap
990 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
992 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
993 snapshot2, previous, type->subtype,
996 res = (addr_pointed1 != addr_pointed2);
1001 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
1002 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
1003 if (addr_pointed1 > state->s_heap
1004 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
1005 && addr_pointed2 > state->s_heap
1006 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1007 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1008 snapshot2, previous, type->subtype,
1011 return (addr_pointed1 != addr_pointed2);
1015 case DW_TAG_structure_type:
1016 case DW_TAG_class_type:
1017 if (type->full_type)
1018 type = type->full_type;
1019 if (area_size != -1 && type->byte_size != area_size) {
1020 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1021 for (i = 0; i < (area_size / type->byte_size); i++) {
1023 compare_heap_area_with_type(state, process_index,
1024 (char *) real_area1 + i * type->byte_size,
1025 (char *) real_area2 + i * type->byte_size,
1026 snapshot1, snapshot2, previous, type, -1,
1036 xbt_dynar_foreach(type->members, cursor, member) {
1037 // TODO, optimize this? (for the offset case)
1038 char *real_member1 =
1039 mc_member_resolve(real_area1, type, member, snapshot1, process_index);
1040 char *real_member2 =
1041 mc_member_resolve(real_area2, type, member, snapshot2, process_index);
1043 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1044 snapshot1, snapshot2,
1045 previous, member->subtype, -1,
1053 case DW_TAG_union_type:
1054 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1055 snapshot1, snapshot2, previous,
1056 type->byte_size, check_ignore);
1066 /** Infer the type of a part of the block from the type of the block
1068 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1070 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1072 * @param type_id DWARF type ID of the root address
1074 * @return DWARF type ID for given offset
1076 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1077 int offset, int area_size,
1078 mc_snapshot_t snapshot, int process_index)
1081 // Beginning of the block, the infered variable type if the type of the block:
1085 switch (type->type) {
1086 case DW_TAG_structure_type:
1087 case DW_TAG_class_type:
1088 if (type->full_type)
1089 type = type->full_type;
1091 if (area_size != -1 && type->byte_size != area_size) {
1092 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1097 unsigned int cursor = 0;
1099 xbt_dynar_foreach(type->members, cursor, member) {
1101 if (!member->location.size) {
1102 // We have the offset, use it directly (shortcut):
1103 if (member->offset == offset)
1104 return member->subtype;
1107 mc_member_resolve(real_base_address, type, member, snapshot, process_index);
1108 if (real_member - (char *) real_base_address == offset)
1109 return member->subtype;
1117 /* FIXME : other cases ? */
1125 * @param area1 Process address for state 1
1126 * @param area2 Process address for state 2
1127 * @param snapshot1 Snapshot of state 1
1128 * @param snapshot2 Snapshot of state 2
1129 * @param previous Pairs of blocks already compared on the current path (or NULL)
1130 * @param type_id Type of variable
1131 * @param pointer_level
1132 * @return 0 (same), 1 (different), -1
1134 int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t snapshot1,
1135 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1136 dw_type_t type, int pointer_level)
1139 struct s_mc_diff *state = mc_diff_info;
1142 ssize_t block1, frag1, block2, frag2;
1144 int check_ignore = 0;
1146 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1148 int offset1 = 0, offset2 = 0;
1149 int new_size1 = -1, new_size2 = -1;
1150 dw_type_t new_type1 = NULL, new_type2 = NULL;
1152 int match_pairs = 0;
1154 malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, process_index);
1155 malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, process_index);
1157 malloc_info heapinfo_temp1, heapinfo_temp2;
1159 if (previous == NULL) {
1161 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1164 // Get block number:
1167 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1170 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1172 // If either block is a stack block:
1173 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1174 add_heap_area_pair(previous, block1, -1, block2, -1);
1176 match_equals(state, previous);
1177 xbt_dynar_free(&previous);
1181 // If either block is not in the expected area of memory:
1182 if (((char *) area1 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1183 || (block1 > state->heapsize1) || (block1 < 1)
1184 || ((char *) area2 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1185 || (block2 > state->heapsize2) || (block2 < 1)) {
1187 xbt_dynar_free(&previous);
1192 // Process address of the block:
1194 ((void *) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE +
1195 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1197 ((void *) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE +
1198 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1202 if (type->full_type)
1203 type = type->full_type;
1205 // This assume that for "boring" types (volatile ...) byte_size is absent:
1206 while (type->byte_size == 0 && type->subtype != NULL)
1207 type = type->subtype;
1210 if ((type->type == DW_TAG_pointer_type)
1211 || ((type->type == DW_TAG_base_type) && type->name != NULL
1212 && (!strcmp(type->name, "char"))))
1215 type_size = type->byte_size;
1219 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1220 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1222 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[block1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
1223 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[block2], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
1225 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1226 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1230 match_equals(state, previous);
1231 xbt_dynar_free(&previous);
1235 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1236 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1237 /* Complete block */
1239 // TODO, lookup variable type from block type as done for fragmented blocks
1241 offset1 = (char *) area1 - (char *) real_addr_block1;
1242 offset2 = (char *) area2 - (char *) real_addr_block2;
1244 if (state->equals_to1_(block1, 0).valid
1245 && state->equals_to2_(block2, 0).valid) {
1246 if (equal_blocks(state, block1, block2)) {
1248 match_equals(state, previous);
1249 xbt_dynar_free(&previous);
1255 if (type_size != -1) {
1256 if (type_size != heapinfo1->busy_block.busy_size
1257 && type_size != heapinfo2->busy_block.busy_size
1258 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1260 match_equals(state, previous);
1261 xbt_dynar_free(&previous);
1267 if (heapinfo1->busy_block.size !=
1268 heapinfo2->busy_block.size) {
1270 xbt_dynar_free(&previous);
1275 if (heapinfo1->busy_block.busy_size !=
1276 heapinfo2->busy_block.busy_size) {
1278 xbt_dynar_free(&previous);
1283 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1285 match_equals(state, previous);
1286 xbt_dynar_free(&previous);
1291 size = heapinfo1->busy_block.busy_size;
1293 // Remember (basic) type inference.
1294 // The current data structure only allows us to do this for the whole block.
1295 if (type != NULL && area1 == real_addr_block1) {
1296 state->types1_(block1, 0) = type;
1298 if (type != NULL && area2 == real_addr_block2) {
1299 state->types2_(block2, 0) = type;
1304 match_equals(state, previous);
1305 xbt_dynar_free(&previous);
1313 if ((heapinfo1->busy_block.ignore > 0)
1314 && (heapinfo2->busy_block.ignore ==
1315 heapinfo1->busy_block.ignore))
1316 check_ignore = heapinfo1->busy_block.ignore;
1318 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1322 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1324 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1326 // Process address of the fragment:
1328 (void *) ((char *) real_addr_block1 +
1329 (frag1 << heapinfo1->type));
1331 (void *) ((char *) real_addr_block2 +
1332 (frag2 << heapinfo2->type));
1334 // Check the size of the fragments against the size of the type:
1335 if (type_size != -1) {
1336 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1337 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1339 match_equals(state, previous);
1340 xbt_dynar_free(&previous);
1345 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1346 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1348 match_equals(state, previous);
1349 xbt_dynar_free(&previous);
1355 // Check if the blocks are already matched together:
1356 if (state->equals_to1_(block1, frag1).valid
1357 && state->equals_to2_(block2, frag2).valid) {
1358 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1360 match_equals(state, previous);
1361 xbt_dynar_free(&previous);
1366 // Compare the size of both fragments:
1367 if (heapinfo1->busy_frag.frag_size[frag1] !=
1368 heapinfo2->busy_frag.frag_size[frag2]) {
1369 if (type_size == -1) {
1371 match_equals(state, previous);
1372 xbt_dynar_free(&previous);
1377 xbt_dynar_free(&previous);
1383 // Size of the fragment:
1384 size = heapinfo1->busy_frag.frag_size[frag1];
1386 // Remember (basic) type inference.
1387 // The current data structure only allows us to do this for the whole fragment.
1388 if (type != NULL && area1 == real_addr_frag1) {
1389 state->types1_(block1, frag1) = type;
1391 if (type != NULL && area2 == real_addr_frag2) {
1392 state->types2_(block2, frag2) = type;
1394 // The type of the variable is already known:
1399 // Type inference from the block type.
1400 else if (state->types1_(block1, frag1) != NULL
1401 || state->types2_(block2, frag2) != NULL) {
1403 offset1 = (char *) area1 - (char *) real_addr_frag1;
1404 offset2 = (char *) area2 - (char *) real_addr_frag2;
1406 if (state->types1_(block1, frag1) != NULL
1407 && state->types2_(block2, frag2) != NULL) {
1409 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1410 offset1, size, snapshot1, process_index);
1412 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1413 offset1, size, snapshot2, process_index);
1414 } else if (state->types1_(block1, frag1) != NULL) {
1416 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1417 offset1, size, snapshot1, process_index);
1419 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1420 offset2, size, snapshot2, process_index);
1421 } else if (state->types2_(block2, frag2) != NULL) {
1423 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1424 offset1, size, snapshot1, process_index);
1426 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1427 offset2, size, snapshot2, process_index);
1430 match_equals(state, previous);
1431 xbt_dynar_free(&previous);
1436 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1439 while (type->byte_size == 0 && type->subtype != NULL)
1440 type = type->subtype;
1441 new_size1 = type->byte_size;
1444 while (type->byte_size == 0 && type->subtype != NULL)
1445 type = type->subtype;
1446 new_size2 = type->byte_size;
1450 match_equals(state, previous);
1451 xbt_dynar_free(&previous);
1457 if (new_size1 > 0 && new_size1 == new_size2) {
1462 if (offset1 == 0 && offset2 == 0) {
1463 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1465 match_equals(state, previous);
1466 xbt_dynar_free(&previous);
1474 match_equals(state, previous);
1475 xbt_dynar_free(&previous);
1480 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1481 && (heapinfo2->busy_frag.ignore[frag2] ==
1482 heapinfo1->busy_frag.ignore[frag1]))
1483 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1488 xbt_dynar_free(&previous);
1495 /* Start comparison */
1498 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1499 previous, type, size, check_ignore,
1503 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1504 previous, size, check_ignore);
1506 if (res_compare == 1) {
1508 xbt_dynar_free(&previous);
1513 match_equals(state, previous);
1514 xbt_dynar_free(&previous);
1520 /*********************************************** Miscellaneous ***************************************************/
1521 /****************************************************************************************************************/
1523 // Not used and broken code:
1527 static int get_pointed_area_size(void *area, int heap)
1530 struct s_mc_diff *state = mc_diff_info;
1533 malloc_info *heapinfo;
1536 heapinfo = state->heapinfo1;
1538 heapinfo = state->heapinfo2;
1542 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1544 if (((char *) area < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1545 || (block > state->heapsize1) || (block < 1))
1548 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1550 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1551 return (int) heapinfo[block].busy_block.busy_size;
1554 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1555 return (int) heapinfo[block].busy_frag.frag_size[frag];
1560 char *get_type_description(mc_object_info_t info, char *type_name)
1563 xbt_dict_cursor_t dict_cursor;
1567 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1568 if (type->name && (strcmp(type->name, type_name) == 0)
1569 && type->byte_size > 0) {
1570 xbt_dict_cursor_free(&dict_cursor);
1575 xbt_dict_cursor_free(&dict_cursor);
1581 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1585 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1588 struct s_mc_diff *state = mc_diff_info;
1590 if (heap1 == NULL && heap1 == NULL) {
1591 XBT_DEBUG("Malloc descriptors null");
1595 if (heap1->heaplimit != heap2->heaplimit) {
1596 XBT_DEBUG("Different limit of valid info table indices");
1600 /* Heap information */
1601 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1604 // Mamailloute in order to find the base address of the main heap:
1606 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
1608 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1609 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1612 (malloc_info *) ((char *) heap1 +
1614 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1616 (malloc_info *) ((char *) heap2 +
1618 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1620 state->heapsize1 = heap1->heapsize;
1621 state->heapsize2 = heap2->heapsize;
1623 /* Start comparison */
1625 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1629 /* Check busy blocks */
1633 while (i <= state->heaplimit) {
1636 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1637 (char *) state->heapbase1));
1639 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1640 (char *) state->heapbase2));
1642 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1644 distance += BLOCKSIZE;
1645 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1646 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1651 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1652 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1657 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1659 if (state->heapinfo1[i].busy_block.size !=
1660 state->heapinfo2[i].busy_block.size) {
1662 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1663 state->heapinfo2[i].busy_block.size);
1664 i += max(state->heapinfo1[i].busy_block.size,
1665 state->heapinfo2[i].busy_block.size);
1667 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1668 i, state->heapinfo1[i].busy_block.size,
1669 state->heapinfo2[i].busy_block.size, distance);
1673 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1674 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1675 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1676 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);
1682 //while(k < (heapinfo1[i].busy_block.busy_size)){
1683 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1684 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1693 } else { /* Fragmented block */
1695 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1698 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1700 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1702 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1703 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1708 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1709 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1710 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);
1716 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1717 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1718 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=