Commit 3bd4ac9d authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Parsing] Create canononical ScopeInfos in the read-only space.

Create canonical ScopeInfos for the global this binding and empty function in
the read only space, rather than creating them during bootstrapping for each
native context. This saves some memory, and also means we don't need to access
the native context to get the global this binding in when deserializing a
scope info, which is important since parsing should be native context independent.

BUG=chromium:992063

Change-Id: I800f576e8e9b95d46e043cba0c1a03ae19a683c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1748690
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63174}
parent 8b7c1c24
......@@ -378,11 +378,8 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
if (deserialization_mode == DeserializationMode::kIncludingVariables &&
script_scope->scope_info_.is_null()) {
Handle<ScriptContextTable> table(
isolate->native_context()->script_context_table(), isolate);
Handle<Context> first = ScriptContextTable::GetContext(isolate, table, 0);
Handle<ScopeInfo> scope_info(first->scope_info(), isolate);
script_scope->SetScriptScopeInfo(scope_info);
script_scope->SetScriptScopeInfo(
ReadOnlyRoots(isolate).global_this_binding_scope_info_handle());
}
if (innermost_scope == nullptr) return script_scope;
......
......@@ -2547,9 +2547,10 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
return result;
}
Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
Handle<ScopeInfo> Factory::NewScopeInfo(int length, AllocationType type) {
DCHECK(type == AllocationType::kOld || type == AllocationType::kReadOnly);
return NewFixedArrayWithMap<ScopeInfo>(RootIndex::kScopeInfoMap, length,
AllocationType::kOld);
type);
}
Handle<SourceTextModuleInfo> Factory::NewSourceTextModuleInfo() {
......
......@@ -769,7 +769,8 @@ class V8_EXPORT_PRIVATE Factory {
AllocationType allocation = AllocationType::kOld);
// Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length);
Handle<ScopeInfo> NewScopeInfo(int length,
AllocationType type = AllocationType::kOld);
Handle<SourceTextModuleInfo> NewSourceTextModuleInfo();
......
......@@ -825,6 +825,15 @@ void Heap::CreateInitialObjects() {
factory->NewFeedbackMetadata(0, 0, AllocationType::kReadOnly);
set_empty_feedback_metadata(*empty_feedback_metadata);
// Canonical scope arrays.
Handle<ScopeInfo> global_this_binding =
ScopeInfo::CreateGlobalThisBinding(isolate());
set_global_this_binding_scope_info(*global_this_binding);
Handle<ScopeInfo> empty_function =
ScopeInfo::CreateForEmptyFunction(isolate());
set_empty_function_scope_info(*empty_function);
// Allocate the empty script.
Handle<Script> script = factory->NewScript(factory->empty_string());
script->set_type(Script::TYPE_NATIVE);
......
......@@ -596,9 +596,6 @@ Handle<JSFunction> Genesis::CreateEmptyFunction() {
empty_function_map->set_is_prototype_map(true);
DCHECK(!empty_function_map->is_dictionary_map());
// Allocate ScopeInfo for the empty function.
Handle<ScopeInfo> scope_info = ScopeInfo::CreateForEmptyFunction(isolate());
// Allocate the empty function as the prototype for function according to
// ES#sec-properties-of-the-function-prototype-object
NewFunctionArgs args = NewFunctionArgs::ForBuiltin(
......@@ -612,7 +609,8 @@ Handle<JSFunction> Genesis::CreateEmptyFunction() {
script->set_type(Script::TYPE_NATIVE);
Handle<WeakFixedArray> infos = factory()->NewWeakFixedArray(2);
script->set_shared_function_infos(*infos);
empty_function->shared().set_scope_info(*scope_info);
empty_function->shared().set_raw_scope_info(
ReadOnlyRoots(isolate()).empty_function_scope_info());
empty_function->shared().DontAdaptArguments();
SharedFunctionInfo::SetScript(handle(empty_function->shared(), isolate()),
script, 1);
......@@ -1154,7 +1152,8 @@ void Genesis::CreateRoots() {
void Genesis::InstallGlobalThisBinding() {
Handle<ScriptContextTable> script_contexts(
native_context()->script_context_table(), isolate());
Handle<ScopeInfo> scope_info = ScopeInfo::CreateGlobalThisBinding(isolate());
Handle<ScopeInfo> scope_info =
ReadOnlyRoots(isolate()).global_this_binding_scope_info_handle();
Handle<Context> context =
factory()->NewScriptContext(native_context(), scope_info);
......
......@@ -413,7 +413,8 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
(has_position_info ? kPositionInfoEntries : 0);
Factory* factory = isolate->factory();
Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
Handle<ScopeInfo> scope_info =
factory->NewScopeInfo(length, AllocationType::kReadOnly);
// Encode the flags.
int flags =
......
......@@ -359,6 +359,11 @@ void SharedFunctionInfo::set_scope_info(ScopeInfo scope_info,
if (HasInferredName() && inferred_name().length() != 0) {
scope_info.SetInferredFunctionName(inferred_name());
}
set_raw_scope_info(scope_info, mode);
}
void SharedFunctionInfo::set_raw_scope_info(ScopeInfo scope_info,
WriteBarrierMode mode) {
WRITE_FIELD(*this, kNameOrScopeInfoOffset, scope_info);
CONDITIONAL_WRITE_BARRIER(*this, kNameOrScopeInfoOffset, scope_info, mode);
}
......
......@@ -256,6 +256,10 @@ class SharedFunctionInfo : public HeapObject {
// [scope_info]: Scope info.
DECL_ACCESSORS(scope_info, ScopeInfo)
// Set scope_info without moving the existing name onto the ScopeInfo.
inline void set_raw_scope_info(ScopeInfo scope_info,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
// End position of this function in the script source.
V8_EXPORT_PRIVATE int EndPosition() const;
......
......@@ -199,6 +199,9 @@ class Symbol;
TrampolineTrivialCodeDataContainer) \
V(CodeDataContainer, trampoline_promise_rejection_code_data_container, \
TrampolinePromiseRejectionCodeDataContainer) \
/* Canonical scope infos */ \
V(ScopeInfo, global_this_binding_scope_info, GlobalThisBindingScopeInfo) \
V(ScopeInfo, empty_function_scope_info, EmptyFunctionScopeInfo) \
/* Hash seed */ \
V(ByteArray, hash_seed, HashSeed)
......
......@@ -172,7 +172,8 @@ TEST_F(JSCreateLoweringTest, JSCreateFunctionContextViaInlinedAllocation) {
// JSCreateWithContext
TEST_F(JSCreateLoweringTest, JSCreateWithContext) {
Handle<ScopeInfo> scope_info = ScopeInfo::CreateForEmptyFunction(isolate());
Handle<ScopeInfo> scope_info =
ReadOnlyRoots(isolate()).empty_function_scope_info_handle();
Node* const object = Parameter(Type::Receiver());
Node* const context = Parameter(Type::Any());
Node* const effect = graph()->start();
......@@ -192,7 +193,8 @@ TEST_F(JSCreateLoweringTest, JSCreateWithContext) {
// JSCreateCatchContext
TEST_F(JSCreateLoweringTest, JSCreateCatchContext) {
Handle<ScopeInfo> scope_info = ScopeInfo::CreateForEmptyFunction(isolate());
Handle<ScopeInfo> scope_info =
ReadOnlyRoots(isolate()).empty_function_scope_info_handle();
Node* const exception = Parameter(Type::Receiver());
Node* const context = Parameter(Type::Any());
Node* const effect = graph()->start();
......
......@@ -293,54 +293,54 @@ KNOWN_MAPS = {
("read_only_space", 0x023e9): (88, "EnumCacheMap"),
("read_only_space", 0x02489): (83, "ArrayBoilerplateDescriptionMap"),
("read_only_space", 0x02679): (91, "InterceptorInfoMap"),
("read_only_space", 0x04e59): (78, "AccessCheckInfoMap"),
("read_only_space", 0x04ea9): (79, "AccessorInfoMap"),
("read_only_space", 0x04ef9): (80, "AccessorPairMap"),
("read_only_space", 0x04f49): (81, "AliasedArgumentsEntryMap"),
("read_only_space", 0x04f99): (82, "AllocationMementoMap"),
("read_only_space", 0x04fe9): (84, "AsmWasmDataMap"),
("read_only_space", 0x05039): (85, "AsyncGeneratorRequestMap"),
("read_only_space", 0x05089): (86, "ClassPositionsMap"),
("read_only_space", 0x050d9): (87, "DebugInfoMap"),
("read_only_space", 0x05129): (89, "FunctionTemplateInfoMap"),
("read_only_space", 0x05179): (90, "FunctionTemplateRareDataMap"),
("read_only_space", 0x051c9): (92, "InterpreterDataMap"),
("read_only_space", 0x05219): (93, "ObjectTemplateInfoMap"),
("read_only_space", 0x05269): (94, "PromiseCapabilityMap"),
("read_only_space", 0x052b9): (95, "PromiseReactionMap"),
("read_only_space", 0x05309): (96, "PrototypeInfoMap"),
("read_only_space", 0x05359): (97, "ScriptMap"),
("read_only_space", 0x053a9): (98, "SourcePositionTableWithFrameCacheMap"),
("read_only_space", 0x053f9): (99, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x05449): (100, "StackFrameInfoMap"),
("read_only_space", 0x05499): (101, "StackTraceFrameMap"),
("read_only_space", 0x054e9): (102, "TemplateObjectDescriptionMap"),
("read_only_space", 0x05539): (103, "Tuple2Map"),
("read_only_space", 0x05589): (104, "Tuple3Map"),
("read_only_space", 0x055d9): (105, "WasmCapiFunctionDataMap"),
("read_only_space", 0x05629): (106, "WasmDebugInfoMap"),
("read_only_space", 0x05679): (107, "WasmExceptionTagMap"),
("read_only_space", 0x056c9): (108, "WasmExportedFunctionDataMap"),
("read_only_space", 0x05719): (109, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x05769): (110, "WasmJSFunctionDataMap"),
("read_only_space", 0x057b9): (111, "CallableTaskMap"),
("read_only_space", 0x05809): (112, "CallbackTaskMap"),
("read_only_space", 0x05859): (113, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x058a9): (114, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x058f9): (115, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x05949): (116, "InternalClassMap"),
("read_only_space", 0x05999): (117, "SmiPairMap"),
("read_only_space", 0x059e9): (118, "SmiBoxMap"),
("read_only_space", 0x05a39): (119, "SortStateMap"),
("read_only_space", 0x05a89): (122, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05ad9): (122, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x05b29): (157, "LoadHandler1Map"),
("read_only_space", 0x05b79): (157, "LoadHandler2Map"),
("read_only_space", 0x05bc9): (157, "LoadHandler3Map"),
("read_only_space", 0x05c19): (165, "StoreHandler0Map"),
("read_only_space", 0x05c69): (165, "StoreHandler1Map"),
("read_only_space", 0x05cb9): (165, "StoreHandler2Map"),
("read_only_space", 0x05d09): (165, "StoreHandler3Map"),
("read_only_space", 0x04ef9): (78, "AccessCheckInfoMap"),
("read_only_space", 0x04f49): (79, "AccessorInfoMap"),
("read_only_space", 0x04f99): (80, "AccessorPairMap"),
("read_only_space", 0x04fe9): (81, "AliasedArgumentsEntryMap"),
("read_only_space", 0x05039): (82, "AllocationMementoMap"),
("read_only_space", 0x05089): (84, "AsmWasmDataMap"),
("read_only_space", 0x050d9): (85, "AsyncGeneratorRequestMap"),
("read_only_space", 0x05129): (86, "ClassPositionsMap"),
("read_only_space", 0x05179): (87, "DebugInfoMap"),
("read_only_space", 0x051c9): (89, "FunctionTemplateInfoMap"),
("read_only_space", 0x05219): (90, "FunctionTemplateRareDataMap"),
("read_only_space", 0x05269): (92, "InterpreterDataMap"),
("read_only_space", 0x052b9): (93, "ObjectTemplateInfoMap"),
("read_only_space", 0x05309): (94, "PromiseCapabilityMap"),
("read_only_space", 0x05359): (95, "PromiseReactionMap"),
("read_only_space", 0x053a9): (96, "PrototypeInfoMap"),
("read_only_space", 0x053f9): (97, "ScriptMap"),
("read_only_space", 0x05449): (98, "SourcePositionTableWithFrameCacheMap"),
("read_only_space", 0x05499): (99, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x054e9): (100, "StackFrameInfoMap"),
("read_only_space", 0x05539): (101, "StackTraceFrameMap"),
("read_only_space", 0x05589): (102, "TemplateObjectDescriptionMap"),
("read_only_space", 0x055d9): (103, "Tuple2Map"),
("read_only_space", 0x05629): (104, "Tuple3Map"),
("read_only_space", 0x05679): (105, "WasmCapiFunctionDataMap"),
("read_only_space", 0x056c9): (106, "WasmDebugInfoMap"),
("read_only_space", 0x05719): (107, "WasmExceptionTagMap"),
("read_only_space", 0x05769): (108, "WasmExportedFunctionDataMap"),
("read_only_space", 0x057b9): (109, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x05809): (110, "WasmJSFunctionDataMap"),
("read_only_space", 0x05859): (111, "CallableTaskMap"),
("read_only_space", 0x058a9): (112, "CallbackTaskMap"),
("read_only_space", 0x058f9): (113, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x05949): (114, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x05999): (115, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x059e9): (116, "InternalClassMap"),
("read_only_space", 0x05a39): (117, "SmiPairMap"),
("read_only_space", 0x05a89): (118, "SmiBoxMap"),
("read_only_space", 0x05ad9): (119, "SortStateMap"),
("read_only_space", 0x05b29): (122, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05b79): (122, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x05bc9): (157, "LoadHandler1Map"),
("read_only_space", 0x05c19): (157, "LoadHandler2Map"),
("read_only_space", 0x05c69): (157, "LoadHandler3Map"),
("read_only_space", 0x05cb9): (165, "StoreHandler0Map"),
("read_only_space", 0x05d09): (165, "StoreHandler1Map"),
("read_only_space", 0x05d59): (165, "StoreHandler2Map"),
("read_only_space", 0x05da9): (165, "StoreHandler3Map"),
("map_space", 0x00111): (1057, "ExternalMap"),
("map_space", 0x00161): (1073, "JSMessageObjectMap"),
}
......@@ -387,7 +387,9 @@ KNOWN_OBJECTS = {
("read_only_space", 0x02769): "OffHeapTrampolineRelocationInfo",
("read_only_space", 0x02781): "TrampolineTrivialCodeDataContainer",
("read_only_space", 0x02799): "TrampolinePromiseRejectionCodeDataContainer",
("read_only_space", 0x027b1): "HashSeed",
("read_only_space", 0x027b1): "GlobalThisBindingScopeInfo",
("read_only_space", 0x02819): "EmptyFunctionScopeInfo",
("read_only_space", 0x02869): "HashSeed",
("old_space", 0x00111): "ArgumentsIteratorAccessor",
("old_space", 0x00181): "ArrayLengthAccessor",
("old_space", 0x001f1): "BoundFunctionLengthAccessor",
......
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