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

Side by Side Diff: src/objects-inl.h

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/objects-debug.cc ('k') | src/ppc/code-stubs-ppc.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 // Review notes: 5 // Review notes:
6 // 6 //
7 // - The use of macros in these inline functions may seem superfluous 7 // - The use of macros in these inline functions may seem superfluous
8 // but it is absolutely needed to make sure gcc generates optimal 8 // but it is absolutely needed to make sure gcc generates optimal
9 // code. gcc is not happy when attempting to inline too deep. 9 // code. gcc is not happy when attempting to inline too deep.
10 // 10 //
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 if (filter & SKIP_STRINGS) return true; 298 if (filter & SKIP_STRINGS) return true;
299 } 299 }
300 return false; 300 return false;
301 } 301 }
302 302
303 303
304 Handle<Object> Object::NewStorageFor(Isolate* isolate, 304 Handle<Object> Object::NewStorageFor(Isolate* isolate,
305 Handle<Object> object, 305 Handle<Object> object,
306 Representation representation) { 306 Representation representation) {
307 if (representation.IsSmi() && object->IsUninitialized(isolate)) { 307 if (representation.IsSmi() && object->IsUninitialized(isolate)) {
308 return handle(Smi::FromInt(0), isolate); 308 return handle(Smi::kZero, isolate);
309 } 309 }
310 if (!representation.IsDouble()) return object; 310 if (!representation.IsDouble()) return object;
311 double value; 311 double value;
312 if (object->IsUninitialized(isolate)) { 312 if (object->IsUninitialized(isolate)) {
313 value = 0; 313 value = 0;
314 } else if (object->IsMutableHeapNumber()) { 314 } else if (object->IsMutableHeapNumber()) {
315 value = HeapNumber::cast(*object)->value(); 315 value = HeapNumber::cast(*object)->value();
316 } else { 316 } else {
317 value = object->Number(); 317 value = object->Number();
318 } 318 }
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 } 1582 }
1583 1583
1584 1584
1585 FixedArrayBase* JSObject::elements() const { 1585 FixedArrayBase* JSObject::elements() const {
1586 Object* array = READ_FIELD(this, kElementsOffset); 1586 Object* array = READ_FIELD(this, kElementsOffset);
1587 return static_cast<FixedArrayBase*>(array); 1587 return static_cast<FixedArrayBase*>(array);
1588 } 1588 }
1589 1589
1590 1590
1591 void AllocationSite::Initialize() { 1591 void AllocationSite::Initialize() {
1592 set_transition_info(Smi::FromInt(0)); 1592 set_transition_info(Smi::kZero);
1593 SetElementsKind(GetInitialFastElementsKind()); 1593 SetElementsKind(GetInitialFastElementsKind());
1594 set_nested_site(Smi::FromInt(0)); 1594 set_nested_site(Smi::kZero);
1595 set_pretenure_data(0); 1595 set_pretenure_data(0);
1596 set_pretenure_create_count(0); 1596 set_pretenure_create_count(0);
1597 set_dependent_code(DependentCode::cast(GetHeap()->empty_fixed_array()), 1597 set_dependent_code(DependentCode::cast(GetHeap()->empty_fixed_array()),
1598 SKIP_WRITE_BARRIER); 1598 SKIP_WRITE_BARRIER);
1599 } 1599 }
1600 1600
1601 1601
1602 bool AllocationSite::IsZombie() { return pretenure_decision() == kZombie; } 1602 bool AllocationSite::IsZombie() { return pretenure_decision() == kZombie; }
1603 1603
1604 1604
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
2012 2012
2013 2013
2014 Object* WeakCell::value() const { return READ_FIELD(this, kValueOffset); } 2014 Object* WeakCell::value() const { return READ_FIELD(this, kValueOffset); }
2015 2015
2016 2016
2017 void WeakCell::clear() { 2017 void WeakCell::clear() {
2018 // Either the garbage collector is clearing the cell or we are simply 2018 // Either the garbage collector is clearing the cell or we are simply
2019 // initializing the root empty weak cell. 2019 // initializing the root empty weak cell.
2020 DCHECK(GetHeap()->gc_state() == Heap::MARK_COMPACT || 2020 DCHECK(GetHeap()->gc_state() == Heap::MARK_COMPACT ||
2021 this == GetHeap()->empty_weak_cell()); 2021 this == GetHeap()->empty_weak_cell());
2022 WRITE_FIELD(this, kValueOffset, Smi::FromInt(0)); 2022 WRITE_FIELD(this, kValueOffset, Smi::kZero);
2023 } 2023 }
2024 2024
2025 2025
2026 void WeakCell::initialize(HeapObject* val) { 2026 void WeakCell::initialize(HeapObject* val) {
2027 WRITE_FIELD(this, kValueOffset, val); 2027 WRITE_FIELD(this, kValueOffset, val);
2028 // We just have to execute the generational barrier here because we never 2028 // We just have to execute the generational barrier here because we never
2029 // mark through a weak cell and collect evacuation candidates when we process 2029 // mark through a weak cell and collect evacuation candidates when we process
2030 // all weak cells. 2030 // all weak cells.
2031 WriteBarrierMode mode = Marking::IsBlack(ObjectMarking::MarkBitFrom(this)) 2031 WriteBarrierMode mode = Marking::IsBlack(ObjectMarking::MarkBitFrom(this))
2032 ? UPDATE_WRITE_BARRIER 2032 ? UPDATE_WRITE_BARRIER
2033 : UPDATE_WEAK_WRITE_BARRIER; 2033 : UPDATE_WEAK_WRITE_BARRIER;
2034 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kValueOffset, val, mode); 2034 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kValueOffset, val, mode);
2035 } 2035 }
2036 2036
2037 2037 bool WeakCell::cleared() const { return value() == Smi::kZero; }
2038 bool WeakCell::cleared() const { return value() == Smi::FromInt(0); }
2039
2040 2038
2041 Object* WeakCell::next() const { return READ_FIELD(this, kNextOffset); } 2039 Object* WeakCell::next() const { return READ_FIELD(this, kNextOffset); }
2042 2040
2043 2041
2044 void WeakCell::set_next(Object* val, WriteBarrierMode mode) { 2042 void WeakCell::set_next(Object* val, WriteBarrierMode mode) {
2045 WRITE_FIELD(this, kNextOffset, val); 2043 WRITE_FIELD(this, kNextOffset, val);
2046 if (mode == UPDATE_WRITE_BARRIER) { 2044 if (mode == UPDATE_WRITE_BARRIER) {
2047 WRITE_BARRIER(GetHeap(), this, kNextOffset, val); 2045 WRITE_BARRIER(GetHeap(), this, kNextOffset, val);
2048 } 2046 }
2049 } 2047 }
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2462 } 2460 }
2463 2461
2464 2462
2465 bool WeakFixedArray::IsEmptySlot(int index) const { 2463 bool WeakFixedArray::IsEmptySlot(int index) const {
2466 DCHECK(index < Length()); 2464 DCHECK(index < Length());
2467 return Get(index)->IsSmi(); 2465 return Get(index)->IsSmi();
2468 } 2466 }
2469 2467
2470 2468
2471 void WeakFixedArray::Clear(int index) { 2469 void WeakFixedArray::Clear(int index) {
2472 FixedArray::cast(this)->set(index + kFirstIndex, Smi::FromInt(0)); 2470 FixedArray::cast(this)->set(index + kFirstIndex, Smi::kZero);
2473 } 2471 }
2474 2472
2475 2473
2476 int WeakFixedArray::Length() const { 2474 int WeakFixedArray::Length() const {
2477 return FixedArray::cast(this)->length() - kFirstIndex; 2475 return FixedArray::cast(this)->length() - kFirstIndex;
2478 } 2476 }
2479 2477
2480 2478
2481 int WeakFixedArray::last_used_index() const { 2479 int WeakFixedArray::last_used_index() const {
2482 return Smi::cast(FixedArray::cast(this)->get(kLastUsedIndexIndex))->value(); 2480 return Smi::cast(FixedArray::cast(this)->get(kLastUsedIndexIndex))->value();
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after
4220 #undef TYPED_ARRAY_CASE 4218 #undef TYPED_ARRAY_CASE
4221 default: 4219 default:
4222 UNREACHABLE(); 4220 UNREACHABLE();
4223 return 0; 4221 return 0;
4224 } 4222 }
4225 return element_size; 4223 return element_size;
4226 } 4224 }
4227 4225
4228 4226
4229 int FixedTypedArrayBase::DataSize(InstanceType type) { 4227 int FixedTypedArrayBase::DataSize(InstanceType type) {
4230 if (base_pointer() == Smi::FromInt(0)) return 0; 4228 if (base_pointer() == Smi::kZero) return 0;
4231 return length() * ElementSize(type); 4229 return length() * ElementSize(type);
4232 } 4230 }
4233 4231
4234 4232
4235 int FixedTypedArrayBase::DataSize() { 4233 int FixedTypedArrayBase::DataSize() {
4236 return DataSize(map()->instance_type()); 4234 return DataSize(map()->instance_type());
4237 } 4235 }
4238 4236
4239 4237
4240 int FixedTypedArrayBase::size() { 4238 int FixedTypedArrayBase::size() {
(...skipping 2669 matching lines...) Expand 10 before | Expand all | Expand 10 after
6910 6908
6911 bool JSArrayBuffer::is_shared() { return IsShared::decode(bit_field()); } 6909 bool JSArrayBuffer::is_shared() { return IsShared::decode(bit_field()); }
6912 6910
6913 6911
6914 void JSArrayBuffer::set_is_shared(bool value) { 6912 void JSArrayBuffer::set_is_shared(bool value) {
6915 set_bit_field(IsShared::update(bit_field(), value)); 6913 set_bit_field(IsShared::update(bit_field(), value));
6916 } 6914 }
6917 6915
6918 6916
6919 Object* JSArrayBufferView::byte_offset() const { 6917 Object* JSArrayBufferView::byte_offset() const {
6920 if (WasNeutered()) return Smi::FromInt(0); 6918 if (WasNeutered()) return Smi::kZero;
6921 return Object::cast(READ_FIELD(this, kByteOffsetOffset)); 6919 return Object::cast(READ_FIELD(this, kByteOffsetOffset));
6922 } 6920 }
6923 6921
6924 6922
6925 void JSArrayBufferView::set_byte_offset(Object* value, WriteBarrierMode mode) { 6923 void JSArrayBufferView::set_byte_offset(Object* value, WriteBarrierMode mode) {
6926 WRITE_FIELD(this, kByteOffsetOffset, value); 6924 WRITE_FIELD(this, kByteOffsetOffset, value);
6927 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kByteOffsetOffset, value, mode); 6925 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kByteOffsetOffset, value, mode);
6928 } 6926 }
6929 6927
6930 6928
6931 Object* JSArrayBufferView::byte_length() const { 6929 Object* JSArrayBufferView::byte_length() const {
6932 if (WasNeutered()) return Smi::FromInt(0); 6930 if (WasNeutered()) return Smi::kZero;
6933 return Object::cast(READ_FIELD(this, kByteLengthOffset)); 6931 return Object::cast(READ_FIELD(this, kByteLengthOffset));
6934 } 6932 }
6935 6933
6936 6934
6937 void JSArrayBufferView::set_byte_length(Object* value, WriteBarrierMode mode) { 6935 void JSArrayBufferView::set_byte_length(Object* value, WriteBarrierMode mode) {
6938 WRITE_FIELD(this, kByteLengthOffset, value); 6936 WRITE_FIELD(this, kByteLengthOffset, value);
6939 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kByteLengthOffset, value, mode); 6937 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kByteLengthOffset, value, mode);
6940 } 6938 }
6941 6939
6942 6940
6943 ACCESSORS(JSArrayBufferView, buffer, Object, kBufferOffset) 6941 ACCESSORS(JSArrayBufferView, buffer, Object, kBufferOffset)
6944 #ifdef VERIFY_HEAP 6942 #ifdef VERIFY_HEAP
6945 ACCESSORS(JSArrayBufferView, raw_byte_offset, Object, kByteOffsetOffset) 6943 ACCESSORS(JSArrayBufferView, raw_byte_offset, Object, kByteOffsetOffset)
6946 ACCESSORS(JSArrayBufferView, raw_byte_length, Object, kByteLengthOffset) 6944 ACCESSORS(JSArrayBufferView, raw_byte_length, Object, kByteLengthOffset)
6947 #endif 6945 #endif
6948 6946
6949 6947
6950 bool JSArrayBufferView::WasNeutered() const { 6948 bool JSArrayBufferView::WasNeutered() const {
6951 return JSArrayBuffer::cast(buffer())->was_neutered(); 6949 return JSArrayBuffer::cast(buffer())->was_neutered();
6952 } 6950 }
6953 6951
6954 6952
6955 Object* JSTypedArray::length() const { 6953 Object* JSTypedArray::length() const {
6956 if (WasNeutered()) return Smi::FromInt(0); 6954 if (WasNeutered()) return Smi::kZero;
6957 return Object::cast(READ_FIELD(this, kLengthOffset)); 6955 return Object::cast(READ_FIELD(this, kLengthOffset));
6958 } 6956 }
6959 6957
6960 6958
6961 uint32_t JSTypedArray::length_value() const { 6959 uint32_t JSTypedArray::length_value() const {
6962 if (WasNeutered()) return 0; 6960 if (WasNeutered()) return 0;
6963 uint32_t index = 0; 6961 uint32_t index = 0;
6964 CHECK(Object::cast(READ_FIELD(this, kLengthOffset))->ToArrayLength(&index)); 6962 CHECK(Object::cast(READ_FIELD(this, kLengthOffset))->ToArrayLength(&index));
6965 return index; 6963 return index;
6966 } 6964 }
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
7698 7696
7699 bool AccessorPair::IsJSAccessor(Object* obj) { 7697 bool AccessorPair::IsJSAccessor(Object* obj) {
7700 return obj->IsCallable() || obj->IsUndefined(GetIsolate()); 7698 return obj->IsCallable() || obj->IsUndefined(GetIsolate());
7701 } 7699 }
7702 7700
7703 7701
7704 template<typename Derived, typename Shape, typename Key> 7702 template<typename Derived, typename Shape, typename Key>
7705 void Dictionary<Derived, Shape, Key>::SetEntry(int entry, 7703 void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
7706 Handle<Object> key, 7704 Handle<Object> key,
7707 Handle<Object> value) { 7705 Handle<Object> value) {
7708 this->SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0))); 7706 this->SetEntry(entry, key, value, PropertyDetails(Smi::kZero));
7709 } 7707 }
7710 7708
7711 7709
7712 template<typename Derived, typename Shape, typename Key> 7710 template<typename Derived, typename Shape, typename Key>
7713 void Dictionary<Derived, Shape, Key>::SetEntry(int entry, 7711 void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
7714 Handle<Object> key, 7712 Handle<Object> key,
7715 Handle<Object> value, 7713 Handle<Object> value,
7716 PropertyDetails details) { 7714 PropertyDetails details) {
7717 Shape::SetEntry(static_cast<Derived*>(this), entry, key, value, details); 7715 Shape::SetEntry(static_cast<Derived*>(this), entry, key, value, details);
7718 } 7716 }
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
8090 if (delta == 0) return; 8088 if (delta == 0) return;
8091 int new_count = ic_generic_count() + delta; 8089 int new_count = ic_generic_count() + delta;
8092 if (new_count >= 0) { 8090 if (new_count >= 0) {
8093 new_count &= ~Smi::kMinValue; 8091 new_count &= ~Smi::kMinValue;
8094 WRITE_FIELD(this, kStorage3Offset, Smi::FromInt(new_count)); 8092 WRITE_FIELD(this, kStorage3Offset, Smi::FromInt(new_count));
8095 } 8093 }
8096 } 8094 }
8097 8095
8098 8096
8099 void TypeFeedbackInfo::initialize_storage() { 8097 void TypeFeedbackInfo::initialize_storage() {
8100 WRITE_FIELD(this, kStorage1Offset, Smi::FromInt(0)); 8098 WRITE_FIELD(this, kStorage1Offset, Smi::kZero);
8101 WRITE_FIELD(this, kStorage2Offset, Smi::FromInt(0)); 8099 WRITE_FIELD(this, kStorage2Offset, Smi::kZero);
8102 WRITE_FIELD(this, kStorage3Offset, Smi::FromInt(0)); 8100 WRITE_FIELD(this, kStorage3Offset, Smi::kZero);
8103 } 8101 }
8104 8102
8105 8103
8106 void TypeFeedbackInfo::change_own_type_change_checksum() { 8104 void TypeFeedbackInfo::change_own_type_change_checksum() {
8107 int value = Smi::cast(READ_FIELD(this, kStorage1Offset))->value(); 8105 int value = Smi::cast(READ_FIELD(this, kStorage1Offset))->value();
8108 int checksum = OwnTypeChangeChecksum::decode(value); 8106 int checksum = OwnTypeChangeChecksum::decode(value);
8109 checksum = (checksum + 1) % (1 << kTypeChangeChecksumBits); 8107 checksum = (checksum + 1) % (1 << kTypeChangeChecksumBits);
8110 value = OwnTypeChangeChecksum::update(value, checksum); 8108 value = OwnTypeChangeChecksum::update(value, checksum);
8111 // Ensure packed bit field is in Smi range. 8109 // Ensure packed bit field is in Smi range.
8112 if (value > Smi::kMaxValue) value |= Smi::kMinValue; 8110 if (value > Smi::kMaxValue) value |= Smi::kMinValue;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
8315 #undef WRITE_INT64_FIELD 8313 #undef WRITE_INT64_FIELD
8316 #undef READ_BYTE_FIELD 8314 #undef READ_BYTE_FIELD
8317 #undef WRITE_BYTE_FIELD 8315 #undef WRITE_BYTE_FIELD
8318 #undef NOBARRIER_READ_BYTE_FIELD 8316 #undef NOBARRIER_READ_BYTE_FIELD
8319 #undef NOBARRIER_WRITE_BYTE_FIELD 8317 #undef NOBARRIER_WRITE_BYTE_FIELD
8320 8318
8321 } // namespace internal 8319 } // namespace internal
8322 } // namespace v8 8320 } // namespace v8
8323 8321
8324 #endif // V8_OBJECTS_INL_H_ 8322 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects-debug.cc ('k') | src/ppc/code-stubs-ppc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698