diff options
author | Jeff Hao <jeffhao@google.com> | 2014-03-13 22:39:08 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-03-13 22:39:08 +0000 |
commit | 53fca11882e634b67aca4f112585413a1918b5ad (patch) | |
tree | a32d5b33d2dfc6067a73c40ae79d9ca4adc495da | |
parent | 27d08a924481389a45d5fbca43ffdc72496038d1 (diff) | |
parent | 8151b8fe2987e01ed915ea2053ed42fac95ff3db (diff) | |
download | android_art-53fca11882e634b67aca4f112585413a1918b5ad.tar.gz android_art-53fca11882e634b67aca4f112585413a1918b5ad.tar.bz2 android_art-53fca11882e634b67aca4f112585413a1918b5ad.zip |
Merge "Fix FindFieldID to use class's classloader to find field type." into klp-dev
-rw-r--r-- | runtime/jni_internal.cc | 4 | ||||
-rw-r--r-- | test/JniTest/JniTest.java | 12 | ||||
-rw-r--r-- | test/JniTest/jni_test.cc | 36 |
3 files changed, 50 insertions, 2 deletions
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc index 412f96e4af..df863f07b7 100644 --- a/runtime/jni_internal.cc +++ b/runtime/jni_internal.cc @@ -291,8 +291,8 @@ static jfieldID FindFieldID(const ScopedObjectAccess& soa, jclass jni_class, con Class* field_type; ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); if (sig[1] != '\0') { - ClassLoader* cl = GetClassLoader(soa); - field_type = class_linker->FindClass(sig, cl); + SirtRef<mirror::ClassLoader> class_loader(soa.Self(), c->GetClassLoader()); + field_type = class_linker->FindClass(sig, class_loader.get()); } else { field_type = class_linker->FindPrimitiveClass(*sig); } diff --git a/test/JniTest/JniTest.java b/test/JniTest/JniTest.java index a1b1f0c69d..9194da581f 100644 --- a/test/JniTest/JniTest.java +++ b/test/JniTest/JniTest.java @@ -20,12 +20,24 @@ class JniTest { public static void main(String[] args) { System.loadLibrary("arttest"); testFindClassOnAttachedNativeThread(); + testFindFieldOnAttachedNativeThread(); testCallStaticVoidMethodOnSubClass(); testGetMirandaMethod(); } private static native void testFindClassOnAttachedNativeThread(); + private static boolean testFindFieldOnAttachedNativeThreadField; + + private static void testFindFieldOnAttachedNativeThread() { + testFindFieldOnAttachedNativeThreadNative(); + if (!testFindFieldOnAttachedNativeThreadField) { + throw new AssertionError(); + } + } + + private static native void testFindFieldOnAttachedNativeThreadNative(); + private static void testCallStaticVoidMethodOnSubClass() { testCallStaticVoidMethodOnSubClassNative(); if (!testCallStaticVoidMethodOnSubClass_SuperClass.executed) { diff --git a/test/JniTest/jni_test.cc b/test/JniTest/jni_test.cc index cfcbb64f38..d15e180c02 100644 --- a/test/JniTest/jni_test.cc +++ b/test/JniTest/jni_test.cc @@ -67,6 +67,42 @@ extern "C" JNIEXPORT void JNICALL Java_JniTest_testFindClassOnAttachedNativeThre assert(pthread_join_result == 0); } +static void* testFindFieldOnAttachedNativeThread(void*) { + assert(jvm != NULL); + + JNIEnv* env = NULL; + JavaVMAttachArgs args = { JNI_VERSION_1_6, __FUNCTION__, NULL }; + int attach_result = jvm->AttachCurrentThread(&env, &args); + assert(attach_result == 0); + + jclass clazz = env->FindClass("JniTest"); + assert(clazz != NULL); + assert(!env->ExceptionCheck()); + + jfieldID field = env->GetStaticFieldID(clazz, "testFindFieldOnAttachedNativeThreadField", "Z"); + assert(field != NULL); + assert(!env->ExceptionCheck()); + + env->SetStaticBooleanField(clazz, field, JNI_TRUE); + + int detach_result = jvm->DetachCurrentThread(); + assert(detach_result == 0); + return NULL; +} + +extern "C" JNIEXPORT void JNICALL Java_JniTest_testFindFieldOnAttachedNativeThreadNative(JNIEnv*, + jclass) { + pthread_t pthread; + int pthread_create_result = pthread_create(&pthread, + NULL, + testFindFieldOnAttachedNativeThread, + NULL); + assert(pthread_create_result == 0); + int pthread_join_result = pthread_join(pthread, NULL); + assert(pthread_join_result == 0); +} + + // http://b/11243757 extern "C" JNIEXPORT void JNICALL Java_JniTest_testCallStaticVoidMethodOnSubClassNative(JNIEnv* env, jclass) { |