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 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
92 /* type = heap->heapinfo[block].type; */
95 /* case MMALLOC_TYPE_HEAPINFO : */
96 /* case MMALLOC_TYPE_FREE : /\* Free block *\/ */
97 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
100 /* case 0: /\* Large block *\/ */
101 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
103 /* default: /\* Fragmented block *\/ */
104 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
105 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
106 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
109 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
115 static int compare_backtrace(int b1, int f1, int b2, int f2)
119 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
120 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
121 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
122 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
127 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
128 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
129 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
130 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
139 /*********************************** Heap comparison ***********************************/
140 /***************************************************************************************/
142 typedef char *type_name;
145 s_xbt_mheap_t std_heap_copy;
147 // Number of blocks in the heaps:
148 size_t heapsize1, heapsize2;
149 xbt_dynar_t to_ignore1, to_ignore2;
150 s_heap_area_t *equals_to1, *equals_to2;
151 dw_type_t *types1, *types2;
155 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
156 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
157 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
158 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
160 __thread struct s_mc_diff *mc_diff_info = NULL;
162 /*********************************** Free functions ************************************/
164 static void heap_area_pair_free(heap_area_pair_t pair)
170 static void heap_area_pair_free_voidp(void *d)
172 heap_area_pair_free((heap_area_pair_t) * (void **) d);
175 static void heap_area_free(heap_area_t area)
181 /************************************************************************************/
183 static s_heap_area_t make_heap_area(int block, int fragment)
188 area.fragment = fragment;
193 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
194 int block2, int fragment2)
197 unsigned int cursor = 0;
198 heap_area_pair_t current_pair;
200 xbt_dynar_foreach(list, cursor, current_pair) {
201 if (current_pair->block1 == block1 && current_pair->block2 == block2
202 && current_pair->fragment1 == fragment1
203 && current_pair->fragment2 == fragment2)
210 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
211 int block2, int fragment2)
214 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
215 heap_area_pair_t pair = NULL;
216 pair = xbt_new0(s_heap_area_pair_t, 1);
217 pair->block1 = block1;
218 pair->fragment1 = fragment1;
219 pair->block2 = block2;
220 pair->fragment2 = fragment2;
222 xbt_dynar_push(list, &pair);
230 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
234 unsigned int cursor = 0;
236 int end = xbt_dynar_length(ignore_list) - 1;
237 mc_heap_ignore_region_t region;
239 while (start <= end) {
240 cursor = (start + end) / 2;
242 (mc_heap_ignore_region_t) xbt_dynar_get_as(ignore_list, cursor,
243 mc_heap_ignore_region_t);
244 if (region->address == address)
246 if (region->address < address)
248 if (region->address > address)
255 static int is_stack(const void *address)
257 unsigned int cursor = 0;
258 stack_region_t stack;
260 xbt_dynar_foreach(stacks_areas, cursor, stack) {
261 if (address == stack->address)
268 // TODO, this should depend on the snapshot?
269 static int is_block_stack(int block)
271 unsigned int cursor = 0;
272 stack_region_t stack;
274 xbt_dynar_foreach(stacks_areas, cursor, stack) {
275 if (block == stack->block)
282 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
285 unsigned int cursor = 0;
286 heap_area_pair_t current_pair;
288 xbt_dynar_foreach(list, cursor, current_pair) {
290 if (current_pair->fragment1 != -1) {
292 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
293 make_heap_area(current_pair->block2, current_pair->fragment2);
294 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
295 make_heap_area(current_pair->block1, current_pair->fragment1);
299 state->equals_to1_(current_pair->block1, 0) =
300 make_heap_area(current_pair->block2, current_pair->fragment2);
301 state->equals_to2_(current_pair->block2, 0) =
302 make_heap_area(current_pair->block1, current_pair->fragment1);
309 /** Check whether two blocks are known to be matching
311 * @param state State used
312 * @param b1 Block of state 1
313 * @param b2 Block of state 2
314 * @return if the blocks are known to be matching
316 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
319 if (state->equals_to1_(b1, 0).block == b2
320 && state->equals_to2_(b2, 0).block == b1)
326 /** Check whether two fragments are known to be matching
328 * @param state State used
329 * @param b1 Block of state 1
330 * @param f1 Fragment of state 1
331 * @param b2 Block of state 2
332 * @param f2 Fragment of state 2
333 * @return if the fragments are known to be matching
335 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
339 if (state->equals_to1_(b1, f1).block == b2
340 && state->equals_to1_(b1, f1).fragment == f2
341 && state->equals_to2_(b2, f2).block == b1
342 && state->equals_to2_(b2, f2).fragment == f1)
348 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
351 if (mc_diff_info == NULL) {
352 mc_diff_info = xbt_new0(struct s_mc_diff, 1);
353 mc_diff_info->equals_to1 = NULL;
354 mc_diff_info->equals_to2 = NULL;
355 mc_diff_info->types1 = NULL;
356 mc_diff_info->types2 = NULL;
358 struct s_mc_diff *state = mc_diff_info;
360 if ((((struct mdesc *) heap1)->heaplimit !=
361 ((struct mdesc *) heap2)->heaplimit)
363 ((((struct mdesc *) heap1)->heapsize !=
364 ((struct mdesc *) heap2)->heapsize)))
367 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
369 state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process());
371 state->heapsize1 = heap1->heapsize;
372 state->heapsize2 = heap2->heapsize;
374 state->to_ignore1 = i1;
375 state->to_ignore2 = i2;
377 if (state->heaplimit > state->available) {
378 state->equals_to1 = (s_heap_area_t*)
379 realloc(state->equals_to1,
380 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
381 sizeof(s_heap_area_t));
382 state->types1 = (s_dw_type**)
383 realloc(state->types1,
384 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
385 sizeof(type_name *));
386 state->equals_to2 = (s_heap_area_t*)
387 realloc(state->equals_to2,
388 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
389 sizeof(s_heap_area_t));
390 state->types2 = (s_dw_type**)
391 realloc(state->types2,
392 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
393 sizeof(type_name *));
394 state->available = state->heaplimit;
397 memset(state->equals_to1, 0,
398 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
399 memset(state->equals_to2, 0,
400 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t));
401 memset(state->types1, 0,
402 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
403 memset(state->types2, 0,
404 state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *));
410 void reset_heap_information()
415 // TODO, have a robust way to find it in O(1)
417 mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
419 size_t n = snapshot->snapshot_regions_count;
420 for (size_t i=0; i!=n; ++i) {
421 mc_mem_region_t region = snapshot->snapshot_regions[i];
422 if (region->region_type == MC_REGION_TYPE_HEAP)
425 xbt_die("No heap region");
428 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
430 mc_process_t process = &mc_model_checker->process();
431 struct s_mc_diff *state = mc_diff_info;
433 /* Start comparison */
434 size_t i1, i2, j1, j2, k;
435 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
436 int nb_diff1 = 0, nb_diff2 = 0;
438 int equal, res_compare = 0;
440 /* Check busy blocks */
444 malloc_info heapinfo_temp1, heapinfo_temp2;
445 malloc_info heapinfo_temp2b;
447 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
448 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
450 // This is the address of std_heap->heapinfo in the application process:
451 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
453 // This is in snapshot do not use them directly:
454 const malloc_info* heapinfos1 = (const malloc_info*) MC_snapshot_read_pointer(snapshot1, heapinfo_address, MC_PROCESS_INDEX_MISSING);
455 const malloc_info* heapinfos2 = (const malloc_info*) MC_snapshot_read_pointer(snapshot2, heapinfo_address, MC_PROCESS_INDEX_MISSING);
457 while (i1 <= state->heaplimit) {
459 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
460 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
462 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
467 if (heapinfo1->type < 0) {
468 fprintf(stderr, "Unkown mmalloc block type.\n");
473 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
474 (char *) state->std_heap_copy.heapbase));
476 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
478 if (is_stack(addr_block1)) {
479 for (k = 0; k < heapinfo1->busy_block.size; k++)
480 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
481 for (k = 0; k < heapinfo2->busy_block.size; k++)
482 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
483 i1 += heapinfo1->busy_block.size;
487 if (state->equals_to1_(i1, 0).valid) {
496 /* Try first to associate to same block in the other heap */
497 if (heapinfo2->type == heapinfo1->type) {
499 if (state->equals_to2_(i1, 0).valid == 0) {
501 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
502 (char *) state->std_heap_copy.heapbase;
505 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_block1, addr_block2, snapshot1, snapshot2,
508 if (res_compare != 1) {
509 for (k = 1; k < heapinfo2->busy_block.size; k++)
510 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
511 for (k = 1; k < heapinfo1->busy_block.size; k++)
512 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
514 i1 += heapinfo1->busy_block.size;
521 while (i2 <= state->heaplimit && !equal) {
523 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
524 (char *) state->std_heap_copy.heapbase;
531 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
533 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
538 if (state->equals_to2_(i2, 0).valid) {
544 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_block1, addr_block2, snapshot1, snapshot2,
547 if (res_compare != 1) {
548 for (k = 1; k < heapinfo2b->busy_block.size; k++)
549 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
550 for (k = 1; k < heapinfo1->busy_block.size; k++)
551 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
553 i1 += heapinfo1->busy_block.size;
561 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
562 heapinfo1->busy_block.busy_size, addr_block1);
563 i1 = state->heaplimit + 1;
568 } else { /* Fragmented block */
570 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
572 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
575 if (state->equals_to1_(i1, j1).valid)
579 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
584 /* Try first to associate to same fragment in the other heap */
585 if (heapinfo2->type == heapinfo1->type) {
587 if (state->equals_to2_(i1, j1).valid == 0) {
589 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
590 (char *) state->std_heap_copy.heapbase;
592 (void *) ((char *) addr_block2 +
593 (j1 << heapinfo2->type));
596 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_frag1, addr_frag2, snapshot1, snapshot2,
599 if (res_compare != 1)
606 while (i2 <= state->heaplimit && !equal) {
608 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
609 heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
610 sizeof(malloc_info));
612 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
617 // We currently do not match fragments with unfragmented blocks (maybe we should).
618 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
623 if (heapinfo2b->type < 0) {
624 fprintf(stderr, "Unkown mmalloc block type.\n");
628 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
631 if (i2 == i1 && j2 == j1)
634 if (state->equals_to2_(i2, j2).valid)
637 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
638 (char *) state->std_heap_copy.heapbase;
640 (void *) ((char *) addr_block2 +
641 (j2 << heapinfo2b->type));
644 compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_frag1, addr_frag2, snapshot2, snapshot2,
647 if (res_compare != 1) {
660 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
661 i1, j1, heapinfo1->busy_frag.frag_size[j1],
663 i2 = state->heaplimit + 1;
664 i1 = state->heaplimit + 1;
677 /* All blocks/fragments are equal to another block/fragment ? */
680 for(i = 1; i <= state->heaplimit; i++) {
681 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
682 heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
683 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
684 if (i1 == state->heaplimit) {
685 if (heapinfo1->busy_block.busy_size > 0) {
686 if (state->equals_to1_(i, 0).valid == 0) {
687 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
689 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
690 heapinfo1->busy_block.busy_size);
691 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
698 if (heapinfo1->type > 0) {
699 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
700 if (i1 == state->heaplimit) {
701 if (heapinfo1->busy_frag.frag_size[j] > 0) {
702 if (state->equals_to1_(i, j).valid == 0) {
703 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
704 // TODO, print fragment address
706 ("Block %zu, Fragment %zu not found (size used = %zd)",
708 heapinfo1->busy_frag.frag_size[j]);
709 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
719 if (i1 == state->heaplimit)
720 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
722 for (i=1; i <= state->heaplimit; i++) {
723 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
724 heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
725 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
726 if (i1 == state->heaplimit) {
727 if (heapinfo2->busy_block.busy_size > 0) {
728 if (state->equals_to2_(i, 0).valid == 0) {
729 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
730 // TODO, print address of the block
731 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
732 heapinfo2->busy_block.busy_size);
733 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
740 if (heapinfo2->type > 0) {
741 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
742 if (i1 == state->heaplimit) {
743 if (heapinfo2->busy_frag.frag_size[j] > 0) {
744 if (state->equals_to2_(i, j).valid == 0) {
745 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
746 // TODO, print address of the block
748 ("Block %zu, Fragment %zu not found (size used = %zd)",
750 heapinfo2->busy_frag.frag_size[j]);
751 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
761 if (i1 == state->heaplimit)
762 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
764 return ((nb_diff1 > 0) || (nb_diff2 > 0));
770 * @param real_area1 Process address for state 1
771 * @param real_area2 Process address for state 2
772 * @param snapshot1 Snapshot of state 1
773 * @param snapshot2 Snapshot of state 2
776 * @param check_ignore
778 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
779 const void *real_area1, const void *real_area2,
780 mc_snapshot_t snapshot1,
781 mc_snapshot_t snapshot2,
782 xbt_dynar_t previous, int size,
785 mc_process_t process = &mc_model_checker->process();
788 const void *addr_pointed1, *addr_pointed2;
789 int pointer_align, res_compare;
790 ssize_t ignore1, ignore2;
792 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
793 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
797 if (check_ignore > 0) {
799 heap_comparison_ignore_size(state->to_ignore1,
800 (char *) real_area1 + i)) != -1) {
802 heap_comparison_ignore_size(state->to_ignore2,
803 (char *) real_area2 + i)) == ignore1) {
816 if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
818 pointer_align = (i / sizeof(void *)) * sizeof(void *);
819 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char *) real_area1 + pointer_align, process_index);
820 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char *) real_area2 + pointer_align, process_index);
822 if (addr_pointed1 > process->maestro_stack_start
823 && addr_pointed1 < process->maestro_stack_end
824 && addr_pointed2 > process->maestro_stack_start
825 && addr_pointed2 < process->maestro_stack_end) {
826 i = pointer_align + sizeof(void *);
828 } else if (addr_pointed1 > state->std_heap_copy.heapbase
829 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
830 && addr_pointed2 > state->std_heap_copy.heapbase
831 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
832 // Both addreses are in the heap:
834 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
835 snapshot2, previous, NULL, 0);
836 if (res_compare == 1) {
839 i = pointer_align + sizeof(void *);
858 * @param real_area1 Process address for state 1
859 * @param real_area2 Process address for state 2
860 * @param snapshot1 Snapshot of state 1
861 * @param snapshot2 Snapshot of state 2
864 * @param area_size either a byte_size or an elements_count (?)
865 * @param check_ignore
866 * @param pointer_level
867 * @return 0 (same), 1 (different), -1 (unknown)
869 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
870 const void *real_area1, const void *real_area2,
871 mc_snapshot_t snapshot1,
872 mc_snapshot_t snapshot2,
873 xbt_dynar_t previous, dw_type_t type,
874 int area_size, int check_ignore,
878 if (is_stack(real_area1) && is_stack(real_area2))
881 ssize_t ignore1, ignore2;
883 if ((check_ignore > 0)
884 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
886 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
891 dw_type_t subtype, subsubtype;
893 unsigned int cursor = 0;
895 const void *addr_pointed1, *addr_pointed2;;
897 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
898 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
900 switch (type->type) {
901 case DW_TAG_unspecified_type:
904 case DW_TAG_base_type:
905 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
906 if (real_area1 == real_area2)
909 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
911 if (area_size != -1 && type->byte_size != area_size)
914 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
918 case DW_TAG_enumeration_type:
919 if (area_size != -1 && type->byte_size != area_size)
922 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
925 case DW_TAG_const_type:
926 case DW_TAG_volatile_type:
928 type = type->subtype;
931 case DW_TAG_array_type:
932 subtype = type->subtype;
933 switch (subtype->type) {
934 case DW_TAG_unspecified_type:
937 case DW_TAG_base_type:
938 case DW_TAG_enumeration_type:
939 case DW_TAG_pointer_type:
940 case DW_TAG_reference_type:
941 case DW_TAG_rvalue_reference_type:
942 case DW_TAG_structure_type:
943 case DW_TAG_class_type:
944 case DW_TAG_union_type:
945 if (subtype->full_type)
946 subtype = subtype->full_type;
947 elm_size = subtype->byte_size;
949 // TODO, just remove the type indirection?
950 case DW_TAG_const_type:
952 case DW_TAG_volatile_type:
953 subsubtype = subtype->subtype;
954 if (subsubtype->full_type)
955 subsubtype = subsubtype->full_type;
956 elm_size = subsubtype->byte_size;
962 for (int i = 0; i < type->element_count; i++) {
963 // TODO, add support for variable stride (DW_AT_byte_stride)
965 compare_heap_area_with_type(state, process_index,
966 (char *) real_area1 + (i * elm_size),
967 (char *) real_area2 + (i * elm_size),
968 snapshot1, snapshot2, previous,
969 type->subtype, subtype->byte_size,
970 check_ignore, pointer_level);
975 case DW_TAG_reference_type:
976 case DW_TAG_rvalue_reference_type:
977 case DW_TAG_pointer_type:
978 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
979 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, real_area1, process_index);
980 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, real_area2, process_index);
981 return (addr_pointed1 != addr_pointed2);;
984 if (pointer_level > 1) { /* Array of pointers */
985 for (size_t i = 0; i < (area_size / sizeof(void *)); i++) {
986 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char*) real_area1 + i * sizeof(void *), process_index);
987 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char*) real_area2 + i * sizeof(void *), process_index);
988 if (addr_pointed1 > state->std_heap_copy.heapbase
989 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
990 && addr_pointed2 > state->std_heap_copy.heapbase
991 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
993 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
994 snapshot2, previous, type->subtype,
997 res = (addr_pointed1 != addr_pointed2);
1002 addr_pointed1 = MC_snapshot_read_pointer(snapshot1, real_area1, process_index);
1003 addr_pointed2 = MC_snapshot_read_pointer(snapshot2, real_area2, process_index);
1004 if (addr_pointed1 > state->std_heap_copy.heapbase
1005 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
1006 && addr_pointed2 > state->std_heap_copy.heapbase
1007 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1008 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1009 snapshot2, previous, type->subtype,
1012 return (addr_pointed1 != addr_pointed2);
1016 case DW_TAG_structure_type:
1017 case DW_TAG_class_type:
1018 if (type->full_type)
1019 type = type->full_type;
1020 if (area_size != -1 && type->byte_size != area_size) {
1021 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1022 for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) {
1024 compare_heap_area_with_type(state, process_index,
1025 (char *) real_area1 + i * type->byte_size,
1026 (char *) real_area2 + i * type->byte_size,
1027 snapshot1, snapshot2, previous, type, -1,
1037 xbt_dynar_foreach(type->members, cursor, member) {
1038 // TODO, optimize this? (for the offset case)
1039 void *real_member1 =
1040 mc_member_resolve(real_area1, type, member, (mc_address_space_t) snapshot1, process_index);
1041 void *real_member2 =
1042 mc_member_resolve(real_area2, type, member, (mc_address_space_t) snapshot2, process_index);
1044 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1045 snapshot1, snapshot2,
1046 previous, member->subtype, -1,
1054 case DW_TAG_union_type:
1055 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1056 snapshot1, snapshot2, previous,
1057 type->byte_size, check_ignore);
1067 /** Infer the type of a part of the block from the type of the block
1069 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1071 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1073 * @param type_id DWARF type ID of the root address
1075 * @return DWARF type ID for given offset
1077 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1078 int offset, int area_size,
1079 mc_snapshot_t snapshot, int process_index)
1082 // Beginning of the block, the infered variable type if the type of the block:
1086 switch (type->type) {
1087 case DW_TAG_structure_type:
1088 case DW_TAG_class_type:
1089 if (type->full_type)
1090 type = type->full_type;
1092 if (area_size != -1 && type->byte_size != area_size) {
1093 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1098 unsigned int cursor = 0;
1100 xbt_dynar_foreach(type->members, cursor, member) {
1102 if (!member->location.size) {
1103 // We have the offset, use it directly (shortcut):
1104 if (member->offset == offset)
1105 return member->subtype;
1108 mc_member_resolve(real_base_address, type, member,
1109 (mc_address_space_t) snapshot, process_index);
1110 if ((char*) real_member - (char *) real_base_address == offset)
1111 return member->subtype;
1119 /* FIXME : other cases ? */
1127 * @param area1 Process address for state 1
1128 * @param area2 Process address for state 2
1129 * @param snapshot1 Snapshot of state 1
1130 * @param snapshot2 Snapshot of state 2
1131 * @param previous Pairs of blocks already compared on the current path (or NULL)
1132 * @param type_id Type of variable
1133 * @param pointer_level
1134 * @return 0 (same), 1 (different), -1
1136 int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
1137 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1138 dw_type_t type, int pointer_level)
1140 mc_process_t process = &mc_model_checker->process();
1142 struct s_mc_diff *state = mc_diff_info;
1145 ssize_t block1, frag1, block2, frag2;
1147 int check_ignore = 0;
1149 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1151 int offset1 = 0, offset2 = 0;
1152 int new_size1 = -1, new_size2 = -1;
1153 dw_type_t new_type1 = NULL, new_type2 = NULL;
1155 int match_pairs = 0;
1157 // This is the address of std_heap->heapinfo in the application process:
1158 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
1160 const malloc_info* heapinfos1 = (const malloc_info*) MC_snapshot_read_pointer(
1161 snapshot1, heapinfo_address, process_index);
1162 const malloc_info* heapinfos2 = (const malloc_info*) MC_snapshot_read_pointer(
1163 snapshot2, heapinfo_address, 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 *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1178 (char *) state->std_heap_copy.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 *) state->std_heap_copy.heapbase)
1191 || (block1 > (ssize_t) state->heapsize1) || (block1 < 1)
1192 || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
1193 || (block2 > (ssize_t) state->heapsize2) || (block2 < 1)) {
1195 xbt_dynar_free(&previous);
1200 // Process address of the block:
1201 real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
1202 (char *) state->std_heap_copy.heapbase;
1203 real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
1204 (char *) state->std_heap_copy.heapbase;
1208 if (type->full_type)
1209 type = type->full_type;
1211 // This assume that for "boring" types (volatile ...) byte_size is absent:
1212 while (type->byte_size == 0 && type->subtype != NULL)
1213 type = type->subtype;
1216 if ((type->type == DW_TAG_pointer_type)
1217 || ((type->type == DW_TAG_base_type) && type->name != NULL
1218 && (!strcmp(type->name, "char"))))
1221 type_size = type->byte_size;
1225 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1226 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1228 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
1229 heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
1230 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
1231 heap_region2, &heapinfo_temp2, &heapinfos2[block2], 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 != (ssize_t) heapinfo1->busy_block.busy_size
1265 && type_size != (ssize_t) 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 *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1552 if (((char *) area < (char *) state->std_heap_copy.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;
1611 state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process());
1613 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1614 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1617 (malloc_info *) ((char *) heap1 +
1619 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1621 (malloc_info *) ((char *) heap2 +
1623 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1625 state->heapsize1 = heap1->heapsize;
1626 state->heapsize2 = heap2->heapsize;
1628 /* Start comparison */
1630 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1634 /* Check busy blocks */
1638 while (i <= state->heaplimit) {
1641 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1642 (char *) state->heapbase1));
1644 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1645 (char *) state->heapbase2));
1647 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1649 distance += BLOCKSIZE;
1650 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1651 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1656 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1657 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1662 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1664 if (state->heapinfo1[i].busy_block.size !=
1665 state->heapinfo2[i].busy_block.size) {
1667 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1668 state->heapinfo2[i].busy_block.size);
1669 i += max(state->heapinfo1[i].busy_block.size,
1670 state->heapinfo2[i].busy_block.size);
1672 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1673 i, state->heapinfo1[i].busy_block.size,
1674 state->heapinfo2[i].busy_block.size, distance);
1678 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1679 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1680 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1681 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);
1687 //while(k < (heapinfo1[i].busy_block.busy_size)){
1688 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1689 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1698 } else { /* Fragmented block */
1700 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1703 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1705 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1707 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1708 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1713 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1714 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1715 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);
1721 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1722 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1723 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=