Commit c1ceee7d authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[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/1365279Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58074}
parent ee485e2c
......@@ -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]);
......
......@@ -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
......
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