From 4667db33a753d88cbcd186f191fb1e65f49f4bd6 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 15 Mar 2016 13:02:11 +0100 Subject: [PATCH] [mc] Move MC malloc introspection code in simgrid::mc --- include/xbt/mmalloc.h | 7 ------ src/mc/malloc.hpp | 38 ++++++++++++++++++++++++++++++++ src/mc/mc_compare.cpp | 12 +++++----- src/mc/mc_diff.cpp | 15 +++++-------- src/mc/mc_snapshot.h | 4 ---- tools/cmake/DefinePackages.cmake | 1 + 6 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 src/mc/malloc.hpp diff --git a/include/xbt/mmalloc.h b/include/xbt/mmalloc.h index 116a6c32b3..af930324cd 100644 --- a/include/xbt/mmalloc.h +++ b/include/xbt/mmalloc.h @@ -60,13 +60,6 @@ XBT_PUBLIC( xbt_mheap_t ) mmalloc_get_default_md(void); xbt_mheap_t mmalloc_set_current_heap(xbt_mheap_t new_heap); xbt_mheap_t mmalloc_get_current_heap(void); -int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2); -int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2); -int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t to_ignore1, xbt_dynar_t to_ignore2); -int compare_heap_area(int process_index, const void *area1, const void* area2, mc_snapshot_t snapshot1, - mc_snapshot_t snapshot2, xbt_dynar_t previous, mc_type_t type, int pointer_level); -void reset_heap_information(void); - size_t mmalloc_get_bytes_used(xbt_mheap_t); ssize_t mmalloc_get_busy_size(xbt_mheap_t, void *ptr); diff --git a/src/mc/malloc.hpp b/src/mc/malloc.hpp new file mode 100644 index 0000000000..82acd86f0b --- /dev/null +++ b/src/mc/malloc.hpp @@ -0,0 +1,38 @@ +/* Copyright (c) 2010-2016. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. + This file was then part of the GNU C Library. */ + +#ifndef SIMGRID_MC_MALLOC_HPP +#define SIMGRID_MC_MALLOC_HPP + +#include + +#include +#include + +#include "src/mc/mc_forward.hpp" +#include "src/mc/Process.hpp" + +namespace simgrid { +namespace mc { + +XBT_PRIVATE int mmalloc_compare_heap(Snapshot* snapshot1, Snapshot* snapshot2); +XBT_PRIVATE int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2); +XBT_PRIVATE int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, + std::vector* i1, + std::vector* i2); +XBT_PRIVATE int compare_heap_area( + int process_index, const void *area1, const void* area2, + Snapshot* snapshot1, Snapshot* snapshot2, + xbt_dynar_t previous, Type* type, int pointer_level); +XBT_PRIVATE void reset_heap_information(void); + +} +} + +#endif diff --git a/src/mc/mc_compare.cpp b/src/mc/mc_compare.cpp index 8aaaefb988..33371e4453 100644 --- a/src/mc/mc_compare.cpp +++ b/src/mc/mc_compare.cpp @@ -18,7 +18,7 @@ #include "src/mc/mc_private.h" #include "src/mc/mc_smx.h" #include "src/mc/mc_dwarf.hpp" - +#include "src/mc/malloc.hpp" #include "src/mc/Frame.hpp" #include "src/mc/ObjectInformation.hpp" #include "src/mc/Variable.hpp" @@ -170,7 +170,7 @@ static int compare_areas_with_type(ComparisonState& state, && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))) return 1; // The pointers are both in the heap: - return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1, + return simgrid::mc::compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1, snapshot2, nullptr, type->subtype, pointer_level); } @@ -427,7 +427,7 @@ int snapshot_compare(void *state1, void *state2) alloca(sizeof(struct mdesc)), sizeof(struct mdesc), remote(process->heap_address), simgrid::mc::ProcessIndexMissing, simgrid::mc::ReadOptions::lazy()); - res_init = init_heap_information(heap1, heap2, &s1->to_ignore, &s2->to_ignore); + res_init = simgrid::mc::init_heap_information(heap1, heap2, &s1->to_ignore, &s2->to_ignore); if (res_init == -1) { #ifdef MC_DEBUG XBT_DEBUG("(%d - %d) Different heap information", num1, num2); @@ -472,7 +472,7 @@ int snapshot_compare(void *state1, void *state2) num2, cursor + 1); #endif - reset_heap_information(); + simgrid::mc::reset_heap_information(); return 1; #endif @@ -522,7 +522,7 @@ int snapshot_compare(void *state1, void *state2) } /* Compare heap */ - if (mmalloc_compare_heap(s1, s2) > 0) { + if (simgrid::mc::mmalloc_compare_heap(s1, s2) > 0) { #ifdef MC_DEBUG XBT_DEBUG("(%d - %d) Different heap (mmalloc_compare)", num1, num2); @@ -537,7 +537,7 @@ int snapshot_compare(void *state1, void *state2) #endif } - reset_heap_information(); + simgrid::mc::reset_heap_information(); #ifdef MC_VERBOSE if (errors || hash_result) diff --git a/src/mc/mc_diff.cpp b/src/mc/mc_diff.cpp index e877474420..6e2bb9fadf 100644 --- a/src/mc/mc_diff.cpp +++ b/src/mc/mc_diff.cpp @@ -11,6 +11,7 @@ #include "mc/mc.h" #include "xbt/mmalloc.h" #include "mc/datatypes.h" +#include "src/mc/malloc.hpp" #include "src/mc/mc_private.h" #include "src/mc/mc_snapshot.h" #include "src/mc/mc_dwarf.hpp" @@ -21,13 +22,9 @@ using simgrid::mc::remote; XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt, "Logging specific to mc_diff in mc"); -extern "C" { - /*********************************** Heap comparison ***********************************/ /***************************************************************************************/ -typedef char *type_name; - struct XBT_PRIVATE s_mc_diff { s_xbt_mheap_t std_heap_copy; std::size_t heaplimit; @@ -218,7 +215,8 @@ static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2, return 0; } -} +namespace simgrid { +namespace mc { int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, std::vector* i1, @@ -275,16 +273,14 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, memset(state->equals_to2, 0, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); memset(state->types1, 0, - state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); + state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(char**)); memset(state->types2, 0, - state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); + state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(char**)); return 0; } -extern "C" { - void reset_heap_information() { @@ -1589,3 +1585,4 @@ int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2) #endif } +} diff --git a/src/mc/mc_snapshot.h b/src/mc/mc_snapshot.h index c84a17bd6e..e73b22813f 100644 --- a/src/mc/mc_snapshot.h +++ b/src/mc/mc_snapshot.h @@ -275,8 +275,4 @@ void* MC_region_read_pointer(mc_mem_region_t region, const void* addr) SG_END_DECL() -XBT_PRIVATE int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, - std::vector* i1, - std::vector* i2); - #endif diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index e7f948cbad..79e7ee3d59 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -597,6 +597,7 @@ set(MC_SRC src/mc/mc_mmalloc.h src/mc/mc_liveness.h src/mc/LocationList.hpp + src/mc/malloc.hpp src/mc/LocationList.cpp src/mc/mc_liveness.cpp src/mc/mc_record.cpp -- 2.20.1