blob: a0f13d35355f80b4df45b4d23522ef8200c2941c [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
Elliott Hughesbfe487b2011-10-26 15:48:55 -070020#include "jni.h"
Elliott Hughes68e76522011-10-05 13:22:16 -070021#include "macros.h"
22
23#include <stdint.h>
24
25namespace art {
26
27class Method;
28class Thread;
29
Elliott Hughesbfe487b2011-10-26 15:48:55 -070030jobject GetThreadStack(JNIEnv*, Thread*);
31
Elliott Hughes68e76522011-10-05 13:22:16 -070032struct NativeToManagedRecord {
33 NativeToManagedRecord* link_;
34 void* last_top_of_managed_stack_;
35 uintptr_t last_top_of_managed_stack_pc_;
36};
37
38// Iterator over managed frames up to the first native-to-managed transition.
39class PACKED Frame {
40 public:
41 Frame() : sp_(NULL) {}
42
43 Method* GetMethod() const {
44 return (sp_ != NULL) ? *sp_ : NULL;
45 }
46
47 bool HasNext() const {
48 return NextMethod() != NULL;
49 }
50
51 void Next();
52
53 uintptr_t GetReturnPC() const;
54
55 uintptr_t LoadCalleeSave(int num) const;
56
Elliott Hughes1bba14f2011-12-01 18:00:36 -080057 uint32_t GetVReg(Method* method, int vreg) const;
Elliott Hughescccd84f2011-12-05 16:51:54 -080058 void SetVReg(Method* method, int vreg, uint32_t new_value);
Elliott Hughes68e76522011-10-05 13:22:16 -070059
60 Method** GetSP() const {
61 return sp_;
62 }
63
64 // TODO: this is here for testing, remove when we have exception unit tests
65 // that use the real stack
66 void SetSP(Method** sp) {
67 sp_ = sp;
68 }
69
70 // Is this a frame for a real method (native or with dex code)
71 bool HasMethod() const;
72
73 private:
74 Method* NextMethod() const;
75
76 friend class Thread;
77
78 Method** sp_;
79};
80
81} // namespace art
82
83#endif // ART_SRC_STACK_H_