diff options
author | Lang Hames <lhames@gmail.com> | 2019-05-20 20:53:05 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2019-05-20 20:53:05 +0000 |
commit | 93d2bdda6bfe287de7825cfac9224dcfe051b1c5 (patch) | |
tree | 7b876090b9f6357dc81e5c09f63addfe0993e528 /llvm/lib/ExecutionEngine/SectionMemoryManager.cpp | |
parent | 52fa90a348c1bed5ecbcc0965c57d67e5ec45d5a (diff) | |
download | llvm-93d2bdda6bfe287de7825cfac9224dcfe051b1c5.zip llvm-93d2bdda6bfe287de7825cfac9224dcfe051b1c5.tar.gz llvm-93d2bdda6bfe287de7825cfac9224dcfe051b1c5.tar.bz2 |
[Support] Renamed member 'Size' to 'AllocatedSize' in MemoryBlock and OwningMemoryBlock.
Rename member 'Size' to 'AllocatedSize' in order to provide a hint that the
allocated size may be different than the requested size. Comments are added to
clarify this point. Updated the InMemoryBuffer in FileOutputBuffer.cpp to track
the requested buffer size.
Patch by Machiel van Hooren. Thanks Machiel!
https://reviews.llvm.org/D61599
llvm-svn: 361195
Diffstat (limited to 'llvm/lib/ExecutionEngine/SectionMemoryManager.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/SectionMemoryManager.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp index 2c0cfeb..925049b2 100644 --- a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp @@ -64,9 +64,9 @@ uint8_t *SectionMemoryManager::allocateSection( // Look in the list of free memory regions and use a block there if one // is available. for (FreeMemBlock &FreeMB : MemGroup.FreeMem) { - if (FreeMB.Free.size() >= RequiredSize) { + if (FreeMB.Free.allocatedSize() >= RequiredSize) { Addr = (uintptr_t)FreeMB.Free.base(); - uintptr_t EndOfBlock = Addr + FreeMB.Free.size(); + uintptr_t EndOfBlock = Addr + FreeMB.Free.allocatedSize(); // Align the address. Addr = (Addr + Alignment - 1) & ~(uintptr_t)(Alignment - 1); @@ -115,7 +115,7 @@ uint8_t *SectionMemoryManager::allocateSection( // Remember that we allocated this memory MemGroup.AllocatedMem.push_back(MB); Addr = (uintptr_t)MB.base(); - uintptr_t EndOfBlock = Addr + MB.size(); + uintptr_t EndOfBlock = Addr + MB.allocatedSize(); // Align the address. Addr = (Addr + Alignment - 1) & ~(uintptr_t)(Alignment - 1); @@ -177,7 +177,7 @@ static sys::MemoryBlock trimBlockToPageSize(sys::MemoryBlock M) { size_t StartOverlap = (PageSize - ((uintptr_t)M.base() % PageSize)) % PageSize; - size_t TrimmedSize = M.size(); + size_t TrimmedSize = M.allocatedSize(); TrimmedSize -= StartOverlap; TrimmedSize -= TrimmedSize % PageSize; @@ -185,8 +185,9 @@ static sys::MemoryBlock trimBlockToPageSize(sys::MemoryBlock M) { TrimmedSize); assert(((uintptr_t)Trimmed.base() % PageSize) == 0); - assert((Trimmed.size() % PageSize) == 0); - assert(M.base() <= Trimmed.base() && Trimmed.size() <= M.size()); + assert((Trimmed.allocatedSize() % PageSize) == 0); + assert(M.base() <= Trimmed.base() && + Trimmed.allocatedSize() <= M.allocatedSize()); return Trimmed; } @@ -209,17 +210,19 @@ SectionMemoryManager::applyMemoryGroupPermissions(MemoryGroup &MemGroup, } // Remove all blocks which are now empty - MemGroup.FreeMem.erase( - remove_if(MemGroup.FreeMem, - [](FreeMemBlock &FreeMB) { return FreeMB.Free.size() == 0; }), - MemGroup.FreeMem.end()); + MemGroup.FreeMem.erase(remove_if(MemGroup.FreeMem, + [](FreeMemBlock &FreeMB) { + return FreeMB.Free.allocatedSize() == 0; + }), + MemGroup.FreeMem.end()); return std::error_code(); } void SectionMemoryManager::invalidateInstructionCache() { for (sys::MemoryBlock &Block : CodeMem.PendingMem) - sys::Memory::InvalidateInstructionCache(Block.base(), Block.size()); + sys::Memory::InvalidateInstructionCache(Block.base(), + Block.allocatedSize()); } SectionMemoryManager::~SectionMemoryManager() { @@ -242,11 +245,7 @@ public: allocateMappedMemory(SectionMemoryManager::AllocationPurpose Purpose, size_t NumBytes, const sys::MemoryBlock *const NearBlock, unsigned Flags, std::error_code &EC) override { - // allocateMappedMemory calls mmap(2). We round up a request size - // to page size to get extra space for free. - static const size_t PageSize = sys::Process::getPageSizeEstimate(); - size_t ReqBytes = (NumBytes + PageSize - 1) & ~(PageSize - 1); - return sys::Memory::allocateMappedMemory(ReqBytes, NearBlock, Flags, EC); + return sys::Memory::allocateMappedMemory(NumBytes, NearBlock, Flags, EC); } std::error_code protectMappedMemory(const sys::MemoryBlock &Block, |