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, |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 23 | Thread* self, Method** sp, bool access_check, InvokeType type) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 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! |
Mathieu Chartier | a92f971 | 2012-07-23 10:56:42 -0700 | [diff] [blame^] | 41 | if (UNLIKELY(code == NULL)) { |
| 42 | MethodHelper mh(method); |
| 43 | LOG(FATAL) << "Code was NULL in method: " << PrettyMethod(method) |
| 44 | << " location: " << mh.GetDexFile().GetLocation(); |
| 45 | } |
| 46 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 47 | |
| 48 | uint32_t method_uint = reinterpret_cast<uint32_t>(method); |
| 49 | uint64_t code_uint = reinterpret_cast<uint32_t>(code); |
| 50 | uint64_t result = ((code_uint << 32) | method_uint); |
| 51 | return result; |
| 52 | } |
| 53 | |
| 54 | // See comments in runtime_support_asm.S |
| 55 | extern "C" uint64_t artInvokeInterfaceTrampoline(uint32_t method_idx, Object* this_object, |
| 56 | Method* caller_method, Thread* self, |
| 57 | Method** sp) { |
| 58 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, false, kInterface); |
| 59 | } |
| 60 | |
| 61 | extern "C" uint64_t artInvokeInterfaceTrampolineWithAccessCheck(uint32_t method_idx, |
| 62 | Object* this_object, |
| 63 | Method* caller_method, Thread* self, |
| 64 | Method** sp) { |
| 65 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kInterface); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | extern "C" uint64_t artInvokeDirectTrampolineWithAccessCheck(uint32_t method_idx, |
| 70 | Object* this_object, |
| 71 | Method* caller_method, Thread* self, |
| 72 | Method** sp) { |
| 73 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kDirect); |
| 74 | } |
| 75 | |
| 76 | extern "C" uint64_t artInvokeStaticTrampolineWithAccessCheck(uint32_t method_idx, |
| 77 | Object* this_object, |
| 78 | Method* caller_method, Thread* self, |
| 79 | Method** sp) { |
| 80 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kStatic); |
| 81 | } |
| 82 | |
| 83 | extern "C" uint64_t artInvokeSuperTrampolineWithAccessCheck(uint32_t method_idx, |
| 84 | Object* this_object, |
| 85 | Method* caller_method, Thread* self, |
| 86 | Method** sp) { |
| 87 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kSuper); |
| 88 | } |
| 89 | |
| 90 | extern "C" uint64_t artInvokeVirtualTrampolineWithAccessCheck(uint32_t method_idx, |
| 91 | Object* this_object, |
| 92 | Method* caller_method, Thread* self, |
| 93 | Method** sp) { |
| 94 | return artInvokeCommon(method_idx, this_object, caller_method, self, sp, true, kVirtual); |
| 95 | } |
| 96 | |
| 97 | } // namespace art |