blob: a3e19e909fae1eabbe3f54402342bf30762c9310 [file] [log] [blame]
Carl Shapiro69759ea2011-07-21 18:13:35 -07001// 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
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07007#include "logging.h"
8#include "macros.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -07009
10namespace art {
11
12class Object;
13
14class 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_