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

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: Fix test 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
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(
1673 return Scavenger::CheckAndScavengeObject(this, addr, DEFAULT_PROMOTION); 1674 this, [this, promotion_mode](Address addr) {
ulan 2016/06/01 11:53:34 promotion mode is not needed here and below in Ite
1674 }); 1675 return Scavenger::CheckAndScavengeObject(this, addr, promotion_mode);
1676 });
1675 1677
1676 RememberedSet<OLD_TO_NEW>::IterateTyped( 1678 RememberedSet<OLD_TO_NEW>::IterateTyped(
1677 this, [this](SlotType type, Address addr) { 1679 this, [this, promotion_mode](SlotType type, Address addr) {
1678 return UpdateTypedSlotHelper::UpdateTypedSlot( 1680 return UpdateTypedSlotHelper::UpdateTypedSlot(
1679 isolate(), type, addr, [this](Object** addr) { 1681 isolate(), type, addr, [this, promotion_mode](Object** addr) {
1680 // We expect that objects referenced by code are long living. 1682 // We expect that objects referenced by code are long living.
1681 // If we do not force promotion, then we need to clear 1683 // If we do not force promotion, then we need to clear
1682 // old_to_new slots in dead code objects after mark-compact. 1684 // old_to_new slots in dead code objects after mark-compact.
1683 return Scavenger::CheckAndScavengeObject( 1685 return Scavenger::CheckAndScavengeObject(
1684 this, reinterpret_cast<Address>(addr), FORCE_PROMOTION); 1686 this, reinterpret_cast<Address>(addr), promotion_mode);
1685 }); 1687 });
1686 }); 1688 });
1687 } 1689 }
1688 1690
1689 { 1691 {
1690 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_WEAK); 1692 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_WEAK);
1691 // Copy objects reachable from the encountered weak collections list. 1693 // Copy objects reachable from the encountered weak collections list.
1692 scavenge_visitor.VisitPointer(&encountered_weak_collections_); 1694 scavenge_visitor.VisitPointer(&encountered_weak_collections_);
1693 // Copy objects reachable from the encountered weak cells. 1695 // Copy objects reachable from the encountered weak cells.
1694 scavenge_visitor.VisitPointer(&encountered_weak_cells_); 1696 scavenge_visitor.VisitPointer(&encountered_weak_cells_);
1695 } 1697 }
1696 1698
1697 { 1699 {
1698 // Copy objects reachable from the code flushing candidates list. 1700 // Copy objects reachable from the code flushing candidates list.
1699 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_CODE_FLUSH_CANDIDATES); 1701 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_CODE_FLUSH_CANDIDATES);
1700 MarkCompactCollector* collector = mark_compact_collector(); 1702 MarkCompactCollector* collector = mark_compact_collector();
1701 if (collector->is_code_flushing_enabled()) { 1703 if (collector->is_code_flushing_enabled()) {
1702 collector->code_flusher()->IteratePointersToFromSpace(&scavenge_visitor); 1704 collector->code_flusher()->IteratePointersToFromSpace(&scavenge_visitor);
1703 } 1705 }
1704 } 1706 }
1705 1707
1706 { 1708 {
1707 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_SEMISPACE); 1709 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_SEMISPACE);
1708 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1710 new_space_front =
1711 DoScavenge(&scavenge_visitor, new_space_front, promotion_mode);
1709 } 1712 }
1710 1713
1711 if (FLAG_scavenge_reclaim_unmodified_objects) { 1714 if (FLAG_scavenge_reclaim_unmodified_objects) {
1712 isolate()->global_handles()->MarkNewSpaceWeakUnmodifiedObjectsPending( 1715 isolate()->global_handles()->MarkNewSpaceWeakUnmodifiedObjectsPending(
1713 &IsUnscavengedHeapObject); 1716 &IsUnscavengedHeapObject);
1714 1717
1715 isolate()->global_handles()->IterateNewSpaceWeakUnmodifiedRoots( 1718 isolate()->global_handles()->IterateNewSpaceWeakUnmodifiedRoots(
1716 &scavenge_visitor); 1719 &scavenge_visitor);
1717 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1720 new_space_front =
1721 DoScavenge(&scavenge_visitor, new_space_front, promotion_mode);
1718 } else { 1722 } else {
1719 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_OBJECT_GROUPS); 1723 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_OBJECT_GROUPS);
1720 while (isolate()->global_handles()->IterateObjectGroups( 1724 while (isolate()->global_handles()->IterateObjectGroups(
1721 &scavenge_visitor, &IsUnscavengedHeapObject)) { 1725 &scavenge_visitor, &IsUnscavengedHeapObject)) {
1722 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1726 new_space_front =
1727 DoScavenge(&scavenge_visitor, new_space_front, promotion_mode);
1723 } 1728 }
1724 isolate()->global_handles()->RemoveObjectGroups(); 1729 isolate()->global_handles()->RemoveObjectGroups();
1725 isolate()->global_handles()->RemoveImplicitRefGroups(); 1730 isolate()->global_handles()->RemoveImplicitRefGroups();
1726 1731
1727 isolate()->global_handles()->IdentifyNewSpaceWeakIndependentHandles( 1732 isolate()->global_handles()->IdentifyNewSpaceWeakIndependentHandles(
1728 &IsUnscavengedHeapObject); 1733 &IsUnscavengedHeapObject);
1729 1734
1730 isolate()->global_handles()->IterateNewSpaceWeakIndependentRoots( 1735 isolate()->global_handles()->IterateNewSpaceWeakIndependentRoots(
1731 &scavenge_visitor); 1736 &scavenge_visitor);
1732 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1737 new_space_front =
1738 DoScavenge(&scavenge_visitor, new_space_front, promotion_mode);
1733 } 1739 }
1734 1740
1735 UpdateNewSpaceReferencesInExternalStringTable( 1741 UpdateNewSpaceReferencesInExternalStringTable(
1736 &UpdateNewSpaceReferenceInExternalStringTableEntry); 1742 &UpdateNewSpaceReferenceInExternalStringTableEntry);
1737 1743
1738 promotion_queue_.Destroy(); 1744 promotion_queue_.Destroy();
1739 1745
1740 incremental_marking()->UpdateMarkingDequeAfterScavenge(); 1746 incremental_marking()->UpdateMarkingDequeAfterScavenge();
1741 1747
1742 ScavengeWeakObjectRetainer weak_object_retainer(this); 1748 ScavengeWeakObjectRetainer weak_object_retainer(this);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 } 1910 }
1905 } 1911 }
1906 1912
1907 private: 1913 private:
1908 v8::ExternalResourceVisitor* visitor_; 1914 v8::ExternalResourceVisitor* visitor_;
1909 } external_string_table_visitor(visitor); 1915 } external_string_table_visitor(visitor);
1910 1916
1911 external_string_table_.Iterate(&external_string_table_visitor); 1917 external_string_table_.Iterate(&external_string_table_visitor);
1912 } 1918 }
1913 1919
1914
1915 Address Heap::DoScavenge(ObjectVisitor* scavenge_visitor, 1920 Address Heap::DoScavenge(ObjectVisitor* scavenge_visitor,
1916 Address new_space_front) { 1921 Address new_space_front,
1922 PromotionMode promotion_mode) {
1917 do { 1923 do {
1918 SemiSpace::AssertValidRange(new_space_front, new_space_.top()); 1924 SemiSpace::AssertValidRange(new_space_front, new_space_.top());
1919 // The addresses new_space_front and new_space_.top() define a 1925 // The addresses new_space_front and new_space_.top() define a
1920 // queue of unprocessed copied objects. Process them until the 1926 // queue of unprocessed copied objects. Process them until the
1921 // queue is empty. 1927 // queue is empty.
1922 while (new_space_front != new_space_.top()) { 1928 while (new_space_front != new_space_.top()) {
1923 if (!Page::IsAlignedToPageSize(new_space_front)) { 1929 if (!Page::IsAlignedToPageSize(new_space_front)) {
1924 HeapObject* object = HeapObject::FromAddress(new_space_front); 1930 HeapObject* object = HeapObject::FromAddress(new_space_front);
1925 new_space_front += 1931 if (promotion_mode == PROMOTE_MARKED) {
1926 StaticScavengeVisitor::IterateBody(object->map(), object); 1932 new_space_front += StaticScavengeVisitor<PROMOTE_MARKED>::IterateBody(
1933 object->map(), object);
1934 } else {
1935 new_space_front +=
1936 StaticScavengeVisitor<DEFAULT_PROMOTION>::IterateBody(
1937 object->map(), object);
1938 }
1927 } else { 1939 } else {
1928 new_space_front = Page::FromAllocationAreaAddress(new_space_front) 1940 new_space_front = Page::FromAllocationAreaAddress(new_space_front)
1929 ->next_page() 1941 ->next_page()
1930 ->area_start(); 1942 ->area_start();
1931 } 1943 }
1932 } 1944 }
1933 1945
1934 // Promote and process all the to-be-promoted objects. 1946 // Promote and process all the to-be-promoted objects.
1935 { 1947 {
1936 while (!promotion_queue()->is_empty()) { 1948 while (!promotion_queue()->is_empty()) {
(...skipping 2745 matching lines...) Expand 10 before | Expand all | Expand 10 after
4682 Address end, bool record_slots, 4694 Address end, bool record_slots,
4683 ObjectSlotCallback callback) { 4695 ObjectSlotCallback callback) {
4684 Address slot_address = start; 4696 Address slot_address = start;
4685 Page* page = Page::FromAddress(start); 4697 Page* page = Page::FromAddress(start);
4686 4698
4687 while (slot_address < end) { 4699 while (slot_address < end) {
4688 Object** slot = reinterpret_cast<Object**>(slot_address); 4700 Object** slot = reinterpret_cast<Object**>(slot_address);
4689 Object* target = *slot; 4701 Object* target = *slot;
4690 if (target->IsHeapObject()) { 4702 if (target->IsHeapObject()) {
4691 if (Heap::InFromSpace(target)) { 4703 if (Heap::InFromSpace(target)) {
4692 callback(reinterpret_cast<HeapObject**>(slot), HeapObject::cast(target), 4704 callback(reinterpret_cast<HeapObject**>(slot),
4693 DEFAULT_PROMOTION); 4705 HeapObject::cast(target));
4694 Object* new_target = *slot; 4706 Object* new_target = *slot;
4695 if (InNewSpace(new_target)) { 4707 if (InNewSpace(new_target)) {
4696 SLOW_DCHECK(Heap::InToSpace(new_target)); 4708 SLOW_DCHECK(Heap::InToSpace(new_target));
4697 SLOW_DCHECK(new_target->IsHeapObject()); 4709 SLOW_DCHECK(new_target->IsHeapObject());
4698 RememberedSet<OLD_TO_NEW>::Insert(page, slot_address); 4710 RememberedSet<OLD_TO_NEW>::Insert(page, slot_address);
4699 } 4711 }
4700 SLOW_DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_target)); 4712 SLOW_DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_target));
4701 } else if (record_slots && 4713 } else if (record_slots &&
4702 MarkCompactCollector::IsOnEvacuationCandidate(target)) { 4714 MarkCompactCollector::IsOnEvacuationCandidate(target)) {
4703 mark_compact_collector()->RecordSlot(object, slot, target); 4715 mark_compact_collector()->RecordSlot(object, slot, target);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
5225 space = spaces.next()) { 5237 space = spaces.next()) {
5226 space->EmptyAllocationInfo(); 5238 space->EmptyAllocationInfo();
5227 } 5239 }
5228 } 5240 }
5229 5241
5230 5242
5231 V8_DECLARE_ONCE(initialize_gc_once); 5243 V8_DECLARE_ONCE(initialize_gc_once);
5232 5244
5233 static void InitializeGCOnce() { 5245 static void InitializeGCOnce() {
5234 Scavenger::Initialize(); 5246 Scavenger::Initialize();
5235 StaticScavengeVisitor::Initialize(); 5247 StaticScavengeVisitor<DEFAULT_PROMOTION>::Initialize();
5248 StaticScavengeVisitor<PROMOTE_MARKED>::Initialize();
5236 MarkCompactCollector::Initialize(); 5249 MarkCompactCollector::Initialize();
5237 } 5250 }
5238 5251
5239 5252
5240 bool Heap::SetUp() { 5253 bool Heap::SetUp() {
5241 #ifdef DEBUG 5254 #ifdef DEBUG
5242 allocation_timeout_ = FLAG_gc_interval; 5255 allocation_timeout_ = FLAG_gc_interval;
5243 #endif 5256 #endif
5244 5257
5245 // Initialize heap spaces and initial maps and objects. Whenever something 5258 // Initialize heap spaces and initial maps and objects. Whenever something
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
6391 } 6404 }
6392 6405
6393 6406
6394 // static 6407 // static
6395 int Heap::GetStaticVisitorIdForMap(Map* map) { 6408 int Heap::GetStaticVisitorIdForMap(Map* map) {
6396 return StaticVisitorBase::GetVisitorId(map); 6409 return StaticVisitorBase::GetVisitorId(map);
6397 } 6410 }
6398 6411
6399 } // namespace internal 6412 } // namespace internal
6400 } // namespace v8 6413 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/heap-inl.h » ('j') | src/heap/scavenger-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698