blob: 14dc6a44ee3eb55f0521a3599d537d7a6b95ec34 [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
Brian Carlstromf867b6f2011-09-16 12:17:25 -070017#include "class_linker.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070018#include "jni_internal.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019#include "mirror/class-inl.h"
20#include "mirror/abstract_method.h"
21#include "mirror/abstract_method-inl.h"
22#include "mirror/object-inl.h"
23#include "mirror/object_array-inl.h"
24#include "mirror/proxy.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080025#include "object_utils.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070026#include "reflection.h"
Ian Rogers00f7d0e2012-07-19 15:28:27 -070027#include "scoped_thread_state_change.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070028
Brian Carlstromf867b6f2011-09-16 12:17:25 -070029namespace art {
30
Elliott Hughes0512f022012-03-15 22:10:52 -070031static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, jobject javaArgs) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070032 ScopedObjectAccess soa(env);
33 return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs);
Brian Carlstromf867b6f2011-09-16 12:17:25 -070034}
35
Elliott Hughes0512f022012-03-15 22:10:52 -070036static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070037 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038 mirror::AbstractMethod* proxy_method = soa.Decode<mirror::Object*>(javaMethod)->AsMethod();
Ian Rogersc2b44472011-12-14 21:17:17 -080039 CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040 mirror::SynthesizedProxyClass* proxy_class =
41 down_cast<mirror::SynthesizedProxyClass*>(proxy_method->GetDeclaringClass());
Ian Rogersc2b44472011-12-14 21:17:17 -080042 int throws_index = -1;
43 size_t num_virt_methods = proxy_class->NumVirtualMethods();
44 for (size_t i = 0; i < num_virt_methods; i++) {
45 if (proxy_class->GetVirtualMethod(i) == proxy_method) {
46 throws_index = i;
47 break;
48 }
49 }
50 CHECK_NE(throws_index, -1);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080051 mirror::ObjectArray<mirror::Class>* declared_exceptions = proxy_class->GetThrows()->Get(throws_index);
Ian Rogers50b35e22012-10-04 10:09:15 -070052 return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self()));
Ian Rogersc2b44472011-12-14 21:17:17 -080053}
54
Elliott Hughes0512f022012-03-15 22:10:52 -070055static jobject Method_findOverriddenMethodNative(JNIEnv* env, jobject javaMethod) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070056 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057 mirror::AbstractMethod* method = soa.Decode<mirror::Object*>(javaMethod)->AsMethod();
Ian Rogers00f7d0e2012-07-19 15:28:27 -070058 return soa.AddLocalReference<jobject>(method->FindOverriddenMethod());
Ian Rogers16f93672012-02-14 12:29:06 -080059}
60
Brian Carlstromf867b6f2011-09-16 12:17:25 -070061static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080062 NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
Ian Rogersc2b44472011-12-14 21:17:17 -080063 NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"),
Ian Rogers19846512012-02-24 11:42:47 -080064 NATIVE_METHOD(Method, findOverriddenMethodNative, "()Ljava/lang/reflect/Method;"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -070065};
66
Brian Carlstromf867b6f2011-09-16 12:17:25 -070067void register_java_lang_reflect_Method(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -070068 REGISTER_NATIVE_METHODS("java/lang/reflect/Method");
Brian Carlstromf867b6f2011-09-16 12:17:25 -070069}
70
71} // namespace art