Merge branch 'branch-weiyu' of /home/git/random-fuzzer into new_fuzzer
authorroot <root@dw-6.eecs.uci.edu>
Mon, 29 Jul 2019 19:21:02 +0000 (12:21 -0700)
committerroot <root@dw-6.eecs.uci.edu>
Mon, 29 Jul 2019 19:21:02 +0000 (12:21 -0700)
1  2 
execution.cc
history.cc

diff --combined execution.cc
index 290a2624666f905dc8bac06c5178aafc2fe5dda0,01125bb2b0910b7e64fa3933afed1f1693e01c2a..de2cace8cecbe61116e74c13837d3dcaedac8c8c
@@@ -277,7 -277,6 +277,6 @@@ ModelAction * ModelExecution::convertNo
        return act;
  }
  
  /**
   * Processes a read model action.
   * @param curr is the read model action to process.
@@@ -461,8 -460,8 +460,8 @@@ bool ModelExecution::process_fence(Mode
                                continue;
  
                        /* Establish hypothetical release sequences */
 -                      ClockVector *cv = get_hb_from_write(act);
 -                      if (curr->get_cv()->merge(cv))
 +                      ClockVector *cv = get_hb_from_write(act->get_reads_from());
 +                      if (cv != NULL && curr->get_cv()->merge(cv))
                                updated = true;
                }
        }
@@@ -852,7 -851,7 +851,7 @@@ bool ModelExecution::r_modification_ord
                        if (act->happens_before(curr)) {
                                if (i==0) {
                                        if (last_sc_fence_local == NULL ||
 -                                                      (*last_sc_fence_local < *prev_same_thread)) {
 +                                                      (*last_sc_fence_local < *act)) {
                                                prev_same_thread = act;
                                        }
                                }
@@@ -910,17 -909,13 +909,17 @@@ void ModelExecution::w_modification_ord
        unsigned int i;
        ASSERT(curr->is_write());
  
 +      SnapList<ModelAction *> edgeset;
 +
        if (curr->is_seqcst()) {
                /* We have to at least see the last sequentially consistent write,
                         so we are initialized. */
                ModelAction *last_seq_cst = get_last_seq_cst_write(curr);
                if (last_seq_cst != NULL) {
 -                      mo_graph->addEdge(last_seq_cst, curr);
 +                      edgeset.push_back(last_seq_cst);
                }
 +              //update map for next query
 +              obj_last_sc_map.put(curr->get_location(), curr);
        }
  
        /* Last SC fence in the current thread */
                /* Iterate over actions in thread, starting from most recent */
                action_list_t *list = &(*thrd_lists)[i];
                action_list_t::reverse_iterator rit;
 -              bool force_edge = false;
                for (rit = list->rbegin();rit != list->rend();rit++) {
                        ModelAction *act = *rit;
                        if (act == curr) {
                                 * 3) If normal write, we need to look at earlier actions, so
                                 * continue processing list.
                                 */
 -                              force_edge = true;
                                if (curr->is_rmw()) {
                                        if (curr->get_reads_from() != NULL)
                                                break;
                        /* C++, Section 29.3 statement 7 */
                        if (last_sc_fence_thread_before && act->is_write() &&
                                        *act < *last_sc_fence_thread_before) {
 -                              mo_graph->addEdge(act, curr, force_edge);
 +                              edgeset.push_back(act);
                                break;
                        }
  
                                 *   readfrom(act) --mo--> act
                                 */
                                if (act->is_write())
 -                                      mo_graph->addEdge(act, curr, force_edge);
 +                                      edgeset.push_back(act);
                                else if (act->is_read()) {
                                        //if previous read accessed a null, just keep going
 -                                      mo_graph->addEdge(act->get_reads_from(), curr, force_edge);
 +                                      edgeset.push_back(act->get_reads_from());
                                }
                                break;
                        }
                }
        }
 +      mo_graph->addEdges(&edgeset, curr);
 +
  }
  
  /**
@@@ -1209,6 -1204,10 +1208,6 @@@ void ModelExecution::add_normal_write_t
  
  
  void ModelExecution::add_write_to_lists(ModelAction *write) {
 -      // Update seq_cst map
 -      if (write->is_seqcst())
 -              obj_last_sc_map.put(write->get_location(), write);
 -
        SnapVector<action_list_t> *vec = get_safe_ptr_vect_action(&obj_wr_thrd_map, write->get_location());
        int tid = id_to_int(write->get_tid());
        if (tid >= (int)vec->size())
@@@ -1632,7 -1631,7 +1631,7 @@@ Thread * ModelExecution::take_step(Mode
        ASSERT(curr);
  
        /* Process this action in ModelHistory for records*/
-       model->get_history()->process_action( curr, curr_thrd->get_id() );
+       model->get_history()->process_action( curr, curr->get_tid() );
  
        if (curr_thrd->is_blocked() || curr_thrd->is_complete())
                scheduler->remove_thread(curr_thrd);
diff --combined history.cc
index ca176b1900759e71ec8b8c25aa2c979749c88f1a,7b6e3c87fe6adfca4e5bbcd54e99203b8ec35234..3c000e7de06c20f2054610a96f7138db78d92745
@@@ -13,14 -13,15 +13,15 @@@ ModelHistory::ModelHistory() 
        func_counter(1),        /* function id starts with 1 */
        func_map(),
        func_map_rev(),
-       func_nodes()
+       func_nodes(),
+       write_history()
  {}
  
  void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid)
  {
        //model_print("thread %d entering func %d\n", tid, func_id);
        uint32_t id = id_to_int(tid);
-       SnapVector<func_id_list_t *> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+       SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
        SnapVector< SnapList<func_inst_list_t *> *> *
                thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists();
  
                thrd_func_inst_lists->resize( id + 1 );
        }
  
-       func_id_list_t * func_list = thrd_func_list->at(id);
        SnapList<func_inst_list_t *> * func_inst_lists = thrd_func_inst_lists->at(id);
  
-       if (func_list == NULL) {
-               func_list = new func_id_list_t();
-               thrd_func_list->at(id) = func_list;
-       }
        if (func_inst_lists == NULL) {
                func_inst_lists = new SnapList< func_inst_list_t *>();
                thrd_func_inst_lists->at(id) = func_inst_lists;
        }
  
-       func_list->push_back(func_id);
+       (*thrd_func_list)[id].push_back(func_id);
        func_inst_lists->push_back( new func_inst_list_t() );
  
        if ( func_nodes.size() <= func_id )
  void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid)
  {
        uint32_t id = id_to_int(tid);
-       SnapVector<func_id_list_t *> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+       SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
        SnapVector< SnapList<func_inst_list_t *> *> *
                thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists();
  
-       func_id_list_t * func_list = thrd_func_list->at(id);
        SnapList<func_inst_list_t *> * func_inst_lists = thrd_func_inst_lists->at(id);
-       uint32_t last_func_id = func_list->back();
+       uint32_t last_func_id = (*thrd_func_list)[id].back();
  
        if (last_func_id == func_id) {
 -              /* clear read map upon exiting functions */
                FuncNode * func_node = func_nodes[func_id];
                func_node->clear_read_map(tid);
  
                func_inst_list_t * curr_inst_list = func_inst_lists->back();
                func_node->link_insts(curr_inst_list);
  
-               func_list->pop_back();
+               (*thrd_func_list)[id].pop_back();
                func_inst_lists->pop_back();
        } else {
                model_print("trying to exit with a wrong function id\n");
@@@ -85,7 -79,7 +78,7 @@@ void ModelHistory::resize_func_nodes(ui
        if ( old_size < new_size )
                func_nodes.resize(new_size);
  
 -      for (uint32_t id = old_size; id < new_size; id++) {
 +      for (uint32_t id = old_size;id < new_size;id++) {
                const char * func_name = func_map_rev[id];
                FuncNode * func_node = new FuncNode();
                func_node->set_func_id(id);
@@@ -98,22 -92,18 +91,18 @@@ void ModelHistory::process_action(Model
  {
        /* 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();
+       SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
        SnapVector< SnapList<func_inst_list_t *> *> *
                thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists();
  
        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 = (*thrd_func_list)[id].back();
        SnapList<func_inst_list_t *> * func_inst_lists = thrd_func_inst_lists->at(id);
  
-       uint32_t func_id = func_list->back();
        if ( func_nodes.size() <= func_id )
                resize_func_nodes( func_id + 1 );
  
        if (inst == NULL)
                return;
  
 -      if (inst->is_read())
 -              func_node->store_read(act, tid);
 +      //      if (inst->is_read())
 +      //      func_node->store_read(act, tid);
  
+       if (inst->is_write())
+               add_to_write_history(act->get_location(), act->get_write_value());
        /* add to curr_inst_list */
        func_inst_list_t * curr_inst_list = func_inst_lists->back();
        ASSERT(curr_inst_list != NULL);
@@@ -144,6 -137,32 +136,32 @@@ FuncNode * ModelHistory::get_func_node(
        return func_nodes[func_id];
  }
  
+ uint64_t ModelHistory::query_last_read(void * location, thread_id_t tid)
+ {
+       SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+       uint32_t id = id_to_int(tid);
+       ASSERT( thrd_func_list->size() > id );
+       uint32_t func_id = (*thrd_func_list)[id].back();
+       FuncNode * func_node = func_nodes[func_id];
+       uint64_t last_read_val = 0xdeadbeef;
+       if (func_node != NULL) {
+               last_read_val = func_node->query_last_read(location, tid);
+       }
+       return last_read_val;
+ }
+ void ModelHistory::add_to_write_history(void * location, uint64_t write_val)
+ {
+       if ( !write_history.contains(location) )
+               write_history.put(location, new write_set_t() );
+       write_set_t * write_set = write_history.get(location);
+       write_set->add(write_val);
+ }
  void ModelHistory::print()
  {
        /* function id starts with 1 */