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

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

Issue 1410593005: Adds a scavenge GC pass to collect unmodified references (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Forgot a fix in the last patch Created 5 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
« no previous file with comments | « src/global-handles.cc ('k') | no next file » | 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/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 } 1494 }
1495 } 1495 }
1496 1496
1497 1497
1498 static bool IsUnscavengedHeapObject(Heap* heap, Object** p) { 1498 static bool IsUnscavengedHeapObject(Heap* heap, Object** p) {
1499 return heap->InNewSpace(*p) && 1499 return heap->InNewSpace(*p) &&
1500 !HeapObject::cast(*p)->map_word().IsForwardingAddress(); 1500 !HeapObject::cast(*p)->map_word().IsForwardingAddress();
1501 } 1501 }
1502 1502
1503 1503
1504 static bool IsUnmodifiedHeapObject(Object** p) {
1505 Object* object = *p;
1506 DCHECK(object->IsHeapObject());
1507 HeapObject* heap_object = HeapObject::cast(object);
1508 if (!object->IsJSObject()) return false;
1509 Object* obj_constructor = (JSObject::cast(object))->map()->GetConstructor();
1510 if (!obj_constructor->IsJSFunction()) return false;
1511 JSFunction* constructor = JSFunction::cast(obj_constructor);
1512 if (constructor != nullptr &&
1513 constructor->initial_map() == heap_object->map()) {
1514 return true;
1515 }
1516 return false;
1517 }
1518
1519
1504 void Heap::ScavengeStoreBufferCallback(Heap* heap, MemoryChunk* page, 1520 void Heap::ScavengeStoreBufferCallback(Heap* heap, MemoryChunk* page,
1505 StoreBufferEvent event) { 1521 StoreBufferEvent event) {
1506 heap->store_buffer_rebuilder_.Callback(page, event); 1522 heap->store_buffer_rebuilder_.Callback(page, event);
1507 } 1523 }
1508 1524
1509 1525
1510 void PromotionQueue::Initialize() { 1526 void PromotionQueue::Initialize() {
1511 // The last to-space page may be used for promotion queue. On promotion 1527 // The last to-space page may be used for promotion queue. On promotion
1512 // conflict, we use the emergency stack. 1528 // conflict, we use the emergency stack.
1513 DCHECK((Page::kPageSize - MemoryChunk::kBodyOffset) % (2 * kPointerSize) == 1529 DCHECK((Page::kPageSize - MemoryChunk::kBodyOffset) % (2 * kPointerSize) ==
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 // updated as a side effect of promoting an object. 1628 // updated as a side effect of promoting an object.
1613 // 1629 //
1614 // There is guaranteed to be enough room at the top of the to space 1630 // There is guaranteed to be enough room at the top of the to space
1615 // for the addresses of promoted objects: every object promoted 1631 // for the addresses of promoted objects: every object promoted
1616 // frees up its size in bytes from the top of the new space, and 1632 // frees up its size in bytes from the top of the new space, and
1617 // objects are at least one pointer in size. 1633 // objects are at least one pointer in size.
1618 Address new_space_front = new_space_.ToSpaceStart(); 1634 Address new_space_front = new_space_.ToSpaceStart();
1619 promotion_queue_.Initialize(); 1635 promotion_queue_.Initialize();
1620 1636
1621 ScavengeVisitor scavenge_visitor(this); 1637 ScavengeVisitor scavenge_visitor(this);
1638
1639 if (FLAG_scavenge_reclaim_unmodified_objects) {
1640 isolate()->global_handles()->IdentifyWeakUnmodifiedObjects(
1641 &IsUnmodifiedHeapObject);
1642 }
1643
1622 { 1644 {
1623 // Copy roots. 1645 // Copy roots.
1624 GCTracer::Scope gc_scope(tracer(), GCTracer::Scope::SCAVENGER_ROOTS); 1646 GCTracer::Scope gc_scope(tracer(), GCTracer::Scope::SCAVENGER_ROOTS);
1625 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE); 1647 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE);
1626 } 1648 }
1627 1649
1628 { 1650 {
1629 // Copy objects reachable from the old generation. 1651 // Copy objects reachable from the old generation.
1630 GCTracer::Scope gc_scope(tracer(), 1652 GCTracer::Scope gc_scope(tracer(),
1631 GCTracer::Scope::SCAVENGER_OLD_TO_NEW_POINTERS); 1653 GCTracer::Scope::SCAVENGER_OLD_TO_NEW_POINTERS);
(...skipping 18 matching lines...) Expand all
1650 if (collector->is_code_flushing_enabled()) { 1672 if (collector->is_code_flushing_enabled()) {
1651 collector->code_flusher()->IteratePointersToFromSpace(&scavenge_visitor); 1673 collector->code_flusher()->IteratePointersToFromSpace(&scavenge_visitor);
1652 } 1674 }
1653 } 1675 }
1654 1676
1655 { 1677 {
1656 GCTracer::Scope gc_scope(tracer(), GCTracer::Scope::SCAVENGER_SEMISPACE); 1678 GCTracer::Scope gc_scope(tracer(), GCTracer::Scope::SCAVENGER_SEMISPACE);
1657 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1679 new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
1658 } 1680 }
1659 1681
1660 { 1682 if (FLAG_scavenge_reclaim_unmodified_objects) {
1683 isolate()->global_handles()->MarkNewSpaceWeakUnmodifiedObjectsPending(
1684 &IsUnscavengedHeapObject);
1685
1686 isolate()->global_handles()->IterateNewSpaceWeakUnmodifiedRoots(
1687 &scavenge_visitor);
1688 new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
1689 } else {
1661 GCTracer::Scope gc_scope(tracer(), 1690 GCTracer::Scope gc_scope(tracer(),
1662 GCTracer::Scope::SCAVENGER_OBJECT_GROUPS); 1691 GCTracer::Scope::SCAVENGER_OBJECT_GROUPS);
1663 while (isolate()->global_handles()->IterateObjectGroups( 1692 while (isolate()->global_handles()->IterateObjectGroups(
1664 &scavenge_visitor, &IsUnscavengedHeapObject)) { 1693 &scavenge_visitor, &IsUnscavengedHeapObject)) {
1665 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1694 new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
1666 } 1695 }
1667 isolate()->global_handles()->RemoveObjectGroups(); 1696 isolate()->global_handles()->RemoveObjectGroups();
1668 isolate()->global_handles()->RemoveImplicitRefGroups(); 1697 isolate()->global_handles()->RemoveImplicitRefGroups();
1698
1699 isolate()->global_handles()->IdentifyNewSpaceWeakIndependentHandles(
1700 &IsUnscavengedHeapObject);
1701
1702 isolate()->global_handles()->IterateNewSpaceWeakIndependentRoots(
1703 &scavenge_visitor);
1704 new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
1669 } 1705 }
1670 1706
1671 isolate()->global_handles()->IdentifyNewSpaceWeakIndependentHandles(
1672 &IsUnscavengedHeapObject);
1673
1674 isolate()->global_handles()->IterateNewSpaceWeakIndependentRoots(
1675 &scavenge_visitor);
1676 new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
1677
1678 UpdateNewSpaceReferencesInExternalStringTable( 1707 UpdateNewSpaceReferencesInExternalStringTable(
1679 &UpdateNewSpaceReferenceInExternalStringTableEntry); 1708 &UpdateNewSpaceReferenceInExternalStringTableEntry);
1680 1709
1681 promotion_queue_.Destroy(); 1710 promotion_queue_.Destroy();
1682 1711
1683 incremental_marking()->UpdateMarkingDequeAfterScavenge(); 1712 incremental_marking()->UpdateMarkingDequeAfterScavenge();
1684 1713
1685 ScavengeWeakObjectRetainer weak_object_retainer(this); 1714 ScavengeWeakObjectRetainer weak_object_retainer(this);
1686 ProcessYoungWeakReferences(&weak_object_retainer); 1715 ProcessYoungWeakReferences(&weak_object_retainer);
1687 1716
(...skipping 4432 matching lines...) Expand 10 before | Expand all | Expand 10 after
6120 } 6149 }
6121 6150
6122 6151
6123 // static 6152 // static
6124 int Heap::GetStaticVisitorIdForMap(Map* map) { 6153 int Heap::GetStaticVisitorIdForMap(Map* map) {
6125 return StaticVisitorBase::GetVisitorId(map); 6154 return StaticVisitorBase::GetVisitorId(map);
6126 } 6155 }
6127 6156
6128 } // namespace internal 6157 } // namespace internal
6129 } // namespace v8 6158 } // namespace v8
OLDNEW
« no previous file with comments | « src/global-handles.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698