Skip to content

Commit

Permalink
Merge pull request eclipse-omr#4517 from mikezhang1234567890/ddrgen-perf
Browse files Browse the repository at this point in the history
Change Dwarf_CU_Context files list from vector to map
  • Loading branch information
rwy7 authored Dec 11, 2019
2 parents b3fe6aa + 4b9df41 commit 4e318da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ddr/include/ddr/scanner/dwarf/DwarfFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct Dwarf_CU_Context
Dwarf_Unsigned _nextCUheaderOffset;
Dwarf_CU_Context *_nextCU;

static vector<string> _fileList;
static unordered_map<string, size_t> _fileId; /* key: file name, value: order added indexed at 0 */
static Dwarf_CU_Context *_firstCU;
static Dwarf_CU_Context *_currentCU;
};
Expand Down
21 changes: 9 additions & 12 deletions ddr/lib/ddr-scanner/dwarf/AixSymbolTableParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
/* Statics. */
static die_map createdDies;
static die_map builtInDies;
static std::set<string> filesAdded;
/* This vector contains the typeID of the nested class and parent class for populating nested classes. */
static vector<pair<int, Dwarf_Die> > nestedClassesToPopulate;
/* This vector contains the typeID of the type reference and type attribute to populate. */
Expand Down Expand Up @@ -93,7 +92,7 @@ dwarf_finish(Dwarf_Debug dbg, Dwarf_Error *error)
}

_lastDie = NULL;
Dwarf_CU_Context::_fileList.clear();
Dwarf_CU_Context::_fileId.clear();
Dwarf_CU_Context::_currentCU = NULL;
Dwarf_CU_Context::_firstCU = NULL;
Dwarf_Die_s::refMap.clear();
Expand Down Expand Up @@ -880,11 +879,9 @@ parseSymbolTable(const char *line, Dwarf_Error *error)
fileName = strip(data.substr(index + fileNameIndex), '\n');

/* Verify that the file has not been parsed through before. */
if (filesAdded.end() == filesAdded.find(fileName)) {
if (Dwarf_CU_Context::_fileId.end() == Dwarf_CU_Context::_fileId.find(fileName)) {
/* Add the file to the list of files */
Dwarf_CU_Context::_fileList.push_back(fileName);

filesAdded.insert(fileName);
Dwarf_CU_Context::_fileId.insert(make_pair(fileName, Dwarf_CU_Context::_fileId.size()));

/* Create one compilation unit context per file. */
Dwarf_CU_Context *newCU = new Dwarf_CU_Context;
Expand Down Expand Up @@ -920,7 +917,7 @@ parseSymbolTable(const char *line, Dwarf_Error *error)
name->_form = DW_FORM_string;
name->_sdata = 0;
name->_udata = 0;
name->_stringdata = strdup(Dwarf_CU_Context::_fileList.back().c_str());
name->_stringdata = strdup(fileName.c_str());
name->_refdata = 0;
name->_ref = NULL;

Expand Down Expand Up @@ -1201,7 +1198,7 @@ parseField(const string & data, Dwarf_Die currentDie, Dwarf_Error *error)
declFile->_nextAttr = offset;
declFile->_sdata = 0;
/* The declaration file number starts at 1. */
declFile->_udata = Dwarf_CU_Context::_fileList.size();
declFile->_udata = Dwarf_CU_Context::_fileId.size();
declFile->_refdata = 0;
declFile->_ref = NULL;

Expand Down Expand Up @@ -1539,9 +1536,9 @@ parseTypeDef(const string & data,
declFile->_sdata = 0;
declFile->_refdata = 0;
declFile->_ref = NULL;
if (!Dwarf_CU_Context::_fileList.empty()) {
if (!Dwarf_CU_Context::_fileId.empty()) {
/* The declaration file number starts at 1. */
declFile->_udata = Dwarf_CU_Context::_fileList.size();
declFile->_udata = Dwarf_CU_Context::_fileId.size();
} else {
/* If there is no declaring file then delete the attributes for the declFile and declLine. */
name->_nextAttr = NULL;
Expand Down Expand Up @@ -1889,7 +1886,7 @@ setDieAttributes(const string & dieName,
break;
case DW_AT_decl_file:
/* The declaration file number starts at 1. */
tmp->_udata = Dwarf_CU_Context::_fileList.size();
tmp->_udata = Dwarf_CU_Context::_fileId.size();
break;
}
tmp = tmp->_nextAttr;
Expand Down Expand Up @@ -1927,7 +1924,7 @@ setDieAttributes(const string & dieName,
declFile->_form = DW_FORM_udata;
declFile->_sdata = 0;
/* The declaration file number starts at 1. */
declFile->_udata = Dwarf_CU_Context::_fileList.size();
declFile->_udata = Dwarf_CU_Context::_fileId.size();
declFile->_refdata = 0;
declFile->_ref = NULL;

Expand Down
12 changes: 5 additions & 7 deletions ddr/lib/ddr-scanner/dwarf/DwarfFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static const char * const _errmsgs[] = {
"DW_DLE_VMM (9) dwarf format/library version mismatch",
};

vector<string> Dwarf_CU_Context::_fileList;
unordered_map<string, size_t> Dwarf_CU_Context::_fileId;
unordered_map<Dwarf_Off, Dwarf_Die> Dwarf_Die_s::refMap;

int
Expand All @@ -53,21 +53,19 @@ dwarf_srcfiles(Dwarf_Die die, char ***srcfiles, Dwarf_Signed *filecount, Dwarf_E
* This implementation maintains the entire list through
* all CU's, rather than just the current CU, for simplicity.
*/
*filecount = Dwarf_CU_Context::_fileList.size();
*filecount = Dwarf_CU_Context::_fileId.size();
*srcfiles = new char *[*filecount];
if (NULL == *srcfiles) {
ret = DW_DLV_ERROR;
setError(error, DW_DLE_MAF);
} else {
size_t index = 0;
for (str_vect::iterator it = Dwarf_CU_Context::_fileList.begin(); it != Dwarf_CU_Context::_fileList.end(); ++it) {
(*srcfiles)[index] = strdup(it->c_str());
if (NULL == (*srcfiles)[index]) {
for (unordered_map<string, size_t>::const_iterator it = Dwarf_CU_Context::_fileId.begin(); it != Dwarf_CU_Context::_fileId.end(); ++it) {
(*srcfiles)[it->second] = strdup(it->first.c_str());
if (NULL == (*srcfiles)[it->second]) {
ret = DW_DLV_ERROR;
setError(error, DW_DLE_MAF);
break;
}
index += 1;
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions ddr/lib/ddr-scanner/dwarf/DwarfParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dwarf_finish(Dwarf_Debug dbg, Dwarf_Error *error)
delete Dwarf_CU_Context::_currentCU;
Dwarf_CU_Context::_currentCU = nextCU;
}
Dwarf_CU_Context::_fileList.clear();
Dwarf_CU_Context::_fileId.clear();
Dwarf_CU_Context::_currentCU = NULL;
Dwarf_CU_Context::_firstCU = NULL;
return DW_DLV_OK;
Expand Down Expand Up @@ -465,8 +465,12 @@ parseAttribute(char *line, Dwarf_Die *lastCreatedDie,
setError(error, DW_DLE_MAF);
newAttr->_udata = 0;
} else if (DW_TAG_unknown != (*lastCreatedDie)->_tag) {
Dwarf_CU_Context::_fileList.push_back(string(newAttr->_stringdata));
newAttr->_udata = Dwarf_CU_Context::_fileList.size();
string fileName = string(newAttr->_stringdata);
unordered_map<string, size_t>::const_iterator insertIt = Dwarf_CU_Context::_fileId.insert(make_pair(fileName, Dwarf_CU_Context::_fileId.size())).first;
/* whether the insert succeeded or not due to duplicates, the pair at the iterator will have the right index value */
newAttr->_udata = insertIt->second + 1; /* since this attribute is indexed at 1 */


}
} else if (DW_FORM_string == form) {
char *valueStart = line + span + 3;
Expand Down

0 comments on commit 4e318da

Please sign in to comment.