Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More automatic memory mgmt in MC
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 27 Apr 2023 12:09:03 +0000 (14:09 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 27 Apr 2023 13:49:14 +0000 (15:49 +0200)
src/mc/api/State.cpp
src/mc/api/State.hpp
src/mc/explo/DFSExplorer.cpp
src/mc/explo/LivenessChecker.cpp
src/mc/explo/UdporChecker.cpp

index 2abb88f..a5fdc64 100644 (file)
@@ -51,7 +51,7 @@ State::State(RemoteApp& remote_app, std::shared_ptr<State> parent_state)
   *strategy_ = *(parent_state->strategy_);
 
   recipe_ = std::list(parent_state_->get_recipe());
-  recipe_.push_back(incoming_transition_);
+  recipe_.push_back(incoming_transition_.get());
 
   remote_app.get_actors_status(strategy_->actors_to_run_);
 
@@ -158,12 +158,11 @@ std::shared_ptr<Transition> State::execute_next(aid_t next, RemoteApp& app)
   //  2. what action actor `next` was able to take given `times_considered`
   // The latter update is important as *more* information is potentially available
   // about a transition AFTER it has executed.
-  transition_ = just_executed;
+  outgoing_transition_ = std::shared_ptr<Transition>(just_executed);
 
-  const auto executed_transition = std::shared_ptr<Transition>(just_executed);
-  actor_state.set_transition(executed_transition, times_considered);
+  actor_state.set_transition(outgoing_transition_, times_considered);
   app.wait_for_requests();
 
-  return executed_transition;
+  return outgoing_transition_;
 }
 } // namespace simgrid::mc
index 1dc026b..3551843 100644 (file)
@@ -21,19 +21,11 @@ namespace simgrid::mc {
 class XBT_PRIVATE State : public xbt::Extendable<State> {
   static long expended_states_; /* Count total amount of states, for stats */
 
-  /**
-   * @brief The outgoing transition: what was the last transition that we took to leave this state?
-   *
-   * The owner of the transition is the `ActorState` instance which exists in this state.
-   */
-  Transition* transition_ = nullptr;
+  /** @brief The outgoing transition is the last transition that we took to leave this state.  */
+  std::shared_ptr<Transition> outgoing_transition_ = nullptr;
 
-  /**
-   * @brief The incoming transition is what led to this state, coming from its parent
-   *
-   * The owner of the transition is the `ActorState` instance of the parent.
-   */
-  Transition* incoming_transition_ = nullptr;
+  /** @brief The incoming transition is what led to this state, coming from its parent  */
+  std::shared_ptr<Transition> incoming_transition_ = nullptr;
 
   /** @brief A list of transition to be replayed in order to get in this state. */
   std::list<Transition*> recipe_;
@@ -84,8 +76,7 @@ public:
   unsigned long consider_all() const { return strategy_->consider_all(); }
 
   bool is_actor_done(aid_t actor) const { return strategy_->actors_to_run_.at(actor).is_done(); }
-  Transition* get_transition_out() const { return transition_; }
-  void set_transition_out(Transition* t) { transition_ = t; }
+  std::shared_ptr<Transition> get_transition_out() const { return outgoing_transition_; }
   std::shared_ptr<State> get_parent_state() const { return parent_state_; }
   std::list<Transition*> get_recipe() const { return recipe_; }
 
@@ -98,7 +89,7 @@ public:
   void set_system_state(std::shared_ptr<Snapshot> state) { system_state_ = std::move(state); }
 
   std::map<aid_t, Transition> const& get_sleep_set() const { return sleep_set_; }
-  void add_sleep_set(const Transition* t)
+  void add_sleep_set(std::shared_ptr<Transition> t)
   {
     sleep_set_.insert_or_assign(t->aid_, Transition(t->type_, t->aid_, t->times_considered_));
   }
index 4e9c03b..0130455 100644 (file)
@@ -71,7 +71,7 @@ RecordTrace DFSExplorer::get_record_trace() // override
   RecordTrace res;
   for (auto const& transition : stack_.back()->get_recipe())
     res.push_back(transition);
-  res.push_back(stack_.back()->get_transition_out());
+  res.push_back(stack_.back()->get_transition_out().get());
   return res;
 }
 
@@ -81,7 +81,7 @@ std::vector<std::string> DFSExplorer::get_textual_trace() // override
   for (auto const& transition : stack_.back()->get_recipe()) {
     trace.push_back(xbt::string_printf("%ld: %s", transition->aid_, transition->to_string().c_str()));
   }
-  if (const auto* trans = stack_.back()->get_transition_out(); trans != nullptr)
+  if (const auto trans = stack_.back()->get_transition_out(); trans != nullptr)
     trace.push_back(xbt::string_printf("%ld: %s", trans->aid_, trans->to_string().c_str()));
   return trace;
 }
@@ -176,7 +176,7 @@ void DFSExplorer::run()
 
     /* Actually answer the request: let's execute the selected request (MCed does one step) */
     state->execute_next(next, get_remote_app());
-    on_transition_execute_signal(state->get_transition_out(), get_remote_app());
+    on_transition_execute_signal(state->get_transition_out().get(), get_remote_app());
 
     // If there are processes to interleave and the maximum depth has not been
     // reached then perform one step of the exploration algorithm.
@@ -209,7 +209,7 @@ void DFSExplorer::run()
                     prev_state->get_transition_out()->to_string().c_str(), issuer_id);
           tmp_stack.pop_back();
           continue;
-        } else if (prev_state->get_transition_out()->depends(state->get_transition_out())) {
+        } else if (prev_state->get_transition_out()->depends(state->get_transition_out().get())) {
           XBT_VERB("Dependent Transitions:");
           XBT_VERB("  %s (state=%ld)", prev_state->get_transition_out()->to_string().c_str(), prev_state->get_num());
           XBT_VERB("  %s (state=%ld)", state->get_transition_out()->to_string().c_str(), state->get_num());
index 46f11b1..e254683 100644 (file)
@@ -258,7 +258,7 @@ RecordTrace LivenessChecker::get_record_trace() // override
 {
   RecordTrace res;
   for (std::shared_ptr<Pair> const& pair : exploration_stack_)
-    res.push_back(pair->app_state_->get_transition_out());
+    res.push_back(pair->app_state_->get_transition_out().get());
   return res;
 }
 
index 743d999..6d913b2 100644 (file)
@@ -321,7 +321,7 @@ RecordTrace UdporChecker::get_record_trace()
 {
   RecordTrace res;
   for (auto const& state : state_stack)
-    res.push_back(state->get_transition_out());
+    res.push_back(state->get_transition_out().get());
   return res;
 }
 
@@ -329,7 +329,7 @@ std::vector<std::string> UdporChecker::get_textual_trace()
 {
   std::vector<std::string> trace;
   for (auto const& state : state_stack) {
-    const auto* t = state->get_transition_out();
+    const auto t = state->get_transition_out();
     trace.push_back(xbt::string_printf("%ld: %s", t->aid_, t->to_string().c_str()));
   }
   return trace;