Commit 2f4b5238 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Track some stats about the memory we allocate for the JIT

parent 3420ef7e
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "llvm/Support/Memory.h" #include "llvm/Support/Memory.h"
#include "core/common.h" #include "core/common.h"
#include "core/stats.h"
#include "core/util.h" #include "core/util.h"
// This code was copy-pasted from SectionMemoryManager.cpp; // This code was copy-pasted from SectionMemoryManager.cpp;
...@@ -33,29 +34,30 @@ namespace pyston { ...@@ -33,29 +34,30 @@ namespace pyston {
class PystonMemoryManager : public RTDyldMemoryManager { class PystonMemoryManager : public RTDyldMemoryManager {
public: public:
PystonMemoryManager() {} PystonMemoryManager() {}
virtual ~PystonMemoryManager(); ~PystonMemoryManager() override;
virtual uint8_t* allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName); uint8_t* allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID,
StringRef SectionName) override;
virtual uint8_t* allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, uint8_t* allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName,
bool isReadOnly); bool isReadOnly) override;
virtual bool finalizeMemory(std::string* ErrMsg = 0); bool finalizeMemory(std::string* ErrMsg = 0) override;
virtual void invalidateInstructionCache();
private: private:
void invalidateInstructionCache();
struct MemoryGroup { struct MemoryGroup {
SmallVector<sys::MemoryBlock, 16> AllocatedMem; SmallVector<sys::MemoryBlock, 16> AllocatedMem;
SmallVector<sys::MemoryBlock, 16> FreeMem; SmallVector<sys::MemoryBlock, 16> FreeMem;
sys::MemoryBlock Near; sys::MemoryBlock Near;
}; };
uint8_t* allocateSection(MemoryGroup& MemGroup, uintptr_t Size, unsigned Alignment); uint8_t* allocateSection(MemoryGroup& MemGroup, uintptr_t Size, unsigned Alignment, StringRef SectionName);
llvm_error_code applyMemoryGroupPermissions(MemoryGroup& MemGroup, unsigned Permissions); llvm_error_code applyMemoryGroupPermissions(MemoryGroup& MemGroup, unsigned Permissions);
virtual uint64_t getSymbolAddress(const std::string& Name); uint64_t getSymbolAddress(const std::string& Name) override;
MemoryGroup CodeMem; MemoryGroup CodeMem;
MemoryGroup RWDataMem; MemoryGroup RWDataMem;
...@@ -67,17 +69,18 @@ uint8_t* PystonMemoryManager::allocateDataSection(uintptr_t Size, unsigned Align ...@@ -67,17 +69,18 @@ uint8_t* PystonMemoryManager::allocateDataSection(uintptr_t Size, unsigned Align
// printf("allocating data section: %ld %d %d %s %d\n", Size, Alignment, SectionID, SectionName.data(), IsReadOnly); // printf("allocating data section: %ld %d %d %s %d\n", Size, Alignment, SectionID, SectionName.data(), IsReadOnly);
// assert(SectionName != ".llvm_stackmaps"); // assert(SectionName != ".llvm_stackmaps");
if (IsReadOnly) if (IsReadOnly)
return allocateSection(RODataMem, Size, Alignment); return allocateSection(RODataMem, Size, Alignment, SectionName);
return allocateSection(RWDataMem, Size, Alignment); return allocateSection(RWDataMem, Size, Alignment, SectionName);
} }
uint8_t* PystonMemoryManager::allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, uint8_t* PystonMemoryManager::allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID,
StringRef SectionName) { StringRef SectionName) {
// printf("allocating code section: %ld %d %d %s\n", Size, Alignment, SectionID, SectionName.data()); // printf("allocating code section: %ld %d %d %s\n", Size, Alignment, SectionID, SectionName.data());
return allocateSection(CodeMem, Size, Alignment); return allocateSection(CodeMem, Size, Alignment, SectionName);
} }
uint8_t* PystonMemoryManager::allocateSection(MemoryGroup& MemGroup, uintptr_t Size, unsigned Alignment) { uint8_t* PystonMemoryManager::allocateSection(MemoryGroup& MemGroup, uintptr_t Size, unsigned Alignment,
StringRef SectionName) {
if (!Alignment) if (!Alignment)
Alignment = 16; Alignment = 16;
...@@ -118,6 +121,9 @@ uint8_t* PystonMemoryManager::allocateSection(MemoryGroup& MemGroup, uintptr_t S ...@@ -118,6 +121,9 @@ uint8_t* PystonMemoryManager::allocateSection(MemoryGroup& MemGroup, uintptr_t S
return NULL; return NULL;
} }
std::string stat_name = "mem_section_" + std::string(SectionName);
Stats::log(Stats::getStatId(stat_name), MB.size());
// Save this address as the basis for our next request // Save this address as the basis for our next request
MemGroup.Near = MB; MemGroup.Near = MB;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment