[Android] Pre-allocate memory

This commit is contained in:
zilmar 2016-09-26 21:10:11 +10:00
parent 9eaa9d77e6
commit 6cfd981b7d
8 changed files with 45 additions and 18 deletions

View File

@ -234,8 +234,8 @@ bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char
SetupTrace(); SetupTrace();
FixDirectories(); FixDirectories();
#ifdef _WIN32
CMipsMemoryVM::ReserveMemory(); CMipsMemoryVM::ReserveMemory();
#ifdef _WIN32
IncreaseThreadPriority(); IncreaseThreadPriority();
#else #else
if (!CMipsMemoryVM::SetupSegvHandler()) if (!CMipsMemoryVM::SetupSegvHandler())

View File

@ -105,6 +105,8 @@ private:
//Recompiler has access to manipulate and call functions //Recompiler has access to manipulate and call functions
friend CSystemTimer; friend CSystemTimer;
friend CMipsMemoryVM;
//Used for loading and potentially executing the CPU in its own thread. //Used for loading and potentially executing the CPU in its own thread.
static void StartEmulationThread(CThread * thread); static void StartEmulationThread(CThread * thread);
static bool EmulationStarting(CThread * thread); static bool EmulationStarting(CThread * thread);

View File

@ -465,6 +465,8 @@ void CN64Rom::NotificationCB(const char * Status, CN64Rom * /*_this*/)
bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
{ {
WriteTrace(TraceN64System, TraceDebug, "Start (FileLoc: \"%s\" LoadBootCodeOnly: %s)", FileLoc, LoadBootCodeOnly ? "true" : "false");
UnallocateRomImage(); UnallocateRomImage();
m_ErrorMsg = EMPTY_STRING; m_ErrorMsg = EMPTY_STRING;
@ -482,6 +484,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
{ {
//Pop up a dialog and select file //Pop up a dialog and select file
//allocate memory for sub name and copy selected file name to var //allocate memory for sub name and copy selected file name to var
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false; //remove once dialog is done return false; //remove once dialog is done
} }
else else
@ -517,6 +520,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
if (!AllocateRomImage(RomFileSize)) if (!AllocateRomImage(RomFileSize))
{ {
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false; return false;
} }
@ -525,12 +529,14 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
if (!ZipFile.GetFile(i, m_ROMImage, RomFileSize)) if (!ZipFile.GetFile(i, m_ROMImage, RomFileSize))
{ {
SetError(MSG_FAIL_IMAGE); SetError(MSG_FAIL_IMAGE);
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false; return false;
} }
if (!IsValidRomImage(m_ROMImage)) if (!IsValidRomImage(m_ROMImage))
{ {
SetError(MSG_FAIL_IMAGE); SetError(MSG_FAIL_IMAGE);
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false; return false;
} }
g_Notify->DisplayMessage(5, MSG_BYTESWAP); g_Notify->DisplayMessage(5, MSG_BYTESWAP);
@ -544,6 +550,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
if (!Loaded7zFile) if (!Loaded7zFile)
{ {
SetError(MSG_7Z_FILE_NOT_FOUND); SetError(MSG_7Z_FILE_NOT_FOUND);
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false; return false;
} }
} }
@ -556,10 +563,12 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
{ {
if (m_ErrorMsg != EMPTY_STRING) if (m_ErrorMsg != EMPTY_STRING)
{ {
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false; return false;
} }
if (!AllocateAndLoadN64Image(FileLoc, LoadBootCodeOnly)) if (!AllocateAndLoadN64Image(FileLoc, LoadBootCodeOnly))
{ {
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false; return false;
} }
} }
@ -606,6 +615,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
CalculateRomCrc(); CalculateRomCrc();
} }
WriteTrace(TraceN64System, TraceDebug, "Done (res: true)");
return true; return true;
} }
@ -759,7 +769,7 @@ void CN64Rom::SaveRomSettingID(bool temp)
g_Settings->SaveBool(Game_TempLoaded, temp); g_Settings->SaveBool(Game_TempLoaded, temp);
g_Settings->SaveString(Game_GameName, m_RomName.c_str()); g_Settings->SaveString(Game_GameName, m_RomName.c_str());
g_Settings->SaveString(Game_IniKey, m_RomIdent.c_str()); g_Settings->SaveString(Game_IniKey, m_RomIdent.c_str());
g_Settings->SaveString(Game_UniqueSaveDir, stdstr_f("%s-%s", m_RomName.c_str(), m_MD5.c_str() ).c_str()); g_Settings->SaveString(Game_UniqueSaveDir, stdstr_f("%s-%s", m_RomName.c_str(), m_MD5.c_str()).c_str());
switch (GetCountry()) switch (GetCountry())
{ {

View File

@ -26,9 +26,10 @@ CFunctionMap::~CFunctionMap()
bool CFunctionMap::AllocateMemory() bool CFunctionMap::AllocateMemory()
{ {
if (g_System->LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable == NULL) WriteTrace(TraceRecompiler, TraceDebug, "start");
if (LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable == NULL)
{ {
m_FunctionTable = new PCCompiledFunc_TABLE[0x100000]; m_FunctionTable = new (std::nothrow) PCCompiledFunc_TABLE[0x100000];
if (m_FunctionTable == NULL) if (m_FunctionTable == NULL)
{ {
WriteTrace(TraceRecompiler, TraceError, "failed to allocate function table"); WriteTrace(TraceRecompiler, TraceError, "failed to allocate function table");
@ -37,17 +38,18 @@ bool CFunctionMap::AllocateMemory()
} }
memset(m_FunctionTable, 0, 0x100000 * sizeof(PCCompiledFunc_TABLE)); memset(m_FunctionTable, 0, 0x100000 * sizeof(PCCompiledFunc_TABLE));
} }
if (g_System->LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable == NULL) if (LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable == NULL)
{ {
m_JumpTable = new PCCompiledFunc[g_MMU->RdramSize() >> 2]; m_JumpTable = new (std::nothrow) PCCompiledFunc[RdramSize() >> 2];
if (m_JumpTable == NULL) if (m_JumpTable == NULL)
{ {
WriteTrace(TraceRecompiler, TraceError, "failed to allocate jump table"); WriteTrace(TraceRecompiler, TraceError, "failed to allocate jump table");
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR); g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
return false; return false;
} }
memset(m_JumpTable, 0, (g_MMU->RdramSize() >> 2) * sizeof(PCCompiledFunc)); memset(m_JumpTable, 0, (RdramSize() >> 2) * sizeof(PCCompiledFunc));
} }
WriteTrace(TraceRecompiler, TraceDebug, "Done");
return true; return true;
} }
@ -62,7 +64,7 @@ void CFunctionMap::CleanBuffers()
delete m_FunctionTable[i]; delete m_FunctionTable[i];
} }
} }
delete [] m_FunctionTable; delete[] m_FunctionTable;
m_FunctionTable = NULL; m_FunctionTable = NULL;
} }
if (m_JumpTable) if (m_JumpTable)
@ -74,9 +76,11 @@ void CFunctionMap::CleanBuffers()
void CFunctionMap::Reset(bool bAllocate) void CFunctionMap::Reset(bool bAllocate)
{ {
WriteTrace(TraceRecompiler, TraceDebug, "start (bAllocate: %s)", bAllocate ? "true" : "false");
CleanBuffers(); CleanBuffers();
if (bAllocate && (g_System->LookUpMode() == FuncFind_VirtualLookup || g_System->LookUpMode() == FuncFind_PhysicalLookup)) if (bAllocate && (g_System->LookUpMode() == FuncFind_VirtualLookup || g_System->LookUpMode() == FuncFind_PhysicalLookup))
{ {
AllocateMemory(); AllocateMemory();
} }
WriteTrace(TraceRecompiler, TraceDebug, "Done");
} }

View File

@ -11,7 +11,8 @@
#pragma once #pragma once
#include <Project64-core/N64System/Recompiler/FunctionInfo.h> #include <Project64-core/N64System/Recompiler/FunctionInfo.h>
class CFunctionMap class CFunctionMap :
private CGameSettings
{ {
protected: protected:
typedef CCompiledFunc * PCCompiledFunc; typedef CCompiledFunc * PCCompiledFunc;

View File

@ -22,6 +22,7 @@ CRecompiler::CRecompiler(CRegisters & Registers, CProfiling & Profile, bool & En
m_EndEmulation(EndEmulation), m_EndEmulation(EndEmulation),
PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER) PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER)
{ {
CFunctionMap::AllocateMemory();
if (g_MMU != NULL) if (g_MMU != NULL)
{ {
ResetMemoryStackPos(); ResetMemoryStackPos();
@ -718,12 +719,15 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB()
void CRecompiler::Reset() void CRecompiler::Reset()
{ {
WriteTrace(TraceRecompiler, TraceDebug, "start");
ResetRecompCode(true); ResetRecompCode(true);
ResetMemoryStackPos(); ResetMemoryStackPos();
WriteTrace(TraceRecompiler, TraceDebug, "Done");
} }
void CRecompiler::ResetRecompCode(bool bAllocate) void CRecompiler::ResetRecompCode(bool bAllocate)
{ {
WriteTrace(TraceRecompiler, TraceDebug, "start");
CRecompMemory::Reset(); CRecompMemory::Reset();
CFunctionMap::Reset(bAllocate); CFunctionMap::Reset(bAllocate);
@ -739,6 +743,7 @@ void CRecompiler::ResetRecompCode(bool bAllocate)
} }
} }
m_Functions.clear(); m_Functions.clear();
WriteTrace(TraceRecompiler, TraceDebug, "Done");
} }
void CRecompiler::RecompilerMain_ChangeMemory() void CRecompiler::RecompilerMain_ChangeMemory()
@ -1036,18 +1041,21 @@ void CRecompiler::ClearRecompCode_Phys(uint32_t Address, int length, REMOVE_REAS
void CRecompiler::ClearRecompCode_Virt(uint32_t Address, int length, REMOVE_REASON Reason) void CRecompiler::ClearRecompCode_Virt(uint32_t Address, int length, REMOVE_REASON Reason)
{ {
uint32_t AddressIndex, WriteStart;
int DataInBlock, DataToWrite, DataLeft;
switch (g_System->LookUpMode()) switch (g_System->LookUpMode())
{ {
case FuncFind_VirtualLookup: case FuncFind_VirtualLookup:
AddressIndex = Address >> 0xC;
WriteStart = (Address & 0xFFC);
length = ((length + 3) & ~0x3);
DataInBlock = 0x1000 - WriteStart;
DataToWrite = length < DataInBlock ? length : DataInBlock;
DataLeft = length - DataToWrite;
{ {
uint32_t AddressIndex = Address >> 0xC;
uint32_t WriteStart = (Address & 0xFFC);
length = ((length + 3) & ~0x3);
int DataInBlock = 0x1000 - WriteStart;
int DataToWrite = length < DataInBlock ? length : DataInBlock;
int DataLeft = length - DataToWrite;
PCCompiledFunc_TABLE & table = FunctionTable()[AddressIndex]; PCCompiledFunc_TABLE & table = FunctionTable()[AddressIndex];
if (table) if (table)
{ {

View File

@ -40,6 +40,7 @@ CPU_TYPE CGameSettings::m_CpuType = CPU_Recompiler;
void CGameSettings::RefreshGameSettings() void CGameSettings::RefreshGameSettings()
{ {
WriteTrace(TraceN64System, TraceDebug, "start");
m_bSMM_StoreInstruc = false /*g_Settings->LoadBool(Game_SMM_StoreInstruc)*/; m_bSMM_StoreInstruc = false /*g_Settings->LoadBool(Game_SMM_StoreInstruc)*/;
m_bSMM_Protect = g_Settings->LoadBool(Game_SMM_Protect); m_bSMM_Protect = g_Settings->LoadBool(Game_SMM_Protect);
m_bSMM_ValidFunc = g_Settings->LoadBool(Game_SMM_ValidFunc); m_bSMM_ValidFunc = g_Settings->LoadBool(Game_SMM_ValidFunc);
@ -73,6 +74,7 @@ void CGameSettings::RefreshGameSettings()
{ {
m_CountPerOp = 2; m_CountPerOp = 2;
} }
WriteTrace(TraceN64System, TraceDebug, "Done");
} }
void CGameSettings::SpeedChanged(int SpeedLimit) void CGameSettings::SpeedChanged(int SpeedLimit)

View File

@ -130,7 +130,7 @@ bool CSettingTypeApplication::Load(int /*Index*/, bool & Value) const
{ {
bool bRes = false; bool bRes = false;
uint32_t dwValue; uint32_t dwValue = 0;
bRes = m_SettingsIniFile ? m_SettingsIniFile->GetNumber(SectionName(), m_KeyNameIdex.c_str(), Value, dwValue) : false; bRes = m_SettingsIniFile ? m_SettingsIniFile->GetNumber(SectionName(), m_KeyNameIdex.c_str(), Value, dwValue) : false;
if (bRes) if (bRes)
{ {