+
+ }
+
+ }else{
+
+ if((heapinfo1[block_pointed1].type > 0) && (heapinfo2[block_pointed2].type > 0)){
+
+ addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
+ addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
+
+ frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
+ frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
+
+ if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */
+ return 1;
+
+ addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 << heapinfo1[block_pointed1].type));
+ addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 << heapinfo2[block_pointed2].type));
+
+ if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
+
+ if(ignore_done < xbt_dynar_length(mc_comparison_ignore)){
+ if(in_mc_comparison_ignore(block_pointed1, frag_pointed1))
+ res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
+ else
+ res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
+ }else{
+ res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
+ }
+
+ if(res_compare == 1)
+ return 1;
+
+ }
+
+ }else{
+ return 1;
+ }
+
+ }
+
+ i = pointer_align + sizeof(void *);
+
+ }else{
+
+ i++;
+
+ }
+ }
+
+ return 0;
+
+
+}
+
+static void heap_area_pair_free(heap_area_pair_t pair){
+ if (pair){
+ free(pair);
+ pair = NULL;
+ }
+}
+
+static void heap_area_pair_free_voidp(void *d)
+{
+ heap_area_pair_free((heap_area_pair_t) * (void **) d);
+}
+
+static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
+
+ if(is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)){
+ heap_area_pair_t pair = NULL;
+ pair = xbt_new0(s_heap_area_pair_t, 1);
+ pair->block1 = block1;
+ pair->fragment1 = fragment1;
+ pair->block2 = block2;
+ pair->fragment2 = fragment2;
+
+ xbt_dynar_push(list, &pair);
+
+ return 1;
+ }
+
+ return 0;
+}
+
+static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
+
+ unsigned int cursor = 0;
+ heap_area_pair_t current_pair;
+
+ xbt_dynar_foreach(list, cursor, current_pair){
+ if(current_pair->block1 == block1 && current_pair->block2 == block2 && current_pair->fragment1 == fragment1 && current_pair->fragment2 == fragment2)
+ return 0;
+ }
+
+ return 1;
+}
+
+static void match_equals(xbt_dynar_t list, xbt_dynar_t *equals){
+
+ unsigned int cursor = 0;
+ heap_area_pair_t current_pair;
+ heap_area_t previous_area;
+
+ void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
+
+ xbt_dynar_foreach(list, cursor, current_pair){
+
+ if(current_pair->fragment1 != -1){
+
+ real_addr_block1 = ((void*) (((ADDR2UINT((size_t)current_pair->block1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
+ real_addr_frag1 = (void*) ((char *)real_addr_block1 + (current_pair->fragment1 << heapinfo1[current_pair->block1].type));
+ real_addr_block2 = ((void*) (((ADDR2UINT((size_t)current_pair->block2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
+ real_addr_frag2 = (void*) ((char *)real_addr_block2 + (current_pair->fragment2 << heapinfo2[current_pair->block2].type));
+
+ if(heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1] != NULL){
+ remove_heap_equality(equals, 1, real_addr_frag1);
+ previous_area = heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1];
+ xbt_free( heapinfo2[previous_area->block].busy_frag.equal_to[previous_area->fragment]);
+ heapinfo2[previous_area->block].busy_frag.equal_to[previous_area->fragment] = NULL;
+ xbt_free(heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1]);
+ }
+ if(heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2] != NULL){
+ remove_heap_equality(equals, 2, real_addr_frag2);
+ previous_area = heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2];
+ xbt_free(heapinfo1[previous_area->block].busy_frag.equal_to[previous_area->fragment]);
+ heapinfo1[previous_area->block].busy_frag.equal_to[previous_area->fragment] = NULL;
+ xbt_free(heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2]);
+ }
+
+ if(real_addr_frag1 != real_addr_frag2)
+ add_heap_equality(equals, real_addr_frag1, real_addr_frag2);
+
+ heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1] = new_heap_area(current_pair->block2, current_pair->fragment2);
+ heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2] = new_heap_area(current_pair->block1, current_pair->fragment1);
+
+ }else{
+
+ real_addr_block1 = ((void*) (((ADDR2UINT((size_t)current_pair->block1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
+ real_addr_block2 = ((void*) (((ADDR2UINT((size_t)current_pair->block2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
+
+ if(heapinfo1[current_pair->block1].busy_block.equal_to != NULL){
+ remove_heap_equality(equals, 1, real_addr_block1);
+ previous_area = heapinfo1[current_pair->block1].busy_block.equal_to;
+ xbt_free(heapinfo2[previous_area->block].busy_block.equal_to);
+ heapinfo2[previous_area->block].busy_block.equal_to = NULL;
+ xbt_free(heapinfo1[current_pair->block1].busy_block.equal_to);
+ }
+ if(heapinfo2[current_pair->block2].busy_block.equal_to != NULL){
+ remove_heap_equality(equals, 2, real_addr_block2);
+ previous_area = heapinfo2[current_pair->block2].busy_block.equal_to;
+ xbt_free(heapinfo1[previous_area->block].busy_block.equal_to);
+ heapinfo1[previous_area->block].busy_block.equal_to = NULL;
+ xbt_free(heapinfo2[current_pair->block2].busy_block.equal_to);
+ }
+
+ if(real_addr_block1 != real_addr_block2)
+ add_heap_equality(equals, real_addr_block1, real_addr_block2);
+
+ heapinfo1[current_pair->block1].busy_block.equal_to = new_heap_area(current_pair->block2, current_pair->fragment2);
+ heapinfo2[current_pair->block2].busy_block.equal_to = new_heap_area(current_pair->block1, current_pair->fragment1);
+
+ }
+ }
+
+
+}
+
+#ifndef max
+#define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
+#endif
+
+int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
+
+ if(heap1 == NULL && heap1 == NULL){
+ XBT_DEBUG("Malloc descriptors null");
+ return 0;
+ }
+
+ if(heap1->heaplimit != heap2->heaplimit){
+ XBT_DEBUG("Different limit of valid info table indices");
+ return 1;
+ }
+
+ /* Heap information */
+ heaplimit = ((struct mdesc *)heap1)->heaplimit;
+
+ s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
+
+ heapbase1 = (char *)heap1 + BLOCKSIZE;
+ heapbase2 = (char *)heap2 + BLOCKSIZE;
+
+ heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)heap1->heapinfo - (char *)s_heap)));
+ heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)heap2->heapinfo - (char *)s_heap)));
+
+ heapsize1 = heap1->heapsize;
+ heapsize2 = heap2->heapsize;
+
+ /* Start comparison */
+ size_t i, j, k;
+ void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
+
+ int distance = 0;
+
+ /* Check busy blocks*/
+
+ i = 1;
+
+ while(i <= heaplimit){
+
+ addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
+ addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
+
+ if(heapinfo1[i].type != heapinfo2[i].type){
+
+ distance += BLOCKSIZE;
+ XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i, heapinfo1[i].type, heapinfo2[i].type, distance);
+ i++;
+
+ }else{
+
+ if(heapinfo1[i].type == -1){ /* Free block */
+ i++;
+ continue;
+ }
+
+ if(heapinfo1[i].type == 0){ /* Large block */
+
+ if(heapinfo1[i].busy_block.size != heapinfo2[i].busy_block.size){
+ distance += BLOCKSIZE * max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
+ i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
+ XBT_DEBUG("Different larger of cluster at block %zu : %zu - %zu -> distance = %d", i, heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size, distance);
+ continue;