move work_list (thrd_func_list) from history.h to execution.h, and fix the memory...
authorweiyu <weiyuluo1232@gmail.com>
Fri, 28 Jun 2019 19:42:35 +0000 (12:42 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Fri, 28 Jun 2019 19:42:35 +0000 (12:42 -0700)
classlist.h
execution.h
funcnode.h
history.cc
history.h

index 90f111d8454973b85bbb40650ac876232db6e7c4..67f6f8b7e89a9191988ac07abfb104a2911b6412 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef CLASSLIST_H
 #define CLASSLIST_H
 #ifndef CLASSLIST_H
 #define CLASSLIST_H
+#include <inttypes.h>
 #include "stl-model.h"
 
 class ClockVector;
 #include "stl-model.h"
 
 class ClockVector;
@@ -21,4 +22,5 @@ class FuncInst;
 struct model_snapshot_members;
 struct bug_message;
 typedef SnapList<ModelAction *> action_list_t;
 struct model_snapshot_members;
 struct bug_message;
 typedef SnapList<ModelAction *> action_list_t;
+typedef SnapList<uint32_t> func_id_list_t;
 #endif
 #endif
index 20bbfdc67f6466fe1ba47b46af00e1b6ad84d31e..9487fd6e95b8dbd015244aab2e111ecc135e11f1 100644 (file)
@@ -106,6 +106,8 @@ public:
        HashTable<pthread_cond_t *, cdsc::condition_variable *, uintptr_t, 4> * getCondMap() {return &cond_map;}
        HashTable<pthread_mutex_t *, cdsc::mutex *, uintptr_t, 4> * getMutexMap() {return &mutex_map;}
 
        HashTable<pthread_cond_t *, cdsc::condition_variable *, uintptr_t, 4> * getCondMap() {return &cond_map;}
        HashTable<pthread_mutex_t *, cdsc::mutex *, uintptr_t, 4> * getMutexMap() {return &mutex_map;}
 
+       SnapVector<func_id_list_t *> * get_thrd_func_list() { return &thrd_func_list; }
+
        SNAPSHOTALLOC
 private:
        int get_execution_number() const;
        SNAPSHOTALLOC
 private:
        int get_execution_number() const;
@@ -205,6 +207,12 @@ private:
        Fuzzer * fuzzer;
 
        Thread * action_select_next_thread(const ModelAction *curr) const;
        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__ */
 };
 
 #endif /* __EXECUTION_H__ */
index f150846d5b2cbef16ceadd37dc85ca0c802c68d5..6ddcbb26d328859ddc2a8a42716ecee5ff935958 100644 (file)
@@ -30,7 +30,7 @@ public:
 
        void add_action(ModelAction *act);
 
 
        void add_action(ModelAction *act);
 
-       HashTable<const char *, FuncInst *, uintptr_t, 4> * getFuncInsts() { return &func_insts; }
+       HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> * getFuncInsts() { return &func_insts; }
        func_inst_list_t * get_inst_list() { return &inst_list; }
 
        MEMALLOC
        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
         */
         * To do: cds_atomic_compare_exchange contains three atomic operations
         * that are feeded with the same source line number by llvm pass
         */
-       HashTable<const char *, FuncInst *, uintptr_t, 4> func_insts;
+       HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> func_insts;
 
        func_inst_list_t inst_list;
 };
 
        func_inst_list_t inst_list;
 };
index ec90a5a4826a06d42a7cb3cff1599ec621a99c25..2ae49a1650b526697b239085f8421a862f3cfb90 100644 (file)
@@ -3,24 +3,28 @@
 #include "action.h"
 #include "funcnode.h"
 
 #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(),
 /** @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);
 {}
 
 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<func_id_list_t *> * 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();
        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);
        }
 
        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)
 {
 
 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<func_id_list_t *> * 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) {
        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 */
        /* return if thread i has not entered any function or has exited
           from all functions */
+       SnapVector<func_id_list_t *> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+
        uint32_t id = id_to_int(tid);
        uint32_t id = id_to_int(tid);
-       if ( work_list.size() <= id )
+       if ( thrd_func_list->size() <= id )
                return;
                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 */
                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 )
        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);
 }
 
        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();
        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();
index b42c34b1ca99884e82a836bd016e0ceb7421c570..dd8f13d8c14a9527eddc19e4f17b1146966863c3 100644 (file)
--- a/history.h
+++ b/history.h
@@ -3,8 +3,6 @@
 #include "hashtable.h"
 #include "threads-model.h"
 
 #include "hashtable.h"
 #include "threads-model.h"
 
-typedef SnapList<uint32_t> func_id_list_t;
-
 class ModelHistory {
 public:
        ModelHistory();
 class ModelHistory {
 public:
        ModelHistory();
@@ -18,7 +16,7 @@ public:
 
        void add_func_atomic(ModelAction *act, thread_id_t tid);
 
 
        void add_func_atomic(ModelAction *act, thread_id_t tid);
 
-       HashTable<const char *, uint32_t, uintptr_t, 4> * getFuncMap() { return &func_map; }
+       HashTable<const char *, uint32_t, uintptr_t, 4, model_malloc, model_calloc, model_free> * getFuncMap() { return &func_map; }
        ModelVector<FuncNode *> * getFuncAtomics() { return &func_atomics; }
 
        void print();
        ModelVector<FuncNode *> * getFuncAtomics() { return &func_atomics; }
 
        void print();
@@ -28,15 +26,7 @@ private:
        uint32_t func_counter;
 
        /* map function names to integer ids */ 
        uint32_t func_counter;
 
        /* map function names to integer ids */ 
-       HashTable<const char *, uint32_t, uintptr_t, 4> func_map;
+       HashTable<const char *, uint32_t, uintptr_t, 4, model_malloc, model_calloc, model_free> func_map;
 
        ModelVector<FuncNode *> func_atomics;
 
        ModelVector<FuncNode *> 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;
 };
 };