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