java_lang_reflect_Method.cc revision c2b4447ae9c0c1e77595620acac6508999df6698
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 "jni_internal.h" 18f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom#include "class_linker.h" 19f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom#include "object.h" 206d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers#include "object_utils.h" 21418d20fc407052d4152157f61e7453359f902383Elliott Hughes#include "reflection.h" 22f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 23f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom#include "JniConstants.h" // Last to avoid problems with LOG redefinition. 24f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 25f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromnamespace art { 26f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 27f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromnamespace { 28f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 296d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogersjobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, jobject javaArgs) { 306d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers return InvokeMethod(env, javaMethod, javaReceiver, javaArgs); 31f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} 32f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 33c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogersjobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) { 34c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers Method* proxy_method = Decode<Object*>(env, javaMethod)->AsMethod(); 35c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers CHECK(proxy_method->GetDeclaringClass()->IsProxyClass()); 36c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers SynthesizedProxyClass* proxy_class = 37c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers down_cast<SynthesizedProxyClass*>(proxy_method->GetDeclaringClass()); 38c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers int throws_index = -1; 39c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers size_t num_virt_methods = proxy_class->NumVirtualMethods(); 40c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers for (size_t i = 0; i < num_virt_methods; i++) { 41c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers if (proxy_class->GetVirtualMethod(i) == proxy_method) { 42c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers throws_index = i; 43c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers break; 44c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers } 45c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers } 46c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers CHECK_NE(throws_index, -1); 47c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers ObjectArray<Class>* declared_exceptions = proxy_class->GetThrows()->Get(throws_index); 48c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers return AddLocalReference<jobject>(env, declared_exceptions->Clone()); 49c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers} 50c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers 516d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogersjobject Method_getReturnTypeNative(JNIEnv* env, jobject javaMethod) { 526d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers Method* m = Decode<Object*>(env, javaMethod)->AsMethod(); 536d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers MethodHelper mh(m); 546d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers return AddLocalReference<jobject>(env, mh.GetReturnType()); 55418d20fc407052d4152157f61e7453359f902383Elliott Hughes} 56418d20fc407052d4152157f61e7453359f902383Elliott Hughes 57f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromstatic JNINativeMethod gMethods[] = { 586d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"), 59c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"), 606d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers NATIVE_METHOD(Method, getReturnTypeNative, "()Ljava/lang/Class;") 61f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom}; 62f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 63f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} // namespace 64f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 65f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromvoid register_java_lang_reflect_Method(JNIEnv* env) { 66f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom jniRegisterNativeMethods(env, "java/lang/reflect/Method", gMethods, NELEM(gMethods)); 67f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} 68f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom 69f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom} // namespace art 70