OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 // Returns the current number of weak handles to global objects. | 151 // Returns the current number of weak handles to global objects. |
152 // These handles are also included in NumberOfWeakHandles(). | 152 // These handles are also included in NumberOfWeakHandles(). |
153 int NumberOfGlobalObjectWeakHandles(); | 153 int NumberOfGlobalObjectWeakHandles(); |
154 | 154 |
155 // Returns the current number of handles to global objects. | 155 // Returns the current number of handles to global objects. |
156 int global_handles_count() const { | 156 int global_handles_count() const { |
157 return number_of_global_handles_; | 157 return number_of_global_handles_; |
158 } | 158 } |
159 | 159 |
160 // Returns the current number of allocated blocks | |
161 int block_count() const { return number_of_blocks_; } | |
162 | |
163 // Clear the weakness of a global handle. | 160 // Clear the weakness of a global handle. |
164 static void ClearWeakness(Object** location); | 161 static void ClearWeakness(Object** location); |
165 | 162 |
166 // Clear the weakness of a global handle. | 163 // Clear the weakness of a global handle. |
167 static void MarkIndependent(Object** location); | 164 static void MarkIndependent(Object** location); |
168 | 165 |
169 // Mark the reference to this object externaly unreachable. | 166 // Mark the reference to this object externaly unreachable. |
170 static void MarkPartiallyDependent(Object** location); | 167 static void MarkPartiallyDependent(Object** location); |
171 | 168 |
172 static bool IsIndependent(Object** location); | 169 static bool IsIndependent(Object** location); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 void RemoveImplicitRefGroups(); | 269 void RemoveImplicitRefGroups(); |
273 | 270 |
274 // Tear down the global handle structure. | 271 // Tear down the global handle structure. |
275 void TearDown(); | 272 void TearDown(); |
276 | 273 |
277 Isolate* isolate() { return isolate_; } | 274 Isolate* isolate() { return isolate_; } |
278 | 275 |
279 #ifdef DEBUG | 276 #ifdef DEBUG |
280 void PrintStats(); | 277 void PrintStats(); |
281 void Print(); | 278 void Print(); |
282 void VerifyBlockInvariants(); | |
283 #endif | 279 #endif |
284 | 280 |
285 private: | 281 private: |
286 explicit GlobalHandles(Isolate* isolate); | 282 explicit GlobalHandles(Isolate* isolate); |
287 | 283 |
288 void SortBlocks(bool shouldPrune); | |
289 | |
290 // Migrates data from the internal representation (object_group_connections_, | 284 // Migrates data from the internal representation (object_group_connections_, |
291 // retainer_infos_ and implicit_ref_connections_) to the public and more | 285 // retainer_infos_ and implicit_ref_connections_) to the public and more |
292 // efficient representation (object_groups_ and implicit_ref_groups_). | 286 // efficient representation (object_groups_ and implicit_ref_groups_). |
293 void ComputeObjectGroupsAndImplicitReferences(); | 287 void ComputeObjectGroupsAndImplicitReferences(); |
294 | 288 |
295 // v8::internal::List is inefficient even for small number of elements, if we | 289 // v8::internal::List is inefficient even for small number of elements, if we |
296 // don't assign any initial capacity. | 290 // don't assign any initial capacity. |
297 static const int kObjectGroupConnectionsCapacity = 20; | 291 static const int kObjectGroupConnectionsCapacity = 20; |
298 | 292 |
299 // Internal node structures. | 293 // Internal node structures. |
300 class Node; | 294 class Node; |
301 class NodeBlock; | 295 class NodeBlock; |
302 class NodeIterator; | 296 class NodeIterator; |
303 class BlockListIterator; | |
304 // Base class for NodeBlock | |
305 class BlockList { | |
306 public: | |
307 BlockList(); | |
308 ~BlockList() { ASSERT(IsDetached()); } | |
309 void Detach(); | |
310 void InsertAsHead(BlockList* block) { | |
311 ASSERT(IsAnchor()); | |
312 InsertAsNext(block); | |
313 } | |
314 void InsertAsTail(BlockList* block) { | |
315 ASSERT(IsAnchor()); | |
316 prev_block_->InsertAsNext(block); | |
317 } | |
318 inline bool IsAnchor() { return first_free_ == NULL && used_nodes_ == 0; } | |
319 inline bool IsDetached() { | |
320 ASSERT_EQ(prev_block_ == this, next_block_ == this); | |
321 return prev_block_ == this; | |
322 } | |
323 bool HasAtLeastLength(int length); | |
324 bool IsUnused() { return used_nodes_ == 0; } | |
325 int used_nodes() const { return used_nodes_; } | |
326 BlockList* next() { return next_block_; } | |
327 BlockList* prev() { return prev_block_; } | |
328 #ifdef DEBUG | |
329 int LengthOfFreeList(); | |
330 #endif | |
331 static void SortBlocks(GlobalHandles* global_handles, bool prune); | |
332 | |
333 protected: | |
334 BlockList* prev_block_; | |
335 BlockList* next_block_; | |
336 Node* first_free_; | |
337 int used_nodes_; | |
338 | |
339 private: | |
340 // Needed for quicksort | |
341 static int CompareBlocks(const void* a, const void* b); | |
342 void InsertAsNext(BlockList* block); | |
343 DISALLOW_COPY_AND_ASSIGN(BlockList); | |
344 }; | |
345 | 297 |
346 Isolate* isolate_; | 298 Isolate* isolate_; |
347 | 299 |
348 // Field always containing the number of blocks allocated. | |
349 int number_of_blocks_; | |
350 // Field always containing the number of handles to global objects. | 300 // Field always containing the number of handles to global objects. |
351 int number_of_global_handles_; | 301 int number_of_global_handles_; |
352 | 302 |
353 // Anchors for doubly linked lists of blocks | 303 // List of all allocated node blocks. |
354 BlockList full_blocks_; | 304 NodeBlock* first_block_; |
355 BlockList non_full_blocks_; | |
356 | 305 |
357 // An array of all the anchors held by GlobalHandles. | 306 // List of node blocks with used nodes. |
358 // This simplifies iteration across all blocks. | 307 NodeBlock* first_used_block_; |
359 static const int kAllAnchorsSize = 2; | 308 |
360 BlockList* all_anchors_[kAllAnchorsSize]; | 309 // Free list of nodes. |
| 310 Node* first_free_; |
361 | 311 |
362 // Contains all nodes holding new space objects. Note: when the list | 312 // Contains all nodes holding new space objects. Note: when the list |
363 // is accessed, some of the objects may have been promoted already. | 313 // is accessed, some of the objects may have been promoted already. |
364 List<Node*> new_space_nodes_; | 314 List<Node*> new_space_nodes_; |
365 | 315 |
366 int post_gc_processing_count_; | 316 int post_gc_processing_count_; |
367 | 317 |
368 // Object groups and implicit references, public and more efficient | 318 // Object groups and implicit references, public and more efficient |
369 // representation. | 319 // representation. |
370 List<ObjectGroup*> object_groups_; | 320 List<ObjectGroup*> object_groups_; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 List<int> new_space_indices_; | 398 List<int> new_space_indices_; |
449 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; | 399 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
450 | 400 |
451 DISALLOW_COPY_AND_ASSIGN(EternalHandles); | 401 DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
452 }; | 402 }; |
453 | 403 |
454 | 404 |
455 } } // namespace v8::internal | 405 } } // namespace v8::internal |
456 | 406 |
457 #endif // V8_GLOBAL_HANDLES_H_ | 407 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |