blob: 38252c275070fc3f3a99e208844f1f698c2cf04a [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"
Brian Carlstromdb4d5402011-08-09 12:18:28 -07008#include "mem_map.h"
9#include "scoped_ptr.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070010
11namespace art {
12
13class Object;
14
15class MarkStack {
16 public:
Carl Shapiro58551df2011-07-24 03:09:51 -070017 static MarkStack* Create(size_t maximum_size);
Carl Shapiro69759ea2011-07-21 18:13:35 -070018
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
44 bool Init(size_t maximum_size);
45
Brian Carlstromdb4d5402011-08-09 12:18:28 -070046 // Memory mapping of the mark stack.
47 scoped_ptr<MemMap> mem_map_;
48
Carl Shapiro69759ea2011-07-21 18:13:35 -070049 // 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_