@@ -127,6 +127,24 @@ Node* CodeStubAssembler::IntPtrSubFoldConstants(Node* left, Node* right) {
127127 return IntPtrSub (left, right);
128128}
129129
130+ Node* CodeStubAssembler::IntPtrRoundUpToPowerOfTwo32 (Node* value) {
131+ Comment (" IntPtrRoundUpToPowerOfTwo32" );
132+ CSA_ASSERT (UintPtrLessThanOrEqual (value, IntPtrConstant (0x80000000u )));
133+ value = IntPtrSub (value, IntPtrConstant (1 ));
134+ for (int i = 1 ; i <= 16 ; i *= 2 ) {
135+ value = WordOr (value, WordShr (value, IntPtrConstant (i)));
136+ }
137+ return IntPtrAdd (value, IntPtrConstant (1 ));
138+ }
139+
140+ Node* CodeStubAssembler::WordIsPowerOfTwo (Node* value) {
141+ // value && !(value & (value - 1))
142+ return WordEqual (
143+ Select (WordEqual (value, IntPtrConstant (0 )), IntPtrConstant (1 ),
144+ WordAnd (value, IntPtrSub (value, IntPtrConstant (1 )))),
145+ IntPtrConstant (0 ));
146+ }
147+
130148Node* CodeStubAssembler::Float64Round (Node* x) {
131149 Node* one = Float64Constant (1.0 );
132150 Node* one_half = Float64Constant (0.5 );
@@ -775,6 +793,7 @@ Node* CodeStubAssembler::AllocateRawAligned(Node* size_in_bytes,
775793}
776794
777795Node* CodeStubAssembler::Allocate (Node* size_in_bytes, AllocationFlags flags) {
796+ Comment (" Allocate" );
778797 bool const new_space = !(flags & kPretenured );
779798 Node* top_address = ExternalConstant (
780799 new_space
@@ -1105,6 +1124,12 @@ Node* CodeStubAssembler::IsSpecialReceiverInstanceType(Node* instance_type) {
11051124 Int32Constant (LAST_SPECIAL_RECEIVER_TYPE));
11061125}
11071126
1127+ Node* CodeStubAssembler::IsDictionaryMap (Node* map) {
1128+ Node* bit_field3 = LoadMapBitField3 (map);
1129+ return Word32NotEqual (IsSetWord32<Map::DictionaryMap>(bit_field3),
1130+ Int32Constant (0 ));
1131+ }
1132+
11081133Node* CodeStubAssembler::LoadNameHashField (Node* name) {
11091134 return LoadObjectField (name, Name::kHashFieldOffset , MachineType::Uint32 ());
11101135}
@@ -1659,6 +1684,57 @@ Node* CodeStubAssembler::AllocateRegExpResult(Node* context, Node* length,
16591684 return result;
16601685}
16611686
1687+ Node* CodeStubAssembler::AllocateNameDictionary (int at_least_space_for) {
1688+ return AllocateNameDictionary (IntPtrConstant (at_least_space_for));
1689+ }
1690+
1691+ Node* CodeStubAssembler::AllocateNameDictionary (Node* at_least_space_for) {
1692+ CSA_ASSERT (UintPtrLessThanOrEqual (
1693+ at_least_space_for, IntPtrConstant (NameDictionary::kMaxCapacity )));
1694+
1695+ Node* capacity = HashTableComputeCapacity (at_least_space_for);
1696+ CSA_ASSERT (WordIsPowerOfTwo (capacity));
1697+
1698+ Node* length = EntryToIndex<NameDictionary>(capacity);
1699+ Node* store_size =
1700+ IntPtrAddFoldConstants (WordShl (length, IntPtrConstant (kPointerSizeLog2 )),
1701+ IntPtrConstant (NameDictionary::kHeaderSize ));
1702+
1703+ Node* result = Allocate (store_size);
1704+ Comment (" Initialize NameDictionary" );
1705+ // Initialize FixedArray fields.
1706+ StoreObjectFieldRoot (result, FixedArray::kMapOffset ,
1707+ Heap::kHashTableMapRootIndex );
1708+ StoreObjectFieldNoWriteBarrier (result, FixedArray::kLengthOffset ,
1709+ SmiFromWord (length));
1710+ // Initialized HashTable fields.
1711+ Node* zero = SmiConstant (0 );
1712+ StoreFixedArrayElement (result, NameDictionary::kNumberOfElementsIndex , zero,
1713+ SKIP_WRITE_BARRIER);
1714+ StoreFixedArrayElement (result, NameDictionary::kNumberOfDeletedElementsIndex ,
1715+ zero, SKIP_WRITE_BARRIER);
1716+ StoreFixedArrayElement (result, NameDictionary::kCapacityIndex ,
1717+ SmiTag (capacity), SKIP_WRITE_BARRIER);
1718+ // Initialize Dictionary fields.
1719+ Node* filler = LoadRoot (Heap::kUndefinedValueRootIndex );
1720+ StoreFixedArrayElement (result, NameDictionary::kMaxNumberKeyIndex , filler,
1721+ SKIP_WRITE_BARRIER);
1722+ StoreFixedArrayElement (result, NameDictionary::kNextEnumerationIndexIndex ,
1723+ SmiConstant (PropertyDetails::kInitialIndex ),
1724+ SKIP_WRITE_BARRIER);
1725+
1726+ // Initialize NameDictionary elements.
1727+ Node* start_address = IntPtrAdd (
1728+ result, IntPtrConstant (NameDictionary::OffsetOfElementAt (
1729+ NameDictionary::kElementsStartIndex ) -
1730+ kHeapObjectTag ));
1731+ Node* end_address = IntPtrAdd (
1732+ result,
1733+ IntPtrSubFoldConstants (store_size, IntPtrConstant (kHeapObjectTag )));
1734+ StoreFieldsNoWriteBarrier (start_address, end_address, filler);
1735+ return result;
1736+ }
1737+
16621738Node* CodeStubAssembler::AllocateJSObjectFromMap (Node* map, Node* properties,
16631739 Node* elements) {
16641740 Node* size =
@@ -1676,6 +1752,7 @@ void CodeStubAssembler::InitializeJSObjectFromMap(Node* object, Node* map,
16761752 // This helper assumes that the object is in new-space, as guarded by the
16771753 // check in AllocatedJSObjectFromMap.
16781754 if (properties == nullptr ) {
1755+ CSA_ASSERT (Word32BinaryNot (IsDictionaryMap ((map))));
16791756 StoreObjectFieldRoot (object, JSObject::kPropertiesOffset ,
16801757 Heap::kEmptyFixedArrayRootIndex );
16811758 } else {
@@ -3835,6 +3912,19 @@ Node* CodeStubAssembler::EntryToIndex(Node* entry, int field_index) {
38353912 field_index));
38363913}
38373914
3915+ template Node* CodeStubAssembler::EntryToIndex<NameDictionary>(Node*, int );
3916+ template Node* CodeStubAssembler::EntryToIndex<GlobalDictionary>(Node*, int );
3917+
3918+ Node* CodeStubAssembler::HashTableComputeCapacity (Node* at_least_space_for) {
3919+ Node* capacity = IntPtrRoundUpToPowerOfTwo32 (
3920+ WordShl (at_least_space_for, IntPtrConstant (1 )));
3921+ return IntPtrMax (capacity, IntPtrConstant (HashTableBase::kMinCapacity ));
3922+ }
3923+
3924+ Node* CodeStubAssembler::IntPtrMax (Node* left, Node* right) {
3925+ return Select (IntPtrGreaterThanOrEqual (left, right), left, right);
3926+ }
3927+
38383928template <typename Dictionary>
38393929void CodeStubAssembler::NameDictionaryLookup (Node* dictionary,
38403930 Node* unique_name, Label* if_found,
0 commit comments