blob: bf5c85039911c840046dbce855a8b3228cf8ef29 [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"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070022
Brian Carlstromf867b6f2011-09-16 12:17:25 -070023namespace art {
24
Elliott Hughes0512f022012-03-15 22:10:52 -070025static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, jobject javaArgs) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080026 return InvokeMethod(env, javaMethod, javaReceiver, javaArgs);
Brian Carlstromf867b6f2011-09-16 12:17:25 -070027}
28
Elliott Hughes0512f022012-03-15 22:10:52 -070029static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
Ian Rogersc2b44472011-12-14 21:17:17 -080030 Method* proxy_method = Decode<Object*>(env, javaMethod)->AsMethod();
31 CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
32 SynthesizedProxyClass* proxy_class =
33 down_cast<SynthesizedProxyClass*>(proxy_method->GetDeclaringClass());
34 int throws_index = -1;
35 size_t num_virt_methods = proxy_class->NumVirtualMethods();
36 for (size_t i = 0; i < num_virt_methods; i++) {
37 if (proxy_class->GetVirtualMethod(i) == proxy_method) {
38 throws_index = i;
39 break;
40 }
41 }
42 CHECK_NE(throws_index, -1);
43 ObjectArray<Class>* declared_exceptions = proxy_class->GetThrows()->Get(throws_index);
Ian Rogersf45b1542012-02-03 18:03:48 -080044 // Change thread state for allocation
Elliott Hughes34e06962012-04-09 13:55:55 -070045 ScopedThreadStateChange tsc(Thread::Current(), kRunnable);
Ian Rogersc2b44472011-12-14 21:17:17 -080046 return AddLocalReference<jobject>(env, declared_exceptions->Clone());
47}
48
Elliott Hughes0512f022012-03-15 22:10:52 -070049static jobject Method_findOverriddenMethodNative(JNIEnv* env, jobject javaMethod) {
Ian Rogers16f93672012-02-14 12:29:06 -080050 Method* method = Decode<Object*>(env, javaMethod)->AsMethod();
51 return AddLocalReference<jobject>(env, method->FindOverriddenMethod());
52}
53
Brian Carlstromf867b6f2011-09-16 12:17:25 -070054static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080055 NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
Ian Rogersc2b44472011-12-14 21:17:17 -080056 NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"),
Ian Rogers19846512012-02-24 11:42:47 -080057 NATIVE_METHOD(Method, findOverriddenMethodNative, "()Ljava/lang/reflect/Method;"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -070058};
59
Brian Carlstromf867b6f2011-09-16 12:17:25 -070060void register_java_lang_reflect_Method(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -070061 REGISTER_NATIVE_METHODS("java/lang/reflect/Method");
Brian Carlstromf867b6f2011-09-16 12:17:25 -070062}
63
64} // namespace art