2022-02-16 07:24:35 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
namespace lsplant::art::jit {
|
|
|
|
class JitCodeCache {
|
|
|
|
CREATE_MEM_FUNC_SYMBOL_ENTRY(void, MoveObsoleteMethod, JitCodeCache *thiz,
|
2022-02-19 03:47:26 +08:00
|
|
|
ArtMethod *old_method, ArtMethod *new_method) {
|
|
|
|
if (MoveObsoleteMethodSym) [[likely]]
|
|
|
|
MoveObsoleteMethodSym(thiz, old_method, new_method);
|
2022-02-16 07:24:35 +08:00
|
|
|
}
|
|
|
|
|
2022-02-19 03:47:26 +08:00
|
|
|
CREATE_MEM_HOOK_STUB_ENTRY("_ZN3art3jit12JitCodeCache19GarbageCollectCacheEPNS_6ThreadE", void,
|
|
|
|
GarbageCollectCache, (JitCodeCache * thiz, Thread *self), {
|
|
|
|
LOGD("Before jit cache gc, moving hooked methods");
|
|
|
|
for (auto [target, backup] : GetJitMovements()) {
|
|
|
|
MoveObsoleteMethod(thiz, target, backup);
|
|
|
|
}
|
|
|
|
backup(thiz, self);
|
|
|
|
});
|
2022-02-16 07:24:35 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static bool Init(const HookHandler &handler) {
|
2022-02-19 03:47:26 +08:00
|
|
|
if (!RETRIEVE_MEM_FUNC_SYMBOL(
|
|
|
|
MoveObsoleteMethod,
|
|
|
|
"_ZN3art3jit12JitCodeCache18MoveObsoleteMethodEPNS_9ArtMethodES3_")) {
|
2022-02-16 07:24:35 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!HookSyms(handler, GarbageCollectCache)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2022-02-19 03:47:26 +08:00
|
|
|
} // namespace lsplant::art::jit
|