Unverified Commit 564a3fd3 authored by ganyao114's avatar ganyao114 Committed by GitHub

Merge pull request #40 from virjar/master

stopTheWorld after jit compile to avoid jit compile dead lock
parents e6bf7f4b 8c679f1b
...@@ -180,9 +180,6 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or ...@@ -180,9 +180,6 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or
int mode = reinterpret_cast<int>(hookMode); int mode = reinterpret_cast<int>(hookMode);
//suspend other threads
SandHook::StopTheWorld stopTheWorld;
if (mode == INLINE) { if (mode == INLINE) {
if (!origin->isCompiled()) { if (!origin->isCompiled()) {
if (SDK_INT >= ANDROID_N) { if (SDK_INT >= ANDROID_N) {
...@@ -219,6 +216,8 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or ...@@ -219,6 +216,8 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or
label_hook: label_hook:
//suspend other threads
SandHook::StopTheWorld stopTheWorld;
if (isInlineHook && trampolineManager.canSafeInline(origin)) { if (isInlineHook && trampolineManager.canSafeInline(origin)) {
return doHookWithInline(env, origin, hook, backup) ? INLINE : -1; return doHookWithInline(env, origin, hook, backup) ? INLINE : -1;
} else { } else {
......
...@@ -157,17 +157,23 @@ extern "C" { ...@@ -157,17 +157,23 @@ extern "C" {
if (jitCompilerHandle == nullptr) if (jitCompilerHandle == nullptr)
return false; return false;
if (!canCompile()) return false; if (!canCompile()) return false;
//backup thread flag and state because of jit compile function will modify thread state
uint32_t old_flag_and_state = *((uint32_t *) thread);
bool ret;
if (SDK_INT >= ANDROID_Q) { if (SDK_INT >= ANDROID_Q) {
if (jitCompileMethodQ == nullptr) { if (jitCompileMethodQ == nullptr) {
return false; return false;
} }
return jitCompileMethodQ(jitCompilerHandle, artMethod, thread, false, false); ret = jitCompileMethodQ(jitCompilerHandle, artMethod, thread, false, false);
} else { } else {
if (jitCompileMethod == nullptr) { if (jitCompileMethod == nullptr) {
return false; return false;
} }
return jitCompileMethod(jitCompilerHandle, artMethod, thread, false); ret= jitCompileMethod(jitCompilerHandle, artMethod, thread, false);
} }
memcpy(thread, &old_flag_and_state, 4);
return ret;
} }
void suspendVM() { void suspendVM() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment