Commit dbd2ec3a authored by Victor Gomes's avatar Victor Gomes Committed by Commit Bot

[runtime] Creates a global/read-only ScopeInfo for NativeContext

The native context used an empty function scope info. This is inconsistent with the fact the native context has an extension slot, since the empty function scope info doesn't have the extension slot flag set.

This CL creates a scope info dedicated for the native context with the flag set.

Bug: v8:9744
Change-Id: I00459e9a0ca75dd7a0e2add5e9e61747d0635f39
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1876821
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64550}
parent 9d8f4ded
...@@ -811,6 +811,10 @@ void Heap::CreateInitialObjects() { ...@@ -811,6 +811,10 @@ void Heap::CreateInitialObjects() {
ScopeInfo::CreateForEmptyFunction(isolate()); ScopeInfo::CreateForEmptyFunction(isolate());
set_empty_function_scope_info(*empty_function); set_empty_function_scope_info(*empty_function);
Handle<ScopeInfo> native_scope_info =
ScopeInfo::CreateForNativeContext(isolate());
set_native_scope_info(*native_scope_info);
// Allocate the empty script. // Allocate the empty script.
Handle<Script> script = factory->NewScript(factory->empty_string()); Handle<Script> script = factory->NewScript(factory->empty_string());
script->set_type(Script::TYPE_NATIVE); script->set_type(Script::TYPE_NATIVE);
......
...@@ -1413,8 +1413,9 @@ void InstallMakeError(Isolate* isolate, int builtin_id, int context_index) { ...@@ -1413,8 +1413,9 @@ void InstallMakeError(Isolate* isolate, int builtin_id, int context_index) {
void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> empty_function) { Handle<JSFunction> empty_function) {
// --- N a t i v e C o n t e x t --- // --- N a t i v e C o n t e x t ---
// Use the empty scope info. // Use the native scope info.
native_context()->set_scope_info(empty_function->shared().scope_info()); native_context()->set_scope_info(
ReadOnlyRoots(isolate()).native_scope_info());
native_context()->set_previous(Context()); native_context()->set_previous(Context());
// Set extension and global object. // Set extension and global object.
native_context()->set_extension(*global_object); native_context()->set_extension(*global_object);
......
...@@ -422,23 +422,29 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope( ...@@ -422,23 +422,29 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
// static // static
Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) {
return CreateForBootstrapping(isolate, SCRIPT_SCOPE); return CreateForBootstrapping(isolate, BootstrappingType::kScript);
} }
// static // static
Handle<ScopeInfo> ScopeInfo::CreateForEmptyFunction(Isolate* isolate) { Handle<ScopeInfo> ScopeInfo::CreateForEmptyFunction(Isolate* isolate) {
return CreateForBootstrapping(isolate, FUNCTION_SCOPE); return CreateForBootstrapping(isolate, BootstrappingType::kFunction);
} }
// static // static
Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate, Handle<ScopeInfo> ScopeInfo::CreateForNativeContext(Isolate* isolate) {
ScopeType type) { return CreateForBootstrapping(isolate, BootstrappingType::kNative);
DCHECK(type == SCRIPT_SCOPE || type == FUNCTION_SCOPE); }
// static
Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
BootstrappingType type) {
const int parameter_count = 0; const int parameter_count = 0;
const bool is_empty_function = type == FUNCTION_SCOPE; const bool is_empty_function = type == BootstrappingType::kFunction;
const int context_local_count = is_empty_function ? 0 : 1; const bool is_native_context = type == BootstrappingType::kNative;
const bool has_receiver = !is_empty_function; const bool is_script = type == BootstrappingType::kScript;
const int context_local_count =
is_empty_function || is_native_context ? 0 : 1;
const bool has_receiver = is_script;
const bool has_inferred_function_name = is_empty_function; const bool has_inferred_function_name = is_empty_function;
const bool has_position_info = true; const bool has_position_info = true;
const int length = kVariablePartIndex + 2 * context_local_count + const int length = kVariablePartIndex + 2 * context_local_count +
...@@ -452,25 +458,26 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate, ...@@ -452,25 +458,26 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
factory->NewScopeInfo(length, AllocationType::kReadOnly); factory->NewScopeInfo(length, AllocationType::kReadOnly);
// Encode the flags. // Encode the flags.
int flags = int flags = ScopeTypeField::encode(is_empty_function ? FUNCTION_SCOPE
ScopeTypeField::encode(type) | : SCRIPT_SCOPE) |
SloppyEvalCanExtendVarsField::encode(false) | SloppyEvalCanExtendVarsField::encode(false) |
LanguageModeField::encode(LanguageMode::kSloppy) | LanguageModeField::encode(LanguageMode::kSloppy) |
DeclarationScopeField::encode(true) | DeclarationScopeField::encode(true) |
ReceiverVariableField::encode(is_empty_function ? UNUSED : CONTEXT) | ReceiverVariableField::encode(is_script ? CONTEXT : UNUSED) |
HasClassBrandField::encode(false) | HasClassBrandField::encode(false) |
HasSavedClassVariableIndexField::encode(false) | HasSavedClassVariableIndexField::encode(false) |
HasNewTargetField::encode(false) | HasNewTargetField::encode(false) |
FunctionVariableField::encode(is_empty_function ? UNUSED : NONE) | FunctionVariableField::encode(is_empty_function ? UNUSED : NONE) |
HasInferredFunctionNameField::encode(has_inferred_function_name) | HasInferredFunctionNameField::encode(has_inferred_function_name) |
IsAsmModuleField::encode(false) | HasSimpleParametersField::encode(true) | IsAsmModuleField::encode(false) |
FunctionKindField::encode(FunctionKind::kNormalFunction) | HasSimpleParametersField::encode(true) |
HasOuterScopeInfoField::encode(false) | FunctionKindField::encode(FunctionKind::kNormalFunction) |
IsDebugEvaluateScopeField::encode(false) | HasOuterScopeInfoField::encode(false) |
ForceContextAllocationField::encode(false) | IsDebugEvaluateScopeField::encode(false) |
PrivateNameLookupSkipsOuterClassField::encode(false) | ForceContextAllocationField::encode(false) |
CanElideThisHoleChecksField::encode(false) | PrivateNameLookupSkipsOuterClassField::encode(false) |
HasContextExtensionField::encode(false); CanElideThisHoleChecksField::encode(false) |
HasContextExtensionField::encode(is_native_context);
scope_info->SetFlags(flags); scope_info->SetFlags(flags);
scope_info->SetParameterCount(parameter_count); scope_info->SetParameterCount(parameter_count);
scope_info->SetContextLocalCount(context_local_count); scope_info->SetContextLocalCount(context_local_count);
...@@ -483,7 +490,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate, ...@@ -483,7 +490,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
scope_info->set(index++, ReadOnlyRoots(isolate).this_string()); scope_info->set(index++, ReadOnlyRoots(isolate).this_string());
} }
DCHECK_EQ(index, scope_info->ContextLocalInfosIndex()); DCHECK_EQ(index, scope_info->ContextLocalInfosIndex());
if (context_local_count) { if (context_local_count > 0) {
const uint32_t value = const uint32_t value =
VariableModeField::encode(VariableMode::kConst) | VariableModeField::encode(VariableMode::kConst) |
InitFlagField::encode(kCreatedInitialized) | InitFlagField::encode(kCreatedInitialized) |
...@@ -495,8 +502,8 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate, ...@@ -495,8 +502,8 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
// And here we record that this scopeinfo binds a receiver. // And here we record that this scopeinfo binds a receiver.
DCHECK_EQ(index, scope_info->ReceiverInfoIndex()); DCHECK_EQ(index, scope_info->ReceiverInfoIndex());
const int receiver_index = scope_info->ContextHeaderLength(); if (has_receiver) {
if (!is_empty_function) { const int receiver_index = scope_info->ContextHeaderLength();
scope_info->set(index++, Smi::FromInt(receiver_index)); scope_info->set(index++, Smi::FromInt(receiver_index));
} }
...@@ -516,7 +523,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate, ...@@ -516,7 +523,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
DCHECK_EQ(index, scope_info->OuterScopeInfoIndex()); DCHECK_EQ(index, scope_info->OuterScopeInfoIndex());
DCHECK_EQ(index, scope_info->length()); DCHECK_EQ(index, scope_info->length());
DCHECK_EQ(scope_info->ParameterCount(), parameter_count); DCHECK_EQ(scope_info->ParameterCount(), parameter_count);
if (type == FUNCTION_SCOPE) { if (is_empty_function || is_native_context) {
DCHECK_EQ(scope_info->ContextLength(), 0); DCHECK_EQ(scope_info->ContextLength(), 0);
} else { } else {
DCHECK_EQ(scope_info->ContextLength(), DCHECK_EQ(scope_info->ContextLength(),
...@@ -685,6 +692,7 @@ Object ScopeInfo::InferredFunctionName() const { ...@@ -685,6 +692,7 @@ Object ScopeInfo::InferredFunctionName() const {
} }
String ScopeInfo::FunctionDebugName() const { String ScopeInfo::FunctionDebugName() const {
if (!HasFunctionName()) return GetReadOnlyRoots().empty_string();
Object name = FunctionName(); Object name = FunctionName();
if (name.IsString() && String::cast(name).length() > 0) { if (name.IsString() && String::cast(name).length() > 0) {
return String::cast(name); return String::cast(name);
......
...@@ -209,6 +209,7 @@ class ScopeInfo : public FixedArray { ...@@ -209,6 +209,7 @@ class ScopeInfo : public FixedArray {
Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope); Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope);
V8_EXPORT_PRIVATE static Handle<ScopeInfo> CreateForEmptyFunction( V8_EXPORT_PRIVATE static Handle<ScopeInfo> CreateForEmptyFunction(
Isolate* isolate); Isolate* isolate);
static Handle<ScopeInfo> CreateForNativeContext(Isolate* isolate);
static Handle<ScopeInfo> CreateGlobalThisBinding(Isolate* isolate); static Handle<ScopeInfo> CreateGlobalThisBinding(Isolate* isolate);
// Serializes empty scope info. // Serializes empty scope info.
...@@ -323,8 +324,10 @@ class ScopeInfo : public FixedArray { ...@@ -323,8 +324,10 @@ class ScopeInfo : public FixedArray {
int ModuleVariablesIndex() const; int ModuleVariablesIndex() const;
static bool NeedsPositionInfo(ScopeType type); static bool NeedsPositionInfo(ScopeType type);
enum class BootstrappingType { kScript, kFunction, kNative };
static Handle<ScopeInfo> CreateForBootstrapping(Isolate* isolate, static Handle<ScopeInfo> CreateForBootstrapping(Isolate* isolate,
ScopeType type); BootstrappingType type);
int Lookup(Handle<String> name, int start, int end, VariableMode* mode, int Lookup(Handle<String> name, int start, int end, VariableMode* mode,
VariableLocation* location, InitializationFlag* init_flag, VariableLocation* location, InitializationFlag* init_flag,
......
...@@ -189,6 +189,7 @@ class Symbol; ...@@ -189,6 +189,7 @@ class Symbol;
/* Canonical scope infos */ \ /* Canonical scope infos */ \
V(ScopeInfo, global_this_binding_scope_info, GlobalThisBindingScopeInfo) \ V(ScopeInfo, global_this_binding_scope_info, GlobalThisBindingScopeInfo) \
V(ScopeInfo, empty_function_scope_info, EmptyFunctionScopeInfo) \ V(ScopeInfo, empty_function_scope_info, EmptyFunctionScopeInfo) \
V(ScopeInfo, native_scope_info, NativeScopeInfo) \
/* Hash seed */ \ /* Hash seed */ \
V(ByteArray, hash_seed, HashSeed) V(ByteArray, hash_seed, HashSeed)
......
...@@ -280,54 +280,54 @@ KNOWN_MAPS = { ...@@ -280,54 +280,54 @@ KNOWN_MAPS = {
("read_only_space", 0x02031): (94, "EnumCacheMap"), ("read_only_space", 0x02031): (94, "EnumCacheMap"),
("read_only_space", 0x020d1): (88, "ArrayBoilerplateDescriptionMap"), ("read_only_space", 0x020d1): (88, "ArrayBoilerplateDescriptionMap"),
("read_only_space", 0x022c1): (97, "InterceptorInfoMap"), ("read_only_space", 0x022c1): (97, "InterceptorInfoMap"),
("read_only_space", 0x04c01): (71, "PromiseFulfillReactionJobTaskMap"), ("read_only_space", 0x04c39): (71, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x04c51): (72, "PromiseRejectReactionJobTaskMap"), ("read_only_space", 0x04c89): (72, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x04ca1): (73, "CallableTaskMap"), ("read_only_space", 0x04cd9): (73, "CallableTaskMap"),
("read_only_space", 0x04cf1): (74, "CallbackTaskMap"), ("read_only_space", 0x04d29): (74, "CallbackTaskMap"),
("read_only_space", 0x04d41): (75, "PromiseResolveThenableJobTaskMap"), ("read_only_space", 0x04d79): (75, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x04d91): (78, "FunctionTemplateInfoMap"), ("read_only_space", 0x04dc9): (78, "FunctionTemplateInfoMap"),
("read_only_space", 0x04de1): (79, "ObjectTemplateInfoMap"), ("read_only_space", 0x04e19): (79, "ObjectTemplateInfoMap"),
("read_only_space", 0x04e31): (80, "Tuple2Map"), ("read_only_space", 0x04e69): (80, "Tuple2Map"),
("read_only_space", 0x04e81): (81, "Tuple3Map"), ("read_only_space", 0x04eb9): (81, "Tuple3Map"),
("read_only_space", 0x04ed1): (82, "AccessCheckInfoMap"), ("read_only_space", 0x04f09): (82, "AccessCheckInfoMap"),
("read_only_space", 0x04f21): (83, "AccessorInfoMap"), ("read_only_space", 0x04f59): (83, "AccessorInfoMap"),
("read_only_space", 0x04f71): (84, "AccessorPairMap"), ("read_only_space", 0x04fa9): (84, "AccessorPairMap"),
("read_only_space", 0x04fc1): (85, "AliasedArgumentsEntryMap"), ("read_only_space", 0x04ff9): (85, "AliasedArgumentsEntryMap"),
("read_only_space", 0x05011): (86, "AllocationMementoMap"), ("read_only_space", 0x05049): (86, "AllocationMementoMap"),
("read_only_space", 0x05061): (89, "AsmWasmDataMap"), ("read_only_space", 0x05099): (89, "AsmWasmDataMap"),
("read_only_space", 0x050b1): (90, "AsyncGeneratorRequestMap"), ("read_only_space", 0x050e9): (90, "AsyncGeneratorRequestMap"),
("read_only_space", 0x05101): (92, "ClassPositionsMap"), ("read_only_space", 0x05139): (92, "ClassPositionsMap"),
("read_only_space", 0x05151): (93, "DebugInfoMap"), ("read_only_space", 0x05189): (93, "DebugInfoMap"),
("read_only_space", 0x051a1): (96, "FunctionTemplateRareDataMap"), ("read_only_space", 0x051d9): (96, "FunctionTemplateRareDataMap"),
("read_only_space", 0x051f1): (99, "InterpreterDataMap"), ("read_only_space", 0x05229): (99, "InterpreterDataMap"),
("read_only_space", 0x05241): (100, "PromiseCapabilityMap"), ("read_only_space", 0x05279): (100, "PromiseCapabilityMap"),
("read_only_space", 0x05291): (101, "PromiseReactionMap"), ("read_only_space", 0x052c9): (101, "PromiseReactionMap"),
("read_only_space", 0x052e1): (102, "PrototypeInfoMap"), ("read_only_space", 0x05319): (102, "PrototypeInfoMap"),
("read_only_space", 0x05331): (103, "ScriptMap"), ("read_only_space", 0x05369): (103, "ScriptMap"),
("read_only_space", 0x05381): (107, "SourcePositionTableWithFrameCacheMap"), ("read_only_space", 0x053b9): (107, "SourcePositionTableWithFrameCacheMap"),
("read_only_space", 0x053d1): (108, "SourceTextModuleInfoEntryMap"), ("read_only_space", 0x05409): (108, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x05421): (109, "StackFrameInfoMap"), ("read_only_space", 0x05459): (109, "StackFrameInfoMap"),
("read_only_space", 0x05471): (110, "StackTraceFrameMap"), ("read_only_space", 0x054a9): (110, "StackTraceFrameMap"),
("read_only_space", 0x054c1): (111, "TemplateObjectDescriptionMap"), ("read_only_space", 0x054f9): (111, "TemplateObjectDescriptionMap"),
("read_only_space", 0x05511): (112, "WasmCapiFunctionDataMap"), ("read_only_space", 0x05549): (112, "WasmCapiFunctionDataMap"),
("read_only_space", 0x05561): (113, "WasmDebugInfoMap"), ("read_only_space", 0x05599): (113, "WasmDebugInfoMap"),
("read_only_space", 0x055b1): (114, "WasmExceptionTagMap"), ("read_only_space", 0x055e9): (114, "WasmExceptionTagMap"),
("read_only_space", 0x05601): (115, "WasmExportedFunctionDataMap"), ("read_only_space", 0x05639): (115, "WasmExportedFunctionDataMap"),
("read_only_space", 0x05651): (116, "WasmIndirectFunctionTableMap"), ("read_only_space", 0x05689): (116, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x056a1): (117, "WasmJSFunctionDataMap"), ("read_only_space", 0x056d9): (117, "WasmJSFunctionDataMap"),
("read_only_space", 0x056f1): (98, "InternalClassMap"), ("read_only_space", 0x05729): (98, "InternalClassMap"),
("read_only_space", 0x05741): (105, "SmiPairMap"), ("read_only_space", 0x05779): (105, "SmiPairMap"),
("read_only_space", 0x05791): (104, "SmiBoxMap"), ("read_only_space", 0x057c9): (104, "SmiBoxMap"),
("read_only_space", 0x057e1): (106, "SortStateMap"), ("read_only_space", 0x05819): (106, "SortStateMap"),
("read_only_space", 0x05831): (87, "AllocationSiteWithWeakNextMap"), ("read_only_space", 0x05869): (87, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05881): (87, "AllocationSiteWithoutWeakNextMap"), ("read_only_space", 0x058b9): (87, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x058d1): (76, "LoadHandler1Map"), ("read_only_space", 0x05909): (76, "LoadHandler1Map"),
("read_only_space", 0x05921): (76, "LoadHandler2Map"), ("read_only_space", 0x05959): (76, "LoadHandler2Map"),
("read_only_space", 0x05971): (76, "LoadHandler3Map"), ("read_only_space", 0x059a9): (76, "LoadHandler3Map"),
("read_only_space", 0x059c1): (77, "StoreHandler0Map"), ("read_only_space", 0x059f9): (77, "StoreHandler0Map"),
("read_only_space", 0x05a11): (77, "StoreHandler1Map"), ("read_only_space", 0x05a49): (77, "StoreHandler1Map"),
("read_only_space", 0x05a61): (77, "StoreHandler2Map"), ("read_only_space", 0x05a99): (77, "StoreHandler2Map"),
("read_only_space", 0x05ab1): (77, "StoreHandler3Map"), ("read_only_space", 0x05ae9): (77, "StoreHandler3Map"),
("map_space", 0x00119): (1057, "ExternalMap"), ("map_space", 0x00119): (1057, "ExternalMap"),
("map_space", 0x00169): (1072, "JSMessageObjectMap"), ("map_space", 0x00169): (1072, "JSMessageObjectMap"),
} }
...@@ -376,7 +376,8 @@ KNOWN_OBJECTS = { ...@@ -376,7 +376,8 @@ KNOWN_OBJECTS = {
("read_only_space", 0x023e1): "TrampolinePromiseRejectionCodeDataContainer", ("read_only_space", 0x023e1): "TrampolinePromiseRejectionCodeDataContainer",
("read_only_space", 0x023f9): "GlobalThisBindingScopeInfo", ("read_only_space", 0x023f9): "GlobalThisBindingScopeInfo",
("read_only_space", 0x02461): "EmptyFunctionScopeInfo", ("read_only_space", 0x02461): "EmptyFunctionScopeInfo",
("read_only_space", 0x024b1): "HashSeed", ("read_only_space", 0x024b1): "NativeScopeInfo",
("read_only_space", 0x024e9): "HashSeed",
("old_space", 0x00119): "ArgumentsIteratorAccessor", ("old_space", 0x00119): "ArgumentsIteratorAccessor",
("old_space", 0x00189): "ArrayLengthAccessor", ("old_space", 0x00189): "ArrayLengthAccessor",
("old_space", 0x001f9): "BoundFunctionLengthAccessor", ("old_space", 0x001f9): "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