From b186ca9c7528c9dde6811db9c82b639e49b14ab9 Mon Sep 17 00:00:00 2001 From: Toon Verwaest Date: Wed, 21 Jun 2017 09:43:47 +0200 Subject: [PATCH] [runtime] Move MaxNumberKey and NextEnumerationIndex to the subclasses that use it Bug: Change-Id: Ica3ebd998ad44d24c401cfb74cf5cbe3a6164c47 Reviewed-on: https://chromium-review.googlesource.com/541344 Commit-Queue: Toon Verwaest Reviewed-by: Camillo Bruni Reviewed-by: Michael Starzinger Cr-Commit-Position: refs/heads/master@{#46099} --- src/code-stub-assembler.cc | 2 -- src/compiler/access-builder.cc | 2 +- src/compiler/js-builtin-reducer.cc | 5 +--- src/objects.cc | 12 +++++--- src/objects/dictionary.h | 45 +++++++++++++++++------------- tools/v8heapconst.py | 24 ++++++++-------- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc index 2edaa9dd05..220746d897 100644 --- a/src/code-stub-assembler.cc +++ b/src/code-stub-assembler.cc @@ -2106,8 +2106,6 @@ Node* CodeStubAssembler::AllocateNameDictionaryWithCapacity(Node* capacity) { SmiTag(capacity), SKIP_WRITE_BARRIER); // Initialize Dictionary fields. Node* filler = LoadRoot(Heap::kUndefinedValueRootIndex); - StoreFixedArrayElement(result, NameDictionary::kMaxNumberKeyIndex, filler, - SKIP_WRITE_BARRIER); StoreFixedArrayElement(result, NameDictionary::kNextEnumerationIndexIndex, SmiConstant(PropertyDetails::kInitialIndex), SKIP_WRITE_BARRIER); diff --git a/src/compiler/access-builder.cc b/src/compiler/access-builder.cc index f24c9dbe2b..89ce0329db 100644 --- a/src/compiler/access-builder.cc +++ b/src/compiler/access-builder.cc @@ -998,7 +998,7 @@ FieldAccess AccessBuilder::ForHashTableBaseCapacity() { FieldAccess AccessBuilder::ForDictionaryMaxNumberKey() { FieldAccess access = { kTaggedBase, - FixedArray::OffsetOfElementAt(NameDictionary::kMaxNumberKeyIndex), + FixedArray::OffsetOfElementAt(SeededNumberDictionary::kMaxNumberKeyIndex), MaybeHandle(), MaybeHandle(), Type::Any(), diff --git a/src/compiler/js-builtin-reducer.cc b/src/compiler/js-builtin-reducer.cc index a5a3cc5696..98c63ef954 100644 --- a/src/compiler/js-builtin-reducer.cc +++ b/src/compiler/js-builtin-reducer.cc @@ -1928,15 +1928,12 @@ Reduction JSBuiltinReducer::ReduceObjectCreate(Node* node) { value, jsgraph()->SmiConstant(capacity), effect, control); // Initialize Dictionary fields. Node* undefined = jsgraph()->UndefinedConstant(); - effect = graph()->NewNode( - simplified()->StoreField(AccessBuilder::ForDictionaryMaxNumberKey()), - value, undefined, effect, control); effect = graph()->NewNode( simplified()->StoreField( AccessBuilder::ForDictionaryNextEnumerationIndex()), value, jsgraph()->SmiConstant(PropertyDetails::kInitialIndex), effect, control); - // Initialize hte Properties fields. + // Initialize the Properties fields. for (int index = NameDictionary::kNextEnumerationIndexIndex + 1; index < length; index++) { effect = graph()->NewNode( diff --git a/src/objects.cc b/src/objects.cc index f2e9d33c80..98c1dd3271 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -17479,8 +17479,10 @@ Handle Dictionary::New( Handle dict = DerivedHashTable::New(isolate, at_least_space_for, capacity_option, pretenure); - // Initialize the next enumeration index. - dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex); + if (Shape::kIsEnumerable) { + // Initialize the next enumeration index. + dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex); + } return dict; } @@ -17490,8 +17492,10 @@ Handle Dictionary::NewEmpty(Isolate* isolate, Handle dict = DerivedHashTable::New(isolate, 1, pretenure); // Attempt to add one element to the empty dictionary must cause reallocation. DCHECK(!dict->HasSufficientCapacityToAdd(1)); - // Initialize the next enumeration index. - dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex); + if (Shape::kIsEnumerable) { + // Initialize the next enumeration index. + dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex); + } return dict; } diff --git a/src/objects/dictionary.h b/src/objects/dictionary.h index e3659988ae..a7c26e3cf5 100644 --- a/src/objects/dictionary.h +++ b/src/objects/dictionary.h @@ -61,6 +61,9 @@ class Dictionary : public HashTable { return DerivedHashTable::Shrink(dictionary); } + int NextEnumerationIndex() { UNREACHABLE(); } + void SetNextEnumerationIndex(int index) { UNREACHABLE(); } + int NumberOfEnumerableProperties(); // Return the key indices sorted by its enumeration index. @@ -77,16 +80,6 @@ class Dictionary : public HashTable { Handle storage, KeyCollectionMode mode, KeyAccumulator* accumulator); - // Accessors for next enumeration index. - void SetNextEnumerationIndex(int index) { - DCHECK(index != 0); - this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); - } - - int NextEnumerationIndex() { - return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); - } - // Creates a new dictionary. MUST_USE_RESULT static Handle New( Isolate* isolate, int at_least_space_for, @@ -122,9 +115,6 @@ class Dictionary : public HashTable { PropertyDetails details, int* entry_out = nullptr); - static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex; - static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; - static const bool kIsEnumerable = Shape::kIsEnumerable; protected: @@ -169,7 +159,7 @@ class NameDictionaryShape : public BaseDictionaryShape> { static inline uint32_t Hash(Handle key); static inline uint32_t HashForObject(Object* object); static inline Handle AsHandle(Isolate* isolate, Handle key); - static const int kPrefixSize = 2; + static const int kPrefixSize = 1; static const int kEntrySize = 3; static const int kEntryValueIndex = 1; static const int kEntryDetailsIndex = 2; @@ -177,13 +167,29 @@ class NameDictionaryShape : public BaseDictionaryShape> { static const bool kNeedsHoleCheck = false; }; -class NameDictionary : public Dictionary { - typedef Dictionary DerivedDictionary; +template +class BaseNameDictionary : public Dictionary { + public: + static const int kNextEnumerationIndexIndex = + HashTableBase::kPrefixStartIndex; + static const int kEntryValueIndex = 1; + // Accessors for next enumeration index. + void SetNextEnumerationIndex(int index) { + DCHECK_NE(0, index); + this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); + } + + int NextEnumerationIndex() { + return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); + } +}; + +class NameDictionary + : public BaseNameDictionary { public: DECLARE_CAST(NameDictionary) - static const int kEntryValueIndex = 1; static const int kEntryDetailsIndex = 2; static const int kInitialCapacity = 2; }; @@ -208,7 +214,7 @@ class GlobalDictionaryShape : public NameDictionaryShape { }; class GlobalDictionary - : public Dictionary { + : public BaseNameDictionary { public: DECLARE_CAST(GlobalDictionary) @@ -225,7 +231,7 @@ class NumberDictionaryShape : public BaseDictionaryShape { class SeededNumberDictionaryShape : public NumberDictionaryShape { public: static const bool UsesSeed = true; - static const int kPrefixSize = 2; + static const int kPrefixSize = 1; static const int kEntrySize = 3; static inline uint32_t SeededHash(uint32_t key, uint32_t seed); @@ -275,6 +281,7 @@ class SeededNumberDictionary Handle value, PropertyDetails details, Handle dictionary_holder); + static const int kMaxNumberKeyIndex = kPrefixStartIndex; void UpdateMaxNumberKey(uint32_t key, Handle dictionary_holder); // Returns true if the dictionary contains any elements that are non-writable, diff --git a/tools/v8heapconst.py b/tools/v8heapconst.py index 18b0d307ca..8fdc46c083 100644 --- a/tools/v8heapconst.py +++ b/tools/v8heapconst.py @@ -296,18 +296,18 @@ KNOWN_OBJECTS = { ("OLD_SPACE", 0x02811): "UndefinedCell", ("OLD_SPACE", 0x02821): "EmptySloppyArgumentsElements", ("OLD_SPACE", 0x02841): "EmptySlowElementDictionary", - ("OLD_SPACE", 0x02891): "EmptyPropertyCell", - ("OLD_SPACE", 0x028b1): "EmptyWeakCell", - ("OLD_SPACE", 0x028c9): "ArrayProtector", - ("OLD_SPACE", 0x028e9): "IsConcatSpreadableProtector", - ("OLD_SPACE", 0x028f9): "SpeciesProtector", - ("OLD_SPACE", 0x02909): "StringLengthProtector", - ("OLD_SPACE", 0x02929): "FastArrayIterationProtector", - ("OLD_SPACE", 0x02939): "ArrayIteratorProtector", - ("OLD_SPACE", 0x02959): "ArrayBufferNeuteringProtector", - ("OLD_SPACE", 0x02979): "InfinityValue", - ("OLD_SPACE", 0x02989): "MinusZeroValue", - ("OLD_SPACE", 0x02999): "MinusInfinityValue", + ("OLD_SPACE", 0x02889): "EmptyPropertyCell", + ("OLD_SPACE", 0x028a9): "EmptyWeakCell", + ("OLD_SPACE", 0x028c1): "ArrayProtector", + ("OLD_SPACE", 0x028e1): "IsConcatSpreadableProtector", + ("OLD_SPACE", 0x028f1): "SpeciesProtector", + ("OLD_SPACE", 0x02901): "StringLengthProtector", + ("OLD_SPACE", 0x02921): "FastArrayIterationProtector", + ("OLD_SPACE", 0x02931): "ArrayIteratorProtector", + ("OLD_SPACE", 0x02951): "ArrayBufferNeuteringProtector", + ("OLD_SPACE", 0x02971): "InfinityValue", + ("OLD_SPACE", 0x02981): "MinusZeroValue", + ("OLD_SPACE", 0x02991): "MinusInfinityValue", } # List of known V8 Frame Markers.