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 using simgrid::mc::remote;
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
23 "Logging specific to mc_diff in mc");
25 xbt_dynar_t mc_heap_comparison_ignore;
26 xbt_dynar_t stacks_areas;
30 /********************************* Backtrace ***********************************/
31 /******************************************************************************/
33 static void mmalloc_backtrace_block_display(void *heapinfo, int block)
38 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
39 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
43 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
44 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
46 /* xbt_ex_setup_backtrace(&e); */
47 /* if (e.used == 0) { */
48 /* fprintf(stderr, "(backtrace not set)\n"); */
49 /* } else if (e.bt_strings == NULL) { */
50 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
54 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
55 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
56 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
61 static void mmalloc_backtrace_fragment_display(void *heapinfo, int block,
67 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
68 /* e.used = XBT_BACKTRACE_SIZE; */
70 /* xbt_ex_setup_backtrace(&e); */
71 /* if (e.used == 0) { */
72 /* fprintf(stderr, "(backtrace not set)\n"); */
73 /* } else if (e.bt_strings == NULL) { */
74 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
78 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
79 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
80 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
86 static void mmalloc_backtrace_display(void *addr)
89 /* size_t block, frag_nb; */
92 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
94 /* type = heap->heapinfo[block].type; */
97 /* case MMALLOC_TYPE_HEAPINFO : */
98 /* case MMALLOC_TYPE_FREE : /\* Free block *\/ */
99 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
102 /* case 0: /\* Large block *\/ */
103 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
105 /* default: /\* Fragmented block *\/ */
106 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
107 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
108 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
111 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
117 static int compare_backtrace(int b1, int f1, int b2, int f2)
121 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
122 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
123 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
124 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
129 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
130 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
131 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
132 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
141 /*********************************** Heap comparison ***********************************/
142 /***************************************************************************************/
144 typedef char *type_name;
147 s_xbt_mheap_t std_heap_copy;
149 // Number of blocks in the heaps:
150 size_t heapsize1, heapsize2;
151 std::vector<s_mc_heap_ignore_region_t>* to_ignore1;
152 std::vector<s_mc_heap_ignore_region_t>* to_ignore2;
153 s_heap_area_t *equals_to1, *equals_to2;
154 mc_type_t *types1, *types2;
158 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
159 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
160 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
161 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
163 __thread struct s_mc_diff *mc_diff_info = NULL;
165 /*********************************** Free functions ************************************/
167 static void heap_area_pair_free(heap_area_pair_t pair)
173 static void heap_area_pair_free_voidp(void *d)
175 heap_area_pair_free((heap_area_pair_t) * (void **) d);
178 static void heap_area_free(heap_area_t area)
184 /************************************************************************************/
186 static s_heap_area_t make_heap_area(int block, int fragment)
191 area.fragment = fragment;
196 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
197 int block2, int fragment2)
200 unsigned int cursor = 0;
201 heap_area_pair_t current_pair;
203 xbt_dynar_foreach(list, cursor, current_pair) {
204 if (current_pair->block1 == block1 && current_pair->block2 == block2
205 && current_pair->fragment1 == fragment1
206 && current_pair->fragment2 == fragment2)
213 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
214 int block2, int fragment2)
217 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
218 heap_area_pair_t pair = NULL;
219 pair = xbt_new0(s_heap_area_pair_t, 1);
220 pair->block1 = block1;
221 pair->fragment1 = fragment1;
222 pair->block2 = block2;
223 pair->fragment2 = fragment2;
225 xbt_dynar_push(list, &pair);
233 static ssize_t heap_comparison_ignore_size(std::vector<s_mc_heap_ignore_region_t>* ignore_list,
237 int end = ignore_list->size() - 1;
239 while (start <= end) {
240 unsigned int cursor = (start + end) / 2;
241 s_mc_heap_ignore_region_t region = (*ignore_list)[cursor];
242 if (region.address == address)
244 if (region.address < address)
246 if (region.address > address)
253 static int is_stack(const void *address)
255 unsigned int cursor = 0;
256 stack_region_t stack;
258 xbt_dynar_foreach(stacks_areas, cursor, stack) {
259 if (address == stack->address)
266 // TODO, this should depend on the snapshot?
267 static int is_block_stack(int block)
269 unsigned int cursor = 0;
270 stack_region_t stack;
272 xbt_dynar_foreach(stacks_areas, cursor, stack) {
273 if (block == stack->block)
280 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
283 unsigned int cursor = 0;
284 heap_area_pair_t current_pair;
286 xbt_dynar_foreach(list, cursor, current_pair) {
288 if (current_pair->fragment1 != -1) {
290 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
291 make_heap_area(current_pair->block2, current_pair->fragment2);
292 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
293 make_heap_area(current_pair->block1, current_pair->fragment1);
297 state->equals_to1_(current_pair->block1, 0) =
298 make_heap_area(current_pair->block2, current_pair->fragment2);
299 state->equals_to2_(current_pair->block2, 0) =
300 make_heap_area(current_pair->block1, current_pair->fragment1);
307 /** Check whether two blocks are known to be matching
309 * @param state State used
310 * @param b1 Block of state 1
311 * @param b2 Block of state 2
312 * @return if the blocks are known to be matching
314 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
317 if (state->equals_to1_(b1, 0).block == b2
318 && state->equals_to2_(b2, 0).block == b1)
324 /** Check whether two fragments are known to be matching
326 * @param state State used
327 * @param b1 Block of state 1
328 * @param f1 Fragment of state 1
329 * @param b2 Block of state 2
330 * @param f2 Fragment of state 2
331 * @return if the fragments are known to be matching
333 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
337 if (state->equals_to1_(b1, f1).block == b2
338 && state->equals_to1_(b1, f1).fragment == f2
339 && state->equals_to2_(b2, f2).block == b1
340 && state->equals_to2_(b2, f2).fragment == f1)
348 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2,
349 std::vector<s_mc_heap_ignore_region_t>* i1,
350 std::vector<s_mc_heap_ignore_region_t>* i2)
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 state->std_heap_copy = *mc_model_checker->process().get_heap();
372 state->heapsize1 = heap1->heapsize;
373 state->heapsize2 = heap2->heapsize;
375 state->to_ignore1 = i1;
376 state->to_ignore2 = i2;
378 if (state->heaplimit > state->available) {
379 state->equals_to1 = (s_heap_area_t*)
380 realloc(state->equals_to1,
381 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
382 sizeof(s_heap_area_t));
383 state->types1 = (simgrid::mc::Type**)
384 realloc(state->types1,
385 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
386 sizeof(type_name *));
387 state->equals_to2 = (s_heap_area_t*)
388 realloc(state->equals_to2,
389 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
390 sizeof(s_heap_area_t));
391 state->types2 = (simgrid::mc::Type**)
392 realloc(state->types2,
393 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
394 sizeof(type_name *));
395 state->available = state->heaplimit;
398 memset(state->equals_to1, 0,
399 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
400 memset(state->equals_to2, 0,
401 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
402 memset(state->types1, 0,
403 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
404 memset(state->types2, 0,
405 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.size();
423 for (size_t i=0; i!=n; ++i) {
424 mc_mem_region_t region = snapshot->snapshot_regions[i].get();
425 if (region->region_type() == simgrid::mc::RegionType::Heap)
428 xbt_die("No heap region");
431 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
433 mc_process_t process = &mc_model_checker->process();
434 struct s_mc_diff *state = mc_diff_info;
436 /* Start comparison */
437 size_t i1, i2, j1, j2, k;
438 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
439 int nb_diff1 = 0, nb_diff2 = 0;
441 int equal, res_compare = 0;
443 /* Check busy blocks */
447 malloc_info heapinfo_temp1, heapinfo_temp2;
448 malloc_info heapinfo_temp2b;
450 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
451 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
453 // This is the address of std_heap->heapinfo in the application process:
454 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
456 // This is in snapshot do not use them directly:
457 const malloc_info* heapinfos1 = snapshot1->read<malloc_info*>(
458 (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
459 const malloc_info* heapinfos2 = snapshot2->read<malloc_info*>(
460 (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
462 while (i1 <= state->heaplimit) {
464 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
465 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
467 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
472 if (heapinfo1->type < 0) {
473 fprintf(stderr, "Unkown mmalloc block type.\n");
478 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
479 (char *) state->std_heap_copy.heapbase));
481 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
483 if (is_stack(addr_block1)) {
484 for (k = 0; k < heapinfo1->busy_block.size; k++)
485 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
486 for (k = 0; k < heapinfo2->busy_block.size; k++)
487 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
488 i1 += heapinfo1->busy_block.size;
492 if (state->equals_to1_(i1, 0).valid) {
501 /* Try first to associate to same block in the other heap */
502 if (heapinfo2->type == heapinfo1->type) {
504 if (state->equals_to2_(i1, 0).valid == 0) {
506 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
507 (char *) state->std_heap_copy.heapbase;
510 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, snapshot2,
513 if (res_compare != 1) {
514 for (k = 1; k < heapinfo2->busy_block.size; k++)
515 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
516 for (k = 1; k < heapinfo1->busy_block.size; k++)
517 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
519 i1 += heapinfo1->busy_block.size;
526 while (i2 <= state->heaplimit && !equal) {
528 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
529 (char *) state->std_heap_copy.heapbase;
536 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
538 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
543 if (state->equals_to2_(i2, 0).valid) {
549 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, snapshot2,
552 if (res_compare != 1) {
553 for (k = 1; k < heapinfo2b->busy_block.size; k++)
554 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
555 for (k = 1; k < heapinfo1->busy_block.size; k++)
556 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
558 i1 += heapinfo1->busy_block.size;
566 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
567 heapinfo1->busy_block.busy_size, addr_block1);
568 i1 = state->heaplimit + 1;
573 } else { /* Fragmented block */
575 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
577 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
580 if (state->equals_to1_(i1, j1).valid)
584 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
589 /* Try first to associate to same fragment in the other heap */
590 if (heapinfo2->type == heapinfo1->type) {
592 if (state->equals_to2_(i1, j1).valid == 0) {
594 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
595 (char *) state->std_heap_copy.heapbase;
597 (void *) ((char *) addr_block2 +
598 (j1 << heapinfo2->type));
601 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot1, snapshot2,
604 if (res_compare != 1)
611 while (i2 <= state->heaplimit && !equal) {
613 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
614 heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
615 sizeof(malloc_info));
617 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
622 // We currently do not match fragments with unfragmented blocks (maybe we should).
623 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
628 if (heapinfo2b->type < 0) {
629 fprintf(stderr, "Unkown mmalloc block type.\n");
633 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
636 if (i2 == i1 && j2 == j1)
639 if (state->equals_to2_(i2, j2).valid)
642 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
643 (char *) state->std_heap_copy.heapbase;
645 (void *) ((char *) addr_block2 +
646 (j2 << heapinfo2b->type));
649 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot2, snapshot2,
652 if (res_compare != 1) {
665 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
666 i1, j1, heapinfo1->busy_frag.frag_size[j1],
668 i2 = state->heaplimit + 1;
669 i1 = state->heaplimit + 1;
682 /* All blocks/fragments are equal to another block/fragment ? */
685 for(i = 1; i <= state->heaplimit; i++) {
686 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
687 heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
688 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
689 if (i1 == state->heaplimit) {
690 if (heapinfo1->busy_block.busy_size > 0) {
691 if (state->equals_to1_(i, 0).valid == 0) {
692 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
694 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
695 heapinfo1->busy_block.busy_size);
696 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
703 if (heapinfo1->type > 0) {
704 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
705 if (i1 == state->heaplimit) {
706 if (heapinfo1->busy_frag.frag_size[j] > 0) {
707 if (state->equals_to1_(i, j).valid == 0) {
708 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
709 // TODO, print fragment address
711 ("Block %zu, Fragment %zu not found (size used = %zd)",
713 heapinfo1->busy_frag.frag_size[j]);
714 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
724 if (i1 == state->heaplimit)
725 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
727 for (i=1; i <= state->heaplimit; i++) {
728 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
729 heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
730 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
731 if (i1 == state->heaplimit) {
732 if (heapinfo2->busy_block.busy_size > 0) {
733 if (state->equals_to2_(i, 0).valid == 0) {
734 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
735 // TODO, print address of the block
736 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
737 heapinfo2->busy_block.busy_size);
738 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
745 if (heapinfo2->type > 0) {
746 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
747 if (i1 == state->heaplimit) {
748 if (heapinfo2->busy_frag.frag_size[j] > 0) {
749 if (state->equals_to2_(i, j).valid == 0) {
750 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
751 // TODO, print address of the block
753 ("Block %zu, Fragment %zu not found (size used = %zd)",
755 heapinfo2->busy_frag.frag_size[j]);
756 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
766 if (i1 == state->heaplimit)
767 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
769 return ((nb_diff1 > 0) || (nb_diff2 > 0));
775 * @param real_area1 Process address for state 1
776 * @param real_area2 Process address for state 2
777 * @param snapshot1 Snapshot of state 1
778 * @param snapshot2 Snapshot of state 2
781 * @param check_ignore
783 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
784 const void *real_area1, const void *real_area2,
785 mc_snapshot_t snapshot1,
786 mc_snapshot_t snapshot2,
787 xbt_dynar_t previous, int size,
790 mc_process_t process = &mc_model_checker->process();
793 const void *addr_pointed1, *addr_pointed2;
794 int pointer_align, res_compare;
795 ssize_t ignore1, ignore2;
797 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
798 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
802 if (check_ignore > 0) {
804 heap_comparison_ignore_size(state->to_ignore1,
805 (char *) real_area1 + i)) != -1) {
807 heap_comparison_ignore_size(state->to_ignore2,
808 (char *) real_area2 + i)) == ignore1) {
821 if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
823 pointer_align = (i / sizeof(void *)) * sizeof(void *);
824 addr_pointed1 = snapshot1->read(
825 remote((void**)((char *) real_area1 + pointer_align)), process_index);
826 addr_pointed2 = snapshot2->read(
827 remote((void**)((char *) real_area2 + pointer_align)), process_index);
829 if (process->in_maestro_stack(remote(addr_pointed1))
830 && process->in_maestro_stack(remote(addr_pointed2))) {
831 i = pointer_align + sizeof(void *);
833 } else if (addr_pointed1 > state->std_heap_copy.heapbase
834 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
835 && addr_pointed2 > state->std_heap_copy.heapbase
836 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
837 // Both addreses are in the heap:
839 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
840 snapshot2, previous, NULL, 0);
841 if (res_compare == 1) {
844 i = pointer_align + sizeof(void *);
863 * @param real_area1 Process address for state 1
864 * @param real_area2 Process address for state 2
865 * @param snapshot1 Snapshot of state 1
866 * @param snapshot2 Snapshot of state 2
869 * @param area_size either a byte_size or an elements_count (?)
870 * @param check_ignore
871 * @param pointer_level
872 * @return 0 (same), 1 (different), -1 (unknown)
874 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
875 const void *real_area1, const void *real_area2,
876 mc_snapshot_t snapshot1,
877 mc_snapshot_t snapshot2,
878 xbt_dynar_t previous, mc_type_t type,
879 int area_size, int check_ignore,
883 if (is_stack(real_area1) && is_stack(real_area2))
886 ssize_t ignore1, ignore2;
888 if ((check_ignore > 0)
889 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
891 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
896 mc_type_t subtype, subsubtype;
898 const void *addr_pointed1, *addr_pointed2;
900 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
901 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
903 switch (type->type) {
904 case DW_TAG_unspecified_type:
907 case DW_TAG_base_type:
908 if (!type->name.empty() && type->name == "char") { /* String, hence random (arbitrary ?) size */
909 if (real_area1 == real_area2)
912 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
914 if (area_size != -1 && type->byte_size != area_size)
917 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
921 case DW_TAG_enumeration_type:
922 if (area_size != -1 && type->byte_size != area_size)
925 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
928 case DW_TAG_const_type:
929 case DW_TAG_volatile_type:
931 type = type->subtype;
934 case DW_TAG_array_type:
935 subtype = type->subtype;
936 switch (subtype->type) {
937 case DW_TAG_unspecified_type:
940 case DW_TAG_base_type:
941 case DW_TAG_enumeration_type:
942 case DW_TAG_pointer_type:
943 case DW_TAG_reference_type:
944 case DW_TAG_rvalue_reference_type:
945 case DW_TAG_structure_type:
946 case DW_TAG_class_type:
947 case DW_TAG_union_type:
948 if (subtype->full_type)
949 subtype = subtype->full_type;
950 elm_size = subtype->byte_size;
952 // TODO, just remove the type indirection?
953 case DW_TAG_const_type:
955 case DW_TAG_volatile_type:
956 subsubtype = subtype->subtype;
957 if (subsubtype->full_type)
958 subsubtype = subsubtype->full_type;
959 elm_size = subsubtype->byte_size;
965 for (int i = 0; i < type->element_count; i++) {
966 // TODO, add support for variable stride (DW_AT_byte_stride)
968 compare_heap_area_with_type(state, process_index,
969 (char *) real_area1 + (i * elm_size),
970 (char *) real_area2 + (i * elm_size),
971 snapshot1, snapshot2, previous,
972 type->subtype, subtype->byte_size,
973 check_ignore, pointer_level);
978 case DW_TAG_reference_type:
979 case DW_TAG_rvalue_reference_type:
980 case DW_TAG_pointer_type:
981 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
982 addr_pointed1 = snapshot1->read(remote((void**)real_area1), process_index);
983 addr_pointed2 = snapshot2->read(remote((void**)real_area2), process_index);
984 return (addr_pointed1 != addr_pointed2);;
987 if (pointer_level > 1) { /* Array of pointers */
988 for (size_t i = 0; i < (area_size / sizeof(void *)); i++) {
989 addr_pointed1 = snapshot1->read(
990 remote((void**)((char*) real_area1 + i * sizeof(void *))),
992 addr_pointed2 = snapshot2->read(
993 remote((void**)((char*) real_area2 + i * sizeof(void *))),
995 if (addr_pointed1 > state->std_heap_copy.heapbase
996 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
997 && addr_pointed2 > state->std_heap_copy.heapbase
998 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1000 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1001 snapshot2, previous, type->subtype,
1004 res = (addr_pointed1 != addr_pointed2);
1009 addr_pointed1 = snapshot1->read(remote((void**)real_area1), process_index);
1010 addr_pointed2 = snapshot2->read(remote((void**)real_area2), process_index);
1011 if (addr_pointed1 > state->std_heap_copy.heapbase
1012 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
1013 && addr_pointed2 > state->std_heap_copy.heapbase
1014 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1015 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1016 snapshot2, previous, type->subtype,
1019 return (addr_pointed1 != addr_pointed2);
1023 case DW_TAG_structure_type:
1024 case DW_TAG_class_type:
1025 if (type->full_type)
1026 type = type->full_type;
1027 if (area_size != -1 && type->byte_size != area_size) {
1028 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1029 for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) {
1031 compare_heap_area_with_type(state, process_index,
1032 (char *) real_area1 + i * type->byte_size,
1033 (char *) real_area2 + i * type->byte_size,
1034 snapshot1, snapshot2, previous, type, -1,
1043 for(simgrid::mc::Type& member : type->members) {
1044 // TODO, optimize this? (for the offset case)
1045 void *real_member1 =
1046 mc_member_resolve(real_area1, type, &member, (mc_address_space_t) snapshot1, process_index);
1047 void *real_member2 =
1048 mc_member_resolve(real_area2, type, &member, (mc_address_space_t) snapshot2, process_index);
1050 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1051 snapshot1, snapshot2,
1052 previous, member.subtype, -1,
1060 case DW_TAG_union_type:
1061 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1062 snapshot1, snapshot2, previous,
1063 type->byte_size, check_ignore);
1073 /** Infer the type of a part of the block from the type of the block
1075 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1077 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1079 * @param type_id DWARF type ID of the root address
1081 * @return DWARF type ID for given offset
1083 static mc_type_t get_offset_type(void *real_base_address, mc_type_t type,
1084 int offset, int area_size,
1085 mc_snapshot_t snapshot, int process_index)
1088 // Beginning of the block, the infered variable type if the type of the block:
1092 switch (type->type) {
1093 case DW_TAG_structure_type:
1094 case DW_TAG_class_type:
1095 if (type->full_type)
1096 type = type->full_type;
1098 if (area_size != -1 && type->byte_size != area_size) {
1099 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1104 for(simgrid::mc::Type& member : type->members) {
1106 if (member.has_offset_location()) {
1107 // We have the offset, use it directly (shortcut):
1108 if (member.offset() == offset)
1109 return member.subtype;
1112 mc_member_resolve(real_base_address, type, &member,
1113 snapshot, process_index);
1114 if ((char*) real_member - (char *) real_base_address == offset)
1115 return member.subtype;
1123 /* FIXME : other cases ? */
1131 * @param area1 Process address for state 1
1132 * @param area2 Process address for state 2
1133 * @param snapshot1 Snapshot of state 1
1134 * @param snapshot2 Snapshot of state 2
1135 * @param previous Pairs of blocks already compared on the current path (or NULL)
1136 * @param type_id Type of variable
1137 * @param pointer_level
1138 * @return 0 (same), 1 (different), -1
1140 int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
1141 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1142 mc_type_t type, int pointer_level)
1144 mc_process_t process = &mc_model_checker->process();
1146 struct s_mc_diff *state = mc_diff_info;
1149 ssize_t block1, frag1, block2, frag2;
1151 int check_ignore = 0;
1153 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1155 int offset1 = 0, offset2 = 0;
1156 int new_size1 = -1, new_size2 = -1;
1157 mc_type_t new_type1 = NULL, new_type2 = NULL;
1159 int match_pairs = 0;
1161 // This is the address of std_heap->heapinfo in the application process:
1162 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
1164 const malloc_info* heapinfos1 = snapshot1->read(
1165 remote((const malloc_info**)heapinfo_address), process_index);
1166 const malloc_info* heapinfos2 = snapshot2->read(
1167 remote((const malloc_info**)heapinfo_address), process_index);
1169 malloc_info heapinfo_temp1, heapinfo_temp2;
1171 if (previous == NULL) {
1173 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1176 // Get block number:
1179 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1182 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1184 // If either block is a stack block:
1185 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1186 add_heap_area_pair(previous, block1, -1, block2, -1);
1188 match_equals(state, previous);
1189 xbt_dynar_free(&previous);
1193 // If either block is not in the expected area of memory:
1194 if (((char *) area1 < (char *) state->std_heap_copy.heapbase)
1195 || (block1 > (ssize_t) state->heapsize1) || (block1 < 1)
1196 || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
1197 || (block2 > (ssize_t) state->heapsize2) || (block2 < 1)) {
1199 xbt_dynar_free(&previous);
1204 // Process address of the block:
1205 real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
1206 (char *) state->std_heap_copy.heapbase;
1207 real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
1208 (char *) state->std_heap_copy.heapbase;
1212 if (type->full_type)
1213 type = type->full_type;
1215 // This assume that for "boring" types (volatile ...) byte_size is absent:
1216 while (type->byte_size == 0 && type->subtype != NULL)
1217 type = type->subtype;
1220 if ((type->type == DW_TAG_pointer_type)
1221 || ((type->type == DW_TAG_base_type) && !type->name.empty()
1222 && type->name == "char"))
1225 type_size = type->byte_size;
1229 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1230 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1232 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
1233 heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
1234 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
1235 heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
1237 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1238 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1242 match_equals(state, previous);
1243 xbt_dynar_free(&previous);
1247 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1248 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1249 /* Complete block */
1251 // TODO, lookup variable type from block type as done for fragmented blocks
1253 offset1 = (char *) area1 - (char *) real_addr_block1;
1254 offset2 = (char *) area2 - (char *) real_addr_block2;
1256 if (state->equals_to1_(block1, 0).valid
1257 && state->equals_to2_(block2, 0).valid) {
1258 if (equal_blocks(state, block1, block2)) {
1260 match_equals(state, previous);
1261 xbt_dynar_free(&previous);
1267 if (type_size != -1) {
1268 if (type_size != (ssize_t) heapinfo1->busy_block.busy_size
1269 && type_size != (ssize_t) heapinfo2->busy_block.busy_size
1270 && (type->name.empty() || type->name == "struct s_smx_context")) {
1272 match_equals(state, previous);
1273 xbt_dynar_free(&previous);
1279 if (heapinfo1->busy_block.size !=
1280 heapinfo2->busy_block.size) {
1282 xbt_dynar_free(&previous);
1287 if (heapinfo1->busy_block.busy_size !=
1288 heapinfo2->busy_block.busy_size) {
1290 xbt_dynar_free(&previous);
1295 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1297 match_equals(state, previous);
1298 xbt_dynar_free(&previous);
1303 size = heapinfo1->busy_block.busy_size;
1305 // Remember (basic) type inference.
1306 // The current data structure only allows us to do this for the whole block.
1307 if (type != NULL && area1 == real_addr_block1) {
1308 state->types1_(block1, 0) = type;
1310 if (type != NULL && area2 == real_addr_block2) {
1311 state->types2_(block2, 0) = type;
1316 match_equals(state, previous);
1317 xbt_dynar_free(&previous);
1325 if ((heapinfo1->busy_block.ignore > 0)
1326 && (heapinfo2->busy_block.ignore ==
1327 heapinfo1->busy_block.ignore))
1328 check_ignore = heapinfo1->busy_block.ignore;
1330 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1334 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1336 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1338 // Process address of the fragment:
1340 (void *) ((char *) real_addr_block1 +
1341 (frag1 << heapinfo1->type));
1343 (void *) ((char *) real_addr_block2 +
1344 (frag2 << heapinfo2->type));
1346 // Check the size of the fragments against the size of the type:
1347 if (type_size != -1) {
1348 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1349 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1351 match_equals(state, previous);
1352 xbt_dynar_free(&previous);
1357 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1358 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1360 match_equals(state, previous);
1361 xbt_dynar_free(&previous);
1367 // Check if the blocks are already matched together:
1368 if (state->equals_to1_(block1, frag1).valid
1369 && state->equals_to2_(block2, frag2).valid) {
1370 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1372 match_equals(state, previous);
1373 xbt_dynar_free(&previous);
1378 // Compare the size of both fragments:
1379 if (heapinfo1->busy_frag.frag_size[frag1] !=
1380 heapinfo2->busy_frag.frag_size[frag2]) {
1381 if (type_size == -1) {
1383 match_equals(state, previous);
1384 xbt_dynar_free(&previous);
1389 xbt_dynar_free(&previous);
1395 // Size of the fragment:
1396 size = heapinfo1->busy_frag.frag_size[frag1];
1398 // Remember (basic) type inference.
1399 // The current data structure only allows us to do this for the whole fragment.
1400 if (type != NULL && area1 == real_addr_frag1) {
1401 state->types1_(block1, frag1) = type;
1403 if (type != NULL && area2 == real_addr_frag2) {
1404 state->types2_(block2, frag2) = type;
1406 // The type of the variable is already known:
1411 // Type inference from the block type.
1412 else if (state->types1_(block1, frag1) != NULL
1413 || state->types2_(block2, frag2) != NULL) {
1415 offset1 = (char *) area1 - (char *) real_addr_frag1;
1416 offset2 = (char *) area2 - (char *) real_addr_frag2;
1418 if (state->types1_(block1, frag1) != NULL
1419 && state->types2_(block2, frag2) != NULL) {
1421 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1422 offset1, size, snapshot1, process_index);
1424 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1425 offset1, size, snapshot2, process_index);
1426 } else if (state->types1_(block1, frag1) != NULL) {
1428 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1429 offset1, size, snapshot1, process_index);
1431 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1432 offset2, size, snapshot2, process_index);
1433 } else if (state->types2_(block2, frag2) != NULL) {
1435 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1436 offset1, size, snapshot1, process_index);
1438 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1439 offset2, size, snapshot2, process_index);
1442 match_equals(state, previous);
1443 xbt_dynar_free(&previous);
1448 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1451 while (type->byte_size == 0 && type->subtype != NULL)
1452 type = type->subtype;
1453 new_size1 = type->byte_size;
1456 while (type->byte_size == 0 && type->subtype != NULL)
1457 type = type->subtype;
1458 new_size2 = type->byte_size;
1462 match_equals(state, previous);
1463 xbt_dynar_free(&previous);
1469 if (new_size1 > 0 && new_size1 == new_size2) {
1474 if (offset1 == 0 && offset2 == 0) {
1475 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1477 match_equals(state, previous);
1478 xbt_dynar_free(&previous);
1486 match_equals(state, previous);
1487 xbt_dynar_free(&previous);
1492 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1493 && (heapinfo2->busy_frag.ignore[frag2] ==
1494 heapinfo1->busy_frag.ignore[frag1]))
1495 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1500 xbt_dynar_free(&previous);
1507 /* Start comparison */
1510 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1511 previous, type, size, check_ignore,
1515 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1516 previous, size, check_ignore);
1518 if (res_compare == 1) {
1520 xbt_dynar_free(&previous);
1525 match_equals(state, previous);
1526 xbt_dynar_free(&previous);
1532 /*********************************************** Miscellaneous ***************************************************/
1533 /****************************************************************************************************************/
1535 // Not used and broken code:
1539 static int get_pointed_area_size(void *area, int heap)
1542 struct s_mc_diff *state = mc_diff_info;
1545 malloc_info *heapinfo;
1548 heapinfo = state->heapinfo1;
1550 heapinfo = state->heapinfo2;
1554 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1556 if (((char *) area < (char *) state->std_heap_copy.heapbase)
1557 || (block > state->heapsize1) || (block < 1))
1560 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1562 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1563 return (int) heapinfo[block].busy_block.busy_size;
1566 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1567 return (int) heapinfo[block].busy_frag.frag_size[frag];
1572 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1576 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1579 struct s_mc_diff *state = mc_diff_info;
1581 if (heap1 == NULL && heap1 == NULL) {
1582 XBT_DEBUG("Malloc descriptors null");
1586 if (heap1->heaplimit != heap2->heaplimit) {
1587 XBT_DEBUG("Different limit of valid info table indices");
1591 /* Heap information */
1592 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1594 state->std_heap_copy = *mc_model_checker->process().get_heap();
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) !=