blob: eeeb79c35171428b679b60730313c5f57d27c069 [file] [log] [blame]
Carl Shapiro69759ea2011-07-21 18:13:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
Carl Shapiro69759ea2011-07-21 18:13:35 -07002
3#ifndef ART_SRC_MARK_STACK_H_
4#define ART_SRC_MARK_STACK_H_
5
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07006#include "logging.h"
7#include "macros.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -07008
9namespace art {
10
11class Object;
12
13class MarkStack {
14 public:
Carl Shapiro58551df2011-07-24 03:09:51 -070015 static MarkStack* Create(size_t maximum_size);
Carl Shapiro69759ea2011-07-21 18:13:35 -070016
17 ~MarkStack();
18
19 void Push(const Object* obj) {
20 DCHECK(obj != NULL);
21 DCHECK_NE(ptr_, limit_);
22 *ptr_ = obj;
23 ++ptr_;
24 }
25
26 const Object* Pop() {
27 DCHECK_NE(ptr_, base_);
28 --ptr_;
29 DCHECK(*ptr_ != NULL);
30 return *ptr_;
31 }
32
33 bool IsEmpty() const {
34 return ptr_ == base_;
35 }
36
37 private:
38 MarkStack() :
39 base_(NULL), limit_(NULL), ptr_(NULL) {
40 }
41
42 bool Init(size_t maximum_size);
43
44 // Base of the mark stack.
45 const Object* const* base_;
46
47 // Exclusive limit of the mark stack.
48 const Object* const* limit_;
49
50 // Pointer to the top of the mark stack.
51 Object const** ptr_;
52
53 DISALLOW_COPY_AND_ASSIGN(MarkStack);
54};
55
56} // namespace art
57
58#endif // ART_SRC_MARK_STACK_H_