Skip to content

Commit

Permalink
Merge pull request #26 from WaterlooBridge/master
Browse files Browse the repository at this point in the history
add sync for MovingGC Clone
  • Loading branch information
asLody authored May 7, 2019
2 parents 8f7e7b0 + 9ffd7fe commit 02f108c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion whale/src/android/art/art_hook_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ArtHookParam final {
u4 origin_code_item_off;
jobject origin_method_;
jobject hooked_method_;
ptr_t decl_class_;
volatile ptr_t decl_class_;
jobject class_Loader_;
jmethodID hooked_native_method_;
jmethodID origin_native_method_;
Expand Down
4 changes: 4 additions & 0 deletions whale/src/android/art/art_jni_trampoline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace whale {
namespace art {

static void UnBoxValue(JNIEnv *env, jvalue *jv, jobject obj, char type) {
if (obj == nullptr) {
jv->l = obj;
return;
}
switch (type) {
case 'I':
jv->i = Types::FromInteger(env, obj);
Expand Down
31 changes: 18 additions & 13 deletions whale/src/android/art/art_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ bool ArtRuntime::OnLoad(JavaVM *vm, JNIEnv *env, jclass java_class) {
CHECK_FIELD(quick_generic_jni_trampoline, nullptr)
class_linker_objects_.quick_generic_jni_trampoline_ = quick_generic_jni_trampoline;

pthread_mutex_init(&mutex, nullptr);
EnforceDisableHiddenAPIPolicy();
return true;

Expand Down Expand Up @@ -267,19 +268,23 @@ ArtRuntime::InvokeOriginalMethod(jlong slot, jobject this_object, jobjectArray a
ArtMethod hooked_method(param->hooked_native_method_);
ptr_t decl_class = hooked_method.GetDeclaringClass();
if (param->decl_class_ != decl_class) {
ScopedSuspendAll suspend_all;
LOG(INFO)
<< "Notice: MovingGC cause the GcRoot References changed.";
jobject origin_java_method = hooked_method.Clone(env, param->origin_access_flags);
jmethodID origin_jni_method = env->FromReflectedMethod(origin_java_method);
ArtMethod origin_method(origin_jni_method);
origin_method.SetEntryPointFromQuickCompiledCode(param->origin_compiled_code_);
origin_method.SetEntryPointFromJni(param->origin_jni_code_);
origin_method.SetDexCodeItemOffset(param->origin_code_item_off);
param->origin_native_method_ = origin_jni_method;
env->DeleteGlobalRef(param->origin_method_);
param->origin_method_ = env->NewGlobalRef(origin_java_method);
param->decl_class_ = decl_class;
pthread_mutex_lock(&mutex);
if (param->decl_class_ != decl_class) {
ScopedSuspendAll suspend_all;
LOG(INFO)
<< "Notice: MovingGC cause the GcRoot References changed.";
jobject origin_java_method = hooked_method.Clone(env, param->origin_access_flags);
jmethodID origin_jni_method = env->FromReflectedMethod(origin_java_method);
ArtMethod origin_method(origin_jni_method);
origin_method.SetEntryPointFromQuickCompiledCode(param->origin_compiled_code_);
origin_method.SetEntryPointFromJni(param->origin_jni_code_);
origin_method.SetDexCodeItemOffset(param->origin_code_item_off);
param->origin_native_method_ = origin_jni_method;
env->DeleteGlobalRef(param->origin_method_);
param->origin_method_ = env->NewGlobalRef(origin_java_method);
param->decl_class_ = decl_class;
}
pthread_mutex_unlock(&mutex);
}

jobject ret = env->CallNonvirtualObjectMethod(
Expand Down
1 change: 1 addition & 0 deletions whale/src/android/art/art_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class ArtRuntime final {
ClassLinkerObjects class_linker_objects_;
ArtMethodOffsets method_offset_;
std::map<jmethodID, ArtHookParam *> hooked_method_map_;
pthread_mutex_t mutex;

bool EnforceDisableHiddenAPIPolicyImpl();

Expand Down

0 comments on commit 02f108c

Please sign in to comment.