Commit 6479d426 authored by ulan's avatar ulan Committed by Commit bot

Record slots in the string table to avoid iterating it twice.

Currently we iterate the string table to clear non-live references and
to update pointers. We can skip the second iteration if we record slots.

BUG=

Review URL: https://codereview.chromium.org/1814033004

Cr-Commit-Position: refs/heads/master@{#34936}
parent 1c34e5f8
...@@ -1403,17 +1403,21 @@ class RootMarkingVisitor : public ObjectVisitor { ...@@ -1403,17 +1403,21 @@ class RootMarkingVisitor : public ObjectVisitor {
// Helper class for pruning the string table. // Helper class for pruning the string table.
template <bool finalize_external_strings> template <bool finalize_external_strings, bool record_slots>
class StringTableCleaner : public ObjectVisitor { class StringTableCleaner : public ObjectVisitor {
public: public:
explicit StringTableCleaner(Heap* heap) : heap_(heap), pointers_removed_(0) {} StringTableCleaner(Heap* heap, HeapObject* table)
: heap_(heap), pointers_removed_(0), table_(table) {
DCHECK(!record_slots || table != nullptr);
}
void VisitPointers(Object** start, Object** end) override { void VisitPointers(Object** start, Object** end) override {
// Visit all HeapObject pointers in [start, end). // Visit all HeapObject pointers in [start, end).
MarkCompactCollector* collector = heap_->mark_compact_collector();
for (Object** p = start; p < end; p++) { for (Object** p = start; p < end; p++) {
Object* o = *p; Object* o = *p;
if (o->IsHeapObject() && if (o->IsHeapObject()) {
Marking::IsWhite(Marking::MarkBitFrom(HeapObject::cast(o)))) { if (Marking::IsWhite(Marking::MarkBitFrom(HeapObject::cast(o)))) {
if (finalize_external_strings) { if (finalize_external_strings) {
DCHECK(o->IsExternalString()); DCHECK(o->IsExternalString());
heap_->FinalizeExternalString(String::cast(*p)); heap_->FinalizeExternalString(String::cast(*p));
...@@ -1422,6 +1426,11 @@ class StringTableCleaner : public ObjectVisitor { ...@@ -1422,6 +1426,11 @@ class StringTableCleaner : public ObjectVisitor {
} }
// Set the entry to the_hole_value (as deleted). // Set the entry to the_hole_value (as deleted).
*p = heap_->the_hole_value(); *p = heap_->the_hole_value();
} else if (record_slots) {
// StringTable contains only old space strings.
DCHECK(!heap_->InNewSpace(o));
collector->RecordSlot(table_, p, o);
}
} }
} }
} }
...@@ -1434,12 +1443,11 @@ class StringTableCleaner : public ObjectVisitor { ...@@ -1434,12 +1443,11 @@ class StringTableCleaner : public ObjectVisitor {
private: private:
Heap* heap_; Heap* heap_;
int pointers_removed_; int pointers_removed_;
HeapObject* table_;
}; };
typedef StringTableCleaner<false, true> InternalizedStringTableCleaner;
typedef StringTableCleaner<false> InternalizedStringTableCleaner; typedef StringTableCleaner<true, false> ExternalStringTableCleaner;
typedef StringTableCleaner<true> ExternalStringTableCleaner;
// Implementation of WeakObjectRetainer for mark compact GCs. All marked objects // Implementation of WeakObjectRetainer for mark compact GCs. All marked objects
// are retained. // are retained.
...@@ -2117,11 +2125,11 @@ void MarkCompactCollector::ClearNonLiveReferences() { ...@@ -2117,11 +2125,11 @@ void MarkCompactCollector::ClearNonLiveReferences() {
// string table. Cannot use string_table() here because the string // string table. Cannot use string_table() here because the string
// table is marked. // table is marked.
StringTable* string_table = heap()->string_table(); StringTable* string_table = heap()->string_table();
InternalizedStringTableCleaner internalized_visitor(heap()); InternalizedStringTableCleaner internalized_visitor(heap(), string_table);
string_table->IterateElements(&internalized_visitor); string_table->IterateElements(&internalized_visitor);
string_table->ElementsRemoved(internalized_visitor.PointersRemoved()); string_table->ElementsRemoved(internalized_visitor.PointersRemoved());
ExternalStringTableCleaner external_visitor(heap()); ExternalStringTableCleaner external_visitor(heap(), nullptr);
heap()->external_string_table_.Iterate(&external_visitor); heap()->external_string_table_.Iterate(&external_visitor);
heap()->external_string_table_.CleanUp(); heap()->external_string_table_.CleanUp();
} }
...@@ -3636,8 +3644,6 @@ void MarkCompactCollector::UpdatePointersAfterEvacuation() { ...@@ -3636,8 +3644,6 @@ void MarkCompactCollector::UpdatePointersAfterEvacuation() {
{ {
GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_EVACUATE_UPDATE_POINTERS_WEAK); GCTracer::Scope::MC_EVACUATE_UPDATE_POINTERS_WEAK);
heap_->string_table()->Iterate(&updating_visitor);
// Update pointers from external string table. // Update pointers from external string table.
heap_->UpdateReferencesInExternalStringTable( heap_->UpdateReferencesInExternalStringTable(
&UpdateReferenceInExternalStringTableEntry); &UpdateReferenceInExternalStringTableEntry);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment