Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_MARK_STACK_H_ |
| 18 | #define ART_SRC_MARK_STACK_H_ |
| 19 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 20 | #include "UniquePtr.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 21 | #include "logging.h" |
| 22 | #include "macros.h" |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 23 | #include "mem_map.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | class Object; |
| 28 | |
| 29 | class MarkStack { |
| 30 | public: |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 31 | static MarkStack* Create(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 32 | |
| 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 Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 43 | DCHECK_NE(ptr_, begin_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 44 | --ptr_; |
| 45 | DCHECK(*ptr_ != NULL); |
| 46 | return *ptr_; |
| 47 | } |
| 48 | |
| 49 | bool IsEmpty() const { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 50 | return ptr_ == begin_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 53 | void Reset(); |
| 54 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 55 | private: |
| 56 | MarkStack() : |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 57 | begin_(NULL), limit_(NULL), ptr_(NULL) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Jesse Wilson | 078f9b0 | 2011-11-18 17:51:47 -0500 | [diff] [blame] | 60 | void Init(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 61 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 62 | // Memory mapping of the mark stack. |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 63 | UniquePtr<MemMap> mem_map_; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 64 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 65 | // Base of the mark stack. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 66 | const Object* const* begin_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 67 | |
| 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_ |