Commit 2fec36d9 authored by ishell's avatar ishell Committed by Commit bot

[ic] Avoid memory wasting when allocating names table of type feedback metadata.

BUG=chromium:625894

Review-Url: https://codereview.chromium.org/2181303002
Cr-Commit-Position: refs/heads/master@{#38047}
parent 1d2793f8
...@@ -16425,20 +16425,23 @@ template class Dictionary<UnseededNumberDictionary, ...@@ -16425,20 +16425,23 @@ template class Dictionary<UnseededNumberDictionary,
uint32_t>; uint32_t>;
template Handle<SeededNumberDictionary> template Handle<SeededNumberDictionary>
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::New(
New(Isolate*, int at_least_space_for, PretenureFlag pretenure); Isolate*, int at_least_space_for, PretenureFlag pretenure,
MinimumCapacity capacity_option);
template Handle<UnseededNumberDictionary> template Handle<UnseededNumberDictionary>
Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>:: Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape,
New(Isolate*, int at_least_space_for, PretenureFlag pretenure); uint32_t>::New(Isolate*, int at_least_space_for,
PretenureFlag pretenure,
MinimumCapacity capacity_option);
template Handle<NameDictionary> template Handle<NameDictionary>
Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >:: Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>::New(
New(Isolate*, int n, PretenureFlag pretenure); Isolate*, int n, PretenureFlag pretenure, MinimumCapacity capacity_option);
template Handle<GlobalDictionary> template Handle<GlobalDictionary>
Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name> >::New( Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>::New(
Isolate*, int n, PretenureFlag pretenure); Isolate*, int n, PretenureFlag pretenure, MinimumCapacity capacity_option);
template Handle<SeededNumberDictionary> template Handle<SeededNumberDictionary>
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
...@@ -17230,17 +17233,13 @@ void CompilationCacheTable::Remove(Object* value) { ...@@ -17230,17 +17233,13 @@ void CompilationCacheTable::Remove(Object* value) {
return; return;
} }
template <typename Derived, typename Shape, typename Key>
template<typename Derived, typename Shape, typename Key>
Handle<Derived> Dictionary<Derived, Shape, Key>::New( Handle<Derived> Dictionary<Derived, Shape, Key>::New(
Isolate* isolate, Isolate* isolate, int at_least_space_for, PretenureFlag pretenure,
int at_least_space_for, MinimumCapacity capacity_option) {
PretenureFlag pretenure) {
DCHECK(0 <= at_least_space_for); DCHECK(0 <= at_least_space_for);
Handle<Derived> dict = DerivedHashTable::New(isolate, Handle<Derived> dict = DerivedHashTable::New(isolate, at_least_space_for,
at_least_space_for, capacity_option, pretenure);
USE_DEFAULT_MINIMUM_CAPACITY,
pretenure);
// Initialize the next enumeration index. // Initialize the next enumeration index.
dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex); dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex);
......
...@@ -3512,9 +3512,9 @@ class Dictionary: public HashTable<Derived, Shape, Key> { ...@@ -3512,9 +3512,9 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
// Creates a new dictionary. // Creates a new dictionary.
MUST_USE_RESULT static Handle<Derived> New( MUST_USE_RESULT static Handle<Derived> New(
Isolate* isolate, Isolate* isolate, int at_least_space_for,
int at_least_space_for, PretenureFlag pretenure = NOT_TENURED,
PretenureFlag pretenure = NOT_TENURED); MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY);
// Ensures that a new dictionary is created when the capacity is checked. // Ensures that a new dictionary is created when the capacity is checked.
void SetRequiresCopyOnCapacityChange(); void SetRequiresCopyOnCapacityChange();
......
...@@ -100,8 +100,12 @@ Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New(Isolate* isolate, ...@@ -100,8 +100,12 @@ Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New(Isolate* isolate,
// Add names to NamesTable. // Add names to NamesTable.
const int name_count = spec->name_count(); const int name_count = spec->name_count();
Handle<UnseededNumberDictionary> names = Handle<UnseededNumberDictionary> names;
UnseededNumberDictionary::New(isolate, name_count); if (name_count) {
names = UnseededNumberDictionary::New(
isolate, base::bits::RoundUpToPowerOfTwo32(name_count), TENURED,
USE_CUSTOM_MINIMUM_CAPACITY);
}
int name_index = 0; int name_index = 0;
for (int i = 0; i < slot_count; i++) { for (int i = 0; i < slot_count; i++) {
...@@ -115,7 +119,8 @@ Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New(Isolate* isolate, ...@@ -115,7 +119,8 @@ Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New(Isolate* isolate,
} }
} }
DCHECK_EQ(name_count, name_index); DCHECK_EQ(name_count, name_index);
metadata->set(kNamesTableIndex, *names); metadata->set(kNamesTableIndex,
name_count ? static_cast<Object*>(*names) : Smi::FromInt(0));
// It's important that the TypeFeedbackMetadata have a COW map, since it's // It's important that the TypeFeedbackMetadata have a COW map, since it's
// pointed to by both a SharedFunctionInfo and indirectly by closures through // pointed to by both a SharedFunctionInfo and indirectly by closures through
......
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