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();
-
- // Use the original action type and decrement ref count
- // so that actions may be deleted by Execution::collectActions
- if (act->get_original_type() != ATOMIC_NOP && act->get_swap_flag() == false)
- act->use_original_type();
+// func_inst_list_t inst_list;
- act->decr_func_ref_count();
+ FuncInst * func_inst = get_inst(act);
+ void * loc = act->get_location();
- if (act->is_read()) {
- // For every read or rmw actions in this list, the reads_from was marked, and not deleted.
- // So it is safe to call get_reads_from
- ModelAction * rf = act->get_reads_from();
- if (rf->get_original_type() != ATOMIC_NOP && rf->get_swap_flag() == false)
- rf->use_original_type();
-
- rf->decr_func_ref_count();
- }
-
- 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;) {
- ModelAction * act = it->getVal();
- // Do iteration early in case we delete read actions
- it = it->getNext();
-
- // Collect write actions and reads_froms
- if (act->is_read()) {
- if (act->is_rmw()) {
- write_actions.add(act);
- }
-
- ModelAction * rf = act->get_reads_from();
- write_actions.add(rf);
- } else if (act->is_write()) {
- write_actions.add(act);
- }
-
- // Revert back action types
- if (act->is_read()) {
- ModelAction * rf = act->get_reads_from();
- if (rf->get_swap_flag() == true)
- rf->use_original_type();
- }
-
- if (act->get_swap_flag() == true)
- act->use_original_type();
-
- // Free read actions
- if (act->is_read()) {
- if (act->is_rmw()) {
- // Do nothing. Its reads_from can not be READY_FREE
- } else {
- ModelAction *rf = act->get_reads_from();
- if (rf->is_free()) {
- model_print("delete read %d; %p\n", act->get_seq_number(), act);
- delete act;
- }
- }
+ if (act->is_read()) {
+
+ /* 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);
}
}
- // Free write actions if possible
- HSIterator<ModelAction *, uintptr_t, 2> * it = write_actions.iterator();
- while (it->hasNext()) {
- ModelAction * act = it->next();
-
- if (act->is_free() && act->get_func_ref_count() == 0)
- delete act;
- }
- delete it;
+// 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)
{
#define MAX_DIST 10
typedef ModelList<FuncInst *> func_inst_list_mt;
+typedef HashTable<void *, ModelAction *, uintptr_t, 0, model_malloc, model_calloc, model_free> loc_act_map_t;
+typedef HashTable<FuncInst *, uint32_t, uintptr_t, 0, model_malloc, model_calloc, model_free> inst_id_map_t;
+typedef HashTable<FuncInst *, Predicate *, uintptr_t, 0, model_malloc, model_calloc, model_free> inst_pred_map_t;
+
typedef enum edge_type {
IN_EDGE, OUT_EDGE, BI_EDGE
} edge_type_t;
func_inst_list_mt * get_entry_insts() { return &entry_insts; }
void add_entry_inst(FuncInst * inst);
- void update_tree(action_list_t * act_list);
+ void function_entry_handler(thread_id_t tid);
+ void function_exit_handler(thread_id_t tid);
+
+ void update_tree(ModelAction * act);
void update_inst_tree(func_inst_list_t * inst_list);
- void update_predicate_tree(action_list_t * act_list);
+ void update_predicate_tree(ModelAction * act);
bool follow_branch(Predicate ** curr_pred, FuncInst * next_inst, ModelAction * next_act, Predicate ** unset_predicate);
- void incr_exit_count() { exit_count++; }
uint32_t get_exit_count() { return exit_count; }
- SnapList<action_list_t *> * get_action_list_buffer() { return action_list_buffer; }
-
void add_to_val_loc_map(uint64_t val, void * loc);
void add_to_val_loc_map(value_set_t * values, void * loc);
void update_loc_may_equal_map(void * new_loc, loc_set_t * old_locations);
uint32_t exit_count;
uint32_t marker;
-
- void incr_marker() { marker++; }
+ uint32_t inst_counter;
/* Use source line number as the key of hashtable, to check if
* atomic operation with this line number has been added or not
func_inst_list_mt entry_insts;
/* Map a FuncInst to the its predicate when updating predicate trees */
- HashTable<FuncInst *, Predicate *, uintptr_t, 0, model_malloc, model_calloc, model_free> inst_pred_map;
+ SnapVector<inst_pred_map_t *> thrd_inst_pred_map;
/* Number FuncInsts to detect loops when updating predicate trees */
- HashTable<FuncInst *, uint32_t, uintptr_t, 0, model_malloc, model_calloc, model_free> inst_id_map;
+ SnapVector<inst_id_map_t *> thrd_inst_id_map;
/* Delect read actions at the same locations when updating predicate trees */
- HashTable<void *, ModelAction *, uintptr_t, 0, model_malloc, model_calloc, model_free> loc_act_map;
+ SnapVector<loc_act_map_t *> thrd_loc_act_map;
+
+ void init_maps(thread_id_t tid);
+ void reset_maps(thread_id_t tid);
void infer_predicates(FuncInst * next_inst, ModelAction * next_act, SnapVector<struct half_pred_expr *> * half_pred_expressions);
void generate_predicates(Predicate * curr_pred, FuncInst * next_inst, SnapVector<struct half_pred_expr *> * half_pred_expressions);
bool amend_predicate_expr(Predicate * curr_pred, FuncInst * next_inst, ModelAction * next_act);
- /* Store action_lists when calls to update_tree are deferred */
- SnapList<action_list_t *> * action_list_buffer;
-
/* Set of locations read by this FuncNode */
loc_set_t * read_locations;
resize_func_nodes( func_id + 1 );
FuncNode * func_node = func_nodes[func_id];
- func_node->init_predicate_tree_position(tid);
- func_node->init_inst_act_map(tid);
+ func_node->function_entry_handler(tid);
/* Add edges between FuncNodes */
if (last_entered_func_id != 0) {
if (last_func_id == func_id) {
FuncNode * func_node = func_nodes[func_id];
- func_node->set_predicate_tree_position(tid, NULL);
- func_node->reset_inst_act_map(tid);
-
- action_list_t * curr_act_list = func_act_lists->back();
-
- /* defer the processing of curr_act_list until the function has exits a few times
- * (currently twice) so that more information can be gathered to infer nullity predicates.
- */
- func_node->incr_exit_count();
- if (func_node->get_exit_count() >= 2) {
- SnapList<action_list_t *> * action_list_buffer = func_node->get_action_list_buffer();
- while (action_list_buffer->size() > 0) {
- action_list_t * act_list = action_list_buffer->back();
- action_list_buffer->pop_back();
- func_node->update_tree(act_list);
- }
-
- func_node->update_tree(curr_act_list);
- } else
- func_node->get_action_list_buffer()->push_front(curr_act_list);
+ func_node->function_exit_handler(tid);
(*thrd_func_list)[id].pop_back();
func_act_lists->pop_back();
/* Add to curr_inst_list */
curr_act_list->push_back(act);
- // Increment ref count for every action and reads_froms
- act->incr_func_ref_count();
- if (act->is_read()) {
- ModelAction * rf = act->get_reads_from();
- rf->incr_func_ref_count();
- }
-
FuncNode * func_node = func_nodes[func_id];
func_node->add_inst(act);
if (act->is_read()) {
func_node->update_inst_act_map(tid, act);
- Fuzzer * fuzzer = model->get_execution()->getFuzzer();
- Predicate * selected_branch = ((NewFuzzer *)fuzzer)->get_selected_child_branch(tid);
- func_node->set_predicate_tree_position(tid, selected_branch);
+// Fuzzer * fuzzer = model->get_execution()->getFuzzer();
+// Predicate * selected_branch = ((NewFuzzer *)fuzzer)->get_selected_child_branch(tid);
+// func_node->set_predicate_tree_position(tid, selected_branch);
}
-
+/*
if (act->is_write()) {
Predicate * curr_pred = func_node->get_predicate_tree_position(tid);
FuncInst * curr_inst = func_node->get_inst(act);
}
func_node->set_predicate_tree_position(tid, curr_pred);
}
+*/
+
+ func_node->update_tree(act);
}
/* Return the FuncNode given its func_id */
func_node->print_predicate_tree();
/*
- func_inst_list_mt * entry_insts = func_node->get_entry_insts();
- model_print("function %s has entry actions\n", func_node->get_func_name());
-
- mllnode<FuncInst*>* it;
- for (it = entry_insts->begin();it != NULL;it=it->getNext()) {
- FuncInst *inst = it->getVal();
- model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position());
- }
- */
+ func_inst_list_mt * entry_insts = func_node->get_entry_insts();
+ model_print("function %s has entry actions\n", func_node->get_func_name());
+
+ mllnode<FuncInst*>* it;
+ for (it = entry_insts->begin();it != NULL;it=it->getNext()) {
+ FuncInst *inst = it->getVal();
+ model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position());
+ }
+*/
}
}