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"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
21 "Logging specific to mc_diff in mc");
23 xbt_dynar_t mc_heap_comparison_ignore;
24 xbt_dynar_t stacks_areas;
28 /********************************* Backtrace ***********************************/
29 /******************************************************************************/
31 static void mmalloc_backtrace_block_display(void *heapinfo, int block)
36 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
37 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
41 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
42 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
44 /* xbt_ex_setup_backtrace(&e); */
45 /* if (e.used == 0) { */
46 /* fprintf(stderr, "(backtrace not set)\n"); */
47 /* } else if (e.bt_strings == NULL) { */
48 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
52 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
53 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
54 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
59 static void mmalloc_backtrace_fragment_display(void *heapinfo, int block,
65 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
66 /* e.used = XBT_BACKTRACE_SIZE; */
68 /* xbt_ex_setup_backtrace(&e); */
69 /* if (e.used == 0) { */
70 /* fprintf(stderr, "(backtrace not set)\n"); */
71 /* } else if (e.bt_strings == NULL) { */
72 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
76 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
77 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
78 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
84 static void mmalloc_backtrace_display(void *addr)
87 /* size_t block, frag_nb; */
90 /* xbt_mheap_t heap = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); */
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 xbt_dynar_t to_ignore1, to_ignore2;
152 s_heap_area_t *equals_to1, *equals_to2;
153 dw_type_t *types1, *types2;
157 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
158 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
159 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
160 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
162 __thread struct s_mc_diff *mc_diff_info = NULL;
164 /*********************************** Free functions ************************************/
166 static void heap_area_pair_free(heap_area_pair_t pair)
172 static void heap_area_pair_free_voidp(void *d)
174 heap_area_pair_free((heap_area_pair_t) * (void **) d);
177 static void heap_area_free(heap_area_t area)
183 /************************************************************************************/
185 static s_heap_area_t make_heap_area(int block, int fragment)
190 area.fragment = fragment;
195 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
196 int block2, int fragment2)
199 unsigned int cursor = 0;
200 heap_area_pair_t current_pair;
202 xbt_dynar_foreach(list, cursor, current_pair) {
203 if (current_pair->block1 == block1 && current_pair->block2 == block2
204 && current_pair->fragment1 == fragment1
205 && current_pair->fragment2 == fragment2)
212 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
213 int block2, int fragment2)
216 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
217 heap_area_pair_t pair = NULL;
218 pair = xbt_new0(s_heap_area_pair_t, 1);
219 pair->block1 = block1;
220 pair->fragment1 = fragment1;
221 pair->block2 = block2;
222 pair->fragment2 = fragment2;
224 xbt_dynar_push(list, &pair);
232 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
236 unsigned int cursor = 0;
238 int end = xbt_dynar_length(ignore_list) - 1;
239 mc_heap_ignore_region_t region;
241 while (start <= end) {
242 cursor = (start + end) / 2;
244 (mc_heap_ignore_region_t) xbt_dynar_get_as(ignore_list, cursor,
245 mc_heap_ignore_region_t);
246 if (region->address == address)
248 if (region->address < address)
250 if (region->address > address)
257 static int is_stack(const void *address)
259 unsigned int cursor = 0;
260 stack_region_t stack;
262 xbt_dynar_foreach(stacks_areas, cursor, stack) {
263 if (address == stack->address)
270 // TODO, this should depend on the snapshot?
271 static int is_block_stack(int block)
273 unsigned int cursor = 0;
274 stack_region_t stack;
276 xbt_dynar_foreach(stacks_areas, cursor, stack) {
277 if (block == stack->block)
284 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
287 unsigned int cursor = 0;
288 heap_area_pair_t current_pair;
290 xbt_dynar_foreach(list, cursor, current_pair) {
292 if (current_pair->fragment1 != -1) {
294 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
295 make_heap_area(current_pair->block2, current_pair->fragment2);
296 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
297 make_heap_area(current_pair->block1, current_pair->fragment1);
301 state->equals_to1_(current_pair->block1, 0) =
302 make_heap_area(current_pair->block2, current_pair->fragment2);
303 state->equals_to2_(current_pair->block2, 0) =
304 make_heap_area(current_pair->block1, current_pair->fragment1);
311 /** Check whether two blocks are known to be matching
313 * @param state State used
314 * @param b1 Block of state 1
315 * @param b2 Block of state 2
316 * @return if the blocks are known to be matching
318 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
321 if (state->equals_to1_(b1, 0).block == b2
322 && state->equals_to2_(b2, 0).block == b1)
328 /** Check whether two fragments are known to be matching
330 * @param state State used
331 * @param b1 Block of state 1
332 * @param f1 Fragment of state 1
333 * @param b2 Block of state 2
334 * @param f2 Fragment of state 2
335 * @return if the fragments are known to be matching
337 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
341 if (state->equals_to1_(b1, f1).block == b2
342 && state->equals_to1_(b1, f1).fragment == f2
343 && state->equals_to2_(b2, f2).block == b1
344 && state->equals_to2_(b2, f2).fragment == f1)
350 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
353 if (mc_diff_info == NULL) {
354 mc_diff_info = xbt_new0(struct s_mc_diff, 1);
355 mc_diff_info->equals_to1 = NULL;
356 mc_diff_info->equals_to2 = NULL;
357 mc_diff_info->types1 = NULL;
358 mc_diff_info->types2 = NULL;
360 struct s_mc_diff *state = mc_diff_info;
362 if ((((struct mdesc *) heap1)->heaplimit !=
363 ((struct mdesc *) heap2)->heaplimit)
365 ((((struct mdesc *) heap1)->heapsize !=
366 ((struct mdesc *) heap2)->heapsize)))
369 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
371 state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process());
373 state->heapsize1 = heap1->heapsize;
374 state->heapsize2 = heap2->heapsize;
376 state->to_ignore1 = i1;
377 state->to_ignore2 = i2;
379 if (state->heaplimit > state->available) {
380 state->equals_to1 = (s_heap_area_t*)
381 realloc(state->equals_to1,
382 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
383 sizeof(s_heap_area_t));
384 state->types1 = (s_dw_type**)
385 realloc(state->types1,
386 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
387 sizeof(type_name *));
388 state->equals_to2 = (s_heap_area_t*)
389 realloc(state->equals_to2,
390 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
391 sizeof(s_heap_area_t));
392 state->types2 = (s_dw_type**)
393 realloc(state->types2,
394 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
395 sizeof(type_name *));
396 state->available = state->heaplimit;
399 memset(state->equals_to1, 0,
400 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
401 memset(state->equals_to2, 0,
402 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
403 memset(state->types1, 0,
404 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
405 memset(state->types2, 0,
406 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
412 void reset_heap_information()
417 // TODO, have a robust way to find it in O(1)
419 mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
421 size_t n = snapshot->snapshot_regions_count;
422 for (size_t i=0; i!=n; ++i) {
423 mc_mem_region_t region = snapshot->snapshot_regions[i];
424 if (region->region_type == MC_REGION_TYPE_HEAP)
427 xbt_die("No heap region");
430 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
432 mc_process_t process = &mc_model_checker->process();
433 struct s_mc_diff *state = mc_diff_info;
435 /* Start comparison */
436 size_t i1, i2, j1, j2, k;
437 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
438 int nb_diff1 = 0, nb_diff2 = 0;
440 int equal, res_compare = 0;
442 /* Check busy blocks */
446 malloc_info heapinfo_temp1, heapinfo_temp2;
447 malloc_info heapinfo_temp2b;
449 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
450 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
452 // This is the address of std_heap->heapinfo in the application process:
453 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
455 // This is in snapshot do not use them directly:
456 const malloc_info* heapinfos1 = (const malloc_info*) MC_snapshot_read_pointer(snapshot1, heapinfo_address, MC_PROCESS_INDEX_MISSING);
457 const malloc_info* heapinfos2 = (const malloc_info*) MC_snapshot_read_pointer(snapshot2, heapinfo_address, MC_PROCESS_INDEX_MISSING);
459 while (i1 <= state->heaplimit) {
461 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
462 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
464 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
469 if (heapinfo1->type < 0) {
470 fprintf(stderr, "Unkown mmalloc block type.\n");
475 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
476 (char *) state->std_heap_copy.heapbase));
478 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
480 if (is_stack(addr_block1)) {
481 for (k = 0; k < heapinfo1->busy_block.size; k++)
482 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
483 for (k = 0; k < heapinfo2->busy_block.size; k++)
484 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
485 i1 += heapinfo1->busy_block.size;
489 if (state->equals_to1_(i1, 0).valid) {
498 /* Try first to associate to same block in the other heap */
499 if (heapinfo2->type == heapinfo1->type) {
501 if (state->equals_to2_(i1, 0).valid == 0) {
503 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
504 (char *) state->std_heap_copy.heapbase;
507 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_block1, addr_block2, snapshot1, snapshot2,
510 if (res_compare != 1) {
511 for (k = 1; k < heapinfo2->busy_block.size; k++)
512 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
513 for (k = 1; k < heapinfo1->busy_block.size; k++)
514 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
516 i1 += heapinfo1->busy_block.size;
523 while (i2 <= state->heaplimit && !equal) {
525 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
526 (char *) state->std_heap_copy.heapbase;
533 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
535 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
540 if (state->equals_to2_(i2, 0).valid) {
546 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_block1, addr_block2, snapshot1, snapshot2,
549 if (res_compare != 1) {
550 for (k = 1; k < heapinfo2b->busy_block.size; k++)
551 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
552 for (k = 1; k < heapinfo1->busy_block.size; k++)
553 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
555 i1 += heapinfo1->busy_block.size;
563 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
564 heapinfo1->busy_block.busy_size, addr_block1);
565 i1 = state->heaplimit + 1;
570 } else { /* Fragmented block */
572 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
574 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
577 if (state->equals_to1_(i1, j1).valid)
581 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
586 /* Try first to associate to same fragment in the other heap */
587 if (heapinfo2->type == heapinfo1->type) {
589 if (state->equals_to2_(i1, j1).valid == 0) {
591 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
592 (char *) state->std_heap_copy.heapbase;
594 (void *) ((char *) addr_block2 +
595 (j1 << heapinfo2->type));
598 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_frag1, addr_frag2, snapshot1, snapshot2,
601 if (res_compare != 1)
608 while (i2 <= state->heaplimit && !equal) {
610 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
611 heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
612 sizeof(malloc_info));
614 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
619 // We currently do not match fragments with unfragmented blocks (maybe we should).
620 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
625 if (heapinfo2b->type < 0) {
626 fprintf(stderr, "Unkown mmalloc block type.\n");
630 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
633 if (i2 == i1 && j2 == j1)
636 if (state->equals_to2_(i2, j2).valid)
639 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
640 (char *) state->std_heap_copy.heapbase;
642 (void *) ((char *) addr_block2 +
643 (j2 << heapinfo2b->type));
646 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_frag1, addr_frag2, snapshot2, snapshot2,
649 if (res_compare != 1) {
662 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
663 i1, j1, heapinfo1->busy_frag.frag_size[j1],
665 i2 = state->heaplimit + 1;
666 i1 = state->heaplimit + 1;
679 /* All blocks/fragments are equal to another block/fragment ? */
682 for(i = 1; i <= state->heaplimit; i++) {
683 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
684 heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
685 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
686 if (i1 == state->heaplimit) {
687 if (heapinfo1->busy_block.busy_size > 0) {
688 if (state->equals_to1_(i, 0).valid == 0) {
689 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
691 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
692 heapinfo1->busy_block.busy_size);
693 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
700 if (heapinfo1->type > 0) {
701 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
702 if (i1 == state->heaplimit) {
703 if (heapinfo1->busy_frag.frag_size[j] > 0) {
704 if (state->equals_to1_(i, j).valid == 0) {
705 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
706 // TODO, print fragment address
708 ("Block %zu, Fragment %zu not found (size used = %zd)",
710 heapinfo1->busy_frag.frag_size[j]);
711 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
721 if (i1 == state->heaplimit)
722 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
724 for (i=1; i <= state->heaplimit; i++) {
725 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
726 heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
727 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
728 if (i1 == state->heaplimit) {
729 if (heapinfo2->busy_block.busy_size > 0) {
730 if (state->equals_to2_(i, 0).valid == 0) {
731 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
732 // TODO, print address of the block
733 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
734 heapinfo2->busy_block.busy_size);
735 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
742 if (heapinfo2->type > 0) {
743 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
744 if (i1 == state->heaplimit) {
745 if (heapinfo2->busy_frag.frag_size[j] > 0) {
746 if (state->equals_to2_(i, j).valid == 0) {
747 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
748 // TODO, print address of the block
750 ("Block %zu, Fragment %zu not found (size used = %zd)",
752 heapinfo2->busy_frag.frag_size[j]);
753 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
763 if (i1 == state->heaplimit)
764 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
766 return ((nb_diff1 > 0) || (nb_diff2 > 0));
772 * @param real_area1 Process address for state 1
773 * @param real_area2 Process address for state 2
774 * @param snapshot1 Snapshot of state 1
775 * @param snapshot2 Snapshot of state 2
778 * @param check_ignore
780 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
781 const void *real_area1, const void *real_area2,
782 mc_snapshot_t snapshot1,
783 mc_snapshot_t snapshot2,
784 xbt_dynar_t previous, int size,
787 mc_process_t process = &mc_model_checker->process();
790 const void *addr_pointed1, *addr_pointed2;
791 int pointer_align, res_compare;
792 ssize_t ignore1, ignore2;
794 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
795 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
799 if (check_ignore > 0) {
801 heap_comparison_ignore_size(state->to_ignore1,
802 (char *) real_area1 + i)) != -1) {
804 heap_comparison_ignore_size(state->to_ignore2,
805 (char *) real_area2 + i)) == ignore1) {
818 if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
820 pointer_align = (i / sizeof(void *)) * sizeof(void *);
821 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char *) real_area1 + pointer_align, process_index);
822 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char *) real_area2 + pointer_align, process_index);
824 if (addr_pointed1 > process->maestro_stack_start
825 && addr_pointed1 < process->maestro_stack_end
826 && addr_pointed2 > process->maestro_stack_start
827 && addr_pointed2 < process->maestro_stack_end) {
828 i = pointer_align + sizeof(void *);
830 } else if (addr_pointed1 > state->std_heap_copy.heapbase
831 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
832 && addr_pointed2 > state->std_heap_copy.heapbase
833 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
834 // Both addreses are in the heap:
836 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
837 snapshot2, previous, NULL, 0);
838 if (res_compare == 1) {
841 i = pointer_align + sizeof(void *);
860 * @param real_area1 Process address for state 1
861 * @param real_area2 Process address for state 2
862 * @param snapshot1 Snapshot of state 1
863 * @param snapshot2 Snapshot of state 2
866 * @param area_size either a byte_size or an elements_count (?)
867 * @param check_ignore
868 * @param pointer_level
869 * @return 0 (same), 1 (different), -1 (unknown)
871 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
872 const void *real_area1, const void *real_area2,
873 mc_snapshot_t snapshot1,
874 mc_snapshot_t snapshot2,
875 xbt_dynar_t previous, dw_type_t type,
876 int area_size, int check_ignore,
880 if (is_stack(real_area1) && is_stack(real_area2))
883 ssize_t ignore1, ignore2;
885 if ((check_ignore > 0)
886 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
888 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
893 dw_type_t subtype, subsubtype;
895 unsigned int cursor = 0;
897 const void *addr_pointed1, *addr_pointed2;;
899 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
900 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
902 switch (type->type) {
903 case DW_TAG_unspecified_type:
906 case DW_TAG_base_type:
907 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
908 if (real_area1 == real_area2)
911 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
913 if (area_size != -1 && type->byte_size != area_size)
916 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
920 case DW_TAG_enumeration_type:
921 if (area_size != -1 && type->byte_size != area_size)
924 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
927 case DW_TAG_const_type:
928 case DW_TAG_volatile_type:
930 type = type->subtype;
933 case DW_TAG_array_type:
934 subtype = type->subtype;
935 switch (subtype->type) {
936 case DW_TAG_unspecified_type:
939 case DW_TAG_base_type:
940 case DW_TAG_enumeration_type:
941 case DW_TAG_pointer_type:
942 case DW_TAG_reference_type:
943 case DW_TAG_rvalue_reference_type:
944 case DW_TAG_structure_type:
945 case DW_TAG_class_type:
946 case DW_TAG_union_type:
947 if (subtype->full_type)
948 subtype = subtype->full_type;
949 elm_size = subtype->byte_size;
951 // TODO, just remove the type indirection?
952 case DW_TAG_const_type:
954 case DW_TAG_volatile_type:
955 subsubtype = subtype->subtype;
956 if (subsubtype->full_type)
957 subsubtype = subsubtype->full_type;
958 elm_size = subsubtype->byte_size;
964 for (int i = 0; i < type->element_count; i++) {
965 // TODO, add support for variable stride (DW_AT_byte_stride)
967 compare_heap_area_with_type(state, process_index,
968 (char *) real_area1 + (i * elm_size),
969 (char *) real_area2 + (i * elm_size),
970 snapshot1, snapshot2, previous,
971 type->subtype, subtype->byte_size,
972 check_ignore, pointer_level);
977 case DW_TAG_reference_type:
978 case DW_TAG_rvalue_reference_type:
979 case DW_TAG_pointer_type:
980 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
981 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, real_area1, process_index);
982 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, real_area2, process_index);
983 return (addr_pointed1 != addr_pointed2);;
986 if (pointer_level > 1) { /* Array of pointers */
987 for (size_t i = 0; i < (area_size / sizeof(void *)); i++) {
988 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char*) real_area1 + i * sizeof(void *), process_index);
989 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char*) real_area2 + i * sizeof(void *), process_index);
990 if (addr_pointed1 > state->std_heap_copy.heapbase
991 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
992 && addr_pointed2 > state->std_heap_copy.heapbase
993 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
995 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
996 snapshot2, previous, type->subtype,
999 res = (addr_pointed1 != addr_pointed2);
1004 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, real_area1, process_index);
1005 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, real_area2, process_index);
1006 if (addr_pointed1 > state->std_heap_copy.heapbase
1007 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
1008 && addr_pointed2 > state->std_heap_copy.heapbase
1009 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1010 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1011 snapshot2, previous, type->subtype,
1014 return (addr_pointed1 != addr_pointed2);
1018 case DW_TAG_structure_type:
1019 case DW_TAG_class_type:
1020 if (type->full_type)
1021 type = type->full_type;
1022 if (area_size != -1 && type->byte_size != area_size) {
1023 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1024 for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) {
1026 compare_heap_area_with_type(state, process_index,
1027 (char *) real_area1 + i * type->byte_size,
1028 (char *) real_area2 + i * type->byte_size,
1029 snapshot1, snapshot2, previous, type, -1,
1039 xbt_dynar_foreach(type->members, cursor, member) {
1040 // TODO, optimize this? (for the offset case)
1041 void *real_member1 =
1042 mc_member_resolve(real_area1, type, member, (mc_address_space_t) snapshot1, process_index);
1043 void *real_member2 =
1044 mc_member_resolve(real_area2, type, member, (mc_address_space_t) snapshot2, process_index);
1046 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1047 snapshot1, snapshot2,
1048 previous, member->subtype, -1,
1056 case DW_TAG_union_type:
1057 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1058 snapshot1, snapshot2, previous,
1059 type->byte_size, check_ignore);
1069 /** Infer the type of a part of the block from the type of the block
1071 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1073 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1075 * @param type_id DWARF type ID of the root address
1077 * @return DWARF type ID for given offset
1079 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1080 int offset, int area_size,
1081 mc_snapshot_t snapshot, int process_index)
1084 // Beginning of the block, the infered variable type if the type of the block:
1088 switch (type->type) {
1089 case DW_TAG_structure_type:
1090 case DW_TAG_class_type:
1091 if (type->full_type)
1092 type = type->full_type;
1094 if (area_size != -1 && type->byte_size != area_size) {
1095 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1100 unsigned int cursor = 0;
1102 xbt_dynar_foreach(type->members, cursor, member) {
1104 if (!member->location.size) {
1105 // We have the offset, use it directly (shortcut):
1106 if (member->offset == offset)
1107 return member->subtype;
1110 mc_member_resolve(real_base_address, type, member,
1111 (mc_address_space_t) snapshot, process_index);
1112 if ((char*) real_member - (char *) real_base_address == offset)
1113 return member->subtype;
1121 /* FIXME : other cases ? */
1129 * @param area1 Process address for state 1
1130 * @param area2 Process address for state 2
1131 * @param snapshot1 Snapshot of state 1
1132 * @param snapshot2 Snapshot of state 2
1133 * @param previous Pairs of blocks already compared on the current path (or NULL)
1134 * @param type_id Type of variable
1135 * @param pointer_level
1136 * @return 0 (same), 1 (different), -1
1138 int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
1139 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1140 dw_type_t type, int pointer_level)
1142 mc_process_t process = &mc_model_checker->process();
1144 struct s_mc_diff *state = mc_diff_info;
1147 ssize_t block1, frag1, block2, frag2;
1149 int check_ignore = 0;
1151 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1153 int offset1 = 0, offset2 = 0;
1154 int new_size1 = -1, new_size2 = -1;
1155 dw_type_t new_type1 = NULL, new_type2 = NULL;
1157 int match_pairs = 0;
1159 // This is the address of std_heap->heapinfo in the application process:
1160 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
1162 const malloc_info* heapinfos1 = (const malloc_info*) MC_snapshot_read_pointer(
1163 snapshot1, heapinfo_address, process_index);
1164 const malloc_info* heapinfos2 = (const malloc_info*) MC_snapshot_read_pointer(
1165 snapshot2, heapinfo_address, process_index);
1167 malloc_info heapinfo_temp1, heapinfo_temp2;
1169 if (previous == NULL) {
1171 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1174 // Get block number:
1177 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1180 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1182 // If either block is a stack block:
1183 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1184 add_heap_area_pair(previous, block1, -1, block2, -1);
1186 match_equals(state, previous);
1187 xbt_dynar_free(&previous);
1191 // If either block is not in the expected area of memory:
1192 if (((char *) area1 < (char *) state->std_heap_copy.heapbase)
1193 || (block1 > (ssize_t) state->heapsize1) || (block1 < 1)
1194 || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
1195 || (block2 > (ssize_t) state->heapsize2) || (block2 < 1)) {
1197 xbt_dynar_free(&previous);
1202 // Process address of the block:
1203 real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
1204 (char *) state->std_heap_copy.heapbase;
1205 real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
1206 (char *) state->std_heap_copy.heapbase;
1210 if (type->full_type)
1211 type = type->full_type;
1213 // This assume that for "boring" types (volatile ...) byte_size is absent:
1214 while (type->byte_size == 0 && type->subtype != NULL)
1215 type = type->subtype;
1218 if ((type->type == DW_TAG_pointer_type)
1219 || ((type->type == DW_TAG_base_type) && type->name != NULL
1220 && (!strcmp(type->name, "char"))))
1223 type_size = type->byte_size;
1227 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1228 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1230 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
1231 heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
1232 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
1233 heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
1235 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1236 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1240 match_equals(state, previous);
1241 xbt_dynar_free(&previous);
1245 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1246 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1247 /* Complete block */
1249 // TODO, lookup variable type from block type as done for fragmented blocks
1251 offset1 = (char *) area1 - (char *) real_addr_block1;
1252 offset2 = (char *) area2 - (char *) real_addr_block2;
1254 if (state->equals_to1_(block1, 0).valid
1255 && state->equals_to2_(block2, 0).valid) {
1256 if (equal_blocks(state, block1, block2)) {
1258 match_equals(state, previous);
1259 xbt_dynar_free(&previous);
1265 if (type_size != -1) {
1266 if (type_size != (ssize_t) heapinfo1->busy_block.busy_size
1267 && type_size != (ssize_t) heapinfo2->busy_block.busy_size
1268 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1270 match_equals(state, previous);
1271 xbt_dynar_free(&previous);
1277 if (heapinfo1->busy_block.size !=
1278 heapinfo2->busy_block.size) {
1280 xbt_dynar_free(&previous);
1285 if (heapinfo1->busy_block.busy_size !=
1286 heapinfo2->busy_block.busy_size) {
1288 xbt_dynar_free(&previous);
1293 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1295 match_equals(state, previous);
1296 xbt_dynar_free(&previous);
1301 size = heapinfo1->busy_block.busy_size;
1303 // Remember (basic) type inference.
1304 // The current data structure only allows us to do this for the whole block.
1305 if (type != NULL && area1 == real_addr_block1) {
1306 state->types1_(block1, 0) = type;
1308 if (type != NULL && area2 == real_addr_block2) {
1309 state->types2_(block2, 0) = type;
1314 match_equals(state, previous);
1315 xbt_dynar_free(&previous);
1323 if ((heapinfo1->busy_block.ignore > 0)
1324 && (heapinfo2->busy_block.ignore ==
1325 heapinfo1->busy_block.ignore))
1326 check_ignore = heapinfo1->busy_block.ignore;
1328 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1332 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1334 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1336 // Process address of the fragment:
1338 (void *) ((char *) real_addr_block1 +
1339 (frag1 << heapinfo1->type));
1341 (void *) ((char *) real_addr_block2 +
1342 (frag2 << heapinfo2->type));
1344 // Check the size of the fragments against the size of the type:
1345 if (type_size != -1) {
1346 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1347 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1349 match_equals(state, previous);
1350 xbt_dynar_free(&previous);
1355 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1356 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1358 match_equals(state, previous);
1359 xbt_dynar_free(&previous);
1365 // Check if the blocks are already matched together:
1366 if (state->equals_to1_(block1, frag1).valid
1367 && state->equals_to2_(block2, frag2).valid) {
1368 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1370 match_equals(state, previous);
1371 xbt_dynar_free(&previous);
1376 // Compare the size of both fragments:
1377 if (heapinfo1->busy_frag.frag_size[frag1] !=
1378 heapinfo2->busy_frag.frag_size[frag2]) {
1379 if (type_size == -1) {
1381 match_equals(state, previous);
1382 xbt_dynar_free(&previous);
1387 xbt_dynar_free(&previous);
1393 // Size of the fragment:
1394 size = heapinfo1->busy_frag.frag_size[frag1];
1396 // Remember (basic) type inference.
1397 // The current data structure only allows us to do this for the whole fragment.
1398 if (type != NULL && area1 == real_addr_frag1) {
1399 state->types1_(block1, frag1) = type;
1401 if (type != NULL && area2 == real_addr_frag2) {
1402 state->types2_(block2, frag2) = type;
1404 // The type of the variable is already known:
1409 // Type inference from the block type.
1410 else if (state->types1_(block1, frag1) != NULL
1411 || state->types2_(block2, frag2) != NULL) {
1413 offset1 = (char *) area1 - (char *) real_addr_frag1;
1414 offset2 = (char *) area2 - (char *) real_addr_frag2;
1416 if (state->types1_(block1, frag1) != NULL
1417 && state->types2_(block2, frag2) != NULL) {
1419 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1420 offset1, size, snapshot1, process_index);
1422 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1423 offset1, size, snapshot2, process_index);
1424 } else if (state->types1_(block1, frag1) != 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->types1_(block1, frag1),
1430 offset2, size, snapshot2, process_index);
1431 } else if (state->types2_(block2, frag2) != NULL) {
1433 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1434 offset1, size, snapshot1, process_index);
1436 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1437 offset2, size, snapshot2, process_index);
1440 match_equals(state, previous);
1441 xbt_dynar_free(&previous);
1446 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1449 while (type->byte_size == 0 && type->subtype != NULL)
1450 type = type->subtype;
1451 new_size1 = type->byte_size;
1454 while (type->byte_size == 0 && type->subtype != NULL)
1455 type = type->subtype;
1456 new_size2 = type->byte_size;
1460 match_equals(state, previous);
1461 xbt_dynar_free(&previous);
1467 if (new_size1 > 0 && new_size1 == new_size2) {
1472 if (offset1 == 0 && offset2 == 0) {
1473 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1475 match_equals(state, previous);
1476 xbt_dynar_free(&previous);
1484 match_equals(state, previous);
1485 xbt_dynar_free(&previous);
1490 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1491 && (heapinfo2->busy_frag.ignore[frag2] ==
1492 heapinfo1->busy_frag.ignore[frag1]))
1493 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1498 xbt_dynar_free(&previous);
1505 /* Start comparison */
1508 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1509 previous, type, size, check_ignore,
1513 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1514 previous, size, check_ignore);
1516 if (res_compare == 1) {
1518 xbt_dynar_free(&previous);
1523 match_equals(state, previous);
1524 xbt_dynar_free(&previous);
1530 /*********************************************** Miscellaneous ***************************************************/
1531 /****************************************************************************************************************/
1533 // Not used and broken code:
1537 static int get_pointed_area_size(void *area, int heap)
1540 struct s_mc_diff *state = mc_diff_info;
1543 malloc_info *heapinfo;
1546 heapinfo = state->heapinfo1;
1548 heapinfo = state->heapinfo2;
1552 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1554 if (((char *) area < (char *) state->std_heap_copy.heapbase)
1555 || (block > state->heapsize1) || (block < 1))
1558 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1560 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1561 return (int) heapinfo[block].busy_block.busy_size;
1564 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1565 return (int) heapinfo[block].busy_frag.frag_size[frag];
1570 char *get_type_description(mc_object_info_t info, char *type_name)
1573 xbt_dict_cursor_t dict_cursor;
1577 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1578 if (type->name && (strcmp(type->name, type_name) == 0)
1579 && type->byte_size > 0) {
1580 xbt_dict_cursor_free(&dict_cursor);
1585 xbt_dict_cursor_free(&dict_cursor);
1591 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1595 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1598 struct s_mc_diff *state = mc_diff_info;
1600 if (heap1 == NULL && heap1 == NULL) {
1601 XBT_DEBUG("Malloc descriptors null");
1605 if (heap1->heaplimit != heap2->heaplimit) {
1606 XBT_DEBUG("Different limit of valid info table indices");
1610 /* Heap information */
1611 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1613 state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process());
1615 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1616 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1619 (malloc_info *) ((char *) heap1 +
1621 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1623 (malloc_info *) ((char *) heap2 +
1625 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1627 state->heapsize1 = heap1->heapsize;
1628 state->heapsize2 = heap2->heapsize;
1630 /* Start comparison */
1632 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1636 /* Check busy blocks */
1640 while (i <= state->heaplimit) {
1643 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1644 (char *) state->heapbase1));
1646 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1647 (char *) state->heapbase2));
1649 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1651 distance += BLOCKSIZE;
1652 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1653 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1658 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1659 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1664 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1666 if (state->heapinfo1[i].busy_block.size !=
1667 state->heapinfo2[i].busy_block.size) {
1669 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1670 state->heapinfo2[i].busy_block.size);
1671 i += max(state->heapinfo1[i].busy_block.size,
1672 state->heapinfo2[i].busy_block.size);
1674 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1675 i, state->heapinfo1[i].busy_block.size,
1676 state->heapinfo2[i].busy_block.size, distance);
1680 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1681 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1682 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1683 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);
1689 //while(k < (heapinfo1[i].busy_block.busy_size)){
1690 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1691 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1700 } else { /* Fragmented block */
1702 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1705 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1707 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1709 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1710 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1715 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1716 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1717 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);
1723 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1724 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1725 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=