blob: f8beaff16a565e15b4b144c1d2591b360a0fd602 [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
Elliott Hughes90a33692011-08-30 13:27:07 -07006#include "UniquePtr.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07007#include "logging.h"
8#include "macros.h"
Brian Carlstromdb4d5402011-08-09 12:18:28 -07009#include "mem_map.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070010
11namespace art {
12
13class Object;
14
15class MarkStack {
16 public:
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070017 static MarkStack* Create();
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
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070044 bool Init();
Carl Shapiro69759ea2011-07-21 18:13:35 -070045
Brian Carlstromdb4d5402011-08-09 12:18:28 -070046 // Memory mapping of the mark stack.
Elliott Hughes90a33692011-08-30 13:27:07 -070047 UniquePtr<MemMap> mem_map_;
Brian Carlstromdb4d5402011-08-09 12:18:28 -070048
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_