OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_HANDLES_H_ | 5 #ifndef VM_HANDLES_H_ |
6 #define VM_HANDLES_H_ | 6 #define VM_HANDLES_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 } | 68 } |
69 }; | 69 }; |
70 | 70 |
71 | 71 |
72 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 72 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
73 class Handles { | 73 class Handles { |
74 public: | 74 public: |
75 Handles() | 75 Handles() |
76 : zone_blocks_(NULL), | 76 : zone_blocks_(NULL), |
77 first_scoped_block_(NULL), | 77 first_scoped_block_(NULL), |
78 scoped_blocks_(&first_scoped_block_) { | 78 scoped_blocks_(&first_scoped_block_), |
79 last_visited_block_(NULL) { | |
79 } | 80 } |
80 ~Handles() { | 81 ~Handles() { |
81 DeleteAll(); | 82 DeleteAll(); |
82 } | 83 } |
83 | 84 |
84 // Visit all object pointers stored in the various handles. | 85 // Visit all object pointers stored in the various handles. |
85 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 86 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
86 | 87 |
88 // Visit only the scoped handles | |
siva
2012/12/14 02:11:54
missing period.
cshapiro
2012/12/15 19:56:49
Done.
| |
89 void VisitScopedHandles(ObjectPointerVisitor* visitor); | |
90 | |
91 // Visit all blocks that have been added since the last time | |
92 // this method was called. | |
93 // Be careful with this, since multiple users of this method could | |
94 // interfere with eachother. | |
95 // Currently only used by GC trace facility. | |
96 void VisitUnvisitedScopedHandles(ObjectPointerVisitor* visitor); | |
97 | |
87 // Visit all of the various handles. | 98 // Visit all of the various handles. |
88 void Visit(HandleVisitor* visitor); | 99 void Visit(HandleVisitor* visitor); |
89 | 100 |
90 // Allocates a handle in the current handle scope. This handle is valid only | 101 // Allocates a handle in the current handle scope. This handle is valid only |
91 // in the current handle scope and is destroyed when the current handle | 102 // in the current handle scope and is destroyed when the current handle |
92 // scope ends. | 103 // scope ends. |
93 static uword AllocateHandle(Isolate* isolate); | 104 static uword AllocateHandle(Isolate* isolate); |
94 | 105 |
95 // Allocates a handle in the current zone. This handle will be destroyed | 106 // Allocates a handle in the current zone. This handle will be destroyed |
96 // when the current zone is destroyed. | 107 // when the current zone is destroyed. |
(...skipping 22 matching lines...) Expand all Loading... | |
119 private: | 130 private: |
120 // Base structure for managing blocks of handles. | 131 // Base structure for managing blocks of handles. |
121 // Handles are allocated in Chunks (each chunk holds kHandlesPerChunk | 132 // Handles are allocated in Chunks (each chunk holds kHandlesPerChunk |
122 // handles). The chunk is uninitialized, subsequent requests for handles | 133 // handles). The chunk is uninitialized, subsequent requests for handles |
123 // is allocated from the chunk until we run out space in the chunk, | 134 // is allocated from the chunk until we run out space in the chunk, |
124 // at this point another chunk is allocated. These chunks are chained | 135 // at this point another chunk is allocated. These chunks are chained |
125 // together. | 136 // together. |
126 class HandlesBlock { | 137 class HandlesBlock { |
127 public: | 138 public: |
128 explicit HandlesBlock(HandlesBlock* next) | 139 explicit HandlesBlock(HandlesBlock* next) |
129 : next_handle_slot_(0), | 140 : last_visited_handle_(0), |
141 next_handle_slot_(0), | |
130 next_block_(next) { } | 142 next_block_(next) { } |
131 ~HandlesBlock(); | 143 ~HandlesBlock(); |
132 | 144 |
133 // Reinitializes handle block for reuse. | 145 // Reinitializes handle block for reuse. |
134 void ReInit(); | 146 void ReInit(); |
135 | 147 |
136 // Returns true if the handle block is full. | 148 // Returns true if the handle block is full. |
137 bool IsFull() const { | 149 bool IsFull() const { |
138 return next_handle_slot_ >= (kHandleSizeInWords * kHandlesPerChunk); | 150 return next_handle_slot_ >= (kHandleSizeInWords * kHandlesPerChunk); |
139 } | 151 } |
140 | 152 |
141 // Returns true if passed in handle belongs to this block. | 153 // Returns true if passed in handle belongs to this block. |
142 bool IsValidHandle(uword handle) const { | 154 bool IsValidHandle(uword handle) const { |
143 uword start = reinterpret_cast<uword>(data_); | 155 uword start = reinterpret_cast<uword>(data_); |
144 uword end = start + (kHandleSizeInWords * kWordSize * kHandlesPerChunk); | 156 uword end = start + (kHandleSizeInWords * kWordSize * kHandlesPerChunk); |
145 return (start <= handle && handle < end); | 157 return (start <= handle && handle < end); |
146 } | 158 } |
147 | 159 |
148 // Allocates space for a handle in the data area. | 160 // Allocates space for a handle in the data area. |
149 uword AllocateHandle() { | 161 uword AllocateHandle() { |
150 ASSERT(!IsFull()); | 162 ASSERT(!IsFull()); |
151 uword handle_address = reinterpret_cast<uword>(data_ + next_handle_slot_); | 163 uword handle_address = reinterpret_cast<uword>(data_ + next_handle_slot_); |
152 next_handle_slot_ += kHandleSizeInWords; | 164 next_handle_slot_ += kHandleSizeInWords; |
153 return handle_address; | 165 return handle_address; |
154 } | 166 } |
155 | 167 |
156 // Visit all object pointers in the handle block. | 168 // Visit all object pointers in the handle block. |
157 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 169 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
158 | 170 |
171 // Visit all the object pointers in the block since the last time this | |
172 // method was called. | |
173 void VisitUnvisitedObjectPointers(ObjectPointerVisitor* visitor); | |
174 | |
159 // Visit all of the handles in the handle block. | 175 // Visit all of the handles in the handle block. |
160 void Visit(HandleVisitor* visitor); | 176 void Visit(HandleVisitor* visitor); |
161 | 177 |
162 #if defined(DEBUG) | 178 #if defined(DEBUG) |
163 // Zaps the free handle area to an uninitialized value. | 179 // Zaps the free handle area to an uninitialized value. |
164 void ZapFreeHandles(); | 180 void ZapFreeHandles(); |
165 #endif | 181 #endif |
166 | 182 |
167 // Returns number of active handles in the handle block. | 183 // Returns number of active handles in the handle block. |
168 int HandleCount() const; | 184 int HandleCount() const; |
169 | 185 |
170 // Accessors. | 186 // Accessors. |
171 intptr_t next_handle_slot() const { return next_handle_slot_; } | 187 intptr_t next_handle_slot() const { return next_handle_slot_; } |
172 void set_next_handle_slot(intptr_t next_handle_slot) { | 188 void set_next_handle_slot(intptr_t next_handle_slot) { |
173 next_handle_slot_ = next_handle_slot; | 189 next_handle_slot_ = next_handle_slot; |
174 } | 190 } |
175 HandlesBlock* next_block() const { return next_block_; } | 191 HandlesBlock* next_block() const { return next_block_; } |
176 void set_next_block(HandlesBlock* next) { next_block_ = next; } | 192 void set_next_block(HandlesBlock* next) { next_block_ = next; } |
177 | 193 |
178 private: | 194 private: |
195 // Last handle visited by VisitUnvisitedObjectPointers. Handles | |
196 // at, or beyond this index are new. | |
197 intptr_t last_visited_handle_; | |
198 | |
179 uword data_[kHandleSizeInWords * kHandlesPerChunk]; // Handles area. | 199 uword data_[kHandleSizeInWords * kHandlesPerChunk]; // Handles area. |
180 intptr_t next_handle_slot_; // Next slot for allocation in current block. | 200 intptr_t next_handle_slot_; // Next slot for allocation in current block. |
181 HandlesBlock* next_block_; // Link to next block of handles. | 201 HandlesBlock* next_block_; // Link to next block of handles. |
182 | 202 |
183 DISALLOW_COPY_AND_ASSIGN(HandlesBlock); | 203 DISALLOW_COPY_AND_ASSIGN(HandlesBlock); |
184 }; | 204 }; |
185 | 205 |
186 // Deletes all the allocated handle blocks. | 206 // Deletes all the allocated handle blocks. |
187 void DeleteAll(); | 207 void DeleteAll(); |
188 void DeleteHandleBlocks(HandlesBlock* blocks); | 208 void DeleteHandleBlocks(HandlesBlock* blocks); |
(...skipping 16 matching lines...) Expand all Loading... | |
205 // Verifies consistency of handle blocks after a scope is destroyed. | 225 // Verifies consistency of handle blocks after a scope is destroyed. |
206 void VerifyScopedHandleState(); | 226 void VerifyScopedHandleState(); |
207 | 227 |
208 // Zaps the free scoped handles to an uninitialized value. | 228 // Zaps the free scoped handles to an uninitialized value. |
209 void ZapFreeScopedHandles(); | 229 void ZapFreeScopedHandles(); |
210 #endif | 230 #endif |
211 | 231 |
212 HandlesBlock* zone_blocks_; // List of zone handles. | 232 HandlesBlock* zone_blocks_; // List of zone handles. |
213 HandlesBlock first_scoped_block_; // First block of scoped handles. | 233 HandlesBlock first_scoped_block_; // First block of scoped handles. |
214 HandlesBlock* scoped_blocks_; // List of scoped handles. | 234 HandlesBlock* scoped_blocks_; // List of scoped handles. |
235 // Last block visited by VisitUnvisitedHandles. | |
236 HandlesBlock* last_visited_block_; | |
215 | 237 |
216 friend class HandleScope; | 238 friend class HandleScope; |
217 DISALLOW_ALLOCATION(); | 239 DISALLOW_ALLOCATION(); |
218 DISALLOW_COPY_AND_ASSIGN(Handles); | 240 DISALLOW_COPY_AND_ASSIGN(Handles); |
219 }; | 241 }; |
220 | 242 |
221 | 243 |
222 static const int kVMHandleSizeInWords = 2; | 244 static const int kVMHandleSizeInWords = 2; |
223 static const int kVMHandlesPerChunk = 64; | 245 static const int kVMHandlesPerChunk = 64; |
224 static const int kOffsetOfRawPtr = kWordSize; | 246 static const int kOffsetOfRawPtr = kWordSize; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 }; | 338 }; |
317 #endif // defined(DEBUG) | 339 #endif // defined(DEBUG) |
318 | 340 |
319 // Macro to start a no handles scope in the code. | 341 // Macro to start a no handles scope in the code. |
320 #define NOHANDLESCOPE(isolate) \ | 342 #define NOHANDLESCOPE(isolate) \ |
321 dart::NoHandleScope no_vm_internal_handles_scope_(isolate); | 343 dart::NoHandleScope no_vm_internal_handles_scope_(isolate); |
322 | 344 |
323 } // namespace dart | 345 } // namespace dart |
324 | 346 |
325 #endif // VM_HANDLES_H_ | 347 #endif // VM_HANDLES_H_ |
OLD | NEW |