Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 2 | |
| 3 | #ifndef ART_SRC_MARK_STACK_H_ |
| 4 | #define ART_SRC_MARK_STACK_H_ |
| 5 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 6 | #include "UniquePtr.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 7 | #include "logging.h" |
| 8 | #include "macros.h" |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 9 | #include "mem_map.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 10 | |
| 11 | namespace art { |
| 12 | |
| 13 | class Object; |
| 14 | |
| 15 | class MarkStack { |
| 16 | public: |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 17 | static MarkStack* Create(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 18 | |
| 19 | ~MarkStack(); |
| 20 | |
| 21 | void Push(const Object* obj) { |
| 22 | DCHECK(obj != NULL); |
| 23 | DCHECK_NE(ptr_, limit_); |
| 24 | *ptr_ = obj; |
| 25 | ++ptr_; |
| 26 | } |
| 27 | |
| 28 | const Object* Pop() { |
| 29 | DCHECK_NE(ptr_, base_); |
| 30 | --ptr_; |
| 31 | DCHECK(*ptr_ != NULL); |
| 32 | return *ptr_; |
| 33 | } |
| 34 | |
| 35 | bool IsEmpty() const { |
| 36 | return ptr_ == base_; |
| 37 | } |
| 38 | |
| 39 | private: |
| 40 | MarkStack() : |
| 41 | base_(NULL), limit_(NULL), ptr_(NULL) { |
| 42 | } |
| 43 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 44 | bool Init(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 45 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 46 | // Memory mapping of the mark stack. |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 47 | UniquePtr<MemMap> mem_map_; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 48 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 49 | // Base of the mark stack. |
| 50 | const Object* const* base_; |
| 51 | |
| 52 | // Exclusive limit of the mark stack. |
| 53 | const Object* const* limit_; |
| 54 | |
| 55 | // Pointer to the top of the mark stack. |
| 56 | Object const** ptr_; |
| 57 | |
| 58 | DISALLOW_COPY_AND_ASSIGN(MarkStack); |
| 59 | }; |
| 60 | |
| 61 | } // namespace art |
| 62 | |
| 63 | #endif // ART_SRC_MARK_STACK_H_ |