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

Side by Side Diff: src/objects.cc

Issue 2274001: Revert r4715. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: 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 | Annotate | Revision Log
« 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 4766 matching lines...) Expand 10 before | Expand all | Expand 10 after
4777 for (; i < length; i++) { 4777 for (; i < length; i++) {
4778 hasher.AddCharacterNoIndex(chars[i]); 4778 hasher.AddCharacterNoIndex(chars[i]);
4779 } 4779 }
4780 } 4780 }
4781 return hasher.GetHashField(); 4781 return hasher.GetHashField();
4782 } 4782 }
4783 4783
4784 4784
4785 uint32_t String::ComputeAndSetHash() { 4785 uint32_t String::ComputeAndSetHash() {
4786 // Should only be called if hash code has not yet been computed. 4786 // Should only be called if hash code has not yet been computed.
4787 ASSERT(!HasHashCode()); 4787 ASSERT(!(hash_field() & kHashComputedMask));
4788 4788
4789 const int len = length(); 4789 const int len = length();
4790 4790
4791 // Compute the hash code. 4791 // Compute the hash code.
4792 uint32_t field = 0; 4792 uint32_t field = 0;
4793 if (StringShape(this).IsSequentialAscii()) { 4793 if (StringShape(this).IsSequentialAscii()) {
4794 field = HashSequentialString(SeqAsciiString::cast(this)->GetChars(), len); 4794 field = HashSequentialString(SeqAsciiString::cast(this)->GetChars(), len);
4795 } else if (StringShape(this).IsSequentialTwoByte()) { 4795 } else if (StringShape(this).IsSequentialTwoByte()) {
4796 field = HashSequentialString(SeqTwoByteString::cast(this)->GetChars(), len); 4796 field = HashSequentialString(SeqTwoByteString::cast(this)->GetChars(), len);
4797 } else { 4797 } else {
4798 StringInputBuffer buffer(this); 4798 StringInputBuffer buffer(this);
4799 field = ComputeHashField(&buffer, len); 4799 field = ComputeHashField(&buffer, len);
4800 } 4800 }
4801 4801
4802 // Store the hash code in the object. 4802 // Store the hash code in the object.
4803 set_hash_field(field); 4803 set_hash_field(field);
4804 4804
4805 // Check the hash code is there. 4805 // Check the hash code is there.
4806 ASSERT(HasHashCode()); 4806 ASSERT(hash_field() & kHashComputedMask);
4807 uint32_t result = field >> kHashShift; 4807 uint32_t result = field >> kHashShift;
4808 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. 4808 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed.
4809 return result; 4809 return result;
4810 } 4810 }
4811 4811
4812 4812
4813 bool String::ComputeArrayIndex(unibrow::CharacterStream* buffer, 4813 bool String::ComputeArrayIndex(unibrow::CharacterStream* buffer,
4814 uint32_t* index, 4814 uint32_t* index,
4815 int length) { 4815 int length) {
4816 if (length == 0 || length > kMaxArrayIndexSize) return false; 4816 if (length == 0 || length > kMaxArrayIndexSize) return false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4851 } else { 4851 } else {
4852 StringInputBuffer buffer(this); 4852 StringInputBuffer buffer(this);
4853 return ComputeArrayIndex(&buffer, index, length()); 4853 return ComputeArrayIndex(&buffer, index, length());
4854 } 4854 }
4855 } 4855 }
4856 4856
4857 4857
4858 static inline uint32_t HashField(uint32_t hash, 4858 static inline uint32_t HashField(uint32_t hash,
4859 bool is_array_index, 4859 bool is_array_index,
4860 int length = -1) { 4860 int length = -1) {
4861 uint32_t result = (hash << String::kHashShift); 4861 uint32_t result =
4862 (hash << String::kHashShift) | String::kHashComputedMask;
4862 if (is_array_index) { 4863 if (is_array_index) {
4863 // For array indexes mix the length into the hash as an array index could 4864 // For array indexes mix the length into the hash as an array index could
4864 // be zero. 4865 // be zero.
4865 ASSERT(length > 0); 4866 ASSERT(length > 0);
4866 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < 4867 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) <
4867 (1 << String::kArrayIndexValueBits)); 4868 (1 << String::kArrayIndexValueBits));
4868 result |= String::kIsArrayIndexMask; 4869 result |= String::kIsArrayIndexMask;
4869 result |= length << String::kArrayIndexHashLengthShift; 4870 result |= length << String::kArrayIndexHashLengthShift;
4870 } 4871 }
4871 return result; 4872 return result;
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
5631 } 5632 }
5632 default: 5633 default:
5633 UNREACHABLE(); 5634 UNREACHABLE();
5634 break; 5635 break;
5635 } 5636 }
5636 } 5637 }
5637 5638
5638 // General slow case. 5639 // General slow case.
5639 if (len->IsNumber()) { 5640 if (len->IsNumber()) {
5640 uint32_t length; 5641 uint32_t length;
5641 if (len->ToArrayIndex(&length)) { 5642 if (Array::IndexFromObject(len, &length)) {
5642 return SetSlowElements(len); 5643 return SetSlowElements(len);
5643 } else { 5644 } else {
5644 return ArrayLengthRangeError(); 5645 return ArrayLengthRangeError();
5645 } 5646 }
5646 } 5647 }
5647 5648
5648 // len is not a number so make the array size one and 5649 // len is not a number so make the array size one and
5649 // set only element to len. 5650 // set only element to len.
5650 Object* obj = Heap::AllocateFixedArray(1); 5651 Object* obj = Heap::AllocateFixedArray(1);
5651 if (obj->IsFailure()) return obj; 5652 if (obj->IsFailure()) return obj;
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
6055 return value; 6056 return value;
6056 } 6057 }
6057 } 6058 }
6058 6059
6059 // Check whether there is extra space in fixed array.. 6060 // Check whether there is extra space in fixed array..
6060 if (index < elms_length) { 6061 if (index < elms_length) {
6061 elms->set(index, value); 6062 elms->set(index, value);
6062 if (IsJSArray()) { 6063 if (IsJSArray()) {
6063 // Update the length of the array if needed. 6064 // Update the length of the array if needed.
6064 uint32_t array_length = 0; 6065 uint32_t array_length = 0;
6065 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_length)); 6066 CHECK(Array::IndexFromObject(JSArray::cast(this)->length(),
6067 &array_length));
6066 if (index >= array_length) { 6068 if (index >= array_length) {
6067 JSArray::cast(this)->set_length(Smi::FromInt(index + 1)); 6069 JSArray::cast(this)->set_length(Smi::FromInt(index + 1));
6068 } 6070 }
6069 } 6071 }
6070 return value; 6072 return value;
6071 } 6073 }
6072 6074
6073 // Allow gap in fast case. 6075 // Allow gap in fast case.
6074 if ((index - elms_length) < kMaxGap) { 6076 if ((index - elms_length) < kMaxGap) {
6075 // Try allocating extra space. 6077 // Try allocating extra space.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
6193 JSArray* array = JSArray::cast(this); 6195 JSArray* array = JSArray::cast(this);
6194 Object* return_value = array->JSArrayUpdateLengthFromIndex(index, 6196 Object* return_value = array->JSArrayUpdateLengthFromIndex(index,
6195 value); 6197 value);
6196 if (return_value->IsFailure()) return return_value; 6198 if (return_value->IsFailure()) return return_value;
6197 } 6199 }
6198 6200
6199 // Attempt to put this object back in fast case. 6201 // Attempt to put this object back in fast case.
6200 if (ShouldConvertToFastElements()) { 6202 if (ShouldConvertToFastElements()) {
6201 uint32_t new_length = 0; 6203 uint32_t new_length = 0;
6202 if (IsJSArray()) { 6204 if (IsJSArray()) {
6203 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&new_length)); 6205 CHECK(Array::IndexFromObject(JSArray::cast(this)->length(),
6206 &new_length));
6204 JSArray::cast(this)->set_length(Smi::FromInt(new_length)); 6207 JSArray::cast(this)->set_length(Smi::FromInt(new_length));
6205 } else { 6208 } else {
6206 new_length = NumberDictionary::cast(elements())->max_number_key() + 1; 6209 new_length = NumberDictionary::cast(elements())->max_number_key() + 1;
6207 } 6210 }
6208 Object* obj = Heap::AllocateFixedArrayWithHoles(new_length); 6211 Object* obj = Heap::AllocateFixedArrayWithHoles(new_length);
6209 if (obj->IsFailure()) return obj; 6212 if (obj->IsFailure()) return obj;
6210 SetFastElements(FixedArray::cast(obj)); 6213 SetFastElements(FixedArray::cast(obj));
6211 #ifdef DEBUG 6214 #ifdef DEBUG
6212 if (FLAG_trace_normalization) { 6215 if (FLAG_trace_normalization) {
6213 PrintF("Object elements are fast case again:\n"); 6216 PrintF("Object elements are fast case again:\n");
(...skipping 10 matching lines...) Expand all
6224 } 6227 }
6225 // All possible cases have been handled above. Add a return to avoid the 6228 // All possible cases have been handled above. Add a return to avoid the
6226 // complaints from the compiler. 6229 // complaints from the compiler.
6227 UNREACHABLE(); 6230 UNREACHABLE();
6228 return Heap::null_value(); 6231 return Heap::null_value();
6229 } 6232 }
6230 6233
6231 6234
6232 Object* JSArray::JSArrayUpdateLengthFromIndex(uint32_t index, Object* value) { 6235 Object* JSArray::JSArrayUpdateLengthFromIndex(uint32_t index, Object* value) {
6233 uint32_t old_len = 0; 6236 uint32_t old_len = 0;
6234 CHECK(length()->ToArrayIndex(&old_len)); 6237 CHECK(Array::IndexFromObject(length(), &old_len));
6235 // Check to see if we need to update the length. For now, we make 6238 // Check to see if we need to update the length. For now, we make
6236 // sure that the length stays within 32-bits (unsigned). 6239 // sure that the length stays within 32-bits (unsigned).
6237 if (index >= old_len && index != 0xffffffff) { 6240 if (index >= old_len && index != 0xffffffff) {
6238 Object* len = 6241 Object* len =
6239 Heap::NumberFromDouble(static_cast<double>(index) + 1); 6242 Heap::NumberFromDouble(static_cast<double>(index) + 1);
6240 if (len->IsFailure()) return len; 6243 if (len->IsFailure()) return len;
6241 set_length(len); 6244 set_length(len);
6242 } 6245 }
6243 return value; 6246 return value;
6244 } 6247 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
6506 // dictionary, we cannot go back to fast case. 6509 // dictionary, we cannot go back to fast case.
6507 if (dictionary->requires_slow_elements()) return false; 6510 if (dictionary->requires_slow_elements()) return false;
6508 // An object requiring access checks is never allowed to have fast 6511 // An object requiring access checks is never allowed to have fast
6509 // elements. If it had fast elements we would skip security checks. 6512 // elements. If it had fast elements we would skip security checks.
6510 if (IsAccessCheckNeeded()) return false; 6513 if (IsAccessCheckNeeded()) return false;
6511 // If the dictionary backing storage takes up roughly half as much 6514 // If the dictionary backing storage takes up roughly half as much
6512 // space as a fast-case backing storage would the array should have 6515 // space as a fast-case backing storage would the array should have
6513 // fast elements. 6516 // fast elements.
6514 uint32_t length = 0; 6517 uint32_t length = 0;
6515 if (IsJSArray()) { 6518 if (IsJSArray()) {
6516 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&length)); 6519 CHECK(Array::IndexFromObject(JSArray::cast(this)->length(), &length));
6517 } else { 6520 } else {
6518 length = dictionary->max_number_key(); 6521 length = dictionary->max_number_key();
6519 } 6522 }
6520 return static_cast<uint32_t>(dictionary->Capacity()) >= 6523 return static_cast<uint32_t>(dictionary->Capacity()) >=
6521 (length / (2 * NumberDictionary::kEntrySize)); 6524 (length / (2 * NumberDictionary::kEntrySize));
6522 } 6525 }
6523 6526
6524 6527
6525 // Certain compilers request function template instantiation when they 6528 // Certain compilers request function template instantiation when they
6526 // see the definition of the other template functions in the 6529 // see the definition of the other template functions in the
(...skipping 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after
8708 if (break_point_objects()->IsUndefined()) return 0; 8711 if (break_point_objects()->IsUndefined()) return 0;
8709 // Single beak point. 8712 // Single beak point.
8710 if (!break_point_objects()->IsFixedArray()) return 1; 8713 if (!break_point_objects()->IsFixedArray()) return 1;
8711 // Multiple break points. 8714 // Multiple break points.
8712 return FixedArray::cast(break_point_objects())->length(); 8715 return FixedArray::cast(break_point_objects())->length();
8713 } 8716 }
8714 #endif 8717 #endif
8715 8718
8716 8719
8717 } } // namespace v8::internal 8720 } } // 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