java_lang_reflect_Method.cc revision fc58af45e342ba9e18bbdf597f205a58ec731658
1f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom/*
2f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * Copyright (C) 2008 The Android Open Source Project
3f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom *
4f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License");
5f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * you may not use this file except in compliance with the License.
6f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * You may obtain a copy of the License at
7f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom *
8f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom *      http://www.apache.org/licenses/LICENSE-2.0
9f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom *
10f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * Unless required by applicable law or agreed to in writing, software
11f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS,
12f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * See the License for the specific language governing permissions and
14f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom * limitations under the License.
15f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom */
16f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom
17277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe#include "java_lang_reflect_Method.h"
18277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe
19f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom#include "class_linker.h"
20eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes#include "jni_internal.h"
21ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "mirror/art_method.h"
22ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "mirror/art_method-inl.h"
232dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/class-inl.h"
242dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object-inl.h"
252dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object_array-inl.h"
26418d20fc407052d4152157f61e7453359f902383Elliott Hughes#include "reflection.h"
2753b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers#include "scoped_fast_native_object_access.h"
28ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "well_known_classes.h"
29f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom
30f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromnamespace art {
31f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom
3211d5d8fffe41cc7daadbfa2ca98ecb978f3029afJeff Haostatic jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver,
33fc58af45e342ba9e18bbdf597f205a58ec731658Mathieu Chartier                             jobject javaArgs) {
3453b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers  ScopedFastNativeObjectAccess soa(env);
35fc58af45e342ba9e18bbdf597f205a58ec731658Mathieu Chartier  return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs);
36f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom}
37f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom
380512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughesstatic jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
3953b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers  ScopedFastNativeObjectAccess soa(env);
4062f0512bf6d9bc6141358bf22e93afa70dc58b1aIan Rogers  mirror::ArtMethod* proxy_method = mirror::ArtMethod::FromReflectedMethod(soa, javaMethod);
41c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers  CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
4298d1cc8033251c93786e2fa8c59a2e555a9493beMingyao Yang  mirror::Class* proxy_class = proxy_method->GetDeclaringClass();
43c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers  int throws_index = -1;
44c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers  size_t num_virt_methods = proxy_class->NumVirtualMethods();
45c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers  for (size_t i = 0; i < num_virt_methods; i++) {
46c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers    if (proxy_class->GetVirtualMethod(i) == proxy_method) {
47c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers      throws_index = i;
48c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers      break;
49c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers    }
50c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers  }
51c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers  CHECK_NE(throws_index, -1);
52ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ObjectArray<mirror::Class>* declared_exceptions =
53ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom          proxy_class->GetThrows()->Get(throws_index);
5450b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers  return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self()));
55c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers}
56c2b4447ae9c0c1e77595620acac6508999df6698Ian Rogers
57f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromstatic JNINativeMethod gMethods[] = {
58fc58af45e342ba9e18bbdf597f205a58ec731658Mathieu Chartier  NATIVE_METHOD(Method, invoke, "!(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
5953b8b09fc80329539585dcf43657bc5f4ecefdffIan Rogers  NATIVE_METHOD(Method, getExceptionTypesNative, "!()[Ljava/lang/Class;"),
60f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom};
61f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom
62f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstromvoid register_java_lang_reflect_Method(JNIEnv* env) {
63eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes  REGISTER_NATIVE_METHODS("java/lang/reflect/Method");
64f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom}
65f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom
66f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom}  // namespace art
67