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 dw_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 = (s_dw_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 = (s_dw_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, dw_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 dw_type_t subtype, subsubtype;
898 unsigned int cursor = 0;
900 const void *addr_pointed1, *addr_pointed2;;
902 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
903 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
905 switch (type->type) {
906 case DW_TAG_unspecified_type:
909 case DW_TAG_base_type:
910 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
911 if (real_area1 == real_area2)
914 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
916 if (area_size != -1 && type->byte_size != area_size)
919 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
923 case DW_TAG_enumeration_type:
924 if (area_size != -1 && type->byte_size != area_size)
927 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
930 case DW_TAG_const_type:
931 case DW_TAG_volatile_type:
933 type = type->subtype;
936 case DW_TAG_array_type:
937 subtype = type->subtype;
938 switch (subtype->type) {
939 case DW_TAG_unspecified_type:
942 case DW_TAG_base_type:
943 case DW_TAG_enumeration_type:
944 case DW_TAG_pointer_type:
945 case DW_TAG_reference_type:
946 case DW_TAG_rvalue_reference_type:
947 case DW_TAG_structure_type:
948 case DW_TAG_class_type:
949 case DW_TAG_union_type:
950 if (subtype->full_type)
951 subtype = subtype->full_type;
952 elm_size = subtype->byte_size;
954 // TODO, just remove the type indirection?
955 case DW_TAG_const_type:
957 case DW_TAG_volatile_type:
958 subsubtype = subtype->subtype;
959 if (subsubtype->full_type)
960 subsubtype = subsubtype->full_type;
961 elm_size = subsubtype->byte_size;
967 for (int i = 0; i < type->element_count; i++) {
968 // TODO, add support for variable stride (DW_AT_byte_stride)
970 compare_heap_area_with_type(state, process_index,
971 (char *) real_area1 + (i * elm_size),
972 (char *) real_area2 + (i * elm_size),
973 snapshot1, snapshot2, previous,
974 type->subtype, subtype->byte_size,
975 check_ignore, pointer_level);
980 case DW_TAG_reference_type:
981 case DW_TAG_rvalue_reference_type:
982 case DW_TAG_pointer_type:
983 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
984 addr_pointed1 = snapshot1->read(remote((void**)real_area1), process_index);
985 addr_pointed2 = snapshot2->read(remote((void**)real_area2), process_index);
986 return (addr_pointed1 != addr_pointed2);;
989 if (pointer_level > 1) { /* Array of pointers */
990 for (size_t i = 0; i < (area_size / sizeof(void *)); i++) {
991 addr_pointed1 = snapshot1->read(
992 remote((void**)((char*) real_area1 + i * sizeof(void *))),
994 addr_pointed2 = snapshot2->read(
995 remote((void**)((char*) real_area2 + i * sizeof(void *))),
997 if (addr_pointed1 > state->std_heap_copy.heapbase
998 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
999 && addr_pointed2 > state->std_heap_copy.heapbase
1000 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1002 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1003 snapshot2, previous, type->subtype,
1006 res = (addr_pointed1 != addr_pointed2);
1011 addr_pointed1 = snapshot1->read(remote((void**)real_area1), process_index);
1012 addr_pointed2 = snapshot2->read(remote((void**)real_area2), process_index);
1013 if (addr_pointed1 > state->std_heap_copy.heapbase
1014 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
1015 && addr_pointed2 > state->std_heap_copy.heapbase
1016 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1017 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1018 snapshot2, previous, type->subtype,
1021 return (addr_pointed1 != addr_pointed2);
1025 case DW_TAG_structure_type:
1026 case DW_TAG_class_type:
1027 if (type->full_type)
1028 type = type->full_type;
1029 if (area_size != -1 && type->byte_size != area_size) {
1030 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1031 for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) {
1033 compare_heap_area_with_type(state, process_index,
1034 (char *) real_area1 + i * type->byte_size,
1035 (char *) real_area2 + i * type->byte_size,
1036 snapshot1, snapshot2, previous, type, -1,
1046 xbt_dynar_foreach(type->members, cursor, member) {
1047 // TODO, optimize this? (for the offset case)
1048 void *real_member1 =
1049 mc_member_resolve(real_area1, type, member, (mc_address_space_t) snapshot1, process_index);
1050 void *real_member2 =
1051 mc_member_resolve(real_area2, type, member, (mc_address_space_t) snapshot2, process_index);
1053 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1054 snapshot1, snapshot2,
1055 previous, member->subtype, -1,
1063 case DW_TAG_union_type:
1064 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1065 snapshot1, snapshot2, previous,
1066 type->byte_size, check_ignore);
1076 /** Infer the type of a part of the block from the type of the block
1078 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1080 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1082 * @param type_id DWARF type ID of the root address
1084 * @return DWARF type ID for given offset
1086 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1087 int offset, int area_size,
1088 mc_snapshot_t snapshot, int process_index)
1091 // Beginning of the block, the infered variable type if the type of the block:
1095 switch (type->type) {
1096 case DW_TAG_structure_type:
1097 case DW_TAG_class_type:
1098 if (type->full_type)
1099 type = type->full_type;
1101 if (area_size != -1 && type->byte_size != area_size) {
1102 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1107 unsigned int cursor = 0;
1109 xbt_dynar_foreach(type->members, cursor, member) {
1111 if (!member->location.size) {
1112 // We have the offset, use it directly (shortcut):
1113 if (member->offset == offset)
1114 return member->subtype;
1117 mc_member_resolve(real_base_address, type, member,
1118 snapshot, process_index);
1119 if ((char*) real_member - (char *) real_base_address == offset)
1120 return member->subtype;
1128 /* FIXME : other cases ? */
1136 * @param area1 Process address for state 1
1137 * @param area2 Process address for state 2
1138 * @param snapshot1 Snapshot of state 1
1139 * @param snapshot2 Snapshot of state 2
1140 * @param previous Pairs of blocks already compared on the current path (or NULL)
1141 * @param type_id Type of variable
1142 * @param pointer_level
1143 * @return 0 (same), 1 (different), -1
1145 int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
1146 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1147 dw_type_t type, int pointer_level)
1149 mc_process_t process = &mc_model_checker->process();
1151 struct s_mc_diff *state = mc_diff_info;
1154 ssize_t block1, frag1, block2, frag2;
1156 int check_ignore = 0;
1158 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1160 int offset1 = 0, offset2 = 0;
1161 int new_size1 = -1, new_size2 = -1;
1162 dw_type_t new_type1 = NULL, new_type2 = NULL;
1164 int match_pairs = 0;
1166 // This is the address of std_heap->heapinfo in the application process:
1167 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
1169 const malloc_info* heapinfos1 = snapshot1->read(
1170 remote((const malloc_info**)heapinfo_address), process_index);
1171 const malloc_info* heapinfos2 = snapshot2->read(
1172 remote((const malloc_info**)heapinfo_address), process_index);
1174 malloc_info heapinfo_temp1, heapinfo_temp2;
1176 if (previous == NULL) {
1178 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1181 // Get block number:
1184 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1187 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1189 // If either block is a stack block:
1190 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1191 add_heap_area_pair(previous, block1, -1, block2, -1);
1193 match_equals(state, previous);
1194 xbt_dynar_free(&previous);
1198 // If either block is not in the expected area of memory:
1199 if (((char *) area1 < (char *) state->std_heap_copy.heapbase)
1200 || (block1 > (ssize_t) state->heapsize1) || (block1 < 1)
1201 || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
1202 || (block2 > (ssize_t) state->heapsize2) || (block2 < 1)) {
1204 xbt_dynar_free(&previous);
1209 // Process address of the block:
1210 real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
1211 (char *) state->std_heap_copy.heapbase;
1212 real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
1213 (char *) state->std_heap_copy.heapbase;
1217 if (type->full_type)
1218 type = type->full_type;
1220 // This assume that for "boring" types (volatile ...) byte_size is absent:
1221 while (type->byte_size == 0 && type->subtype != NULL)
1222 type = type->subtype;
1225 if ((type->type == DW_TAG_pointer_type)
1226 || ((type->type == DW_TAG_base_type) && type->name != NULL
1227 && (!strcmp(type->name, "char"))))
1230 type_size = type->byte_size;
1234 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1235 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1237 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
1238 heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
1239 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
1240 heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
1242 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1243 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1247 match_equals(state, previous);
1248 xbt_dynar_free(&previous);
1252 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1253 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1254 /* Complete block */
1256 // TODO, lookup variable type from block type as done for fragmented blocks
1258 offset1 = (char *) area1 - (char *) real_addr_block1;
1259 offset2 = (char *) area2 - (char *) real_addr_block2;
1261 if (state->equals_to1_(block1, 0).valid
1262 && state->equals_to2_(block2, 0).valid) {
1263 if (equal_blocks(state, block1, block2)) {
1265 match_equals(state, previous);
1266 xbt_dynar_free(&previous);
1272 if (type_size != -1) {
1273 if (type_size != (ssize_t) heapinfo1->busy_block.busy_size
1274 && type_size != (ssize_t) heapinfo2->busy_block.busy_size
1275 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1277 match_equals(state, previous);
1278 xbt_dynar_free(&previous);
1284 if (heapinfo1->busy_block.size !=
1285 heapinfo2->busy_block.size) {
1287 xbt_dynar_free(&previous);
1292 if (heapinfo1->busy_block.busy_size !=
1293 heapinfo2->busy_block.busy_size) {
1295 xbt_dynar_free(&previous);
1300 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1302 match_equals(state, previous);
1303 xbt_dynar_free(&previous);
1308 size = heapinfo1->busy_block.busy_size;
1310 // Remember (basic) type inference.
1311 // The current data structure only allows us to do this for the whole block.
1312 if (type != NULL && area1 == real_addr_block1) {
1313 state->types1_(block1, 0) = type;
1315 if (type != NULL && area2 == real_addr_block2) {
1316 state->types2_(block2, 0) = type;
1321 match_equals(state, previous);
1322 xbt_dynar_free(&previous);
1330 if ((heapinfo1->busy_block.ignore > 0)
1331 && (heapinfo2->busy_block.ignore ==
1332 heapinfo1->busy_block.ignore))
1333 check_ignore = heapinfo1->busy_block.ignore;
1335 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1339 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1341 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1343 // Process address of the fragment:
1345 (void *) ((char *) real_addr_block1 +
1346 (frag1 << heapinfo1->type));
1348 (void *) ((char *) real_addr_block2 +
1349 (frag2 << heapinfo2->type));
1351 // Check the size of the fragments against the size of the type:
1352 if (type_size != -1) {
1353 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1354 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1356 match_equals(state, previous);
1357 xbt_dynar_free(&previous);
1362 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1363 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1365 match_equals(state, previous);
1366 xbt_dynar_free(&previous);
1372 // Check if the blocks are already matched together:
1373 if (state->equals_to1_(block1, frag1).valid
1374 && state->equals_to2_(block2, frag2).valid) {
1375 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1377 match_equals(state, previous);
1378 xbt_dynar_free(&previous);
1383 // Compare the size of both fragments:
1384 if (heapinfo1->busy_frag.frag_size[frag1] !=
1385 heapinfo2->busy_frag.frag_size[frag2]) {
1386 if (type_size == -1) {
1388 match_equals(state, previous);
1389 xbt_dynar_free(&previous);
1394 xbt_dynar_free(&previous);
1400 // Size of the fragment:
1401 size = heapinfo1->busy_frag.frag_size[frag1];
1403 // Remember (basic) type inference.
1404 // The current data structure only allows us to do this for the whole fragment.
1405 if (type != NULL && area1 == real_addr_frag1) {
1406 state->types1_(block1, frag1) = type;
1408 if (type != NULL && area2 == real_addr_frag2) {
1409 state->types2_(block2, frag2) = type;
1411 // The type of the variable is already known:
1416 // Type inference from the block type.
1417 else if (state->types1_(block1, frag1) != NULL
1418 || state->types2_(block2, frag2) != NULL) {
1420 offset1 = (char *) area1 - (char *) real_addr_frag1;
1421 offset2 = (char *) area2 - (char *) real_addr_frag2;
1423 if (state->types1_(block1, frag1) != NULL
1424 && state->types2_(block2, frag2) != NULL) {
1426 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1427 offset1, size, snapshot1, process_index);
1429 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1430 offset1, size, snapshot2, process_index);
1431 } else if (state->types1_(block1, frag1) != NULL) {
1433 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1434 offset1, size, snapshot1, process_index);
1436 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1437 offset2, size, snapshot2, process_index);
1438 } else if (state->types2_(block2, frag2) != NULL) {
1440 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1441 offset1, size, snapshot1, process_index);
1443 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1444 offset2, size, snapshot2, process_index);
1447 match_equals(state, previous);
1448 xbt_dynar_free(&previous);
1453 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1456 while (type->byte_size == 0 && type->subtype != NULL)
1457 type = type->subtype;
1458 new_size1 = type->byte_size;
1461 while (type->byte_size == 0 && type->subtype != NULL)
1462 type = type->subtype;
1463 new_size2 = type->byte_size;
1467 match_equals(state, previous);
1468 xbt_dynar_free(&previous);
1474 if (new_size1 > 0 && new_size1 == new_size2) {
1479 if (offset1 == 0 && offset2 == 0) {
1480 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1482 match_equals(state, previous);
1483 xbt_dynar_free(&previous);
1491 match_equals(state, previous);
1492 xbt_dynar_free(&previous);
1497 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1498 && (heapinfo2->busy_frag.ignore[frag2] ==
1499 heapinfo1->busy_frag.ignore[frag1]))
1500 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1505 xbt_dynar_free(&previous);
1512 /* Start comparison */
1515 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1516 previous, type, size, check_ignore,
1520 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1521 previous, size, check_ignore);
1523 if (res_compare == 1) {
1525 xbt_dynar_free(&previous);
1530 match_equals(state, previous);
1531 xbt_dynar_free(&previous);
1537 /*********************************************** Miscellaneous ***************************************************/
1538 /****************************************************************************************************************/
1540 // Not used and broken code:
1544 static int get_pointed_area_size(void *area, int heap)
1547 struct s_mc_diff *state = mc_diff_info;
1550 malloc_info *heapinfo;
1553 heapinfo = state->heapinfo1;
1555 heapinfo = state->heapinfo2;
1559 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1561 if (((char *) area < (char *) state->std_heap_copy.heapbase)
1562 || (block > state->heapsize1) || (block < 1))
1565 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1567 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1568 return (int) heapinfo[block].busy_block.busy_size;
1571 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1572 return (int) heapinfo[block].busy_frag.frag_size[frag];
1577 char *get_type_description(mc_object_info_t info, char *type_name)
1580 xbt_dict_cursor_t dict_cursor;
1584 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1585 if (type->name && (strcmp(type->name, type_name) == 0)
1586 && type->byte_size > 0) {
1587 xbt_dict_cursor_free(&dict_cursor);
1592 xbt_dict_cursor_free(&dict_cursor);
1598 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1602 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1605 struct s_mc_diff *state = mc_diff_info;
1607 if (heap1 == NULL && heap1 == NULL) {
1608 XBT_DEBUG("Malloc descriptors null");
1612 if (heap1->heaplimit != heap2->heaplimit) {
1613 XBT_DEBUG("Different limit of valid info table indices");
1617 /* Heap information */
1618 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1620 state->std_heap_copy = *mc_model_checker->process().get_heap();
1622 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1623 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1626 (malloc_info *) ((char *) heap1 +
1628 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1630 (malloc_info *) ((char *) heap2 +
1632 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1634 state->heapsize1 = heap1->heapsize;
1635 state->heapsize2 = heap2->heapsize;
1637 /* Start comparison */
1639 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1643 /* Check busy blocks */
1647 while (i <= state->heaplimit) {
1650 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1651 (char *) state->heapbase1));
1653 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1654 (char *) state->heapbase2));
1656 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1658 distance += BLOCKSIZE;
1659 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1660 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1665 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1666 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1671 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1673 if (state->heapinfo1[i].busy_block.size !=
1674 state->heapinfo2[i].busy_block.size) {
1676 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1677 state->heapinfo2[i].busy_block.size);
1678 i += max(state->heapinfo1[i].busy_block.size,
1679 state->heapinfo2[i].busy_block.size);
1681 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1682 i, state->heapinfo1[i].busy_block.size,
1683 state->heapinfo2[i].busy_block.size, distance);
1687 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1688 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1689 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1690 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);
1696 //while(k < (heapinfo1[i].busy_block.busy_size)){
1697 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1698 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1707 } else { /* Fragmented block */
1709 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1712 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1714 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1716 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1717 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1722 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1723 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1724 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);
1730 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1731 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1732 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=