blob: 14040cee88ea68b70926d27789a563b2b93dae97 [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,
23 Thread* self, Method** sp, bool access_check, InvokeType type){
24 Method* method = FindMethodFast(method_idx, this_object, caller_method, access_check, type);
25 if (UNLIKELY(method == NULL)) {
26 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
27 if (UNLIKELY(this_object == NULL && type != kDirect && type != kStatic)) {
28 ThrowNullPointerExceptionForMethodAccess(self, caller_method, method_idx, type);
29 return 0; // failure
30 }
31 method = FindMethodFromCode(method_idx, this_object, caller_method, self, access_check, type);
32 if (UNLIKELY(method == NULL)) {
33 CHECK(self->IsExceptionPending());
34 return 0; // failure
35 }
36 }
37 DCHECK(!self->IsExceptionPending());
38 const void* code = method->GetCode();
39
40 // When we return, the caller will branch to this address, so it had better not be 0!
41 CHECK(code != NULL) << PrettyMethod(method);
42
43 uint32_t method_uint = reinterpret_cast<uint32_t>(method);
44 uint64_t code_uint = reinterpret_cast<uint32_t>(code);
45 uint64_t result = ((code_uint << 32) | method_uint);
46 return result;
47}
48
49// See comments in runtime_support_asm.S
50extern "C" uint64_t artInvokeInterfaceTrampoline(uint32_t method_idx, Object* this_object,
51 Method* caller_method, Thread* self,
52 Method** sp) {
53 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, false, kInterface);
54}
55
56extern "C" uint64_t artInvokeInterfaceTrampolineWithAccessCheck(uint32_t method_idx,
57 Object* this_object,
58 Method* caller_method, Thread* self,
59 Method** sp) {
60 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kInterface);
61}
62
63
64extern "C" uint64_t artInvokeDirectTrampolineWithAccessCheck(uint32_t method_idx,
65 Object* this_object,
66 Method* caller_method, Thread* self,
67 Method** sp) {
68 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kDirect);
69}
70
71extern "C" uint64_t artInvokeStaticTrampolineWithAccessCheck(uint32_t method_idx,
72 Object* this_object,
73 Method* caller_method, Thread* self,
74 Method** sp) {
75 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kStatic);
76}
77
78extern "C" uint64_t artInvokeSuperTrampolineWithAccessCheck(uint32_t method_idx,
79 Object* this_object,
80 Method* caller_method, Thread* self,
81 Method** sp) {
82 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kSuper);
83}
84
85extern "C" uint64_t artInvokeVirtualTrampolineWithAccessCheck(uint32_t method_idx,
86 Object* this_object,
87 Method* caller_method, Thread* self,
88 Method** sp) {
89 return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kVirtual);
90}
91
92} // namespace art