Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2011 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 "stack.h" |
| 18 | |
| 19 | #include "compiler.h" |
| 20 | #include "object.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | bool Frame::HasMethod() const { |
| 25 | return GetMethod() != NULL && (!GetMethod()->IsPhony()); |
| 26 | } |
| 27 | |
| 28 | void Frame::Next() { |
| 29 | size_t frame_size = GetMethod()->GetFrameSizeInBytes(); |
| 30 | DCHECK_NE(frame_size, 0u); |
| 31 | DCHECK_LT(frame_size, 1024u); |
| 32 | byte* next_sp = reinterpret_cast<byte*>(sp_) + frame_size; |
| 33 | sp_ = reinterpret_cast<Method**>(next_sp); |
| 34 | if (*sp_ != NULL) { |
| 35 | DCHECK((*sp_)->GetClass() == Method::GetMethodClass() || |
| 36 | (*sp_)->GetClass() == Method::GetConstructorClass()); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | uintptr_t Frame::GetReturnPC() const { |
| 41 | byte* pc_addr = reinterpret_cast<byte*>(sp_) + GetMethod()->GetReturnPcOffsetInBytes(); |
| 42 | return *reinterpret_cast<uintptr_t*>(pc_addr); |
| 43 | } |
| 44 | |
| 45 | uintptr_t Frame::GetVReg(Method* method, int vreg) const { |
| 46 | DCHECK(method == GetMethod()); |
| 47 | int offset = oatVRegOffsetFromMethod(method, vreg); |
| 48 | byte* vreg_addr = reinterpret_cast<byte*>(sp_) + offset; |
| 49 | return *reinterpret_cast<uintptr_t*>(vreg_addr); |
| 50 | } |
| 51 | |
| 52 | uintptr_t Frame::LoadCalleeSave(int num) const { |
| 53 | // Callee saves are held at the top of the frame |
| 54 | Method* method = GetMethod(); |
| 55 | DCHECK(method != NULL); |
| 56 | size_t frame_size = method->GetFrameSizeInBytes(); |
| 57 | byte* save_addr = reinterpret_cast<byte*>(sp_) + frame_size - ((num + 1) * kPointerSize); |
| 58 | #if defined(__i386__) |
| 59 | save_addr -= kPointerSize; // account for return address |
| 60 | #endif |
| 61 | return *reinterpret_cast<uintptr_t*>(save_addr); |
| 62 | } |
| 63 | |
| 64 | Method* Frame::NextMethod() const { |
| 65 | byte* next_sp = reinterpret_cast<byte*>(sp_) + GetMethod()->GetFrameSizeInBytes(); |
| 66 | return *reinterpret_cast<Method**>(next_sp); |
| 67 | } |
| 68 | |
| 69 | } // namespace art |