blob: 868b157e98a73a443c02524f26876949ce814c98 [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#ifndef ART_SRC_STACK_H_
18#define ART_SRC_STACK_H_
19
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080020#include "dex_file.h"
Elliott Hughesbfe487b2011-10-26 15:48:55 -070021#include "jni.h"
Elliott Hughes68e76522011-10-05 13:22:16 -070022#include "macros.h"
23
24#include <stdint.h>
25
26namespace art {
27
28class Method;
29class Thread;
30
Elliott Hughesbfe487b2011-10-26 15:48:55 -070031jobject GetThreadStack(JNIEnv*, Thread*);
32
Elliott Hughes68e76522011-10-05 13:22:16 -070033struct NativeToManagedRecord {
34 NativeToManagedRecord* link_;
35 void* last_top_of_managed_stack_;
36 uintptr_t last_top_of_managed_stack_pc_;
37};
38
39// Iterator over managed frames up to the first native-to-managed transition.
40class PACKED Frame {
41 public:
42 Frame() : sp_(NULL) {}
43
44 Method* GetMethod() const {
45 return (sp_ != NULL) ? *sp_ : NULL;
46 }
47
48 bool HasNext() const {
49 return NextMethod() != NULL;
50 }
51
52 void Next();
53
54 uintptr_t GetReturnPC() const;
55
jeffhaoe343b762011-12-05 16:36:44 -080056 void SetReturnPC(uintptr_t pc);
57
Elliott Hughes68e76522011-10-05 13:22:16 -070058 uintptr_t LoadCalleeSave(int num) const;
59
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080060
61 uint32_t GetVReg(const DexFile::CodeItem* code_item, uint32_t core_spills, uint32_t fp_spills,
62 size_t frame_size, int vreg) const;
63
64 uintptr_t GetVReg(Method* m, int vreg) const;
Elliott Hughescccd84f2011-12-05 16:51:54 -080065 void SetVReg(Method* method, int vreg, uint32_t new_value);
Elliott Hughes68e76522011-10-05 13:22:16 -070066
67 Method** GetSP() const {
68 return sp_;
69 }
70
71 // TODO: this is here for testing, remove when we have exception unit tests
72 // that use the real stack
73 void SetSP(Method** sp) {
74 sp_ = sp;
75 }
76
77 // Is this a frame for a real method (native or with dex code)
78 bool HasMethod() const;
79
80 private:
81 Method* NextMethod() const;
82
83 friend class Thread;
84
85 Method** sp_;
86};
87
88} // namespace art
89
90#endif // ART_SRC_STACK_H_