fix git conflict
authorweiyu <weiyuluo1232@gmail.com>
Mon, 1 Jul 2019 18:47:38 +0000 (11:47 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Mon, 1 Jul 2019 18:47:38 +0000 (11:47 -0700)
Makefile
classlist.h
execution.cc
execution.h
funcnode.cc [new file with mode: 0644]
funcnode.h [new file with mode: 0644]
history.cc
history.h

index 0d2af4647ed740a8fb21decc2c36d6e0e5b71d40..214873ac0e0a7edacade3df693bbdc94193675c1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ OBJECTS := libthreads.o schedule.o model.o threads.o librace.o action.o \
           datarace.o impatomic.o cmodelint.o \
           snapshot.o malloc.o mymemory.o common.o mutex.o conditionvariable.o \
           context.o execution.o libannotate.o plugins.o pthread.o futex.o fuzzer.o \
-          sleeps.o history.o printf.o
+          sleeps.o history.o funcnode.o printf.o
 
 CPPFLAGS += -Iinclude -I.
 LDFLAGS := -ldl -lrt -rdynamic
@@ -36,8 +36,8 @@ README.html: README.md
 malloc.o: malloc.c
        $(CC) -fPIC -c malloc.c -DMSPACES -DONLY_MSPACES -DHAVE_MMAP=1 $(CPPFLAGS) -Wno-unused-variable
 
-futex.o: futex.cc
-       $(CXX) -fPIC -c futex.cc -std=c++11 $(CPPFLAGS)
+#futex.o: futex.cc
+#      $(CXX) -fPIC -c futex.cc -std=c++11 $(CPPFLAGS)
 
 %.o : %.cc
        $(CXX) -MMD -MF .$@.d -fPIC -c $< $(CPPFLAGS)
index 641a148103b73f98a1d5448a9ff755867368e372..67f6f8b7e89a9191988ac07abfb104a2911b6412 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef CLASSLIST_H
 #define CLASSLIST_H
+#include <inttypes.h>
 #include "stl-model.h"
 
 class ClockVector;
@@ -15,8 +16,11 @@ class Scheduler;
 class Thread;
 class TraceAnalysis;
 class Fuzzer;
+class FuncNode;
+class FuncInst;
 
 struct model_snapshot_members;
 struct bug_message;
 typedef SnapList<ModelAction *> action_list_t;
+typedef SnapList<uint32_t> func_id_list_t;
 #endif
index 4b76520660e2f0fedc67d72c8f9f262bbed843fc..a72cb675bb5dd20df4c56bceecb3f840a21b30d3 100644 (file)
@@ -14,6 +14,7 @@
 #include "datarace.h"
 #include "threads-model.h"
 #include "bugmessage.h"
+#include "history.h"
 #include "fuzzer.h"
 
 #define INITIAL_THREAD_ID       0
@@ -388,10 +389,7 @@ bool ModelExecution::process_mutex(ModelAction *curr)
  */
 void ModelExecution::process_write(ModelAction *curr)
 {
-
        w_modification_order(curr);
-
-
        get_thread(curr)->set_return_value(VALUE_NONE);
 }
 
@@ -1617,6 +1615,9 @@ Thread * ModelExecution::take_step(ModelAction *curr)
        curr = check_current_action(curr);
        ASSERT(curr);
 
+       // model_print("poitner loc: %p, thread: %d, type: %d, order: %d, position: %s\n", curr, curr->get_tid(), curr->get_type(), curr->get_mo(), curr->get_position() );
+       model->get_history()->add_func_atomic( curr, curr_thrd->get_id() );
+
        if (curr_thrd->is_blocked() || curr_thrd->is_complete())
                scheduler->remove_thread(curr_thrd);
 
index fa2b78b8a282fda6234f3090a00bda968104cc54..0a36d31cab50f5532f8171c9e3f83935ab39b840 100644 (file)
@@ -107,6 +107,8 @@ public:
        HashTable<pthread_mutex_t *, cdsc::snapmutex *, uintptr_t, 4> * getMutexMap() {return &mutex_map;}
        ModelAction * check_current_action(ModelAction *curr);
 
+       SnapVector<func_id_list_t *> * 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.cc b/funcnode.cc
new file mode 100644 (file)
index 0000000..27d57f0
--- /dev/null
@@ -0,0 +1,44 @@
+#include "funcnode.h"
+
+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
new file mode 100644 (file)
index 0000000..6ddcbb2
--- /dev/null
@@ -0,0 +1,46 @@
+#include "action.h"
+#include "hashtable.h"
+
+class ModelAction;
+
+typedef ModelList<FuncInst *> func_inst_list_t;
+
+class FuncInst {
+public:
+       FuncInst(ModelAction *act);
+       ~FuncInst();
+
+       //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;
+       const char * position;
+       void *location;
+       action_type type;
+};
+
+class FuncNode {
+public:
+       FuncNode();
+       ~FuncNode();
+
+       void add_action(ModelAction *act);
+
+       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
+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<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> func_insts;
+
+       func_inst_list_t inst_list;
+};
index e0560bad79df58a452ad0c9f566ead7e160e773c..2ae49a1650b526697b239085f8421a862f3cfb90 100644 (file)
@@ -1,30 +1,40 @@
 #include <inttypes.h>
 #include "history.h"
 #include "action.h"
+#include "funcnode.h"
 
+#include "model.h"
+#include "execution.h"
+
+/** @brief Constructor */
 ModelHistory::ModelHistory() :
-       func_id(1),     /* function id starts with 1 */
+       func_counter(0), /* function id starts with 0 */
        func_map(),
-       func_history(),
-       work_list()
+       func_atomics()
 {}
 
 void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid)
 {
-       if ( !work_list.contains(tid) ) {
-               // This thread has not been pushed to work_list
-               SnapList<uint32_t> * func_list = new SnapList<uint32_t>();
-               func_list->push_back(func_id);
-               work_list.put(tid, func_list);
-       } else {
-               SnapList<uint32_t> * func_list = work_list.get(tid);
-               func_list->push_back(func_id);
+       uint32_t id = id_to_int(tid);
+       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 = thrd_func_list->at(id);
+       if (func_list == NULL) {
+               func_list = new func_id_list_t();
+               thrd_func_list->at(id) = func_list;
        }
+
+       func_list->push_back(func_id);
 }
 
 void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid)
 {
-       SnapList<uint32_t> * func_list = work_list.get(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) {
@@ -34,3 +44,49 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid)
                model_print("--- last_func: %d, func_id: %d\n", last_func_id, func_id);
        }
 }
+
+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<func_id_list_t *> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+
+       uint32_t id = id_to_int(tid);
+       if ( thrd_func_list->size() <= id )
+               return;
+       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 = thrd_func_list->at(id);
+       uint32_t func_id = func_list->back();
+
+       if ( func_atomics.size() <= func_id )
+               func_atomics.resize( func_id + 1 );
+
+       FuncNode * func_node = func_atomics[func_id];
+       if (func_node == NULL) {
+               func_node = new FuncNode();
+               func_atomics[func_id] = func_node;
+       }
+
+       func_node->add_action(act);
+}
+
+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();
+
+               if (funcNode == NULL)
+                       continue;
+
+               model_print("function with id: %d has following actions\n", i);
+               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());
+               }
+       }
+}
index 179439ce44ad24d6a0fafc0d31689558de94820c..dd8f13d8c14a9527eddc19e4f17b1146966863c3 100644 (file)
--- a/history.h
+++ b/history.h
@@ -1,39 +1,32 @@
 #include "stl-model.h"
 #include "common.h"
 #include "hashtable.h"
-#include "modeltypes.h"
-
-/* forward declaration */
-class ModelAction;
-
-typedef ModelList<ModelAction *> action_mlist_t;
+#include "threads-model.h"
 
 class ModelHistory {
 public:
        ModelHistory();
+       ~ModelHistory();
 
        void enter_function(const uint32_t func_id, thread_id_t tid);
        void exit_function(const uint32_t func_id, thread_id_t tid);
 
-       uint32_t get_func_counter() { return func_id; }
-       void incr_func_counter() { func_id++; }
+       uint32_t get_func_counter() { return func_counter; }
+       void incr_func_counter() { func_counter++; }
+
+       void add_func_atomic(ModelAction *act, thread_id_t tid);
 
-       HashTable<const char *, uint32_t, uintptr_t, 4> * getFuncMap() { return &func_map; }
-       HashTable<uint32_t, action_mlist_t *, uintptr_t, 4> * getFuncHistory() { return &func_history; }
+       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();
+
        MEMALLOC
 private:
-       uint32_t func_id;
-
-       /* map function names to integer ids */
-       HashTable<const char *, uint32_t, uintptr_t, 4> func_map;
+       uint32_t func_counter;
 
-       HashTable<uint32_t, action_mlist_t *, uintptr_t, 4> func_history;
+       /* map function names to integer ids */ 
+       HashTable<const char *, uint32_t, uintptr_t, 4, model_malloc, model_calloc, model_free> func_map;
 
-       /* work_list stores a list of function ids for each thread
-        * SnapList<uint32_t> is intended to be used as a stack storing
-        * the functions that thread i has entered and yet to exit from
-        */
-       HashTable<thread_id_t, SnapList<uint32_t> *, uintptr_t, 4> work_list;
+       ModelVector<FuncNode *> func_atomics;
 };