Commit 90a66422 authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

Remove 'length' field from ScopeInfo

This change relands the last part of https://crrev.com/c/2601880 .

ScopeInfo has a vestigial 'length' field from when it used to be a
FixedArray. This change removes that field, which saves some memory.

More specifically:

- Make ScopeInfo inherit from HeapObject, not FixedArrayBase which
  supplied the 'length' field.
- Change FactoryBase::NewScopeInfo to allocate the updated object shape.
  It maintains the existing behavior of filling the newly-allocated
  object with undefined, even though that's not a valid ScopeInfo and
  further initialization is required.
- Change a few length computations to use HeapObject::kHeaderSize rather
  than FixedArray::kHeaderSize.
- Remove an unnecessary heap verifier function.

Change-Id: I9b3980157568fdb0402fa31660949966b401fd31
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2733037Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#73278}
parent e0f40862
......@@ -583,20 +583,6 @@ void Context::ContextVerify(Isolate* isolate) {
}
}
void ScopeInfo::ScopeInfoVerify(Isolate* isolate) {
TorqueGeneratedClassVerifiers::ScopeInfoVerify(*this, isolate);
// Make sure that the FixedArray-style length matches the length that we would
// compute based on the Torque indexed fields.
CHECK_EQ(FixedArray::SizeFor(length()), AllocatedSize());
// Code that treats ScopeInfo like a FixedArray expects all values to be
// tagged.
for (int i = 0; i < length(); ++i) {
Object::VerifyPointer(isolate, get(isolate, i));
}
}
void NativeContext::NativeContextVerify(Isolate* isolate) {
ContextVerify(isolate);
CHECK_EQ(length(), NativeContext::NATIVE_CONTEXT_SLOTS);
......
......@@ -703,11 +703,13 @@ template <typename Impl>
Handle<ScopeInfo> FactoryBase<Impl>::NewScopeInfo(int length,
AllocationType type) {
DCHECK(type == AllocationType::kOld || type == AllocationType::kReadOnly);
Handle<HeapObject> result =
Handle<HeapObject>::cast(NewFixedArray(length, type));
result->set_map_after_allocation(*read_only_roots().scope_info_map_handle(),
SKIP_WRITE_BARRIER);
return Handle<ScopeInfo>::cast(result);
int size = ScopeInfo::SizeFor(length);
HeapObject obj = AllocateRawWithImmortalMap(
size, type, read_only_roots().scope_info_map());
ScopeInfo scope_info = ScopeInfo::cast(obj);
MemsetTagged(scope_info.data_start(), read_only_roots().undefined_value(),
length);
return handle(scope_info, isolate());
}
template <typename Impl>
......
......@@ -510,11 +510,10 @@ bool Heap::CreateInitialMaps() {
{
AllocationResult alloc =
AllocateRaw(FixedArray::SizeFor(ScopeInfo::kVariablePartIndex),
AllocateRaw(ScopeInfo::SizeFor(ScopeInfo::kVariablePartIndex),
AllocationType::kReadOnly);
if (!alloc.To(&obj)) return false;
obj.set_map_after_allocation(roots.scope_info_map(), SKIP_WRITE_BARRIER);
ScopeInfo::cast(obj).set_length(ScopeInfo::kVariablePartIndex);
int flags = ScopeInfo::IsEmptyBit::encode(true);
DCHECK_EQ(ScopeInfo::LanguageModeBit::decode(flags), LanguageMode::kSloppy);
DCHECK_EQ(ScopeInfo::ReceiverVariableBits::decode(flags),
......
......@@ -616,7 +616,7 @@ int ScopeInfo::length() const {
// AllocatedSize() is generated by Torque and represents the size in bytes of
// the object, as computed from flags, context_local_count, and possibly
// module_variable_count. Convert that size into a number of slots.
return (AllocatedSize() - FixedArray::kHeaderSize) / kTaggedSize;
return (AllocatedSize() - HeapObject::kHeaderSize) / kTaggedSize;
}
// static
......
......@@ -38,13 +38,11 @@ class Zone;
// This object provides quick access to scope info details for runtime
// routines.
class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, FixedArrayBase> {
class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, HeapObject> {
public:
DEFINE_TORQUE_GENERATED_SCOPE_FLAGS()
DECL_PRINTER(ScopeInfo)
DECL_VERIFIER(ScopeInfo)
class BodyDescriptor;
// Return the type of this scope.
......@@ -310,10 +308,10 @@ class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, FixedArrayBase> {
// index (number of tagged-pointer-sized slots starting after the standard
// HeapObject header).
static constexpr int OffsetOfElementAt(int index) {
return FixedArray::kHeaderSize + index * kTaggedSize;
return HeapObject::kHeaderSize + index * kTaggedSize;
}
static constexpr int ConvertOffsetToIndex(int offset) {
int index = (offset - FixedArray::kHeaderSize) / kTaggedSize;
int index = (offset - HeapObject::kHeaderSize) / kTaggedSize;
CONSTEXPR_DCHECK(OffsetOfElementAt(index) == offset);
return index;
}
......
......@@ -99,7 +99,7 @@ struct ModuleVariable {
@generateCppClass
@generateBodyDescriptor
extern class ScopeInfo extends FixedArrayBase {
extern class ScopeInfo extends HeapObject {
const flags: SmiTagged<ScopeFlags>;
// The number of parameters. For non-function scopes this is 0.
......
This diff is collapsed.
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