blob: f1fb08f9ffe023bc89befdb8c2a769748afe709d [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
57 uintptr_t GetVReg(Method* method, int vreg) const;
58
59 Method** GetSP() const {
60 return sp_;
61 }
62
63 // TODO: this is here for testing, remove when we have exception unit tests
64 // that use the real stack
65 void SetSP(Method** sp) {
66 sp_ = sp;
67 }
68
69 // Is this a frame for a real method (native or with dex code)
70 bool HasMethod() const;
71
72 private:
73 Method* NextMethod() const;
74
75 friend class Thread;
76
77 Method** sp_;
78};
79
80} // namespace art
81
82#endif // ART_SRC_STACK_H_