blob: cd308c53b174f4dbb39716dea54e55fc71fd7075 [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
Mathieu Chartier5301cd22012-05-31 12:11:36 -070053 void Reset();
54
Carl Shapiro69759ea2011-07-21 18:13:35 -070055 private:
56 MarkStack() :
Ian Rogers30fab402012-01-23 15:43:46 -080057 begin_(NULL), limit_(NULL), ptr_(NULL) {
Carl Shapiro69759ea2011-07-21 18:13:35 -070058 }
59
Jesse Wilson078f9b02011-11-18 17:51:47 -050060 void Init();
Carl Shapiro69759ea2011-07-21 18:13:35 -070061
Brian Carlstromdb4d5402011-08-09 12:18:28 -070062 // Memory mapping of the mark stack.
Elliott Hughes90a33692011-08-30 13:27:07 -070063 UniquePtr<MemMap> mem_map_;
Brian Carlstromdb4d5402011-08-09 12:18:28 -070064
Carl Shapiro69759ea2011-07-21 18:13:35 -070065 // Base of the mark stack.
Ian Rogers30fab402012-01-23 15:43:46 -080066 const Object* const* begin_;
Carl Shapiro69759ea2011-07-21 18:13:35 -070067
68 // Exclusive limit of the mark stack.
69 const Object* const* limit_;
70
71 // Pointer to the top of the mark stack.
72 Object const** ptr_;
73
74 DISALLOW_COPY_AND_ASSIGN(MarkStack);
75};
76
77} // namespace art
78
79#endif // ART_SRC_MARK_STACK_H_