From f3d4d4eaa82d8a66f77c814c21f9d75d108de445 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Wed, 26 Feb 2020 15:53:47 -0400 Subject: ARM_Interface: Cache the JITs instead of deleting/recreating. This was a bug inherited from citra which was fixed by then at some time. This commit corrects such bug and ensures JITs are correctly recycled. --- src/core/arm/dynarmic/arm_dynarmic.cpp | 11 +++++++++-- src/core/arm/dynarmic/arm_dynarmic.h | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/core/arm') diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 29eaf74e5..7c9d59ab8 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -132,7 +132,7 @@ public: u64 tpidr_el0 = 0; }; -std::unique_ptr ARM_Dynarmic::MakeJit(Common::PageTable& page_table, +std::shared_ptr ARM_Dynarmic::MakeJit(Common::PageTable& page_table, std::size_t address_space_bits) const { Dynarmic::A64::UserConfig config; @@ -159,7 +159,7 @@ std::unique_ptr ARM_Dynarmic::MakeJit(Common::PageTable& pag // Unpredictable instructions config.define_unpredictable_behaviour = true; - return std::make_unique(config); + return std::make_shared(config); } MICROPROFILE_DEFINE(ARM_Jit_Dynarmic, "ARM JIT", "Dynarmic", MP_RGB(255, 64, 64)); @@ -267,7 +267,14 @@ void ARM_Dynarmic::ClearExclusiveState() { void ARM_Dynarmic::PageTableChanged(Common::PageTable& page_table, std::size_t new_address_space_size_in_bits) { + auto key = std::make_pair(&page_table, new_address_space_size_in_bits); + auto iter = jit_cache.find(key); + if (iter != jit_cache.end()) { + jit = iter->second; + return; + } jit = MakeJit(page_table, new_address_space_size_in_bits); + jit_cache.emplace(key, jit); } DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(Memory::Memory& memory_, std::size_t core_count) diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index 9cd475cfb..ffbb69d76 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -5,9 +5,12 @@ #pragma once #include +#include + #include #include #include "common/common_types.h" +#include "common/hash.h" #include "core/arm/arm_interface.h" #include "core/arm/exclusive_monitor.h" #include "core/arm/unicorn/arm_unicorn.h" @@ -22,6 +25,10 @@ class ARM_Dynarmic_Callbacks; class DynarmicExclusiveMonitor; class System; +using JitCacheKey = std::pair; +using JitCacheType = + std::unordered_map, Common::PairHash>; + class ARM_Dynarmic final : public ARM_Interface { public: ARM_Dynarmic(System& system, ExclusiveMonitor& exclusive_monitor, std::size_t core_index); @@ -53,12 +60,13 @@ public: std::size_t new_address_space_size_in_bits) override; private: - std::unique_ptr MakeJit(Common::PageTable& page_table, + std::shared_ptr MakeJit(Common::PageTable& page_table, std::size_t address_space_bits) const; friend class ARM_Dynarmic_Callbacks; std::unique_ptr cb; - std::unique_ptr jit; + JitCacheType jit_cache; + std::shared_ptr jit; ARM_Unicorn inner_unicorn; std::size_t core_index; -- cgit v1.2.3