history(history),
exit_count(0),
marker(1),
+ inst_counter(1),
func_inst_map(),
inst_list(),
entry_insts(),
- inst_pred_map(128),
- inst_id_map(128),
- loc_act_map(128),
+ thrd_inst_pred_map(),
+ thrd_inst_id_map(),
+ thrd_loc_act_map(),
predicate_tree_position(),
predicate_leaves(),
leaves_tmp_storage(),
predicate_tree_exit->set_depth(MAX_DEPTH);
/* Snapshot data structures below */
- action_list_buffer = new SnapList<action_list_t *>();
read_locations = new loc_set_t();
write_locations = new loc_set_t();
val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
/* Reallocate snapshotted memories when new executions start */
void FuncNode::set_new_exec_flag()
{
- action_list_buffer = new SnapList<action_list_t *>();
read_locations = new loc_set_t();
write_locations = new loc_set_t();
val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
}
}
-
void FuncNode::add_entry_inst(FuncInst * inst)
{
if (inst == NULL)
entry_insts.push_back(inst);
}
+void FuncNode::function_entry_handler(thread_id_t tid)
+{
+ marker++;
+
+ init_predicate_tree_position(tid);
+ init_inst_act_map(tid);
+ init_maps(tid);
+}
+
+void FuncNode::function_exit_handler(thread_id_t tid)
+{
+ exit_count++;
+
+ reset_inst_act_map(tid);
+ reset_maps(tid);
+
+ Predicate * exit_pred = get_predicate_tree_position(tid);
+ if (exit_pred->get_exit() == NULL) {
+ // Exit predicate is unset yet
+ exit_pred->set_exit(predicate_tree_exit);
+ }
+
+ set_predicate_tree_position(tid, NULL);
+}
+
/**
* @brief Convert ModelAdtion list to FuncInst list
* @param act_list A list of ModelActions
*/
-void FuncNode::update_tree(action_list_t * act_list)
+void FuncNode::update_tree(ModelAction * act)
{
- if (act_list == NULL || act_list->size() == 0)
- return;
-
HashTable<void *, value_set_t *, uintptr_t, 0> * write_history = history->getWriteHistory();
+ HashSet<ModelAction *, uintptr_t, 2> write_actions;
/* build inst_list from act_list for later processing */
- func_inst_list_t inst_list;
- action_list_t rw_act_list;
-
- for (sllnode<ModelAction *> * it = act_list->begin();it != NULL;it = it->getNext()) {
- ModelAction * act = it->getVal();
-
- // Only ATOMIC_RMW or ATOMIC_WRITE may be swapped with their original types,
- // which are later added to rw_act_list. Therefore, it is safe to only revert
- // back action types for actions in rw_act_list whose types have been swapped.
- if (act->get_original_type() != ATOMIC_NOP && act->get_swap_flag() == false)
- act->use_original_type();
-
- // Remove func_act_ref so that actions can be deleted by Execution::collectActions
- act->setFuncActRef(NULL);
- if (act->is_read()) {
- // For every read or rmw actions in this list, the reads_from is not deleted.
- // So it is safe to call get_reads_from
- ModelAction * rf = act->get_reads_from();
- rf->setFuncActRef(NULL);
- }
+// func_inst_list_t inst_list;
- FuncInst * func_inst = get_inst(act);
- void * loc = act->get_location();
+ FuncInst * func_inst = get_inst(act);
+ void * loc = act->get_location();
- if (func_inst == NULL)
- continue;
+ if (func_inst == NULL)
+ return;
- inst_list.push_back(func_inst);
- bool act_added = false;
+// inst_list.push_back(func_inst);
- if (act->is_write()) {
- rw_act_list.push_back(act);
- act_added = true;
- if (!write_locations->contains(loc)) {
- write_locations->add(loc);
- history->update_loc_wr_func_nodes_map(loc, this);
- }
+ if (act->is_write()) {
+ if (!write_locations->contains(loc)) {
+ write_locations->add(loc);
+ history->update_loc_wr_func_nodes_map(loc, this);
}
- if (act->is_read()) {
- if (!act_added)
- rw_act_list.push_back(act);
-
- /* If func_inst may only read_from a single location, then:
- *
- * The first time an action reads from some location,
- * import all the values that have been written to this
- * location from ModelHistory and notify ModelHistory
- * that this FuncNode may read from this location.
- */
- if (!read_locations->contains(loc) && func_inst->is_single_location()) {
- read_locations->add(loc);
- value_set_t * write_values = write_history->get(loc);
- add_to_val_loc_map(write_values, loc);
- history->update_loc_rd_func_nodes_map(loc, this);
- }
- }
+ // Do not process writes for now
+ return;
}
- update_inst_tree(&inst_list);
- update_predicate_tree(&rw_act_list);
-
- // Revert back action types and free
- for (sllnode<ModelAction *> * it = act_list->begin(); it != NULL; it = it->getNext()) {
- ModelAction * act = it->getVal();
+ if (act->is_read()) {
- // Revert back action types for actions whose types have been changed.
- if (act->get_swap_flag() == true)
- act->use_original_type();
-
- /** Free actions
- * case 1. READY_FREE -> delete
- * case 2. Read action whose read from is READY_FREE -> delete both actions
- * In both cases, the actions have already been removed from core model
- * action lists.
+ /* If func_inst may only read_from a single location, then:
+ *
+ * The first time an action reads from some location,
+ * import all the values that have been written to this
+ * location from ModelHistory and notify ModelHistory
+ * that this FuncNode may read from this location.
*/
-
- /* Problematic: could double free actions
- if (act->is_free()) {
- model_print("delete free act %d\n", act->get_seq_number());
- delete act;
- } else if (act->is_read()) {
- ModelAction * rf = act->get_reads_from();
- if (rf->is_free()) {
- model_print("delete act %d\n", act->get_seq_number());
- model_print("delete act %d\n", rf->get_seq_number());
- delete rf;
- delete act;
- }
- }*/
+ if (!read_locations->contains(loc) && func_inst->is_single_location()) {
+ read_locations->add(loc);
+ value_set_t * write_values = write_history->get(loc);
+ add_to_val_loc_map(write_values, loc);
+ history->update_loc_rd_func_nodes_map(loc, this);
+ }
}
+// update_inst_tree(&inst_list); TODO
+ update_predicate_tree(act);
+
// print_predicate_tree();
}
}
}
-void FuncNode::update_predicate_tree(action_list_t * act_list)
+void FuncNode::update_predicate_tree(ModelAction * next_act)
{
- if (act_list == NULL || act_list->size() == 0)
- return;
-
- incr_marker();
- uint32_t inst_counter = 0;
+ thread_id_t tid = next_act->get_tid();
+ int thread_id = id_to_int(tid);
// Clear hashtables
- loc_act_map.reset();
- inst_pred_map.reset();
- inst_id_map.reset();
+ loc_act_map_t * loc_act_map = thrd_loc_act_map[thread_id];
+ inst_pred_map_t * inst_pred_map = thrd_inst_pred_map[thread_id];
+ inst_id_map_t * inst_id_map = thrd_inst_id_map[thread_id];
// Clear the set of leaves encountered in this path
- leaves_tmp_storage.clear();
+ // leaves_tmp_storage.clear();
- sllnode<ModelAction *> *it = act_list->begin();
- Predicate * curr_pred = predicate_tree_entry;
- while (it != NULL) {
- ModelAction * next_act = it->getVal();
+ Predicate * curr_pred = get_predicate_tree_position(tid);
+ while (true) {
FuncInst * next_inst = get_inst(next_act);
next_inst->set_associated_act(next_act, marker);
}
// Detect loops
- if (!branch_found && inst_id_map.contains(next_inst)) {
+ if (!branch_found && inst_id_map->contains(next_inst)) {
FuncInst * curr_inst = curr_pred->get_func_inst();
- uint32_t curr_id = inst_id_map.get(curr_inst);
- uint32_t next_id = inst_id_map.get(next_inst);
+ uint32_t curr_id = inst_id_map->get(curr_inst);
+ uint32_t next_id = inst_id_map->get(next_inst);
if (curr_id >= next_id) {
- Predicate * old_pred = inst_pred_map.get(next_inst);
+ Predicate * old_pred = inst_pred_map->get(next_inst);
Predicate * back_pred = old_pred->get_parent();
// For updating weights
if (next_act->is_read()) {
/* Only need to store the locations of read actions */
- loc_act_map.put(next_act->get_location(), next_act);
+ loc_act_map->put(next_act->get_location(), next_act);
}
- inst_pred_map.put(next_inst, curr_pred);
- if (!inst_id_map.contains(next_inst))
- inst_id_map.put(next_inst, inst_counter++);
+ inst_pred_map->put(next_inst, curr_pred);
+ set_predicate_tree_position(tid, curr_pred);
- it = it->getNext();
- curr_pred->incr_expl_count();
- }
+ if (!inst_id_map->contains(next_inst))
+ inst_id_map->put(next_inst, inst_counter++);
- if (curr_pred->get_exit() == NULL) {
- // Exit predicate is unset yet
- curr_pred->set_exit(predicate_tree_exit);
+ curr_pred->incr_expl_count();
+ break;
}
- leaves_tmp_storage.push_back(curr_pred);
- update_predicate_tree_weight();
+// leaves_tmp_storage.push_back(curr_pred);
+// update_predicate_tree_weight();
}
/* Given curr_pred and next_inst, find the branch following curr_pred that
/* Only read and rmw actions my have unset predicate expressions */
if (pred_expressions->getSize() == 0) {
predicate_correct = false;
+
if (*unset_predicate == NULL)
*unset_predicate = branch;
else
SnapVector<struct half_pred_expr *> * half_pred_expressions)
{
void * loc = next_act->get_location();
+ int thread_id = id_to_int(next_act->get_tid());
+ loc_act_map_t * loc_act_map = thrd_loc_act_map[thread_id];
if (next_inst->is_read()) {
/* read + rmw */
- if ( loc_act_map.contains(loc) ) {
- ModelAction * last_act = loc_act_map.get(loc);
+ if ( loc_act_map->contains(loc) ) {
+ ModelAction * last_act = loc_act_map->get(loc);
FuncInst * last_inst = get_inst(last_act);
struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
half_pred_expressions->push_back(expression);
loc_set_iter * loc_it = loc_may_equal->iterator();
while (loc_it->hasNext()) {
void * neighbor = loc_it->next();
- if (loc_act_map.contains(neighbor)) {
- ModelAction * last_act = loc_act_map.get(neighbor);
+ if (loc_act_map->contains(neighbor)) {
+ ModelAction * last_act = loc_act_map->get(neighbor);
FuncInst * last_inst = get_inst(last_act);
struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
uint old_size = thrd_inst_act_map->size();
- if (thrd_inst_act_map->size() <= (uint) thread_id) {
+ if (old_size <= (uint) thread_id) {
uint new_size = thread_id + 1;
thrd_inst_act_map->resize(new_size);
return (*thrd_inst_act_map)[thread_id];
}
+/* Make sure elements of thrd_loc_act_map are initialized properly when threads enter functions */
+void FuncNode::init_maps(thread_id_t tid)
+{
+ int thread_id = id_to_int(tid);
+ uint old_size = thrd_loc_act_map.size();
+
+ if (old_size <= (uint) thread_id) {
+ uint new_size = thread_id + 1;
+ thrd_loc_act_map.resize(new_size);
+ thrd_inst_id_map.resize(new_size);
+ thrd_inst_pred_map.resize(new_size);
+
+ for (uint i = old_size; i < new_size;i++) {
+ thrd_loc_act_map[i] = new loc_act_map_t(128);
+ thrd_inst_id_map[i] = new inst_id_map_t(128);
+ thrd_inst_pred_map[i] = new inst_pred_map_t(128);
+ }
+ }
+}
+
+/* Reset elements of thrd_loc_act_map when threads exit functions */
+void FuncNode::reset_maps(thread_id_t tid)
+{
+ int thread_id = id_to_int(tid);
+ thrd_loc_act_map[thread_id]->reset();
+ thrd_inst_id_map[thread_id]->reset();
+ thrd_inst_pred_map[thread_id]->reset();
+}
+
/* Add FuncNodes that this node may follow */
void FuncNode::add_out_edge(FuncNode * other)
{