Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: src/heap/mark-compact.h

Issue 2498583002: [heap] Minor MC: Add marking (Closed)
Patch Set: Fix uncommitting of markingdeque Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_HEAP_MARK_COMPACT_H_ 5 #ifndef V8_HEAP_MARK_COMPACT_H_
6 #define V8_HEAP_MARK_COMPACT_H_ 6 #define V8_HEAP_MARK_COMPACT_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
11 #include "src/base/platform/condition-variable.h" 11 #include "src/base/platform/condition-variable.h"
12 #include "src/cancelable-task.h" 12 #include "src/cancelable-task.h"
13 #include "src/heap/marking.h" 13 #include "src/heap/marking.h"
14 #include "src/heap/spaces.h" 14 #include "src/heap/spaces.h"
15 #include "src/heap/store-buffer.h" 15 #include "src/heap/store-buffer.h"
16 16
17 namespace v8 { 17 namespace v8 {
18 namespace internal { 18 namespace internal {
19 19
20 enum class MarkCompactMode { FULL, YOUNG_GENERATION };
21
20 // Callback function, returns whether an object is alive. The heap size 22 // Callback function, returns whether an object is alive. The heap size
21 // of the object is returned in size. It optionally updates the offset 23 // of the object is returned in size. It optionally updates the offset
22 // to the first live object in the page (only used for old and map objects). 24 // to the first live object in the page (only used for old and map objects).
23 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); 25 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset);
24 26
25 // Callback function to mark an object in a given heap. 27 // Callback function to mark an object in a given heap.
26 typedef void (*MarkObjectFunction)(Heap* heap, HeapObject* object); 28 typedef void (*MarkObjectFunction)(Heap* heap, HeapObject* object);
27 29
28 // Forward declarations. 30 // Forward declarations.
29 class CodeFlusher; 31 class CodeFlusher;
30 class MarkCompactCollector; 32 class MarkCompactCollector;
31 class MarkingVisitor; 33 class MarkingVisitor;
34 template <MarkCompactMode mode>
32 class RootMarkingVisitor; 35 class RootMarkingVisitor;
33 36
34 class ObjectMarking : public AllStatic { 37 class ObjectMarking : public AllStatic {
35 public: 38 public:
36 INLINE(static MarkBit MarkBitFrom(Address addr)) { 39 INLINE(static MarkBit MarkBitFrom(Address addr)) {
37 MemoryChunk* p = MemoryChunk::FromAddress(addr); 40 MemoryChunk* p = MemoryChunk::FromAddress(addr);
38 return p->markbits()->MarkBitFromIndex(p->AddressToMarkbitIndex(addr)); 41 return p->markbits()->MarkBitFromIndex(p->AddressToMarkbitIndex(addr));
39 } 42 }
40 43
41 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) { 44 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) {
(...skipping 23 matching lines...) Expand all
65 in_use_(false), 68 in_use_(false),
66 uncommit_task_pending_(false), 69 uncommit_task_pending_(false),
67 heap_(heap) {} 70 heap_(heap) {}
68 71
69 void SetUp(); 72 void SetUp();
70 void TearDown(); 73 void TearDown();
71 74
72 // Ensures that the marking deque is committed and will stay committed until 75 // Ensures that the marking deque is committed and will stay committed until
73 // StopUsing() is called. 76 // StopUsing() is called.
74 void StartUsing(); 77 void StartUsing();
75 void StopUsing(); 78 void StopUsing(bool free_immediately = false);
ulan 2016/11/15 19:57:21 nit: let's use enum instead of bool
Michael Lippautz 2016/11/16 08:59:37 Done.
76 void Clear(); 79 void Clear();
77 80
78 inline bool IsFull() { return ((top_ + 1) & mask_) == bottom_; } 81 inline bool IsFull() { return ((top_ + 1) & mask_) == bottom_; }
79 82
80 inline bool IsEmpty() { return top_ == bottom_; } 83 inline bool IsEmpty() { return top_ == bottom_; }
81 84
82 bool overflowed() const { return overflowed_; } 85 bool overflowed() const { return overflowed_; }
83 86
84 void ClearOverflowed() { overflowed_ = false; } 87 void ClearOverflowed() { overflowed_ = false; }
85 88
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 base::AtomicNumber<intptr_t> num_sweeping_tasks_; 412 base::AtomicNumber<intptr_t> num_sweeping_tasks_;
410 }; 413 };
411 414
412 enum IterationMode { 415 enum IterationMode {
413 kKeepMarking, 416 kKeepMarking,
414 kClearMarkbits, 417 kClearMarkbits,
415 }; 418 };
416 419
417 static void Initialize(); 420 static void Initialize();
418 421
422 static SlotCallbackResult CheckAndMarkObject(Heap* heap,
423 Address slot_address);
424
419 void SetUp(); 425 void SetUp();
420 426
421 void TearDown(); 427 void TearDown();
422 428
423 void CollectEvacuationCandidates(PagedSpace* space); 429 void CollectEvacuationCandidates(PagedSpace* space);
424 430
425 void AddEvacuationCandidate(Page* p); 431 void AddEvacuationCandidate(Page* p);
426 432
427 // Prepares for GC by resetting relocation info in old and map spaces and 433 // Prepares for GC by resetting relocation info in old and map spaces and
428 // choosing spaces to compact. 434 // choosing spaces to compact.
(...skipping 29 matching lines...) Expand all
458 CodeFlusher* code_flusher() { return code_flusher_; } 464 CodeFlusher* code_flusher() { return code_flusher_; }
459 inline bool is_code_flushing_enabled() const { return code_flusher_ != NULL; } 465 inline bool is_code_flushing_enabled() const { return code_flusher_ != NULL; }
460 466
461 #ifdef VERIFY_HEAP 467 #ifdef VERIFY_HEAP
462 void VerifyValidStoreAndSlotsBufferEntries(); 468 void VerifyValidStoreAndSlotsBufferEntries();
463 void VerifyMarkbitsAreClean(); 469 void VerifyMarkbitsAreClean();
464 static void VerifyMarkbitsAreClean(PagedSpace* space); 470 static void VerifyMarkbitsAreClean(PagedSpace* space);
465 static void VerifyMarkbitsAreClean(NewSpace* space); 471 static void VerifyMarkbitsAreClean(NewSpace* space);
466 void VerifyWeakEmbeddedObjectsInCode(); 472 void VerifyWeakEmbeddedObjectsInCode();
467 void VerifyOmittedMapChecks(); 473 void VerifyOmittedMapChecks();
474
475 void MarkYoungGenerationForVerification();
476 std::vector<HeapObject*> GetObjectsInToSpace();
477 void VerifyYoungGenerationMarkbitsUsingForwardingPointers(
478 const std::vector<HeapObject*>& objects);
468 #endif 479 #endif
469 480
470 INLINE(static bool ShouldSkipEvacuationSlotRecording(Object* host)) { 481 INLINE(static bool ShouldSkipEvacuationSlotRecording(Object* host)) {
471 return Page::FromAddress(reinterpret_cast<Address>(host)) 482 return Page::FromAddress(reinterpret_cast<Address>(host))
472 ->ShouldSkipEvacuationSlotRecording(); 483 ->ShouldSkipEvacuationSlotRecording();
473 } 484 }
474 485
475 static inline bool IsOnEvacuationCandidate(HeapObject* obj) { 486 static inline bool IsOnEvacuationCandidate(HeapObject* obj) {
476 return Page::FromAddress(reinterpret_cast<Address>(obj)) 487 return Page::FromAddress(reinterpret_cast<Address>(obj))
477 ->IsEvacuationCandidate(); 488 ->IsEvacuationCandidate();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // MarkCompactCollector::Prepare() and is otherwise in its 568 // MarkCompactCollector::Prepare() and is otherwise in its
558 // normal state. 569 // normal state.
559 // 570 //
560 // After: Live objects are marked and non-live objects are unmarked. 571 // After: Live objects are marked and non-live objects are unmarked.
561 572
562 friend class CodeMarkingVisitor; 573 friend class CodeMarkingVisitor;
563 friend class IncrementalMarkingMarkingVisitor; 574 friend class IncrementalMarkingMarkingVisitor;
564 friend class MarkCompactMarkingVisitor; 575 friend class MarkCompactMarkingVisitor;
565 friend class MarkingVisitor; 576 friend class MarkingVisitor;
566 friend class RecordMigratedSlotVisitor; 577 friend class RecordMigratedSlotVisitor;
578 template <MarkCompactMode mode>
567 friend class RootMarkingVisitor; 579 friend class RootMarkingVisitor;
568 friend class SharedFunctionInfoMarkingVisitor; 580 friend class SharedFunctionInfoMarkingVisitor;
581 friend class StaticYoungGenerationMarkingVisitor;
569 582
570 // Mark code objects that are active on the stack to prevent them 583 // Mark code objects that are active on the stack to prevent them
571 // from being flushed. 584 // from being flushed.
572 void PrepareThreadForCodeFlushing(Isolate* isolate, ThreadLocalTop* top); 585 void PrepareThreadForCodeFlushing(Isolate* isolate, ThreadLocalTop* top);
573 586
574 void PrepareForCodeFlushing(); 587 void PrepareForCodeFlushing();
575 588
576 // Marking operations for objects reachable from roots. 589 // Marking operations for objects reachable from roots.
577 void MarkLiveObjects(); 590 void MarkLiveObjects();
591 // Mark the young generation.
592 void MarkLiveObjectsInYoungGeneration();
578 593
579 // Pushes a black object onto the marking stack and accounts for live bytes. 594 // Pushes a black object onto the marking stack and accounts for live bytes.
580 // Note that this assumes live bytes have not yet been counted. 595 // Note that this assumes live bytes have not yet been counted.
581 INLINE(void PushBlack(HeapObject* obj)); 596 INLINE(void PushBlack(HeapObject* obj));
582 597
583 // Unshifts a black object into the marking stack and accounts for live bytes. 598 // Unshifts a black object into the marking stack and accounts for live bytes.
584 // Note that this assumes lives bytes have already been counted. 599 // Note that this assumes lives bytes have already been counted.
585 INLINE(void UnshiftBlack(HeapObject* obj)); 600 INLINE(void UnshiftBlack(HeapObject* obj));
586 601
587 // Marks the object black and pushes it on the marking stack. 602 // Marks the object black and pushes it on the marking stack.
588 // This is for non-incremental marking only. 603 // This is for non-incremental marking only.
589 INLINE(void MarkObject(HeapObject* obj, MarkBit mark_bit)); 604 INLINE(void MarkObject(HeapObject* obj, MarkBit mark_bit));
590 605
591 // Marks the object black assuming that it is not yet marked. 606 // Marks the object black assuming that it is not yet marked.
592 // This is for non-incremental marking only. 607 // This is for non-incremental marking only.
593 INLINE(void SetMark(HeapObject* obj, MarkBit mark_bit)); 608 INLINE(void SetMark(HeapObject* obj, MarkBit mark_bit));
594 609
595 // Mark the heap roots and all objects reachable from them. 610 // Mark the heap roots and all objects reachable from them.
596 void MarkRoots(RootMarkingVisitor* visitor); 611 void MarkRoots(RootMarkingVisitor<MarkCompactMode::FULL>* visitor);
597 612
598 // Mark the string table specially. References to internalized strings from 613 // Mark the string table specially. References to internalized strings from
599 // the string table are weak. 614 // the string table are weak.
600 void MarkStringTable(RootMarkingVisitor* visitor); 615 void MarkStringTable(RootMarkingVisitor<MarkCompactMode::FULL>* visitor);
601 616
602 // Mark objects reachable (transitively) from objects in the marking stack 617 // Mark objects reachable (transitively) from objects in the marking stack
603 // or overflowed in the heap. 618 // or overflowed in the heap.
619 template <MarkCompactMode mode>
604 void ProcessMarkingDeque(); 620 void ProcessMarkingDeque();
605 621
606 // Mark objects reachable (transitively) from objects in the marking stack 622 // Mark objects reachable (transitively) from objects in the marking stack
607 // or overflowed in the heap. This respects references only considered in 623 // or overflowed in the heap. This respects references only considered in
608 // the final atomic marking pause including the following: 624 // the final atomic marking pause including the following:
609 // - Processing of objects reachable through Harmony WeakMaps. 625 // - Processing of objects reachable through Harmony WeakMaps.
610 // - Objects reachable due to host application logic like object groups, 626 // - Objects reachable due to host application logic like object groups,
611 // implicit references' groups, or embedder heap tracing. 627 // implicit references' groups, or embedder heap tracing.
612 void ProcessEphemeralMarking(ObjectVisitor* visitor, 628 void ProcessEphemeralMarking(ObjectVisitor* visitor,
613 bool only_process_harmony_weak_collections); 629 bool only_process_harmony_weak_collections);
614 630
615 // If the call-site of the top optimized code was not prepared for 631 // If the call-site of the top optimized code was not prepared for
616 // deoptimization, then treat the maps in the code as strong pointers, 632 // deoptimization, then treat the maps in the code as strong pointers,
617 // otherwise a map can die and deoptimize the code. 633 // otherwise a map can die and deoptimize the code.
618 void ProcessTopOptimizedFrame(ObjectVisitor* visitor); 634 void ProcessTopOptimizedFrame(ObjectVisitor* visitor);
619 635
620 // Collects a list of dependent code from maps embedded in optimize code. 636 // Collects a list of dependent code from maps embedded in optimize code.
621 DependentCode* DependentCodeListFromNonLiveMaps(); 637 DependentCode* DependentCodeListFromNonLiveMaps();
622 638
623 // Mark objects reachable (transitively) from objects in the marking 639 // Mark objects reachable (transitively) from objects in the marking
624 // stack. This function empties the marking stack, but may leave 640 // stack. This function empties the marking stack, but may leave
625 // overflowed objects in the heap, in which case the marking stack's 641 // overflowed objects in the heap, in which case the marking stack's
626 // overflow flag will be set. 642 // overflow flag will be set.
643 template <MarkCompactMode mode>
627 void EmptyMarkingDeque(); 644 void EmptyMarkingDeque();
628 645
629 // Refill the marking stack with overflowed objects from the heap. This 646 // Refill the marking stack with overflowed objects from the heap. This
630 // function either leaves the marking stack full or clears the overflow 647 // function either leaves the marking stack full or clears the overflow
631 // flag on the marking stack. 648 // flag on the marking stack.
649 template <MarkCompactMode mode>
632 void RefillMarkingDeque(); 650 void RefillMarkingDeque();
633 651
634 // Helper methods for refilling the marking stack by discovering grey objects 652 // Helper methods for refilling the marking stack by discovering grey objects
635 // on various pages of the heap. Used by {RefillMarkingDeque} only. 653 // on various pages of the heap. Used by {RefillMarkingDeque} only.
636 template <class T> 654 template <class T>
637 void DiscoverGreyObjectsWithIterator(T* it); 655 void DiscoverGreyObjectsWithIterator(T* it);
638 void DiscoverGreyObjectsOnPage(MemoryChunk* p); 656 void DiscoverGreyObjectsOnPage(MemoryChunk* p);
639 void DiscoverGreyObjectsInSpace(PagedSpace* space); 657 void DiscoverGreyObjectsInSpace(PagedSpace* space);
640 void DiscoverGreyObjectsInNewSpace(); 658 void DiscoverGreyObjectsInNewSpace();
641 659
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 790
773 private: 791 private:
774 MarkCompactCollector* collector_; 792 MarkCompactCollector* collector_;
775 }; 793 };
776 794
777 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); 795 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space);
778 } // namespace internal 796 } // namespace internal
779 } // namespace v8 797 } // namespace v8
780 798
781 #endif // V8_HEAP_MARK_COMPACT_H_ 799 #endif // V8_HEAP_MARK_COMPACT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698