| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // next live object in the same page. For spaces using a different | 120 // next live object in the same page. For spaces using a different |
| 121 // encoding (ie, contiguous spaces), the offset parameter is ignored. | 121 // encoding (ie, contiguous spaces), the offset parameter is ignored. |
| 122 typedef void (*EncodingFunction)(HeapObject* old_object, | 122 typedef void (*EncodingFunction)(HeapObject* old_object, |
| 123 int object_size, | 123 int object_size, |
| 124 Object* new_object, | 124 Object* new_object, |
| 125 int* offset); | 125 int* offset); |
| 126 | 126 |
| 127 // Type of functions to process non-live objects. | 127 // Type of functions to process non-live objects. |
| 128 typedef void (*ProcessNonLiveFunction)(HeapObject* object); | 128 typedef void (*ProcessNonLiveFunction)(HeapObject* object); |
| 129 | 129 |
| 130 // Pointer to member function, used in IterateLiveObjects. |
| 131 typedef int (MarkCompactCollector::*LiveObjectCallback)(HeapObject* obj); |
| 132 |
| 130 // Set the global force_compaction flag, it must be called before Prepare | 133 // Set the global force_compaction flag, it must be called before Prepare |
| 131 // to take effect. | 134 // to take effect. |
| 132 void SetForceCompaction(bool value) { | 135 void SetForceCompaction(bool value) { |
| 133 force_compaction_ = value; | 136 force_compaction_ = value; |
| 134 } | 137 } |
| 135 | 138 |
| 136 | 139 |
| 137 static void Initialize(); | 140 static void Initialize(); |
| 138 | 141 |
| 139 // Prepares for GC by resetting relocation info in old and map spaces and | 142 // Prepares for GC by resetting relocation info in old and map spaces and |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 360 |
| 358 // Function template to encode the forwarding addresses of objects in | 361 // Function template to encode the forwarding addresses of objects in |
| 359 // paged spaces, parameterized by allocation and non-live processing | 362 // paged spaces, parameterized by allocation and non-live processing |
| 360 // functions. | 363 // functions. |
| 361 template<AllocationFunction Alloc, ProcessNonLiveFunction ProcessNonLive> | 364 template<AllocationFunction Alloc, ProcessNonLiveFunction ProcessNonLive> |
| 362 void EncodeForwardingAddressesInPagedSpace(PagedSpace* space); | 365 void EncodeForwardingAddressesInPagedSpace(PagedSpace* space); |
| 363 | 366 |
| 364 // Iterates live objects in a space, passes live objects | 367 // Iterates live objects in a space, passes live objects |
| 365 // to a callback function which returns the heap size of the object. | 368 // to a callback function which returns the heap size of the object. |
| 366 // Returns the number of live objects iterated. | 369 // Returns the number of live objects iterated. |
| 367 int IterateLiveObjects(NewSpace* space, HeapObjectCallback size_f); | 370 int IterateLiveObjects(NewSpace* space, LiveObjectCallback size_f); |
| 368 int IterateLiveObjects(PagedSpace* space, HeapObjectCallback size_f); | 371 int IterateLiveObjects(PagedSpace* space, LiveObjectCallback size_f); |
| 369 | 372 |
| 370 // Iterates the live objects between a range of addresses, returning the | 373 // Iterates the live objects between a range of addresses, returning the |
| 371 // number of live objects. | 374 // number of live objects. |
| 372 int IterateLiveObjectsInRange(Address start, Address end, | 375 int IterateLiveObjectsInRange(Address start, Address end, |
| 373 HeapObjectCallback size_func); | 376 LiveObjectCallback size_func); |
| 374 | 377 |
| 375 // If we are not compacting the heap, we simply sweep the spaces except | 378 // If we are not compacting the heap, we simply sweep the spaces except |
| 376 // for the large object space, clearing mark bits and adding unmarked | 379 // for the large object space, clearing mark bits and adding unmarked |
| 377 // regions to each space's free list. | 380 // regions to each space's free list. |
| 378 void SweepSpaces(); | 381 void SweepSpaces(); |
| 379 | 382 |
| 380 // ----------------------------------------------------------------------- | 383 // ----------------------------------------------------------------------- |
| 381 // Phase 3: Updating pointers in live objects. | 384 // Phase 3: Updating pointers in live objects. |
| 382 // | 385 // |
| 383 // Before: Same as after phase 2 (compacting collection). | 386 // Before: Same as after phase 2 (compacting collection). |
| 384 // | 387 // |
| 385 // After: All pointers in live objects, including encoded map | 388 // After: All pointers in live objects, including encoded map |
| 386 // pointers, are updated to point to their target's new | 389 // pointers, are updated to point to their target's new |
| 387 // location. | 390 // location. |
| 388 | 391 |
| 389 friend class UpdatingVisitor; // helper for updating visited objects | 392 friend class UpdatingVisitor; // helper for updating visited objects |
| 390 | 393 |
| 391 // Updates pointers in all spaces. | 394 // Updates pointers in all spaces. |
| 392 void UpdatePointers(); | 395 void UpdatePointers(); |
| 393 | 396 |
| 394 // Updates pointers in an object in new space. | 397 // Updates pointers in an object in new space. |
| 395 // Returns the heap size of the object. | 398 // Returns the heap size of the object. |
| 396 static int UpdatePointersInNewObject(HeapObject* obj); | 399 int UpdatePointersInNewObject(HeapObject* obj); |
| 397 | 400 |
| 398 // Updates pointers in an object in old spaces. | 401 // Updates pointers in an object in old spaces. |
| 399 // Returns the heap size of the object. | 402 // Returns the heap size of the object. |
| 400 static int UpdatePointersInOldObject(HeapObject* obj); | 403 int UpdatePointersInOldObject(HeapObject* obj); |
| 401 | 404 |
| 402 // Calculates the forwarding address of an object in an old space. | 405 // Calculates the forwarding address of an object in an old space. |
| 403 static Address GetForwardingAddressInOldSpace(HeapObject* obj); | 406 static Address GetForwardingAddressInOldSpace(HeapObject* obj); |
| 404 | 407 |
| 405 // ----------------------------------------------------------------------- | 408 // ----------------------------------------------------------------------- |
| 406 // Phase 4: Relocating objects. | 409 // Phase 4: Relocating objects. |
| 407 // | 410 // |
| 408 // Before: Pointers to live objects are updated to point to their | 411 // Before: Pointers to live objects are updated to point to their |
| 409 // target's new location. | 412 // target's new location. |
| 410 // | 413 // |
| 411 // After: Objects have been moved to their new addresses. | 414 // After: Objects have been moved to their new addresses. |
| 412 | 415 |
| 413 // Relocates objects in all spaces. | 416 // Relocates objects in all spaces. |
| 414 void RelocateObjects(); | 417 void RelocateObjects(); |
| 415 | 418 |
| 416 // Converts a code object's inline target to addresses, convention from | 419 // Converts a code object's inline target to addresses, convention from |
| 417 // address to target happens in the marking phase. | 420 // address to target happens in the marking phase. |
| 418 int ConvertCodeICTargetToAddress(HeapObject* obj); | 421 int ConvertCodeICTargetToAddress(HeapObject* obj); |
| 419 | 422 |
| 420 // Relocate a map object. | 423 // Relocate a map object. |
| 421 static int RelocateMapObject(HeapObject* obj); | 424 int RelocateMapObject(HeapObject* obj); |
| 422 | 425 |
| 423 // Relocates an old object. | 426 // Relocates an old object. |
| 424 static int RelocateOldPointerObject(HeapObject* obj); | 427 int RelocateOldPointerObject(HeapObject* obj); |
| 425 static int RelocateOldDataObject(HeapObject* obj); | 428 int RelocateOldDataObject(HeapObject* obj); |
| 426 | 429 |
| 427 // Relocate a property cell object. | 430 // Relocate a property cell object. |
| 428 static int RelocateCellObject(HeapObject* obj); | 431 int RelocateCellObject(HeapObject* obj); |
| 429 | 432 |
| 430 // Helper function. | 433 // Helper function. |
| 431 inline int RelocateOldNonCodeObject(HeapObject* obj, | 434 inline int RelocateOldNonCodeObject(HeapObject* obj, |
| 432 PagedSpace* space); | 435 PagedSpace* space); |
| 433 | 436 |
| 434 // Relocates an object in the code space. | 437 // Relocates an object in the code space. |
| 435 static int RelocateCodeObject(HeapObject* obj); | 438 int RelocateCodeObject(HeapObject* obj); |
| 436 | 439 |
| 437 // Copy a new object. | 440 // Copy a new object. |
| 438 static int RelocateNewObject(HeapObject* obj); | 441 int RelocateNewObject(HeapObject* obj); |
| 439 | 442 |
| 440 #ifdef DEBUG | 443 #ifdef DEBUG |
| 441 // ----------------------------------------------------------------------- | 444 // ----------------------------------------------------------------------- |
| 442 // Debugging variables, functions and classes | 445 // Debugging variables, functions and classes |
| 443 // Counters used for debugging the marking phase of mark-compact or | 446 // Counters used for debugging the marking phase of mark-compact or |
| 444 // mark-sweep collection. | 447 // mark-sweep collection. |
| 445 | 448 |
| 446 // Size of live objects in Heap::to_space_. | 449 // Size of live objects in Heap::to_space_. |
| 447 int live_young_objects_size_; | 450 int live_young_objects_size_; |
| 448 | 451 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 477 Heap* heap_; | 480 Heap* heap_; |
| 478 MarkingStack marking_stack_; | 481 MarkingStack marking_stack_; |
| 479 friend class Heap; | 482 friend class Heap; |
| 480 friend class OverflowedObjectsScanner; | 483 friend class OverflowedObjectsScanner; |
| 481 }; | 484 }; |
| 482 | 485 |
| 483 | 486 |
| 484 } } // namespace v8::internal | 487 } } // namespace v8::internal |
| 485 | 488 |
| 486 #endif // V8_MARK_COMPACT_H_ | 489 #endif // V8_MARK_COMPACT_H_ |
| OLD | NEW |