From 75c4f9295f59dab2c9085c966c769196997b6c93 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 27 Apr 2023 14:09:03 +0200 Subject: [PATCH] More automatic memory mgmt in MC --- src/mc/api/State.cpp | 9 ++++----- src/mc/api/State.hpp | 21 ++++++--------------- src/mc/explo/DFSExplorer.cpp | 8 ++++---- src/mc/explo/LivenessChecker.cpp | 2 +- src/mc/explo/UdporChecker.cpp | 4 ++-- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/mc/api/State.cpp b/src/mc/api/State.cpp index 2abb88f6c5..a5fdc64df2 100644 --- a/src/mc/api/State.cpp +++ b/src/mc/api/State.cpp @@ -51,7 +51,7 @@ State::State(RemoteApp& remote_app, std::shared_ptr 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 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(just_executed); - const auto executed_transition = std::shared_ptr(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 diff --git a/src/mc/api/State.hpp b/src/mc/api/State.hpp index 1dc026b71e..3551843bc4 100644 --- a/src/mc/api/State.hpp +++ b/src/mc/api/State.hpp @@ -21,19 +21,11 @@ namespace simgrid::mc { class XBT_PRIVATE State : public xbt::Extendable { 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 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 incoming_transition_ = nullptr; /** @brief A list of transition to be replayed in order to get in this state. */ std::list 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 get_transition_out() const { return outgoing_transition_; } std::shared_ptr get_parent_state() const { return parent_state_; } std::list get_recipe() const { return recipe_; } @@ -98,7 +89,7 @@ public: void set_system_state(std::shared_ptr state) { system_state_ = std::move(state); } std::map const& get_sleep_set() const { return sleep_set_; } - void add_sleep_set(const Transition* t) + void add_sleep_set(std::shared_ptr t) { sleep_set_.insert_or_assign(t->aid_, Transition(t->type_, t->aid_, t->times_considered_)); } diff --git a/src/mc/explo/DFSExplorer.cpp b/src/mc/explo/DFSExplorer.cpp index 4e9c03b8c3..0130455d79 100644 --- a/src/mc/explo/DFSExplorer.cpp +++ b/src/mc/explo/DFSExplorer.cpp @@ -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 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()); diff --git a/src/mc/explo/LivenessChecker.cpp b/src/mc/explo/LivenessChecker.cpp index 46f11b14e1..e254683fa6 100644 --- a/src/mc/explo/LivenessChecker.cpp +++ b/src/mc/explo/LivenessChecker.cpp @@ -258,7 +258,7 @@ RecordTrace LivenessChecker::get_record_trace() // override { RecordTrace res; for (std::shared_ptr 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; } diff --git a/src/mc/explo/UdporChecker.cpp b/src/mc/explo/UdporChecker.cpp index 743d999c56..6d913b2b96 100644 --- a/src/mc/explo/UdporChecker.cpp +++ b/src/mc/explo/UdporChecker.cpp @@ -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 UdporChecker::get_textual_trace() { std::vector 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; -- 2.20.1