java_lang_reflect_Method.cc revision 0512f02dd6623c0870c11fbf3274d7462f732136
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "jni_internal.h" 18#include "class_linker.h" 19#include "object.h" 20#include "object_utils.h" 21#include "reflection.h" 22 23#include "JniConstants.h" // Last to avoid problems with LOG redefinition. 24 25namespace art { 26 27static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, jobject javaArgs) { 28 return InvokeMethod(env, javaMethod, javaReceiver, javaArgs); 29} 30 31static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) { 32 Method* proxy_method = Decode<Object*>(env, javaMethod)->AsMethod(); 33 CHECK(proxy_method->GetDeclaringClass()->IsProxyClass()); 34 SynthesizedProxyClass* proxy_class = 35 down_cast<SynthesizedProxyClass*>(proxy_method->GetDeclaringClass()); 36 int throws_index = -1; 37 size_t num_virt_methods = proxy_class->NumVirtualMethods(); 38 for (size_t i = 0; i < num_virt_methods; i++) { 39 if (proxy_class->GetVirtualMethod(i) == proxy_method) { 40 throws_index = i; 41 break; 42 } 43 } 44 CHECK_NE(throws_index, -1); 45 ObjectArray<Class>* declared_exceptions = proxy_class->GetThrows()->Get(throws_index); 46 // Change thread state for allocation 47 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); 48 return AddLocalReference<jobject>(env, declared_exceptions->Clone()); 49} 50 51static jobject Method_findOverriddenMethodNative(JNIEnv* env, jobject javaMethod) { 52 Method* method = Decode<Object*>(env, javaMethod)->AsMethod(); 53 return AddLocalReference<jobject>(env, method->FindOverriddenMethod()); 54} 55 56static JNINativeMethod gMethods[] = { 57 NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"), 58 NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"), 59 NATIVE_METHOD(Method, findOverriddenMethodNative, "()Ljava/lang/reflect/Method;"), 60}; 61 62void register_java_lang_reflect_Method(JNIEnv* env) { 63 jniRegisterNativeMethods(env, "java/lang/reflect/Method", gMethods, NELEM(gMethods)); 64} 65 66} // namespace art 67