Commit 9d5b307f authored by verwaest's avatar verwaest Committed by Commit bot

Internalize AstRawStrings by walking the string_table_ instead of adding them to a list

BUG=

Review-Url: https://codereview.chromium.org/2446993002
Cr-Commit-Position: refs/heads/master@{#40561}
parent b3bdb05f
...@@ -97,6 +97,8 @@ void AstString::Internalize(Isolate* isolate) { ...@@ -97,6 +97,8 @@ void AstString::Internalize(Isolate* isolate) {
} }
void AstRawString::Internalize(Isolate* isolate) { void AstRawString::Internalize(Isolate* isolate) {
// Skip over already internalized strings.
if (!string_.is_null()) return;
if (literal_bytes_.length() == 0) { if (literal_bytes_.length() == 0) {
string_ = isolate->factory()->empty_string(); string_ = isolate->factory()->empty_string();
} else { } else {
...@@ -256,7 +258,7 @@ const AstConsString* AstValueFactory::NewConsString( ...@@ -256,7 +258,7 @@ const AstConsString* AstValueFactory::NewConsString(
// the AstRawString will not be moved). // the AstRawString will not be moved).
AstConsString* new_string = new (zone_) AstConsString(left, right); AstConsString* new_string = new (zone_) AstConsString(left, right);
CHECK(new_string != nullptr); CHECK(new_string != nullptr);
AddString(new_string); AddConsString(new_string);
return new_string; return new_string;
} }
...@@ -295,18 +297,25 @@ const AstRawString* AstValueFactory::ConcatStrings(const AstRawString* left, ...@@ -295,18 +297,25 @@ const AstRawString* AstValueFactory::ConcatStrings(const AstRawString* left,
void AstValueFactory::Internalize(Isolate* isolate) { void AstValueFactory::Internalize(Isolate* isolate) {
// Strings need to be internalized before values, because values refer to // Strings need to be internalized before values, because values refer to
// strings. // strings. Internalize flat strings before cons strings since cons strings
for (AstString* current = strings_; current != nullptr;) { // may point to flat strings.
AstString* next = current->next(); for (base::CustomMatcherHashMap::Entry* entry = string_table_.Start();
entry != nullptr; entry = string_table_.Next(entry)) {
reinterpret_cast<AstRawString*>(entry->key)->Internalize(isolate);
}
for (AstConsString* current = cons_strings_; current != nullptr;) {
AstConsString* next = current->next();
current->Internalize(isolate); current->Internalize(isolate);
current = next; current = next;
} }
for (AstValue* current = values_; current != nullptr;) { for (AstValue* current = values_; current != nullptr;) {
AstValue* next = current->next(); AstValue* next = current->next();
current->Internalize(isolate); current->Internalize(isolate);
current = next; current = next;
} }
ResetStrings(); ResetConsStrings();
values_ = nullptr; values_ = nullptr;
} }
...@@ -385,7 +394,6 @@ AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, ...@@ -385,7 +394,6 @@ AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte,
is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); is_one_byte, Vector<const byte>(new_literal_bytes, length), hash);
CHECK(new_string != nullptr); CHECK(new_string != nullptr);
entry->key = new_string; entry->key = new_string;
AddString(new_string);
entry->value = reinterpret_cast<void*>(1); entry->value = reinterpret_cast<void*>(1);
} }
return reinterpret_cast<AstRawString*>(entry->key); return reinterpret_cast<AstRawString*>(entry->key);
......
...@@ -44,7 +44,7 @@ namespace internal { ...@@ -44,7 +44,7 @@ namespace internal {
class AstString : public ZoneObject { class AstString : public ZoneObject {
public: public:
explicit AstString(bool is_raw) explicit AstString(bool is_raw)
: next_(nullptr), bit_field_(IsRawStringBits::encode(is_raw)) {} : bit_field_(IsRawStringBits::encode(is_raw)) {}
int length() const; int length() const;
bool IsEmpty() const { return length() == 0; } bool IsEmpty() const { return length() == 0; }
...@@ -58,13 +58,9 @@ class AstString : public ZoneObject { ...@@ -58,13 +58,9 @@ class AstString : public ZoneObject {
return string_; return string_;
} }
AstString** next_location() { return &next_; }
AstString* next() const { return next_; }
protected: protected:
// Handle<String>::null() until internalized. // Handle<String>::null() until internalized.
Handle<String> string_; Handle<String> string_;
AstString* next_;
// Poor-man's virtual dispatch to AstRawString / AstConsString. Takes less // Poor-man's virtual dispatch to AstRawString / AstConsString. Takes less
// memory. // memory.
class IsRawStringBits : public BitField<bool, 0, 1> {}; class IsRawStringBits : public BitField<bool, 0, 1> {};
...@@ -133,16 +129,21 @@ class AstConsString final : public AstString { ...@@ -133,16 +129,21 @@ class AstConsString final : public AstString {
: AstString(false), : AstString(false),
length_(left->length() + right->length()), length_(left->length() + right->length()),
left_(left), left_(left),
right_(right) {} right_(right),
next_(nullptr) {}
int length() const { return length_; } int length() const { return length_; }
void Internalize(Isolate* isolate); void Internalize(Isolate* isolate);
AstConsString* next() { return next_; }
AstConsString** next_location() { return &next_; }
private: private:
const int length_; const int length_;
const AstString* left_; const AstString* left_;
const AstString* right_; const AstString* right_;
AstConsString* next_;
}; };
...@@ -264,7 +265,6 @@ class AstValue : public ZoneObject { ...@@ -264,7 +265,6 @@ class AstValue : public ZoneObject {
double number_; double number_;
int smi_; int smi_;
bool bool_; bool bool_;
const AstRawString* strings_;
const char* symbol_name_; const char* symbol_name_;
}; };
...@@ -325,10 +325,10 @@ class AstValueFactory { ...@@ -325,10 +325,10 @@ class AstValueFactory {
AstValueFactory(Zone* zone, uint32_t hash_seed) AstValueFactory(Zone* zone, uint32_t hash_seed)
: string_table_(AstRawStringCompare), : string_table_(AstRawStringCompare),
values_(nullptr), values_(nullptr),
strings_end_(&strings_), cons_strings_(nullptr),
cons_strings_end_(&cons_strings_),
zone_(zone), zone_(zone),
hash_seed_(hash_seed) { hash_seed_(hash_seed) {
ResetStrings();
#define F(name, str) name##_string_ = NULL; #define F(name, str) name##_string_ = NULL;
STRING_CONSTANTS(F) STRING_CONSTANTS(F)
#undef F #undef F
...@@ -387,14 +387,14 @@ class AstValueFactory { ...@@ -387,14 +387,14 @@ class AstValueFactory {
values_ = value; values_ = value;
return value; return value;
} }
AstString* AddString(AstString* string) { AstConsString* AddConsString(AstConsString* string) {
*strings_end_ = string; *cons_strings_end_ = string;
strings_end_ = string->next_location(); cons_strings_end_ = string->next_location();
return string; return string;
} }
void ResetStrings() { void ResetConsStrings() {
strings_ = nullptr; cons_strings_ = nullptr;
strings_end_ = &strings_; cons_strings_end_ = &cons_strings_;
} }
V8_EXPORT_PRIVATE AstRawString* GetOneByteStringInternal( V8_EXPORT_PRIVATE AstRawString* GetOneByteStringInternal(
Vector<const uint8_t> literal); Vector<const uint8_t> literal);
...@@ -409,10 +409,10 @@ class AstValueFactory { ...@@ -409,10 +409,10 @@ class AstValueFactory {
// For keeping track of all AstValues and AstRawStrings we've created (so that // For keeping track of all AstValues and AstRawStrings we've created (so that
// they can be internalized later). // they can be internalized later).
AstValue* values_; AstValue* values_;
// We need to keep track of strings_ in order, since cons strings require // We need to keep track of cons_strings_ in order since they require their
// their members to be internalized first. // members to be internalized first.
AstString* strings_; AstConsString* cons_strings_;
AstString** strings_end_; AstConsString** cons_strings_end_;
Zone* zone_; Zone* zone_;
uint32_t hash_seed_; uint32_t hash_seed_;
......
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