From 68690971b2a9fc95250480fb3dd4752b2f936791 Mon Sep 17 00:00:00 2001 From: weiyu Date: Mon, 22 Jul 2019 19:45:31 -0700 Subject: [PATCH] initialize the newly added element in the vector when resizing func_nodes --- funcnode.cc | 4 +++- history.cc | 27 ++++++++++++++++++--------- history.h | 1 + 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/funcnode.cc b/funcnode.cc index 27a9abd7..8e76ebc6 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -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(); } diff --git a/history.cc b/history.cc index 6b263ad2..cb2df7a4 100644 --- a/history.cc +++ b/history.cc @@ -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); diff --git a/history.h b/history.h index d6d090ba..0984e03a 100644 --- 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 * getFuncMap() { return &func_map; } -- 2.34.1