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 s_xbt_mheap_t std_heap_copy;
147 // Number of blocks in the heaps:
148 size_t heapsize1, heapsize2;
149 xbt_dynar_t to_ignore1, to_ignore2;
150 s_heap_area_t *equals_to1, *equals_to2;
151 dw_type_t *types1, *types2;
155 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
156 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
157 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
158 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
160 __thread struct s_mc_diff *mc_diff_info = NULL;
162 /*********************************** Free functions ************************************/
164 static void heap_area_pair_free(heap_area_pair_t pair)
170 static void heap_area_pair_free_voidp(void *d)
172 heap_area_pair_free((heap_area_pair_t) * (void **) d);
175 static void heap_area_free(heap_area_t area)
181 /************************************************************************************/
183 static s_heap_area_t make_heap_area(int block, int fragment)
188 area.fragment = fragment;
193 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
194 int block2, int fragment2)
197 unsigned int cursor = 0;
198 heap_area_pair_t current_pair;
200 xbt_dynar_foreach(list, cursor, current_pair) {
201 if (current_pair->block1 == block1 && current_pair->block2 == block2
202 && current_pair->fragment1 == fragment1
203 && current_pair->fragment2 == fragment2)
210 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
211 int block2, int fragment2)
214 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
215 heap_area_pair_t pair = NULL;
216 pair = xbt_new0(s_heap_area_pair_t, 1);
217 pair->block1 = block1;
218 pair->fragment1 = fragment1;
219 pair->block2 = block2;
220 pair->fragment2 = fragment2;
222 xbt_dynar_push(list, &pair);
230 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
234 unsigned int cursor = 0;
236 int end = xbt_dynar_length(ignore_list) - 1;
237 mc_heap_ignore_region_t region;
239 while (start <= end) {
240 cursor = (start + end) / 2;
242 (mc_heap_ignore_region_t) xbt_dynar_get_as(ignore_list, cursor,
243 mc_heap_ignore_region_t);
244 if (region->address == address)
246 if (region->address < address)
248 if (region->address > address)
255 static int is_stack(const void *address)
257 unsigned int cursor = 0;
258 stack_region_t stack;
260 xbt_dynar_foreach(stacks_areas, cursor, stack) {
261 if (address == stack->address)
268 // TODO, this should depend on the snapshot?
269 static int is_block_stack(int block)
271 unsigned int cursor = 0;
272 stack_region_t stack;
274 xbt_dynar_foreach(stacks_areas, cursor, stack) {
275 if (block == stack->block)
282 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
285 unsigned int cursor = 0;
286 heap_area_pair_t current_pair;
288 xbt_dynar_foreach(list, cursor, current_pair) {
290 if (current_pair->fragment1 != -1) {
292 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
293 make_heap_area(current_pair->block2, current_pair->fragment2);
294 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
295 make_heap_area(current_pair->block1, current_pair->fragment1);
299 state->equals_to1_(current_pair->block1, 0) =
300 make_heap_area(current_pair->block2, current_pair->fragment2);
301 state->equals_to2_(current_pair->block2, 0) =
302 make_heap_area(current_pair->block1, current_pair->fragment1);
309 /** Check whether two blocks are known to be matching
311 * @param state State used
312 * @param b1 Block of state 1
313 * @param b2 Block of state 2
314 * @return if the blocks are known to be matching
316 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
319 if (state->equals_to1_(b1, 0).block == b2
320 && state->equals_to2_(b2, 0).block == b1)
326 /** Check whether two fragments are known to be matching
328 * @param state State used
329 * @param b1 Block of state 1
330 * @param f1 Fragment of state 1
331 * @param b2 Block of state 2
332 * @param f2 Fragment of state 2
333 * @return if the fragments are known to be matching
335 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
339 if (state->equals_to1_(b1, f1).block == b2
340 && state->equals_to1_(b1, f1).fragment == f2
341 && state->equals_to2_(b2, f2).block == b1
342 && state->equals_to2_(b2, f2).fragment == f1)
348 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
351 if (mc_diff_info == NULL) {
352 mc_diff_info = xbt_new0(struct s_mc_diff, 1);
353 mc_diff_info->equals_to1 = NULL;
354 mc_diff_info->equals_to2 = NULL;
355 mc_diff_info->types1 = NULL;
356 mc_diff_info->types2 = NULL;
358 struct s_mc_diff *state = mc_diff_info;
360 if ((((struct mdesc *) heap1)->heaplimit !=
361 ((struct mdesc *) heap2)->heaplimit)
363 ((((struct mdesc *) heap1)->heapsize !=
364 ((struct mdesc *) heap2)->heapsize)))
367 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
369 state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process);
371 state->heapsize1 = heap1->heapsize;
372 state->heapsize2 = heap2->heapsize;
374 state->to_ignore1 = i1;
375 state->to_ignore2 = i2;
377 if (state->heaplimit > state->available) {
379 realloc(state->equals_to1,
380 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
381 sizeof(s_heap_area_t));
383 realloc(state->types1,
384 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
385 sizeof(type_name *));
387 realloc(state->equals_to2,
388 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
389 sizeof(s_heap_area_t));
391 realloc(state->types2,
392 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
393 sizeof(type_name *));
394 state->available = state->heaplimit;
397 memset(state->equals_to1, 0,
398 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
399 memset(state->equals_to2, 0,
400 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
401 memset(state->types1, 0,
402 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
403 memset(state->types2, 0,
404 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
410 void reset_heap_information()
415 // TODO, have a robust way to find it in O(1)
417 mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
419 size_t n = snapshot->snapshot_regions_count;
420 for (size_t i=0; i!=n; ++i) {
421 mc_mem_region_t region = snapshot->snapshot_regions[i];
422 if (region->region_type == MC_REGION_TYPE_HEAP)
425 xbt_die("No heap region");
428 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
430 mc_process_t process = &mc_model_checker->process;
431 struct s_mc_diff *state = mc_diff_info;
433 /* Start comparison */
434 size_t i1, i2, j1, j2, k;
435 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
436 int nb_diff1 = 0, nb_diff2 = 0;
438 int equal, res_compare = 0;
440 /* Check busy blocks */
444 malloc_info heapinfo_temp1, heapinfo_temp2;
445 malloc_info heapinfo_temp2b;
447 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
448 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
450 // This is the address of std_heap->heapinfo in the application process:
451 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
453 // This is in snapshot do not use them directly:
454 const malloc_info* heapinfos1 = MC_snapshot_read_pointer(snapshot1, heapinfo_address, MC_PROCESS_INDEX_MISSING);
455 const malloc_info* heapinfos2 = MC_snapshot_read_pointer(snapshot2, heapinfo_address, MC_PROCESS_INDEX_MISSING);
457 while (i1 <= state->heaplimit) {
459 const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
460 const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
462 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
467 if (heapinfo1->type < 0) {
468 fprintf(stderr, "Unkown mmalloc block type.\n");
473 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
474 (char *) state->std_heap_copy.heapbase));
476 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
478 if (is_stack(addr_block1)) {
479 for (k = 0; k < heapinfo1->busy_block.size; k++)
480 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
481 for (k = 0; k < heapinfo2->busy_block.size; k++)
482 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
483 i1 += heapinfo1->busy_block.size;
487 if (state->equals_to1_(i1, 0).valid) {
496 /* Try first to associate to same block in the other heap */
497 if (heapinfo2->type == heapinfo1->type) {
499 if (state->equals_to2_(i1, 0).valid == 0) {
501 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
502 (char *) state->std_heap_copy.heapbase;
505 compare_heap_area(MC_PROCESS_INDEX_MISSING, 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) {
523 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
524 (char *) state->std_heap_copy.heapbase;
531 const malloc_info* heapinfo2b = MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
533 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
538 if (state->equals_to2_(i2, 0).valid) {
544 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_block1, addr_block2, snapshot1, snapshot2,
547 if (res_compare != 1) {
548 for (k = 1; k < heapinfo2b->busy_block.size; k++)
549 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
550 for (k = 1; k < heapinfo1->busy_block.size; k++)
551 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
553 i1 += heapinfo1->busy_block.size;
561 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
562 heapinfo1->busy_block.busy_size, addr_block1);
563 i1 = state->heaplimit + 1;
568 } else { /* Fragmented block */
570 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
572 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
575 if (state->equals_to1_(i1, j1).valid)
579 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
584 /* Try first to associate to same fragment in the other heap */
585 if (heapinfo2->type == heapinfo1->type) {
587 if (state->equals_to2_(i1, j1).valid == 0) {
589 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
590 (char *) state->std_heap_copy.heapbase;
592 (void *) ((char *) addr_block2 +
593 (j1 << heapinfo2->type));
596 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_frag1, addr_frag2, snapshot1, snapshot2,
599 if (res_compare != 1)
606 while (i2 <= state->heaplimit && !equal) {
608 const malloc_info* heapinfo2b = MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
610 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
615 // We currently do not match fragments with unfragmented blocks (maybe we should).
616 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
621 if (heapinfo2b->type < 0) {
622 fprintf(stderr, "Unkown mmalloc block type.\n");
626 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
629 if (i2 == i1 && j2 == j1)
632 if (state->equals_to2_(i2, j2).valid)
635 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
636 (char *) state->std_heap_copy.heapbase;
638 (void *) ((char *) addr_block2 +
639 (j2 << heapinfo2b->type));
642 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_frag1, addr_frag2, snapshot2, snapshot2,
645 if (res_compare != 1) {
658 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
659 i1, j1, heapinfo1->busy_frag.frag_size[j1],
661 i2 = state->heaplimit + 1;
662 i1 = state->heaplimit + 1;
675 /* All blocks/fragments are equal to another block/fragment ? */
678 for(i = 1; i <= state->heaplimit; i++) {
679 const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
680 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
681 if (i1 == state->heaplimit) {
682 if (heapinfo1->busy_block.busy_size > 0) {
683 if (state->equals_to1_(i, 0).valid == 0) {
684 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
686 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
687 heapinfo1->busy_block.busy_size);
688 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
695 if (heapinfo1->type > 0) {
696 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
697 if (i1 == state->heaplimit) {
698 if (heapinfo1->busy_frag.frag_size[j] > 0) {
699 if (state->equals_to1_(i, j).valid == 0) {
700 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
701 // TODO, print fragment address
703 ("Block %zu, Fragment %zu not found (size used = %zd)",
705 heapinfo1->busy_frag.frag_size[j]);
706 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
716 if (i1 == state->heaplimit)
717 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
719 for (i=1; i <= state->heaplimit; i++) {
720 const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
721 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
722 if (i1 == state->heaplimit) {
723 if (heapinfo2->busy_block.busy_size > 0) {
724 if (state->equals_to2_(i, 0).valid == 0) {
725 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
726 // TODO, print address of the block
727 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
728 heapinfo2->busy_block.busy_size);
729 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
736 if (heapinfo2->type > 0) {
737 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
738 if (i1 == state->heaplimit) {
739 if (heapinfo2->busy_frag.frag_size[j] > 0) {
740 if (state->equals_to2_(i, j).valid == 0) {
741 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
742 // TODO, print address of the block
744 ("Block %zu, Fragment %zu not found (size used = %zd)",
746 heapinfo2->busy_frag.frag_size[j]);
747 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
757 if (i1 == state->heaplimit)
758 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
760 return ((nb_diff1 > 0) || (nb_diff2 > 0));
766 * @param real_area1 Process address for state 1
767 * @param real_area2 Process address for state 2
768 * @param snapshot1 Snapshot of state 1
769 * @param snapshot2 Snapshot of state 2
772 * @param check_ignore
774 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
775 const void *real_area1, const void *real_area2,
776 mc_snapshot_t snapshot1,
777 mc_snapshot_t snapshot2,
778 xbt_dynar_t previous, int size,
781 mc_process_t process = &mc_model_checker->process;
784 const void *addr_pointed1, *addr_pointed2;
785 int pointer_align, res_compare;
786 ssize_t ignore1, ignore2;
788 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
789 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
793 if (check_ignore > 0) {
795 heap_comparison_ignore_size(state->to_ignore1,
796 (char *) real_area1 + i)) != -1) {
798 heap_comparison_ignore_size(state->to_ignore2,
799 (char *) real_area2 + i)) == ignore1) {
812 if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
814 pointer_align = (i / sizeof(void *)) * sizeof(void *);
815 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char *) real_area1 + pointer_align, process_index);
816 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char *) real_area2 + pointer_align, process_index);
818 if (addr_pointed1 > process->maestro_stack_start
819 && addr_pointed1 < process->maestro_stack_end
820 && addr_pointed2 > process->maestro_stack_start
821 && addr_pointed2 < process->maestro_stack_end) {
822 i = pointer_align + sizeof(void *);
824 } else if (addr_pointed1 > state->std_heap_copy.heapbase
825 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
826 && addr_pointed2 > state->std_heap_copy.heapbase
827 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
828 // Both addreses are in the heap:
830 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
831 snapshot2, previous, NULL, 0);
832 if (res_compare == 1) {
835 i = pointer_align + sizeof(void *);
854 * @param real_area1 Process address for state 1
855 * @param real_area2 Process address for state 2
856 * @param snapshot1 Snapshot of state 1
857 * @param snapshot2 Snapshot of state 2
860 * @param area_size either a byte_size or an elements_count (?)
861 * @param check_ignore
862 * @param pointer_level
863 * @return 0 (same), 1 (different), -1 (unknown)
865 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
866 const void *real_area1, const void *real_area2,
867 mc_snapshot_t snapshot1,
868 mc_snapshot_t snapshot2,
869 xbt_dynar_t previous, dw_type_t type,
870 int area_size, int check_ignore,
874 if (is_stack(real_area1) && is_stack(real_area2))
877 ssize_t ignore1, ignore2;
879 if ((check_ignore > 0)
880 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
882 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
887 dw_type_t subtype, subsubtype;
888 int res, elm_size, i;
889 unsigned int cursor = 0;
891 const void *addr_pointed1, *addr_pointed2;;
893 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
894 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
896 switch (type->type) {
897 case DW_TAG_unspecified_type:
900 case DW_TAG_base_type:
901 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
902 if (real_area1 == real_area2)
905 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
907 if (area_size != -1 && type->byte_size != area_size)
910 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
914 case DW_TAG_enumeration_type:
915 if (area_size != -1 && type->byte_size != area_size)
918 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
921 case DW_TAG_const_type:
922 case DW_TAG_volatile_type:
924 type = type->subtype;
927 case DW_TAG_array_type:
928 subtype = type->subtype;
929 switch (subtype->type) {
930 case DW_TAG_unspecified_type:
933 case DW_TAG_base_type:
934 case DW_TAG_enumeration_type:
935 case DW_TAG_pointer_type:
936 case DW_TAG_reference_type:
937 case DW_TAG_rvalue_reference_type:
938 case DW_TAG_structure_type:
939 case DW_TAG_class_type:
940 case DW_TAG_union_type:
941 if (subtype->full_type)
942 subtype = subtype->full_type;
943 elm_size = subtype->byte_size;
945 // TODO, just remove the type indirection?
946 case DW_TAG_const_type:
948 case DW_TAG_volatile_type:
949 subsubtype = subtype->subtype;
950 if (subsubtype->full_type)
951 subsubtype = subsubtype->full_type;
952 elm_size = subsubtype->byte_size;
958 for (i = 0; i < type->element_count; i++) {
959 // TODO, add support for variable stride (DW_AT_byte_stride)
961 compare_heap_area_with_type(state, process_index,
962 (char *) real_area1 + (i * elm_size),
963 (char *) real_area2 + (i * elm_size),
964 snapshot1, snapshot2, previous,
965 type->subtype, subtype->byte_size,
966 check_ignore, pointer_level);
971 case DW_TAG_reference_type:
972 case DW_TAG_rvalue_reference_type:
973 case DW_TAG_pointer_type:
974 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
975 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, real_area1, process_index);
976 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, real_area2, process_index);
977 return (addr_pointed1 != addr_pointed2);;
980 if (pointer_level > 1) { /* Array of pointers */
981 for (i = 0; i < (area_size / sizeof(void *)); i++) {
982 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char*) real_area1 + i * sizeof(void *), process_index);
983 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char*) real_area2 + i * sizeof(void *), process_index);
984 if (addr_pointed1 > state->std_heap_copy.heapbase
985 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
986 && addr_pointed2 > state->std_heap_copy.heapbase
987 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
989 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
990 snapshot2, previous, type->subtype,
993 res = (addr_pointed1 != addr_pointed2);
998 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, real_area1, process_index);
999 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, real_area2, process_index);
1000 if (addr_pointed1 > state->std_heap_copy.heapbase
1001 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
1002 && addr_pointed2 > state->std_heap_copy.heapbase
1003 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1004 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1005 snapshot2, previous, type->subtype,
1008 return (addr_pointed1 != addr_pointed2);
1012 case DW_TAG_structure_type:
1013 case DW_TAG_class_type:
1014 if (type->full_type)
1015 type = type->full_type;
1016 if (area_size != -1 && type->byte_size != area_size) {
1017 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1018 for (i = 0; i < (area_size / type->byte_size); i++) {
1020 compare_heap_area_with_type(state, process_index,
1021 (char *) real_area1 + i * type->byte_size,
1022 (char *) real_area2 + i * type->byte_size,
1023 snapshot1, snapshot2, previous, type, -1,
1033 xbt_dynar_foreach(type->members, cursor, member) {
1034 // TODO, optimize this? (for the offset case)
1035 char *real_member1 =
1036 mc_member_resolve(real_area1, type, member, (mc_address_space_t) snapshot1, process_index);
1037 char *real_member2 =
1038 mc_member_resolve(real_area2, type, member, (mc_address_space_t) snapshot2, process_index);
1040 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1041 snapshot1, snapshot2,
1042 previous, member->subtype, -1,
1050 case DW_TAG_union_type:
1051 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1052 snapshot1, snapshot2, previous,
1053 type->byte_size, check_ignore);
1063 /** Infer the type of a part of the block from the type of the block
1065 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1067 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1069 * @param type_id DWARF type ID of the root address
1071 * @return DWARF type ID for given offset
1073 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1074 int offset, int area_size,
1075 mc_snapshot_t snapshot, int process_index)
1078 // Beginning of the block, the infered variable type if the type of the block:
1082 switch (type->type) {
1083 case DW_TAG_structure_type:
1084 case DW_TAG_class_type:
1085 if (type->full_type)
1086 type = type->full_type;
1088 if (area_size != -1 && type->byte_size != area_size) {
1089 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1094 unsigned int cursor = 0;
1096 xbt_dynar_foreach(type->members, cursor, member) {
1098 if (!member->location.size) {
1099 // We have the offset, use it directly (shortcut):
1100 if (member->offset == offset)
1101 return member->subtype;
1104 mc_member_resolve(real_base_address, type, member, (mc_address_space_t) snapshot, process_index);
1105 if (real_member - (char *) real_base_address == offset)
1106 return member->subtype;
1114 /* FIXME : other cases ? */
1122 * @param area1 Process address for state 1
1123 * @param area2 Process address for state 2
1124 * @param snapshot1 Snapshot of state 1
1125 * @param snapshot2 Snapshot of state 2
1126 * @param previous Pairs of blocks already compared on the current path (or NULL)
1127 * @param type_id Type of variable
1128 * @param pointer_level
1129 * @return 0 (same), 1 (different), -1
1131 int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
1132 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1133 dw_type_t type, int pointer_level)
1135 mc_process_t process = &mc_model_checker->process;
1137 struct s_mc_diff *state = mc_diff_info;
1140 ssize_t block1, frag1, block2, frag2;
1142 int check_ignore = 0;
1144 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1146 int offset1 = 0, offset2 = 0;
1147 int new_size1 = -1, new_size2 = -1;
1148 dw_type_t new_type1 = NULL, new_type2 = NULL;
1150 int match_pairs = 0;
1152 // This is the address of std_heap->heapinfo in the application process:
1153 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
1155 const malloc_info* heapinfos1 = MC_snapshot_read_pointer(snapshot1, heapinfo_address, process_index);
1156 const malloc_info* heapinfos2 = MC_snapshot_read_pointer(snapshot2, heapinfo_address, process_index);
1158 malloc_info heapinfo_temp1, heapinfo_temp2;
1160 if (previous == NULL) {
1162 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1165 // Get block number:
1168 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1171 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1173 // If either block is a stack block:
1174 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1175 add_heap_area_pair(previous, block1, -1, block2, -1);
1177 match_equals(state, previous);
1178 xbt_dynar_free(&previous);
1182 // If either block is not in the expected area of memory:
1183 if (((char *) area1 < (char *) state->std_heap_copy.heapbase)
1184 || (block1 > state->heapsize1) || (block1 < 1)
1185 || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
1186 || (block2 > state->heapsize2) || (block2 < 1)) {
1188 xbt_dynar_free(&previous);
1193 // Process address of the block:
1194 real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
1195 (char *) state->std_heap_copy.heapbase;
1196 real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
1197 (char *) state->std_heap_copy.heapbase;
1201 if (type->full_type)
1202 type = type->full_type;
1204 // This assume that for "boring" types (volatile ...) byte_size is absent:
1205 while (type->byte_size == 0 && type->subtype != NULL)
1206 type = type->subtype;
1209 if ((type->type == DW_TAG_pointer_type)
1210 || ((type->type == DW_TAG_base_type) && type->name != NULL
1211 && (!strcmp(type->name, "char"))))
1214 type_size = type->byte_size;
1218 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1219 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1221 const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
1222 const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
1224 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1225 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1229 match_equals(state, previous);
1230 xbt_dynar_free(&previous);
1234 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1235 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1236 /* Complete block */
1238 // TODO, lookup variable type from block type as done for fragmented blocks
1240 offset1 = (char *) area1 - (char *) real_addr_block1;
1241 offset2 = (char *) area2 - (char *) real_addr_block2;
1243 if (state->equals_to1_(block1, 0).valid
1244 && state->equals_to2_(block2, 0).valid) {
1245 if (equal_blocks(state, block1, block2)) {
1247 match_equals(state, previous);
1248 xbt_dynar_free(&previous);
1254 if (type_size != -1) {
1255 if (type_size != heapinfo1->busy_block.busy_size
1256 && type_size != heapinfo2->busy_block.busy_size
1257 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1259 match_equals(state, previous);
1260 xbt_dynar_free(&previous);
1266 if (heapinfo1->busy_block.size !=
1267 heapinfo2->busy_block.size) {
1269 xbt_dynar_free(&previous);
1274 if (heapinfo1->busy_block.busy_size !=
1275 heapinfo2->busy_block.busy_size) {
1277 xbt_dynar_free(&previous);
1282 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1284 match_equals(state, previous);
1285 xbt_dynar_free(&previous);
1290 size = heapinfo1->busy_block.busy_size;
1292 // Remember (basic) type inference.
1293 // The current data structure only allows us to do this for the whole block.
1294 if (type != NULL && area1 == real_addr_block1) {
1295 state->types1_(block1, 0) = type;
1297 if (type != NULL && area2 == real_addr_block2) {
1298 state->types2_(block2, 0) = type;
1303 match_equals(state, previous);
1304 xbt_dynar_free(&previous);
1312 if ((heapinfo1->busy_block.ignore > 0)
1313 && (heapinfo2->busy_block.ignore ==
1314 heapinfo1->busy_block.ignore))
1315 check_ignore = heapinfo1->busy_block.ignore;
1317 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1321 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1323 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1325 // Process address of the fragment:
1327 (void *) ((char *) real_addr_block1 +
1328 (frag1 << heapinfo1->type));
1330 (void *) ((char *) real_addr_block2 +
1331 (frag2 << heapinfo2->type));
1333 // Check the size of the fragments against the size of the type:
1334 if (type_size != -1) {
1335 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1336 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1338 match_equals(state, previous);
1339 xbt_dynar_free(&previous);
1344 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1345 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1347 match_equals(state, previous);
1348 xbt_dynar_free(&previous);
1354 // Check if the blocks are already matched together:
1355 if (state->equals_to1_(block1, frag1).valid
1356 && state->equals_to2_(block2, frag2).valid) {
1357 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1359 match_equals(state, previous);
1360 xbt_dynar_free(&previous);
1365 // Compare the size of both fragments:
1366 if (heapinfo1->busy_frag.frag_size[frag1] !=
1367 heapinfo2->busy_frag.frag_size[frag2]) {
1368 if (type_size == -1) {
1370 match_equals(state, previous);
1371 xbt_dynar_free(&previous);
1376 xbt_dynar_free(&previous);
1382 // Size of the fragment:
1383 size = heapinfo1->busy_frag.frag_size[frag1];
1385 // Remember (basic) type inference.
1386 // The current data structure only allows us to do this for the whole fragment.
1387 if (type != NULL && area1 == real_addr_frag1) {
1388 state->types1_(block1, frag1) = type;
1390 if (type != NULL && area2 == real_addr_frag2) {
1391 state->types2_(block2, frag2) = type;
1393 // The type of the variable is already known:
1398 // Type inference from the block type.
1399 else if (state->types1_(block1, frag1) != NULL
1400 || state->types2_(block2, frag2) != NULL) {
1402 offset1 = (char *) area1 - (char *) real_addr_frag1;
1403 offset2 = (char *) area2 - (char *) real_addr_frag2;
1405 if (state->types1_(block1, frag1) != NULL
1406 && state->types2_(block2, frag2) != NULL) {
1408 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1409 offset1, size, snapshot1, process_index);
1411 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1412 offset1, size, snapshot2, process_index);
1413 } else if (state->types1_(block1, frag1) != NULL) {
1415 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1416 offset1, size, snapshot1, process_index);
1418 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1419 offset2, size, snapshot2, process_index);
1420 } else if (state->types2_(block2, frag2) != NULL) {
1422 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1423 offset1, size, snapshot1, process_index);
1425 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1426 offset2, size, snapshot2, process_index);
1429 match_equals(state, previous);
1430 xbt_dynar_free(&previous);
1435 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1438 while (type->byte_size == 0 && type->subtype != NULL)
1439 type = type->subtype;
1440 new_size1 = type->byte_size;
1443 while (type->byte_size == 0 && type->subtype != NULL)
1444 type = type->subtype;
1445 new_size2 = type->byte_size;
1449 match_equals(state, previous);
1450 xbt_dynar_free(&previous);
1456 if (new_size1 > 0 && new_size1 == new_size2) {
1461 if (offset1 == 0 && offset2 == 0) {
1462 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1464 match_equals(state, previous);
1465 xbt_dynar_free(&previous);
1473 match_equals(state, previous);
1474 xbt_dynar_free(&previous);
1479 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1480 && (heapinfo2->busy_frag.ignore[frag2] ==
1481 heapinfo1->busy_frag.ignore[frag1]))
1482 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1487 xbt_dynar_free(&previous);
1494 /* Start comparison */
1497 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1498 previous, type, size, check_ignore,
1502 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1503 previous, size, check_ignore);
1505 if (res_compare == 1) {
1507 xbt_dynar_free(&previous);
1512 match_equals(state, previous);
1513 xbt_dynar_free(&previous);
1519 /*********************************************** Miscellaneous ***************************************************/
1520 /****************************************************************************************************************/
1522 // Not used and broken code:
1526 static int get_pointed_area_size(void *area, int heap)
1529 struct s_mc_diff *state = mc_diff_info;
1532 malloc_info *heapinfo;
1535 heapinfo = state->heapinfo1;
1537 heapinfo = state->heapinfo2;
1541 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1543 if (((char *) area < (char *) state->std_heap_copy.heapbase)
1544 || (block > state->heapsize1) || (block < 1))
1547 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1549 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1550 return (int) heapinfo[block].busy_block.busy_size;
1553 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1554 return (int) heapinfo[block].busy_frag.frag_size[frag];
1559 char *get_type_description(mc_object_info_t info, char *type_name)
1562 xbt_dict_cursor_t dict_cursor;
1566 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1567 if (type->name && (strcmp(type->name, type_name) == 0)
1568 && type->byte_size > 0) {
1569 xbt_dict_cursor_free(&dict_cursor);
1574 xbt_dict_cursor_free(&dict_cursor);
1580 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1584 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1587 struct s_mc_diff *state = mc_diff_info;
1589 if (heap1 == NULL && heap1 == NULL) {
1590 XBT_DEBUG("Malloc descriptors null");
1594 if (heap1->heaplimit != heap2->heaplimit) {
1595 XBT_DEBUG("Different limit of valid info table indices");
1599 /* Heap information */
1600 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1602 state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process);
1604 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1605 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1608 (malloc_info *) ((char *) heap1 +
1610 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1612 (malloc_info *) ((char *) heap2 +
1614 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1616 state->heapsize1 = heap1->heapsize;
1617 state->heapsize2 = heap2->heapsize;
1619 /* Start comparison */
1621 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1625 /* Check busy blocks */
1629 while (i <= state->heaplimit) {
1632 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1633 (char *) state->heapbase1));
1635 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1636 (char *) state->heapbase2));
1638 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1640 distance += BLOCKSIZE;
1641 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1642 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1647 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1648 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1653 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1655 if (state->heapinfo1[i].busy_block.size !=
1656 state->heapinfo2[i].busy_block.size) {
1658 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1659 state->heapinfo2[i].busy_block.size);
1660 i += max(state->heapinfo1[i].busy_block.size,
1661 state->heapinfo2[i].busy_block.size);
1663 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1664 i, state->heapinfo1[i].busy_block.size,
1665 state->heapinfo2[i].busy_block.size, distance);
1669 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1670 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1671 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1672 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);
1678 //while(k < (heapinfo1[i].busy_block.busy_size)){
1679 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1680 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1689 } else { /* Fragmented block */
1691 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1694 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1696 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1698 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1699 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1704 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1705 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1706 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);
1712 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1713 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1714 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=