java_lang_reflect_Method.cc revision ea46f950e7a51585db293cd7f047de190a482414
1f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom/* 2f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * Copyright (C) 2008 The Android Open Source Project 3f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * 4f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License"); 5f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * you may not use this file except in compliance with the License. 6f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * You may obtain a copy of the License at 7f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * 8f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * http://www.apache.org/licenses/LICENSE-2.0 9f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * 10f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * Unless required by applicable law or agreed to in writing, software 11f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS, 12f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * See the License for the specific language governing permissions and 14f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * limitations under the License. 15f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom */ 16f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 17f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom#include "class_linker.h" 18eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes#include "jni_internal.h" 19ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "mirror/art_method.h" 20ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "mirror/art_method-inl.h" 212dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/class-inl.h" 222dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object-inl.h" 232dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object_array-inl.h" 242dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/proxy.h" 256d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers#include "object_utils.h" 26418d20fc407052d4152157f61e7453359f902383Elliott Hughes#include "reflection.h" 2700f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers#include "scoped_thread_state_change.h" 28ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "well_known_classes.h" 29f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 30f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromnamespace art { 31f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 32ea46f950e7a51585db293cd7f047de190a482414Brian Carlstromstatic jobject Method_invoke(JNIEnv* env, 33ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom jobject javaMethod, jobject javaReceiver, jobject javaArgs) { 3400f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers ScopedObjectAccess soa(env); 3500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs); 36f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} 37f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 380512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughesstatic jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) { 3900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers ScopedObjectAccess soa(env); 40ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom jobject art_method = soa.Env()->GetObjectField( 41ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom javaMethod, WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod); 42ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom 43ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom mirror::ArtMethod* proxy_method = soa.Decode<mirror::Object*>(art_method)->AsArtMethod(); 44c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers CHECK(proxy_method->GetDeclaringClass()->IsProxyClass()); 452dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::SynthesizedProxyClass* proxy_class = 462dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers down_cast<mirror::SynthesizedProxyClass*>(proxy_method->GetDeclaringClass()); 47c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers int throws_index = -1; 48c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers size_t num_virt_methods = proxy_class->NumVirtualMethods(); 49c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers for (size_t i = 0; i < num_virt_methods; i++) { 50c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers if (proxy_class->GetVirtualMethod(i) == proxy_method) { 51c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers throws_index = i; 52c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers break; 53c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers } 54c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers } 55c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers CHECK_NE(throws_index, -1); 56ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom mirror::ObjectArray<mirror::Class>* declared_exceptions = 57ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom proxy_class->GetThrows()->Get(throws_index); 5850b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self())); 59c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers} 60c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers 61f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromstatic JNINativeMethod gMethods[] = { 626d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"), 63c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"), 64f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom}; 65f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 66f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromvoid register_java_lang_reflect_Method(JNIEnv* env) { 67eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes REGISTER_NATIVE_METHODS("java/lang/reflect/Method"); 68f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} 69f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 70f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} // namespace art 71