blob: 540e46bbfe3f329c9edb8f49cfb2ffdd780c720f [file] [log] [blame]
Ian Rogers57b86d42012-03-27 16:05:41 -07001/*
2 * Copyright (C) 2012 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 "callee_save_frame.h"
18#include "runtime_support.h"
19
20namespace art {
21
22static uint64_t artInvokeCommon(uint32_t method_idx, Object* this_object, Method* caller_method,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070023 Thread* self, Method** sp, bool access_check, InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -070024 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070025 Method* method = FindMethodFast(method_idx, this_object, caller_method, access_check, type);
26 if (UNLIKELY(method == NULL)) {
27 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
28 if (UNLIKELY(this_object == NULL && type != kDirect && type != kStatic)) {
Ian Rogers87e552d2012-08-31 15:54:48 -070029 ThrowNullPointerExceptionForMethodAccess(caller_method, method_idx, type);
Ian Rogers57b86d42012-03-27 16:05:41 -070030 return 0; // failure
31 }
32 method = FindMethodFromCode(method_idx, this_object, caller_method, self, access_check, type);
33 if (UNLIKELY(method == NULL)) {
34 CHECK(self->IsExceptionPending());
35 return 0; // failure
36 }
37 }
38 DCHECK(!self->IsExceptionPending());
39 const void* code = method->GetCode();
40
41 // When we return, the caller will branch to this address, so it had better not be 0!
Mathieu Chartiera92f9712012-07-23 10:56:42 -070042 if (UNLIKELY(code == NULL)) {
43 MethodHelper mh(method);
44 LOG(FATAL) << "Code was NULL in method: " << PrettyMethod(method)
45 << " location: " << mh.GetDexFile().GetLocation();
46 }
47
Ian Rogers57b86d42012-03-27 16:05:41 -070048
49 uint32_t method_uint = reinterpret_cast<uint32_t>(method);
50 uint64_t code_uint = reinterpret_cast<uint32_t>(code);
51 uint64_t result = ((code_uint << 32) | method_uint);
52 return result;
53}
54
55// See comments in runtime_support_asm.S
56extern "C" uint64_t artInvokeInterfaceTrampoline(uint32_t method_idx, Object* this_object,
57 Method* caller_method, Thread* self,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070058 Method** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070059 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070060 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, false, kInterface);
61}
62
63extern "C" uint64_t artInvokeInterfaceTrampolineWithAccessCheck(uint32_t method_idx,
64 Object* this_object,
65 Method* caller_method, Thread* self,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070066 Method** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070067 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070068 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kInterface);
69}
70
71
72extern "C" uint64_t artInvokeDirectTrampolineWithAccessCheck(uint32_t method_idx,
73 Object* this_object,
74 Method* caller_method, Thread* self,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070075 Method** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070076 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070077 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kDirect);
78}
79
80extern "C" uint64_t artInvokeStaticTrampolineWithAccessCheck(uint32_t method_idx,
81 Object* this_object,
82 Method* caller_method, Thread* self,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070083 Method** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070084 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070085 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kStatic);
86}
87
88extern "C" uint64_t artInvokeSuperTrampolineWithAccessCheck(uint32_t method_idx,
89 Object* this_object,
90 Method* caller_method, Thread* self,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070091 Method** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070092 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070093 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kSuper);
94}
95
96extern "C" uint64_t artInvokeVirtualTrampolineWithAccessCheck(uint32_t method_idx,
97 Object* this_object,
98 Method* caller_method, Thread* self,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070099 Method** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700100 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -0700101 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kVirtual);
102}
103
104} // namespace art