Jit64: Merge memory allocations into a single allocation

Instead of each component allocating their own memory, we instead allocate
the memory once and divvy that up among the components as required. This
ensures that relative memory offsets remain within architecture limits.
This commit is contained in:
MerryMage 2017-03-21 18:51:07 +00:00
parent da434e1a1c
commit cb7d9556bf
8 changed files with 36 additions and 39 deletions

View File

@ -229,9 +229,14 @@ void Jit64::Init()
gpr.SetEmitter(this);
fpr.SetEmitter(this);
trampolines.Init(jo.memcheck ? TRAMPOLINE_CODE_SIZE_MMU : TRAMPOLINE_CODE_SIZE);
const size_t routines_size = asm_routines.CODE_SIZE;
const size_t trampolines_size = jo.memcheck ? TRAMPOLINE_CODE_SIZE_MMU : TRAMPOLINE_CODE_SIZE;
const size_t farcode_size = jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE;
const size_t constpool_size = m_const_pool.CONST_POOL_SIZE;
AllocCodeSpace(CODE_SIZE + constpool_size);
AllocCodeSpace(CODE_SIZE + routines_size + trampolines_size + farcode_size + constpool_size);
AddChildCodeSpace(&asm_routines, routines_size);
AddChildCodeSpace(&trampolines, trampolines_size);
AddChildCodeSpace(&m_far_code, farcode_size);
m_const_pool.Init(AllocChildCodeSpace(constpool_size), constpool_size);
// BLR optimization has the same consequences as block linking, as well as
@ -250,7 +255,7 @@ void Jit64::Init()
// important: do this *after* generating the global asm routines, because we can't use farcode in
// them.
// it'll crash because the farcode functions get cleared on JIT clears.
m_far_code.Init(jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE);
m_far_code.Init();
Clear();
code_block.m_stats = &js.st;
@ -276,8 +281,6 @@ void Jit64::Shutdown()
FreeCodeSpace();
blocks.Shutdown();
trampolines.Shutdown();
asm_routines.Shutdown();
m_far_code.Shutdown();
m_const_pool.Shutdown();
}

View File

@ -2,7 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Core/PowerPC/Jit64/Jit.h"
#include "Core/PowerPC/Jit64/JitAsm.h"
#include "Common/CommonTypes.h"
#include "Common/JitRegister.h"
#include "Common/x64ABI.h"
@ -11,7 +11,7 @@
#include "Core/CoreTiming.h"
#include "Core/HW/CPU.h"
#include "Core/HW/Memmap.h"
#include "Core/PowerPC/Jit64/JitAsm.h"
#include "Core/PowerPC/Jit64/Jit.h"
#include "Core/PowerPC/Jit64Common/Jit64PowerPCState.h"
#include "Core/PowerPC/PowerPC.h"
@ -20,6 +20,14 @@ using namespace Gen;
// Not PowerPC state. Can't put in 'this' because it's out of range...
static void* s_saved_rsp;
void Jit64AsmRoutineManager::Init(u8* stack_top)
{
m_const_pool.Init(AllocChildCodeSpace(4096), 4096);
m_stack_top = stack_top;
Generate();
WriteProtect();
}
// PLAN: no more block numbers - crazy opcodes just contain offset within
// dynarec buffer
// At this offset - 4, there is an int specifying the block number.

View File

@ -34,16 +34,11 @@ private:
u8* m_stack_top;
public:
void Init(u8* stack_top)
{
m_stack_top = stack_top;
// NOTE: When making large additions to the AsmCommon code, you might
// want to ensure this number is big enough.
AllocCodeSpace(16384);
Generate();
WriteProtect();
}
// NOTE: When making large additions to the AsmCommon code, you might
// want to ensure this number is big enough.
static constexpr size_t CODE_SIZE = 16384;
void Init(u8* stack_top);
void Shutdown() { FreeCodeSpace(); }
void ResetStack(Gen::X64CodeBlock& emitter);
};

View File

@ -4,15 +4,13 @@
#include "Core/PowerPC/Jit64Common/FarCodeCache.h"
void FarCodeCache::Init(size_t size)
void FarCodeCache::Init()
{
AllocCodeSpace(size);
m_enabled = true;
}
void FarCodeCache::Shutdown()
{
FreeCodeSpace();
m_enabled = false;
}

View File

@ -17,7 +17,7 @@ constexpr size_t FARCODE_SIZE_MMU = 1024 * 1024 * 48;
class FarCodeCache : public Gen::X64CodeBlock
{
public:
void Init(size_t size);
void Init();
void Shutdown();
bool Enabled() const;

View File

@ -23,21 +23,11 @@
using namespace Gen;
void TrampolineCache::Init(size_t size)
{
AllocCodeSpace(size);
}
void TrampolineCache::ClearCodeSpace()
{
X64CodeBlock::ClearCodeSpace();
}
void TrampolineCache::Shutdown()
{
FreeCodeSpace();
}
const u8* TrampolineCache::GenerateTrampoline(const TrampolineInfo& info)
{
if (info.read)

View File

@ -24,8 +24,6 @@ class TrampolineCache : public EmuCodeBlock
const u8* GenerateWriteTrampoline(const TrampolineInfo& info);
public:
void Init(size_t size);
void Shutdown();
const u8* GenerateTrampoline(const TrampolineInfo& info);
void ClearCodeSpace();
};

View File

@ -262,12 +262,19 @@ void JitIL::Init()
jo.accurateSinglePrecision = false;
UpdateMemoryOptions();
trampolines.Init(jo.memcheck ? TRAMPOLINE_CODE_SIZE_MMU : TRAMPOLINE_CODE_SIZE);
AllocCodeSpace(CODE_SIZE);
const size_t routines_size = asm_routines.CODE_SIZE;
const size_t trampolines_size = jo.memcheck ? TRAMPOLINE_CODE_SIZE_MMU : TRAMPOLINE_CODE_SIZE;
const size_t farcode_size = jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE;
const size_t constpool_size = m_const_pool.CONST_POOL_SIZE;
AllocCodeSpace(CODE_SIZE + routines_size + trampolines_size + farcode_size + constpool_size);
AddChildCodeSpace(&asm_routines, routines_size);
AddChildCodeSpace(&trampolines, trampolines_size);
AddChildCodeSpace(&m_far_code, farcode_size);
m_const_pool.Init(AllocChildCodeSpace(constpool_size), constpool_size);
blocks.Init();
asm_routines.Init(nullptr);
m_far_code.Init(jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE);
m_far_code.Init();
Clear();
code_block.m_stats = &js.st;
@ -299,8 +306,6 @@ void JitIL::Shutdown()
FreeCodeSpace();
blocks.Shutdown();
trampolines.Shutdown();
asm_routines.Shutdown();
m_far_code.Shutdown();
}