initialize the newly added element in the vector when resizing func_nodes
authorweiyu <weiyuluo1232@gmail.com>
Tue, 23 Jul 2019 02:45:31 +0000 (19:45 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Tue, 23 Jul 2019 02:45:31 +0000 (19:45 -0700)
funcnode.cc
history.cc
history.h

index 27a9abd74b8bd653fdb7e97d3aa562683efac8ac..8e76ebc674bf8e6d7339b45768b6a8b87c0a961d 100644 (file)
@@ -159,7 +159,9 @@ uint64_t FuncNode::query_last_read(ModelAction * act, uint32_t tid)
  */
 void FuncNode::clear_read_map(uint32_t tid)
 {
-       ASSERT(thrd_read_map.size() > tid);
+       if (thrd_read_map.size() <= tid)
+               return;
+
        thrd_read_map[tid]->reset();
 }
 
index 6b263ad2df01afec5a1e47862d384679e50c442f..cb2df7a4659185bd1313db26004b91497477ebe2 100644 (file)
@@ -76,6 +76,22 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid)
        //model_print("thread %d exiting func %d\n", tid, func_id);
 }
 
+void ModelHistory::resize_func_nodes(uint32_t new_size)
+{
+       uint32_t old_size = func_nodes.size();
+
+       if ( old_size < new_size )
+               func_nodes.resize(new_size);
+
+       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);
+               func_node->set_func_name(func_name);
+               func_nodes[id] = func_node;
+       }
+}
+
 void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
 {
        /* return if thread i has not entered any function or has exited
@@ -97,17 +113,10 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
        uint32_t func_id = func_list->back();
 
        if ( func_nodes.size() <= func_id )
-               func_nodes.resize( func_id + 1 );
+               resize_func_nodes( func_id + 1 );
 
        FuncNode * func_node = func_nodes[func_id];
-       if (func_node == NULL) {
-               const char * func_name = func_map_rev[func_id];
-               func_node = new FuncNode();
-               func_node->set_func_id(func_id);
-               func_node->set_func_name(func_name);
-
-               func_nodes[func_id] = func_node;
-       }
+       ASSERT (func_node != NULL);
 
        /* add corresponding FuncInst to func_node */
        FuncInst * inst = func_node->get_or_add_action(act);
index d6d090baa741e83cb1d9fe0f49580c70ac7fc1b9..0984e03ae129e4efc58fc517b8281bdf58ad9fff 100644 (file)
--- a/history.h
+++ b/history.h
@@ -14,6 +14,7 @@ public:
        uint32_t get_func_counter() { return func_counter; }
        void incr_func_counter() { func_counter++; }
 
+       void resize_func_nodes(uint32_t max_func_id);
        void process_action(ModelAction *act, thread_id_t tid);
 
        HashTable<const char *, uint32_t, uintptr_t, 4, model_malloc, model_calloc, model_free> * getFuncMap() { return &func_map; }