blob: 7049eff0860dff735f0fa196714dc8bf9dd03a30 [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
17#include "jni_internal.h"
18#include "class_linker.h"
19#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"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070022
23#include "JniConstants.h" // Last to avoid problems with LOG redefinition.
24
25namespace art {
26
27namespace {
28
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080029jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, jobject javaArgs) {
30 return InvokeMethod(env, javaMethod, javaReceiver, javaArgs);
Brian Carlstromf867b6f2011-09-16 12:17:25 -070031}
32
Ian Rogersc2b44472011-12-14 21:17:17 -080033jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
34 Method* proxy_method = Decode<Object*>(env, javaMethod)->AsMethod();
35 CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
36 SynthesizedProxyClass* proxy_class =
37 down_cast<SynthesizedProxyClass*>(proxy_method->GetDeclaringClass());
38 int throws_index = -1;
39 size_t num_virt_methods = proxy_class->NumVirtualMethods();
40 for (size_t i = 0; i < num_virt_methods; i++) {
41 if (proxy_class->GetVirtualMethod(i) == proxy_method) {
42 throws_index = i;
43 break;
44 }
45 }
46 CHECK_NE(throws_index, -1);
47 ObjectArray<Class>* declared_exceptions = proxy_class->GetThrows()->Get(throws_index);
Ian Rogersf45b1542012-02-03 18:03:48 -080048 // Change thread state for allocation
49 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
Ian Rogersc2b44472011-12-14 21:17:17 -080050 return AddLocalReference<jobject>(env, declared_exceptions->Clone());
51}
52
Ian Rogers19846512012-02-24 11:42:47 -080053jobject Method_findOverriddenMethodNative(JNIEnv* env, jobject javaMethod) {
Ian Rogers16f93672012-02-14 12:29:06 -080054 Method* method = Decode<Object*>(env, javaMethod)->AsMethod();
55 return AddLocalReference<jobject>(env, method->FindOverriddenMethod());
56}
57
Brian Carlstromf867b6f2011-09-16 12:17:25 -070058static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080059 NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
Ian Rogersc2b44472011-12-14 21:17:17 -080060 NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"),
Ian Rogers19846512012-02-24 11:42:47 -080061 NATIVE_METHOD(Method, findOverriddenMethodNative, "()Ljava/lang/reflect/Method;"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -070062};
63
64} // namespace
65
66void register_java_lang_reflect_Method(JNIEnv* env) {
67 jniRegisterNativeMethods(env, "java/lang/reflect/Method", gMethods, NELEM(gMethods));
68}
69
70} // namespace art