Commit 75b794ad authored by Marius Wachtler's avatar Marius Wachtler

bjit: allocate code block using mmap

also add a option to pass MAP_32BIT to mmap
parent b022674c
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <llvm/ADT/DenseMap.h> #include <llvm/ADT/DenseMap.h>
#include <llvm/ADT/DenseSet.h> #include <llvm/ADT/DenseSet.h>
#include <sys/mman.h>
#include "codegen/irgen/hooks.h" #include "codegen/irgen/hooks.h"
#include "codegen/memmgr.h" #include "codegen/memmgr.h"
...@@ -59,12 +60,22 @@ static_assert(JitCodeBlock::scratch_size == 256, "have to update EH table!"); ...@@ -59,12 +60,22 @@ static_assert(JitCodeBlock::scratch_size == 256, "have to update EH table!");
constexpr int code_size = JitCodeBlock::memory_size - sizeof(eh_info); constexpr int code_size = JitCodeBlock::memory_size - sizeof(eh_info);
JitCodeBlock::MemoryManager::MemoryManager() {
int protection = PROT_READ | PROT_WRITE | PROT_EXEC;
int flags = MAP_PRIVATE | MAP_ANONYMOUS;
#if ENABLE_BASELINEJIT_MAP_32BIT
flags |= MAP_32BIT;
#endif
addr = (uint8_t*)mmap(NULL, JitCodeBlock::memory_size, protection, flags, -1, 0);
}
JitCodeBlock::MemoryManager::~MemoryManager() {
munmap(addr, JitCodeBlock::memory_size);
addr = NULL;
}
JitCodeBlock::JitCodeBlock(llvm::StringRef name) JitCodeBlock::JitCodeBlock(llvm::StringRef name)
: memory(new uint8_t[memory_size]), : entry_offset(0), a(memory.get() + sizeof(eh_info), code_size), is_currently_writing(false), asm_failed(false) {
entry_offset(0),
a(memory.get() + sizeof(eh_info), code_size),
is_currently_writing(false),
asm_failed(false) {
static StatCounter num_jit_code_blocks("num_baselinejit_code_blocks"); static StatCounter num_jit_code_blocks("num_baselinejit_code_blocks");
num_jit_code_blocks.log(); num_jit_code_blocks.log();
static StatCounter num_jit_total_bytes("num_baselinejit_total_bytes"); static StatCounter num_jit_total_bytes("num_baselinejit_total_bytes");
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
namespace pyston { namespace pyston {
// passes MAP_32BIT to mmap when allocating the memory for the bjit code.
// it's nice for inspecting the generated asm because the debugger is able to show the name of called C/C++ functions
#define ENABLE_BASELINEJIT_MAP_32BIT 0
#define ENABLE_BASELINEJIT_ICS 1 #define ENABLE_BASELINEJIT_ICS 1
class AST_stmt; class AST_stmt;
...@@ -147,8 +150,18 @@ public: ...@@ -147,8 +150,18 @@ public:
static constexpr int sp_adjustment = scratch_size + num_stack_args * 8 + 8 /* = alignment */; static constexpr int sp_adjustment = scratch_size + num_stack_args * 8 + 8 /* = alignment */;
private: private:
struct MemoryManager {
private:
uint8_t* addr;
public:
MemoryManager();
~MemoryManager();
uint8_t* get() { return addr; }
};
// the memory block contains the EH frame directly followed by the generated machine code. // the memory block contains the EH frame directly followed by the generated machine code.
std::unique_ptr<uint8_t[]> memory; MemoryManager memory;
int entry_offset; int entry_offset;
assembler::Assembler a; assembler::Assembler a;
bool is_currently_writing; bool is_currently_writing;
......
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