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