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 | #ifndef ART_SRC_STACK_H_ |
| 18 | #define ART_SRC_STACK_H_ |
| 19 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 20 | #include "dex_file.h" |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 21 | #include "jni.h" |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 22 | #include "macros.h" |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | class Method; |
| 29 | class Thread; |
| 30 | |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 31 | jobject GetThreadStack(JNIEnv*, Thread*); |
| 32 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 33 | struct 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. |
| 40 | class PACKED Frame { |
| 41 | public: |
| 42 | Frame() : sp_(NULL) {} |
| 43 | |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 44 | Frame(Method** sp) : sp_(sp) {} |
| 45 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 46 | Method* GetMethod() const { |
| 47 | return (sp_ != NULL) ? *sp_ : NULL; |
| 48 | } |
| 49 | |
| 50 | bool HasNext() const { |
| 51 | return NextMethod() != NULL; |
| 52 | } |
| 53 | |
| 54 | void Next(); |
| 55 | |
| 56 | uintptr_t GetReturnPC() const; |
| 57 | |
jeffhao | e343b76 | 2011-12-05 16:36:44 -0800 | [diff] [blame] | 58 | void SetReturnPC(uintptr_t pc); |
| 59 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 60 | uintptr_t LoadCalleeSave(int num) const; |
| 61 | |
buzbee | efccc56 | 2012-03-11 11:19:28 -0700 | [diff] [blame] | 62 | static int GetVRegOffset(const DexFile::CodeItem* code_item, uint32_t core_spills, |
| 63 | uint32_t fp_spills, size_t frame_size, int reg); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 64 | |
| 65 | uint32_t GetVReg(const DexFile::CodeItem* code_item, uint32_t core_spills, uint32_t fp_spills, |
| 66 | size_t frame_size, int vreg) const; |
| 67 | |
Elliott Hughes | 215f314 | 2012-01-19 00:22:47 -0800 | [diff] [blame] | 68 | uint32_t GetVReg(Method* m, int vreg) const; |
Elliott Hughes | cccd84f | 2011-12-05 16:51:54 -0800 | [diff] [blame] | 69 | void SetVReg(Method* method, int vreg, uint32_t new_value); |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 70 | |
| 71 | Method** GetSP() const { |
| 72 | return sp_; |
| 73 | } |
| 74 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 75 | void SetSP(Method** sp) { |
| 76 | sp_ = sp; |
| 77 | } |
| 78 | |
| 79 | // Is this a frame for a real method (native or with dex code) |
| 80 | bool HasMethod() const; |
| 81 | |
| 82 | private: |
| 83 | Method* NextMethod() const; |
| 84 | |
| 85 | friend class Thread; |
| 86 | |
| 87 | Method** sp_; |
| 88 | }; |
| 89 | |
| 90 | } // namespace art |
| 91 | |
| 92 | #endif // ART_SRC_STACK_H_ |