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" 24418d20fc407052d4152157f61e7453359f902383Elliott Hughes#include "reflection.h" 2553b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers#include "scoped_fast_native_object_access.h" 26ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "well_known_classes.h" 27f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 28f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromnamespace art { 29f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 3011d5d8fffe41cc7daadbfa2ca98ecb978f3029afJeff Haostatic jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, 3111d5d8fffe41cc7daadbfa2ca98ecb978f3029afJeff Hao jobject javaArgs, jboolean accessible) { 3253b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers ScopedFastNativeObjectAccess soa(env); 33cb4581aa13d6f43f705535818a4d0893d551be3aJeff Hao return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs, (accessible == JNI_TRUE)); 34f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} 35f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 360512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughesstatic jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) { 3753b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers ScopedFastNativeObjectAccess soa(env); 3862f0512bf6d9bc6141358bf22e93afa70dc58b1aIan Rogers mirror::ArtMethod* proxy_method = mirror::ArtMethod::FromReflectedMethod(soa, javaMethod); 39c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers CHECK(proxy_method->GetDeclaringClass()->IsProxyClass()); 4098d1cc8033251c93786e2fa8c59a2e555a9493beMingyao Yang mirror::Class* proxy_class = proxy_method->GetDeclaringClass(); 41c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers int throws_index = -1; 42c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers size_t num_virt_methods = proxy_class->NumVirtualMethods(); 43c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers for (size_t i = 0; i < num_virt_methods; i++) { 44c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers if (proxy_class->GetVirtualMethod(i) == proxy_method) { 45c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers throws_index = i; 46c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers break; 47c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers } 48c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers } 49c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers CHECK_NE(throws_index, -1); 50ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom mirror::ObjectArray<mirror::Class>* declared_exceptions = 51ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom proxy_class->GetThrows()->Get(throws_index); 5250b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self())); 53c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers} 54c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers 55f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromstatic JNINativeMethod gMethods[] = { 5611d5d8fffe41cc7daadbfa2ca98ecb978f3029afJeff Hao NATIVE_METHOD(Method, invoke, "!(Ljava/lang/Object;[Ljava/lang/Object;Z)Ljava/lang/Object;"), 5753b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers NATIVE_METHOD(Method, getExceptionTypesNative, "!()[Ljava/lang/Class;"), 58f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom}; 59f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 60f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromvoid register_java_lang_reflect_Method(JNIEnv* env) { 61eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes REGISTER_NATIVE_METHODS("java/lang/reflect/Method"); 62f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} 63f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 64f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} // namespace art 65