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

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: Detemplatize Scavenger::Scavenge and friends, add tests 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 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 if (map_word.IsForwardingAddress()) { 1592 if (map_word.IsForwardingAddress()) {
1593 return map_word.ToForwardingAddress(); 1593 return map_word.ToForwardingAddress();
1594 } 1594 }
1595 return NULL; 1595 return NULL;
1596 } 1596 }
1597 1597
1598 private: 1598 private:
1599 Heap* heap_; 1599 Heap* heap_;
1600 }; 1600 };
1601 1601
1602
1603 void Heap::Scavenge() { 1602 void Heap::Scavenge() {
1604 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_SCAVENGE); 1603 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_SCAVENGE);
1605 RelocationLock relocation_lock(this); 1604 RelocationLock relocation_lock(this);
1606 // There are soft limits in the allocation code, designed to trigger a mark 1605 // There are soft limits in the allocation code, designed to trigger a mark
1607 // sweep collection by failing allocations. There is no sense in trying to 1606 // sweep collection by failing allocations. There is no sense in trying to
1608 // trigger one during scavenge: scavenges allocation should always succeed. 1607 // trigger one during scavenge: scavenges allocation should always succeed.
1609 AlwaysAllocateScope scope(isolate()); 1608 AlwaysAllocateScope scope(isolate());
1610 1609
1611 // Bump-pointer allocations done during scavenge are not real allocations. 1610 // Bump-pointer allocations done during scavenge are not real allocations.
1612 // Pause the inline allocation steps. 1611 // Pause the inline allocation steps.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 // objects lie between a 'front' mark and a 'rear' mark that is 1645 // objects lie between a 'front' mark and a 'rear' mark that is
1647 // updated as a side effect of promoting an object. 1646 // updated as a side effect of promoting an object.
1648 // 1647 //
1649 // There is guaranteed to be enough room at the top of the to space 1648 // There is guaranteed to be enough room at the top of the to space
1650 // for the addresses of promoted objects: every object promoted 1649 // for the addresses of promoted objects: every object promoted
1651 // frees up its size in bytes from the top of the new space, and 1650 // frees up its size in bytes from the top of the new space, and
1652 // objects are at least one pointer in size. 1651 // objects are at least one pointer in size.
1653 Address new_space_front = new_space_.ToSpaceStart(); 1652 Address new_space_front = new_space_.ToSpaceStart();
1654 promotion_queue_.Initialize(); 1653 promotion_queue_.Initialize();
1655 1654
1656 ScavengeVisitor scavenge_visitor(this); 1655 PromotionMode promotion_mode = CurrentPromotionMode();
1656 ScavengeVisitor scavenge_visitor(this, promotion_mode);
1657 1657
1658 if (FLAG_scavenge_reclaim_unmodified_objects) { 1658 if (FLAG_scavenge_reclaim_unmodified_objects) {
1659 isolate()->global_handles()->IdentifyWeakUnmodifiedObjects( 1659 isolate()->global_handles()->IdentifyWeakUnmodifiedObjects(
1660 &IsUnmodifiedHeapObject); 1660 &IsUnmodifiedHeapObject);
1661 } 1661 }
1662 1662
1663 { 1663 {
1664 // Copy roots. 1664 // Copy roots.
1665 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_ROOTS); 1665 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_ROOTS);
1666 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE); 1666 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE);
1667 } 1667 }
1668 1668
1669 { 1669 {
1670 // Copy objects reachable from the old generation. 1670 // Copy objects reachable from the old generation.
1671 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_OLD_TO_NEW_POINTERS); 1671 TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_OLD_TO_NEW_POINTERS);
1672 RememberedSet<OLD_TO_NEW>::Iterate(this, [this](Address addr) { 1672 RememberedSet<OLD_TO_NEW>::Iterate(
1673 return Scavenger::CheckAndScavengeObject(this, addr, DEFAULT_PROMOTION); 1673 this, [this, promotion_mode](Address addr) {
1674 }); 1674 return Scavenger::CheckAndScavengeObject(this, addr, promotion_mode);
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, promotion_mode](SlotType type, Address addr) {
1678 return UpdateTypedSlotHelper::UpdateTypedSlot( 1679 return UpdateTypedSlotHelper::UpdateTypedSlot(
1679 isolate(), type, addr, [this](Object** addr) { 1680 isolate(), type, addr, [this, promotion_mode](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), promotion_mode);
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()) {
1937 HeapObject* target; 1948 HeapObject* target;
1938 int32_t size; 1949 int32_t size;
1939 bool was_marked_black; 1950 bool was_marked_black;
1940 promotion_queue()->remove(&target, &size, &was_marked_black); 1951 promotion_queue()->remove(&target, &size, &was_marked_black);
1941 1952
1942 // Promoted object might be already partially visited 1953 // Promoted object might be already partially visited
1943 // during old space pointer iteration. Thus we search specifically 1954 // during old space pointer iteration. Thus we search specifically
1944 // for pointers to from semispace instead of looking for pointers 1955 // for pointers to from semispace instead of looking for pointers
1945 // to new space. 1956 // to new space.
1946 DCHECK(!target->IsMap()); 1957 DCHECK(!target->IsMap());
1947 1958
1948 IteratePromotedObject(target, static_cast<int>(size), was_marked_black, 1959 if (promotion_mode == PROMOTE_MARKED) {
1949 &Scavenger::ScavengeObject); 1960 IteratePromotedObject(target, static_cast<int>(size),
1961 was_marked_black,
1962 &Scavenger::ScavengeObject<PROMOTE_MARKED>);
1963 } else {
1964 IteratePromotedObject(target, static_cast<int>(size),
1965 was_marked_black,
1966 &Scavenger::ScavengeObject<DEFAULT_PROMOTION>);
1967 }
1950 } 1968 }
1951 } 1969 }
1952 1970
1953 // Take another spin if there are now unswept objects in new space 1971 // Take another spin if there are now unswept objects in new space
1954 // (there are currently no more unswept promoted objects). 1972 // (there are currently no more unswept promoted objects).
1955 } while (new_space_front != new_space_.top()); 1973 } while (new_space_front != new_space_.top());
1956 1974
1957 return new_space_front; 1975 return new_space_front;
1958 } 1976 }
1959 1977
(...skipping 2722 matching lines...) Expand 10 before | Expand all | Expand 10 after
4682 Address end, bool record_slots, 4700 Address end, bool record_slots,
4683 ObjectSlotCallback callback) { 4701 ObjectSlotCallback callback) {
4684 Address slot_address = start; 4702 Address slot_address = start;
4685 Page* page = Page::FromAddress(start); 4703 Page* page = Page::FromAddress(start);
4686 4704
4687 while (slot_address < end) { 4705 while (slot_address < end) {
4688 Object** slot = reinterpret_cast<Object**>(slot_address); 4706 Object** slot = reinterpret_cast<Object**>(slot_address);
4689 Object* target = *slot; 4707 Object* target = *slot;
4690 if (target->IsHeapObject()) { 4708 if (target->IsHeapObject()) {
4691 if (Heap::InFromSpace(target)) { 4709 if (Heap::InFromSpace(target)) {
4692 callback(reinterpret_cast<HeapObject**>(slot), HeapObject::cast(target), 4710 callback(reinterpret_cast<HeapObject**>(slot),
4693 DEFAULT_PROMOTION); 4711 HeapObject::cast(target));
4694 Object* new_target = *slot; 4712 Object* new_target = *slot;
4695 if (InNewSpace(new_target)) { 4713 if (InNewSpace(new_target)) {
4696 SLOW_DCHECK(Heap::InToSpace(new_target)); 4714 SLOW_DCHECK(Heap::InToSpace(new_target));
4697 SLOW_DCHECK(new_target->IsHeapObject()); 4715 SLOW_DCHECK(new_target->IsHeapObject());
4698 RememberedSet<OLD_TO_NEW>::Insert(page, slot_address); 4716 RememberedSet<OLD_TO_NEW>::Insert(page, slot_address);
4699 } 4717 }
4700 SLOW_DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_target)); 4718 SLOW_DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_target));
4701 } else if (record_slots && 4719 } else if (record_slots &&
4702 MarkCompactCollector::IsOnEvacuationCandidate(target)) { 4720 MarkCompactCollector::IsOnEvacuationCandidate(target)) {
4703 mark_compact_collector()->RecordSlot(object, slot, target); 4721 mark_compact_collector()->RecordSlot(object, slot, target);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
5225 space = spaces.next()) { 5243 space = spaces.next()) {
5226 space->EmptyAllocationInfo(); 5244 space->EmptyAllocationInfo();
5227 } 5245 }
5228 } 5246 }
5229 5247
5230 5248
5231 V8_DECLARE_ONCE(initialize_gc_once); 5249 V8_DECLARE_ONCE(initialize_gc_once);
5232 5250
5233 static void InitializeGCOnce() { 5251 static void InitializeGCOnce() {
5234 Scavenger::Initialize(); 5252 Scavenger::Initialize();
5235 StaticScavengeVisitor::Initialize(); 5253 StaticScavengeVisitor<DEFAULT_PROMOTION>::Initialize();
5254 StaticScavengeVisitor<PROMOTE_MARKED>::Initialize();
5236 MarkCompactCollector::Initialize(); 5255 MarkCompactCollector::Initialize();
5237 } 5256 }
5238 5257
5239 5258
5240 bool Heap::SetUp() { 5259 bool Heap::SetUp() {
5241 #ifdef DEBUG 5260 #ifdef DEBUG
5242 allocation_timeout_ = FLAG_gc_interval; 5261 allocation_timeout_ = FLAG_gc_interval;
5243 #endif 5262 #endif
5244 5263
5245 // Initialize heap spaces and initial maps and objects. Whenever something 5264 // Initialize heap spaces and initial maps and objects. Whenever something
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
6391 } 6410 }
6392 6411
6393 6412
6394 // static 6413 // static
6395 int Heap::GetStaticVisitorIdForMap(Map* map) { 6414 int Heap::GetStaticVisitorIdForMap(Map* map) {
6396 return StaticVisitorBase::GetVisitorId(map); 6415 return StaticVisitorBase::GetVisitorId(map);
6397 } 6416 }
6398 6417
6399 } // namespace internal 6418 } // namespace internal
6400 } // namespace v8 6419 } // 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