diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 42c3412f56dfc5531219a755e318f97a372ba615..8fbb0ee1934a282fd06465a09712a785718fe337 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index ce73d9ba0a6443b28a3d53d4535155339a6dd2de..65e789cabf2f2cb194ca9e9cbcee733a6ea4350b 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 6c8c5359f60aeb376f586b45863caa57df8befb1..2b4054555a9da5b61a36ffb3342da81b7080ac5a 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/BUILD.gn b/src/maple_driver/BUILD.gn index f2f230e4d4458e2534b33437108ed7a8b4a2ebc1..57fe6029dcbb58e27c564d859148d511a7619ce2 100644 --- a/src/maple_driver/BUILD.gn +++ b/src/maple_driver/BUILD.gn @@ -55,12 +55,11 @@ executable("maple") { "src/mplcg_compiler.cpp", ] - include_dirs = include_directories deps = [ - ":liboption_parser", ":libdriver_option", + ":liboption_parser", "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", "${MAPLEALL_ROOT}/maple_be:libcg", "${MAPLEALL_ROOT}/maple_be:libmplad", @@ -84,9 +83,7 @@ static_library("libdriver_option") { "src/driver_option_common.cpp", ] - include_dirs = [ - "${MAPLEALL_ROOT}/maple_driver/include", - ] + include_dirs = [ "${MAPLEALL_ROOT}/maple_driver/include" ] output_dir = "${root_out_dir}/lib/${HOST_ARCH}" } diff --git a/src/maple_driver/include/file_utils.h b/src/maple_driver/include/file_utils.h index 47a6cb2e85bd6b31328acf88e1a8266a9e4185fe..216f4f7135e11f75feb29602a3c13b10104f3b42 100644 --- a/src/maple_driver/include/file_utils.h +++ b/src/maple_driver/include/file_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -24,6 +24,7 @@ constexpr char kMapleRoot[] = "MAPLE_ROOT"; class FileUtils { public: + static std::string GetRealPath(const std::string &filePath); static std::string GetFileName(const std::string &filePath, bool isWithExtension); static std::string GetFileExtension(const std::string &filePath); static std::string GetFileFolder(const std::string &filePath); diff --git a/src/maple_driver/src/driver_runner.cpp b/src/maple_driver/src/driver_runner.cpp index 402a49c961f2f55ed74eb959fb5e59e4abb24172..c323067d0d10eae35a12b61c8c709141f750b15e 100644 --- a/src/maple_driver/src/driver_runner.cpp +++ b/src/maple_driver/src/driver_runner.cpp @@ -420,6 +420,7 @@ void DriverRunner::EmitDuplicatedAsmFunc(const CG &cg) const { std::ifstream duplicateAsmFileFD(cgOptions->GetDuplicateAsmFile()); if (!duplicateAsmFileFD.is_open()) { + duplicateAsmFileFD.close(); ERR(kLncErr, " %s open failed!", cgOptions->GetDuplicateAsmFile().c_str()); return; } @@ -442,6 +443,7 @@ void DriverRunner::EmitDuplicatedAsmFunc(const CG &cg) const { cg.GetEmitter()->Emit(contend + "\n"); } + duplicateAsmFileFD.close(); } diff --git a/src/maple_driver/src/file_utils.cpp b/src/maple_driver/src/file_utils.cpp index b30a48b2e02fdc3273886eb291b51078700ea936..a1bb625c75780be6b190226045ee9f0484350301 100644 --- a/src/maple_driver/src/file_utils.cpp +++ b/src/maple_driver/src/file_utils.cpp @@ -12,9 +12,16 @@ * FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v1 for more details. */ -#include "file_utils.h" #include +#include +#include +#include "file_utils.h" #include "string_utils.h" +#include "mpl_logging.h" + +#ifdef _WIN32 +#include +#endif namespace { const char kFileSeperatorLinuxStyleChar = '/'; @@ -28,6 +35,22 @@ const char kFileSeperatorChar = kFileSeperatorLinuxStyleChar; const std::string kFileSeperatorStr = kFileSeperatorLinuxStyleStr; +std::string FileUtils::GetRealPath(const std::string &filePath) { +#ifdef _WIN32 + char *path; + if (filePath.size() > PATH_MAX || !PathCanonicalize(path, filePath.c_str())) { + CHECK_FATAL(false, "invalid file path"); + } +#else + char path[PATH_MAX] = {0}; + if (filePath.size() > PATH_MAX || realpath(filePath.c_str(), path) == nullptr) { + CHECK_FATAL(false, "invalid file path"); + } +#endif + std::string result(path, path + strlen(path)); + return result; +} + std::string FileUtils::GetFileName(const std::string &filePath, bool isWithExtension) { std::string fullFileName = StringUtils::GetStrAfterLast(filePath, kFileSeperatorStr); #ifdef _WIN32 diff --git a/src/maple_driver/src/maple_comb_compiler.cpp b/src/maple_driver/src/maple_comb_compiler.cpp index a7fbeaf0f573b0c9dd5193b869dfd4146964319a..002bca9e0ed065ac84e065c08e34df115d673f9b 100644 --- a/src/maple_driver/src/maple_comb_compiler.cpp +++ b/src/maple_driver/src/maple_comb_compiler.cpp @@ -54,6 +54,7 @@ void MapleCombCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::v } else { ++iter; } + infile.close(); } } diff --git a/src/maple_driver/src/mpl_options.cpp b/src/maple_driver/src/mpl_options.cpp index 42f394e5f46f649e04834e4c9d0be3fbed3633e2..61b02ffae015a5ecf2c31b9df63f376428b9e319 100644 --- a/src/maple_driver/src/mpl_options.cpp +++ b/src/maple_driver/src/mpl_options.cpp @@ -283,8 +283,10 @@ ErrorCode MplOptions::CheckFileExits() { if (infile.fail()) { LogInfo::MapleLogger(kLlErr) << "Cannot open input file " << fileName << '\n'; ret = kErrorFileNotFound; + infile.close(); return ret; } + infile.close(); } return ret; } diff --git a/src/maple_ir/BUILD.gn b/src/maple_ir/BUILD.gn index c4c1e52bb4cb0c37835dc5cb9cb9bc8f7956c878..a002c51d80283c55bee79c2469a0d8930fc8db72 100644 --- a/src/maple_ir/BUILD.gn +++ b/src/maple_ir/BUILD.gn @@ -60,8 +60,8 @@ static_library("libmplir") { libs = [] libs += [ "${OPENSOURCE_DEPS}/libmplutil.a" ] deps = [ - "${MAPLEALL_ROOT}/maple_driver:liboption_parser", "${MAPLEALL_ROOT}/maple_driver:libdriver_option", + "${MAPLEALL_ROOT}/maple_driver:liboption_parser", ] } diff --git a/src/maple_ir/src/mir_module.cpp b/src/maple_ir/src/mir_module.cpp index 8ae10a7b4af298efa068e84c08d188ddf6fce3a7..5651a5ca4e1e90a3d4d25770580091a67f1f9311 100644 --- a/src/maple_ir/src/mir_module.cpp +++ b/src/maple_ir/src/mir_module.cpp @@ -299,6 +299,7 @@ void MIRModule::Emit(const std::string &outFileName) const { } // Restore cout's buffer. LogInfo::MapleLogger().rdbuf(backup); + file.close(); } void MIRModule::DumpFunctionList(bool skipBody) const { @@ -328,6 +329,7 @@ void MIRModule::OutputFunctionListAsciiMpl(const std::string &phaseName) { DumpGlobalArraySymbol(); DumpFunctionList(); LogInfo::MapleLogger().rdbuf(backup); // restore cout's buffer + mplFile.close(); } void MIRModule::DumpToFile(const std::string &fileNameStr, bool emitStructureType) const { @@ -343,6 +345,7 @@ void MIRModule::DumpToFile(const std::string &fileNameStr, bool emitStructureTyp Dump(emitStructureType); // Restore cout's buffer. LogInfo::MapleLogger().rdbuf(backup); + file.close(); } void MIRModule::DumpInlineCandidateToFile(const std::string &fileNameStr) const { @@ -360,6 +363,7 @@ void MIRModule::DumpInlineCandidateToFile(const std::string &fileNameStr) const } // Restore cout's buffer. LogInfo::MapleLogger().rdbuf(backup); + file.close(); } // This is not efficient. Only used in debug mode for now. @@ -411,6 +415,7 @@ void MIRModule::DumpToHeaderFile(bool binaryMplt, const std::string &outputName) } /* restore cout */ LogInfo::MapleLogger().rdbuf(backup); + mpltFile.close(); } } @@ -440,6 +445,7 @@ void MIRModule::DumpClassToFile(const std::string &path) const { LogInfo::MapleLogger() << '\n'; /* restore cout */ LogInfo::MapleLogger().rdbuf(backup); + mplFile.close();; } } @@ -476,6 +482,7 @@ void MIRModule::OutputAsciiMpl(const std::string &phaseName, bool emitStructureT LogInfo::MapleLogger().rdbuf(mplFile.rdbuf()); // change cout's buffer to that of file Dump(emitStructureType); LogInfo::MapleLogger().rdbuf(backup); // restore cout's buffer + mplFile.close(); } uint32 MIRModule::GetFileinfo(GStrIdx strIdx) const { diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index 329c6b4145ae56fc7e869d3dc9f85bc1cd718446..b9f001fc6ad20587eda5f0c2fbadd7feff364458 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -2642,6 +2642,7 @@ bool MIRParser::ParseMIRForImport() { FATAL(kLncFatal, "cannot open MPLT file: %s\n", importFileName.c_str()); } bool failedParse = !ParseMPLT(mpltFile, importFileName); + mpltFile.close(); if (failedParse) { // parse the mplt file return false; } @@ -2655,6 +2656,7 @@ bool MIRParser::ParseMIRForImport() { FATAL(kLncFatal, "cannot open MPLT file: %s\n", importFileName.c_str()); } bool failedParse = !ParseMPLT(mpltFile, importFileName); + mpltFile.close(); if (failedParse) { // parse the mplt file return false; } diff --git a/src/maple_me/include/me_profile_use.h b/src/maple_me/include/me_profile_use.h index 16acb8e0dea510fcc38aa7d688c00340c8fa2b29..23e4c0360492e21993fc493aeb1a01e125215257 100644 --- a/src/maple_me/include/me_profile_use.h +++ b/src/maple_me/include/me_profile_use.h @@ -45,7 +45,7 @@ class BBUseEdge : public BBEdge { class BBUseInfo { public: - BBUseInfo() {} + BBUseInfo(MemPool &tmpPool) : tmpAlloc(&tmpPool), inEdges(tmpAlloc.Adapter()), outEdges(tmpAlloc.Adapter()) {} void SetCount(uint64 value) { countValue = value; @@ -73,11 +73,11 @@ class BBUseInfo { } } - const std::vector &GetInEdges() const { + const MapleVector &GetInEdges() const { return inEdges; } - std::vector &GetInEdges() { + MapleVector &GetInEdges() { return inEdges; } @@ -85,11 +85,11 @@ class BBUseInfo { return inEdges.size(); } - const std::vector &GetOutEdges() const { + const MapleVector &GetOutEdges() const { return outEdges; } - std::vector &GetOutEdges() { + MapleVector &GetOutEdges() { return outEdges; } @@ -118,8 +118,9 @@ class BBUseInfo { uint64 countValue = 0; uint32 unknownInEdges = 0; uint32 unknownOutEdges = 0; - std::vector inEdges; - std::vector outEdges; + MapleAllocator tmpAlloc; + MapleVector inEdges; + MapleVector outEdges; }; class MeProfUse : public PGOInstrument { @@ -135,11 +136,11 @@ class MeProfUse : public PGOInstrument { private: bool IsAllZero(Profile::BBInfo &result) const; void SetEdgeCount(BBUseEdge &edge, uint32 value); - void SetEdgeCount(std::vector &edges, uint64 value); + void SetEdgeCount(MapleVector &edges, uint64 value); void ComputeEdgeFreq(); void InitBBEdgeInfo(); void ComputeBBFreq(BBUseInfo &bbInfo, bool &changed); - uint64 SumEdgesCount(const std::vector &edges) const; + uint64 SumEdgesCount(const MapleVector &edges) const; BBUseInfo *GetBBUseInfo(const BB &bb) const; BBUseInfo *GetOrCreateBBUseInfo(const BB &bb) ; MeFunction *func; diff --git a/src/maple_me/src/me_bb_layout.cpp b/src/maple_me/src/me_bb_layout.cpp index 0fe4042962db3b6d3773a52acd8c7a469b83d79e..7d0a8b2627d2ca802131c75af45ead3182859e08 100644 --- a/src/maple_me/src/me_bb_layout.cpp +++ b/src/maple_me/src/me_bb_layout.cpp @@ -460,7 +460,7 @@ void BBLayout::DealWithStartTryBB() { continue; } auto curBB = func.GetBBFromID(BBId(i)); - for (size_t j = i + 1; !startTryBBVec[j] && j < size; ++j) { + for (size_t j = i + 1; j < size && !startTryBBVec[j]; ++j) { auto nextBB = func.GetBBFromID(BBId(j)); if (nextBB != nullptr) { if (nextBB->GetAttributes(kBBAttrIsTry)) { diff --git a/src/maple_me/src/me_profile_use.cpp b/src/maple_me/src/me_profile_use.cpp index ab84d409ec4d42ca11a3b3181822b8ef02c28271..1e7e4832eb08259d816fa5d3cf07ccef4ec2583e 100644 --- a/src/maple_me/src/me_profile_use.cpp +++ b/src/maple_me/src/me_profile_use.cpp @@ -24,7 +24,7 @@ BBUseInfo *MeProfUse::GetOrCreateBBUseInfo(const BB &bb) { if (item != bbProfileInfo.end()) { return item->second; } else { - BBUseInfo *useInfo = mp->New(); + BBUseInfo *useInfo = mp->New(*mp); bbProfileInfo.insert(std::make_pair(&bb, useInfo)); return useInfo; } @@ -36,7 +36,7 @@ BBUseInfo *MeProfUse::GetBBUseInfo(const BB &bb) const { return item->second; } -uint64 MeProfUse::SumEdgesCount(const std::vector &edges) const { +uint64 MeProfUse::SumEdgesCount(const MapleVector &edges) const { uint64 count = 0; for (const auto &e : edges) { count += e->GetCount(); @@ -146,7 +146,7 @@ void MeProfUse::ComputeEdgeFreq() { * this used to set the edge count for the unknown edge * ensure only one unkown edge in the edges */ -void MeProfUse::SetEdgeCount(std::vector &edges, uint64 value) { +void MeProfUse::SetEdgeCount(MapleVector &edges, uint64 value) { for (const auto &e : edges) { if (!e->GetStatus()) { e->SetCount(value); diff --git a/src/maple_util/src/profile.cpp b/src/maple_util/src/profile.cpp index 100c3beb883aad8a5847899eec16c89d4c4fe368..50a933721eb9b0d2bf1f6ef72038d3f708851510 100644 --- a/src/maple_util/src/profile.cpp +++ b/src/maple_util/src/profile.cpp @@ -257,12 +257,14 @@ bool Profile::DeCompress(const std::string &path, const std::string &dexNameInne LogInfo::MapleLogger() << "WARN: DeCompress(" << "), failed to read all data for " << path << ", " << strerror(errno) << '\n';; res = false; + in.close(); return res; } if (byteCount < sizeof(Header)) { LogInfo::MapleLogger() << "WARN: DeCompress(" << "), failed, read no data for " << path << ", " << strerror(errno) << '\n';; res = false; + in.close(); return res; } Header *header = reinterpret_cast(buf); @@ -271,6 +273,7 @@ bool Profile::DeCompress(const std::string &path, const std::string &dexNameInne LogInfo::MapleLogger() << "invalid maigc number " << header->magic << '\n';; } res = false; + in.close(); return res; } this->isAppProfile = (header->profileFileType == kApp) ? true : false; @@ -353,6 +356,7 @@ bool Profile::DeCompress(const std::string &path, const std::string &dexNameInne } LogInfo::MapleLogger() << "SUCC parse " << path << '\n';; valid = true; + in.close(); return res; } @@ -499,38 +503,39 @@ void Profile::DumpFuncIRProfUseInfo() const { } void Profile::Dump() const { - std::ofstream outfile; - outfile.open("prof.dump"); - outfile << "classMeta profile start " <<'\n';; + std::ofstream outFile; + outFile.open("prof.dump"); + outFile << "classMeta profile start " <<'\n';; for (const auto &item : classMeta) { - outfile << item << '\n';; + outFile << item << '\n';; } - outfile << "fieldMeta profile start " <<'\n';; + outFile << "fieldMeta profile start " <<'\n';; for (const auto &item : fieldMeta) { - outfile << item << '\n';; + outFile << item << '\n';; } - outfile << "methodMeta profile start " <<'\n';; + outFile << "methodMeta profile start " <<'\n';; for (const auto &item : methodMeta) { - outfile << item << '\n';; + outFile << item << '\n';; } - outfile << "literal profile start " <<'\n';; + outFile << "literal profile start " <<'\n';; for (const auto &item : literal) { - outfile << item << '\n';; + outFile << item << '\n';; } - outfile << "func profile start " <<'\n';; + outFile << "func profile start " <<'\n';; for (const auto &item : funcProfData) { - outfile << item.first << " " + outFile << item.first << " " << static_cast((item.second).type) << " " << (item.second).callTimes << '\n';; } - outfile << "reflectStr profile start " <<'\n';; + outFile << "reflectStr profile start " <<'\n';; for (const auto &item : reflectionStrData) { - outfile << item.first << " " << static_cast(item.second) << '\n';; + outFile << item.first << " " << static_cast(item.second) << '\n';; } + outFile.close(); } } // namespace maple diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index 0ba83a15c10b7cf2532ea23c59dbfc078793775c..b61ce7df80003292ff721392d7d217ce78b5a175 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -95,6 +95,7 @@ void MUIDReplacement::DumpMUIDFile(bool isFunc) { outFile << keyVal.first.ToStr() << "\n"; } } + outFile.close(); } void MUIDReplacement::CollectFuncAndDataFromKlasses() {