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 17277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe#include "java_lang_reflect_Method.h" 18277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe 193d21bdf8894e780d349c481e5c9e29fe1556051cMathieu Chartier#include "art_method-inl.h" 20f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom#include "class_linker.h" 21eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes#include "jni_internal.h" 222dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/class-inl.h" 232dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object-inl.h" 242dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object_array-inl.h" 25418d20fc407052d4152157f61e7453359f902383Elliott Hughes#include "reflection.h" 2653b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers#include "scoped_fast_native_object_access.h" 27ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "well_known_classes.h" 28f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 29f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromnamespace art { 30f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 3111d5d8fffe41cc7daadbfa2ca98ecb978f3029afJeff Haostatic jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, 32fc58af45e342ba9e18bbdf597f205a58ec731658Mathieu Chartier jobject javaArgs) { 3353b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers ScopedFastNativeObjectAccess soa(env); 34fc58af45e342ba9e18bbdf597f205a58ec731658Mathieu Chartier return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs); 35f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} 36f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 370512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughesstatic jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) { 3853b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers ScopedFastNativeObjectAccess soa(env); 393d21bdf8894e780d349c481e5c9e29fe1556051cMathieu Chartier ArtMethod* proxy_method = ArtMethod::FromReflectedMethod(soa, javaMethod); 40c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers CHECK(proxy_method->GetDeclaringClass()->IsProxyClass()); 4198d1cc8033251c93786e2fa8c59a2e555a9493beMingyao Yang mirror::Class* proxy_class = proxy_method->GetDeclaringClass(); 42c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers int throws_index = -1; 433d21bdf8894e780d349c481e5c9e29fe1556051cMathieu Chartier size_t i = 0; 443d21bdf8894e780d349c481e5c9e29fe1556051cMathieu Chartier for (const auto& m : proxy_class->GetVirtualMethods(sizeof(void*))) { 453d21bdf8894e780d349c481e5c9e29fe1556051cMathieu Chartier if (&m == proxy_method) { 46c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers throws_index = i; 47c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers break; 48c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers } 493d21bdf8894e780d349c481e5c9e29fe1556051cMathieu Chartier ++i; 50c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers } 51c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers CHECK_NE(throws_index, -1); 52ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom mirror::ObjectArray<mirror::Class>* declared_exceptions = 53ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom proxy_class->GetThrows()->Get(throws_index); 5450b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self())); 55c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers} 56c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers 57f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromstatic JNINativeMethod gMethods[] = { 58fc58af45e342ba9e18bbdf597f205a58ec731658Mathieu Chartier NATIVE_METHOD(Method, invoke, "!(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"), 5953b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers NATIVE_METHOD(Method, getExceptionTypesNative, "!()[Ljava/lang/Class;"), 60f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom}; 61f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 62f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromvoid register_java_lang_reflect_Method(JNIEnv* env) { 63eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes REGISTER_NATIVE_METHODS("java/lang/reflect/Method"); 64f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} 65f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 66f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} // namespace art 67