Skip to content

Commit fb188e5

Browse files
authored
Merge pull request #20504 from hrydgard/ir-interpreter-switch-fix
Correct the clearing/destruction order when switching CPU cores.
2 parents 28caa6f + 6e84cd7 commit fb188e5

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

Common/Log.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ __attribute__((format(printf, 5, 6)))
140140
// They can have a value between 0 and 15.
141141
enum class DebugCounter {
142142
APP_BOOT = 0,
143-
GAME_BOOT = 0,
144-
GAME_SHUTDOWN = 0,
143+
GAME_BOOT = 1,
144+
GAME_SHUTDOWN = 2,
145+
CPUCORE_SWITCHES = 3,
145146
};
146147

147148
bool HitAnyAsserts();

Core/MIPS/IR/IRJit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class IRBlock {
119119
class IRBlockCache : public JitBlockCacheDebugInterface {
120120
public:
121121
IRBlockCache(bool compileToNative);
122+
~IRBlockCache() {
123+
Clear();
124+
}
122125

123126
void Clear();
124127
std::vector<int> FindInvalidatedBlockNumbers(u32 address, u32 length);

Core/MIPS/MIPS.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -228,39 +228,39 @@ void MIPSState::UpdateCore(CPUCore desired) {
228228
return;
229229
}
230230

231+
IncrementDebugCounter(DebugCounter::CPUCORE_SWITCHES);
232+
233+
// Get rid of the old JIT first, before switching.
234+
{
235+
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
236+
if (MIPSComp::jit) {
237+
delete MIPSComp::jit;
238+
MIPSComp::jit = nullptr;
239+
}
240+
}
241+
231242
PSP_CoreParameter().cpuCore = desired;
232-
MIPSComp::JitInterface *oldjit = MIPSComp::jit;
233-
MIPSComp::JitInterface *newjit = nullptr;
234243

244+
MIPSComp::JitInterface *newjit = nullptr;
235245
switch (PSP_CoreParameter().cpuCore) {
236246
case CPUCore::JIT:
237247
case CPUCore::JIT_IR:
238248
INFO_LOG(Log::CPU, "Switching to JIT%s", PSP_CoreParameter().cpuCore == CPUCore::JIT_IR ? " IR" : "");
239-
if (oldjit) {
240-
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
241-
MIPSComp::jit = nullptr;
242-
delete oldjit;
243-
}
244249
newjit = MIPSComp::CreateNativeJit(this, PSP_CoreParameter().cpuCore == CPUCore::JIT_IR);
245250
break;
246251

247252
case CPUCore::IR_INTERPRETER:
248253
INFO_LOG(Log::CPU, "Switching to IR interpreter");
249-
if (oldjit) {
250-
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
251-
MIPSComp::jit = nullptr;
252-
delete oldjit;
253-
}
254254
newjit = new MIPSComp::IRJit(this, false);
255255
break;
256256

257257
case CPUCore::INTERPRETER:
258258
INFO_LOG(Log::CPU, "Switching to interpreter");
259-
if (oldjit) {
260-
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
261-
MIPSComp::jit = nullptr;
262-
delete oldjit;
263-
}
259+
// Leaving newjit as null.
260+
break;
261+
262+
default:
263+
WARN_LOG(Log::CPU, "Invalid value for cpuCore, falling back to interpreter");
264264
break;
265265
}
266266

0 commit comments

Comments
 (0)