diff --git a/src/heap/factory-base-inl.h b/src/heap/factory-base-inl.h index 6f218b8248..6c1cede212 100644 --- a/src/heap/factory-base-inl.h +++ b/src/heap/factory-base-inl.h @@ -6,9 +6,10 @@ #define V8_HEAP_FACTORY_BASE_INL_H_ #include "src/heap/factory-base.h" - #include "src/numbers/conversions.h" #include "src/objects/heap-number.h" +#include "src/objects/map.h" +#include "src/objects/slots-inl.h" #include "src/objects/smi.h" #include "src/roots/roots.h" @@ -93,6 +94,29 @@ Handle FactoryBase::NewHeapNumberWithHoleNaN() { return NewHeapNumberFromBits(kHoleNanInt64); } +template +template +StructType FactoryBase::NewStructInternal(InstanceType type, + AllocationType allocation) { + ReadOnlyRoots roots = read_only_roots(); + Map map = Map::GetInstanceTypeMap(roots, type); + int size = StructType::kSize; + return StructType::cast(NewStructInternal(roots, map, size, allocation)); +} + +template +Struct FactoryBase::NewStructInternal(ReadOnlyRoots roots, Map map, + int size, + AllocationType allocation) { + DCHECK_EQ(size, map.instance_size()); + HeapObject result = AllocateRawWithImmortalMap(size, allocation, map); + Struct str = Struct::cast(result); + Object value = roots.undefined_value(); + int length = (size >> kTaggedSizeLog2) - 1; + MemsetTagged(str.RawField(Struct::kHeaderSize), value, length); + return str; +} + } // namespace internal } // namespace v8 diff --git a/src/heap/factory-base.cc b/src/heap/factory-base.cc index 27fcbba92a..a9223af42a 100644 --- a/src/heap/factory-base.cc +++ b/src/heap/factory-base.cc @@ -53,29 +53,20 @@ FactoryBase::NewHeapNumber(); template Handle FactoryBase::NewStruct(InstanceType type, AllocationType allocation) { - return handle(NewStructInternal(type, allocation), isolate()); -} - -template -Struct FactoryBase::NewStructInternal(InstanceType type, - AllocationType allocation) { - Map map = Map::GetInstanceTypeMap(read_only_roots(), type); + ReadOnlyRoots roots = read_only_roots(); + Map map = Map::GetInstanceTypeMap(roots, type); int size = map.instance_size(); - HeapObject result = AllocateRawWithImmortalMap(size, allocation, map); - Struct str = Struct::cast(result); - str.InitializeBody(size); - return str; + return handle(NewStructInternal(roots, map, size, allocation), isolate()); } template Handle FactoryBase::NewAccessorPair() { - Handle accessors = Handle::cast( - NewStruct(ACCESSOR_PAIR_TYPE, AllocationType::kOld)); - AccessorPair raw = *accessors; + auto accessors = + NewStructInternal(ACCESSOR_PAIR_TYPE, AllocationType::kOld); DisallowGarbageCollection no_gc; - raw.set_getter(read_only_roots().null_value(), SKIP_WRITE_BARRIER); - raw.set_setter(read_only_roots().null_value(), SKIP_WRITE_BARRIER); - return accessors; + accessors.set_getter(read_only_roots().null_value(), SKIP_WRITE_BARRIER); + accessors.set_setter(read_only_roots().null_value(), SKIP_WRITE_BARRIER); + return handle(accessors, isolate()); } template @@ -233,8 +224,8 @@ Handle