Commit 43995e2f authored by neis's avatar neis Committed by Commit bot

[modules] Make ModuleInfoEntry a Struct rather than FixedArray.

It always has the same number of slots.

R=adamk@chromium.org
TBR=bmeurer@chromium.org
BUG=v8:1569

Review-Url: https://codereview.chromium.org/2460353002
Cr-Commit-Position: refs/heads/master@{#40754}
parent 62937cf5
...@@ -8343,8 +8343,8 @@ class Internals { ...@@ -8343,8 +8343,8 @@ class Internals {
static const int kNodeIsPartiallyDependentShift = 4; static const int kNodeIsPartiallyDependentShift = 4;
static const int kNodeIsActiveShift = 4; static const int kNodeIsActiveShift = 4;
static const int kJSObjectType = 0xbb; static const int kJSObjectType = 0xbc;
static const int kJSApiObjectType = 0xba; static const int kJSApiObjectType = 0xbb;
static const int kFirstNonstringType = 0x80; static const int kFirstNonstringType = 0x80;
static const int kOddballType = 0x83; static const int kOddballType = 0x83;
static const int kForeignType = 0x87; static const int kForeignType = 0x87;
......
...@@ -284,6 +284,7 @@ AstType::bitset AstBitsetType::Lub(i::Map* map) { ...@@ -284,6 +284,7 @@ AstType::bitset AstBitsetType::Lub(i::Map* map) {
case CODE_TYPE: case CODE_TYPE:
case PROPERTY_CELL_TYPE: case PROPERTY_CELL_TYPE:
case MODULE_TYPE: case MODULE_TYPE:
case MODULE_INFO_ENTRY_TYPE:
return kOtherInternal & kTaggedPointer; return kOtherInternal & kTaggedPointer;
// Remaining instance types are unsupported for now. If any of them do // Remaining instance types are unsupported for now. If any of them do
......
...@@ -867,14 +867,15 @@ Handle<ModuleInfoEntry> ModuleInfoEntry::New(Isolate* isolate, ...@@ -867,14 +867,15 @@ Handle<ModuleInfoEntry> ModuleInfoEntry::New(Isolate* isolate,
Handle<Object> import_name, Handle<Object> import_name,
int module_request, int cell_index, int module_request, int cell_index,
int beg_pos, int end_pos) { int beg_pos, int end_pos) {
Handle<ModuleInfoEntry> result = isolate->factory()->NewModuleInfoEntry(); Handle<ModuleInfoEntry> result = Handle<ModuleInfoEntry>::cast(
result->set(kExportNameIndex, *export_name); isolate->factory()->NewStruct(MODULE_INFO_ENTRY_TYPE));
result->set(kLocalNameIndex, *local_name); result->set_export_name(*export_name);
result->set(kImportNameIndex, *import_name); result->set_local_name(*local_name);
result->set(kModuleRequestIndex, Smi::FromInt(module_request)); result->set_import_name(*import_name);
result->set(kCellIndexIndex, Smi::FromInt(cell_index)); result->set_module_request(module_request);
result->set(kBegPosIndex, Smi::FromInt(beg_pos)); result->set_cell_index(cell_index);
result->set(kEndPosIndex, Smi::FromInt(end_pos)); result->set_beg_pos(beg_pos);
result->set_end_pos(end_pos);
return result; return result;
} }
......
...@@ -280,6 +280,7 @@ Type::bitset BitsetType::Lub(i::Map* map) { ...@@ -280,6 +280,7 @@ Type::bitset BitsetType::Lub(i::Map* map) {
case CODE_TYPE: case CODE_TYPE:
case PROPERTY_CELL_TYPE: case PROPERTY_CELL_TYPE:
case MODULE_TYPE: case MODULE_TYPE:
case MODULE_INFO_ENTRY_TYPE:
return kOtherInternal; return kOtherInternal;
// Remaining instance types are unsupported for now. If any of them do // Remaining instance types are unsupported for now. If any of them do
......
...@@ -1512,12 +1512,6 @@ Handle<ScopeInfo> Factory::NewScopeInfo(int length) { ...@@ -1512,12 +1512,6 @@ Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
return scope_info; return scope_info;
} }
Handle<ModuleInfoEntry> Factory::NewModuleInfoEntry() {
Handle<FixedArray> array = NewFixedArray(ModuleInfoEntry::kLength, TENURED);
array->set_map_no_write_barrier(*module_info_entry_map());
return Handle<ModuleInfoEntry>::cast(array);
}
Handle<ModuleInfo> Factory::NewModuleInfo() { Handle<ModuleInfo> Factory::NewModuleInfo() {
Handle<FixedArray> array = NewFixedArray(ModuleInfo::kLength, TENURED); Handle<FixedArray> array = NewFixedArray(ModuleInfo::kLength, TENURED);
array->set_map_no_write_barrier(*module_info_map()); array->set_map_no_write_barrier(*module_info_map());
......
...@@ -2265,7 +2265,6 @@ bool Heap::CreateInitialMaps() { ...@@ -2265,7 +2265,6 @@ bool Heap::CreateInitialMaps() {
DCHECK_NE(fixed_array_map(), fixed_cow_array_map()); DCHECK_NE(fixed_array_map(), fixed_cow_array_map());
ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info) ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info)
ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, module_info_entry)
ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, module_info) ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, module_info)
ALLOCATE_PRIMITIVE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number, ALLOCATE_PRIMITIVE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number,
Context::NUMBER_FUNCTION_INDEX) Context::NUMBER_FUNCTION_INDEX)
......
...@@ -92,7 +92,6 @@ using v8::MemoryPressureLevel; ...@@ -92,7 +92,6 @@ using v8::MemoryPressureLevel;
V(Map, message_object_map, JSMessageObjectMap) \ V(Map, message_object_map, JSMessageObjectMap) \
V(Map, external_map, ExternalMap) \ V(Map, external_map, ExternalMap) \
V(Map, bytecode_array_map, BytecodeArrayMap) \ V(Map, bytecode_array_map, BytecodeArrayMap) \
V(Map, module_info_entry_map, ModuleInfoEntryMap) \
V(Map, module_info_map, ModuleInfoMap) \ V(Map, module_info_map, ModuleInfoMap) \
/* String maps */ \ /* String maps */ \
V(Map, native_source_string_map, NativeSourceStringMap) \ V(Map, native_source_string_map, NativeSourceStringMap) \
...@@ -277,7 +276,6 @@ using v8::MemoryPressureLevel; ...@@ -277,7 +276,6 @@ using v8::MemoryPressureLevel;
V(FixedArrayMap) \ V(FixedArrayMap) \
V(CodeMap) \ V(CodeMap) \
V(ScopeInfoMap) \ V(ScopeInfoMap) \
V(ModuleInfoEntryMap) \
V(ModuleInfoMap) \ V(ModuleInfoMap) \
V(FixedCOWArrayMap) \ V(FixedCOWArrayMap) \
V(FixedDoubleArrayMap) \ V(FixedDoubleArrayMap) \
......
...@@ -1000,6 +1000,24 @@ void JSFixedArrayIterator::JSFixedArrayIteratorVerify() { ...@@ -1000,6 +1000,24 @@ void JSFixedArrayIterator::JSFixedArrayIteratorVerify() {
CHECK_LE(index(), array()->length()); CHECK_LE(index(), array()->length());
} }
void ModuleInfoEntry::ModuleInfoEntryVerify() {
Isolate* isolate = GetIsolate();
CHECK(IsModuleInfoEntry());
CHECK(export_name()->IsUndefined(isolate) || export_name()->IsString());
CHECK(local_name()->IsUndefined(isolate) || local_name()->IsString());
CHECK(import_name()->IsUndefined(isolate) || import_name()->IsString());
VerifySmiField(kModuleRequestOffset);
VerifySmiField(kCellIndexOffset);
VerifySmiField(kBegPosOffset);
VerifySmiField(kEndPosOffset);
CHECK_IMPLIES(import_name()->IsString(), module_request() >= 0);
CHECK_IMPLIES(export_name()->IsString() && import_name()->IsString(),
local_name()->IsUndefined(isolate));
}
void Module::ModuleVerify() { void Module::ModuleVerify() {
CHECK(IsModule()); CHECK(IsModule());
......
...@@ -803,10 +803,6 @@ bool HeapObject::IsScopeInfo() const { ...@@ -803,10 +803,6 @@ bool HeapObject::IsScopeInfo() const {
return map() == GetHeap()->scope_info_map(); return map() == GetHeap()->scope_info_map();
} }
bool HeapObject::IsModuleInfoEntry() const {
return map() == GetHeap()->module_info_entry_map();
}
bool HeapObject::IsModuleInfo() const { bool HeapObject::IsModuleInfo() const {
return map() == GetHeap()->module_info_map(); return map() == GetHeap()->module_info_map();
} }
...@@ -3351,7 +3347,6 @@ CAST_ACCESSOR(JSWeakMap) ...@@ -3351,7 +3347,6 @@ CAST_ACCESSOR(JSWeakMap)
CAST_ACCESSOR(JSWeakSet) CAST_ACCESSOR(JSWeakSet)
CAST_ACCESSOR(LayoutDescriptor) CAST_ACCESSOR(LayoutDescriptor)
CAST_ACCESSOR(Map) CAST_ACCESSOR(Map)
CAST_ACCESSOR(ModuleInfoEntry)
CAST_ACCESSOR(ModuleInfo) CAST_ACCESSOR(ModuleInfo)
CAST_ACCESSOR(Name) CAST_ACCESSOR(Name)
CAST_ACCESSOR(NameDictionary) CAST_ACCESSOR(NameDictionary)
...@@ -8046,27 +8041,13 @@ bool ScopeInfo::HasSimpleParameters() { ...@@ -8046,27 +8041,13 @@ bool ScopeInfo::HasSimpleParameters() {
FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(SCOPE_INFO_FIELD_ACCESSORS) FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(SCOPE_INFO_FIELD_ACCESSORS)
#undef SCOPE_INFO_FIELD_ACCESSORS #undef SCOPE_INFO_FIELD_ACCESSORS
Object* ModuleInfoEntry::export_name() const { return get(kExportNameIndex); } ACCESSORS(ModuleInfoEntry, export_name, Object, kExportNameOffset)
ACCESSORS(ModuleInfoEntry, local_name, Object, kLocalNameOffset)
Object* ModuleInfoEntry::local_name() const { return get(kLocalNameIndex); } ACCESSORS(ModuleInfoEntry, import_name, Object, kImportNameOffset)
SMI_ACCESSORS(ModuleInfoEntry, module_request, kModuleRequestOffset)
Object* ModuleInfoEntry::import_name() const { return get(kImportNameIndex); } SMI_ACCESSORS(ModuleInfoEntry, cell_index, kCellIndexOffset)
SMI_ACCESSORS(ModuleInfoEntry, beg_pos, kBegPosOffset)
int ModuleInfoEntry::module_request() const { SMI_ACCESSORS(ModuleInfoEntry, end_pos, kEndPosOffset)
return Smi::cast(get(kModuleRequestIndex))->value();
}
int ModuleInfoEntry::cell_index() const {
return Smi::cast(get(kCellIndexIndex))->value();
}
int ModuleInfoEntry::beg_pos() const {
return Smi::cast(get(kBegPosIndex))->value();
}
int ModuleInfoEntry::end_pos() const {
return Smi::cast(get(kEndPosIndex))->value();
}
FixedArray* ModuleInfo::module_requests() const { FixedArray* ModuleInfo::module_requests() const {
return FixedArray::cast(get(kModuleRequestsIndex)); return FixedArray::cast(get(kModuleRequestsIndex));
......
...@@ -1186,6 +1186,18 @@ void PromiseReactionJobInfo::PromiseReactionJobInfoPrint( ...@@ -1186,6 +1186,18 @@ void PromiseReactionJobInfo::PromiseReactionJobInfoPrint(
os << "\n"; os << "\n";
} }
void ModuleInfoEntry::ModuleInfoEntryPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "ModuleInfoEntry");
os << "\n - export_name: " << Brief(export_name());
os << "\n - local_name: " << Brief(local_name());
os << "\n - import_name: " << Brief(import_name());
os << "\n - module_request: " << module_request();
os << "\n - cell_index: " << cell_index();
os << "\n - beg_pos: " << beg_pos();
os << "\n - end_pos: " << end_pos();
os << "\n";
}
void Module::ModulePrint(std::ostream& os) { // NOLINT void Module::ModulePrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "Module"); HeapObject::PrintHeader(os, "Module");
os << "\n - code: " << Brief(code()); os << "\n - code: " << Brief(code());
......
...@@ -97,7 +97,6 @@ ...@@ -97,7 +97,6 @@
// - TemplateList // - TemplateList
// - TransitionArray // - TransitionArray
// - ScopeInfo // - ScopeInfo
// - ModuleInfoEntry
// - ModuleInfo // - ModuleInfo
// - ScriptContextTable // - ScriptContextTable
// - WeakFixedArray // - WeakFixedArray
...@@ -159,6 +158,7 @@ ...@@ -159,6 +158,7 @@
// - CodeCache // - CodeCache
// - PrototypeInfo // - PrototypeInfo
// - Module // - Module
// - ModuleInfoEntry
// - WeakCell // - WeakCell
// //
// Formats of Object*: // Formats of Object*:
...@@ -407,6 +407,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; ...@@ -407,6 +407,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(TUPLE3_TYPE) \ V(TUPLE3_TYPE) \
V(CONTEXT_EXTENSION_TYPE) \ V(CONTEXT_EXTENSION_TYPE) \
V(MODULE_TYPE) \ V(MODULE_TYPE) \
V(MODULE_INFO_ENTRY_TYPE) \
\ \
V(FIXED_ARRAY_TYPE) \ V(FIXED_ARRAY_TYPE) \
V(FIXED_DOUBLE_ARRAY_TYPE) \ V(FIXED_DOUBLE_ARRAY_TYPE) \
...@@ -572,6 +573,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; ...@@ -572,6 +573,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(PROTOTYPE_INFO, PrototypeInfo, prototype_info) \ V(PROTOTYPE_INFO, PrototypeInfo, prototype_info) \
V(TUPLE3, Tuple3, tuple3) \ V(TUPLE3, Tuple3, tuple3) \
V(MODULE, Module, module) \ V(MODULE, Module, module) \
V(MODULE_INFO_ENTRY, ModuleInfoEntry, module_info_entry) \
V(CONTEXT_EXTENSION, ContextExtension, context_extension) V(CONTEXT_EXTENSION, ContextExtension, context_extension)
// We use the full 8 bits of the instance_type field to encode heap object // We use the full 8 bits of the instance_type field to encode heap object
...@@ -751,6 +753,7 @@ enum InstanceType { ...@@ -751,6 +753,7 @@ enum InstanceType {
TUPLE3_TYPE, TUPLE3_TYPE,
CONTEXT_EXTENSION_TYPE, CONTEXT_EXTENSION_TYPE,
MODULE_TYPE, MODULE_TYPE,
MODULE_INFO_ENTRY_TYPE,
// All the following types are subtypes of JSReceiver, which corresponds to // All the following types are subtypes of JSReceiver, which corresponds to
// objects in the JS sense. The first and the last type in this range are // objects in the JS sense. The first and the last type in this range are
...@@ -1102,7 +1105,6 @@ template <class C> inline bool Is(Object* obj); ...@@ -1102,7 +1105,6 @@ template <class C> inline bool Is(Object* obj);
V(ScriptContextTable) \ V(ScriptContextTable) \
V(NativeContext) \ V(NativeContext) \
V(ScopeInfo) \ V(ScopeInfo) \
V(ModuleInfoEntry) \
V(ModuleInfo) \ V(ModuleInfo) \
V(JSBoundFunction) \ V(JSBoundFunction) \
V(JSFunction) \ V(JSFunction) \
...@@ -4734,71 +4736,6 @@ class ScopeInfo : public FixedArray { ...@@ -4734,71 +4736,6 @@ class ScopeInfo : public FixedArray {
friend class ScopeIterator; friend class ScopeIterator;
}; };
class ModuleInfoEntry : public FixedArray {
public:
DECLARE_CAST(ModuleInfoEntry)
static Handle<ModuleInfoEntry> New(Isolate* isolate,
Handle<Object> export_name,
Handle<Object> local_name,
Handle<Object> import_name,
int module_request, int cell_index,
int beg_pos, int end_pos);
inline Object* export_name() const;
inline Object* local_name() const;
inline Object* import_name() const;
inline int module_request() const;
inline int cell_index() const;
inline int beg_pos() const;
inline int end_pos() const;
private:
friend class Factory;
enum {
kExportNameIndex,
kLocalNameIndex,
kImportNameIndex,
kModuleRequestIndex,
kCellIndexIndex,
kBegPosIndex,
kEndPosIndex,
kLength
};
};
// ModuleInfo is to ModuleDescriptor what ScopeInfo is to Scope.
// TODO(neis): Use Struct instead of FixedArray.
class ModuleInfo : public FixedArray {
public:
DECLARE_CAST(ModuleInfo)
static Handle<ModuleInfo> New(Isolate* isolate, Zone* zone,
ModuleDescriptor* descr);
inline FixedArray* module_requests() const;
inline FixedArray* special_exports() const;
inline FixedArray* regular_exports() const;
inline FixedArray* namespace_imports() const;
inline FixedArray* regular_imports() const;
static Handle<ModuleInfoEntry> LookupRegularImport(Handle<ModuleInfo> info,
Handle<String> local_name);
#ifdef DEBUG
inline bool Equals(ModuleInfo* other) const;
#endif
private:
friend class Factory;
enum {
kModuleRequestsIndex,
kSpecialExportsIndex,
kRegularExportsIndex,
kNamespaceImportsIndex,
kRegularImportsIndex,
kLength
};
};
// The cache for maps used by normalized (dictionary mode) objects. // The cache for maps used by normalized (dictionary mode) objects.
// Such maps do not have property descriptors, so a typical program // Such maps do not have property descriptors, so a typical program
// needs very limited number of distinct normalized maps. // needs very limited number of distinct normalized maps.
...@@ -8124,6 +8061,73 @@ class JSGeneratorObject: public JSObject { ...@@ -8124,6 +8061,73 @@ class JSGeneratorObject: public JSObject {
DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject); DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject);
}; };
class ModuleInfoEntry : public Struct {
public:
DECLARE_CAST(ModuleInfoEntry)
DECLARE_PRINTER(ModuleInfoEntry)
DECLARE_VERIFIER(ModuleInfoEntry)
DECL_ACCESSORS(export_name, Object)
DECL_ACCESSORS(local_name, Object)
DECL_ACCESSORS(import_name, Object)
DECL_INT_ACCESSORS(module_request)
DECL_INT_ACCESSORS(cell_index)
DECL_INT_ACCESSORS(beg_pos)
DECL_INT_ACCESSORS(end_pos)
static Handle<ModuleInfoEntry> New(Isolate* isolate,
Handle<Object> export_name,
Handle<Object> local_name,
Handle<Object> import_name,
int module_request, int cell_index,
int beg_pos, int end_pos);
static const int kExportNameOffset = HeapObject::kHeaderSize;
static const int kLocalNameOffset = kExportNameOffset + kPointerSize;
static const int kImportNameOffset = kLocalNameOffset + kPointerSize;
static const int kModuleRequestOffset = kImportNameOffset + kPointerSize;
static const int kCellIndexOffset = kModuleRequestOffset + kPointerSize;
static const int kBegPosOffset = kCellIndexOffset + kPointerSize;
static const int kEndPosOffset = kBegPosOffset + kPointerSize;
static const int kSize = kEndPosOffset + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ModuleInfoEntry);
};
// ModuleInfo is to ModuleDescriptor what ScopeInfo is to Scope.
class ModuleInfo : public FixedArray {
public:
DECLARE_CAST(ModuleInfo)
static Handle<ModuleInfo> New(Isolate* isolate, Zone* zone,
ModuleDescriptor* descr);
inline FixedArray* module_requests() const;
inline FixedArray* special_exports() const;
inline FixedArray* regular_exports() const;
inline FixedArray* namespace_imports() const;
inline FixedArray* regular_imports() const;
static Handle<ModuleInfoEntry> LookupRegularImport(Handle<ModuleInfo> info,
Handle<String> local_name);
#ifdef DEBUG
inline bool Equals(ModuleInfo* other) const;
#endif
private:
friend class Factory;
enum {
kModuleRequestsIndex,
kSpecialExportsIndex,
kRegularExportsIndex,
kNamespaceImportsIndex,
kRegularImportsIndex,
kLength
};
DISALLOW_IMPLICIT_CONSTRUCTORS(ModuleInfo);
};
// When importing a module namespace (import * as foo from "bar"), a // When importing a module namespace (import * as foo from "bar"), a
// JSModuleNamespace object (representing module "bar") is created and bound to // JSModuleNamespace object (representing module "bar") is created and bound to
// the declared variable (foo). A module can have at most one namespace object. // the declared variable (foo). A module can have at most one namespace object.
......
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