| OLD | NEW |
| 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/mark-compact.h" | 5 #include "src/heap/mark-compact.h" |
| 6 | 6 |
| 7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 // Mark all the objects reachable from the map and body. May leave | 1396 // Mark all the objects reachable from the map and body. May leave |
| 1397 // overflowed objects in the heap. | 1397 // overflowed objects in the heap. |
| 1398 collector_->EmptyMarkingDeque(); | 1398 collector_->EmptyMarkingDeque(); |
| 1399 } | 1399 } |
| 1400 | 1400 |
| 1401 MarkCompactCollector* collector_; | 1401 MarkCompactCollector* collector_; |
| 1402 }; | 1402 }; |
| 1403 | 1403 |
| 1404 | 1404 |
| 1405 // Helper class for pruning the string table. | 1405 // Helper class for pruning the string table. |
| 1406 template <bool finalize_external_strings> | 1406 template <bool finalize_external_strings, bool record_slots> |
| 1407 class StringTableCleaner : public ObjectVisitor { | 1407 class StringTableCleaner : public ObjectVisitor { |
| 1408 public: | 1408 public: |
| 1409 explicit StringTableCleaner(Heap* heap) : heap_(heap), pointers_removed_(0) {} | 1409 StringTableCleaner(Heap* heap, HeapObject* table) |
| 1410 : heap_(heap), pointers_removed_(0), table_(table) { |
| 1411 DCHECK(!record_slots || table != nullptr); |
| 1412 } |
| 1410 | 1413 |
| 1411 void VisitPointers(Object** start, Object** end) override { | 1414 void VisitPointers(Object** start, Object** end) override { |
| 1412 // Visit all HeapObject pointers in [start, end). | 1415 // Visit all HeapObject pointers in [start, end). |
| 1416 MarkCompactCollector* collector = heap_->mark_compact_collector(); |
| 1413 for (Object** p = start; p < end; p++) { | 1417 for (Object** p = start; p < end; p++) { |
| 1414 Object* o = *p; | 1418 Object* o = *p; |
| 1415 if (o->IsHeapObject() && | 1419 if (o->IsHeapObject()) { |
| 1416 Marking::IsWhite(Marking::MarkBitFrom(HeapObject::cast(o)))) { | 1420 if (Marking::IsWhite(Marking::MarkBitFrom(HeapObject::cast(o)))) { |
| 1417 if (finalize_external_strings) { | 1421 if (finalize_external_strings) { |
| 1418 DCHECK(o->IsExternalString()); | 1422 DCHECK(o->IsExternalString()); |
| 1419 heap_->FinalizeExternalString(String::cast(*p)); | 1423 heap_->FinalizeExternalString(String::cast(*p)); |
| 1420 } else { | 1424 } else { |
| 1421 pointers_removed_++; | 1425 pointers_removed_++; |
| 1426 } |
| 1427 // Set the entry to the_hole_value (as deleted). |
| 1428 *p = heap_->the_hole_value(); |
| 1429 } else if (record_slots) { |
| 1430 // StringTable contains only old space strings. |
| 1431 DCHECK(!heap_->InNewSpace(o)); |
| 1432 collector->RecordSlot(table_, p, o); |
| 1422 } | 1433 } |
| 1423 // Set the entry to the_hole_value (as deleted). | |
| 1424 *p = heap_->the_hole_value(); | |
| 1425 } | 1434 } |
| 1426 } | 1435 } |
| 1427 } | 1436 } |
| 1428 | 1437 |
| 1429 int PointersRemoved() { | 1438 int PointersRemoved() { |
| 1430 DCHECK(!finalize_external_strings); | 1439 DCHECK(!finalize_external_strings); |
| 1431 return pointers_removed_; | 1440 return pointers_removed_; |
| 1432 } | 1441 } |
| 1433 | 1442 |
| 1434 private: | 1443 private: |
| 1435 Heap* heap_; | 1444 Heap* heap_; |
| 1436 int pointers_removed_; | 1445 int pointers_removed_; |
| 1446 HeapObject* table_; |
| 1437 }; | 1447 }; |
| 1438 | 1448 |
| 1439 | 1449 typedef StringTableCleaner<false, true> InternalizedStringTableCleaner; |
| 1440 typedef StringTableCleaner<false> InternalizedStringTableCleaner; | 1450 typedef StringTableCleaner<true, false> ExternalStringTableCleaner; |
| 1441 typedef StringTableCleaner<true> ExternalStringTableCleaner; | |
| 1442 | |
| 1443 | 1451 |
| 1444 // Implementation of WeakObjectRetainer for mark compact GCs. All marked objects | 1452 // Implementation of WeakObjectRetainer for mark compact GCs. All marked objects |
| 1445 // are retained. | 1453 // are retained. |
| 1446 class MarkCompactWeakObjectRetainer : public WeakObjectRetainer { | 1454 class MarkCompactWeakObjectRetainer : public WeakObjectRetainer { |
| 1447 public: | 1455 public: |
| 1448 virtual Object* RetainAs(Object* object) { | 1456 virtual Object* RetainAs(Object* object) { |
| 1449 MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(object)); | 1457 MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(object)); |
| 1450 DCHECK(!Marking::IsGrey(mark_bit)); | 1458 DCHECK(!Marking::IsGrey(mark_bit)); |
| 1451 if (Marking::IsBlack(mark_bit)) { | 1459 if (Marking::IsBlack(mark_bit)) { |
| 1452 return object; | 1460 return object; |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2110 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_CLEAR); | 2118 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_CLEAR); |
| 2111 | 2119 |
| 2112 { | 2120 { |
| 2113 GCTracer::Scope gc_scope(heap()->tracer(), | 2121 GCTracer::Scope gc_scope(heap()->tracer(), |
| 2114 GCTracer::Scope::MC_CLEAR_STRING_TABLE); | 2122 GCTracer::Scope::MC_CLEAR_STRING_TABLE); |
| 2115 | 2123 |
| 2116 // Prune the string table removing all strings only pointed to by the | 2124 // Prune the string table removing all strings only pointed to by the |
| 2117 // string table. Cannot use string_table() here because the string | 2125 // string table. Cannot use string_table() here because the string |
| 2118 // table is marked. | 2126 // table is marked. |
| 2119 StringTable* string_table = heap()->string_table(); | 2127 StringTable* string_table = heap()->string_table(); |
| 2120 InternalizedStringTableCleaner internalized_visitor(heap()); | 2128 InternalizedStringTableCleaner internalized_visitor(heap(), string_table); |
| 2121 string_table->IterateElements(&internalized_visitor); | 2129 string_table->IterateElements(&internalized_visitor); |
| 2122 string_table->ElementsRemoved(internalized_visitor.PointersRemoved()); | 2130 string_table->ElementsRemoved(internalized_visitor.PointersRemoved()); |
| 2123 | 2131 |
| 2124 ExternalStringTableCleaner external_visitor(heap()); | 2132 ExternalStringTableCleaner external_visitor(heap(), nullptr); |
| 2125 heap()->external_string_table_.Iterate(&external_visitor); | 2133 heap()->external_string_table_.Iterate(&external_visitor); |
| 2126 heap()->external_string_table_.CleanUp(); | 2134 heap()->external_string_table_.CleanUp(); |
| 2127 } | 2135 } |
| 2128 | 2136 |
| 2129 { | 2137 { |
| 2130 GCTracer::Scope gc_scope(heap()->tracer(), | 2138 GCTracer::Scope gc_scope(heap()->tracer(), |
| 2131 GCTracer::Scope::MC_CLEAR_WEAK_LISTS); | 2139 GCTracer::Scope::MC_CLEAR_WEAK_LISTS); |
| 2132 // Process the weak references. | 2140 // Process the weak references. |
| 2133 MarkCompactWeakObjectRetainer mark_compact_object_retainer; | 2141 MarkCompactWeakObjectRetainer mark_compact_object_retainer; |
| 2134 heap()->ProcessAllWeakReferences(&mark_compact_object_retainer); | 2142 heap()->ProcessAllWeakReferences(&mark_compact_object_retainer); |
| (...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3634 if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) { | 3642 if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) { |
| 3635 p->ClearEvacuationCandidate(); | 3643 p->ClearEvacuationCandidate(); |
| 3636 VisitLiveObjectsBody(p, &updating_visitor); | 3644 VisitLiveObjectsBody(p, &updating_visitor); |
| 3637 } | 3645 } |
| 3638 } | 3646 } |
| 3639 } | 3647 } |
| 3640 | 3648 |
| 3641 { | 3649 { |
| 3642 GCTracer::Scope gc_scope(heap()->tracer(), | 3650 GCTracer::Scope gc_scope(heap()->tracer(), |
| 3643 GCTracer::Scope::MC_EVACUATE_UPDATE_POINTERS_WEAK); | 3651 GCTracer::Scope::MC_EVACUATE_UPDATE_POINTERS_WEAK); |
| 3644 heap_->string_table()->Iterate(&updating_visitor); | |
| 3645 | |
| 3646 // Update pointers from external string table. | 3652 // Update pointers from external string table. |
| 3647 heap_->UpdateReferencesInExternalStringTable( | 3653 heap_->UpdateReferencesInExternalStringTable( |
| 3648 &UpdateReferenceInExternalStringTableEntry); | 3654 &UpdateReferenceInExternalStringTableEntry); |
| 3649 | 3655 |
| 3650 EvacuationWeakObjectRetainer evacuation_object_retainer; | 3656 EvacuationWeakObjectRetainer evacuation_object_retainer; |
| 3651 heap()->ProcessWeakListRoots(&evacuation_object_retainer); | 3657 heap()->ProcessWeakListRoots(&evacuation_object_retainer); |
| 3652 } | 3658 } |
| 3653 } | 3659 } |
| 3654 | 3660 |
| 3655 | 3661 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3863 MarkBit mark_bit = Marking::MarkBitFrom(host); | 3869 MarkBit mark_bit = Marking::MarkBitFrom(host); |
| 3864 if (Marking::IsBlack(mark_bit)) { | 3870 if (Marking::IsBlack(mark_bit)) { |
| 3865 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); | 3871 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); |
| 3866 RecordRelocSlot(host, &rinfo, target); | 3872 RecordRelocSlot(host, &rinfo, target); |
| 3867 } | 3873 } |
| 3868 } | 3874 } |
| 3869 } | 3875 } |
| 3870 | 3876 |
| 3871 } // namespace internal | 3877 } // namespace internal |
| 3872 } // namespace v8 | 3878 } // namespace v8 |
| OLD | NEW |