1 /* mc_diff - Memory snapshooting and comparison */
3 /* Copyright (c) 2008-2014. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/ex_interface.h" /* internals of backtrace setup */
12 #include "xbt/mmalloc.h"
13 #include "mc_object_info.h"
14 #include "mc/datatypes.h"
15 #include "mc/mc_private.h"
16 #include "mc/mc_snapshot.h"
18 using simgrid::mc::remote;
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
23 "Logging specific to mc_diff in mc");
25 xbt_dynar_t mc_heap_comparison_ignore;
26 xbt_dynar_t stacks_areas;
30 /********************************* Backtrace ***********************************/
31 /******************************************************************************/
33 static void mmalloc_backtrace_block_display(void *heapinfo, int block)
38 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
39 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
43 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
44 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
46 /* xbt_ex_setup_backtrace(&e); */
47 /* if (e.used == 0) { */
48 /* fprintf(stderr, "(backtrace not set)\n"); */
49 /* } else if (e.bt_strings == NULL) { */
50 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
54 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
55 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
56 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
61 static void mmalloc_backtrace_fragment_display(void *heapinfo, int block,
67 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
68 /* e.used = XBT_BACKTRACE_SIZE; */
70 /* xbt_ex_setup_backtrace(&e); */
71 /* if (e.used == 0) { */
72 /* fprintf(stderr, "(backtrace not set)\n"); */
73 /* } else if (e.bt_strings == NULL) { */
74 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
78 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
79 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
80 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
86 static void mmalloc_backtrace_display(void *addr)
89 /* size_t block, frag_nb; */
92 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
94 /* type = heap->heapinfo[block].type; */
97 /* case MMALLOC_TYPE_HEAPINFO : */
98 /* case MMALLOC_TYPE_FREE : /\* Free block *\/ */
99 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
102 /* case 0: /\* Large block *\/ */
103 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
105 /* default: /\* Fragmented block *\/ */
106 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
107 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
108 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
111 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
117 static int compare_backtrace(int b1, int f1, int b2, int f2)
121 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
122 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
123 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
124 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
129 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
130 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
131 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
132 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
141 /*********************************** Heap comparison ***********************************/
142 /***************************************************************************************/
144 typedef char *type_name;
147 s_xbt_mheap_t std_heap_copy;
149 // Number of blocks in the heaps:
150 size_t heapsize1, heapsize2;
151 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_model_checker->process().get_heap();
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 = snapshot1->read<malloc_info*>(
457 (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
458 const malloc_info* heapinfos2 = snapshot2->read<malloc_info*>(
459 (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
461 while (i1 <= state->heaplimit) {
463 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
464 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
466 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
471 if (heapinfo1->type < 0) {
472 fprintf(stderr, "Unkown mmalloc block type.\n");
477 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
478 (char *) state->std_heap_copy.heapbase));
480 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
482 if (is_stack(addr_block1)) {
483 for (k = 0; k < heapinfo1->busy_block.size; k++)
484 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
485 for (k = 0; k < heapinfo2->busy_block.size; k++)
486 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
487 i1 += heapinfo1->busy_block.size;
491 if (state->equals_to1_(i1, 0).valid) {
500 /* Try first to associate to same block in the other heap */
501 if (heapinfo2->type == heapinfo1->type) {
503 if (state->equals_to2_(i1, 0).valid == 0) {
505 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
506 (char *) state->std_heap_copy.heapbase;
509 compare_heap_area(simgrid::mc::ProcessIndexMissing, 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) {
527 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
528 (char *) state->std_heap_copy.heapbase;
535 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
537 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
542 if (state->equals_to2_(i2, 0).valid) {
548 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, snapshot2,
551 if (res_compare != 1) {
552 for (k = 1; k < heapinfo2b->busy_block.size; k++)
553 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
554 for (k = 1; k < heapinfo1->busy_block.size; k++)
555 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
557 i1 += heapinfo1->busy_block.size;
565 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
566 heapinfo1->busy_block.busy_size, addr_block1);
567 i1 = state->heaplimit + 1;
572 } else { /* Fragmented block */
574 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
576 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
579 if (state->equals_to1_(i1, j1).valid)
583 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
588 /* Try first to associate to same fragment in the other heap */
589 if (heapinfo2->type == heapinfo1->type) {
591 if (state->equals_to2_(i1, j1).valid == 0) {
593 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
594 (char *) state->std_heap_copy.heapbase;
596 (void *) ((char *) addr_block2 +
597 (j1 << heapinfo2->type));
600 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot1, snapshot2,
603 if (res_compare != 1)
610 while (i2 <= state->heaplimit && !equal) {
612 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
613 heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
614 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)
641 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
642 (char *) state->std_heap_copy.heapbase;
644 (void *) ((char *) addr_block2 +
645 (j2 << heapinfo2b->type));
648 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot2, snapshot2,
651 if (res_compare != 1) {
664 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
665 i1, j1, heapinfo1->busy_frag.frag_size[j1],
667 i2 = state->heaplimit + 1;
668 i1 = state->heaplimit + 1;
681 /* All blocks/fragments are equal to another block/fragment ? */
684 for(i = 1; i <= state->heaplimit; i++) {
685 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
686 heap_region1, &heapinfo_temp1, &heapinfos1[i], 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 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
728 heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
729 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
730 if (i1 == state->heaplimit) {
731 if (heapinfo2->busy_block.busy_size > 0) {
732 if (state->equals_to2_(i, 0).valid == 0) {
733 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
734 // TODO, print address of the block
735 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
736 heapinfo2->busy_block.busy_size);
737 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
744 if (heapinfo2->type > 0) {
745 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
746 if (i1 == state->heaplimit) {
747 if (heapinfo2->busy_frag.frag_size[j] > 0) {
748 if (state->equals_to2_(i, j).valid == 0) {
749 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
750 // TODO, print address of the block
752 ("Block %zu, Fragment %zu not found (size used = %zd)",
754 heapinfo2->busy_frag.frag_size[j]);
755 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
765 if (i1 == state->heaplimit)
766 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
768 return ((nb_diff1 > 0) || (nb_diff2 > 0));
774 * @param real_area1 Process address for state 1
775 * @param real_area2 Process address for state 2
776 * @param snapshot1 Snapshot of state 1
777 * @param snapshot2 Snapshot of state 2
780 * @param check_ignore
782 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
783 const void *real_area1, const void *real_area2,
784 mc_snapshot_t snapshot1,
785 mc_snapshot_t snapshot2,
786 xbt_dynar_t previous, int size,
789 mc_process_t process = &mc_model_checker->process();
792 const void *addr_pointed1, *addr_pointed2;
793 int pointer_align, res_compare;
794 ssize_t ignore1, ignore2;
796 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
797 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
801 if (check_ignore > 0) {
803 heap_comparison_ignore_size(state->to_ignore1,
804 (char *) real_area1 + i)) != -1) {
806 heap_comparison_ignore_size(state->to_ignore2,
807 (char *) real_area2 + i)) == ignore1) {
820 if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
822 pointer_align = (i / sizeof(void *)) * sizeof(void *);
823 addr_pointed1 = snapshot1->read(
824 remote((void**)((char *) real_area1 + pointer_align)), process_index);
825 addr_pointed2 = snapshot2->read(
826 remote((void**)((char *) real_area2 + pointer_align)), process_index);
828 if (process->in_maestro_stack(remote(addr_pointed1))
829 && process->in_maestro_stack(remote(addr_pointed2))) {
830 i = pointer_align + sizeof(void *);
832 } else if (addr_pointed1 > state->std_heap_copy.heapbase
833 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
834 && addr_pointed2 > state->std_heap_copy.heapbase
835 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
836 // Both addreses are in the heap:
838 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
839 snapshot2, previous, NULL, 0);
840 if (res_compare == 1) {
843 i = pointer_align + sizeof(void *);
862 * @param real_area1 Process address for state 1
863 * @param real_area2 Process address for state 2
864 * @param snapshot1 Snapshot of state 1
865 * @param snapshot2 Snapshot of state 2
868 * @param area_size either a byte_size or an elements_count (?)
869 * @param check_ignore
870 * @param pointer_level
871 * @return 0 (same), 1 (different), -1 (unknown)
873 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
874 const void *real_area1, const void *real_area2,
875 mc_snapshot_t snapshot1,
876 mc_snapshot_t snapshot2,
877 xbt_dynar_t previous, dw_type_t type,
878 int area_size, int check_ignore,
882 if (is_stack(real_area1) && is_stack(real_area2))
885 ssize_t ignore1, ignore2;
887 if ((check_ignore > 0)
888 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
890 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
895 dw_type_t subtype, subsubtype;
897 unsigned int cursor = 0;
899 const void *addr_pointed1, *addr_pointed2;;
901 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
902 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
904 switch (type->type) {
905 case DW_TAG_unspecified_type:
908 case DW_TAG_base_type:
909 if (type->name != NULL && strcmp(type->name, "char") == 0) { /* String, hence random (arbitrary ?) size */
910 if (real_area1 == real_area2)
913 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
915 if (area_size != -1 && type->byte_size != area_size)
918 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
922 case DW_TAG_enumeration_type:
923 if (area_size != -1 && type->byte_size != area_size)
926 return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
929 case DW_TAG_const_type:
930 case DW_TAG_volatile_type:
932 type = type->subtype;
935 case DW_TAG_array_type:
936 subtype = type->subtype;
937 switch (subtype->type) {
938 case DW_TAG_unspecified_type:
941 case DW_TAG_base_type:
942 case DW_TAG_enumeration_type:
943 case DW_TAG_pointer_type:
944 case DW_TAG_reference_type:
945 case DW_TAG_rvalue_reference_type:
946 case DW_TAG_structure_type:
947 case DW_TAG_class_type:
948 case DW_TAG_union_type:
949 if (subtype->full_type)
950 subtype = subtype->full_type;
951 elm_size = subtype->byte_size;
953 // TODO, just remove the type indirection?
954 case DW_TAG_const_type:
956 case DW_TAG_volatile_type:
957 subsubtype = subtype->subtype;
958 if (subsubtype->full_type)
959 subsubtype = subsubtype->full_type;
960 elm_size = subsubtype->byte_size;
966 for (int i = 0; i < type->element_count; i++) {
967 // TODO, add support for variable stride (DW_AT_byte_stride)
969 compare_heap_area_with_type(state, process_index,
970 (char *) real_area1 + (i * elm_size),
971 (char *) real_area2 + (i * elm_size),
972 snapshot1, snapshot2, previous,
973 type->subtype, subtype->byte_size,
974 check_ignore, pointer_level);
979 case DW_TAG_reference_type:
980 case DW_TAG_rvalue_reference_type:
981 case DW_TAG_pointer_type:
982 if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
983 addr_pointed1 = snapshot1->read(remote((void**)real_area1), process_index);
984 addr_pointed2 = snapshot2->read(remote((void**)real_area2), process_index);
985 return (addr_pointed1 != addr_pointed2);;
988 if (pointer_level > 1) { /* Array of pointers */
989 for (size_t i = 0; i < (area_size / sizeof(void *)); i++) {
990 addr_pointed1 = snapshot1->read(
991 remote((void**)((char*) real_area1 + i * sizeof(void *))),
993 addr_pointed2 = snapshot2->read(
994 remote((void**)((char*) real_area2 + i * sizeof(void *))),
996 if (addr_pointed1 > state->std_heap_copy.heapbase
997 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
998 && addr_pointed2 > state->std_heap_copy.heapbase
999 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1001 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1002 snapshot2, previous, type->subtype,
1005 res = (addr_pointed1 != addr_pointed2);
1010 addr_pointed1 = snapshot1->read(remote((void**)real_area1), process_index);
1011 addr_pointed2 = snapshot2->read(remote((void**)real_area2), process_index);
1012 if (addr_pointed1 > state->std_heap_copy.heapbase
1013 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
1014 && addr_pointed2 > state->std_heap_copy.heapbase
1015 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
1016 return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
1017 snapshot2, previous, type->subtype,
1020 return (addr_pointed1 != addr_pointed2);
1024 case DW_TAG_structure_type:
1025 case DW_TAG_class_type:
1026 if (type->full_type)
1027 type = type->full_type;
1028 if (area_size != -1 && type->byte_size != area_size) {
1029 if (area_size > type->byte_size && area_size % type->byte_size == 0) {
1030 for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) {
1032 compare_heap_area_with_type(state, process_index,
1033 (char *) real_area1 + i * type->byte_size,
1034 (char *) real_area2 + i * type->byte_size,
1035 snapshot1, snapshot2, previous, type, -1,
1045 xbt_dynar_foreach(type->members, cursor, member) {
1046 // TODO, optimize this? (for the offset case)
1047 void *real_member1 =
1048 mc_member_resolve(real_area1, type, member, (mc_address_space_t) snapshot1, process_index);
1049 void *real_member2 =
1050 mc_member_resolve(real_area2, type, member, (mc_address_space_t) snapshot2, process_index);
1052 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1053 snapshot1, snapshot2,
1054 previous, member->subtype, -1,
1062 case DW_TAG_union_type:
1063 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1064 snapshot1, snapshot2, previous,
1065 type->byte_size, check_ignore);
1075 /** Infer the type of a part of the block from the type of the block
1077 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1079 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1081 * @param type_id DWARF type ID of the root address
1083 * @return DWARF type ID for given offset
1085 static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
1086 int offset, int area_size,
1087 mc_snapshot_t snapshot, int process_index)
1090 // Beginning of the block, the infered variable type if the type of the block:
1094 switch (type->type) {
1095 case DW_TAG_structure_type:
1096 case DW_TAG_class_type:
1097 if (type->full_type)
1098 type = type->full_type;
1100 if (area_size != -1 && type->byte_size != area_size) {
1101 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1106 unsigned int cursor = 0;
1108 xbt_dynar_foreach(type->members, cursor, member) {
1110 if (!member->location.size) {
1111 // We have the offset, use it directly (shortcut):
1112 if (member->offset == offset)
1113 return member->subtype;
1116 mc_member_resolve(real_base_address, type, member,
1117 snapshot, process_index);
1118 if ((char*) real_member - (char *) real_base_address == offset)
1119 return member->subtype;
1127 /* FIXME : other cases ? */
1135 * @param area1 Process address for state 1
1136 * @param area2 Process address for state 2
1137 * @param snapshot1 Snapshot of state 1
1138 * @param snapshot2 Snapshot of state 2
1139 * @param previous Pairs of blocks already compared on the current path (or NULL)
1140 * @param type_id Type of variable
1141 * @param pointer_level
1142 * @return 0 (same), 1 (different), -1
1144 int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
1145 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1146 dw_type_t type, int pointer_level)
1148 mc_process_t process = &mc_model_checker->process();
1150 struct s_mc_diff *state = mc_diff_info;
1153 ssize_t block1, frag1, block2, frag2;
1155 int check_ignore = 0;
1157 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1159 int offset1 = 0, offset2 = 0;
1160 int new_size1 = -1, new_size2 = -1;
1161 dw_type_t new_type1 = NULL, new_type2 = NULL;
1163 int match_pairs = 0;
1165 // This is the address of std_heap->heapinfo in the application process:
1166 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
1168 const malloc_info* heapinfos1 = snapshot1->read(
1169 remote((const malloc_info**)heapinfo_address), process_index);
1170 const malloc_info* heapinfos2 = snapshot2->read(
1171 remote((const malloc_info**)heapinfo_address), process_index);
1173 malloc_info heapinfo_temp1, heapinfo_temp2;
1175 if (previous == NULL) {
1177 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1180 // Get block number:
1183 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1186 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1188 // If either block is a stack block:
1189 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1190 add_heap_area_pair(previous, block1, -1, block2, -1);
1192 match_equals(state, previous);
1193 xbt_dynar_free(&previous);
1197 // If either block is not in the expected area of memory:
1198 if (((char *) area1 < (char *) state->std_heap_copy.heapbase)
1199 || (block1 > (ssize_t) state->heapsize1) || (block1 < 1)
1200 || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
1201 || (block2 > (ssize_t) state->heapsize2) || (block2 < 1)) {
1203 xbt_dynar_free(&previous);
1208 // Process address of the block:
1209 real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
1210 (char *) state->std_heap_copy.heapbase;
1211 real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
1212 (char *) state->std_heap_copy.heapbase;
1216 if (type->full_type)
1217 type = type->full_type;
1219 // This assume that for "boring" types (volatile ...) byte_size is absent:
1220 while (type->byte_size == 0 && type->subtype != NULL)
1221 type = type->subtype;
1224 if ((type->type == DW_TAG_pointer_type)
1225 || ((type->type == DW_TAG_base_type) && type->name != NULL
1226 && (!strcmp(type->name, "char"))))
1229 type_size = type->byte_size;
1233 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1234 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1236 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
1237 heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
1238 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
1239 heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
1241 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1242 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1246 match_equals(state, previous);
1247 xbt_dynar_free(&previous);
1251 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1252 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1253 /* Complete block */
1255 // TODO, lookup variable type from block type as done for fragmented blocks
1257 offset1 = (char *) area1 - (char *) real_addr_block1;
1258 offset2 = (char *) area2 - (char *) real_addr_block2;
1260 if (state->equals_to1_(block1, 0).valid
1261 && state->equals_to2_(block2, 0).valid) {
1262 if (equal_blocks(state, block1, block2)) {
1264 match_equals(state, previous);
1265 xbt_dynar_free(&previous);
1271 if (type_size != -1) {
1272 if (type_size != (ssize_t) heapinfo1->busy_block.busy_size
1273 && type_size != (ssize_t) heapinfo2->busy_block.busy_size
1274 && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) {
1276 match_equals(state, previous);
1277 xbt_dynar_free(&previous);
1283 if (heapinfo1->busy_block.size !=
1284 heapinfo2->busy_block.size) {
1286 xbt_dynar_free(&previous);
1291 if (heapinfo1->busy_block.busy_size !=
1292 heapinfo2->busy_block.busy_size) {
1294 xbt_dynar_free(&previous);
1299 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1301 match_equals(state, previous);
1302 xbt_dynar_free(&previous);
1307 size = heapinfo1->busy_block.busy_size;
1309 // Remember (basic) type inference.
1310 // The current data structure only allows us to do this for the whole block.
1311 if (type != NULL && area1 == real_addr_block1) {
1312 state->types1_(block1, 0) = type;
1314 if (type != NULL && area2 == real_addr_block2) {
1315 state->types2_(block2, 0) = type;
1320 match_equals(state, previous);
1321 xbt_dynar_free(&previous);
1329 if ((heapinfo1->busy_block.ignore > 0)
1330 && (heapinfo2->busy_block.ignore ==
1331 heapinfo1->busy_block.ignore))
1332 check_ignore = heapinfo1->busy_block.ignore;
1334 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1338 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1340 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1342 // Process address of the fragment:
1344 (void *) ((char *) real_addr_block1 +
1345 (frag1 << heapinfo1->type));
1347 (void *) ((char *) real_addr_block2 +
1348 (frag2 << heapinfo2->type));
1350 // Check the size of the fragments against the size of the type:
1351 if (type_size != -1) {
1352 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1353 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1355 match_equals(state, previous);
1356 xbt_dynar_free(&previous);
1361 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1362 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1364 match_equals(state, previous);
1365 xbt_dynar_free(&previous);
1371 // Check if the blocks are already matched together:
1372 if (state->equals_to1_(block1, frag1).valid
1373 && state->equals_to2_(block2, frag2).valid) {
1374 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1376 match_equals(state, previous);
1377 xbt_dynar_free(&previous);
1382 // Compare the size of both fragments:
1383 if (heapinfo1->busy_frag.frag_size[frag1] !=
1384 heapinfo2->busy_frag.frag_size[frag2]) {
1385 if (type_size == -1) {
1387 match_equals(state, previous);
1388 xbt_dynar_free(&previous);
1393 xbt_dynar_free(&previous);
1399 // Size of the fragment:
1400 size = heapinfo1->busy_frag.frag_size[frag1];
1402 // Remember (basic) type inference.
1403 // The current data structure only allows us to do this for the whole fragment.
1404 if (type != NULL && area1 == real_addr_frag1) {
1405 state->types1_(block1, frag1) = type;
1407 if (type != NULL && area2 == real_addr_frag2) {
1408 state->types2_(block2, frag2) = type;
1410 // The type of the variable is already known:
1415 // Type inference from the block type.
1416 else if (state->types1_(block1, frag1) != NULL
1417 || state->types2_(block2, frag2) != NULL) {
1419 offset1 = (char *) area1 - (char *) real_addr_frag1;
1420 offset2 = (char *) area2 - (char *) real_addr_frag2;
1422 if (state->types1_(block1, frag1) != NULL
1423 && state->types2_(block2, frag2) != NULL) {
1425 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1426 offset1, size, snapshot1, process_index);
1428 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1429 offset1, size, snapshot2, process_index);
1430 } else if (state->types1_(block1, frag1) != NULL) {
1432 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1433 offset1, size, snapshot1, process_index);
1435 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1436 offset2, size, snapshot2, process_index);
1437 } else if (state->types2_(block2, frag2) != NULL) {
1439 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1440 offset1, size, snapshot1, process_index);
1442 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1443 offset2, size, snapshot2, process_index);
1446 match_equals(state, previous);
1447 xbt_dynar_free(&previous);
1452 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1455 while (type->byte_size == 0 && type->subtype != NULL)
1456 type = type->subtype;
1457 new_size1 = type->byte_size;
1460 while (type->byte_size == 0 && type->subtype != NULL)
1461 type = type->subtype;
1462 new_size2 = type->byte_size;
1466 match_equals(state, previous);
1467 xbt_dynar_free(&previous);
1473 if (new_size1 > 0 && new_size1 == new_size2) {
1478 if (offset1 == 0 && offset2 == 0) {
1479 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1481 match_equals(state, previous);
1482 xbt_dynar_free(&previous);
1490 match_equals(state, previous);
1491 xbt_dynar_free(&previous);
1496 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1497 && (heapinfo2->busy_frag.ignore[frag2] ==
1498 heapinfo1->busy_frag.ignore[frag1]))
1499 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1504 xbt_dynar_free(&previous);
1511 /* Start comparison */
1514 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1515 previous, type, size, check_ignore,
1519 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1520 previous, size, check_ignore);
1522 if (res_compare == 1) {
1524 xbt_dynar_free(&previous);
1529 match_equals(state, previous);
1530 xbt_dynar_free(&previous);
1536 /*********************************************** Miscellaneous ***************************************************/
1537 /****************************************************************************************************************/
1539 // Not used and broken code:
1543 static int get_pointed_area_size(void *area, int heap)
1546 struct s_mc_diff *state = mc_diff_info;
1549 malloc_info *heapinfo;
1552 heapinfo = state->heapinfo1;
1554 heapinfo = state->heapinfo2;
1558 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1560 if (((char *) area < (char *) state->std_heap_copy.heapbase)
1561 || (block > state->heapsize1) || (block < 1))
1564 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1566 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1567 return (int) heapinfo[block].busy_block.busy_size;
1570 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1571 return (int) heapinfo[block].busy_frag.frag_size[frag];
1576 char *get_type_description(mc_object_info_t info, char *type_name)
1579 xbt_dict_cursor_t dict_cursor;
1583 xbt_dict_foreach(info->types, dict_cursor, type_origin, type) {
1584 if (type->name && (strcmp(type->name, type_name) == 0)
1585 && type->byte_size > 0) {
1586 xbt_dict_cursor_free(&dict_cursor);
1591 xbt_dict_cursor_free(&dict_cursor);
1597 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1601 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1604 struct s_mc_diff *state = mc_diff_info;
1606 if (heap1 == NULL && heap1 == NULL) {
1607 XBT_DEBUG("Malloc descriptors null");
1611 if (heap1->heaplimit != heap2->heaplimit) {
1612 XBT_DEBUG("Different limit of valid info table indices");
1616 /* Heap information */
1617 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1619 state->std_heap_copy = *mc_model_checker->process().get_heap();
1621 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1622 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1625 (malloc_info *) ((char *) heap1 +
1627 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1629 (malloc_info *) ((char *) heap2 +
1631 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1633 state->heapsize1 = heap1->heapsize;
1634 state->heapsize2 = heap2->heapsize;
1636 /* Start comparison */
1638 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1642 /* Check busy blocks */
1646 while (i <= state->heaplimit) {
1649 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1650 (char *) state->heapbase1));
1652 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1653 (char *) state->heapbase2));
1655 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1657 distance += BLOCKSIZE;
1658 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1659 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1664 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1665 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1670 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1672 if (state->heapinfo1[i].busy_block.size !=
1673 state->heapinfo2[i].busy_block.size) {
1675 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1676 state->heapinfo2[i].busy_block.size);
1677 i += max(state->heapinfo1[i].busy_block.size,
1678 state->heapinfo2[i].busy_block.size);
1680 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1681 i, state->heapinfo1[i].busy_block.size,
1682 state->heapinfo2[i].busy_block.size, distance);
1686 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1687 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1688 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1689 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);
1695 //while(k < (heapinfo1[i].busy_block.busy_size)){
1696 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1697 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1706 } else { /* Fragmented block */
1708 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1711 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1713 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1715 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1716 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1721 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1722 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1723 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);
1729 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1730 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1731 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=