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

Side by Side Diff: src/heap/heap.cc

Issue 2005173003: Immediatelly promote marked objects (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Really should concentrate more Created 4 years, 6 months 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
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/heap-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "src/heap/heap.h" 5 #include "src/heap/heap.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/ast/scopeinfo.h" 9 #include "src/ast/scopeinfo.h"
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 // objects lie between a 'front' mark and a 'rear' mark that is 1646 // objects lie between a 'front' mark and a 'rear' mark that is
1647 // updated as a side effect of promoting an object. 1647 // updated as a side effect of promoting an object.
1648 // 1648 //
1649 // There is guaranteed to be enough room at the top of the to space 1649 // There is guaranteed to be enough room at the top of the to space
1650 // for the addresses of promoted objects: every object promoted 1650 // for the addresses of promoted objects: every object promoted
1651 // frees up its size in bytes from the top of the new space, and 1651 // frees up its size in bytes from the top of the new space, and
1652 // objects are at least one pointer in size. 1652 // objects are at least one pointer in size.
1653 Address new_space_front = new_space_.ToSpaceStart(); 1653 Address new_space_front = new_space_.ToSpaceStart();
1654 promotion_queue_.Initialize(); 1654 promotion_queue_.Initialize();
1655 1655
1656 PromotionMode promotion_mode = CurrentPromotionMode();
1656 ScavengeVisitor scavenge_visitor(this); 1657 ScavengeVisitor scavenge_visitor(this);
1657 1658
1658 if (FLAG_scavenge_reclaim_unmodified_objects) { 1659 if (FLAG_scavenge_reclaim_unmodified_objects) {
1659 isolate()->global_handles()->IdentifyWeakUnmodifiedObjects( 1660 isolate()->global_handles()->IdentifyWeakUnmodifiedObjects(
1660 &IsUnmodifiedHeapObject); 1661 &IsUnmodifiedHeapObject);
1661 } 1662 }
1662 1663
1663 { 1664 {
1664 // Copy roots. 1665 // Copy roots.
1665 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_ROOTS); 1666 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_ROOTS);
1666 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE); 1667 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE);
1667 } 1668 }
1668 1669
1669 { 1670 {
1670 // Copy objects reachable from the old generation. 1671 // Copy objects reachable from the old generation.
1671 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_OLD_TO_NEW_POINTERS); 1672 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_OLD_TO_NEW_POINTERS);
1672 RememberedSet<OLD_TO_NEW>::Iterate(this, [this](Address addr) { 1673 RememberedSet<OLD_TO_NEW>::Iterate(this, [this](Address addr) {
1673 return Scavenger::CheckAndScavengeObject(this, addr, DEFAULT_PROMOTION); 1674 return Scavenger::CheckAndScavengeObject(this, addr);
1674 }); 1675 });
1675 1676
1676 RememberedSet<OLD_TO_NEW>::IterateTyped( 1677 RememberedSet<OLD_TO_NEW>::IterateTyped(
1677 this, [this](SlotType type, Address addr) { 1678 this, [this](SlotType type, Address addr) {
1678 return UpdateTypedSlotHelper::UpdateTypedSlot( 1679 return UpdateTypedSlotHelper::UpdateTypedSlot(
1679 isolate(), type, addr, [this](Object** addr) { 1680 isolate(), type, addr, [this](Object** addr) {
1680 // We expect that objects referenced by code are long living. 1681 // We expect that objects referenced by code are long living.
1681 // If we do not force promotion, then we need to clear 1682 // If we do not force promotion, then we need to clear
1682 // old_to_new slots in dead code objects after mark-compact. 1683 // old_to_new slots in dead code objects after mark-compact.
1683 return Scavenger::CheckAndScavengeObject( 1684 return Scavenger::CheckAndScavengeObject(
1684 this, reinterpret_cast<Address>(addr), FORCE_PROMOTION); 1685 this, reinterpret_cast<Address>(addr));
1685 }); 1686 });
1686 }); 1687 });
1687 } 1688 }
1688 1689
1689 { 1690 {
1690 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_WEAK); 1691 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_WEAK);
1691 // Copy objects reachable from the encountered weak collections list. 1692 // Copy objects reachable from the encountered weak collections list.
1692 scavenge_visitor.VisitPointer(&encountered_weak_collections_); 1693 scavenge_visitor.VisitPointer(&encountered_weak_collections_);
1693 // Copy objects reachable from the encountered weak cells. 1694 // Copy objects reachable from the encountered weak cells.
1694 scavenge_visitor.VisitPointer(&encountered_weak_cells_); 1695 scavenge_visitor.VisitPointer(&encountered_weak_cells_);
1695 } 1696 }
1696 1697
1697 { 1698 {
1698 // Copy objects reachable from the code flushing candidates list. 1699 // Copy objects reachable from the code flushing candidates list.
1699 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_CODE_FLUSH_CANDIDATES); 1700 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_CODE_FLUSH_CANDIDATES);
1700 MarkCompactCollector* collector = mark_compact_collector(); 1701 MarkCompactCollector* collector = mark_compact_collector();
1701 if (collector->is_code_flushing_enabled()) { 1702 if (collector->is_code_flushing_enabled()) {
1702 collector->code_flusher()->IteratePointersToFromSpace(&scavenge_visitor); 1703 collector->code_flusher()->IteratePointersToFromSpace(&scavenge_visitor);
1703 } 1704 }
1704 } 1705 }
1705 1706
1706 { 1707 {
1707 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_SEMISPACE); 1708 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_SEMISPACE);
1708 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1709 new_space_front =
1710 DoScavenge(&scavenge_visitor, new_space_front, promotion_mode);
1709 } 1711 }
1710 1712
1711 if (FLAG_scavenge_reclaim_unmodified_objects) { 1713 if (FLAG_scavenge_reclaim_unmodified_objects) {
1712 isolate()->global_handles()->MarkNewSpaceWeakUnmodifiedObjectsPending( 1714 isolate()->global_handles()->MarkNewSpaceWeakUnmodifiedObjectsPending(
1713 &IsUnscavengedHeapObject); 1715 &IsUnscavengedHeapObject);
1714 1716
1715 isolate()->global_handles()->IterateNewSpaceWeakUnmodifiedRoots( 1717 isolate()->global_handles()->IterateNewSpaceWeakUnmodifiedRoots(
1716 &scavenge_visitor); 1718 &scavenge_visitor);
1717 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1719 new_space_front =
1720 DoScavenge(&scavenge_visitor, new_space_front, promotion_mode);
1718 } else { 1721 } else {
1719 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_OBJECT_GROUPS); 1722 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_OBJECT_GROUPS);
1720 while (isolate()->global_handles()->IterateObjectGroups( 1723 while (isolate()->global_handles()->IterateObjectGroups(
1721 &scavenge_visitor, &IsUnscavengedHeapObject)) { 1724 &scavenge_visitor, &IsUnscavengedHeapObject)) {
1722 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1725 new_space_front =
1726 DoScavenge(&scavenge_visitor, new_space_front, promotion_mode);
1723 } 1727 }
1724 isolate()->global_handles()->RemoveObjectGroups(); 1728 isolate()->global_handles()->RemoveObjectGroups();
1725 isolate()->global_handles()->RemoveImplicitRefGroups(); 1729 isolate()->global_handles()->RemoveImplicitRefGroups();
1726 1730
1727 isolate()->global_handles()->IdentifyNewSpaceWeakIndependentHandles( 1731 isolate()->global_handles()->IdentifyNewSpaceWeakIndependentHandles(
1728 &IsUnscavengedHeapObject); 1732 &IsUnscavengedHeapObject);
1729 1733
1730 isolate()->global_handles()->IterateNewSpaceWeakIndependentRoots( 1734 isolate()->global_handles()->IterateNewSpaceWeakIndependentRoots(
1731 &scavenge_visitor); 1735 &scavenge_visitor);
1732 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1736 new_space_front =
1737 DoScavenge(&scavenge_visitor, new_space_front, promotion_mode);
1733 } 1738 }
1734 1739
1735 UpdateNewSpaceReferencesInExternalStringTable( 1740 UpdateNewSpaceReferencesInExternalStringTable(
1736 &UpdateNewSpaceReferenceInExternalStringTableEntry); 1741 &UpdateNewSpaceReferenceInExternalStringTableEntry);
1737 1742
1738 promotion_queue_.Destroy(); 1743 promotion_queue_.Destroy();
1739 1744
1740 incremental_marking()->UpdateMarkingDequeAfterScavenge(); 1745 incremental_marking()->UpdateMarkingDequeAfterScavenge();
1741 1746
1742 ScavengeWeakObjectRetainer weak_object_retainer(this); 1747 ScavengeWeakObjectRetainer weak_object_retainer(this);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 } 1909 }
1905 } 1910 }
1906 1911
1907 private: 1912 private:
1908 v8::ExternalResourceVisitor* visitor_; 1913 v8::ExternalResourceVisitor* visitor_;
1909 } external_string_table_visitor(visitor); 1914 } external_string_table_visitor(visitor);
1910 1915
1911 external_string_table_.Iterate(&external_string_table_visitor); 1916 external_string_table_.Iterate(&external_string_table_visitor);
1912 } 1917 }
1913 1918
1914
1915 Address Heap::DoScavenge(ObjectVisitor* scavenge_visitor, 1919 Address Heap::DoScavenge(ObjectVisitor* scavenge_visitor,
1916 Address new_space_front) { 1920 Address new_space_front,
1921 PromotionMode promotion_mode) {
1917 do { 1922 do {
1918 SemiSpace::AssertValidRange(new_space_front, new_space_.top()); 1923 SemiSpace::AssertValidRange(new_space_front, new_space_.top());
1919 // The addresses new_space_front and new_space_.top() define a 1924 // The addresses new_space_front and new_space_.top() define a
1920 // queue of unprocessed copied objects. Process them until the 1925 // queue of unprocessed copied objects. Process them until the
1921 // queue is empty. 1926 // queue is empty.
1922 while (new_space_front != new_space_.top()) { 1927 while (new_space_front != new_space_.top()) {
1923 if (!Page::IsAlignedToPageSize(new_space_front)) { 1928 if (!Page::IsAlignedToPageSize(new_space_front)) {
1924 HeapObject* object = HeapObject::FromAddress(new_space_front); 1929 HeapObject* object = HeapObject::FromAddress(new_space_front);
1925 new_space_front += 1930 if (promotion_mode == PROMOTE_MARKED) {
1926 StaticScavengeVisitor::IterateBody(object->map(), object); 1931 new_space_front += StaticScavengeVisitor<PROMOTE_MARKED>::IterateBody(
1932 object->map(), object);
1933 } else {
1934 new_space_front +=
1935 StaticScavengeVisitor<DEFAULT_PROMOTION>::IterateBody(
1936 object->map(), object);
1937 }
1927 } else { 1938 } else {
1928 new_space_front = Page::FromAllocationAreaAddress(new_space_front) 1939 new_space_front = Page::FromAllocationAreaAddress(new_space_front)
1929 ->next_page() 1940 ->next_page()
1930 ->area_start(); 1941 ->area_start();
1931 } 1942 }
1932 } 1943 }
1933 1944
1934 // Promote and process all the to-be-promoted objects. 1945 // Promote and process all the to-be-promoted objects.
1935 { 1946 {
1936 while (!promotion_queue()->is_empty()) { 1947 while (!promotion_queue()->is_empty()) {
(...skipping 2745 matching lines...) Expand 10 before | Expand all | Expand 10 after
4682 Address end, bool record_slots, 4693 Address end, bool record_slots,
4683 ObjectSlotCallback callback) { 4694 ObjectSlotCallback callback) {
4684 Address slot_address = start; 4695 Address slot_address = start;
4685 Page* page = Page::FromAddress(start); 4696 Page* page = Page::FromAddress(start);
4686 4697
4687 while (slot_address < end) { 4698 while (slot_address < end) {
4688 Object** slot = reinterpret_cast<Object**>(slot_address); 4699 Object** slot = reinterpret_cast<Object**>(slot_address);
4689 Object* target = *slot; 4700 Object* target = *slot;
4690 if (target->IsHeapObject()) { 4701 if (target->IsHeapObject()) {
4691 if (Heap::InFromSpace(target)) { 4702 if (Heap::InFromSpace(target)) {
4692 callback(reinterpret_cast<HeapObject**>(slot), HeapObject::cast(target), 4703 callback(reinterpret_cast<HeapObject**>(slot),
4693 DEFAULT_PROMOTION); 4704 HeapObject::cast(target));
4694 Object* new_target = *slot; 4705 Object* new_target = *slot;
4695 if (InNewSpace(new_target)) { 4706 if (InNewSpace(new_target)) {
4696 SLOW_DCHECK(Heap::InToSpace(new_target)); 4707 SLOW_DCHECK(Heap::InToSpace(new_target));
4697 SLOW_DCHECK(new_target->IsHeapObject()); 4708 SLOW_DCHECK(new_target->IsHeapObject());
4698 RememberedSet<OLD_TO_NEW>::Insert(page, slot_address); 4709 RememberedSet<OLD_TO_NEW>::Insert(page, slot_address);
4699 } 4710 }
4700 SLOW_DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_target)); 4711 SLOW_DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_target));
4701 } else if (record_slots && 4712 } else if (record_slots &&
4702 MarkCompactCollector::IsOnEvacuationCandidate(target)) { 4713 MarkCompactCollector::IsOnEvacuationCandidate(target)) {
4703 mark_compact_collector()->RecordSlot(object, slot, target); 4714 mark_compact_collector()->RecordSlot(object, slot, target);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
5225 space = spaces.next()) { 5236 space = spaces.next()) {
5226 space->EmptyAllocationInfo(); 5237 space->EmptyAllocationInfo();
5227 } 5238 }
5228 } 5239 }
5229 5240
5230 5241
5231 V8_DECLARE_ONCE(initialize_gc_once); 5242 V8_DECLARE_ONCE(initialize_gc_once);
5232 5243
5233 static void InitializeGCOnce() { 5244 static void InitializeGCOnce() {
5234 Scavenger::Initialize(); 5245 Scavenger::Initialize();
5235 StaticScavengeVisitor::Initialize(); 5246 StaticScavengeVisitor<DEFAULT_PROMOTION>::Initialize();
5247 StaticScavengeVisitor<PROMOTE_MARKED>::Initialize();
5236 MarkCompactCollector::Initialize(); 5248 MarkCompactCollector::Initialize();
5237 } 5249 }
5238 5250
5239 5251
5240 bool Heap::SetUp() { 5252 bool Heap::SetUp() {
5241 #ifdef DEBUG 5253 #ifdef DEBUG
5242 allocation_timeout_ = FLAG_gc_interval; 5254 allocation_timeout_ = FLAG_gc_interval;
5243 #endif 5255 #endif
5244 5256
5245 // Initialize heap spaces and initial maps and objects. Whenever something 5257 // Initialize heap spaces and initial maps and objects. Whenever something
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
6391 } 6403 }
6392 6404
6393 6405
6394 // static 6406 // static
6395 int Heap::GetStaticVisitorIdForMap(Map* map) { 6407 int Heap::GetStaticVisitorIdForMap(Map* map) {
6396 return StaticVisitorBase::GetVisitorId(map); 6408 return StaticVisitorBase::GetVisitorId(map);
6397 } 6409 }
6398 6410
6399 } // namespace internal 6411 } // namespace internal
6400 } // namespace v8 6412 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698