blob: 28ad1651ef5d4d87ceb39e783a36bdd7bdd7ef26 [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() {
Ian Rogers30fab402012-01-23 15:43:46 -080029 DCHECK_NE(ptr_, begin_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070030 --ptr_;
31 DCHECK(*ptr_ != NULL);
32 return *ptr_;
33 }
34
35 bool IsEmpty() const {
Ian Rogers30fab402012-01-23 15:43:46 -080036 return ptr_ == begin_;
Carl Shapiro69759ea2011-07-21 18:13:35 -070037 }
38
39 private:
40 MarkStack() :
Ian Rogers30fab402012-01-23 15:43:46 -080041 begin_(NULL), limit_(NULL), ptr_(NULL) {
Carl Shapiro69759ea2011-07-21 18:13:35 -070042 }
43
Jesse Wilson078f9b02011-11-18 17:51:47 -050044 void 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.
Ian Rogers30fab402012-01-23 15:43:46 -080050 const Object* const* begin_;
Carl Shapiro69759ea2011-07-21 18:13:35 -070051
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_