Skip to content

Commit

Permalink
Re-enable IRJit arena overflow check, now with the correct size
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jun 7, 2024
1 parent 5922453 commit da67689
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 15 additions & 0 deletions Core/MIPS/IR/IRJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ IRBlockCache::IRBlockCache() {
// arena_.reserve(1024 * 1024 * 2);
}

int IRBlockCache::AllocateBlock(int emAddr, u32 origSize, const std::vector<IRInst> &inst) {
// We have 24 bits to represent offsets with.
const u32 MAX_ARENA_SIZE = 0x1000000 - 1;
int offset = (int)arena_.size();
if (offset >= MAX_ARENA_SIZE) {
WARN_LOG(JIT, "Filled JIT arena, restarting");
return -1;
}
for (int i = 0; i < inst.size(); i++) {
arena_.push_back(inst[i]);
}
blocks_.push_back(IRBlock(emAddr, origSize, offset, (u16)inst.size()));
return (int)blocks_.size() - 1;
}

int IRBlockCache::GetBlockNumFromOffset(int offset) const {
// Block offsets are always in rising order (we don't go back and replace them when invalidated). So we can binary search.
int low = 0;
Expand Down
17 changes: 9 additions & 8 deletions Core/MIPS/IR/IRJit.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@
#include "stddef.h"
#endif

// Very expensive, time-profiles every block.
// Not to be released with this enabled.
//
// #define IR_PROFILING

// Try to catch obvious misses of be above rule.
#if defined(IR_PROFILING) && defined(GOLD)
#error
#endif

namespace MIPSComp {

// TODO : Use arena allocators. For now let's just malloc.
Expand Down Expand Up @@ -112,14 +120,7 @@ class IRBlockCache : public JitBlockCacheDebugInterface {
std::vector<int> FindInvalidatedBlockNumbers(u32 address, u32 length);
void FinalizeBlock(int blockNum, bool preload = false);
int GetNumBlocks() const override { return (int)blocks_.size(); }
int AllocateBlock(int emAddr, u32 origSize, const std::vector<IRInst> &inst) {
int offset = (int)arena_.size();
for (int i = 0; i < inst.size(); i++) {
arena_.push_back(inst[i]);
}
blocks_.push_back(IRBlock(emAddr, origSize, offset, (u16)inst.size()));
return (int)blocks_.size() - 1;
}
int AllocateBlock(int emAddr, u32 origSize, const std::vector<IRInst> &inst);
IRBlock *GetBlock(int blockNum) {
if (blockNum >= 0 && blockNum < (int)blocks_.size()) {
return &blocks_[blockNum];
Expand Down

0 comments on commit da67689

Please sign in to comment.