From 0d9faca38da7023fa39fc93383051a04458a3518 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Wed, 24 Jul 2024 00:39:03 +0800 Subject: [PATCH] Fix GarbageCollectCache got removed Co-authored-by: JingMatrix --- .../jni/art/runtime/jit/jit_code_cache.cxx | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lsplant/src/main/jni/art/runtime/jit/jit_code_cache.cxx b/lsplant/src/main/jni/art/runtime/jit/jit_code_cache.cxx index f28663419..abd8d981c 100644 --- a/lsplant/src/main/jni/art/runtime/jit/jit_code_cache.cxx +++ b/lsplant/src/main/jni/art/runtime/jit/jit_code_cache.cxx @@ -22,14 +22,23 @@ export class JitCodeCache { } } + void MoveObsoleteMethods() { + auto movements = GetJitMovements(); + LOGD("Before jit cache collection, moving %zu hooked methods", movements.size()); + for (auto [target, backup] : movements) { + MoveObsoleteMethod(this, target, backup); + } + } + CREATE_MEM_HOOK_STUB_ENTRY("_ZN3art3jit12JitCodeCache19GarbageCollectCacheEPNS_6ThreadE", void, GarbageCollectCache, (JitCodeCache * thiz, Thread *self), { - auto movements = GetJitMovements(); - LOGD("Before jit cache gc, moving %zu hooked methods", - movements.size()); - for (auto [target, backup] : movements) { - MoveObsoleteMethod(thiz, target, backup); - } + thiz->MoveObsoleteMethods(); + backup(thiz, self); + }); + + CREATE_MEM_HOOK_STUB_ENTRY("_ZN3art3jit12JitCodeCache12DoCollectionEPNS_6ThreadE", void, + DoCollection, (JitCodeCache * thiz, Thread *self), { + thiz->MoveObsoleteMethods(); backup(thiz, self); }); @@ -45,7 +54,7 @@ export class JitCodeCache { } } if (sdk_int >= __ANDROID_API_N__) [[likely]] { - if (!HookSyms(handler, GarbageCollectCache)) [[unlikely]] { + if (!HookSyms(handler, GarbageCollectCache, DoCollection)) [[unlikely]] { return false; } }