Commit f048b4b1 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[heap] ExternalStringTable: Replace List with std::vector

Bug: v8:6333
Change-Id: I0f5a21a66bbad6c56b3dd84d301b85e64f05cbc1
Reviewed-on: https://chromium-review.googlesource.com/635683Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47607}
parent 234d4307
...@@ -554,33 +554,34 @@ Isolate* Heap::isolate() { ...@@ -554,33 +554,34 @@ Isolate* Heap::isolate() {
} }
void Heap::ExternalStringTable::PromoteAllNewSpaceStrings() { void Heap::ExternalStringTable::PromoteAllNewSpaceStrings() {
old_space_strings_.AddAll(new_space_strings_); old_space_strings_.reserve(old_space_strings_.size() +
new_space_strings_.Clear(); new_space_strings_.size());
std::move(std::begin(new_space_strings_), std::end(new_space_strings_),
std::back_inserter(old_space_strings_));
new_space_strings_.clear();
} }
void Heap::ExternalStringTable::AddString(String* string) { void Heap::ExternalStringTable::AddString(String* string) {
DCHECK(string->IsExternalString()); DCHECK(string->IsExternalString());
if (heap_->InNewSpace(string)) { if (heap_->InNewSpace(string)) {
new_space_strings_.Add(string); new_space_strings_.push_back(string);
} else { } else {
old_space_strings_.Add(string); old_space_strings_.push_back(string);
} }
} }
void Heap::ExternalStringTable::IterateNewSpaceStrings(RootVisitor* v) { void Heap::ExternalStringTable::IterateNewSpaceStrings(RootVisitor* v) {
if (!new_space_strings_.is_empty()) { if (!new_space_strings_.empty()) {
Object** start = &new_space_strings_[0]; v->VisitRootPointers(Root::kExternalStringsTable, new_space_strings_.data(),
v->VisitRootPointers(Root::kExternalStringsTable, start, new_space_strings_.data() + new_space_strings_.size());
start + new_space_strings_.length());
} }
} }
void Heap::ExternalStringTable::IterateAll(RootVisitor* v) { void Heap::ExternalStringTable::IterateAll(RootVisitor* v) {
IterateNewSpaceStrings(v); IterateNewSpaceStrings(v);
if (!old_space_strings_.is_empty()) { if (!old_space_strings_.empty()) {
Object** start = &old_space_strings_[0]; v->VisitRootPointers(Root::kExternalStringsTable, old_space_strings_.data(),
v->VisitRootPointers(Root::kExternalStringsTable, start, old_space_strings_.data() + old_space_strings_.size());
start + old_space_strings_.length());
} }
} }
...@@ -589,12 +590,12 @@ void Heap::ExternalStringTable::IterateAll(RootVisitor* v) { ...@@ -589,12 +590,12 @@ void Heap::ExternalStringTable::IterateAll(RootVisitor* v) {
// mode. // mode.
void Heap::ExternalStringTable::Verify() { void Heap::ExternalStringTable::Verify() {
#ifdef DEBUG #ifdef DEBUG
for (int i = 0; i < new_space_strings_.length(); ++i) { for (size_t i = 0; i < new_space_strings_.size(); ++i) {
Object* obj = Object::cast(new_space_strings_[i]); Object* obj = Object::cast(new_space_strings_[i]);
DCHECK(heap_->InNewSpace(obj)); DCHECK(heap_->InNewSpace(obj));
DCHECK(!obj->IsTheHole(heap_->isolate())); DCHECK(!obj->IsTheHole(heap_->isolate()));
} }
for (int i = 0; i < old_space_strings_.length(); ++i) { for (size_t i = 0; i < old_space_strings_.size(); ++i) {
Object* obj = Object::cast(old_space_strings_[i]); Object* obj = Object::cast(old_space_strings_[i]);
DCHECK(!heap_->InNewSpace(obj)); DCHECK(!heap_->InNewSpace(obj));
DCHECK(!obj->IsTheHole(heap_->isolate())); DCHECK(!obj->IsTheHole(heap_->isolate()));
...@@ -606,17 +607,7 @@ void Heap::ExternalStringTable::Verify() { ...@@ -606,17 +607,7 @@ void Heap::ExternalStringTable::Verify() {
void Heap::ExternalStringTable::AddOldString(String* string) { void Heap::ExternalStringTable::AddOldString(String* string) {
DCHECK(string->IsExternalString()); DCHECK(string->IsExternalString());
DCHECK(!heap_->InNewSpace(string)); DCHECK(!heap_->InNewSpace(string));
old_space_strings_.Add(string); old_space_strings_.push_back(string);
}
void Heap::ExternalStringTable::ShrinkNewStrings(int position) {
new_space_strings_.Rewind(position);
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
Verify();
}
#endif
} }
Oddball* Heap::ToBoolean(bool condition) { Oddball* Heap::ToBoolean(bool condition) {
......
...@@ -2052,47 +2052,59 @@ String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap, ...@@ -2052,47 +2052,59 @@ String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap,
return string->IsExternalString() ? string : nullptr; return string->IsExternalString() ? string : nullptr;
} }
void Heap::ExternalStringTable::UpdateNewSpaceReferences(
Heap::ExternalStringTableUpdaterCallback updater_func) {
if (new_space_strings_.empty()) return;
void Heap::UpdateNewSpaceReferencesInExternalStringTable( Object** start = new_space_strings_.data();
ExternalStringTableUpdaterCallback updater_func) { Object** end = start + new_space_strings_.size();
if (external_string_table_.new_space_strings_.is_empty()) return;
Object** start = &external_string_table_.new_space_strings_[0];
Object** end = start + external_string_table_.new_space_strings_.length();
Object** last = start; Object** last = start;
for (Object** p = start; p < end; ++p) { for (Object** p = start; p < end; ++p) {
String* target = updater_func(this, p); String* target = updater_func(heap_, p);
if (target == NULL) continue; if (target == NULL) continue;
DCHECK(target->IsExternalString()); DCHECK(target->IsExternalString());
if (InNewSpace(target)) { if (heap_->InNewSpace(target)) {
// String is still in new space. Update the table entry. // String is still in new space. Update the table entry.
*last = target; *last = target;
++last; ++last;
} else { } else {
// String got promoted. Move it to the old string list. // String got promoted. Move it to the old string list.
external_string_table_.AddOldString(target); AddOldString(target);
} }
} }
DCHECK(last <= end); DCHECK_LE(last, end);
external_string_table_.ShrinkNewStrings(static_cast<int>(last - start)); new_space_strings_.resize(static_cast<size_t>(last - start));
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
Verify();
}
#endif
} }
void Heap::UpdateNewSpaceReferencesInExternalStringTable(
void Heap::UpdateReferencesInExternalStringTable(
ExternalStringTableUpdaterCallback updater_func) { ExternalStringTableUpdaterCallback updater_func) {
// Update old space string references. external_string_table_.UpdateNewSpaceReferences(updater_func);
if (external_string_table_.old_space_strings_.length() > 0) { }
Object** start = &external_string_table_.old_space_strings_[0];
Object** end = start + external_string_table_.old_space_strings_.length(); void Heap::ExternalStringTable::UpdateReferences(
for (Object** p = start; p < end; ++p) *p = updater_func(this, p); Heap::ExternalStringTableUpdaterCallback updater_func) {
if (old_space_strings_.size() > 0) {
Object** start = old_space_strings_.data();
Object** end = start + old_space_strings_.size();
for (Object** p = start; p < end; ++p) *p = updater_func(heap_, p);
} }
UpdateNewSpaceReferencesInExternalStringTable(updater_func); UpdateNewSpaceReferences(updater_func);
}
void Heap::UpdateReferencesInExternalStringTable(
ExternalStringTableUpdaterCallback updater_func) {
external_string_table_.UpdateReferences(updater_func);
} }
...@@ -6650,7 +6662,7 @@ void Heap::UpdateTotalGCTime(double duration) { ...@@ -6650,7 +6662,7 @@ void Heap::UpdateTotalGCTime(double duration) {
void Heap::ExternalStringTable::CleanUpNewSpaceStrings() { 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 (size_t i = 0; i < new_space_strings_.size(); ++i) {
Object* o = new_space_strings_[i]; Object* o = new_space_strings_[i];
if (o->IsTheHole(isolate)) { if (o->IsTheHole(isolate)) {
continue; continue;
...@@ -6663,18 +6675,17 @@ void Heap::ExternalStringTable::CleanUpNewSpaceStrings() { ...@@ -6663,18 +6675,17 @@ void Heap::ExternalStringTable::CleanUpNewSpaceStrings() {
if (heap_->InNewSpace(o)) { if (heap_->InNewSpace(o)) {
new_space_strings_[last++] = o; new_space_strings_[last++] = o;
} else { } else {
old_space_strings_.Add(o); old_space_strings_.push_back(o);
} }
} }
new_space_strings_.Rewind(last); new_space_strings_.resize(last);
new_space_strings_.Trim();
} }
void Heap::ExternalStringTable::CleanUpAll() { void Heap::ExternalStringTable::CleanUpAll() {
CleanUpNewSpaceStrings(); CleanUpNewSpaceStrings();
int last = 0; int last = 0;
Isolate* isolate = heap_->isolate(); Isolate* isolate = heap_->isolate();
for (int i = 0; i < old_space_strings_.length(); ++i) { for (size_t i = 0; i < old_space_strings_.size(); ++i) {
Object* o = old_space_strings_[i]; Object* o = old_space_strings_[i];
if (o->IsTheHole(isolate)) { if (o->IsTheHole(isolate)) {
continue; continue;
...@@ -6687,8 +6698,7 @@ void Heap::ExternalStringTable::CleanUpAll() { ...@@ -6687,8 +6698,7 @@ void Heap::ExternalStringTable::CleanUpAll() {
DCHECK(!heap_->InNewSpace(o)); DCHECK(!heap_->InNewSpace(o));
old_space_strings_[last++] = o; old_space_strings_[last++] = o;
} }
old_space_strings_.Rewind(last); old_space_strings_.resize(last);
old_space_strings_.Trim();
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
if (FLAG_verify_heap) { if (FLAG_verify_heap) {
Verify(); Verify();
...@@ -6697,7 +6707,7 @@ void Heap::ExternalStringTable::CleanUpAll() { ...@@ -6697,7 +6707,7 @@ void Heap::ExternalStringTable::CleanUpAll() {
} }
void Heap::ExternalStringTable::TearDown() { void Heap::ExternalStringTable::TearDown() {
for (int i = 0; i < new_space_strings_.length(); ++i) { for (size_t i = 0; i < new_space_strings_.size(); ++i) {
Object* o = new_space_strings_[i]; Object* o = new_space_strings_[i];
if (o->IsThinString()) { if (o->IsThinString()) {
o = ThinString::cast(o)->actual(); o = ThinString::cast(o)->actual();
...@@ -6705,8 +6715,8 @@ void Heap::ExternalStringTable::TearDown() { ...@@ -6705,8 +6715,8 @@ void Heap::ExternalStringTable::TearDown() {
} }
heap_->FinalizeExternalString(ExternalString::cast(o)); heap_->FinalizeExternalString(ExternalString::cast(o));
} }
new_space_strings_.Free(); new_space_strings_.clear();
for (int i = 0; i < old_space_strings_.length(); ++i) { for (size_t i = 0; i < old_space_strings_.size(); ++i) {
Object* o = old_space_strings_[i]; Object* o = old_space_strings_[i];
if (o->IsThinString()) { if (o->IsThinString()) {
o = ThinString::cast(o)->actual(); o = ThinString::cast(o)->actual();
...@@ -6714,7 +6724,7 @@ void Heap::ExternalStringTable::TearDown() { ...@@ -6714,7 +6724,7 @@ void Heap::ExternalStringTable::TearDown() {
} }
heap_->FinalizeExternalString(ExternalString::cast(o)); heap_->FinalizeExternalString(ExternalString::cast(o));
} }
old_space_strings_.Free(); old_space_strings_.clear();
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "src/debug/debug-interface.h" #include "src/debug/debug-interface.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/heap-symbols.h" #include "src/heap-symbols.h"
#include "src/list.h"
#include "src/objects.h" #include "src/objects.h"
#include "src/objects/hash-table.h" #include "src/objects/hash-table.h"
#include "src/objects/string-table.h" #include "src/objects/string-table.h"
...@@ -1545,11 +1544,16 @@ class Heap { ...@@ -1545,11 +1544,16 @@ class Heap {
class SkipStoreBufferScope; class SkipStoreBufferScope;
class PretenuringScope; class PretenuringScope;
typedef String* (*ExternalStringTableUpdaterCallback)(Heap* heap,
Object** pointer);
// External strings table is a place where all external strings are // External strings table is a place where all external strings are
// registered. We need to keep track of such strings to properly // registered. We need to keep track of such strings to properly
// finalize them. // finalize them.
class ExternalStringTable { class ExternalStringTable {
public: public:
explicit ExternalStringTable(Heap* heap) : heap_(heap) {}
// Registers an external string. // Registers an external string.
inline void AddString(String* string); inline void AddString(String* string);
...@@ -1565,24 +1569,22 @@ class Heap { ...@@ -1565,24 +1569,22 @@ class Heap {
// Destroys all allocated memory. // Destroys all allocated memory.
void TearDown(); void TearDown();
private: void UpdateNewSpaceReferences(
explicit ExternalStringTable(Heap* heap) : heap_(heap) {} Heap::ExternalStringTableUpdaterCallback updater_func);
void UpdateReferences(
Heap::ExternalStringTableUpdaterCallback updater_func);
private:
inline void Verify(); inline void Verify();
inline void AddOldString(String* string); inline void AddOldString(String* string);
// Notifies the table that only a prefix of the new list is valid. Heap* const heap_;
inline void ShrinkNewStrings(int position);
// To speed up scavenge collections new space string are kept // To speed up scavenge collections new space string are kept
// separate from old space strings. // separate from old space strings.
List<Object*> new_space_strings_; std::vector<Object*> new_space_strings_;
List<Object*> old_space_strings_; std::vector<Object*> old_space_strings_;
Heap* heap_;
friend class Heap;
DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); DISALLOW_COPY_AND_ASSIGN(ExternalStringTable);
}; };
...@@ -1619,9 +1621,6 @@ class Heap { ...@@ -1619,9 +1621,6 @@ class Heap {
bool pass_isolate; bool pass_isolate;
}; };
typedef String* (*ExternalStringTableUpdaterCallback)(Heap* heap,
Object** pointer);
static const int kInitialStringTableSize = 2048; static const int kInitialStringTableSize = 2048;
static const int kInitialEvalCacheSize = 64; static const int kInitialEvalCacheSize = 64;
static const int kInitialNumberStringCacheSize = 256; static const int kInitialNumberStringCacheSize = 256;
......
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