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,
uint32_t>;
template Handle<SeededNumberDictionary>
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
New(Isolate*, int at_least_space_for, PretenureFlag pretenure);
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::New(
Isolate*, int at_least_space_for, PretenureFlag pretenure,
MinimumCapacity capacity_option);
template Handle<UnseededNumberDictionary>
Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
New(Isolate*, int at_least_space_for, PretenureFlag pretenure);
Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape,
uint32_t>::New(Isolate*, int at_least_space_for,
PretenureFlag pretenure,
MinimumCapacity capacity_option);
template Handle<NameDictionary>
Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >::
New(Isolate*, int n, PretenureFlag pretenure);
Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>::New(
Isolate*, int n, PretenureFlag pretenure, MinimumCapacity capacity_option);
template Handle<GlobalDictionary>
Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name> >::New(
Isolate*, int n, PretenureFlag pretenure);
Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>::New(
Isolate*, int n, PretenureFlag pretenure, MinimumCapacity capacity_option);
template Handle<SeededNumberDictionary>
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
......@@ -17230,17 +17233,13 @@ void CompilationCacheTable::Remove(Object* value) {
return;
}
template<typename Derived, typename Shape, typename Key>
template <typename Derived, typename Shape, typename Key>
Handle<Derived> Dictionary<Derived, Shape, Key>::New(
Isolate* isolate,
int at_least_space_for,
PretenureFlag pretenure) {
Isolate* isolate, int at_least_space_for, PretenureFlag pretenure,
MinimumCapacity capacity_option) {
DCHECK(0 <= at_least_space_for);
Handle<Derived> dict = DerivedHashTable::New(isolate,
at_least_space_for,
USE_DEFAULT_MINIMUM_CAPACITY,
pretenure);
Handle<Derived> dict = DerivedHashTable::New(isolate, at_least_space_for,
capacity_option, pretenure);
// Initialize the next enumeration index.
dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex);
......
......@@ -3512,9 +3512,9 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
// Creates a new dictionary.
MUST_USE_RESULT static Handle<Derived> New(
Isolate* isolate,
int at_least_space_for,
PretenureFlag pretenure = NOT_TENURED);
Isolate* isolate, int at_least_space_for,
PretenureFlag pretenure = NOT_TENURED,
MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY);
// Ensures that a new dictionary is created when the capacity is checked.
void SetRequiresCopyOnCapacityChange();
......
......@@ -100,8 +100,12 @@ Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New(Isolate* isolate,
// Add names to NamesTable.
const int name_count = spec->name_count();
Handle<UnseededNumberDictionary> names =
UnseededNumberDictionary::New(isolate, name_count);
Handle<UnseededNumberDictionary> names;
if (name_count) {
names = UnseededNumberDictionary::New(
isolate, base::bits::RoundUpToPowerOfTwo32(name_count), TENURED,
USE_CUSTOM_MINIMUM_CAPACITY);
}
int name_index = 0;
for (int i = 0; i < slot_count; i++) {
......@@ -115,7 +119,8 @@ Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New(Isolate* isolate,
}
}
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
// 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