[offthread] Add off-thread scope allocation

Make Scope allocation and ScopeInfo creation Isolate-templated. This
includes making SourceTextModuleInfo allocation templated -- modules
aren't currently streamed off-thread, but will hopefully be in the
future, so this future-proofs them against that.

Bug: chromium:1011762
Change-Id: I8954e08e8e81489eb821b5f62ec35a5be31fce09
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2043790
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66197}
This commit is contained in:
Leszek Swirski 2020-02-10 12:04:30 +01:00 committed by Commit Bot
parent 7a410e739b
commit 5f6384622f
16 changed files with 198 additions and 103 deletions

View File

@ -5,6 +5,7 @@
#include "src/ast/modules.h"
#include "src/ast/ast-value-factory.h"
#include "src/ast/scopes.h"
#include "src/heap/off-thread-factory-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/objects-inl.h"
#include "src/parsing/pending-compilation-error-handler.h"
@ -84,17 +85,17 @@ void SourceTextModuleDescriptor::AddStarExport(
}
namespace {
Handle<PrimitiveHeapObject> ToStringOrUndefined(Isolate* isolate,
const AstRawString* s) {
return (s == nullptr)
? Handle<PrimitiveHeapObject>::cast(
isolate->factory()->undefined_value())
: Handle<PrimitiveHeapObject>::cast(s->string().get<Isolate>());
template <typename Isolate>
HandleFor<Isolate, PrimitiveHeapObject> ToStringOrUndefined(
Isolate* isolate, const AstRawString* s) {
if (s == nullptr) return isolate->factory()->undefined_value();
return s->string();
}
} // namespace
Handle<SourceTextModuleInfoEntry> SourceTextModuleDescriptor::Entry::Serialize(
Isolate* isolate) const {
template <typename Isolate>
HandleFor<Isolate, SourceTextModuleInfoEntry>
SourceTextModuleDescriptor::Entry::Serialize(Isolate* isolate) const {
CHECK(Smi::IsValid(module_request)); // TODO(neis): Check earlier?
return SourceTextModuleInfoEntry::New(
isolate, ToStringOrUndefined(isolate, export_name),
@ -102,14 +103,20 @@ Handle<SourceTextModuleInfoEntry> SourceTextModuleDescriptor::Entry::Serialize(
ToStringOrUndefined(isolate, import_name), module_request, cell_index,
location.beg_pos, location.end_pos);
}
template Handle<SourceTextModuleInfoEntry>
SourceTextModuleDescriptor::Entry::Serialize(Isolate* isolate) const;
template OffThreadHandle<SourceTextModuleInfoEntry>
SourceTextModuleDescriptor::Entry::Serialize(OffThreadIsolate* isolate) const;
Handle<FixedArray> SourceTextModuleDescriptor::SerializeRegularExports(
Isolate* isolate, Zone* zone) const {
template <typename Isolate>
HandleFor<Isolate, FixedArray>
SourceTextModuleDescriptor::SerializeRegularExports(Isolate* isolate,
Zone* zone) const {
// We serialize regular exports in a way that lets us later iterate over their
// local names and for each local name immediately access all its export
// names. (Regular exports have neither import name nor module request.)
ZoneVector<Handle<Object>> data(
ZoneVector<HandleFor<Isolate, Object>> data(
SourceTextModuleInfo::kRegularExportLength * regular_exports_.size(),
zone);
int index = 0;
@ -125,7 +132,8 @@ Handle<FixedArray> SourceTextModuleDescriptor::SerializeRegularExports(
++count;
} while (next != regular_exports_.end() && next->first == it->first);
Handle<FixedArray> export_names = isolate->factory()->NewFixedArray(count);
HandleFor<Isolate, FixedArray> export_names =
isolate->factory()->NewFixedArray(count);
data[index + SourceTextModuleInfo::kRegularExportLocalNameOffset] =
it->second->local_name->string();
data[index + SourceTextModuleInfo::kRegularExportCellIndexOffset] =
@ -149,12 +157,18 @@ Handle<FixedArray> SourceTextModuleDescriptor::SerializeRegularExports(
// We cannot create the FixedArray earlier because we only now know the
// precise size.
Handle<FixedArray> result = isolate->factory()->NewFixedArray(index);
HandleFor<Isolate, FixedArray> result =
isolate->factory()->NewFixedArray(index);
for (int i = 0; i < index; ++i) {
result->set(i, *data[i]);
}
return result;
}
template Handle<FixedArray> SourceTextModuleDescriptor::SerializeRegularExports(
Isolate* isolate, Zone* zone) const;
template OffThreadHandle<FixedArray>
SourceTextModuleDescriptor::SerializeRegularExports(OffThreadIsolate* isolate,
Zone* zone) const;
void SourceTextModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) {
for (auto it = regular_exports_.begin(); it != regular_exports_.end();) {

View File

@ -5,6 +5,7 @@
#ifndef V8_AST_MODULES_H_
#define V8_AST_MODULES_H_
#include "src/handles/handle-for.h"
#include "src/parsing/scanner.h" // Only for Scanner::Location.
#include "src/zone/zone-containers.h"
@ -107,7 +108,9 @@ class SourceTextModuleDescriptor : public ZoneObject {
module_request(-1),
cell_index(0) {}
Handle<SourceTextModuleInfoEntry> Serialize(Isolate* isolate) const;
template <typename Isolate>
HandleFor<Isolate, SourceTextModuleInfoEntry> Serialize(
Isolate* isolate) const;
};
enum CellIndexKind { kInvalid, kExport, kImport };
@ -184,8 +187,9 @@ class SourceTextModuleDescriptor : public ZoneObject {
namespace_imports_.push_back(entry);
}
Handle<FixedArray> SerializeRegularExports(Isolate* isolate,
Zone* zone) const;
template <typename Isolate>
HandleFor<Isolate, FixedArray> SerializeRegularExports(Isolate* isolate,
Zone* zone) const;
private:
ModuleRequestMap module_requests_;

View File

@ -11,6 +11,7 @@
#include "src/base/optional.h"
#include "src/builtins/accessors.h"
#include "src/common/message-template.h"
#include "src/heap/off-thread-factory-inl.h"
#include "src/init/bootstrapper.h"
#include "src/logging/counters.h"
#include "src/objects/module-inl.h"
@ -835,7 +836,8 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name, Scope* cache) {
DCHECK_NULL(cache->variables_.Lookup(name));
DisallowHeapAllocation no_gc;
String name_handle = *name->string().get<Isolate>();
String name_handle = *name->string().get_handle();
ScopeInfo scope_info = *scope_info_.get_handle();
// The Scope is backed up by ScopeInfo. This means it cannot operate in a
// heap-independent mode, and all strings must be internalized immediately. So
// it's ok to get the Handle<String> here.
@ -850,21 +852,21 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name, Scope* cache) {
{
location = VariableLocation::CONTEXT;
index = ScopeInfo::ContextSlotIndex(*scope_info_, name_handle, &mode,
&init_flag, &maybe_assigned_flag,
&is_static_flag);
index =
ScopeInfo::ContextSlotIndex(scope_info, name_handle, &mode, &init_flag,
&maybe_assigned_flag, &is_static_flag);
found = index >= 0;
}
if (!found && is_module_scope()) {
location = VariableLocation::MODULE;
index = scope_info_->ModuleIndex(name_handle, &mode, &init_flag,
&maybe_assigned_flag);
index = scope_info.ModuleIndex(name_handle, &mode, &init_flag,
&maybe_assigned_flag);
found = index != 0;
}
if (!found) {
index = scope_info_->FunctionContextSlotIndex(name_handle);
index = scope_info.FunctionContextSlotIndex(name_handle);
if (index < 0) return nullptr; // Nowhere found.
Variable* var = AsDeclarationScope()->DeclareFunctionVar(name, cache);
DCHECK_EQ(VariableMode::kConst, var->mode());
@ -873,7 +875,7 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name, Scope* cache) {
}
if (!is_module_scope()) {
DCHECK_NE(index, scope_info_->ReceiverContextSlotIndex());
DCHECK_NE(index, scope_info.ReceiverContextSlotIndex());
}
bool was_added;
@ -1220,7 +1222,7 @@ void DeclarationScope::DeserializeReceiver(AstValueFactory* ast_value_factory) {
receiver_->AllocateTo(VariableLocation::LOOKUP, -1);
} else {
receiver_->AllocateTo(VariableLocation::CONTEXT,
scope_info_->ReceiverContextSlotIndex());
scope_info_.get_handle()->ReceiverContextSlotIndex());
}
}
@ -2449,10 +2451,11 @@ void Scope::AllocateVariablesRecursively() {
});
}
void Scope::AllocateScopeInfosRecursively(Isolate* isolate,
MaybeHandle<ScopeInfo> outer_scope) {
template <typename Isolate>
void Scope::AllocateScopeInfosRecursively(
Isolate* isolate, MaybeHandleFor<Isolate, ScopeInfo> outer_scope) {
DCHECK(scope_info_.is_null());
MaybeHandle<ScopeInfo> next_outer_scope = outer_scope;
MaybeHandleFor<Isolate, ScopeInfo> next_outer_scope = outer_scope;
if (NeedsScopeInfo()) {
scope_info_ = ScopeInfo::Create(isolate, zone(), this, outer_scope);
@ -2470,6 +2473,13 @@ void Scope::AllocateScopeInfosRecursively(Isolate* isolate,
}
}
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope::
AllocateScopeInfosRecursively<Isolate>(Isolate* isolate,
MaybeHandle<ScopeInfo> outer_scope);
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope::
AllocateScopeInfosRecursively<OffThreadIsolate>(
OffThreadIsolate* isolate, OffThreadHandle<ScopeInfo> outer_scope);
void DeclarationScope::RecalcPrivateNameContextChain() {
// The outermost scope in a class heritage expression is marked to skip the
// class scope during private name resolution. It is possible, however, that
@ -2512,14 +2522,16 @@ void DeclarationScope::RecordNeedsPrivateNameContextChainRecalc() {
}
// static
template <typename Isolate>
void DeclarationScope::AllocateScopeInfos(ParseInfo* info, Isolate* isolate) {
DeclarationScope* scope = info->literal()->scope();
// No one else should have allocated a scope info for this scope yet.
DCHECK(scope->scope_info_.is_null());
MaybeHandle<ScopeInfo> outer_scope;
MaybeHandleFor<Isolate, ScopeInfo> outer_scope;
if (scope->outer_scope_ != nullptr) {
DCHECK((std::is_same<Isolate, v8::internal::Isolate>::value));
outer_scope = scope->outer_scope_->scope_info_;
}
@ -2540,11 +2552,15 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info, Isolate* isolate) {
// Ensuring that the outer script scope has a scope info avoids having
// special case for native contexts vs other contexts.
if (info->script_scope() && info->script_scope()->scope_info_.is_null()) {
info->script_scope()->scope_info_ =
handle(ScopeInfo::Empty(isolate), isolate);
info->script_scope()->scope_info_ = isolate->factory()->empty_scope_info();
}
}
template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos<Isolate>(
ParseInfo* info, Isolate* isolate);
template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos<
OffThreadIsolate>(ParseInfo* info, OffThreadIsolate* isolate);
int Scope::ContextLocalCount() const {
if (num_heap_slots() == 0) return 0;
Variable* function =
@ -2655,14 +2671,14 @@ Variable* ClassScope::LookupPrivateNameInScopeInfo(const AstRawString* name) {
DCHECK_NULL(LookupLocalPrivateName(name));
DisallowHeapAllocation no_gc;
String name_handle = *name->string().get<Isolate>();
String name_handle = *name->string().get_handle();
VariableMode mode;
InitializationFlag init_flag;
MaybeAssignedFlag maybe_assigned_flag;
IsStaticFlag is_static_flag;
int index =
ScopeInfo::ContextSlotIndex(*scope_info_, name_handle, &mode, &init_flag,
&maybe_assigned_flag, &is_static_flag);
int index = ScopeInfo::ContextSlotIndex(
*scope_info_.get_handle(), name_handle, &mode, &init_flag,
&maybe_assigned_flag, &is_static_flag);
if (index < 0) {
return nullptr;
}

View File

@ -11,6 +11,7 @@
#include "src/base/hashmap.h"
#include "src/base/threaded-list.h"
#include "src/common/globals.h"
#include "src/handles/handle-for.h"
#include "src/objects/function-kind.h"
#include "src/objects/objects.h"
#include "src/utils/pointer-with-payload.h"
@ -520,7 +521,7 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
bool HasThisReference() const;
// Analyze() must have been called once to create the ScopeInfo.
Handle<ScopeInfo> scope_info() const {
HandleOrOffThreadHandle<ScopeInfo> scope_info() const {
DCHECK(!scope_info_.is_null());
return scope_info_;
}
@ -670,8 +671,9 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
V8_INLINE void AllocateNonParameterLocalsAndDeclaredGlobals();
void AllocateVariablesRecursively();
void AllocateScopeInfosRecursively(Isolate* isolate,
MaybeHandle<ScopeInfo> outer_scope);
template <typename Isolate>
void AllocateScopeInfosRecursively(
Isolate* isolate, MaybeHandleFor<Isolate, ScopeInfo> outer_scope);
void AllocateDebuggerScopeInfos(Isolate* isolate,
MaybeHandle<ScopeInfo> outer_scope);
@ -691,6 +693,9 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
void SetDefaults();
void set_scope_info(Handle<ScopeInfo> scope_info);
void set_scope_info(OffThreadHandle<ScopeInfo> scope_info);
friend class DeclarationScope;
friend class ClassScope;
friend class ScopeTestHelper;
@ -718,7 +723,7 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
base::ThreadedList<Declaration> decls_;
// Serialized scope info support.
Handle<ScopeInfo> scope_info_;
HandleOrOffThreadHandle<ScopeInfo> scope_info_;
// Debugging support.
#ifdef DEBUG
const AstRawString* scope_name_;
@ -1098,7 +1103,9 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
// Allocate ScopeInfos for top scope and any inner scopes that need them.
// Does nothing if ScopeInfo is already allocated.
static void AllocateScopeInfos(ParseInfo* info, Isolate* isolate);
template <typename Isolate>
V8_EXPORT_PRIVATE static void AllocateScopeInfos(ParseInfo* info,
Isolate* isolate);
Handle<StringSet> CollectNonLocals(Isolate* isolate, ParseInfo* info,
Handle<StringSet> non_locals);

View File

@ -58,7 +58,7 @@ class Variable final : public ZoneObject {
// parameter initializers.
void set_scope(Scope* scope) { scope_ = scope; }
Handle<String> name() const { return name_->string(); }
HandleOrOffThreadHandle<String> name() const { return name_->string(); }
const AstRawString* raw_name() const { return name_; }
VariableMode mode() const { return VariableModeField::decode(bit_field_); }
void set_mode(VariableMode mode) {

View File

@ -629,6 +629,8 @@ class NewSpace;
class NewLargeObjectSpace;
class NumberDictionary;
class Object;
template <typename T>
class OffThreadHandle;
class OldLargeObjectSpace;
template <HeapObjectReferenceType kRefType, typename StorageType>
class TaggedImpl;

View File

@ -769,7 +769,7 @@ bool ScopeIterator::VisitLocals(const Visitor& visitor, Mode mode) const {
for (Variable* var : *current_scope_->locals()) {
DCHECK(!var->is_this());
if (ScopeInfo::VariableIsSynthetic(*var->name())) continue;
if (ScopeInfo::VariableIsSynthetic(*var->name().get_handle())) continue;
int index = var->index();
Handle<Object> value;

View File

@ -663,7 +663,7 @@ bool HasChangedScope(FunctionLiteral* a, FunctionLiteral* b) {
if (!var->IsContextSlot()) continue;
auto it = vars.find(var->index());
if (it == vars.end()) return true;
if (*it->second != *var->name()) return true;
if (*it->second != *var->name().get_handle()) return true;
}
scope_a = scope_a->outer_scope();
scope_b = scope_b->outer_scope();

View File

@ -11,8 +11,10 @@
#include "src/heap/off-thread-factory-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/objects/literal-objects-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/oddball.h"
#include "src/objects/shared-function-info-inl.h"
#include "src/objects/source-text-module.h"
#include "src/objects/template-objects-inl.h"
namespace v8 {
@ -349,6 +351,22 @@ HandleFor<Impl, FreshlyAllocatedBigInt> FactoryBase<Impl>::NewBigInt(
return handle(bigint, isolate());
}
template <typename Impl>
HandleFor<Impl, ScopeInfo> FactoryBase<Impl>::NewScopeInfo(
int length, AllocationType type) {
DCHECK(type == AllocationType::kOld || type == AllocationType::kReadOnly);
return HandleFor<Impl, ScopeInfo>::cast(
NewFixedArrayWithMap(read_only_roots().scope_info_map(), length, type));
}
template <typename Impl>
HandleFor<Impl, SourceTextModuleInfo>
FactoryBase<Impl>::NewSourceTextModuleInfo() {
return HandleFor<Impl, SourceTextModuleInfo>::cast(NewFixedArrayWithMap(
read_only_roots().module_info_map(), SourceTextModuleInfo::kLength,
AllocationType::kOld));
}
template <typename Impl>
HandleFor<Impl, SeqOneByteString>
FactoryBase<Impl>::AllocateRawOneByteInternalizedString(int length,

View File

@ -21,6 +21,7 @@ class FreshlyAllocatedBigInt;
class ObjectBoilerplateDescription;
class ArrayBoilerplateDescription;
class TemplateObjectDescription;
class SourceTextModuleInfo;
template <typename Impl>
class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
@ -120,6 +121,12 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
HandleFor<Impl, FreshlyAllocatedBigInt> NewBigInt(
int length, AllocationType allocation = AllocationType::kYoung);
// Create a serialized scope info.
HandleFor<Impl, ScopeInfo> NewScopeInfo(
int length, AllocationType type = AllocationType::kOld);
HandleFor<Impl, SourceTextModuleInfo> NewSourceTextModuleInfo();
protected:
// Allocate memory for an uninitialized array (e.g., a FixedArray or similar).
HeapObject AllocateRawArray(int size, AllocationType allocation);

View File

@ -2155,18 +2155,6 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
return result;
}
Handle<ScopeInfo> Factory::NewScopeInfo(int length, AllocationType type) {
DCHECK(type == AllocationType::kOld || type == AllocationType::kReadOnly);
return Handle<ScopeInfo>::cast(
NewFixedArrayWithMap(read_only_roots().scope_info_map(), length, type));
}
Handle<SourceTextModuleInfo> Factory::NewSourceTextModuleInfo() {
return Handle<SourceTextModuleInfo>::cast(NewFixedArrayWithMap(
read_only_roots().module_info_map(), SourceTextModuleInfo::kLength,
AllocationType::kOld));
}
Handle<PreparseData> Factory::NewPreparseData(int data_length,
int children_length) {
int size = PreparseData::SizeFor(data_length, children_length);

View File

@ -60,7 +60,6 @@ class PromiseResolveThenableJobTask;
class RegExpMatchInfo;
class ScriptContextTable;
class SourceTextModule;
class SourceTextModuleInfo;
class StackFrameInfo;
class StackTraceFrame;
class StoreHandler;
@ -677,12 +676,6 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
Handle<Map> map, Handle<SharedFunctionInfo> info, Handle<Context> context,
AllocationType allocation = AllocationType::kOld);
// Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length,
AllocationType type = AllocationType::kOld);
Handle<SourceTextModuleInfo> NewSourceTextModuleInfo();
Handle<PreparseData> NewPreparseData(int data_length, int children_length);
Handle<UncompiledDataWithoutPreparseData>

View File

@ -5351,7 +5351,8 @@ void SharedFunctionInfo::InitFromFunctionLiteral(
if (!is_toplevel) {
Scope* outer_scope = lit->scope()->GetOuterScopeWithContext();
if (outer_scope) {
shared_info->set_outer_scope_info(*outer_scope->scope_info());
shared_info->set_outer_scope_info(
*outer_scope->scope_info().get_handle());
shared_info->set_private_name_lookup_skips_outer_class(
lit->scope()->private_name_lookup_skips_outer_class());
}

View File

@ -12,6 +12,7 @@
#include "src/objects/module-inl.h"
#include "src/objects/objects-inl.h"
#include "src/roots/roots.h"
namespace v8 {
namespace internal {
@ -60,8 +61,10 @@ bool ScopeInfo::Equals(ScopeInfo other) const {
#endif
// static
Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
MaybeHandle<ScopeInfo> outer_scope) {
template <typename Isolate>
HandleFor<Isolate, ScopeInfo> ScopeInfo::Create(
Isolate* isolate, Zone* zone, Scope* scope,
MaybeHandleFor<Isolate, ScopeInfo> outer_scope) {
// Collect variables.
int context_local_count = 0;
int module_vars_count = 0;
@ -165,7 +168,7 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
? 2 + kModuleVariableEntryLength * module_vars_count
: 0);
Handle<ScopeInfo> scope_info_handle =
HandleFor<Isolate, ScopeInfo> scope_info_handle =
isolate->factory()->NewScopeInfo(length);
int index = kVariablePartIndex;
{
@ -239,14 +242,15 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
MaybeAssignedFlagField::encode(var->maybe_assigned()) |
ParameterNumberField::encode(ParameterNumberField::kMax) |
IsStaticFlagField::encode(var->is_static_flag());
scope_info.set(context_local_base + local_index, *var->name(), mode);
scope_info.set(context_local_base + local_index,
*var->name().get<Isolate>(), mode);
scope_info.set(context_local_info_base + local_index,
Smi::FromInt(info));
break;
}
case VariableLocation::MODULE: {
scope_info.set(module_var_entry + kModuleVariableNameOffset,
*var->name(), mode);
*var->name().get<Isolate>(), mode);
scope_info.set(module_var_entry + kModuleVariableIndexOffset,
Smi::FromInt(var->index()));
uint32_t properties =
@ -294,7 +298,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
MaybeAssignedFlagField::encode(var->maybe_assigned()) |
ParameterNumberField::encode(ParameterNumberField::kMax) |
IsStaticFlagField::encode(var->is_static_flag());
scope_info.set(context_local_base + local_index, *var->name(), mode);
scope_info.set(context_local_base + local_index,
*var->name().get<Isolate>(), mode);
scope_info.set(context_local_info_base + local_index,
Smi::FromInt(info));
}
@ -330,7 +335,7 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
Object name = Smi::zero();
if (var != nullptr) {
var_index = var->index();
name = *var->name();
name = *var->name().get<Isolate>();
}
scope_info.set(index++, name, mode);
scope_info.set(index++, Smi::FromInt(var_index));
@ -359,8 +364,9 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
// Module-specific information (only for module scopes).
if (scope->is_module_scope()) {
Handle<SourceTextModuleInfo> module_info = SourceTextModuleInfo::New(
isolate, zone, scope->AsModuleScope()->module());
HandleFor<Isolate, SourceTextModuleInfo> module_info =
SourceTextModuleInfo::New(isolate, zone,
scope->AsModuleScope()->module());
DCHECK_EQ(index, scope_info_handle->ModuleInfoIndex());
scope_info_handle->set(index++, *module_info);
DCHECK_EQ(index, scope_info_handle->ModuleVariableCountIndex());
@ -376,6 +382,15 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
return scope_info_handle;
}
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE)
Handle<ScopeInfo> ScopeInfo::Create<Isolate>(
Isolate* isolate, Zone* zone, Scope* scope,
MaybeHandle<ScopeInfo> outer_scope);
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE)
OffThreadHandle<ScopeInfo> ScopeInfo::Create<OffThreadIsolate>(
OffThreadIsolate* isolate, Zone* zone, Scope* scope,
OffThreadHandle<ScopeInfo> outer_scope);
// static
Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope) {
@ -1031,14 +1046,16 @@ std::ostream& operator<<(std::ostream& os, VariableAllocationInfo var_info) {
return os;
}
Handle<SourceTextModuleInfoEntry> SourceTextModuleInfoEntry::New(
Isolate* isolate, Handle<PrimitiveHeapObject> export_name,
Handle<PrimitiveHeapObject> local_name,
Handle<PrimitiveHeapObject> import_name, int module_request, int cell_index,
int beg_pos, int end_pos) {
Handle<SourceTextModuleInfoEntry> result =
Handle<SourceTextModuleInfoEntry>::cast(isolate->factory()->NewStruct(
SOURCE_TEXT_MODULE_INFO_ENTRY_TYPE, AllocationType::kOld));
template <typename Isolate>
HandleFor<Isolate, SourceTextModuleInfoEntry> SourceTextModuleInfoEntry::New(
Isolate* isolate, HandleFor<Isolate, PrimitiveHeapObject> export_name,
HandleFor<Isolate, PrimitiveHeapObject> local_name,
HandleFor<Isolate, PrimitiveHeapObject> import_name, int module_request,
int cell_index, int beg_pos, int end_pos) {
HandleFor<Isolate, SourceTextModuleInfoEntry> result =
HandleFor<Isolate, SourceTextModuleInfoEntry>::cast(
isolate->factory()->NewStruct(SOURCE_TEXT_MODULE_INFO_ENTRY_TYPE,
AllocationType::kOld));
result->set_export_name(*export_name);
result->set_local_name(*local_name);
result->set_import_name(*import_name);
@ -1049,12 +1066,27 @@ Handle<SourceTextModuleInfoEntry> SourceTextModuleInfoEntry::New(
return result;
}
Handle<SourceTextModuleInfo> SourceTextModuleInfo::New(
template Handle<SourceTextModuleInfoEntry> SourceTextModuleInfoEntry::New(
Isolate* isolate, Handle<PrimitiveHeapObject> export_name,
Handle<PrimitiveHeapObject> local_name,
Handle<PrimitiveHeapObject> import_name, int module_request, int cell_index,
int beg_pos, int end_pos);
template OffThreadHandle<SourceTextModuleInfoEntry>
SourceTextModuleInfoEntry::New(OffThreadIsolate* isolate,
OffThreadHandle<PrimitiveHeapObject> export_name,
OffThreadHandle<PrimitiveHeapObject> local_name,
OffThreadHandle<PrimitiveHeapObject> import_name,
int module_request, int cell_index, int beg_pos,
int end_pos);
template <typename Isolate>
HandleFor<Isolate, SourceTextModuleInfo> SourceTextModuleInfo::New(
Isolate* isolate, Zone* zone, SourceTextModuleDescriptor* descr) {
// Serialize module requests.
int size = static_cast<int>(descr->module_requests().size());
Handle<FixedArray> module_requests = isolate->factory()->NewFixedArray(size);
Handle<FixedArray> module_request_positions =
HandleFor<Isolate, FixedArray> module_requests =
isolate->factory()->NewFixedArray(size);
HandleFor<Isolate, FixedArray> module_request_positions =
isolate->factory()->NewFixedArray(size);
for (const auto& elem : descr->module_requests()) {
module_requests->set(elem.second.index,
@ -1064,46 +1096,49 @@ Handle<SourceTextModuleInfo> SourceTextModuleInfo::New(
}
// Serialize special exports.
Handle<FixedArray> special_exports = isolate->factory()->NewFixedArray(
static_cast<int>(descr->special_exports().size()));
HandleFor<Isolate, FixedArray> special_exports =
isolate->factory()->NewFixedArray(
static_cast<int>(descr->special_exports().size()));
{
int i = 0;
for (auto entry : descr->special_exports()) {
Handle<SourceTextModuleInfoEntry> serialized_entry =
HandleFor<Isolate, SourceTextModuleInfoEntry> serialized_entry =
entry->Serialize(isolate);
special_exports->set(i++, *serialized_entry);
}
}
// Serialize namespace imports.
Handle<FixedArray> namespace_imports = isolate->factory()->NewFixedArray(
static_cast<int>(descr->namespace_imports().size()));
HandleFor<Isolate, FixedArray> namespace_imports =
isolate->factory()->NewFixedArray(
static_cast<int>(descr->namespace_imports().size()));
{
int i = 0;
for (auto entry : descr->namespace_imports()) {
Handle<SourceTextModuleInfoEntry> serialized_entry =
HandleFor<Isolate, SourceTextModuleInfoEntry> serialized_entry =
entry->Serialize(isolate);
namespace_imports->set(i++, *serialized_entry);
}
}
// Serialize regular exports.
Handle<FixedArray> regular_exports =
HandleFor<Isolate, FixedArray> regular_exports =
descr->SerializeRegularExports(isolate, zone);
// Serialize regular imports.
Handle<FixedArray> regular_imports = isolate->factory()->NewFixedArray(
static_cast<int>(descr->regular_imports().size()));
HandleFor<Isolate, FixedArray> regular_imports =
isolate->factory()->NewFixedArray(
static_cast<int>(descr->regular_imports().size()));
{
int i = 0;
for (const auto& elem : descr->regular_imports()) {
Handle<SourceTextModuleInfoEntry> serialized_entry =
HandleFor<Isolate, SourceTextModuleInfoEntry> serialized_entry =
elem.second->Serialize(isolate);
regular_imports->set(i++, *serialized_entry);
}
}
Handle<SourceTextModuleInfo> result =
HandleFor<Isolate, SourceTextModuleInfo> result =
isolate->factory()->NewSourceTextModuleInfo();
result->set(kModuleRequestsIndex, *module_requests);
result->set(kSpecialExportsIndex, *special_exports);
@ -1113,6 +1148,10 @@ Handle<SourceTextModuleInfo> SourceTextModuleInfo::New(
result->set(kModuleRequestPositionsIndex, *module_request_positions);
return result;
}
template Handle<SourceTextModuleInfo> SourceTextModuleInfo::New(
Isolate* isolate, Zone* zone, SourceTextModuleDescriptor* descr);
template OffThreadHandle<SourceTextModuleInfo> SourceTextModuleInfo::New(
OffThreadIsolate* isolate, Zone* zone, SourceTextModuleDescriptor* descr);
int SourceTextModuleInfo::RegularExportCount() const {
DCHECK_EQ(regular_exports().length() % kRegularExportLength, 0);

View File

@ -6,6 +6,7 @@
#define V8_OBJECTS_SCOPE_INFO_H_
#include "src/common/globals.h"
#include "src/handles/handle-for.h"
#include "src/objects/fixed-array.h"
#include "src/objects/function-kind.h"
#include "src/objects/objects.h"
@ -218,8 +219,10 @@ class ScopeInfo : public FixedArray, public TorqueGeneratedScopeFlagsFields {
bool Equals(ScopeInfo other) const;
#endif
static Handle<ScopeInfo> Create(Isolate* isolate, Zone* zone, Scope* scope,
MaybeHandle<ScopeInfo> outer_scope);
template <typename Isolate>
static HandleFor<Isolate, ScopeInfo> Create(
Isolate* isolate, Zone* zone, Scope* scope,
MaybeHandleFor<Isolate, ScopeInfo> outer_scope);
static Handle<ScopeInfo> CreateForWithScope(
Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope);
V8_EXPORT_PRIVATE static Handle<ScopeInfo> CreateForEmptyFunction(

View File

@ -196,8 +196,9 @@ class SourceTextModuleInfo : public FixedArray {
public:
DECL_CAST(SourceTextModuleInfo)
static Handle<SourceTextModuleInfo> New(Isolate* isolate, Zone* zone,
SourceTextModuleDescriptor* descr);
template <typename Isolate>
static HandleFor<Isolate, SourceTextModuleInfo> New(
Isolate* isolate, Zone* zone, SourceTextModuleDescriptor* descr);
inline FixedArray module_requests() const;
inline FixedArray special_exports() const;
@ -217,7 +218,8 @@ class SourceTextModuleInfo : public FixedArray {
#endif
private:
friend class Factory;
template <typename Impl>
friend class FactoryBase;
friend class SourceTextModuleDescriptor;
enum {
kModuleRequestsIndex,
@ -250,10 +252,11 @@ class SourceTextModuleInfoEntry
DECL_INT_ACCESSORS(beg_pos)
DECL_INT_ACCESSORS(end_pos)
static Handle<SourceTextModuleInfoEntry> New(
Isolate* isolate, Handle<PrimitiveHeapObject> export_name,
Handle<PrimitiveHeapObject> local_name,
Handle<PrimitiveHeapObject> import_name, int module_request,
template <typename Isolate>
static HandleFor<Isolate, SourceTextModuleInfoEntry> New(
Isolate* isolate, HandleFor<Isolate, PrimitiveHeapObject> export_name,
HandleFor<Isolate, PrimitiveHeapObject> local_name,
HandleFor<Isolate, PrimitiveHeapObject> import_name, int module_request,
int cell_index, int beg_pos, int end_pos);
TQ_OBJECT_CONSTRUCTORS(SourceTextModuleInfoEntry)