JitInterface: Convert m_jit to unique_ptr.

This commit is contained in:
Admiral H. Curtiss 2023-03-25 16:17:46 +01:00
parent 9217a9eba4
commit 7f50c070b2
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
3 changed files with 18 additions and 15 deletions

View File

@ -46,9 +46,9 @@ JitInterface::JitInterface(Core::System& system) : m_system(system)
JitInterface::~JitInterface() = default; JitInterface::~JitInterface() = default;
void JitInterface::SetJit(JitBase* jit) void JitInterface::SetJit(std::unique_ptr<JitBase> jit)
{ {
m_jit = jit; m_jit = std::move(jit);
} }
void JitInterface::DoState(PointerWrap& p) void JitInterface::DoState(PointerWrap& p)
@ -65,31 +65,31 @@ CPUCoreBase* JitInterface::InitJitCore(PowerPC::CPUCore core)
{ {
#if _M_X86 #if _M_X86
case PowerPC::CPUCore::JIT64: case PowerPC::CPUCore::JIT64:
m_jit = new Jit64(system); m_jit = std::make_unique<Jit64>(system);
break; break;
#endif #endif
#if _M_ARM_64 #if _M_ARM_64
case PowerPC::CPUCore::JITARM64: case PowerPC::CPUCore::JITARM64:
m_jit = new JitArm64(system); m_jit = std::make_unique<JitArm64>(system);
break; break;
#endif #endif
case PowerPC::CPUCore::CachedInterpreter: case PowerPC::CPUCore::CachedInterpreter:
m_jit = new CachedInterpreter(system); m_jit = std::make_unique<CachedInterpreter>(system);
break; break;
default: default:
// Under this case the caller overrides the CPU core to the default and logs that // Under this case the caller overrides the CPU core to the default and logs that
// it performed the override. // it performed the override.
m_jit = nullptr; m_jit.reset();
return nullptr; return nullptr;
} }
m_jit->Init(); m_jit->Init();
return m_jit; return m_jit.get();
} }
CPUCoreBase* JitInterface::GetCore() const CPUCoreBase* JitInterface::GetCore() const
{ {
return m_jit; return m_jit.get();
} }
void JitInterface::SetProfilingState(ProfilingState state) void JitInterface::SetProfilingState(ProfilingState state)
@ -319,7 +319,6 @@ void JitInterface::Shutdown()
if (m_jit) if (m_jit)
{ {
m_jit->Shutdown(); m_jit->Shutdown();
delete m_jit; m_jit.reset();
m_jit = nullptr;
} }
} }

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include <variant> #include <variant>
@ -94,11 +95,11 @@ public:
static void CompileExceptionCheckFromJIT(JitInterface& jit_interface, ExceptionType type); static void CompileExceptionCheckFromJIT(JitInterface& jit_interface, ExceptionType type);
/// used for the page fault unit test, don't use outside of tests! /// used for the page fault unit test, don't use outside of tests!
void SetJit(JitBase* jit); void SetJit(std::unique_ptr<JitBase> jit);
void Shutdown(); void Shutdown();
private: private:
JitBase* m_jit = nullptr; std::unique_ptr<JitBase> m_jit;
Core::System& m_system; Core::System& m_system;
}; };

View File

@ -75,8 +75,10 @@ TEST(PageFault, PageFault)
EXPECT_NE(data, nullptr); EXPECT_NE(data, nullptr);
Common::WriteProtectMemory(data, PAGE_GRAN, false); Common::WriteProtectMemory(data, PAGE_GRAN, false);
PageFaultFakeJit pfjit(Core::System::GetInstance()); auto& system = Core::System::GetInstance();
Core::System::GetInstance().GetJitInterface().SetJit(&pfjit); auto unique_pfjit = std::make_unique<PageFaultFakeJit>(system);
auto& pfjit = *unique_pfjit;
system.GetJitInterface().SetJit(std::move(unique_pfjit));
pfjit.m_data = data; pfjit.m_data = data;
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
@ -88,7 +90,6 @@ TEST(PageFault, PageFault)
}; };
EMM::UninstallExceptionHandler(); EMM::UninstallExceptionHandler();
Core::System::GetInstance().GetJitInterface().SetJit(nullptr);
fmt::print("page fault timing:\n"); fmt::print("page fault timing:\n");
fmt::print("start->HandleFault {} ns\n", fmt::print("start->HandleFault {} ns\n",
@ -98,4 +99,6 @@ TEST(PageFault, PageFault)
fmt::print("HandleFault->end {} ns\n", fmt::print("HandleFault->end {} ns\n",
difference_in_nanoseconds(pfjit.m_post_unprotect_time, end)); difference_in_nanoseconds(pfjit.m_post_unprotect_time, end));
fmt::print("total {} ns\n", difference_in_nanoseconds(start, end)); fmt::print("total {} ns\n", difference_in_nanoseconds(start, end));
system.GetJitInterface().SetJit(nullptr);
} }