blob: 269582269ee875608bd49e7d39e8eb351468681f [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"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070019#include "object.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080020#include "object_utils.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070021#include "reflection.h"
Ian Rogers365c1022012-06-22 15:05:28 -070022#include "scoped_jni_thread_state.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070023
Brian Carlstromf867b6f2011-09-16 12:17:25 -070024namespace art {
25
Elliott Hughes0512f022012-03-15 22:10:52 -070026static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, jobject javaArgs) {
Ian Rogers365c1022012-06-22 15:05:28 -070027 ScopedJniThreadState ts(env);
28 return InvokeMethod(ts, javaMethod, javaReceiver, javaArgs);
Brian Carlstromf867b6f2011-09-16 12:17:25 -070029}
30
Elliott Hughes0512f022012-03-15 22:10:52 -070031static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
Ian Rogers365c1022012-06-22 15:05:28 -070032 ScopedJniThreadState ts(env);
33 Method* proxy_method = ts.Decode<Object*>(javaMethod)->AsMethod();
Ian Rogersc2b44472011-12-14 21:17:17 -080034 CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
35 SynthesizedProxyClass* proxy_class =
36 down_cast<SynthesizedProxyClass*>(proxy_method->GetDeclaringClass());
37 int throws_index = -1;
38 size_t num_virt_methods = proxy_class->NumVirtualMethods();
39 for (size_t i = 0; i < num_virt_methods; i++) {
40 if (proxy_class->GetVirtualMethod(i) == proxy_method) {
41 throws_index = i;
42 break;
43 }
44 }
45 CHECK_NE(throws_index, -1);
46 ObjectArray<Class>* declared_exceptions = proxy_class->GetThrows()->Get(throws_index);
Ian Rogers365c1022012-06-22 15:05:28 -070047 return ts.AddLocalReference<jobject>(declared_exceptions->Clone());
Ian Rogersc2b44472011-12-14 21:17:17 -080048}
49
Elliott Hughes0512f022012-03-15 22:10:52 -070050static jobject Method_findOverriddenMethodNative(JNIEnv* env, jobject javaMethod) {
Ian Rogers365c1022012-06-22 15:05:28 -070051 ScopedJniThreadState ts(env);
52 Method* method = ts.Decode<Object*>(javaMethod)->AsMethod();
53 return ts.AddLocalReference<jobject>(method->FindOverriddenMethod());
Ian Rogers16f93672012-02-14 12:29:06 -080054}
55
Brian Carlstromf867b6f2011-09-16 12:17:25 -070056static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080057 NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
Ian Rogersc2b44472011-12-14 21:17:17 -080058 NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"),
Ian Rogers19846512012-02-24 11:42:47 -080059 NATIVE_METHOD(Method, findOverriddenMethodNative, "()Ljava/lang/reflect/Method;"),
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