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

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

Issue 2381843002: Add Smi::Zero and replace all Smi::FromInt(0) calls (Closed)
Patch Set: Mark Smi::kZero as V8_EXPORT_PRIVATE Created 4 years, 2 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/transitions-inl.h ('k') | src/wasm/wasm-module.cc » ('j') | 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 DCHECK_EQ(FeedbackVectorSlotKind::INVALID, kind); 84 DCHECK_EQ(FeedbackVectorSlotKind::INVALID, kind);
85 } 85 }
86 i += entry_size; 86 i += entry_size;
87 } 87 }
88 #endif 88 #endif
89 89
90 Handle<FixedArray> array = factory->NewFixedArray(length, TENURED); 90 Handle<FixedArray> array = factory->NewFixedArray(length, TENURED);
91 array->set(kSlotsCountIndex, Smi::FromInt(slot_count)); 91 array->set(kSlotsCountIndex, Smi::FromInt(slot_count));
92 // Fill the bit-vector part with zeros. 92 // Fill the bit-vector part with zeros.
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::kZero);
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 if (name_count) { 104 if (name_count) {
105 names = UnseededNumberDictionary::New(isolate, name_count, TENURED); 105 names = UnseededNumberDictionary::New(isolate, name_count, TENURED);
106 } 106 }
107 107
108 int name_index = 0; 108 int name_index = 0;
109 for (int i = 0; i < slot_count; i++) { 109 for (int i = 0; i < slot_count; i++) {
110 FeedbackVectorSlotKind kind = spec->GetKind(i); 110 FeedbackVectorSlotKind kind = spec->GetKind(i);
111 metadata->SetKind(FeedbackVectorSlot(i), kind); 111 metadata->SetKind(FeedbackVectorSlot(i), kind);
112 if (SlotRequiresName(kind)) { 112 if (SlotRequiresName(kind)) {
113 Handle<String> name = spec->GetName(name_index); 113 Handle<String> name = spec->GetName(name_index);
114 DCHECK(!name.is_null()); 114 DCHECK(!name.is_null());
115 Handle<UnseededNumberDictionary> new_names = 115 Handle<UnseededNumberDictionary> new_names =
116 UnseededNumberDictionary::AtNumberPut(names, i, name); 116 UnseededNumberDictionary::AtNumberPut(names, i, name);
117 DCHECK_EQ(*new_names, *names); 117 DCHECK_EQ(*new_names, *names);
118 names = new_names; 118 names = new_names;
119 name_index++; 119 name_index++;
120 } 120 }
121 } 121 }
122 DCHECK_EQ(name_count, name_index); 122 DCHECK_EQ(name_count, name_index);
123 metadata->set(kNamesTableIndex, 123 metadata->set(kNamesTableIndex,
124 name_count ? static_cast<Object*>(*names) : Smi::FromInt(0)); 124 name_count ? static_cast<Object*>(*names) : Smi::kZero);
125 125
126 // It's important that the TypeFeedbackMetadata have a COW map, since it's 126 // It's important that the TypeFeedbackMetadata have a COW map, since it's
127 // pointed to by both a SharedFunctionInfo and indirectly by closures through 127 // pointed to by both a SharedFunctionInfo and indirectly by closures through
128 // the TypeFeedbackVector. The serializer uses the COW map type to decide 128 // the TypeFeedbackVector. The serializer uses the COW map type to decide
129 // this object belongs in the startup snapshot and not the partial 129 // this object belongs in the startup snapshot and not the partial
130 // snapshot(s). 130 // snapshot(s).
131 metadata->set_map(isolate->heap()->fixed_cow_array_map()); 131 metadata->set_map(isolate->heap()->fixed_cow_array_map());
132 132
133 return metadata; 133 return metadata;
134 } 134 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 const int slot_count = metadata->slot_count(); 235 const int slot_count = metadata->slot_count();
236 const int length = slot_count + kReservedIndexCount; 236 const int length = slot_count + kReservedIndexCount;
237 if (length == kReservedIndexCount) { 237 if (length == kReservedIndexCount) {
238 return Handle<TypeFeedbackVector>::cast( 238 return Handle<TypeFeedbackVector>::cast(
239 factory->empty_type_feedback_vector()); 239 factory->empty_type_feedback_vector());
240 } 240 }
241 241
242 Handle<FixedArray> array = factory->NewFixedArray(length, TENURED); 242 Handle<FixedArray> array = factory->NewFixedArray(length, TENURED);
243 array->set(kMetadataIndex, *metadata); 243 array->set(kMetadataIndex, *metadata);
244 array->set(kInvocationCountIndex, Smi::FromInt(0)); 244 array->set(kInvocationCountIndex, Smi::kZero);
245 245
246 DisallowHeapAllocation no_gc; 246 DisallowHeapAllocation no_gc;
247 247
248 // Ensure we can skip the write barrier 248 // Ensure we can skip the write barrier
249 Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); 249 Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate);
250 DCHECK_EQ(*factory->uninitialized_symbol(), *uninitialized_sentinel); 250 DCHECK_EQ(*factory->uninitialized_symbol(), *uninitialized_sentinel);
251 for (int i = 0; i < slot_count;) { 251 for (int i = 0; i < slot_count;) {
252 FeedbackVectorSlot slot(i); 252 FeedbackVectorSlot slot(i);
253 FeedbackVectorSlotKind kind = metadata->GetKind(slot); 253 FeedbackVectorSlotKind kind = metadata->GetKind(slot);
254 int index = TypeFeedbackVector::GetIndex(slot); 254 int index = TypeFeedbackVector::GetIndex(slot);
255 int entry_size = TypeFeedbackMetadata::GetSlotSize(kind); 255 int entry_size = TypeFeedbackMetadata::GetSlotSize(kind);
256 256
257 Object* value; 257 Object* value;
258 if (kind == FeedbackVectorSlotKind::LOAD_GLOBAL_IC) { 258 if (kind == FeedbackVectorSlotKind::LOAD_GLOBAL_IC) {
259 value = *factory->empty_weak_cell(); 259 value = *factory->empty_weak_cell();
260 } else if (kind == FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC || 260 } else if (kind == FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC ||
261 kind == FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC) { 261 kind == FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC) {
262 value = Smi::FromInt(0); 262 value = Smi::kZero;
263 } else { 263 } else {
264 value = *uninitialized_sentinel; 264 value = *uninitialized_sentinel;
265 } 265 }
266 array->set(index, value, SKIP_WRITE_BARRIER); 266 array->set(index, value, SKIP_WRITE_BARRIER);
267 267
268 value = kind == FeedbackVectorSlotKind::CALL_IC ? Smi::FromInt(0) 268 value = kind == FeedbackVectorSlotKind::CALL_IC ? Smi::kZero
269 : *uninitialized_sentinel; 269 : *uninitialized_sentinel;
270 for (int j = 1; j < entry_size; j++) { 270 for (int j = 1; j < entry_size; j++) {
271 array->set(index + j, value, SKIP_WRITE_BARRIER); 271 array->set(index + j, value, SKIP_WRITE_BARRIER);
272 } 272 }
273 i += entry_size; 273 i += entry_size;
274 } 274 }
275 return Handle<TypeFeedbackVector>::cast(array); 275 return Handle<TypeFeedbackVector>::cast(array);
276 } 276 }
277 277
278 278
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 344 }
345 case FeedbackVectorSlotKind::KEYED_STORE_IC: { 345 case FeedbackVectorSlotKind::KEYED_STORE_IC: {
346 KeyedStoreICNexus nexus(this, slot); 346 KeyedStoreICNexus nexus(this, slot);
347 nexus.Clear(shared->code()); 347 nexus.Clear(shared->code());
348 break; 348 break;
349 } 349 }
350 case FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC: 350 case FeedbackVectorSlotKind::INTERPRETER_BINARYOP_IC:
351 case FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC: { 351 case FeedbackVectorSlotKind::INTERPRETER_COMPARE_IC: {
352 DCHECK(Get(slot)->IsSmi()); 352 DCHECK(Get(slot)->IsSmi());
353 // don't clear these smi slots. 353 // don't clear these smi slots.
354 // Set(slot, Smi::FromInt(0)); 354 // Set(slot, Smi::kZero);
355 break; 355 break;
356 } 356 }
357 case FeedbackVectorSlotKind::GENERAL: { 357 case FeedbackVectorSlotKind::GENERAL: {
358 if (obj->IsHeapObject()) { 358 if (obj->IsHeapObject()) {
359 InstanceType instance_type = 359 InstanceType instance_type =
360 HeapObject::cast(obj)->map()->instance_type(); 360 HeapObject::cast(obj)->map()->instance_type();
361 // AllocationSites are exempt from clearing. They don't store Maps 361 // AllocationSites are exempt from clearing. They don't store Maps
362 // or Code pointers which can cause memory leaks if not cleared 362 // or Code pointers which can cause memory leaks if not cleared
363 // regularly. 363 // regularly.
364 if (instance_type != ALLOCATION_SITE_TYPE) { 364 if (instance_type != ALLOCATION_SITE_TYPE) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 double const call_count = ExtractCallCount(); 650 double const call_count = ExtractCallCount();
651 return static_cast<float>(call_count / invocation_count); 651 return static_cast<float>(call_count / invocation_count);
652 } 652 }
653 653
654 void CallICNexus::Clear(Code* host) { CallIC::Clear(GetIsolate(), host, this); } 654 void CallICNexus::Clear(Code* host) { CallIC::Clear(GetIsolate(), host, this); }
655 655
656 void CallICNexus::ConfigureUninitialized() { 656 void CallICNexus::ConfigureUninitialized() {
657 Isolate* isolate = GetIsolate(); 657 Isolate* isolate = GetIsolate();
658 SetFeedback(*TypeFeedbackVector::UninitializedSentinel(isolate), 658 SetFeedback(*TypeFeedbackVector::UninitializedSentinel(isolate),
659 SKIP_WRITE_BARRIER); 659 SKIP_WRITE_BARRIER);
660 SetFeedbackExtra(Smi::FromInt(0), SKIP_WRITE_BARRIER); 660 SetFeedbackExtra(Smi::kZero, SKIP_WRITE_BARRIER);
661 } 661 }
662 662
663 void CallICNexus::ConfigureMonomorphicArray() { 663 void CallICNexus::ConfigureMonomorphicArray() {
664 Object* feedback = GetFeedback(); 664 Object* feedback = GetFeedback();
665 if (!feedback->IsAllocationSite()) { 665 if (!feedback->IsAllocationSite()) {
666 Handle<AllocationSite> new_site = 666 Handle<AllocationSite> new_site =
667 GetIsolate()->factory()->NewAllocationSite(); 667 GetIsolate()->factory()->NewAllocationSite();
668 SetFeedback(*new_site); 668 SetFeedback(*new_site);
669 } 669 }
670 SetFeedbackExtra(Smi::FromInt(1), SKIP_WRITE_BARRIER); 670 SetFeedbackExtra(Smi::FromInt(1), SKIP_WRITE_BARRIER);
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 return BinaryOperationHintFromFeedback(feedback); 1080 return BinaryOperationHintFromFeedback(feedback);
1081 } 1081 }
1082 1082
1083 CompareOperationHint CompareICNexus::GetCompareOperationFeedback() const { 1083 CompareOperationHint CompareICNexus::GetCompareOperationFeedback() const {
1084 int feedback = Smi::cast(GetFeedback())->value(); 1084 int feedback = Smi::cast(GetFeedback())->value();
1085 return CompareOperationHintFromFeedback(feedback); 1085 return CompareOperationHintFromFeedback(feedback);
1086 } 1086 }
1087 1087
1088 } // namespace internal 1088 } // namespace internal
1089 } // namespace v8 1089 } // namespace v8
OLDNEW
« no previous file with comments | « src/transitions-inl.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698