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