From 7f50c070b232b68df04609f60f02db559e97cc4f Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 25 Mar 2023 16:17:46 +0100 Subject: [PATCH] JitInterface: Convert m_jit to unique_ptr. --- Source/Core/Core/PowerPC/JitInterface.cpp | 19 +++++++++---------- Source/Core/Core/PowerPC/JitInterface.h | 5 +++-- Source/UnitTests/Core/PageFaultTest.cpp | 9 ++++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitInterface.cpp b/Source/Core/Core/PowerPC/JitInterface.cpp index 2f56cf4a95..beec9559e6 100644 --- a/Source/Core/Core/PowerPC/JitInterface.cpp +++ b/Source/Core/Core/PowerPC/JitInterface.cpp @@ -46,9 +46,9 @@ JitInterface::JitInterface(Core::System& system) : m_system(system) JitInterface::~JitInterface() = default; -void JitInterface::SetJit(JitBase* jit) +void JitInterface::SetJit(std::unique_ptr jit) { - m_jit = jit; + m_jit = std::move(jit); } void JitInterface::DoState(PointerWrap& p) @@ -65,31 +65,31 @@ CPUCoreBase* JitInterface::InitJitCore(PowerPC::CPUCore core) { #if _M_X86 case PowerPC::CPUCore::JIT64: - m_jit = new Jit64(system); + m_jit = std::make_unique(system); break; #endif #if _M_ARM_64 case PowerPC::CPUCore::JITARM64: - m_jit = new JitArm64(system); + m_jit = std::make_unique(system); break; #endif case PowerPC::CPUCore::CachedInterpreter: - m_jit = new CachedInterpreter(system); + m_jit = std::make_unique(system); break; default: // Under this case the caller overrides the CPU core to the default and logs that // it performed the override. - m_jit = nullptr; + m_jit.reset(); return nullptr; } m_jit->Init(); - return m_jit; + return m_jit.get(); } CPUCoreBase* JitInterface::GetCore() const { - return m_jit; + return m_jit.get(); } void JitInterface::SetProfilingState(ProfilingState state) @@ -319,7 +319,6 @@ void JitInterface::Shutdown() if (m_jit) { m_jit->Shutdown(); - delete m_jit; - m_jit = nullptr; + m_jit.reset(); } } diff --git a/Source/Core/Core/PowerPC/JitInterface.h b/Source/Core/Core/PowerPC/JitInterface.h index 9551caadbc..1ba54cc2c9 100644 --- a/Source/Core/Core/PowerPC/JitInterface.h +++ b/Source/Core/Core/PowerPC/JitInterface.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include @@ -94,11 +95,11 @@ public: static void CompileExceptionCheckFromJIT(JitInterface& jit_interface, ExceptionType type); /// used for the page fault unit test, don't use outside of tests! - void SetJit(JitBase* jit); + void SetJit(std::unique_ptr jit); void Shutdown(); private: - JitBase* m_jit = nullptr; + std::unique_ptr m_jit; Core::System& m_system; }; diff --git a/Source/UnitTests/Core/PageFaultTest.cpp b/Source/UnitTests/Core/PageFaultTest.cpp index b9e37a754c..ab0cdd7bcc 100644 --- a/Source/UnitTests/Core/PageFaultTest.cpp +++ b/Source/UnitTests/Core/PageFaultTest.cpp @@ -75,8 +75,10 @@ TEST(PageFault, PageFault) EXPECT_NE(data, nullptr); Common::WriteProtectMemory(data, PAGE_GRAN, false); - PageFaultFakeJit pfjit(Core::System::GetInstance()); - Core::System::GetInstance().GetJitInterface().SetJit(&pfjit); + auto& system = Core::System::GetInstance(); + auto unique_pfjit = std::make_unique(system); + auto& pfjit = *unique_pfjit; + system.GetJitInterface().SetJit(std::move(unique_pfjit)); pfjit.m_data = data; auto start = std::chrono::high_resolution_clock::now(); @@ -88,7 +90,6 @@ TEST(PageFault, PageFault) }; EMM::UninstallExceptionHandler(); - Core::System::GetInstance().GetJitInterface().SetJit(nullptr); fmt::print("page fault timing:\n"); fmt::print("start->HandleFault {} ns\n", @@ -98,4 +99,6 @@ TEST(PageFault, PageFault) fmt::print("HandleFault->end {} ns\n", difference_in_nanoseconds(pfjit.m_post_unprotect_time, end)); fmt::print("total {} ns\n", difference_in_nanoseconds(start, end)); + + system.GetJitInterface().SetJit(nullptr); }