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

Side by Side Diff: src/objects.cc

Issue 2101002: Cardmarking writebarrier. (Closed)
Patch Set: fixed review comments Created 10 years, 7 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.h ('k') | src/objects-debug.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4658 matching lines...) Expand 10 before | Expand all | Expand 10 after
4669 for (; i < length; i++) { 4669 for (; i < length; i++) {
4670 hasher.AddCharacterNoIndex(chars[i]); 4670 hasher.AddCharacterNoIndex(chars[i]);
4671 } 4671 }
4672 } 4672 }
4673 return hasher.GetHashField(); 4673 return hasher.GetHashField();
4674 } 4674 }
4675 4675
4676 4676
4677 uint32_t String::ComputeAndSetHash() { 4677 uint32_t String::ComputeAndSetHash() {
4678 // Should only be called if hash code has not yet been computed. 4678 // Should only be called if hash code has not yet been computed.
4679 ASSERT(!(hash_field() & kHashComputedMask)); 4679 ASSERT(!HasHashCode());
4680 4680
4681 const int len = length(); 4681 const int len = length();
4682 4682
4683 // Compute the hash code. 4683 // Compute the hash code.
4684 uint32_t field = 0; 4684 uint32_t field = 0;
4685 if (StringShape(this).IsSequentialAscii()) { 4685 if (StringShape(this).IsSequentialAscii()) {
4686 field = HashSequentialString(SeqAsciiString::cast(this)->GetChars(), len); 4686 field = HashSequentialString(SeqAsciiString::cast(this)->GetChars(), len);
4687 } else if (StringShape(this).IsSequentialTwoByte()) { 4687 } else if (StringShape(this).IsSequentialTwoByte()) {
4688 field = HashSequentialString(SeqTwoByteString::cast(this)->GetChars(), len); 4688 field = HashSequentialString(SeqTwoByteString::cast(this)->GetChars(), len);
4689 } else { 4689 } else {
4690 StringInputBuffer buffer(this); 4690 StringInputBuffer buffer(this);
4691 field = ComputeHashField(&buffer, len); 4691 field = ComputeHashField(&buffer, len);
4692 } 4692 }
4693 4693
4694 // Store the hash code in the object. 4694 // Store the hash code in the object.
4695 set_hash_field(field); 4695 set_hash_field(field);
4696 4696
4697 // Check the hash code is there. 4697 // Check the hash code is there.
4698 ASSERT(hash_field() & kHashComputedMask); 4698 ASSERT(HasHashCode());
4699 uint32_t result = field >> kHashShift; 4699 uint32_t result = field >> kHashShift;
4700 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. 4700 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed.
4701 return result; 4701 return result;
4702 } 4702 }
4703 4703
4704 4704
4705 bool String::ComputeArrayIndex(unibrow::CharacterStream* buffer, 4705 bool String::ComputeArrayIndex(unibrow::CharacterStream* buffer,
4706 uint32_t* index, 4706 uint32_t* index,
4707 int length) { 4707 int length) {
4708 if (length == 0 || length > kMaxArrayIndexSize) return false; 4708 if (length == 0 || length > kMaxArrayIndexSize) return false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4743 } else { 4743 } else {
4744 StringInputBuffer buffer(this); 4744 StringInputBuffer buffer(this);
4745 return ComputeArrayIndex(&buffer, index, length()); 4745 return ComputeArrayIndex(&buffer, index, length());
4746 } 4746 }
4747 } 4747 }
4748 4748
4749 4749
4750 static inline uint32_t HashField(uint32_t hash, 4750 static inline uint32_t HashField(uint32_t hash,
4751 bool is_array_index, 4751 bool is_array_index,
4752 int length = -1) { 4752 int length = -1) {
4753 uint32_t result = 4753 uint32_t result = (hash << String::kHashShift);
4754 (hash << String::kHashShift) | String::kHashComputedMask;
4755 if (is_array_index) { 4754 if (is_array_index) {
4756 // For array indexes mix the length into the hash as an array index could 4755 // For array indexes mix the length into the hash as an array index could
4757 // be zero. 4756 // be zero.
4758 ASSERT(length > 0); 4757 ASSERT(length > 0);
4759 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < 4758 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) <
4760 (1 << String::kArrayIndexValueBits)); 4759 (1 << String::kArrayIndexValueBits));
4761 result |= String::kIsArrayIndexMask; 4760 result |= String::kIsArrayIndexMask;
4762 result |= length << String::kArrayIndexHashLengthShift; 4761 result |= length << String::kArrayIndexHashLengthShift;
4763 } 4762 }
4764 return result; 4763 return result;
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
5539 } 5538 }
5540 default: 5539 default:
5541 UNREACHABLE(); 5540 UNREACHABLE();
5542 break; 5541 break;
5543 } 5542 }
5544 } 5543 }
5545 5544
5546 // General slow case. 5545 // General slow case.
5547 if (len->IsNumber()) { 5546 if (len->IsNumber()) {
5548 uint32_t length; 5547 uint32_t length;
5549 if (Array::IndexFromObject(len, &length)) { 5548 if (len->ToArrayIndex(&length)) {
5550 return SetSlowElements(len); 5549 return SetSlowElements(len);
5551 } else { 5550 } else {
5552 return ArrayLengthRangeError(); 5551 return ArrayLengthRangeError();
5553 } 5552 }
5554 } 5553 }
5555 5554
5556 // len is not a number so make the array size one and 5555 // len is not a number so make the array size one and
5557 // set only element to len. 5556 // set only element to len.
5558 Object* obj = Heap::AllocateFixedArray(1); 5557 Object* obj = Heap::AllocateFixedArray(1);
5559 if (obj->IsFailure()) return obj; 5558 if (obj->IsFailure()) return obj;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
5862 return SetPropertyWithDefinedSetter(JSFunction::cast(setter), value); 5861 return SetPropertyWithDefinedSetter(JSFunction::cast(setter), value);
5863 } 5862 }
5864 } 5863 }
5865 5864
5866 // Check whether there is extra space in fixed array.. 5865 // Check whether there is extra space in fixed array..
5867 if (index < elms_length) { 5866 if (index < elms_length) {
5868 elms->set(index, value); 5867 elms->set(index, value);
5869 if (IsJSArray()) { 5868 if (IsJSArray()) {
5870 // Update the length of the array if needed. 5869 // Update the length of the array if needed.
5871 uint32_t array_length = 0; 5870 uint32_t array_length = 0;
5872 CHECK(Array::IndexFromObject(JSArray::cast(this)->length(), 5871 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_length));
5873 &array_length));
5874 if (index >= array_length) { 5872 if (index >= array_length) {
5875 JSArray::cast(this)->set_length(Smi::FromInt(index + 1)); 5873 JSArray::cast(this)->set_length(Smi::FromInt(index + 1));
5876 } 5874 }
5877 } 5875 }
5878 return value; 5876 return value;
5879 } 5877 }
5880 5878
5881 // Allow gap in fast case. 5879 // Allow gap in fast case.
5882 if ((index - elms_length) < kMaxGap) { 5880 if ((index - elms_length) < kMaxGap) {
5883 // Try allocating extra space. 5881 // Try allocating extra space.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
6014 JSArray* array = JSArray::cast(this); 6012 JSArray* array = JSArray::cast(this);
6015 Object* return_value = array->JSArrayUpdateLengthFromIndex(index, 6013 Object* return_value = array->JSArrayUpdateLengthFromIndex(index,
6016 value); 6014 value);
6017 if (return_value->IsFailure()) return return_value; 6015 if (return_value->IsFailure()) return return_value;
6018 } 6016 }
6019 6017
6020 // Attempt to put this object back in fast case. 6018 // Attempt to put this object back in fast case.
6021 if (ShouldConvertToFastElements()) { 6019 if (ShouldConvertToFastElements()) {
6022 uint32_t new_length = 0; 6020 uint32_t new_length = 0;
6023 if (IsJSArray()) { 6021 if (IsJSArray()) {
6024 CHECK(Array::IndexFromObject(JSArray::cast(this)->length(), 6022 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&new_length));
6025 &new_length));
6026 JSArray::cast(this)->set_length(Smi::FromInt(new_length)); 6023 JSArray::cast(this)->set_length(Smi::FromInt(new_length));
6027 } else { 6024 } else {
6028 new_length = NumberDictionary::cast(elements())->max_number_key() + 1; 6025 new_length = NumberDictionary::cast(elements())->max_number_key() + 1;
6029 } 6026 }
6030 Object* obj = Heap::AllocateFixedArrayWithHoles(new_length); 6027 Object* obj = Heap::AllocateFixedArrayWithHoles(new_length);
6031 if (obj->IsFailure()) return obj; 6028 if (obj->IsFailure()) return obj;
6032 SetFastElements(FixedArray::cast(obj)); 6029 SetFastElements(FixedArray::cast(obj));
6033 #ifdef DEBUG 6030 #ifdef DEBUG
6034 if (FLAG_trace_normalization) { 6031 if (FLAG_trace_normalization) {
6035 PrintF("Object elements are fast case again:\n"); 6032 PrintF("Object elements are fast case again:\n");
(...skipping 10 matching lines...) Expand all
6046 } 6043 }
6047 // All possible cases have been handled above. Add a return to avoid the 6044 // All possible cases have been handled above. Add a return to avoid the
6048 // complaints from the compiler. 6045 // complaints from the compiler.
6049 UNREACHABLE(); 6046 UNREACHABLE();
6050 return Heap::null_value(); 6047 return Heap::null_value();
6051 } 6048 }
6052 6049
6053 6050
6054 Object* JSArray::JSArrayUpdateLengthFromIndex(uint32_t index, Object* value) { 6051 Object* JSArray::JSArrayUpdateLengthFromIndex(uint32_t index, Object* value) {
6055 uint32_t old_len = 0; 6052 uint32_t old_len = 0;
6056 CHECK(Array::IndexFromObject(length(), &old_len)); 6053 CHECK(length()->ToArrayIndex(&old_len));
6057 // Check to see if we need to update the length. For now, we make 6054 // Check to see if we need to update the length. For now, we make
6058 // sure that the length stays within 32-bits (unsigned). 6055 // sure that the length stays within 32-bits (unsigned).
6059 if (index >= old_len && index != 0xffffffff) { 6056 if (index >= old_len && index != 0xffffffff) {
6060 Object* len = 6057 Object* len =
6061 Heap::NumberFromDouble(static_cast<double>(index) + 1); 6058 Heap::NumberFromDouble(static_cast<double>(index) + 1);
6062 if (len->IsFailure()) return len; 6059 if (len->IsFailure()) return len;
6063 set_length(len); 6060 set_length(len);
6064 } 6061 }
6065 return value; 6062 return value;
6066 } 6063 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
6340 // dictionary, we cannot go back to fast case. 6337 // dictionary, we cannot go back to fast case.
6341 if (dictionary->requires_slow_elements()) return false; 6338 if (dictionary->requires_slow_elements()) return false;
6342 // An object requiring access checks is never allowed to have fast 6339 // An object requiring access checks is never allowed to have fast
6343 // elements. If it had fast elements we would skip security checks. 6340 // elements. If it had fast elements we would skip security checks.
6344 if (IsAccessCheckNeeded()) return false; 6341 if (IsAccessCheckNeeded()) return false;
6345 // If the dictionary backing storage takes up roughly half as much 6342 // If the dictionary backing storage takes up roughly half as much
6346 // space as a fast-case backing storage would the array should have 6343 // space as a fast-case backing storage would the array should have
6347 // fast elements. 6344 // fast elements.
6348 uint32_t length = 0; 6345 uint32_t length = 0;
6349 if (IsJSArray()) { 6346 if (IsJSArray()) {
6350 CHECK(Array::IndexFromObject(JSArray::cast(this)->length(), &length)); 6347 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&length));
6351 } else { 6348 } else {
6352 length = dictionary->max_number_key(); 6349 length = dictionary->max_number_key();
6353 } 6350 }
6354 return static_cast<uint32_t>(dictionary->Capacity()) >= 6351 return static_cast<uint32_t>(dictionary->Capacity()) >=
6355 (length / (2 * NumberDictionary::kEntrySize)); 6352 (length / (2 * NumberDictionary::kEntrySize));
6356 } 6353 }
6357 6354
6358 6355
6359 // Certain compilers request function template instantiation when they 6356 // Certain compilers request function template instantiation when they
6360 // see the definition of the other template functions in the 6357 // see the definition of the other template functions in the
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after
8548 if (break_point_objects()->IsUndefined()) return 0; 8545 if (break_point_objects()->IsUndefined()) return 0;
8549 // Single beak point. 8546 // Single beak point.
8550 if (!break_point_objects()->IsFixedArray()) return 1; 8547 if (!break_point_objects()->IsFixedArray()) return 1;
8551 // Multiple break points. 8548 // Multiple break points.
8552 return FixedArray::cast(break_point_objects())->length(); 8549 return FixedArray::cast(break_point_objects())->length();
8553 } 8550 }
8554 #endif 8551 #endif
8555 8552
8556 8553
8557 } } // namespace v8::internal 8554 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698