[heap] Force all RO_SPACE strings to be internalized

Since RO_SPACE strings cannot be written to after creation, they cannot
be internalized later. This adds checks to normal string construction
methods that they are not created with TENURED_READ_ONLY.

Also changes the Symbol construction in setup-heap-internal.cc to use
internalized strings, which increases the number of internalized
RO_SPACE strings from 490 to 514 (915 including OLD_SPACE).

Bug: chromium:911416
Change-Id: I222ff883e98f3a2f4ce70d369f22273f5c9edb0b
Reviewed-on: https://chromium-review.googlesource.com/c/1365279
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58074}
This commit is contained in:
Dan Elphick 2018-12-06 12:54:38 +00:00 committed by Commit Bot
parent ee485e2c98
commit c1ceee7d9e
2 changed files with 12 additions and 11 deletions

View File

@ -619,6 +619,7 @@ Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) {
MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
PretenureFlag pretenure) {
DCHECK_NE(pretenure, TENURED_READ_ONLY);
int length = string.length();
if (length == 0) return empty_string();
if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
@ -636,6 +637,7 @@ MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
MaybeHandle<String> Factory::NewStringFromUtf8(Vector<const char> string,
PretenureFlag pretenure) {
DCHECK_NE(pretenure, TENURED_READ_ONLY);
// Check for ASCII first since this is the common case.
const char* ascii_data = string.start();
int length = string.length();
@ -731,6 +733,7 @@ MaybeHandle<String> Factory::NewStringFromUtf8SubString(
MaybeHandle<String> Factory::NewStringFromTwoByte(const uc16* string,
int length,
PretenureFlag pretenure) {
DCHECK_NE(pretenure, TENURED_READ_ONLY);
if (length == 0) return empty_string();
if (String::IsOneByte(string, length)) {
if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);

View File

@ -723,21 +723,19 @@ void Heap::CreateInitialObjects() {
{
HandleScope scope(isolate());
#define SYMBOL_INIT(_, name, description) \
Handle<Symbol> name = factory->NewSymbol(TENURED_READ_ONLY); \
Handle<String> name##d = \
factory->NewStringFromStaticChars(#description, TENURED_READ_ONLY); \
name->set_name(*name##d); \
#define SYMBOL_INIT(_, name, description) \
Handle<Symbol> name = factory->NewSymbol(TENURED_READ_ONLY); \
Handle<String> name##d = factory->InternalizeUtf8String(#description); \
name->set_name(*name##d); \
roots_table()[RootIndex::k##name] = *name;
PUBLIC_SYMBOL_LIST_GENERATOR(SYMBOL_INIT, /* not used */)
#undef SYMBOL_INIT
#define SYMBOL_INIT(_, name, description) \
Handle<Symbol> name = factory->NewSymbol(TENURED_READ_ONLY); \
Handle<String> name##d = \
factory->NewStringFromStaticChars(#description, TENURED_READ_ONLY); \
name->set_is_well_known_symbol(true); \
name->set_name(*name##d); \
#define SYMBOL_INIT(_, name, description) \
Handle<Symbol> name = factory->NewSymbol(TENURED_READ_ONLY); \
Handle<String> name##d = factory->InternalizeUtf8String(#description); \
name->set_is_well_known_symbol(true); \
name->set_name(*name##d); \
roots_table()[RootIndex::k##name] = *name;
WELL_KNOWN_SYMBOL_LIST_GENERATOR(SYMBOL_INIT, /* not used */)
#undef SYMBOL_INIT