blob: 9533b4dc8aa0cbff6d7687ff63cbb2eb096071c4 [file] [log] [blame]
Brian Carlstromf867b6f2011-09-16 12:17:25 -07001/*
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
Andreas Gampe277ccbd2014-11-03 21:36:10 -080017#include "java_lang_reflect_Method.h"
18
Mathieu Chartiere401d142015-04-22 13:56:20 -070019#include "art_method-inl.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070020#include "class_linker.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070021#include "jni_internal.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "mirror/object-inl.h"
24#include "mirror/object_array-inl.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070025#include "reflection.h"
Ian Rogers53b8b092014-03-13 23:45:53 -070026#include "scoped_fast_native_object_access.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070027#include "well_known_classes.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070028
Brian Carlstromf867b6f2011-09-16 12:17:25 -070029namespace art {
30
Jeff Hao11d5d8f2014-03-26 15:08:20 -070031static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver,
Mathieu Chartierfc58af42015-04-16 18:00:39 -070032 jobject javaArgs) {
Ian Rogers53b8b092014-03-13 23:45:53 -070033 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartierfc58af42015-04-16 18:00:39 -070034 return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs);
Brian Carlstromf867b6f2011-09-16 12:17:25 -070035}
36
Elliott Hughes0512f022012-03-15 22:10:52 -070037static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
Ian Rogers53b8b092014-03-13 23:45:53 -070038 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartiere401d142015-04-22 13:56:20 -070039 ArtMethod* proxy_method = ArtMethod::FromReflectedMethod(soa, javaMethod);
Ian Rogersc2b44472011-12-14 21:17:17 -080040 CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
Mingyao Yang98d1cc82014-05-15 17:02:16 -070041 mirror::Class* proxy_class = proxy_method->GetDeclaringClass();
Ian Rogersc2b44472011-12-14 21:17:17 -080042 int throws_index = -1;
Mathieu Chartiere401d142015-04-22 13:56:20 -070043 size_t i = 0;
44 for (const auto& m : proxy_class->GetVirtualMethods(sizeof(void*))) {
45 if (&m == proxy_method) {
Ian Rogersc2b44472011-12-14 21:17:17 -080046 throws_index = i;
47 break;
48 }
Mathieu Chartiere401d142015-04-22 13:56:20 -070049 ++i;
Ian Rogersc2b44472011-12-14 21:17:17 -080050 }
51 CHECK_NE(throws_index, -1);
Brian Carlstromea46f952013-07-30 01:26:50 -070052 mirror::ObjectArray<mirror::Class>* declared_exceptions =
53 proxy_class->GetThrows()->Get(throws_index);
Ian Rogers50b35e22012-10-04 10:09:15 -070054 return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self()));
Ian Rogersc2b44472011-12-14 21:17:17 -080055}
56
Brian Carlstromf867b6f2011-09-16 12:17:25 -070057static JNINativeMethod gMethods[] = {
Mathieu Chartierfc58af42015-04-16 18:00:39 -070058 NATIVE_METHOD(Method, invoke, "!(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
Ian Rogers53b8b092014-03-13 23:45:53 -070059 NATIVE_METHOD(Method, getExceptionTypesNative, "!()[Ljava/lang/Class;"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -070060};
61
Brian Carlstromf867b6f2011-09-16 12:17:25 -070062void register_java_lang_reflect_Method(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -070063 REGISTER_NATIVE_METHODS("java/lang/reflect/Method");
Brian Carlstromf867b6f2011-09-16 12:17:25 -070064}
65
66} // namespace art