Home | History | Annotate | Download | only in native
      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 "class_linker.h"
     18 #include "jni_internal.h"
     19 #include "mirror/art_method.h"
     20 #include "mirror/art_method-inl.h"
     21 #include "mirror/class-inl.h"
     22 #include "mirror/object-inl.h"
     23 #include "mirror/object_array-inl.h"
     24 #include "mirror/proxy.h"
     25 #include "object_utils.h"
     26 #include "reflection.h"
     27 #include "scoped_thread_state_change.h"
     28 #include "well_known_classes.h"
     29 
     30 namespace art {
     31 
     32 static jobject Method_invoke(JNIEnv* env,
     33                              jobject javaMethod, jobject javaReceiver, jobject javaArgs) {
     34   ScopedObjectAccess soa(env);
     35   return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs);
     36 }
     37 
     38 static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
     39   ScopedObjectAccess soa(env);
     40   jobject art_method = soa.Env()->GetObjectField(
     41       javaMethod, WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod);
     42 
     43   mirror::ArtMethod* proxy_method = soa.Decode<mirror::Object*>(art_method)->AsArtMethod();
     44   CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
     45   mirror::SynthesizedProxyClass* proxy_class =
     46       down_cast<mirror::SynthesizedProxyClass*>(proxy_method->GetDeclaringClass());
     47   int throws_index = -1;
     48   size_t num_virt_methods = proxy_class->NumVirtualMethods();
     49   for (size_t i = 0; i < num_virt_methods; i++) {
     50     if (proxy_class->GetVirtualMethod(i) == proxy_method) {
     51       throws_index = i;
     52       break;
     53     }
     54   }
     55   CHECK_NE(throws_index, -1);
     56   mirror::ObjectArray<mirror::Class>* declared_exceptions =
     57           proxy_class->GetThrows()->Get(throws_index);
     58   return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self()));
     59 }
     60 
     61 static JNINativeMethod gMethods[] = {
     62   NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
     63   NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"),
     64 };
     65 
     66 void register_java_lang_reflect_Method(JNIEnv* env) {
     67   REGISTER_NATIVE_METHODS("java/lang/reflect/Method");
     68 }
     69 
     70 }  // namespace art
     71