Skip to content

Correct the clearing/destruction order when switching CPU cores. #20504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Common/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ __attribute__((format(printf, 5, 6)))
// They can have a value between 0 and 15.
enum class DebugCounter {
APP_BOOT = 0,
GAME_BOOT = 0,
GAME_SHUTDOWN = 0,
GAME_BOOT = 1,
GAME_SHUTDOWN = 2,
CPUCORE_SWITCHES = 3,
};

bool HitAnyAsserts();
Expand Down
3 changes: 3 additions & 0 deletions Core/MIPS/IR/IRJit.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class IRBlock {
class IRBlockCache : public JitBlockCacheDebugInterface {
public:
IRBlockCache(bool compileToNative);
~IRBlockCache() {
Clear();
}

void Clear();
std::vector<int> FindInvalidatedBlockNumbers(u32 address, u32 length);
Expand Down
34 changes: 17 additions & 17 deletions Core/MIPS/MIPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,39 +228,39 @@ void MIPSState::UpdateCore(CPUCore desired) {
return;
}

IncrementDebugCounter(DebugCounter::CPUCORE_SWITCHES);

// Get rid of the old JIT first, before switching.
{
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
if (MIPSComp::jit) {
delete MIPSComp::jit;
MIPSComp::jit = nullptr;
}
}

PSP_CoreParameter().cpuCore = desired;
MIPSComp::JitInterface *oldjit = MIPSComp::jit;
MIPSComp::JitInterface *newjit = nullptr;

MIPSComp::JitInterface *newjit = nullptr;
switch (PSP_CoreParameter().cpuCore) {
case CPUCore::JIT:
case CPUCore::JIT_IR:
INFO_LOG(Log::CPU, "Switching to JIT%s", PSP_CoreParameter().cpuCore == CPUCore::JIT_IR ? " IR" : "");
if (oldjit) {
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
MIPSComp::jit = nullptr;
delete oldjit;
}
newjit = MIPSComp::CreateNativeJit(this, PSP_CoreParameter().cpuCore == CPUCore::JIT_IR);
break;

case CPUCore::IR_INTERPRETER:
INFO_LOG(Log::CPU, "Switching to IR interpreter");
if (oldjit) {
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
MIPSComp::jit = nullptr;
delete oldjit;
}
newjit = new MIPSComp::IRJit(this, false);
break;

case CPUCore::INTERPRETER:
INFO_LOG(Log::CPU, "Switching to interpreter");
if (oldjit) {
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
MIPSComp::jit = nullptr;
delete oldjit;
}
// Leaving newjit as null.
break;

default:
WARN_LOG(Log::CPU, "Invalid value for cpuCore, falling back to interpreter");
break;
}

Expand Down
Loading