Commit 17ac7c5f authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[runtime] Ensure that canonical empty dictionaries reallocate upon addition.

BUG=chromium:699166

Change-Id: Ifd460a454d2bf36cff6b114ecd9163ef4fbdc79e
Reviewed-on: https://chromium-review.googlesource.com/456416Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43869}
parent 815d8237
......@@ -2740,7 +2740,7 @@ void Heap::CreateInitialObjects() {
}
Handle<NameDictionary> empty_properties_dictionary =
NameDictionary::New(isolate(), 0, TENURED);
NameDictionary::NewEmpty(isolate(), TENURED);
empty_properties_dictionary->SetRequiresCopyOnCapacityChange();
set_empty_properties_dictionary(*empty_properties_dictionary);
......@@ -2806,7 +2806,7 @@ void Heap::CreateInitialObjects() {
set_script_list(Smi::kZero);
Handle<SeededNumberDictionary> slow_element_dictionary =
SeededNumberDictionary::New(isolate(), 0, TENURED);
SeededNumberDictionary::NewEmpty(isolate(), TENURED);
slow_element_dictionary->set_requires_slow_elements();
set_empty_slow_element_dictionary(*slow_element_dictionary);
......
......@@ -472,7 +472,7 @@ static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT
if (internal_fields > 0) {
os << " - internal fields = {";
for (int i = 0; i < internal_fields; i++) {
os << "\n " << Brief(obj->GetInternalField(i));
os << "\n " << obj->GetInternalField(i);
}
os << "\n }\n";
}
......
......@@ -16343,7 +16343,13 @@ Handle<Derived> HashTable<Derived, Shape, Key>::New(
if (capacity > HashTable::kMaxCapacity) {
v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true);
}
return New(isolate, capacity, pretenure);
}
template <typename Derived, typename Shape, typename Key>
Handle<Derived> HashTable<Derived, Shape, Key>::New(Isolate* isolate,
int capacity,
PretenureFlag pretenure) {
Factory* factory = isolate->factory();
int length = EntryToIndex(capacity);
Handle<FixedArray> array = factory->NewFixedArray(length, pretenure);
......@@ -16356,7 +16362,6 @@ Handle<Derived> HashTable<Derived, Shape, Key>::New(
return table;
}
// Find entry for key otherwise return kNotFound.
template <typename Derived, typename Shape>
int NameDictionaryBase<Derived, Shape>::FindEntry(Handle<Name> key) {
......@@ -16630,6 +16635,10 @@ Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::New(
Isolate*, int at_least_space_for, PretenureFlag pretenure,
MinimumCapacity capacity_option);
template Handle<SeededNumberDictionary>
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
uint32_t>::NewEmpty(Isolate*, PretenureFlag pretenure);
template Handle<UnseededNumberDictionary>
Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape,
uint32_t>::New(Isolate*, int at_least_space_for,
......@@ -16640,6 +16649,10 @@ template Handle<NameDictionary>
Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>::New(
Isolate*, int n, PretenureFlag pretenure, MinimumCapacity capacity_option);
template Handle<NameDictionary>
Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>::NewEmpty(
Isolate*, PretenureFlag pretenure);
template Handle<GlobalDictionary>
Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>::New(
Isolate*, int n, PretenureFlag pretenure, MinimumCapacity capacity_option);
......@@ -17774,6 +17787,17 @@ Handle<Derived> Dictionary<Derived, Shape, Key>::New(
return dict;
}
template <typename Derived, typename Shape, typename Key>
Handle<Derived> Dictionary<Derived, Shape, Key>::NewEmpty(
Isolate* isolate, PretenureFlag pretenure) {
Handle<Derived> 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);
return dict;
}
template <typename Derived, typename Shape, typename Key>
Handle<FixedArray>
Dictionary<Derived, Shape, Key>::GenerateNewEnumerationIndices(
......
......@@ -3431,6 +3431,9 @@ class HashTable : public HashTableBase {
protected:
friend class ObjectHashTable;
MUST_USE_RESULT static Handle<Derived> New(Isolate* isolate, int capacity,
PretenureFlag pretenure);
// Find the entry at which to insert element with the given key that
// has the given hash value.
uint32_t FindInsertionEntry(uint32_t hash);
......@@ -3652,6 +3655,10 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
PretenureFlag pretenure = NOT_TENURED,
MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY);
// Creates an dictionary with minimal possible capacity.
MUST_USE_RESULT static Handle<Derived> NewEmpty(
Isolate* isolate, PretenureFlag pretenure = NOT_TENURED);
// Ensures that a new dictionary is created when the capacity is checked.
void SetRequiresCopyOnCapacityChange();
......
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