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
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)
#ifndef CLASSLIST_H
#define CLASSLIST_H
+#include <inttypes.h>
#include "stl-model.h"
class ClockVector;
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
#include "datarace.h"
#include "threads-model.h"
#include "bugmessage.h"
+#include "history.h"
#include "fuzzer.h"
#define INITIAL_THREAD_ID 0
*/
void ModelExecution::process_write(ModelAction *curr)
{
-
w_modification_order(curr);
-
-
get_thread(curr)->set_return_value(VALUE_NONE);
}
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);
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;
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__ */
--- /dev/null
+#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);
+}
--- /dev/null
+#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;
+};
#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) {
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());
+ }
+ }
+}
#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;
};