Changeset 64937 in webkit
- Timestamp:
- Aug 7, 2010 10:29:38 PM (14 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r64934 r64937 1 2010-08-07 Michael Saboff <msaboff@apple.com> 2 3 Reviewed by Geoffrey Garen. 4 5 Revert JSArray to point to the beginning of the contained ArrayStorage 6 struct. This is described in 7 https://bugs.webkit.org/show_bug.cgi?id=43526. 8 9 * jit/JITPropertyAccess.cpp: 10 (JSC::JIT::emit_op_get_by_val): 11 (JSC::JIT::emit_op_put_by_val): 12 (JSC::JIT::privateCompilePatchGetArrayLength): 13 * jit/JITPropertyAccess32_64.cpp: 14 (JSC::JIT::emit_op_get_by_val): 15 (JSC::JIT::emit_op_put_by_val): 16 (JSC::JIT::privateCompilePatchGetArrayLength): 17 * runtime/JSArray.cpp: 18 (JSC::JSArray::JSArray): 19 (JSC::JSArray::~JSArray): 20 (JSC::JSArray::getOwnPropertySlot): 21 (JSC::JSArray::getOwnPropertyDescriptor): 22 (JSC::JSArray::put): 23 (JSC::JSArray::putSlowCase): 24 (JSC::JSArray::deleteProperty): 25 (JSC::JSArray::getOwnPropertyNames): 26 (JSC::JSArray::getNewVectorLength): 27 (JSC::JSArray::increaseVectorLength): 28 (JSC::JSArray::increaseVectorPrefixLength): 29 (JSC::JSArray::setLength): 30 (JSC::JSArray::pop): 31 (JSC::JSArray::push): 32 (JSC::JSArray::shiftCount): 33 (JSC::JSArray::unshiftCount): 34 (JSC::JSArray::sortNumeric): 35 (JSC::JSArray::sort): 36 (JSC::JSArray::fillArgList): 37 (JSC::JSArray::copyToRegisters): 38 (JSC::JSArray::compactForSorting): 39 (JSC::JSArray::subclassData): 40 (JSC::JSArray::setSubclassData): 41 (JSC::JSArray::checkConsistency): 42 * runtime/JSArray.h: 43 (JSC::JSArray::length): 44 (JSC::JSArray::canGetIndex): 45 (JSC::JSArray::getIndex): 46 (JSC::JSArray::setIndex): 47 (JSC::JSArray::uncheckedSetIndex): 48 (JSC::JSArray::markChildrenDirect): 49 1 50 2010-08-07 Kwang Yul Seo <skyul@company100.net> 2 51 -
trunk/JavaScriptCore/jit/JITPropertyAccess.cpp
r64649 r64937 107 107 addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsArrayVPtr))); 108 108 109 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_ vector)), regT2);109 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT2); 110 110 addSlowCase(branch32(AboveOrEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength)))); 111 111 112 loadPtr(BaseIndex(regT2, regT1, ScalePtr ), regT0);112 loadPtr(BaseIndex(regT2, regT1, ScalePtr, OBJECT_OFFSETOF(ArrayStorage, m_vector[0])), regT0); 113 113 addSlowCase(branchTestPtr(Zero, regT0)); 114 114 … … 218 218 addSlowCase(branch32(AboveOrEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength)))); 219 219 220 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_ vector)), regT2);221 Jump empty = branchTestPtr(Zero, BaseIndex(regT2, regT1, ScalePtr ));220 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT2); 221 Jump empty = branchTestPtr(Zero, BaseIndex(regT2, regT1, ScalePtr, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]))); 222 222 223 223 Label storeResult(this); 224 224 emitGetVirtualRegister(value, regT0); 225 storePtr(regT0, BaseIndex(regT2, regT1, ScalePtr ));225 storePtr(regT0, BaseIndex(regT2, regT1, ScalePtr, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]))); 226 226 Jump end = jump(); 227 227 228 228 empty.link(this); 229 add32(Imm32(1), Address(regT2, OBJECT_OFFSETOF(ArrayStorage, m_numValuesInVector) -OBJECT_OFFSETOF(ArrayStorage, m_vector)));230 branch32(Below, regT1, Address(regT2, OBJECT_OFFSETOF(ArrayStorage, m_length) -OBJECT_OFFSETOF(ArrayStorage, m_vector))).linkTo(storeResult, this);229 add32(Imm32(1), Address(regT2, OBJECT_OFFSETOF(ArrayStorage, m_numValuesInVector))); 230 branch32(Below, regT1, Address(regT2, OBJECT_OFFSETOF(ArrayStorage, m_length))).linkTo(storeResult, this); 231 231 232 232 move(regT1, regT0); 233 233 add32(Imm32(1), regT0); 234 store32(regT0, Address(regT2, OBJECT_OFFSETOF(ArrayStorage, m_length) -OBJECT_OFFSETOF(ArrayStorage, m_vector)));234 store32(regT0, Address(regT2, OBJECT_OFFSETOF(ArrayStorage, m_length))); 235 235 jump().linkTo(storeResult, this); 236 236 … … 737 737 738 738 // Checks out okay! - get the length from the storage 739 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_ vector)), regT3);740 load32(Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_length) -OBJECT_OFFSETOF(ArrayStorage, m_vector)), regT2);739 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT3); 740 load32(Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_length)), regT2); 741 741 Jump failureCases2 = branch32(Above, regT2, Imm32(JSImmediate::maxImmediateInt)); 742 742 -
trunk/JavaScriptCore/jit/JITPropertyAccess32_64.cpp
r64649 r64937 315 315 addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsArrayVPtr))); 316 316 317 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_ vector)), regT3);317 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT3); 318 318 addSlowCase(branch32(AboveOrEqual, regT2, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength)))); 319 319 320 load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF( JSValue, u.asBits.tag)), regT1); // tag321 load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF( JSValue, u.asBits.payload)), regT0); // payload320 load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT1); // tag 321 load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT0); // payload 322 322 addSlowCase(branch32(Equal, regT1, Imm32(JSValue::EmptyValueTag))); 323 323 … … 368 368 addSlowCase(branch32(AboveOrEqual, regT2, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength)))); 369 369 370 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_ vector)), regT3);371 372 Jump empty = branch32(Equal, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF( JSValue, u.asBits.tag)), Imm32(JSValue::EmptyValueTag));370 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT3); 371 372 Jump empty = branch32(Equal, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), Imm32(JSValue::EmptyValueTag)); 373 373 374 374 Label storeResult(this); 375 375 emitLoad(value, regT1, regT0); 376 store32(regT0, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF( JSValue, u.asBits.payload))); // payload377 store32(regT1, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF( JSValue, u.asBits.tag))); // tag376 store32(regT0, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.payload))); // payload 377 store32(regT1, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.tag))); // tag 378 378 Jump end = jump(); 379 379 380 380 empty.link(this); 381 add32(Imm32(1), Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_numValuesInVector) -OBJECT_OFFSETOF(ArrayStorage, m_vector)));382 branch32(Below, regT2, Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_length) -OBJECT_OFFSETOF(ArrayStorage, m_vector))).linkTo(storeResult, this);381 add32(Imm32(1), Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_numValuesInVector))); 382 branch32(Below, regT2, Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_length))).linkTo(storeResult, this); 383 383 384 384 add32(Imm32(1), regT2, regT0); 385 store32(regT0, Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_length) -OBJECT_OFFSETOF(ArrayStorage, m_vector)));385 store32(regT0, Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_length))); 386 386 jump().linkTo(storeResult, this); 387 387 … … 745 745 746 746 // Checks out okay! - get the length from the storage 747 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_ vector)), regT2);748 load32(Address(regT2, OBJECT_OFFSETOF(ArrayStorage, m_length) -OBJECT_OFFSETOF(ArrayStorage, m_vector)), regT2);747 loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT2); 748 load32(Address(regT2, OBJECT_OFFSETOF(ArrayStorage, m_length)), regT2); 749 749 750 750 Jump failureCases2 = branch32(Above, regT2, Imm32(INT_MAX)); -
trunk/JavaScriptCore/runtime/JSArray.cpp
r64773 r64937 132 132 unsigned initialCapacity = 0; 133 133 134 ArrayStorage*storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity)));135 storage->m_allocBase =storage;134 m_storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity))); 135 m_storage->m_allocBase = m_storage; 136 136 m_indexBias = 0; 137 setArrayStorage(storage);138 137 m_vectorLength = initialCapacity; 139 138 … … 150 149 unsigned initialCapacity = 0; 151 150 152 ArrayStorage*storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity)));153 storage->m_allocBase =storage;151 m_storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity))); 152 m_storage->m_allocBase = m_storage; 154 153 m_indexBias = 0; 155 setArrayStorage(storage);156 154 m_vectorLength = initialCapacity; 157 155 … … 170 168 initialCapacity = min(BASE_VECTOR_LEN, MIN_SPARSE_ARRAY_INDEX); 171 169 172 ArrayStorage*storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialCapacity)));173 storage->m_allocBase =storage;174 storage->m_length = initialLength;170 m_storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialCapacity))); 171 m_storage->m_allocBase = m_storage; 172 m_storage->m_length = initialLength; 175 173 m_indexBias = 0; 176 174 m_vectorLength = initialCapacity; 177 setArrayStorage(storage); 178 storage->m_sparseValueMap = 0; 179 storage->subclassData = 0; 180 storage->reportedMapCapacity = 0; 175 m_storage->m_sparseValueMap = 0; 176 m_storage->subclassData = 0; 177 m_storage->reportedMapCapacity = 0; 181 178 182 179 if (creationMode == CreateCompact) { 183 180 #if CHECK_ARRAY_CONSISTENCY 184 storage->m_inCompactInitialization = !!initialCapacity;181 m_storage->m_inCompactInitialization = !!initialCapacity; 185 182 #endif 186 storage->m_length = 0;187 storage->m_numValuesInVector = initialCapacity;183 m_storage->m_length = 0; 184 m_storage->m_numValuesInVector = initialCapacity; 188 185 } else { 189 186 #if CHECK_ARRAY_CONSISTENCY 190 187 storage->m_inCompactInitialization = false; 191 188 #endif 192 storage->m_length = initialLength;193 storage->m_numValuesInVector = 0;194 JSValue* vector = m_ vector;189 m_storage->m_length = initialLength; 190 m_storage->m_numValuesInVector = 0; 191 JSValue* vector = m_storage->m_vector; 195 192 for (size_t i = 0; i < initialCapacity; ++i) 196 193 vector[i] = JSValue(); … … 207 204 unsigned initialCapacity = list.size(); 208 205 209 ArrayStorage*storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialCapacity)));210 storage->m_allocBase =storage;206 m_storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialCapacity))); 207 m_storage->m_allocBase = m_storage; 211 208 m_indexBias = 0; 212 storage->m_length = initialCapacity;209 m_storage->m_length = initialCapacity; 213 210 m_vectorLength = initialCapacity; 214 storage->m_numValuesInVector = initialCapacity;215 storage->m_sparseValueMap = 0;216 storage->subclassData = 0;217 storage->reportedMapCapacity = 0;211 m_storage->m_numValuesInVector = initialCapacity; 212 m_storage->m_sparseValueMap = 0; 213 m_storage->subclassData = 0; 214 m_storage->reportedMapCapacity = 0; 218 215 #if CHECK_ARRAY_CONSISTENCY 219 storage->m_inCompactInitialization = false;216 m_storage->m_inCompactInitialization = false; 220 217 #endif 221 setArrayStorage(storage);222 218 223 219 size_t i = 0; 224 JSValue* vector = m_ vector;220 JSValue* vector = m_storage->m_vector; 225 221 ArgList::const_iterator end = list.end(); 226 222 for (ArgList::const_iterator it = list.begin(); it != end; ++it, ++i) … … 237 233 checkConsistency(DestructorConsistencyCheck); 238 234 239 ArrayStorage* storage = arrayStorage(); 240 delete storage->m_sparseValueMap; 241 fastFree(storage->m_allocBase); 235 delete m_storage->m_sparseValueMap; 236 fastFree(m_storage->m_allocBase); 242 237 } 243 238 244 239 bool JSArray::getOwnPropertySlot(ExecState* exec, unsigned i, PropertySlot& slot) 245 240 { 246 ArrayStorage* storage = arrayStorage();241 ArrayStorage* storage = m_storage; 247 242 248 243 if (i >= storage->m_length) { … … 253 248 254 249 if (i < m_vectorLength) { 255 JSValue& valueSlot = m_vector[i];250 JSValue& valueSlot = storage->m_vector[i]; 256 251 if (valueSlot) { 257 252 slot.setValueSlot(&valueSlot); … … 293 288 } 294 289 295 ArrayStorage* storage = arrayStorage();290 ArrayStorage* storage = m_storage; 296 291 297 292 bool isArrayIndex; … … 301 296 return false; 302 297 if (i < m_vectorLength) { 303 JSValue& value = m_vector[i];298 JSValue& value = storage->m_vector[i]; 304 299 if (value) { 305 300 descriptor.setDescriptor(value, 0); … … 346 341 checkConsistency(); 347 342 348 ArrayStorage* storage = arrayStorage();343 ArrayStorage* storage = m_storage; 349 344 350 345 unsigned length = storage->m_length; … … 355 350 356 351 if (i < m_vectorLength) { 357 JSValue& valueSlot = m_vector[i];352 JSValue& valueSlot = storage->m_vector[i]; 358 353 if (valueSlot) { 359 354 valueSlot = value; … … 372 367 NEVER_INLINE void JSArray::putSlowCase(ExecState* exec, unsigned i, JSValue value) 373 368 { 374 ArrayStorage* storage = arrayStorage();369 ArrayStorage* storage = m_storage; 375 370 376 371 SparseArrayValueMap* map = storage->m_sparseValueMap; … … 410 405 if (!map || map->isEmpty()) { 411 406 if (increaseVectorLength(i + 1)) { 412 m_vector[i] = value; 413 ++arrayStorage()->m_numValuesInVector; 407 storage = m_storage; 408 storage->m_vector[i] = value; 409 ++storage->m_numValuesInVector; 414 410 checkConsistency(); 415 411 } else … … 446 442 } 447 443 448 storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));449 storage->m_allocBase = baseStorage;450 s etArrayStorage(storage);444 m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue)); 445 m_storage->m_allocBase = baseStorage; 446 storage = m_storage; 451 447 452 448 unsigned vectorLength = m_vectorLength; 449 JSValue* vector = storage->m_vector; 453 450 454 451 if (newNumValuesInVector == storage->m_numValuesInVector + 1) { 455 452 for (unsigned j = vectorLength; j < newVectorLength; ++j) 456 m_vector[j] = JSValue();453 vector[j] = JSValue(); 457 454 if (i > MIN_SPARSE_ARRAY_INDEX) 458 455 map->remove(i); 459 456 } else { 460 457 for (unsigned j = vectorLength; j < max(vectorLength, MIN_SPARSE_ARRAY_INDEX); ++j) 461 m_vector[j] = JSValue();458 vector[j] = JSValue(); 462 459 for (unsigned j = max(vectorLength, MIN_SPARSE_ARRAY_INDEX); j < newVectorLength; ++j) 463 m_vector[j] = map->take(j);460 vector[j] = map->take(j); 464 461 } 465 462 … … 469 466 storage->m_numValuesInVector = newNumValuesInVector; 470 467 471 m_vector[i] = value;468 storage->m_vector[i] = value; 472 469 473 470 checkConsistency(); … … 493 490 checkConsistency(); 494 491 495 ArrayStorage* storage = arrayStorage();492 ArrayStorage* storage = m_storage; 496 493 497 494 if (i < m_vectorLength) { 498 JSValue& valueSlot = m_vector[i];495 JSValue& valueSlot = storage->m_vector[i]; 499 496 if (!valueSlot) { 500 497 checkConsistency(); … … 532 529 // which almost certainly means a different structure for PropertyNameArray. 533 530 534 ArrayStorage* storage = arrayStorage();531 ArrayStorage* storage = m_storage; 535 532 536 533 unsigned usedVectorLength = min(storage->m_length, m_vectorLength); 537 534 for (unsigned i = 0; i < usedVectorLength; ++i) { 538 if ( m_vector[i])535 if (storage->m_vector[i]) 539 536 propertyNames.add(Identifier::from(exec, i)); 540 537 } … … 557 554 558 555 unsigned increasedLength; 559 unsigned length = arrayStorage()->m_length;556 unsigned length = m_storage->m_length; 560 557 561 558 if (desiredLength < length) … … 584 581 // to the vector. Callers have to account for that, because they can do it more efficiently. 585 582 586 ArrayStorage* storage = arrayStorage();583 ArrayStorage* storage = m_storage; 587 584 588 585 unsigned vectorLength = m_vectorLength; … … 595 592 return false; 596 593 597 storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue)); 598 storage->m_allocBase = baseStorage; 599 setArrayStorage(storage); 600 601 JSValue* vector = m_vector; 594 storage = m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue)); 595 m_storage->m_allocBase = baseStorage; 596 597 JSValue* vector = storage->m_vector; 602 598 for (unsigned i = vectorLength; i < newVectorLength; ++i) 603 599 vector[i] = JSValue(); … … 615 611 // to the vector. Callers have to account for that, because they can do it more efficiently. 616 612 617 ArrayStorage* storage = arrayStorage(); 618 ArrayStorage* newStorage; 613 ArrayStorage* storage = m_storage; 619 614 620 615 unsigned vectorLength = m_vectorLength; … … 629 624 m_indexBias += newVectorLength - newLength; 630 625 631 newStorage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(newBaseStorage) + m_indexBias * sizeof(JSValue));632 633 memcpy( newStorage, storage, storageSize(0));634 memcpy(& newStorage->m_vector[newLength - m_vectorLength], &storage->m_vector[0], vectorLength * sizeof(JSValue));635 636 newStorage->m_allocBase = newBaseStorage;626 m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(newBaseStorage) + m_indexBias * sizeof(JSValue)); 627 628 memcpy(m_storage, storage, storageSize(0)); 629 memcpy(&m_storage->m_vector[newLength - m_vectorLength], &storage->m_vector[0], vectorLength * sizeof(JSValue)); 630 631 m_storage->m_allocBase = newBaseStorage; 637 632 m_vectorLength = newLength; 638 633 639 634 fastFree(storage->m_allocBase); 640 635 641 setArrayStorage(newStorage);642 643 636 Heap::heap(this)->reportExtraMemoryCost(storageSize(newVectorLength) - storageSize(vectorLength)); 644 637 … … 649 642 void JSArray::setLength(unsigned newLength) 650 643 { 644 ArrayStorage* storage = m_storage; 645 651 646 #if CHECK_ARRAY_CONSISTENCY 652 if (! m_storage->m_inCompactInitialization)647 if (!storage->m_inCompactInitialization) 653 648 checkConsistency(); 654 649 else 655 m_storage->m_inCompactInitialization = false;650 storage->m_inCompactInitialization = false; 656 651 #endif 657 652 658 ArrayStorage* storage = arrayStorage();659 660 653 unsigned length = storage->m_length; 661 654 … … 663 656 unsigned usedVectorLength = min(length, m_vectorLength); 664 657 for (unsigned i = newLength; i < usedVectorLength; ++i) { 665 JSValue& valueSlot = m_vector[i];658 JSValue& valueSlot = storage->m_vector[i]; 666 659 bool hadValue = valueSlot; 667 660 valueSlot = JSValue(); … … 692 685 checkConsistency(); 693 686 694 ArrayStorage* storage = arrayStorage();687 ArrayStorage* storage = m_storage; 695 688 696 689 unsigned length = storage->m_length; … … 703 696 704 697 if (length < m_vectorLength) { 705 JSValue& valueSlot = m_vector[length];698 JSValue& valueSlot = storage->m_vector[length]; 706 699 if (valueSlot) { 707 700 --storage->m_numValuesInVector; … … 736 729 checkConsistency(); 737 730 738 ArrayStorage* storage = arrayStorage();731 ArrayStorage* storage = m_storage; 739 732 740 733 if (storage->m_length < m_vectorLength) { 741 m_vector[storage->m_length] = value;734 storage->m_vector[storage->m_length] = value; 742 735 ++storage->m_numValuesInVector; 743 736 ++storage->m_length; … … 750 743 if (!map || map->isEmpty()) { 751 744 if (increaseVectorLength(storage->m_length + 1)) { 752 storage = arrayStorage();753 m_vector[storage->m_length] = value;745 storage = m_storage; 746 storage->m_vector[storage->m_length] = value; 754 747 ++storage->m_numValuesInVector; 755 748 ++storage->m_length; … … 770 763 ASSERT(count > 0); 771 764 772 ArrayStorage* storage = arrayStorage();765 ArrayStorage* storage = m_storage; 773 766 774 767 unsigned oldLength = storage->m_length; … … 783 776 // 15.4.4.9 steps 11 through 13. 784 777 for (unsigned i = count; i < oldLength; ++i) { 785 if ((i >= m_vectorLength) || (!m_ vector[i])) {778 if ((i >= m_vectorLength) || (!m_storage->m_vector[i])) { 786 779 PropertySlot slot(this); 787 780 JSValue p = prototype(); … … 791 784 } 792 785 793 storage = arrayStorage(); // The put() above could have grown the vector and realloc'ed storage.786 storage = m_storage; // The put() above could have grown the vector and realloc'ed storage. 794 787 795 788 // Need to decrement numValuesInvector based on number of real entries 796 789 for (unsigned i = 0; i < (unsigned)count; ++i) 797 if ((i < m_vectorLength) && ( m_vector[i]))790 if ((i < m_vectorLength) && (storage->m_vector[i])) 798 791 --storage->m_numValuesInVector; 799 792 } else … … 810 803 char* newBaseStorage = reinterpret_cast<char*>(storage) + count * sizeof(JSValue); 811 804 memmove(newBaseStorage, storage, storageSize(0)); 812 storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);805 m_storage = reinterpret_cast<ArrayStorage*>(newBaseStorage); 813 806 814 807 m_indexBias += count; 815 setArrayStorage(storage);816 808 } 817 809 } … … 820 812 void JSArray::unshiftCount(ExecState* exec, int count) 821 813 { 822 ArrayStorage* storage = arrayStorage();814 ArrayStorage* storage = m_storage; 823 815 824 816 ASSERT(m_indexBias >= 0); … … 833 825 // 15.4.4.13 steps 8 through 10. 834 826 for (unsigned i = 0; i < length; ++i) { 835 if ((i >= m_vectorLength) || (!m_ vector[i])) {827 if ((i >= m_vectorLength) || (!m_storage->m_vector[i])) { 836 828 PropertySlot slot(this); 837 829 JSValue p = prototype(); … … 842 834 } 843 835 844 storage = arrayStorage(); // The put() above could have grown the vector and realloc'ed storage.836 storage = m_storage; // The put() above could have grown the vector and realloc'ed storage. 845 837 846 838 if (m_indexBias >= count) { … … 848 840 char* newBaseStorage = reinterpret_cast<char*>(storage) - count * sizeof(JSValue); 849 841 memmove(newBaseStorage, storage, storageSize(0)); 850 storage = reinterpret_cast<ArrayStorage*>(newBaseStorage); 851 setArrayStorage(storage); 842 m_storage = reinterpret_cast<ArrayStorage*>(newBaseStorage); 852 843 m_vectorLength += count; 853 844 } else if (!increaseVectorPrefixLength(m_vectorLength + count)) { … … 856 847 } 857 848 849 JSValue* vector = m_storage->m_vector; 858 850 for (int i = 0; i < count; i++) 859 m_vector[i] = JSValue();851 vector[i] = JSValue(); 860 852 } 861 853 … … 883 875 void JSArray::sortNumeric(ExecState* exec, JSValue compareFunction, CallType callType, const CallData& callData) 884 876 { 885 ArrayStorage* storage = arrayStorage();877 ArrayStorage* storage = m_storage; 886 878 887 879 unsigned lengthNotIncludingUndefined = compactForSorting(); … … 897 889 size_t size = storage->m_numValuesInVector; 898 890 for (size_t i = 0; i < size; ++i) { 899 if (! m_vector[i].isNumber()) {891 if (!storage->m_vector[i].isNumber()) { 900 892 allValuesAreNumbers = false; 901 893 break; … … 909 901 // also don't require mergesort's stability, since there's no user visible 910 902 // side-effect from swapping the order of equal primitive values. 911 qsort( m_vector, size, sizeof(JSValue), compareNumbersForQSort);903 qsort(storage->m_vector, size, sizeof(JSValue), compareNumbersForQSort); 912 904 913 905 checkConsistency(SortConsistencyCheck); … … 916 908 void JSArray::sort(ExecState* exec) 917 909 { 918 ArrayStorage* storage = arrayStorage();910 ArrayStorage* storage = m_storage; 919 911 920 912 unsigned lengthNotIncludingUndefined = compactForSorting(); … … 939 931 940 932 for (size_t i = 0; i < lengthNotIncludingUndefined; i++) { 941 JSValue value = m_vector[i];933 JSValue value = storage->m_vector[i]; 942 934 ASSERT(!value.isUndefined()); 943 935 values[i].first = value; … … 971 963 972 964 for (size_t i = 0; i < lengthNotIncludingUndefined; i++) 973 m_vector[i] = values[i].first;965 storage->m_vector[i] = values[i].first; 974 966 975 967 checkConsistency(SortConsistencyCheck); … … 1058 1050 checkConsistency(); 1059 1051 1060 ArrayStorage* storage = arrayStorage();1052 ArrayStorage* storage = m_storage; 1061 1053 1062 1054 // FIXME: This ignores exceptions raised in the compare function or in toNumber. … … 1097 1089 // Iterate over the array, ignoring missing values, counting undefined ones, and inserting all other ones into the tree. 1098 1090 for (; numDefined < usedVectorLength; ++numDefined) { 1099 JSValue v = m_vector[numDefined];1091 JSValue v = storage->m_vector[numDefined]; 1100 1092 if (!v || v.isUndefined()) 1101 1093 break; … … 1104 1096 } 1105 1097 for (unsigned i = numDefined; i < usedVectorLength; ++i) { 1106 JSValue v = m_vector[i];1098 JSValue v = storage->m_vector[i]; 1107 1099 if (v) { 1108 1100 if (v.isUndefined()) … … 1128 1120 } 1129 1121 1130 storage = arrayStorage();1122 storage = m_storage; 1131 1123 1132 1124 SparseArrayValueMap::iterator end = map->end(); … … 1150 1142 iter.start_iter_least(tree); 1151 1143 for (unsigned i = 0; i < numDefined; ++i) { 1152 m_vector[i] = tree.abstractor().m_nodes[*iter].value;1144 storage->m_vector[i] = tree.abstractor().m_nodes[*iter].value; 1153 1145 ++iter; 1154 1146 } … … 1156 1148 // Put undefined values back in. 1157 1149 for (unsigned i = numDefined; i < newUsedVectorLength; ++i) 1158 m_vector[i] = jsUndefined();1150 storage->m_vector[i] = jsUndefined(); 1159 1151 1160 1152 // Ensure that unused values in the vector are zeroed out. 1161 1153 for (unsigned i = newUsedVectorLength; i < usedVectorLength; ++i) 1162 m_vector[i] = JSValue();1154 storage->m_vector[i] = JSValue(); 1163 1155 1164 1156 storage->m_numValuesInVector = newUsedVectorLength; … … 1169 1161 void JSArray::fillArgList(ExecState* exec, MarkedArgumentBuffer& args) 1170 1162 { 1171 ArrayStorage* storage = arrayStorage();1163 ArrayStorage* storage = m_storage; 1172 1164 1173 1165 JSValue* vector = storage->m_vector; … … 1187 1179 void JSArray::copyToRegisters(ExecState* exec, Register* buffer, uint32_t maxSize) 1188 1180 { 1189 ASSERT( arrayStorage()->m_length >= maxSize);1181 ASSERT(m_storage->m_length >= maxSize); 1190 1182 UNUSED_PARAM(maxSize); 1191 JSValue* vector = m_ vector;1183 JSValue* vector = m_storage->m_vector; 1192 1184 unsigned vectorEnd = min(maxSize, m_vectorLength); 1193 1185 unsigned i = 0; … … 1207 1199 checkConsistency(); 1208 1200 1209 ArrayStorage* storage = arrayStorage();1201 ArrayStorage* storage = m_storage; 1210 1202 1211 1203 unsigned usedVectorLength = min(storage->m_length, m_vectorLength); … … 1215 1207 1216 1208 for (; numDefined < usedVectorLength; ++numDefined) { 1217 JSValue v = m_vector[numDefined];1209 JSValue v = storage->m_vector[numDefined]; 1218 1210 if (!v || v.isUndefined()) 1219 1211 break; 1220 1212 } 1221 1213 for (unsigned i = numDefined; i < usedVectorLength; ++i) { 1222 JSValue v = m_vector[i];1214 JSValue v = storage->m_vector[i]; 1223 1215 if (v) { 1224 1216 if (v.isUndefined()) 1225 1217 ++numUndefined; 1226 1218 else 1227 m_vector[numDefined++] = v;1219 storage->m_vector[numDefined++] = v; 1228 1220 } 1229 1221 } … … 1239 1231 return 0; 1240 1232 1241 storage = arrayStorage();1233 storage = m_storage; 1242 1234 } 1243 1235 1244 1236 SparseArrayValueMap::iterator end = map->end(); 1245 1237 for (SparseArrayValueMap::iterator it = map->begin(); it != end; ++it) 1246 m_vector[numDefined++] = it->second;1238 storage->m_vector[numDefined++] = it->second; 1247 1239 1248 1240 delete map; … … 1251 1243 1252 1244 for (unsigned i = numDefined; i < newUsedVectorLength; ++i) 1253 m_vector[i] = jsUndefined();1245 storage->m_vector[i] = jsUndefined(); 1254 1246 for (unsigned i = newUsedVectorLength; i < usedVectorLength; ++i) 1255 m_vector[i] = JSValue();1247 storage->m_vector[i] = JSValue(); 1256 1248 1257 1249 storage->m_numValuesInVector = newUsedVectorLength; … … 1264 1256 void* JSArray::subclassData() const 1265 1257 { 1266 return arrayStorage()->subclassData;1258 return m_storage->subclassData; 1267 1259 } 1268 1260 1269 1261 void JSArray::setSubclassData(void* d) 1270 1262 { 1271 arrayStorage()->subclassData = d;1263 m_storage->subclassData = d; 1272 1264 } 1273 1265 … … 1276 1268 void JSArray::checkConsistency(ConsistencyCheckType type) 1277 1269 { 1278 ArrayStorage* storage = arrayStorage();1270 ArrayStorage* storage = m_storage; 1279 1271 1280 1272 ASSERT(storage); … … 1284 1276 unsigned numValuesInVector = 0; 1285 1277 for (unsigned i = 0; i < m_vectorLength; ++i) { 1286 if (JSValue value = m_vector[i]) {1278 if (JSValue value = storage->m_vector[i]) { 1287 1279 ASSERT(i < storage->m_length); 1288 1280 if (type != DestructorConsistencyCheck) … … 1302 1294 unsigned index = it->first; 1303 1295 ASSERT(index < storage->m_length); 1304 ASSERT(index >= m_vectorLength);1296 ASSERT(index >= storage->m_vectorLength); 1305 1297 ASSERT(index <= MAX_ARRAY_INDEX); 1306 1298 ASSERT(it->second); -
trunk/JavaScriptCore/runtime/JSArray.h
r64602 r64937 78 78 static JS_EXPORTDATA const ClassInfo info; 79 79 80 unsigned length() const { return arrayStorage()->m_length; }80 unsigned length() const { return m_storage->m_length; } 81 81 void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray. 82 82 … … 91 91 void unshiftCount(ExecState*, int count); 92 92 93 bool canGetIndex(unsigned i) { return i < m_vectorLength && m_ vector[i]; }93 bool canGetIndex(unsigned i) { return i < m_vectorLength && m_storage->m_vector[i]; } 94 94 JSValue getIndex(unsigned i) 95 95 { 96 96 ASSERT(canGetIndex(i)); 97 return m_ vector[i];97 return m_storage->m_vector[i]; 98 98 } 99 99 … … 103 103 ASSERT(canSetIndex(i)); 104 104 105 JSValue& x = m_ vector[i];105 JSValue& x = m_storage->m_vector[i]; 106 106 if (!x) { 107 ArrayStorage *storage = arrayStorage();107 ArrayStorage *storage = m_storage; 108 108 ++storage->m_numValuesInVector; 109 109 if (i >= storage->m_length) … … 116 116 { 117 117 ASSERT(canSetIndex(i)); 118 ArrayStorage *storage = arrayStorage();118 ArrayStorage *storage = m_storage; 119 119 #if CHECK_ARRAY_CONSISTENCY 120 120 ASSERT(storage->m_inCompactInitialization); … … 144 144 void setSubclassData(void*); 145 145 146 inline ArrayStorage *arrayStorage() const147 {148 return reinterpret_cast<ArrayStorage*>(reinterpret_cast<char*>(m_vector) - (sizeof(ArrayStorage) - sizeof(JSValue)));149 }150 151 inline void setArrayStorage(ArrayStorage *storage)152 {153 m_vector = &storage->m_vector[0];154 }155 156 146 private: 157 147 virtual const ClassInfo* classInfo() const { return &info; } … … 171 161 unsigned m_vectorLength; // The valid length of m_vector 172 162 int m_indexBias; // The number of JSValue sized blocks before ArrayStorage. 173 JSValue* m_vector; // Copy of ArrayStorage.m_vector. Used for quick vector access and to materialize ArrayStorage ptr.163 ArrayStorage *m_storage; 174 164 }; 175 165 … … 197 187 JSObject::markChildrenDirect(markStack); 198 188 199 ArrayStorage* storage = arrayStorage();189 ArrayStorage* storage = m_storage; 200 190 201 191 unsigned usedVectorLength = std::min(storage->m_length, m_vectorLength);
Note: See TracChangeset
for help on using the changeset viewer.