blob: 10f5779c18dc5119efc4daa2ce2f27a325361554 [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);
48 return AddLocalReference<jobject>(env, declared_exceptions->Clone());
49}
50
Brian Carlstromf867b6f2011-09-16 12:17:25 -070051static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080052 NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
Ian Rogersc2b44472011-12-14 21:17:17 -080053 NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -070054};
55
56} // namespace
57
58void register_java_lang_reflect_Method(JNIEnv* env) {
59 jniRegisterNativeMethods(env, "java/lang/reflect/Method", gMethods, NELEM(gMethods));
60}
61
62} // namespace art