From: weiyu Date: Fri, 28 Jun 2019 19:42:35 +0000 (-0700) Subject: move work_list (thrd_func_list) from history.h to execution.h, and fix the memory... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=a95ff96d0c30bc84c6e7757e346cd7b0b9ace03b move work_list (thrd_func_list) from history.h to execution.h, and fix the memory issue for HashTable usage --- diff --git a/classlist.h b/classlist.h index 90f111d8..67f6f8b7 100644 --- a/classlist.h +++ b/classlist.h @@ -1,5 +1,6 @@ #ifndef CLASSLIST_H #define CLASSLIST_H +#include #include "stl-model.h" class ClockVector; @@ -21,4 +22,5 @@ class FuncInst; struct model_snapshot_members; struct bug_message; typedef SnapList action_list_t; +typedef SnapList func_id_list_t; #endif diff --git a/execution.h b/execution.h index 20bbfdc6..9487fd6e 100644 --- a/execution.h +++ b/execution.h @@ -106,6 +106,8 @@ public: HashTable * getCondMap() {return &cond_map;} HashTable * getMutexMap() {return &mutex_map;} + SnapVector * get_thrd_func_list() { return &thrd_func_list; } + SNAPSHOTALLOC private: int get_execution_number() const; @@ -205,6 +207,12 @@ private: Fuzzer * fuzzer; Thread * action_select_next_thread(const ModelAction *curr) const; + + /* thrd_func_list stores a list of function ids for each thread. + * Each element in thrd_func_list stores the functions that + * thread i has entered and yet to exit from */ + SnapVector< func_id_list_t * > thrd_func_list; + }; #endif /* __EXECUTION_H__ */ diff --git a/funcnode.h b/funcnode.h index f150846d..6ddcbb26 100644 --- a/funcnode.h +++ b/funcnode.h @@ -30,7 +30,7 @@ public: void add_action(ModelAction *act); - HashTable * getFuncInsts() { return &func_insts; } + HashTable * getFuncInsts() { return &func_insts; } func_inst_list_t * get_inst_list() { return &inst_list; } MEMALLOC @@ -40,7 +40,7 @@ private: * To do: cds_atomic_compare_exchange contains three atomic operations * that are feeded with the same source line number by llvm pass */ - HashTable func_insts; + HashTable func_insts; func_inst_list_t inst_list; }; diff --git a/history.cc b/history.cc index ec90a5a4..2ae49a16 100644 --- a/history.cc +++ b/history.cc @@ -3,24 +3,28 @@ #include "action.h" #include "funcnode.h" +#include "model.h" +#include "execution.h" + /** @brief Constructor */ ModelHistory::ModelHistory() : func_counter(0), /* function id starts with 0 */ func_map(), - func_atomics(), - work_list(2) /* we have at least two threads */ + func_atomics() {} void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) { uint32_t id = id_to_int(tid); - if ( work_list.size() <= id ) - work_list.resize( id + 1 ); + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + + if ( thrd_func_list->size() <= id ) + thrd_func_list->resize( id + 1 ); - func_id_list_t * func_list = work_list[id]; + func_id_list_t * func_list = thrd_func_list->at(id); if (func_list == NULL) { func_list = new func_id_list_t(); - work_list[id] = func_list; + thrd_func_list->at(id) = func_list; } func_list->push_back(func_id); @@ -28,7 +32,9 @@ void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) { - func_id_list_t * func_list = work_list[ id_to_int(tid) ]; + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + + func_id_list_t * func_list = thrd_func_list->at( id_to_int(tid) ); uint32_t last_func_id = func_list->back(); if (last_func_id == func_id) { @@ -39,17 +45,20 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) } } -void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) { +void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) +{ /* return if thread i has not entered any function or has exited from all functions */ + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + uint32_t id = id_to_int(tid); - if ( work_list.size() <= id ) + if ( thrd_func_list->size() <= id ) return; - else if (work_list[id] == NULL) + else if (thrd_func_list->at(id) == NULL) return; /* get the function id that thread i is currently in */ - func_id_list_t * func_list = work_list[id]; + func_id_list_t * func_list = thrd_func_list->at(id); uint32_t func_id = func_list->back(); if ( func_atomics.size() <= func_id ) @@ -64,7 +73,8 @@ void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) { func_node->add_action(act); } -void ModelHistory::print() { +void ModelHistory::print() +{ for (uint32_t i = 0; i < func_atomics.size(); i++ ) { FuncNode * funcNode = func_atomics[i]; func_inst_list_t * inst_list = funcNode->get_inst_list(); diff --git a/history.h b/history.h index b42c34b1..dd8f13d8 100644 --- a/history.h +++ b/history.h @@ -3,8 +3,6 @@ #include "hashtable.h" #include "threads-model.h" -typedef SnapList func_id_list_t; - class ModelHistory { public: ModelHistory(); @@ -18,7 +16,7 @@ public: void add_func_atomic(ModelAction *act, thread_id_t tid); - HashTable * getFuncMap() { return &func_map; } + HashTable * getFuncMap() { return &func_map; } ModelVector * getFuncAtomics() { return &func_atomics; } void print(); @@ -28,15 +26,7 @@ private: uint32_t func_counter; /* map function names to integer ids */ - HashTable func_map; + HashTable func_map; ModelVector func_atomics; - - /* Work_list stores a list of function ids for each thread. - * Each element in work_list is intended to be used as a stack storing - * the functions that thread i has entered and yet to exit from - */ - - /* todo: move work_list to execution.cc to avoid seg fault */ - SnapVector< func_id_list_t * > work_list; };