1 /* mc_diff - Memory snapshooting and comparison */
3 /* Copyright (c) 2008-2014. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/ex_interface.h" /* internals of backtrace setup */
12 #include "xbt/mmalloc.h"
13 #include "mc_object_info.h"
14 #include "mc/datatypes.h"
15 #include "mc/mc_private.h"
16 #include "mc/mc_snapshot.h"
18 using simgrid::mc::remote;
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
23 "Logging specific to mc_diff in mc");
25 xbt_dynar_t mc_heap_comparison_ignore;
26 xbt_dynar_t stacks_areas;
30 /********************************* Backtrace ***********************************/
31 /******************************************************************************/
33 static void mmalloc_backtrace_block_display(void *heapinfo, int block)
38 /* if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) { */
39 /* fprintf(stderr, "No backtrace available for that block, sorry.\n"); */
43 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE); */
44 /* e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size; */
46 /* xbt_ex_setup_backtrace(&e); */
47 /* if (e.used == 0) { */
48 /* fprintf(stderr, "(backtrace not set)\n"); */
49 /* } else if (e.bt_strings == NULL) { */
50 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
54 /* fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used); */
55 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
56 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
61 static void mmalloc_backtrace_fragment_display(void *heapinfo, int block,
67 /* memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE); */
68 /* e.used = XBT_BACKTRACE_SIZE; */
70 /* xbt_ex_setup_backtrace(&e); */
71 /* if (e.used == 0) { */
72 /* fprintf(stderr, "(backtrace not set)\n"); */
73 /* } else if (e.bt_strings == NULL) { */
74 /* fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet"); */
78 /* fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used); */
79 /* for (i = 0; i < e.used; i++) /\* no need to display "xbt_backtrace_display" *\/{ */
80 /* fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4); */
86 static void mmalloc_backtrace_display(void *addr)
89 /* size_t block, frag_nb; */
92 /* block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1); */
94 /* type = heap->heapinfo[block].type; */
97 /* case MMALLOC_TYPE_HEAPINFO : */
98 /* case MMALLOC_TYPE_FREE : /\* Free block *\/ */
99 /* fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n"); */
102 /* case 0: /\* Large block *\/ */
103 /* mmalloc_backtrace_block_display(heap->heapinfo, block); */
105 /* default: /\* Fragmented block *\/ */
106 /* frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type; */
107 /* if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ */
108 /* fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n"); */
111 /* mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb); */
117 static int compare_backtrace(int b1, int f1, int b2, int f2)
121 for(i=0; i< XBT_BACKTRACE_SIZE; i++){
122 if(heapinfo1[b1].busy_frag.bt[f1][i] != heapinfo2[b2].busy_frag.bt[f2][i]){
123 //mmalloc_backtrace_fragment_display((void*)heapinfo1, b1, f1);
124 //mmalloc_backtrace_fragment_display((void*)heapinfo2, b2, f2);
129 for(i=0; i< heapinfo1[b1].busy_block.bt_size; i++){
130 if(heapinfo1[b1].busy_block.bt[i] != heapinfo2[b2].busy_block.bt[i]){
131 //mmalloc_backtrace_block_display((void*)heapinfo1, b1);
132 //mmalloc_backtrace_block_display((void*)heapinfo2, b2);
141 /*********************************** Heap comparison ***********************************/
142 /***************************************************************************************/
144 typedef char *type_name;
147 s_xbt_mheap_t std_heap_copy;
149 // Number of blocks in the heaps:
150 size_t heapsize1, heapsize2;
151 std::vector<s_mc_heap_ignore_region_t>* to_ignore1;
152 std::vector<s_mc_heap_ignore_region_t>* to_ignore2;
153 s_heap_area_t *equals_to1, *equals_to2;
154 simgrid::mc::Type **types1;
155 simgrid::mc::Type **types2;
159 #define equals_to1_(i,j) equals_to1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
160 #define equals_to2_(i,j) equals_to2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
161 #define types1_(i,j) types1[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
162 #define types2_(i,j) types2[ MAX_FRAGMENT_PER_BLOCK*(i) + (j)]
164 __thread struct s_mc_diff *mc_diff_info = NULL;
166 /*********************************** Free functions ************************************/
168 static void heap_area_pair_free(heap_area_pair_t pair)
174 static void heap_area_pair_free_voidp(void *d)
176 heap_area_pair_free((heap_area_pair_t) * (void **) d);
179 static void heap_area_free(heap_area_t area)
185 /************************************************************************************/
187 static s_heap_area_t make_heap_area(int block, int fragment)
192 area.fragment = fragment;
197 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
198 int block2, int fragment2)
201 unsigned int cursor = 0;
202 heap_area_pair_t current_pair;
204 xbt_dynar_foreach(list, cursor, current_pair) {
205 if (current_pair->block1 == block1 && current_pair->block2 == block2
206 && current_pair->fragment1 == fragment1
207 && current_pair->fragment2 == fragment2)
214 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
215 int block2, int fragment2)
218 if (is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)) {
219 heap_area_pair_t pair = NULL;
220 pair = xbt_new0(s_heap_area_pair_t, 1);
221 pair->block1 = block1;
222 pair->fragment1 = fragment1;
223 pair->block2 = block2;
224 pair->fragment2 = fragment2;
226 xbt_dynar_push(list, &pair);
234 static ssize_t heap_comparison_ignore_size(std::vector<s_mc_heap_ignore_region_t>* ignore_list,
238 int end = ignore_list->size() - 1;
240 while (start <= end) {
241 unsigned int cursor = (start + end) / 2;
242 s_mc_heap_ignore_region_t region = (*ignore_list)[cursor];
243 if (region.address == address)
245 if (region.address < address)
247 if (region.address > address)
254 static int is_stack(const void *address)
256 unsigned int cursor = 0;
257 stack_region_t stack;
259 xbt_dynar_foreach(stacks_areas, cursor, stack) {
260 if (address == stack->address)
267 // TODO, this should depend on the snapshot?
268 static int is_block_stack(int block)
270 unsigned int cursor = 0;
271 stack_region_t stack;
273 xbt_dynar_foreach(stacks_areas, cursor, stack) {
274 if (block == stack->block)
281 static void match_equals(struct s_mc_diff *state, xbt_dynar_t list)
284 unsigned int cursor = 0;
285 heap_area_pair_t current_pair;
287 xbt_dynar_foreach(list, cursor, current_pair) {
289 if (current_pair->fragment1 != -1) {
291 state->equals_to1_(current_pair->block1, current_pair->fragment1) =
292 make_heap_area(current_pair->block2, current_pair->fragment2);
293 state->equals_to2_(current_pair->block2, current_pair->fragment2) =
294 make_heap_area(current_pair->block1, current_pair->fragment1);
298 state->equals_to1_(current_pair->block1, 0) =
299 make_heap_area(current_pair->block2, current_pair->fragment2);
300 state->equals_to2_(current_pair->block2, 0) =
301 make_heap_area(current_pair->block1, current_pair->fragment1);
308 /** Check whether two blocks are known to be matching
310 * @param state State used
311 * @param b1 Block of state 1
312 * @param b2 Block of state 2
313 * @return if the blocks are known to be matching
315 static int equal_blocks(struct s_mc_diff *state, int b1, int b2)
318 if (state->equals_to1_(b1, 0).block == b2
319 && state->equals_to2_(b2, 0).block == b1)
325 /** Check whether two fragments are known to be matching
327 * @param state State used
328 * @param b1 Block of state 1
329 * @param f1 Fragment of state 1
330 * @param b2 Block of state 2
331 * @param f2 Fragment of state 2
332 * @return if the fragments are known to be matching
334 static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
338 if (state->equals_to1_(b1, f1).block == b2
339 && state->equals_to1_(b1, f1).fragment == f2
340 && state->equals_to2_(b2, f2).block == b1
341 && state->equals_to2_(b2, f2).fragment == f1)
349 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2,
350 std::vector<s_mc_heap_ignore_region_t>* i1,
351 std::vector<s_mc_heap_ignore_region_t>* i2)
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 = (simgrid::mc::Type**)
385 realloc(state->types1,
386 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
387 sizeof(simgrid::mc::Type*));
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 = (simgrid::mc::Type**)
393 realloc(state->types2,
394 state->heaplimit * MAX_FRAGMENT_PER_BLOCK *
395 sizeof(simgrid::mc::Type*));
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 *));
414 void reset_heap_information()
419 // TODO, have a robust way to find it in O(1)
421 mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
423 size_t n = snapshot->snapshot_regions.size();
424 for (size_t i=0; i!=n; ++i) {
425 mc_mem_region_t region = snapshot->snapshot_regions[i].get();
426 if (region->region_type() == simgrid::mc::RegionType::Heap)
429 xbt_die("No heap region");
432 int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
434 simgrid::mc::Process* process = &mc_model_checker->process();
435 struct s_mc_diff *state = mc_diff_info;
437 /* Start comparison */
438 size_t i1, i2, j1, j2, k;
439 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
440 int nb_diff1 = 0, nb_diff2 = 0;
442 int equal, res_compare = 0;
444 /* Check busy blocks */
448 malloc_info heapinfo_temp1, heapinfo_temp2;
449 malloc_info heapinfo_temp2b;
451 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
452 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
454 // This is the address of std_heap->heapinfo in the application process:
455 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
457 // This is in snapshot do not use them directly:
458 const malloc_info* heapinfos1 = snapshot1->read<malloc_info*>(
459 (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
460 const malloc_info* heapinfos2 = snapshot2->read<malloc_info*>(
461 (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
463 while (i1 <= state->heaplimit) {
465 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
466 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
468 if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
473 if (heapinfo1->type < 0) {
474 fprintf(stderr, "Unkown mmalloc block type.\n");
479 ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
480 (char *) state->std_heap_copy.heapbase));
482 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
484 if (is_stack(addr_block1)) {
485 for (k = 0; k < heapinfo1->busy_block.size; k++)
486 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
487 for (k = 0; k < heapinfo2->busy_block.size; k++)
488 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
489 i1 += heapinfo1->busy_block.size;
493 if (state->equals_to1_(i1, 0).valid) {
502 /* Try first to associate to same block in the other heap */
503 if (heapinfo2->type == heapinfo1->type) {
505 if (state->equals_to2_(i1, 0).valid == 0) {
507 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
508 (char *) state->std_heap_copy.heapbase;
511 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, snapshot2,
514 if (res_compare != 1) {
515 for (k = 1; k < heapinfo2->busy_block.size; k++)
516 state->equals_to2_(i1 + k, 0) = make_heap_area(i1, -1);
517 for (k = 1; k < heapinfo1->busy_block.size; k++)
518 state->equals_to1_(i1 + k, 0) = make_heap_area(i1, -1);
520 i1 += heapinfo1->busy_block.size;
527 while (i2 <= state->heaplimit && !equal) {
529 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
530 (char *) state->std_heap_copy.heapbase;
537 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
539 if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
544 if (state->equals_to2_(i2, 0).valid) {
550 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, snapshot2,
553 if (res_compare != 1) {
554 for (k = 1; k < heapinfo2b->busy_block.size; k++)
555 state->equals_to2_(i2 + k, 0) = make_heap_area(i1, -1);
556 for (k = 1; k < heapinfo1->busy_block.size; k++)
557 state->equals_to1_(i1 + k, 0) = make_heap_area(i2, -1);
559 i1 += heapinfo1->busy_block.size;
567 XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1,
568 heapinfo1->busy_block.busy_size, addr_block1);
569 i1 = state->heaplimit + 1;
574 } else { /* Fragmented block */
576 for (j1 = 0; j1 < (size_t) (BLOCKSIZE >> heapinfo1->type); j1++) {
578 if (heapinfo1->busy_frag.frag_size[j1] == -1) /* Free fragment */
581 if (state->equals_to1_(i1, j1).valid)
585 (void *) ((char *) addr_block1 + (j1 << heapinfo1->type));
590 /* Try first to associate to same fragment in the other heap */
591 if (heapinfo2->type == heapinfo1->type) {
593 if (state->equals_to2_(i1, j1).valid == 0) {
595 addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
596 (char *) state->std_heap_copy.heapbase;
598 (void *) ((char *) addr_block2 +
599 (j1 << heapinfo2->type));
602 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot1, snapshot2,
605 if (res_compare != 1)
612 while (i2 <= state->heaplimit && !equal) {
614 const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
615 heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
616 sizeof(malloc_info));
618 if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
623 // We currently do not match fragments with unfragmented blocks (maybe we should).
624 if (heapinfo2b->type == MMALLOC_TYPE_UNFRAGMENTED) {
629 if (heapinfo2b->type < 0) {
630 fprintf(stderr, "Unkown mmalloc block type.\n");
634 for (j2 = 0; j2 < (size_t) (BLOCKSIZE >> heapinfo2b->type);
637 if (i2 == i1 && j2 == j1)
640 if (state->equals_to2_(i2, j2).valid)
643 addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
644 (char *) state->std_heap_copy.heapbase;
646 (void *) ((char *) addr_block2 +
647 (j2 << heapinfo2b->type));
650 compare_heap_area(simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot2, snapshot2,
653 if (res_compare != 1) {
666 ("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n",
667 i1, j1, heapinfo1->busy_frag.frag_size[j1],
669 i2 = state->heaplimit + 1;
670 i1 = state->heaplimit + 1;
683 /* All blocks/fragments are equal to another block/fragment ? */
686 for(i = 1; i <= state->heaplimit; i++) {
687 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
688 heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
689 if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
690 if (i1 == state->heaplimit) {
691 if (heapinfo1->busy_block.busy_size > 0) {
692 if (state->equals_to1_(i, 0).valid == 0) {
693 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
695 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
696 heapinfo1->busy_block.busy_size);
697 //mmalloc_backtrace_block_display((void*)heapinfo1, i);
704 if (heapinfo1->type > 0) {
705 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++) {
706 if (i1 == state->heaplimit) {
707 if (heapinfo1->busy_frag.frag_size[j] > 0) {
708 if (state->equals_to1_(i, j).valid == 0) {
709 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
710 // TODO, print fragment address
712 ("Block %zu, Fragment %zu not found (size used = %zd)",
714 heapinfo1->busy_frag.frag_size[j]);
715 //mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
725 if (i1 == state->heaplimit)
726 XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
728 for (i=1; i <= state->heaplimit; i++) {
729 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
730 heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
731 if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
732 if (i1 == state->heaplimit) {
733 if (heapinfo2->busy_block.busy_size > 0) {
734 if (state->equals_to2_(i, 0).valid == 0) {
735 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
736 // TODO, print address of the block
737 XBT_DEBUG("Block %zu not found (size used = %zu)", i,
738 heapinfo2->busy_block.busy_size);
739 //mmalloc_backtrace_block_display((void*)heapinfo2, i);
746 if (heapinfo2->type > 0) {
747 for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++) {
748 if (i1 == state->heaplimit) {
749 if (heapinfo2->busy_frag.frag_size[j] > 0) {
750 if (state->equals_to2_(i, j).valid == 0) {
751 if (XBT_LOG_ISENABLED(mc_diff, xbt_log_priority_debug)) {
752 // TODO, print address of the block
754 ("Block %zu, Fragment %zu not found (size used = %zd)",
756 heapinfo2->busy_frag.frag_size[j]);
757 //mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
767 if (i1 == state->heaplimit)
768 XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2);
770 return ((nb_diff1 > 0) || (nb_diff2 > 0));
776 * @param real_area1 Process address for state 1
777 * @param real_area2 Process address for state 2
778 * @param snapshot1 Snapshot of state 1
779 * @param snapshot2 Snapshot of state 2
782 * @param check_ignore
784 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
785 const void *real_area1, const void *real_area2,
786 mc_snapshot_t snapshot1,
787 mc_snapshot_t snapshot2,
788 xbt_dynar_t previous, int size,
791 simgrid::mc::Process* process = &mc_model_checker->process();
794 const void *addr_pointed1, *addr_pointed2;
795 int pointer_align, res_compare;
796 ssize_t ignore1, ignore2;
798 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
799 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
803 if (check_ignore > 0) {
805 heap_comparison_ignore_size(state->to_ignore1,
806 (char *) real_area1 + i)) != -1) {
808 heap_comparison_ignore_size(state->to_ignore2,
809 (char *) real_area2 + i)) == ignore1) {
822 if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
824 pointer_align = (i / sizeof(void *)) * sizeof(void *);
825 addr_pointed1 = snapshot1->read(
826 remote((void**)((char *) real_area1 + pointer_align)), process_index);
827 addr_pointed2 = snapshot2->read(
828 remote((void**)((char *) real_area2 + pointer_align)), process_index);
830 if (process->in_maestro_stack(remote(addr_pointed1))
831 && process->in_maestro_stack(remote(addr_pointed2))) {
832 i = pointer_align + sizeof(void *);
834 } else if (addr_pointed1 > state->std_heap_copy.heapbase
835 && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
836 && addr_pointed2 > state->std_heap_copy.heapbase
837 && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
838 // Both addreses are in the heap:
840 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
841 snapshot2, previous, NULL, 0);
842 if (res_compare == 1) {
845 i = pointer_align + sizeof(void *);
864 * @param real_area1 Process address for state 1
865 * @param real_area2 Process address for state 2
866 * @param snapshot1 Snapshot of state 1
867 * @param snapshot2 Snapshot of state 2
870 * @param area_size either a byte_size or an elements_count (?)
871 * @param check_ignore
872 * @param pointer_level
873 * @return 0 (same), 1 (different), -1 (unknown)
875 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
876 const void *real_area1, const void *real_area2,
877 mc_snapshot_t snapshot1,
878 mc_snapshot_t snapshot2,
879 xbt_dynar_t previous, simgrid::mc::Type* type,
880 int area_size, int check_ignore,
884 if (is_stack(real_area1) && is_stack(real_area2))
887 ssize_t ignore1, ignore2;
889 if ((check_ignore > 0)
890 && ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
892 && ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
897 simgrid::mc::Type *subtype, *subsubtype;
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.empty() && type->name == "char") { /* 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,
1044 for(simgrid::mc::Type& member : type->members) {
1045 // TODO, optimize this? (for the offset case)
1046 void *real_member1 =
1047 mc_member_resolve(real_area1, type, &member, (simgrid::mc::AddressSpace*) snapshot1, process_index);
1048 void *real_member2 =
1049 mc_member_resolve(real_area2, type, &member, (simgrid::mc::AddressSpace*) snapshot2, process_index);
1051 compare_heap_area_with_type(state, process_index, real_member1, real_member2,
1052 snapshot1, snapshot2,
1053 previous, member.subtype, -1,
1061 case DW_TAG_union_type:
1062 return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
1063 snapshot1, snapshot2, previous,
1064 type->byte_size, check_ignore);
1074 /** Infer the type of a part of the block from the type of the block
1076 * TODO, handle DW_TAG_array_type as well as arrays of the object ((*p)[5], p[5])
1078 * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
1080 * @param type_id DWARF type ID of the root address
1082 * @return DWARF type ID for given offset
1084 static simgrid::mc::Type* get_offset_type(void *real_base_address, simgrid::mc::Type* type,
1085 int offset, int area_size,
1086 mc_snapshot_t snapshot, int process_index)
1089 // Beginning of the block, the infered variable type if the type of the block:
1093 switch (type->type) {
1094 case DW_TAG_structure_type:
1095 case DW_TAG_class_type:
1096 if (type->full_type)
1097 type = type->full_type;
1099 if (area_size != -1 && type->byte_size != area_size) {
1100 if (area_size > type->byte_size && area_size % type->byte_size == 0)
1105 for(simgrid::mc::Type& member : type->members) {
1107 if (member.has_offset_location()) {
1108 // We have the offset, use it directly (shortcut):
1109 if (member.offset() == offset)
1110 return member.subtype;
1113 mc_member_resolve(real_base_address, type, &member,
1114 snapshot, process_index);
1115 if ((char*) real_member - (char *) real_base_address == offset)
1116 return member.subtype;
1124 /* FIXME : other cases ? */
1132 * @param area1 Process address for state 1
1133 * @param area2 Process address for state 2
1134 * @param snapshot1 Snapshot of state 1
1135 * @param snapshot2 Snapshot of state 2
1136 * @param previous Pairs of blocks already compared on the current path (or NULL)
1137 * @param type_id Type of variable
1138 * @param pointer_level
1139 * @return 0 (same), 1 (different), -1
1141 int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
1142 mc_snapshot_t snapshot2, xbt_dynar_t previous,
1143 simgrid::mc::Type* type, int pointer_level)
1145 simgrid::mc::Process* process = &mc_model_checker->process();
1147 struct s_mc_diff *state = mc_diff_info;
1150 ssize_t block1, frag1, block2, frag2;
1152 int check_ignore = 0;
1154 void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
1156 int offset1 = 0, offset2 = 0;
1157 int new_size1 = -1, new_size2 = -1;
1158 simgrid::mc::Type *new_type1 = NULL, *new_type2 = NULL;
1160 int match_pairs = 0;
1162 // This is the address of std_heap->heapinfo in the application process:
1163 void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
1165 const malloc_info* heapinfos1 = snapshot1->read(
1166 remote((const malloc_info**)heapinfo_address), process_index);
1167 const malloc_info* heapinfos2 = snapshot2->read(
1168 remote((const malloc_info**)heapinfo_address), process_index);
1170 malloc_info heapinfo_temp1, heapinfo_temp2;
1172 if (previous == NULL) {
1174 xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
1177 // Get block number:
1180 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1183 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1185 // If either block is a stack block:
1186 if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
1187 add_heap_area_pair(previous, block1, -1, block2, -1);
1189 match_equals(state, previous);
1190 xbt_dynar_free(&previous);
1194 // If either block is not in the expected area of memory:
1195 if (((char *) area1 < (char *) state->std_heap_copy.heapbase)
1196 || (block1 > (ssize_t) state->heapsize1) || (block1 < 1)
1197 || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
1198 || (block2 > (ssize_t) state->heapsize2) || (block2 < 1)) {
1200 xbt_dynar_free(&previous);
1205 // Process address of the block:
1206 real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
1207 (char *) state->std_heap_copy.heapbase;
1208 real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
1209 (char *) state->std_heap_copy.heapbase;
1213 if (type->full_type)
1214 type = type->full_type;
1216 // This assume that for "boring" types (volatile ...) byte_size is absent:
1217 while (type->byte_size == 0 && type->subtype != NULL)
1218 type = type->subtype;
1221 if ((type->type == DW_TAG_pointer_type)
1222 || ((type->type == DW_TAG_base_type) && !type->name.empty()
1223 && type->name == "char"))
1226 type_size = type->byte_size;
1230 mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
1231 mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
1233 const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
1234 heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
1235 const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
1236 heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
1238 if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
1239 && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
1243 match_equals(state, previous);
1244 xbt_dynar_free(&previous);
1248 } else if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED
1249 && heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
1250 /* Complete block */
1252 // TODO, lookup variable type from block type as done for fragmented blocks
1254 offset1 = (char *) area1 - (char *) real_addr_block1;
1255 offset2 = (char *) area2 - (char *) real_addr_block2;
1257 if (state->equals_to1_(block1, 0).valid
1258 && state->equals_to2_(block2, 0).valid) {
1259 if (equal_blocks(state, block1, block2)) {
1261 match_equals(state, previous);
1262 xbt_dynar_free(&previous);
1268 if (type_size != -1) {
1269 if (type_size != (ssize_t) heapinfo1->busy_block.busy_size
1270 && type_size != (ssize_t) heapinfo2->busy_block.busy_size
1271 && (type->name.empty() || type->name == "struct s_smx_context")) {
1273 match_equals(state, previous);
1274 xbt_dynar_free(&previous);
1280 if (heapinfo1->busy_block.size !=
1281 heapinfo2->busy_block.size) {
1283 xbt_dynar_free(&previous);
1288 if (heapinfo1->busy_block.busy_size !=
1289 heapinfo2->busy_block.busy_size) {
1291 xbt_dynar_free(&previous);
1296 if (!add_heap_area_pair(previous, block1, -1, block2, -1)) {
1298 match_equals(state, previous);
1299 xbt_dynar_free(&previous);
1304 size = heapinfo1->busy_block.busy_size;
1306 // Remember (basic) type inference.
1307 // The current data structure only allows us to do this for the whole block.
1308 if (type != NULL && area1 == real_addr_block1) {
1309 state->types1_(block1, 0) = type;
1311 if (type != NULL && area2 == real_addr_block2) {
1312 state->types2_(block2, 0) = type;
1317 match_equals(state, previous);
1318 xbt_dynar_free(&previous);
1326 if ((heapinfo1->busy_block.ignore > 0)
1327 && (heapinfo2->busy_block.ignore ==
1328 heapinfo1->busy_block.ignore))
1329 check_ignore = heapinfo1->busy_block.ignore;
1331 } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */
1335 ((uintptr_t) (ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type;
1337 ((uintptr_t) (ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type;
1339 // Process address of the fragment:
1341 (void *) ((char *) real_addr_block1 +
1342 (frag1 << heapinfo1->type));
1344 (void *) ((char *) real_addr_block2 +
1345 (frag2 << heapinfo2->type));
1347 // Check the size of the fragments against the size of the type:
1348 if (type_size != -1) {
1349 if (heapinfo1->busy_frag.frag_size[frag1] == -1
1350 || heapinfo2->busy_frag.frag_size[frag2] == -1) {
1352 match_equals(state, previous);
1353 xbt_dynar_free(&previous);
1358 if (type_size != heapinfo1->busy_frag.frag_size[frag1]
1359 || type_size != heapinfo2->busy_frag.frag_size[frag2]) {
1361 match_equals(state, previous);
1362 xbt_dynar_free(&previous);
1368 // Check if the blocks are already matched together:
1369 if (state->equals_to1_(block1, frag1).valid
1370 && state->equals_to2_(block2, frag2).valid) {
1371 if (offset1==offset2 && equal_fragments(state, block1, frag1, block2, frag2)) {
1373 match_equals(state, previous);
1374 xbt_dynar_free(&previous);
1379 // Compare the size of both fragments:
1380 if (heapinfo1->busy_frag.frag_size[frag1] !=
1381 heapinfo2->busy_frag.frag_size[frag2]) {
1382 if (type_size == -1) {
1384 match_equals(state, previous);
1385 xbt_dynar_free(&previous);
1390 xbt_dynar_free(&previous);
1396 // Size of the fragment:
1397 size = heapinfo1->busy_frag.frag_size[frag1];
1399 // Remember (basic) type inference.
1400 // The current data structure only allows us to do this for the whole fragment.
1401 if (type != NULL && area1 == real_addr_frag1) {
1402 state->types1_(block1, frag1) = type;
1404 if (type != NULL && area2 == real_addr_frag2) {
1405 state->types2_(block2, frag2) = type;
1407 // The type of the variable is already known:
1412 // Type inference from the block type.
1413 else if (state->types1_(block1, frag1) != NULL
1414 || state->types2_(block2, frag2) != NULL) {
1416 offset1 = (char *) area1 - (char *) real_addr_frag1;
1417 offset2 = (char *) area2 - (char *) real_addr_frag2;
1419 if (state->types1_(block1, frag1) != NULL
1420 && state->types2_(block2, frag2) != NULL) {
1422 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1423 offset1, size, snapshot1, process_index);
1425 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1426 offset1, size, snapshot2, process_index);
1427 } else if (state->types1_(block1, frag1) != NULL) {
1429 get_offset_type(real_addr_frag1, state->types1_(block1, frag1),
1430 offset1, size, snapshot1, process_index);
1432 get_offset_type(real_addr_frag2, state->types1_(block1, frag1),
1433 offset2, size, snapshot2, process_index);
1434 } else if (state->types2_(block2, frag2) != NULL) {
1436 get_offset_type(real_addr_frag1, state->types2_(block2, frag2),
1437 offset1, size, snapshot1, process_index);
1439 get_offset_type(real_addr_frag2, state->types2_(block2, frag2),
1440 offset2, size, snapshot2, process_index);
1443 match_equals(state, previous);
1444 xbt_dynar_free(&previous);
1449 if (new_type1 != NULL && new_type2 != NULL && new_type1 != new_type2) {
1452 while (type->byte_size == 0 && type->subtype != NULL)
1453 type = type->subtype;
1454 new_size1 = type->byte_size;
1457 while (type->byte_size == 0 && type->subtype != NULL)
1458 type = type->subtype;
1459 new_size2 = type->byte_size;
1463 match_equals(state, previous);
1464 xbt_dynar_free(&previous);
1470 if (new_size1 > 0 && new_size1 == new_size2) {
1475 if (offset1 == 0 && offset2 == 0) {
1476 if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
1478 match_equals(state, previous);
1479 xbt_dynar_free(&previous);
1487 match_equals(state, previous);
1488 xbt_dynar_free(&previous);
1493 if ((heapinfo1->busy_frag.ignore[frag1] > 0)
1494 && (heapinfo2->busy_frag.ignore[frag2] ==
1495 heapinfo1->busy_frag.ignore[frag1]))
1496 check_ignore = heapinfo1->busy_frag.ignore[frag1];
1501 xbt_dynar_free(&previous);
1508 /* Start comparison */
1511 compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
1512 previous, type, size, check_ignore,
1516 compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
1517 previous, size, check_ignore);
1519 if (res_compare == 1) {
1521 xbt_dynar_free(&previous);
1526 match_equals(state, previous);
1527 xbt_dynar_free(&previous);
1533 /*********************************************** Miscellaneous ***************************************************/
1534 /****************************************************************************************************************/
1536 // Not used and broken code:
1540 static int get_pointed_area_size(void *area, int heap)
1543 struct s_mc_diff *state = mc_diff_info;
1546 malloc_info *heapinfo;
1549 heapinfo = state->heapinfo1;
1551 heapinfo = state->heapinfo2;
1555 (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
1557 if (((char *) area < (char *) state->std_heap_copy.heapbase)
1558 || (block > state->heapsize1) || (block < 1))
1561 if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
1563 } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
1564 return (int) heapinfo[block].busy_block.busy_size;
1567 ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1568 return (int) heapinfo[block].busy_frag.frag_size[frag];
1573 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
1577 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
1580 struct s_mc_diff *state = mc_diff_info;
1582 if (heap1 == NULL && heap1 == NULL) {
1583 XBT_DEBUG("Malloc descriptors null");
1587 if (heap1->heaplimit != heap2->heaplimit) {
1588 XBT_DEBUG("Different limit of valid info table indices");
1592 /* Heap information */
1593 state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
1595 state->std_heap_copy = *mc_model_checker->process().get_heap();
1597 state->heapbase1 = (char *) heap1 + BLOCKSIZE;
1598 state->heapbase2 = (char *) heap2 + BLOCKSIZE;
1601 (malloc_info *) ((char *) heap1 +
1603 ((char *) heap1->heapinfo - (char *) state->s_heap)));
1605 (malloc_info *) ((char *) heap2 +
1607 ((char *) heap2->heapinfo - (char *) state->s_heap)));
1609 state->heapsize1 = heap1->heapsize;
1610 state->heapsize2 = heap2->heapsize;
1612 /* Start comparison */
1614 void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
1618 /* Check busy blocks */
1622 while (i <= state->heaplimit) {
1625 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1626 (char *) state->heapbase1));
1628 ((void *) (((ADDR2UINT(i)) - 1) * BLOCKSIZE +
1629 (char *) state->heapbase2));
1631 if (state->heapinfo1[i].type != state->heapinfo2[i].type) {
1633 distance += BLOCKSIZE;
1634 XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i,
1635 state->heapinfo1[i].type, state->heapinfo2[i].type, distance);
1640 if (state->heapinfo1[i].type == MMALLOC_TYPE_FREE
1641 || state->heapinfo1[i].type == MMALLOC_TYPE_HAPINFO) { /* Free block */
1646 if (state->heapinfo1[i].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Large block */
1648 if (state->heapinfo1[i].busy_block.size !=
1649 state->heapinfo2[i].busy_block.size) {
1651 BLOCKSIZE * max(state->heapinfo1[i].busy_block.size,
1652 state->heapinfo2[i].busy_block.size);
1653 i += max(state->heapinfo1[i].busy_block.size,
1654 state->heapinfo2[i].busy_block.size);
1656 ("Different larger of cluster at block %zu : %zu - %zu -> distance = %d",
1657 i, state->heapinfo1[i].busy_block.size,
1658 state->heapinfo2[i].busy_block.size, distance);
1662 /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
1663 distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
1664 i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
1665 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);
1671 //while(k < (heapinfo1[i].busy_block.busy_size)){
1672 while (k < state->heapinfo1[i].busy_block.size * BLOCKSIZE) {
1673 if (memcmp((char *) addr_block1 + k, (char *) addr_block2 + k, 1) !=
1682 } else { /* Fragmented block */
1684 for (j = 0; j < (size_t) (BLOCKSIZE >> state->heapinfo1[i].type); j++) {
1687 (void *) ((char *) addr_block1 + (j << state->heapinfo1[i].type));
1689 (void *) ((char *) addr_block2 + (j << state->heapinfo2[i].type));
1691 if (state->heapinfo1[i].busy_frag.frag_size[j] == 0
1692 && state->heapinfo2[i].busy_frag.frag_size[j] == 0) {
1697 /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
1698 distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
1699 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);
1705 //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
1706 while (k < (BLOCKSIZE / (BLOCKSIZE >> state->heapinfo1[i].type))) {
1707 if (memcmp((char *) addr_frag1 + k, (char *) addr_frag2 + k, 1) !=