Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: src/type-feedback-vector.cc

Issue 2181303002: [ic] Avoid memory wasting when allocating names table of type feedback metadata. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/type-feedback-vector.h" 5 #include "src/type-feedback-vector.h"
6 6
7 #include "src/code-stubs.h" 7 #include "src/code-stubs.h"
8 #include "src/ic/ic.h" 8 #include "src/ic/ic.h"
9 #include "src/ic/ic-state.h" 9 #include "src/ic/ic-state.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 for (int i = 0; i < slot_kinds_length; i++) { 93 for (int i = 0; i < slot_kinds_length; i++) {
94 array->set(kReservedIndexCount + i, Smi::FromInt(0)); 94 array->set(kReservedIndexCount + i, Smi::FromInt(0));
95 } 95 }
96 96
97 Handle<TypeFeedbackMetadata> metadata = 97 Handle<TypeFeedbackMetadata> metadata =
98 Handle<TypeFeedbackMetadata>::cast(array); 98 Handle<TypeFeedbackMetadata>::cast(array);
99 99
100 // Add names to NamesTable. 100 // Add names to NamesTable.
101 const int name_count = spec->name_count(); 101 const int name_count = spec->name_count();
102 102
103 Handle<UnseededNumberDictionary> names = 103 Handle<UnseededNumberDictionary> names;
104 UnseededNumberDictionary::New(isolate, name_count); 104 if (name_count) {
105 names = UnseededNumberDictionary::New(
106 isolate, base::bits::RoundUpToPowerOfTwo32(name_count), TENURED,
107 USE_CUSTOM_MINIMUM_CAPACITY);
108 }
105 109
106 int name_index = 0; 110 int name_index = 0;
107 for (int i = 0; i < slot_count; i++) { 111 for (int i = 0; i < slot_count; i++) {
108 FeedbackVectorSlotKind kind = spec->GetKind(i); 112 FeedbackVectorSlotKind kind = spec->GetKind(i);
109 metadata->SetKind(FeedbackVectorSlot(i), kind); 113 metadata->SetKind(FeedbackVectorSlot(i), kind);
110 if (SlotRequiresName(kind)) { 114 if (SlotRequiresName(kind)) {
111 Handle<String> name = spec->GetName(name_index); 115 Handle<String> name = spec->GetName(name_index);
112 DCHECK(!name.is_null()); 116 DCHECK(!name.is_null());
113 names = UnseededNumberDictionary::AtNumberPut(names, i, name); 117 names = UnseededNumberDictionary::AtNumberPut(names, i, name);
114 name_index++; 118 name_index++;
115 } 119 }
116 } 120 }
117 DCHECK_EQ(name_count, name_index); 121 DCHECK_EQ(name_count, name_index);
118 metadata->set(kNamesTableIndex, *names); 122 metadata->set(kNamesTableIndex,
123 name_count ? static_cast<Object*>(*names) : Smi::FromInt(0));
119 124
120 // It's important that the TypeFeedbackMetadata have a COW map, since it's 125 // It's important that the TypeFeedbackMetadata have a COW map, since it's
121 // pointed to by both a SharedFunctionInfo and indirectly by closures through 126 // pointed to by both a SharedFunctionInfo and indirectly by closures through
122 // the TypeFeedbackVector. The serializer uses the COW map type to decide 127 // the TypeFeedbackVector. The serializer uses the COW map type to decide
123 // this object belongs in the startup snapshot and not the partial 128 // this object belongs in the startup snapshot and not the partial
124 // snapshot(s). 129 // snapshot(s).
125 metadata->set_map(isolate->heap()->fixed_cow_array_map()); 130 metadata->set_map(isolate->heap()->fixed_cow_array_map());
126 131
127 return metadata; 132 return metadata;
128 } 133 }
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 1015
1011 IcCheckType KeyedStoreICNexus::GetKeyType() const { 1016 IcCheckType KeyedStoreICNexus::GetKeyType() const {
1012 Object* feedback = GetFeedback(); 1017 Object* feedback = GetFeedback();
1013 if (feedback == *TypeFeedbackVector::MegamorphicSentinel(GetIsolate())) { 1018 if (feedback == *TypeFeedbackVector::MegamorphicSentinel(GetIsolate())) {
1014 return static_cast<IcCheckType>(Smi::cast(GetFeedbackExtra())->value()); 1019 return static_cast<IcCheckType>(Smi::cast(GetFeedbackExtra())->value());
1015 } 1020 }
1016 return IsPropertyNameFeedback(feedback) ? PROPERTY : ELEMENT; 1021 return IsPropertyNameFeedback(feedback) ? PROPERTY : ELEMENT;
1017 } 1022 }
1018 } // namespace internal 1023 } // namespace internal
1019 } // namespace v8 1024 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698