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 "reflection.h"
25 #include "scoped_fast_native_object_access.h"
26 #include "well_known_classes.h"
27
28 namespace art {
29
Method_invoke(JNIEnv * env,jobject javaMethod,jobject javaReceiver,jobject javaArgs,jboolean accessible)30 static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver,
31 jobject javaArgs, jboolean accessible) {
32 ScopedFastNativeObjectAccess soa(env);
33 return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs, (accessible == JNI_TRUE));
34 }
35
Method_getExceptionTypesNative(JNIEnv * env,jobject javaMethod)36 static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
37 ScopedFastNativeObjectAccess soa(env);
38 mirror::ArtMethod* proxy_method = mirror::ArtMethod::FromReflectedMethod(soa, javaMethod);
39 CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
40 mirror::Class* proxy_class = proxy_method->GetDeclaringClass();
41 int throws_index = -1;
42 size_t num_virt_methods = proxy_class->NumVirtualMethods();
43 for (size_t i = 0; i < num_virt_methods; i++) {
44 if (proxy_class->GetVirtualMethod(i) == proxy_method) {
45 throws_index = i;
46 break;
47 }
48 }
49 CHECK_NE(throws_index, -1);
50 mirror::ObjectArray<mirror::Class>* declared_exceptions =
51 proxy_class->GetThrows()->Get(throws_index);
52 return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self()));
53 }
54
55 static JNINativeMethod gMethods[] = {
56 NATIVE_METHOD(Method, invoke, "!(Ljava/lang/Object;[Ljava/lang/Object;Z)Ljava/lang/Object;"),
57 NATIVE_METHOD(Method, getExceptionTypesNative, "!()[Ljava/lang/Class;"),
58 };
59
register_java_lang_reflect_Method(JNIEnv * env)60 void register_java_lang_reflect_Method(JNIEnv* env) {
61 REGISTER_NATIVE_METHODS("java/lang/reflect/Method");
62 }
63
64 } // namespace art
65