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