blob: 4301e0e5196da075917868891965fb6be77cc1a4 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiro69759ea2011-07-21 18:13:35 -070016
17#ifndef ART_SRC_MARK_STACK_H_
18#define ART_SRC_MARK_STACK_H_
19
Elliott Hughes90a33692011-08-30 13:27:07 -070020#include "UniquePtr.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021#include "logging.h"
22#include "macros.h"
Brian Carlstromdb4d5402011-08-09 12:18:28 -070023#include "mem_map.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070024
25namespace art {
26
27class Object;
28
29class MarkStack {
30 public:
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070031 static MarkStack* Create();
Carl Shapiro69759ea2011-07-21 18:13:35 -070032
33 ~MarkStack();
34
35 void Push(const Object* obj) {
36 DCHECK(obj != NULL);
37 DCHECK_NE(ptr_, limit_);
38 *ptr_ = obj;
39 ++ptr_;
40 }
41
42 const Object* Pop() {
Ian Rogers30fab402012-01-23 15:43:46 -080043 DCHECK_NE(ptr_, begin_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070044 --ptr_;
45 DCHECK(*ptr_ != NULL);
46 return *ptr_;
47 }
48
49 bool IsEmpty() const {
Ian Rogers30fab402012-01-23 15:43:46 -080050 return ptr_ == begin_;
Carl Shapiro69759ea2011-07-21 18:13:35 -070051 }
52
53 private:
54 MarkStack() :
Ian Rogers30fab402012-01-23 15:43:46 -080055 begin_(NULL), limit_(NULL), ptr_(NULL) {
Carl Shapiro69759ea2011-07-21 18:13:35 -070056 }
57
Jesse Wilson078f9b02011-11-18 17:51:47 -050058 void Init();
Carl Shapiro69759ea2011-07-21 18:13:35 -070059
Brian Carlstromdb4d5402011-08-09 12:18:28 -070060 // Memory mapping of the mark stack.
Elliott Hughes90a33692011-08-30 13:27:07 -070061 UniquePtr<MemMap> mem_map_;
Brian Carlstromdb4d5402011-08-09 12:18:28 -070062
Carl Shapiro69759ea2011-07-21 18:13:35 -070063 // Base of the mark stack.
Ian Rogers30fab402012-01-23 15:43:46 -080064 const Object* const* begin_;
Carl Shapiro69759ea2011-07-21 18:13:35 -070065
66 // Exclusive limit of the mark stack.
67 const Object* const* limit_;
68
69 // Pointer to the top of the mark stack.
70 Object const** ptr_;
71
72 DISALLOW_COPY_AND_ASSIGN(MarkStack);
73};
74
75} // namespace art
76
77#endif // ART_SRC_MARK_STACK_H_