From 0c8b810bcf730dcf184c0b35eef074f89a40fac3 Mon Sep 17 00:00:00 2001 From: weiyu Date: Thu, 27 Jun 2019 18:35:14 -0700 Subject: [PATCH] change data structures --- classlist.h | 2 ++ funcnode.cc | 35 +++++++++++++++++++++++++++++++++-- funcnode.h | 28 ++++++++++++++++++++++------ history.cc | 31 +++++++++++++------------------ history.h | 12 ++++++------ 5 files changed, 76 insertions(+), 32 deletions(-) diff --git a/classlist.h b/classlist.h index 641a1481..90f111d8 100644 --- a/classlist.h +++ b/classlist.h @@ -15,6 +15,8 @@ class Scheduler; class Thread; class TraceAnalysis; class Fuzzer; +class FuncNode; +class FuncInst; struct model_snapshot_members; struct bug_message; diff --git a/funcnode.cc b/funcnode.cc index 3a545112..27d57f06 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -1,13 +1,44 @@ #include "funcnode.h" -FuncInst::FuncInst(ModelAction *act) : - action(act) +FuncInst::FuncInst(ModelAction *act) { ASSERT(act); this->position = act->get_position(); + this->location = act->get_location(); + this->type = act->get_type(); } FuncNode::FuncNode() : func_insts() {} +void FuncNode::add_action(ModelAction *act) +{ + ASSERT(act); + + const char * position = act->get_position(); + + /* Actions THREAD_CREATE, THREAD_START, THREAD_YIELD, THREAD_JOIN, + * THREAD_FINISH, PTHREAD_CREATE, PTHREAD_JOIN, + * ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK are not tagged with their + * source line numbers + */ + if (position == NULL) { + return; + } + + if ( func_insts.contains(position) ) { + FuncInst * inst = func_insts.get(position); + + if (inst->get_type() != act->get_type() && + inst->get_type() != ATOMIC_RMWRCAS ) { + model_print("action with a different type occurs at line number %s \n", position); + } + + return; + } + + FuncInst * func_inst = new FuncInst(act); + func_insts.put(position, func_inst); + inst_list.push_back(func_inst); +} diff --git a/funcnode.h b/funcnode.h index 03c92ef0..f150846d 100644 --- a/funcnode.h +++ b/funcnode.h @@ -3,19 +3,24 @@ class ModelAction; -typedef ModelList action_mlist_t; -typedef SnapList func_id_list_t; +typedef ModelList func_inst_list_t; class FuncInst { -public: +public: FuncInst(ModelAction *act); ~FuncInst(); - ModelAction * get_action() const { return action; } + //ModelAction * get_action() const { return action; } const char * get_position() const { return position; } + void * get_location() const { return location; } + action_type get_type() const { return type; } + + MEMALLOC private: - ModelAction * const action; + //ModelAction * const action; const char * position; + void *location; + action_type type; }; class FuncNode { @@ -23,8 +28,19 @@ public: FuncNode(); ~FuncNode(); + void add_action(ModelAction *act); + HashTable * getFuncInsts() { return &func_insts; } + func_inst_list_t * get_inst_list() { return &inst_list; } + + MEMALLOC private: + /* Use source line number as the key of hashtable + * + * 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; -}; + func_inst_list_t inst_list; +}; diff --git a/history.cc b/history.cc index 4af57289..ec90a5a4 100644 --- a/history.cc +++ b/history.cc @@ -1,7 +1,7 @@ #include #include "history.h" #include "action.h" - +#include "funcnode.h" /** @brief Constructor */ ModelHistory::ModelHistory() : @@ -13,8 +13,6 @@ ModelHistory::ModelHistory() : void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) { -// model_print("entering function: %d\n", func_id); - uint32_t id = id_to_int(tid); if ( work_list.size() <= id ) work_list.resize( id + 1 ); @@ -39,8 +37,6 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) model_print("trying to exit with a wrong function id\n"); model_print("--- last_func: %d, func_id: %d\n", last_func_id, func_id); } - -// model_print("exiting function: %d\n", func_id); } void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) { @@ -59,29 +55,28 @@ void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) { if ( func_atomics.size() <= func_id ) func_atomics.resize( func_id + 1 ); - action_mlist_t * atomic_list = func_atomics[func_id]; - if (atomic_list == NULL) { - atomic_list = new action_mlist_t(); - func_atomics[func_id] = atomic_list; + FuncNode * func_node = func_atomics[func_id]; + if (func_node == NULL) { + func_node = new FuncNode(); + func_atomics[func_id] = func_node; } - atomic_list->push_back(act); - - model_print("func id: %d, added atomic acts: %d\n", func_id, act->get_type()); + func_node->add_action(act); } void ModelHistory::print() { for (uint32_t i = 0; i < func_atomics.size(); i++ ) { - action_mlist_t * atomic_list = func_atomics[i]; + FuncNode * funcNode = func_atomics[i]; + func_inst_list_t * inst_list = funcNode->get_inst_list(); - if (atomic_list == NULL) + if (funcNode == NULL) continue; model_print("function with id: %d has following actions\n", i); - action_mlist_t::iterator it; - for (it = atomic_list->begin(); it != atomic_list->end(); it++) { - const ModelAction *act = *it; - act->print(); + func_inst_list_t::iterator it; + for (it = inst_list->begin(); it != inst_list->end(); it++) { + FuncInst *inst = *it; + model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position()); } } } diff --git a/history.h b/history.h index c8d2265f..b42c34b1 100644 --- a/history.h +++ b/history.h @@ -3,10 +3,6 @@ #include "hashtable.h" #include "threads-model.h" -/* forward declaration */ -class ModelAction; - -typedef ModelList action_mlist_t; typedef SnapList func_id_list_t; class ModelHistory { @@ -23,20 +19,24 @@ public: void add_func_atomic(ModelAction *act, thread_id_t tid); HashTable * getFuncMap() { return &func_map; } - ModelVector< action_mlist_t * > * getFuncAtomics() { return &func_atomics; } + ModelVector * getFuncAtomics() { return &func_atomics; } void print(); + + MEMALLOC private: uint32_t func_counter; /* map function names to integer ids */ HashTable func_map; - ModelVector< action_mlist_t * > func_atomics; + 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; }; -- 2.34.1