blob: 985fd3851993d0d72b21c738e2c20e19ca072c8d [file] [log] [blame]
Elliott Hughes68e76522011-10-05 13:22:16 -07001/*
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 Carlstrom3320cf42011-10-04 14:58:28 -070022int oatVRegOffsetFromMethod(art::Method* method, int reg);
23
Elliott Hughes68e76522011-10-05 13:22:16 -070024namespace art {
25
26bool Frame::HasMethod() const {
Brian Carlstrom3320cf42011-10-04 14:58:28 -070027 return GetMethod() != NULL && (!GetMethod()->IsCalleeSaveMethod());
Elliott Hughes68e76522011-10-05 13:22:16 -070028}
29
30void 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
42uintptr_t Frame::GetReturnPC() const {
43 byte* pc_addr = reinterpret_cast<byte*>(sp_) + GetMethod()->GetReturnPcOffsetInBytes();
44 return *reinterpret_cast<uintptr_t*>(pc_addr);
45}
46
47uintptr_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
54uintptr_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
66Method* 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