1 /* mc_diff - Memory snapshooting and comparison */
3 /* Copyright (c) 2008-2014. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/ex_interface.h" /* internals of backtrace setup */
12 #include "xbt/mmalloc.h"
13 #include "mc_object_info.h"
14 #include "mc/datatypes.h"
15 #include "mc/mc_private.h"
16 #include "mc/mc_snapshot.h"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
19 "Logging specific to mc_diff in mc");
21 xbt_dynar_t mc_heap_comparison_ignore;
22 xbt_dynar_t stacks_areas;
26 /********************************* Backtrace ***********************************/
27 /******************************************************************************/
29 static void mmalloc_backtrace_block_display(void *heapinfo, int block)
34 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
35 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
39 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
40 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
42 /* xbt_ex_setup_backtrace(&e); */
43 /* if (e.used == 0) { */
44 /* fprintf(stderr, "(backtrace not set)\n"); */
45 /* } else if (e.bt_strings == NULL) { */
46 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
50 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
51 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
52 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
57 static void mmalloc_backtrace_fragment_display(void *heapinfo, int block,
63 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
64 /* e.used = XBT_BACKTRACE_SIZE; */
66 /* xbt_ex_setup_backtrace(&e); */
67 /* if (e.used == 0) { */
68 /* fprintf(stderr, "(backtrace not set)\n"); */
69 /* } else if (e.bt_strings == NULL) { */
70 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
74 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
75 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
76 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
82 static void mmalloc_backtrace_display(void *addr)
85 /* size_t block, frag_nb; */
88 /* xbt_mheap_t heap = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); */
90 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
92 /* type = heap->heapinfo[block].type; */
95 /* case MMALLOC_TYPE_HEAPINFO : */
96 /* case MMALLOC_TYPE_FREE : /\* Free block *\/ */
97 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
100 /* case 0: /\* Large block *\/ */
101 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
103 /* default: /\* Fragmented block *\/ */
104 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
105 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
106 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
109 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
115 static int compare_backtrace(int b1, int f1, int b2, int f2)
119 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
120 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
121 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
122 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
127 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
128 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
129 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
130 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
139 /*********************************** Heap comparison ***********************************/
140 /***************************************************************************************/
142 typedef char *type_name;
145 /** \brief Base address of the real heap */
148 // Number of blocks in the heaps:
149 size_t heapsize1, heapsize2;
150 xbt_dynar_t to_ignore1, to_ignore2;
151 s_heap_area_t *equals_to1, *equals_to2;
152 dw_type_t *types1, *types2;
156 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
157 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
158 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
159 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
161 __thread struct s_mc_diff *mc_diff_info = NULL;
163 /*********************************** Free functions ************************************/
165 static void heap_area_pair_free(heap_area_pair_t pair)
171 static void heap_area_pair_free_voidp(void *d)
173 heap_area_pair_free((heap_area_pair_t) * (void **) d);
176 static void heap_area_free(heap_area_t area)
182 /************************************************************************************/
184 static s_heap_area_t make_heap_area(int block, int fragment)
189 area.fragment = fragment;
194 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
195 int block2, int fragment2)
198 unsigned int cursor = 0;
199 heap_area_pair_t current_pair;
201 xbt_dynar_foreach(list, cursor, current_pair) {
202 if (current_pair->block1 == block1 && current_pair->block2 == block2
203 && current_pair->fragment1 == fragment1
204 && current_pair->fragment2 == fragment2)
211 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
212 int block2, int fragment2)
215 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
216 heap_area_pair_t pair = NULL;
217 pair = xbt_new0(s_heap_area_pair_t, 1);
218 pair->block1 = block1;
219 pair->fragment1 = fragment1;
220 pair->block2 = block2;
221 pair->fragment2 = fragment2;
223 xbt_dynar_push(list, &pair);
231 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
235 unsigned int cursor = 0;
237 int end = xbt_dynar_length(ignore_list) - 1;
238 mc_heap_ignore_region_t region;
240 while (start <= end) {
241 cursor = (start + end) / 2;
243 (mc_heap_ignore_region_t) xbt_dynar_get_as(ignore_list, cursor,
244 mc_heap_ignore_region_t);
245 if (region->address == address)
247 if (region->address < address)
249 if (region->address > address)
256 static int is_stack(void *address)
258 unsigned int cursor = 0;
259 stack_region_t stack;
261 xbt_dynar_foreach(stacks_areas, cursor, stack) {
262 if (address == stack->address)
269 // TODO, this should depend on the snapshot?
270 static int is_block_stack(int block)
272 unsigned int cursor = 0;
273 stack_region_t stack;
275 xbt_dynar_foreach(stacks_areas, cursor, stack) {
276 if (block == stack->block)
283 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
286 unsigned int cursor = 0;
287 heap_area_pair_t current_pair;
289 xbt_dynar_foreach(list, cursor, current_pair) {
291 if (current_pair->fragment1 != -1) {
293 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
294 make_heap_area(current_pair->block2, current_pair->fragment2);
295 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
296 make_heap_area(current_pair->block1, current_pair->fragment1);
300 state->equals_to1_(current_pair->block1, 0) =
301 make_heap_area(current_pair->block2, current_pair->fragment2);
302 state->equals_to2_(current_pair->block2, 0) =
303 make_heap_area(current_pair->block1, current_pair->fragment1);
310 /** Check whether two blocks are known to be matching
312 * @param state State used
313 * @param b1 Block of state 1
314 * @param b2 Block of state 2
315 * @return if the blocks are known to be matching
317 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
320 if (state->equals_to1_(b1, 0).block == b2
321 && state->equals_to2_(b2, 0).block == b1)
327 /** Check whether two fragments are known to be matching
329 * @param state State used
330 * @param b1 Block of state 1
331 * @param f1 Fragment of state 1
332 * @param b2 Block of state 2
333 * @param f2 Fragment of state 2
334 * @return if the fragments are known to be matching
336 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
340 if (state->equals_to1_(b1, f1).block == b2
341 && state->equals_to1_(b1, f1).fragment == f2
342 && state->equals_to2_(b2, f2).block == b1
343 && state->equals_to2_(b2, f2).fragment == f1)
349 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
352 if (mc_diff_info == NULL) {
353 mc_diff_info = xbt_new0(struct s_mc_diff, 1);
354 mc_diff_info->equals_to1 = NULL;
355 mc_diff_info->equals_to2 = NULL;
356 mc_diff_info->types1 = NULL;
357 mc_diff_info->types2 = NULL;
359 struct s_mc_diff *state = mc_diff_info;
361 if ((((struct mdesc *) heap1)->heaplimit !=
362 ((struct mdesc *) heap2)->heaplimit)
364 ((((struct mdesc *) heap1)->heapsize !=
365 ((struct mdesc *) heap2)->heapsize)))
368 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
370 // Mamailloute in order to find the base address of the main heap:
372 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
374 state->heapsize1 = heap1->heapsize;
375 state->heapsize2 = heap2->heapsize;
377 state->to_ignore1 = i1;
378 state->to_ignore2 = i2;
380 if (state->heaplimit > state->available) {
382 realloc(state->equals_to1,
383 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
384 sizeof(s_heap_area_t));
386 realloc(state->types1,
387 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
388 sizeof(type_name *));
390 realloc(state->equals_to2,
391 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
392 sizeof(s_heap_area_t));
394 realloc(state->types2,
395 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
396 sizeof(type_name *));
397 state->available = state->heaplimit;
400 memset(state->equals_to1, 0,
401 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
402 memset(state->equals_to2, 0,
403 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
404 memset(state->types1, 0,
405 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
406 memset(state->types2, 0,
407 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
413 void reset_heap_information()
418 // TODO, have a robust way to find it in O(1)
420 mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
422 size_t n = snapshot->snapshot_regions_count;
423 for (size_t i=0; i!=n; ++i) {
424 mc_mem_region_t region = snapshot->snapshot_regions[i];
425 if (region->region_type == MC_REGION_TYPE_HEAP)
428 xbt_die("No heap region");
431 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
433 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 malloc_info* heapinfos1 = mc_snapshot_read_pointer(heapinfo_address, snapshot1, MC_NO_PROCESS_INDEX);
458 malloc_info* heapinfos2 = mc_snapshot_read_pointer(heapinfo_address, snapshot2, MC_NO_PROCESS_INDEX);
460 while (i1 <= state->heaplimit) {
462 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
463 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i1], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
465 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
470 if (heapinfo1->type < 0) {
471 fprintf(stderr, "Unkown mmalloc block type.\n");
476 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
477 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
479 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
481 if (is_stack(addr_block1)) {
482 for (k = 0; k < heapinfo1->busy_block.size; k++)
483 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
484 for (k = 0; k < heapinfo2->busy_block.size; k++)
485 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
486 i1 += heapinfo1->busy_block.size;
490 if (state->equals_to1_(i1, 0).valid) {
499 /* Try first to associate to same block in the other heap */
500 if (heapinfo2->type == heapinfo1->type) {
502 if (state->equals_to2_(i1, 0).valid == 0) {
505 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
506 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
509 compare_heap_area(MC_NO_PROCESS_INDEX, addr_block1, addr_block2, snapshot1, snapshot2,
512 if (res_compare != 1) {
513 for (k = 1; k < heapinfo2->busy_block.size; k++)
514 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
515 for (k = 1; k < heapinfo1->busy_block.size; k++)
516 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
518 i1 += heapinfo1->busy_block.size;
525 while (i2 <= state->heaplimit && !equal) {
528 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
529 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
536 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
538 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
543 if (state->equals_to2_(i2, 0).valid) {
549 compare_heap_area(MC_NO_PROCESS_INDEX, 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) {
595 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
596 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
598 (void *) ((char *) addr_block2 +
599 (j1 << heapinfo2->type));
602 compare_heap_area(MC_NO_PROCESS_INDEX, addr_frag1, addr_frag2, snapshot1, snapshot2,
605 if (res_compare != 1)
612 while (i2 <= state->heaplimit && !equal) {
614 malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
616 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
621 // We currently do not match fragments with unfragmented blocks (maybe we should).
622 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
627 if (heapinfo2b->type < 0) {
628 fprintf(stderr, "Unkown mmalloc block type.\n");
632 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
635 if (i2 == i1 && j2 == j1)
638 if (state->equals_to2_(i2, j2).valid)
642 ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
643 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
645 (void *) ((char *) addr_block2 +
646 (j2 << heapinfo2b->type));
649 compare_heap_area(MC_NO_PROCESS_INDEX, 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 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
687 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
688 if (i1 == state->heaplimit) {
689 if (heapinfo1->busy_block.busy_size > 0) {
690 if (state->equals_to1_(i, 0).valid == 0) {
691 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
693 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
694 heapinfo1->busy_block.busy_size);
695 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
702 if (heapinfo1->type > 0) {
703 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
704 if (i1 == state->heaplimit) {
705 if (heapinfo1->busy_frag.frag_size[j] > 0) {
706 if (state->equals_to1_(i, j).valid == 0) {
707 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
708 // TODO, print fragment address
710 ("Block %zu, Fragment %zu not found (size used = %zd)",
712 heapinfo1->busy_frag.frag_size[j]);
713 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
723 if (i1 == state->heaplimit)
724 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
726 for (i=1; i <= state->heaplimit; i++) {
727 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
728 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
729 if (i1 == state->heaplimit) {
730 if (heapinfo2->busy_block.busy_size > 0) {
731 if (state->equals_to2_(i, 0).valid == 0) {
732 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
733 // TODO, print address of the block
734 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
735 heapinfo2->busy_block.busy_size);
736 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
743 if (heapinfo2->type > 0) {
744 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
745 if (i1 == state->heaplimit) {
746 if (heapinfo2->busy_frag.frag_size[j] > 0) {
747 if (state->equals_to2_(i, j).valid == 0) {
748 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
749 // TODO, print address of the block
751 ("Block %zu, Fragment %zu not found (size used = %zd)",
753 heapinfo2->busy_frag.frag_size[j]);
754 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
764 if (i1 == state->heaplimit)
765 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
767 return ((nb_diff1 > 0) || (nb_diff2 > 0));
773 * @param real_area1 Process address for state 1
774 * @param real_area2 Process address for state 2
775 * @param snapshot1 Snapshot of state 1
776 * @param snapshot2 Snapshot of state 2
779 * @param check_ignore
781 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
782 void *real_area1, void *real_area2,
783 mc_snapshot_t snapshot1,
784 mc_snapshot_t snapshot2,
785 xbt_dynar_t previous, int size,
788 mc_process_t process = &mc_model_checker->process;
791 void *addr_pointed1, *addr_pointed2;
792 int pointer_align, res_compare;
793 ssize_t ignore1, ignore2;
795 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
796 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
800 if (check_ignore > 0) {
802 heap_comparison_ignore_size(state->to_ignore1,
803 (char *) real_area1 + i)) != -1) {
805 heap_comparison_ignore_size(state->to_ignore2,
806 (char *) real_area2 + i)) == ignore1) {
819 if (mc_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
821 pointer_align = (i / sizeof(void *)) * sizeof(void *);
822 addr_pointed1 = mc_snapshot_read_pointer((char *) real_area1 + pointer_align, snapshot1, process_index);
823 addr_pointed2 = mc_snapshot_read_pointer((char *) real_area2 + pointer_align, snapshot2, process_index);
825 if (addr_pointed1 > process->maestro_stack_start
826 && addr_pointed1 < process->maestro_stack_end
827 && addr_pointed2 > process->maestro_stack_start
828 && addr_pointed2 < process->maestro_stack_end) {
829 i = pointer_align + sizeof(void *);
831 } else if (addr_pointed1 > state->s_heap
832 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
833 && addr_pointed2 > state->s_heap
834 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
835 // Both addreses are in the heap:
837 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
838 snapshot2, previous, NULL, 0);
839 if (res_compare == 1) {
842 i = pointer_align + sizeof(void *);
861 * @param real_area1 Process address for state 1
862 * @param real_area2 Process address for state 2
863 * @param snapshot1 Snapshot of state 1
864 * @param snapshot2 Snapshot of state 2
867 * @param area_size either a byte_size or an elements_count (?)
868 * @param check_ignore
869 * @param pointer_level
870 * @return 0 (same), 1 (different), -1 (unknown)
872 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
873 void *real_area1, void *real_area2,
874 mc_snapshot_t snapshot1,
875 mc_snapshot_t snapshot2,
876 xbt_dynar_t previous, dw_type_t type,
877 int area_size, int check_ignore,
881 if (is_stack(real_area1) && is_stack(real_area2))
884 ssize_t ignore1, ignore2;
886 if ((check_ignore > 0)
887 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
889 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
894 dw_type_t subtype, subsubtype;
895 int res, elm_size, i;
896 unsigned int cursor = 0;
898 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 != NULL && strcmp(type->name, "char") == 0) { /* 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 (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 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
983 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
984 return (addr_pointed1 != addr_pointed2);;
987 if (pointer_level > 1) { /* Array of pointers */
988 for (i = 0; i < (area_size / sizeof(void *)); i++) {
989 addr_pointed1 = mc_snapshot_read_pointer((char*) real_area1 + i * sizeof(void *), snapshot1, process_index);
990 addr_pointed2 = mc_snapshot_read_pointer((char*) real_area2 + i * sizeof(void *), snapshot2, process_index);
991 if (addr_pointed1 > state->s_heap
992 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
993 && addr_pointed2 > state->s_heap
994 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
996 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
997 snapshot2, previous, type->subtype,
1000 res = (addr_pointed1 != addr_pointed2);
1005 addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
1006 addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
1007 if (addr_pointed1 > state->s_heap
1008 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
1009 && addr_pointed2 > state->s_heap
1010 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1011 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1012 snapshot2, previous, type->subtype,
1015 return (addr_pointed1 != addr_pointed2);
1019 case DW_TAG_structure_type:
1020 case DW_TAG_class_type:
1021 if (type->full_type)
1022 type = type->full_type;
1023 if (area_size != -1 && type->byte_size != area_size) {
1024 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1025 for (i = 0; i < (area_size / type->byte_size); i++) {
1027 compare_heap_area_with_type(state, process_index,
1028 (char *) real_area1 + i * type->byte_size,
1029 (char *) real_area2 + i * type->byte_size,
1030 snapshot1, snapshot2, previous, type, -1,
1040 xbt_dynar_foreach(type->members, cursor, member) {
1041 // TODO, optimize this? (for the offset case)
1042 char *real_member1 =
1043 mc_member_resolve(real_area1, type, member, snapshot1, process_index);
1044 char *real_member2 =
1045 mc_member_resolve(real_area2, type, member, snapshot2, process_index);
1047 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1048 snapshot1, snapshot2,
1049 previous, member->subtype, -1,
1057 case DW_TAG_union_type:
1058 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1059 snapshot1, snapshot2, previous,
1060 type->byte_size, check_ignore);
1070 /** Infer the type of a part of the block from the type of the block
1072 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1074 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1076 * @param type_id DWARF type ID of the root address
1078 * @return DWARF type ID for given offset
1080 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1081 int offset, int area_size,
1082 mc_snapshot_t snapshot, int process_index)
1085 // Beginning of the block, the infered variable type if the type of the block:
1089 switch (type->type) {
1090 case DW_TAG_structure_type:
1091 case DW_TAG_class_type:
1092 if (type->full_type)
1093 type = type->full_type;
1095 if (area_size != -1 && type->byte_size != area_size) {
1096 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1101 unsigned int cursor = 0;
1103 xbt_dynar_foreach(type->members, cursor, member) {
1105 if (!member->location.size) {
1106 // We have the offset, use it directly (shortcut):
1107 if (member->offset == offset)
1108 return member->subtype;
1111 mc_member_resolve(real_base_address, type, member, snapshot, process_index);
1112 if (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, void *area1, 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 malloc_info* heapinfos1 = mc_snapshot_read_pointer(heapinfo_address, snapshot1, process_index);
1163 malloc_info* heapinfos2 = mc_snapshot_read_pointer(heapinfo_address, snapshot2, process_index);
1165 malloc_info heapinfo_temp1, heapinfo_temp2;
1167 if (previous == NULL) {
1169 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1172 // Get block number:
1175 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1178 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1180 // If either block is a stack block:
1181 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1182 add_heap_area_pair(previous, block1, -1, block2, -1);
1184 match_equals(state, previous);
1185 xbt_dynar_free(&previous);
1189 // If either block is not in the expected area of memory:
1190 if (((char *) area1 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1191 || (block1 > state->heapsize1) || (block1 < 1)
1192 || ((char *) area2 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1193 || (block2 > state->heapsize2) || (block2 < 1)) {
1195 xbt_dynar_free(&previous);
1200 // Process address of the block:
1202 ((void *) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE +
1203 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
1205 ((void *) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE +
1206 (char *) ((xbt_mheap_t) state->s_heap)->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 malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[block1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
1231 malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[block2], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
1233 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1234 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1238 match_equals(state, previous);
1239 xbt_dynar_free(&previous);
1243 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1244 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1245 /* Complete block */
1247 // TODO, lookup variable type from block type as done for fragmented blocks
1249 offset1 = (char *) area1 - (char *) real_addr_block1;
1250 offset2 = (char *) area2 - (char *) real_addr_block2;
1252 if (state->equals_to1_(block1, 0).valid
1253 && state->equals_to2_(block2, 0).valid) {
1254 if (equal_blocks(state, block1, block2)) {
1256 match_equals(state, previous);
1257 xbt_dynar_free(&previous);
1263 if (type_size != -1) {
1264 if (type_size != heapinfo1->busy_block.busy_size
1265 && type_size != heapinfo2->busy_block.busy_size
1266 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1268 match_equals(state, previous);
1269 xbt_dynar_free(&previous);
1275 if (heapinfo1->busy_block.size !=
1276 heapinfo2->busy_block.size) {
1278 xbt_dynar_free(&previous);
1283 if (heapinfo1->busy_block.busy_size !=
1284 heapinfo2->busy_block.busy_size) {
1286 xbt_dynar_free(&previous);
1291 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1293 match_equals(state, previous);
1294 xbt_dynar_free(&previous);
1299 size = heapinfo1->busy_block.busy_size;
1301 // Remember (basic) type inference.
1302 // The current data structure only allows us to do this for the whole block.
1303 if (type != NULL && area1 == real_addr_block1) {
1304 state->types1_(block1, 0) = type;
1306 if (type != NULL && area2 == real_addr_block2) {
1307 state->types2_(block2, 0) = type;
1312 match_equals(state, previous);
1313 xbt_dynar_free(&previous);
1321 if ((heapinfo1->busy_block.ignore > 0)
1322 && (heapinfo2->busy_block.ignore ==
1323 heapinfo1->busy_block.ignore))
1324 check_ignore = heapinfo1->busy_block.ignore;
1326 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1330 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1332 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1334 // Process address of the fragment:
1336 (void *) ((char *) real_addr_block1 +
1337 (frag1 << heapinfo1->type));
1339 (void *) ((char *) real_addr_block2 +
1340 (frag2 << heapinfo2->type));
1342 // Check the size of the fragments against the size of the type:
1343 if (type_size != -1) {
1344 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1345 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1347 match_equals(state, previous);
1348 xbt_dynar_free(&previous);
1353 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1354 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1356 match_equals(state, previous);
1357 xbt_dynar_free(&previous);
1363 // Check if the blocks are already matched together:
1364 if (state->equals_to1_(block1, frag1).valid
1365 && state->equals_to2_(block2, frag2).valid) {
1366 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1368 match_equals(state, previous);
1369 xbt_dynar_free(&previous);
1374 // Compare the size of both fragments:
1375 if (heapinfo1->busy_frag.frag_size[frag1] !=
1376 heapinfo2->busy_frag.frag_size[frag2]) {
1377 if (type_size == -1) {
1379 match_equals(state, previous);
1380 xbt_dynar_free(&previous);
1385 xbt_dynar_free(&previous);
1391 // Size of the fragment:
1392 size = heapinfo1->busy_frag.frag_size[frag1];
1394 // Remember (basic) type inference.
1395 // The current data structure only allows us to do this for the whole fragment.
1396 if (type != NULL && area1 == real_addr_frag1) {
1397 state->types1_(block1, frag1) = type;
1399 if (type != NULL && area2 == real_addr_frag2) {
1400 state->types2_(block2, frag2) = type;
1402 // The type of the variable is already known:
1407 // Type inference from the block type.
1408 else if (state->types1_(block1, frag1) != NULL
1409 || state->types2_(block2, frag2) != NULL) {
1411 offset1 = (char *) area1 - (char *) real_addr_frag1;
1412 offset2 = (char *) area2 - (char *) real_addr_frag2;
1414 if (state->types1_(block1, frag1) != NULL
1415 && state->types2_(block2, frag2) != NULL) {
1417 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1418 offset1, size, snapshot1, process_index);
1420 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1421 offset1, size, snapshot2, process_index);
1422 } else if (state->types1_(block1, frag1) != NULL) {
1424 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1425 offset1, size, snapshot1, process_index);
1427 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1428 offset2, size, snapshot2, process_index);
1429 } else if (state->types2_(block2, frag2) != NULL) {
1431 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1432 offset1, size, snapshot1, process_index);
1434 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1435 offset2, size, snapshot2, process_index);
1438 match_equals(state, previous);
1439 xbt_dynar_free(&previous);
1444 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1447 while (type->byte_size == 0 && type->subtype != NULL)
1448 type = type->subtype;
1449 new_size1 = type->byte_size;
1452 while (type->byte_size == 0 && type->subtype != NULL)
1453 type = type->subtype;
1454 new_size2 = type->byte_size;
1458 match_equals(state, previous);
1459 xbt_dynar_free(&previous);
1465 if (new_size1 > 0 && new_size1 == new_size2) {
1470 if (offset1 == 0 && offset2 == 0) {
1471 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1473 match_equals(state, previous);
1474 xbt_dynar_free(&previous);
1482 match_equals(state, previous);
1483 xbt_dynar_free(&previous);
1488 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1489 && (heapinfo2->busy_frag.ignore[frag2] ==
1490 heapinfo1->busy_frag.ignore[frag1]))
1491 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1496 xbt_dynar_free(&previous);
1503 /* Start comparison */
1506 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1507 previous, type, size, check_ignore,
1511 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1512 previous, size, check_ignore);
1514 if (res_compare == 1) {
1516 xbt_dynar_free(&previous);
1521 match_equals(state, previous);
1522 xbt_dynar_free(&previous);
1528 /*********************************************** Miscellaneous ***************************************************/
1529 /****************************************************************************************************************/
1531 // Not used and broken code:
1535 static int get_pointed_area_size(void *area, int heap)
1538 struct s_mc_diff *state = mc_diff_info;
1541 malloc_info *heapinfo;
1544 heapinfo = state->heapinfo1;
1546 heapinfo = state->heapinfo2;
1550 (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
1552 if (((char *) area < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
1553 || (block > state->heapsize1) || (block < 1))
1556 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1558 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1559 return (int) heapinfo[block].busy_block.busy_size;
1562 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1563 return (int) heapinfo[block].busy_frag.frag_size[frag];
1568 char *get_type_description(mc_object_info_t info, char *type_name)
1571 xbt_dict_cursor_t dict_cursor;
1575 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1576 if (type->name && (strcmp(type->name, type_name) == 0)
1577 && type->byte_size > 0) {
1578 xbt_dict_cursor_free(&dict_cursor);
1583 xbt_dict_cursor_free(&dict_cursor);
1589 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1593 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1596 struct s_mc_diff *state = mc_diff_info;
1598 if (heap1 == NULL && heap1 == NULL) {
1599 XBT_DEBUG("Malloc descriptors null");
1603 if (heap1->heaplimit != heap2->heaplimit) {
1604 XBT_DEBUG("Different limit of valid info table indices");
1608 /* Heap information */
1609 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1612 // Mamailloute in order to find the base address of the main heap:
1614 (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
1616 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1617 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1620 (malloc_info *) ((char *) heap1 +
1622 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1624 (malloc_info *) ((char *) heap2 +
1626 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1628 state->heapsize1 = heap1->heapsize;
1629 state->heapsize2 = heap2->heapsize;
1631 /* Start comparison */
1633 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1637 /* Check busy blocks */
1641 while (i <= state->heaplimit) {
1644 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1645 (char *) state->heapbase1));
1647 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1648 (char *) state->heapbase2));
1650 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1652 distance += BLOCKSIZE;
1653 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1654 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1659 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1660 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1665 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1667 if (state->heapinfo1[i].busy_block.size !=
1668 state->heapinfo2[i].busy_block.size) {
1670 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1671 state->heapinfo2[i].busy_block.size);
1672 i += max(state->heapinfo1[i].busy_block.size,
1673 state->heapinfo2[i].busy_block.size);
1675 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1676 i, state->heapinfo1[i].busy_block.size,
1677 state->heapinfo2[i].busy_block.size, distance);
1681 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1682 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1683 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1684 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);
1690 //while(k < (heapinfo1[i].busy_block.busy_size)){
1691 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1692 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1701 } else { /* Fragmented block */
1703 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1706 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1708 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1710 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1711 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1716 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1717 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1718 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);
1724 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1725 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1726 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=