Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Make s_mc_global_t::stacks a std::vector
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 8 Jun 2015 15:36:58 +0000 (17:36 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Jun 2015 08:20:45 +0000 (10:20 +0200)
buildtools/Cmake/DefinePackages.cmake
src/mc/mc_checkpoint.cpp
src/mc/mc_compare.cpp
src/mc/mc_hash.cpp
src/mc/mc_hash.hpp [new file with mode: 0644]
src/mc/mc_private.h
src/mc/mc_snapshot.cpp
src/mc/mc_snapshot.h

index 7fcb767..bdc0ef8 100644 (file)
@@ -631,6 +631,7 @@ set(MC_SRC
   src/mc/mc_dwarf_attrnames.h
   src/mc/mc_dwarf_expression.cpp
   src/mc/mc_dwarf_tagnames.h
+  src/mc/mc_hash.hpp
   src/mc/mc_hash.cpp
   src/mc/mc_ignore.cpp
   src/mc/mcer_ignore.cpp
index 559504a..ebc9475 100644 (file)
@@ -34,6 +34,7 @@
 #include "mc_unw.h"
 #include "mc_protocol.h"
 #include "mc_smx.h"
+#include "mc_hash.hpp"
 
 using simgrid::mc::remote;
 
@@ -48,7 +49,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
 s_mc_snapshot_stack::~s_mc_snapshot_stack()
 {
   xbt_dynar_free(&(this->stack_frames));
-  mc_unw_destroy_context(this->context);
+  if (this->context)
+    mc_unw_destroy_context(this->context);
   xbt_free(this->context);
 }
 
@@ -423,44 +425,41 @@ static xbt_dynar_t MC_unwind_stack_frames(mc_unw_context_t stack_context)
   return result;
 };
 
-static xbt_dynar_t MC_take_snapshot_stacks(mc_snapshot_t * snapshot)
+static std::vector<s_mc_snapshot_stack_t> MC_take_snapshot_stacks(mc_snapshot_t * snapshot)
 {
-
-  xbt_dynar_t res =
-      xbt_dynar_new(sizeof(s_mc_snapshot_stack_t),
-                    MC_snapshot_stack_free_voidp);
+  std::vector<s_mc_snapshot_stack_t> res;
 
   unsigned int cursor = 0;
   stack_region_t current_stack;
 
   // FIXME, cross-process support (stack_areas)
   xbt_dynar_foreach(stacks_areas, cursor, current_stack) {
-    mc_snapshot_stack_t st = new s_mc_snapshot_stack();
+    s_mc_snapshot_stack_t st;
 
     // Read the context from remote process:
     unw_context_t context;
     mc_model_checker->process().read_bytes(
       &context, sizeof(context), remote(current_stack->context));
 
-    st->context = xbt_new0(s_mc_unw_context_t, 1);
-    if (mc_unw_init_context(st->context, &mc_model_checker->process(),
+    st.context = xbt_new0(s_mc_unw_context_t, 1);
+    if (mc_unw_init_context(st.context, &mc_model_checker->process(),
       &context) < 0) {
       xbt_die("Could not initialise the libunwind context.");
     }
+    st.stack_frames = MC_unwind_stack_frames(st.context);
+    st.local_variables = MC_get_local_variables_values(st.stack_frames, current_stack->process_index);
+    st.process_index = current_stack->process_index;
 
-    st->stack_frames = MC_unwind_stack_frames(st->context);
-    st->local_variables = MC_get_local_variables_values(st->stack_frames, current_stack->process_index);
-    st->process_index = current_stack->process_index;
+    unw_word_t sp = xbt_dynar_get_as(st.stack_frames, 0, mc_stack_frame_t)->sp;
 
-    unw_word_t sp = xbt_dynar_get_as(st->stack_frames, 0, mc_stack_frame_t)->sp;
+    res.push_back(std::move(st));
 
-    xbt_dynar_push(res, &st);
     size_t stack_size =
       (char*) current_stack->address + current_stack->size - (char*) sp;
     (*snapshot)->stack_sizes.push_back(stack_size);
   }
 
-  return res;
+  return std::move(res);
 
 }
 
@@ -622,7 +621,7 @@ mc_snapshot_t MC_take_snapshot(int num_state)
   if (_sg_mc_visited > 0 || strcmp(_sg_mc_property_file, "")) {
     snapshot->stacks =
         MC_take_snapshot_stacks(&snapshot);
-    if (_sg_mc_hash && snapshot->stacks != NULL) {
+    if (_sg_mc_hash && !snapshot->stacks.empty()) {
       snapshot->hash = mc_hash_processes_state(num_state, snapshot->stacks);
     } else {
       snapshot->hash = 0;
index f65fe41..39aaf87 100644 (file)
@@ -446,7 +446,7 @@ int snapshot_compare(void *state1, void *state2)
   int is_diff = 0;
 
   /* Compare size of stacks */
-  while (i < xbt_dynar_length(s1->stacks)) {
+  while (i < s1->stacks.size()) {
     size_used1 = s1->stack_sizes[i];
     size_used2 = s2->stack_sizes[i];
     if (size_used1 != size_used2) {
@@ -523,13 +523,9 @@ int snapshot_compare(void *state1, void *state2)
   is_diff = 0;
 #endif
   mc_snapshot_stack_t stack1, stack2;
-  while (cursor < xbt_dynar_length(s1->stacks)) {
-    stack1 =
-        (mc_snapshot_stack_t) xbt_dynar_get_as(s1->stacks, cursor,
-                                               mc_snapshot_stack_t);
-    stack2 =
-        (mc_snapshot_stack_t) xbt_dynar_get_as(s2->stacks, cursor,
-                                               mc_snapshot_stack_t);
+  while (cursor < s1->stacks.size()) {
+    stack1 = &s1->stacks[cursor];
+    stack2 = &s1->stacks[cursor];
 
     if (stack1->process_index != stack2->process_index) {
       diff_local = 1;
index 4164c53..c830253 100644 (file)
@@ -12,8 +12,7 @@
 #include "mc_private.h"
 #include "mc/datatypes.h"
 #include <mc/mc.h>
-
-extern "C" {
+#include "mc_hash.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_hash, mc, "Logging specific to mc_hash");
 
@@ -322,7 +321,7 @@ static void mc_hash_stacks(mc_hash_t * hash, mc_hashing_state * state,
 }
 #endif
 
-uint64_t mc_hash_processes_state(int num_state, xbt_dynar_t stacks)
+uint64_t mc_hash_processes_state(int num_state, std::vector<s_mc_snapshot_stack_t> const& stacks)
 {
   XBT_DEBUG("START hash %i", num_state);
 
@@ -344,5 +343,3 @@ uint64_t mc_hash_processes_state(int num_state, xbt_dynar_t stacks)
   XBT_DEBUG("END hash %i", num_state);
   return hash;
 }
-
-}
diff --git a/src/mc/mc_hash.hpp b/src/mc/mc_hash.hpp
new file mode 100644 (file)
index 0000000..5362e18
--- /dev/null
@@ -0,0 +1,34 @@
+/* Copyright (c) 2007-2015. 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. */
+
+#include <stdio.h>
+#include <stdint.h>
+
+#include <vector>
+
+#include "xbt/misc.h"
+#include "mc_snapshot.h"
+
+#ifndef SIMGRID_MC_HASH_HPP
+#define SIMGRID_MC_HASH_HPP
+
+/** \brief Hash the current state
+ *  \param num_state number of states
+ *  \param stacks stacks (mc_snapshot_stak_t) used fot the stack unwinding informations
+ *  \result resulting hash
+ * */
+XBT_INTERNAL uint64_t mc_hash_processes_state(
+  int num_state, std::vector<s_mc_snapshot_stack_t> const& stacks);
+
+/** @brief Dump the stacks of the application processes
+ *
+ *   This functions is currently not used but it is quite convenient
+ *   to call from the debugger.
+ *
+ *   Does not work when an application thread is running.
+ */
+
+#endif
index 631681d..97f7827 100644 (file)
@@ -111,22 +111,6 @@ XBT_INTERNAL void print_comparison_times(void);
 
 /********************************** Miscellaneous **********************************/
 
-/* *********** Hash *********** */
-
-/** \brief Hash the current state
- *  \param num_state number of states
- *  \param stacks stacks (mc_snapshot_stak_t) used fot the stack unwinding informations
- *  \result resulting hash
- * */
-XBT_INTERNAL uint64_t mc_hash_processes_state(int num_state, xbt_dynar_t stacks);
-
-/** @brief Dump the stacks of the application processes
- *
- *   This functions is currently not used but it is quite convenient
- *   to call from the debugger.
- *
- *   Does not work when an application thread is running.
- */
 XBT_INTERNAL void MC_dump_stacks(FILE* file);
 
 XBT_INTERNAL void MC_report_assertion_error(void);
index 0fdb7a1..bfc3d89 100644 (file)
@@ -159,8 +159,6 @@ Snapshot::Snapshot() :
   heap_bytes_used(0),
   enabled_processes(),
   privatization_index(0),
-  stack_sizes(),
-  stacks(nullptr),
   hash(0)
 {
 
@@ -168,7 +166,7 @@ Snapshot::Snapshot() :
 
 Snapshot::~Snapshot()
 {
-  xbt_dynar_free(&(this->stacks));
+
 }
 
 const void* Snapshot::read_bytes(void* buffer, std::size_t size,
index 4467b9f..85683f7 100644 (file)
@@ -124,7 +124,29 @@ typedef struct s_mc_snapshot_stack{
   xbt_dynar_t stack_frames; // mc_stack_frame_t
   int process_index;
 
+  s_mc_snapshot_stack()
+    : context(nullptr), stack_frames(nullptr), process_index(0)
+  {}
   ~s_mc_snapshot_stack();
+  s_mc_snapshot_stack(s_mc_snapshot_stack& p) = delete;
+  s_mc_snapshot_stack& operator=(s_mc_snapshot_stack&) = delete;
+
+  s_mc_snapshot_stack(s_mc_snapshot_stack&& that)
+  {
+    *this = std::move(that);
+  }
+  s_mc_snapshot_stack& operator=(s_mc_snapshot_stack&& that)
+  {
+    this->local_variables = std::move(that.local_variables);
+    this->context = std::move(that.context);
+    that.context = nullptr;
+    this->stack_frames = std::move(that.stack_frames);
+    that.stack_frames = nullptr;
+    this->process_index = that.process_index;
+    that.process_index = 0;
+    return *this;
+  }
+
 }s_mc_snapshot_stack_t, *mc_snapshot_stack_t;
 
 typedef struct s_mc_global_t {
@@ -156,7 +178,7 @@ public: // To be private
   std::set<pid_t> enabled_processes;
   int privatization_index;
   std::vector<size_t> stack_sizes;
-  xbt_dynar_t stacks;
+  std::vector<s_mc_snapshot_stack_t> stacks;
   std::vector<s_mc_heap_ignore_region_t> to_ignore;
   uint64_t hash;
   std::vector<s_mc_snapshot_ignored_data> ignored_data;