Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | namespace art { |
| 21 | |
| 22 | static uint64_t artInvokeCommon(uint32_t method_idx, Object* this_object, Method* caller_method, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 23 | Thread* self, Method** sp, bool access_check, InvokeType type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 24 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 25 | 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 Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 29 | ThrowNullPointerExceptionForMethodAccess(caller_method, method_idx, type); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 30 | 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 Chartier | a92f971 | 2012-07-23 10:56:42 -0700 | [diff] [blame] | 42 | 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 Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 48 | |
| 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 |
| 56 | extern "C" uint64_t artInvokeInterfaceTrampoline(uint32_t method_idx, Object* this_object, |
| 57 | Method* caller_method, Thread* self, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 58 | Method** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 59 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 60 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, false, kInterface); |
| 61 | } |
| 62 | |
| 63 | extern "C" uint64_t artInvokeInterfaceTrampolineWithAccessCheck(uint32_t method_idx, |
| 64 | Object* this_object, |
| 65 | Method* caller_method, Thread* self, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 66 | Method** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 67 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 68 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kInterface); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | extern "C" uint64_t artInvokeDirectTrampolineWithAccessCheck(uint32_t method_idx, |
| 73 | Object* this_object, |
| 74 | Method* caller_method, Thread* self, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 75 | Method** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 76 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 77 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kDirect); |
| 78 | } |
| 79 | |
| 80 | extern "C" uint64_t artInvokeStaticTrampolineWithAccessCheck(uint32_t method_idx, |
| 81 | Object* this_object, |
| 82 | Method* caller_method, Thread* self, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 83 | Method** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 84 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 85 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kStatic); |
| 86 | } |
| 87 | |
| 88 | extern "C" uint64_t artInvokeSuperTrampolineWithAccessCheck(uint32_t method_idx, |
| 89 | Object* this_object, |
| 90 | Method* caller_method, Thread* self, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 91 | Method** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 92 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 93 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kSuper); |
| 94 | } |
| 95 | |
| 96 | extern "C" uint64_t artInvokeVirtualTrampolineWithAccessCheck(uint32_t method_idx, |
| 97 | Object* this_object, |
| 98 | Method* caller_method, Thread* self, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 99 | Method** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 100 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 101 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kVirtual); |
| 102 | } |
| 103 | |
| 104 | } // namespace art |