blob: 22e81e4b3a6b485a418229a1357a2ba682b8a10f [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 Carlstromea46f952013-07-30 01:26:50 -070019#include "mirror/art_method.h"
20#include "mirror/art_method-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#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 Rogers53b8b092014-03-13 23:45:53 -070027#include "scoped_fast_native_object_access.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070028#include "well_known_classes.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070029
Brian Carlstromf867b6f2011-09-16 12:17:25 -070030namespace art {
31
Jeff Hao11d5d8f2014-03-26 15:08:20 -070032static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver,
33 jobject javaArgs, jboolean accessible) {
Ian Rogers53b8b092014-03-13 23:45:53 -070034 ScopedFastNativeObjectAccess soa(env);
Jeff Haocb4581a2014-03-28 15:43:37 -070035 return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs, (accessible == JNI_TRUE));
Brian Carlstromf867b6f2011-09-16 12:17:25 -070036}
37
Elliott Hughes0512f022012-03-15 22:10:52 -070038static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
Ian Rogers53b8b092014-03-13 23:45:53 -070039 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -070040 mirror::ArtMethod* proxy_method = mirror::ArtMethod::FromReflectedMethod(soa, javaMethod);
Ian Rogersc2b44472011-12-14 21:17:17 -080041 CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042 mirror::SynthesizedProxyClass* proxy_class =
43 down_cast<mirror::SynthesizedProxyClass*>(proxy_method->GetDeclaringClass());
Ian Rogersc2b44472011-12-14 21:17:17 -080044 int throws_index = -1;
45 size_t num_virt_methods = proxy_class->NumVirtualMethods();
46 for (size_t i = 0; i < num_virt_methods; i++) {
47 if (proxy_class->GetVirtualMethod(i) == proxy_method) {
48 throws_index = i;
49 break;
50 }
51 }
52 CHECK_NE(throws_index, -1);
Brian Carlstromea46f952013-07-30 01:26:50 -070053 mirror::ObjectArray<mirror::Class>* declared_exceptions =
54 proxy_class->GetThrows()->Get(throws_index);
Ian Rogers50b35e22012-10-04 10:09:15 -070055 return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self()));
Ian Rogersc2b44472011-12-14 21:17:17 -080056}
57
Brian Carlstromf867b6f2011-09-16 12:17:25 -070058static JNINativeMethod gMethods[] = {
Jeff Hao11d5d8f2014-03-26 15:08:20 -070059 NATIVE_METHOD(Method, invoke, "!(Ljava/lang/Object;[Ljava/lang/Object;Z)Ljava/lang/Object;"),
Ian Rogers53b8b092014-03-13 23:45:53 -070060 NATIVE_METHOD(Method, getExceptionTypesNative, "!()[Ljava/lang/Class;"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -070061};
62
Brian Carlstromf867b6f2011-09-16 12:17:25 -070063void register_java_lang_reflect_Method(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -070064 REGISTER_NATIVE_METHODS("java/lang/reflect/Method");
Brian Carlstromf867b6f2011-09-16 12:17:25 -070065}
66
67} // namespace art