From a7363b329b98ad2a54ef40a078b345051f976b9a Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Fri, 13 Oct 2017 12:26:45 +0200 Subject: [PATCH] logic: Use sizeof(SharedMemory::String) in shared memory size estimation instead of std::string (issue #471) --- src/lib/data/indexer/IndexerCommand.cpp | 8 ++++---- src/lib/data/indexer/IndexerCommand.h | 2 +- .../InterprocessIndexerCommandManager.cpp | 4 ++-- .../InterprocessIndexingStatusManager.cpp | 6 +++--- .../InterprocessIntermediateStorageManager.cpp | 5 +++-- src/lib/data/storage/IntermediateStorage.cpp | 16 ++++++++-------- src/lib/data/storage/IntermediateStorage.h | 2 +- src/lib_cxx/data/indexer/IndexerCommandCxx.cpp | 10 +++++----- src/lib_cxx/data/indexer/IndexerCommandCxx.h | 2 +- .../data/indexer/IndexerCommandCxxCdb.cpp | 4 ++-- src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h | 2 +- .../data/indexer/IndexerCommandCxxManual.cpp | 4 ++-- .../data/indexer/IndexerCommandCxxManual.h | 2 +- src/lib_java/data/indexer/IndexerCommandJava.cpp | 6 +++--- src/lib_java/data/indexer/IndexerCommandJava.h | 2 +- 15 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/lib/data/indexer/IndexerCommand.cpp b/src/lib/data/indexer/IndexerCommand.cpp index 9d9b81ea..f19c096c 100644 --- a/src/lib/data/indexer/IndexerCommand.cpp +++ b/src/lib/data/indexer/IndexerCommand.cpp @@ -13,18 +13,18 @@ IndexerCommand::~IndexerCommand() { } -size_t IndexerCommand::getByteSize() const +size_t IndexerCommand::getByteSize(size_t stringSize) const { - size_t size = sizeof(std::string) + m_sourceFilePath.str().size(); + size_t size = m_sourceFilePath.str().size(); for (const FilePath& path: m_indexedPaths) { - size += sizeof(std::string) + path.str().size(); + size += stringSize + path.str().size(); } for (const FilePath& path : m_excludedPaths) { - size += sizeof(std::string) + path.str().size(); + size += stringSize + path.str().size(); } return size; diff --git a/src/lib/data/indexer/IndexerCommand.h b/src/lib/data/indexer/IndexerCommand.h index edba398b..e083c87f 100644 --- a/src/lib/data/indexer/IndexerCommand.h +++ b/src/lib/data/indexer/IndexerCommand.h @@ -15,7 +15,7 @@ public: virtual IndexerCommandType getIndexerCommandType() const = 0; - virtual size_t getByteSize() const; + virtual size_t getByteSize(size_t stringSize) const; const FilePath& getSourceFilePath() const; const std::set& getIndexedPaths() const; diff --git a/src/lib/data/indexer/interprocess/InterprocessIndexerCommandManager.cpp b/src/lib/data/indexer/interprocess/InterprocessIndexerCommandManager.cpp index aa38755b..a2ec683f 100644 --- a/src/lib/data/indexer/interprocess/InterprocessIndexerCommandManager.cpp +++ b/src/lib/data/indexer/interprocess/InterprocessIndexerCommandManager.cpp @@ -19,12 +19,12 @@ InterprocessIndexerCommandManager::~InterprocessIndexerCommandManager() void InterprocessIndexerCommandManager::setIndexerCommands( const std::vector>& indexerCommands) { - const unsigned int overestimationMultiplier = 3; + const size_t overestimationMultiplier = 2; size_t estimatedSize = 1048576; /* 1 MB */ for (auto& command : indexerCommands) { - estimatedSize += command->getByteSize() + sizeof(SharedIndexerCommand); + estimatedSize += command->getByteSize(sizeof(SharedMemory::String)) + sizeof(SharedIndexerCommand); } estimatedSize *= overestimationMultiplier; diff --git a/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.cpp b/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.cpp index c62917f7..896d332c 100644 --- a/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.cpp +++ b/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.cpp @@ -39,10 +39,10 @@ void InterprocessIndexingStatusManager::startIndexingSourceFile(const FilePath& SharedMemory::Map::iterator it = currentFilesPtr->find(getProcessId()); if (it != currentFilesPtr->end()) { - const int overestimationMultiplier = 3; + const size_t overestimationMultiplier = 3; const std::string crashedFilePath = it->second.c_str(); - size_t estimatedSize = 262144 + sizeof(std::string) + crashedFilePath.size(); + size_t estimatedSize = 262144 + sizeof(SharedMemory::String) + crashedFilePath.size(); estimatedSize *= overestimationMultiplier; while (access.getFreeMemorySize() < estimatedSize) @@ -215,7 +215,7 @@ void InterprocessIndexingStatusManager::addIndexedFiles(std::set fileP size_t estimatedSize = 262144; for (auto& newFile : newFiles) { - estimatedSize += sizeof(std::string) + newFile.size(); + estimatedSize += sizeof(SharedMemory::String) + newFile.size(); } estimatedSize *= overestimationMultiplier; diff --git a/src/lib/data/indexer/interprocess/InterprocessIntermediateStorageManager.cpp b/src/lib/data/indexer/interprocess/InterprocessIntermediateStorageManager.cpp index 359b75bf..b75c83b1 100644 --- a/src/lib/data/indexer/interprocess/InterprocessIntermediateStorageManager.cpp +++ b/src/lib/data/indexer/interprocess/InterprocessIntermediateStorageManager.cpp @@ -27,8 +27,9 @@ InterprocessIntermediateStorageManager::~InterprocessIntermediateStorageManager( void InterprocessIntermediateStorageManager::pushIntermediateStorage( const std::shared_ptr& intermediateStorage) { - const unsigned int overestimationMultiplier = 3; - size_t size = (intermediateStorage->getByteSize() + sizeof(SharedIntermediateStorage)) * overestimationMultiplier + 1048576/* 1 MB */; + const size_t overestimationMultiplier = 2; + size_t size = (intermediateStorage->getByteSize(sizeof(SharedMemory::String)) + + sizeof(SharedIntermediateStorage)) * overestimationMultiplier + 1048576/* 1 MB */; SharedMemory::ScopedAccess access(&m_sharedMemory); diff --git a/src/lib/data/storage/IntermediateStorage.cpp b/src/lib/data/storage/IntermediateStorage.cpp index d73287d5..34d9e6c7 100644 --- a/src/lib/data/storage/IntermediateStorage.cpp +++ b/src/lib/data/storage/IntermediateStorage.cpp @@ -28,35 +28,35 @@ void IntermediateStorage::clear() m_nextId = 1; } -size_t IntermediateStorage::getByteSize() const +size_t IntermediateStorage::getByteSize(size_t stringSize) const { unsigned int byteSize = 0; for (const StorageFile& storageFile: getStorageFiles()) { byteSize += sizeof(StorageFile); - byteSize += storageFile.filePath.size(); - byteSize += storageFile.modificationTime.size(); + byteSize += stringSize + storageFile.filePath.size(); + byteSize += stringSize + storageFile.modificationTime.size(); } for (const StorageError& storageError: getErrors()) { byteSize += sizeof(StorageError); - byteSize += storageError.filePath.str().size(); - byteSize += storageError.message.size(); - byteSize += storageError.commandline.size(); + byteSize += stringSize + storageError.filePath.str().size(); + byteSize += stringSize + storageError.message.size(); + byteSize += stringSize + storageError.commandline.size(); } for (const StorageNode& storageNode: getStorageNodes()) { byteSize += sizeof(StorageNode); - byteSize += storageNode.serializedName.size(); + byteSize += stringSize + storageNode.serializedName.size(); } for (const StorageLocalSymbol& storageLocalSymbol: getStorageLocalSymbols()) { byteSize += sizeof(StorageLocalSymbol); - byteSize += storageLocalSymbol.name.size(); + byteSize += stringSize + storageLocalSymbol.name.size(); } byteSize += sizeof(StorageEdge) * getStorageEdges().size(); diff --git a/src/lib/data/storage/IntermediateStorage.h b/src/lib/data/storage/IntermediateStorage.h index 39b6c609..c25483dc 100644 --- a/src/lib/data/storage/IntermediateStorage.h +++ b/src/lib/data/storage/IntermediateStorage.h @@ -17,7 +17,7 @@ public: void clear(); - size_t getByteSize() const; + size_t getByteSize(size_t stringSize) const; size_t getSourceLocationCount() const; void setAllFilesIncomplete(); diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp index c252dcd2..175cfa22 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp +++ b/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp @@ -21,23 +21,23 @@ IndexerCommandCxx::~IndexerCommandCxx() { } -size_t IndexerCommandCxx::getByteSize() const +size_t IndexerCommandCxx::getByteSize(size_t stringSize) const { - size_t size = IndexerCommand::getByteSize(); + size_t size = IndexerCommand::getByteSize(stringSize); for (auto& i : m_systemHeaderSearchPaths) { - size += sizeof(std::string) + i.str().size(); + size += stringSize + i.str().size(); } for (auto& i : m_frameworkSearchPaths) { - size += sizeof(std::string) + i.str().size(); + size += stringSize + i.str().size(); } for (auto& i : m_compilerFlags) { - size += sizeof(std::string) + i.size(); + size += stringSize + i.size(); } return size; diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxx.h b/src/lib_cxx/data/indexer/IndexerCommandCxx.h index fccd0ab0..99ea42d2 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxx.h +++ b/src/lib_cxx/data/indexer/IndexerCommandCxx.h @@ -22,7 +22,7 @@ public: const bool shouldApplyAnonymousTypedefTransformation); virtual ~IndexerCommandCxx(); - virtual size_t getByteSize() const override; + virtual size_t getByteSize(size_t stringSize) const override; std::vector getSystemHeaderSearchPaths() const; std::vector getFrameworkSearchPaths() const; diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp index bec0fff7..5604d2ec 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp @@ -63,9 +63,9 @@ IndexerCommandType IndexerCommandCxxCdb::getIndexerCommandType() const return getStaticIndexerCommandType(); } -size_t IndexerCommandCxxCdb::getByteSize() const +size_t IndexerCommandCxxCdb::getByteSize(size_t stringSize) const { - return IndexerCommandCxx::getByteSize() + sizeof(std::string) + m_workingDirectory.str().size(); + return IndexerCommandCxx::getByteSize(stringSize) + m_workingDirectory.str().size(); } FilePath IndexerCommandCxxCdb::getWorkingDirectory() const diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h index a684c2e6..8d7176fb 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h @@ -33,7 +33,7 @@ public: virtual ~IndexerCommandCxxCdb(); virtual IndexerCommandType getIndexerCommandType() const override; - virtual size_t getByteSize() const override; + virtual size_t getByteSize(size_t stringSize) const override; FilePath getWorkingDirectory() const; diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp index 6faeed4c..3579d023 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp @@ -29,9 +29,9 @@ IndexerCommandType IndexerCommandCxxManual::getIndexerCommandType() const return getStaticIndexerCommandType(); } -size_t IndexerCommandCxxManual::getByteSize() const +size_t IndexerCommandCxxManual::getByteSize(size_t stringSize) const { - return IndexerCommandCxx::getByteSize() + sizeof(std::string) + m_languageStandard.size(); + return IndexerCommandCxx::getByteSize(stringSize) + m_languageStandard.size(); } std::string IndexerCommandCxxManual::getLanguageStandard() const diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h index 3e6481f8..92200e8f 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h @@ -24,7 +24,7 @@ public: virtual ~IndexerCommandCxxManual(); virtual IndexerCommandType getIndexerCommandType() const override; - virtual size_t getByteSize() const override; + virtual size_t getByteSize(size_t stringSize) const override; std::string getLanguageStandard() const; diff --git a/src/lib_java/data/indexer/IndexerCommandJava.cpp b/src/lib_java/data/indexer/IndexerCommandJava.cpp index 48d3c909..f08eab21 100644 --- a/src/lib_java/data/indexer/IndexerCommandJava.cpp +++ b/src/lib_java/data/indexer/IndexerCommandJava.cpp @@ -25,13 +25,13 @@ IndexerCommandType IndexerCommandJava::getIndexerCommandType() const return getStaticIndexerCommandType(); } -size_t IndexerCommandJava::getByteSize() const +size_t IndexerCommandJava::getByteSize(size_t stringSize) const { - size_t size = IndexerCommand::getByteSize(); + size_t size = IndexerCommand::getByteSize(stringSize); for (auto& i : m_classPath) { - size += sizeof(std::string) + i.str().size(); + size += stringSize + i.str().size(); } return size; diff --git a/src/lib_java/data/indexer/IndexerCommandJava.h b/src/lib_java/data/indexer/IndexerCommandJava.h index e8948cb7..799aa9e0 100644 --- a/src/lib_java/data/indexer/IndexerCommandJava.h +++ b/src/lib_java/data/indexer/IndexerCommandJava.h @@ -21,7 +21,7 @@ public: virtual ~IndexerCommandJava(); virtual IndexerCommandType getIndexerCommandType() const override; - virtual size_t getByteSize() const override; + virtual size_t getByteSize(size_t stringSize) const override; std::vector getClassPath() const;