[heap] ExternalStringTable: Separate Iterate and CleanUp methods

This way we can just process new space strings when needed.

BUG=chromium:651354

Review-Url: https://codereview.chromium.org/2515643002
Cr-Commit-Position: refs/heads/master@{#41107}
This commit is contained in:
mlippautz 2016-11-18 05:00:58 -08:00 committed by Commit bot
parent cfd1dd2f95
commit 80339771e3
4 changed files with 21 additions and 12 deletions

View File

@ -702,12 +702,15 @@ void Heap::ExternalStringTable::AddString(String* string) {
} }
} }
void Heap::ExternalStringTable::IterateNewSpaceStrings(ObjectVisitor* v) {
void Heap::ExternalStringTable::Iterate(ObjectVisitor* v) {
if (!new_space_strings_.is_empty()) { if (!new_space_strings_.is_empty()) {
Object** start = &new_space_strings_[0]; Object** start = &new_space_strings_[0];
v->VisitPointers(start, start + new_space_strings_.length()); v->VisitPointers(start, start + new_space_strings_.length());
} }
}
void Heap::ExternalStringTable::IterateAll(ObjectVisitor* v) {
IterateNewSpaceStrings(v);
if (!old_space_strings_.is_empty()) { if (!old_space_strings_.is_empty()) {
Object** start = &old_space_strings_[0]; Object** start = &old_space_strings_[0];
v->VisitPointers(start, start + old_space_strings_.length()); v->VisitPointers(start, start + old_space_strings_.length());

View File

@ -1859,7 +1859,7 @@ void Heap::VisitExternalResources(v8::ExternalResourceVisitor* visitor) {
v8::ExternalResourceVisitor* visitor_; v8::ExternalResourceVisitor* visitor_;
} external_string_table_visitor(visitor); } external_string_table_visitor(visitor);
external_string_table_.Iterate(&external_string_table_visitor); external_string_table_.IterateAll(&external_string_table_visitor);
} }
Address Heap::DoScavenge(ObjectVisitor* scavenge_visitor, Address Heap::DoScavenge(ObjectVisitor* scavenge_visitor,
@ -4817,7 +4817,7 @@ void Heap::IterateWeakRoots(ObjectVisitor* v, VisitMode mode) {
v->Synchronize(VisitorSynchronization::kStringTable); v->Synchronize(VisitorSynchronization::kStringTable);
if (mode != VISIT_ALL_IN_SCAVENGE && mode != VISIT_ALL_IN_SWEEP_NEWSPACE) { if (mode != VISIT_ALL_IN_SCAVENGE && mode != VISIT_ALL_IN_SWEEP_NEWSPACE) {
// Scavenge collections have special processing for this. // Scavenge collections have special processing for this.
external_string_table_.Iterate(v); external_string_table_.IterateAll(v);
} }
v->Synchronize(VisitorSynchronization::kExternalStringsTable); v->Synchronize(VisitorSynchronization::kExternalStringsTable);
} }
@ -6308,7 +6308,7 @@ void Heap::UpdateTotalGCTime(double duration) {
} }
} }
void Heap::ExternalStringTable::CleanUp() { void Heap::ExternalStringTable::CleanUpNewSpaceStrings() {
int last = 0; int last = 0;
Isolate* isolate = heap_->isolate(); Isolate* isolate = heap_->isolate();
for (int i = 0; i < new_space_strings_.length(); ++i) { for (int i = 0; i < new_space_strings_.length(); ++i) {
@ -6324,8 +6324,12 @@ void Heap::ExternalStringTable::CleanUp() {
} }
new_space_strings_.Rewind(last); new_space_strings_.Rewind(last);
new_space_strings_.Trim(); new_space_strings_.Trim();
}
last = 0; void Heap::ExternalStringTable::CleanUpAll() {
CleanUpNewSpaceStrings();
int last = 0;
Isolate* isolate = heap_->isolate();
for (int i = 0; i < old_space_strings_.length(); ++i) { for (int i = 0; i < old_space_strings_.length(); ++i) {
if (old_space_strings_[i]->IsTheHole(isolate)) { if (old_space_strings_[i]->IsTheHole(isolate)) {
continue; continue;

View File

@ -1511,11 +1511,13 @@ class Heap {
// Registers an external string. // Registers an external string.
inline void AddString(String* string); inline void AddString(String* string);
inline void Iterate(ObjectVisitor* v); inline void IterateAll(ObjectVisitor* v);
inline void IterateNewSpaceStrings(ObjectVisitor* v);
// Restores internal invariant and gets rid of collected strings. // Restores internal invariant and gets rid of collected strings. Must be
// Must be called after each Iterate() that modified the strings. // called after each Iterate*() that modified the strings.
void CleanUp(); void CleanUpAll();
void CleanUpNewSpaceStrings();
// Destroys all allocated memory. // Destroys all allocated memory.
void TearDown(); void TearDown();

View File

@ -2514,8 +2514,8 @@ void MarkCompactCollector::ClearNonLiveReferences() {
string_table->ElementsRemoved(internalized_visitor.PointersRemoved()); string_table->ElementsRemoved(internalized_visitor.PointersRemoved());
ExternalStringTableCleaner external_visitor(heap(), nullptr); ExternalStringTableCleaner external_visitor(heap(), nullptr);
heap()->external_string_table_.Iterate(&external_visitor); heap()->external_string_table_.IterateAll(&external_visitor);
heap()->external_string_table_.CleanUp(); heap()->external_string_table_.CleanUpAll();
} }
{ {