Changeset 64937 in webkit


Ignore:
Timestamp:
Aug 7, 2010 10:29:38 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-08-07 Michael Saboff <msaboff@apple.com>

Reviewed by Geoffrey Garen.

Revert JSArray to point to the beginning of the contained ArrayStorage
struct. This is described in
https://bugs.webkit.org/show_bug.cgi?id=43526.

  • jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_by_val): (JSC::JIT::emit_op_put_by_val): (JSC::JIT::privateCompilePatchGetArrayLength):
  • jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_by_val): (JSC::JIT::emit_op_put_by_val): (JSC::JIT::privateCompilePatchGetArrayLength):
  • runtime/JSArray.cpp: (JSC::JSArray::JSArray): (JSC::JSArray::~JSArray): (JSC::JSArray::getOwnPropertySlot): (JSC::JSArray::getOwnPropertyDescriptor): (JSC::JSArray::put): (JSC::JSArray::putSlowCase): (JSC::JSArray::deleteProperty): (JSC::JSArray::getOwnPropertyNames): (JSC::JSArray::getNewVectorLength): (JSC::JSArray::increaseVectorLength): (JSC::JSArray::increaseVectorPrefixLength): (JSC::JSArray::setLength): (JSC::JSArray::pop): (JSC::JSArray::push): (JSC::JSArray::shiftCount): (JSC::JSArray::unshiftCount): (JSC::JSArray::sortNumeric): (JSC::JSArray::sort): (JSC::JSArray::fillArgList): (JSC::JSArray::copyToRegisters): (JSC::JSArray::compactForSorting): (JSC::JSArray::subclassData): (JSC::JSArray::setSubclassData): (JSC::JSArray::checkConsistency):
  • runtime/JSArray.h: (JSC::JSArray::length): (JSC::JSArray::canGetIndex): (JSC::JSArray::getIndex): (JSC::JSArray::setIndex): (JSC::JSArray::uncheckedSetIndex): (JSC::JSArray::markChildrenDirect):
Location:
trunk/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r64934 r64937  
     12010-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
    1502010-08-07  Kwang Yul Seo  <skyul@company100.net>
    251
  • trunk/JavaScriptCore/jit/JITPropertyAccess.cpp

    r64649 r64937  
    107107    addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsArrayVPtr)));
    108108
    109     loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_vector)), regT2);
     109    loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT2);
    110110    addSlowCase(branch32(AboveOrEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength))));
    111111
    112     loadPtr(BaseIndex(regT2, regT1, ScalePtr), regT0);
     112    loadPtr(BaseIndex(regT2, regT1, ScalePtr, OBJECT_OFFSETOF(ArrayStorage, m_vector[0])), regT0);
    113113    addSlowCase(branchTestPtr(Zero, regT0));
    114114
     
    218218    addSlowCase(branch32(AboveOrEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength))));
    219219
    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])));
    222222
    223223    Label storeResult(this);
    224224    emitGetVirtualRegister(value, regT0);
    225     storePtr(regT0, BaseIndex(regT2, regT1, ScalePtr));
     225    storePtr(regT0, BaseIndex(regT2, regT1, ScalePtr, OBJECT_OFFSETOF(ArrayStorage, m_vector[0])));
    226226    Jump end = jump();
    227227   
    228228    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);
    231231
    232232    move(regT1, regT0);
    233233    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)));
    235235    jump().linkTo(storeResult, this);
    236236
     
    737737
    738738    // 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);
    741741    Jump failureCases2 = branch32(Above, regT2, Imm32(JSImmediate::maxImmediateInt));
    742742
  • trunk/JavaScriptCore/jit/JITPropertyAccess32_64.cpp

    r64649 r64937  
    315315    addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsArrayVPtr)));
    316316   
    317     loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_vector)), regT3);
     317    loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT3);
    318318    addSlowCase(branch32(AboveOrEqual, regT2, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength))));
    319319   
    320     load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT1); // tag
    321     load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT0); // payload
     320    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
    322322    addSlowCase(branch32(Equal, regT1, Imm32(JSValue::EmptyValueTag)));
    323323   
     
    368368    addSlowCase(branch32(AboveOrEqual, regT2, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength))));
    369369   
    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));
    373373   
    374374    Label storeResult(this);
    375375    emitLoad(value, regT1, regT0);
    376     store32(regT0, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload))); // payload
    377     store32(regT1, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag))); // tag
     376    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
    378378    Jump end = jump();
    379379   
    380380    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);
    383383   
    384384    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)));
    386386    jump().linkTo(storeResult, this);
    387387   
     
    745745   
    746746    // 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);
    749749   
    750750    Jump failureCases2 = branch32(Above, regT2, Imm32(INT_MAX));
  • trunk/JavaScriptCore/runtime/JSArray.cpp

    r64773 r64937  
    132132    unsigned initialCapacity = 0;
    133133
    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;
    136136    m_indexBias = 0;
    137     setArrayStorage(storage);
    138137    m_vectorLength = initialCapacity;
    139138
     
    150149    unsigned initialCapacity = 0;
    151150
    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;
    154153    m_indexBias = 0;
    155     setArrayStorage(storage);
    156154    m_vectorLength = initialCapacity;
    157155
     
    170168        initialCapacity = min(BASE_VECTOR_LEN, MIN_SPARSE_ARRAY_INDEX);
    171169   
    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;
    175173    m_indexBias = 0;
    176174    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;
    181178
    182179    if (creationMode == CreateCompact) {
    183180#if CHECK_ARRAY_CONSISTENCY
    184         storage->m_inCompactInitialization = !!initialCapacity;
     181        m_storage->m_inCompactInitialization = !!initialCapacity;
    185182#endif
    186         storage->m_length = 0;
    187         storage->m_numValuesInVector = initialCapacity;
     183        m_storage->m_length = 0;
     184        m_storage->m_numValuesInVector = initialCapacity;
    188185    } else {
    189186#if CHECK_ARRAY_CONSISTENCY
    190187        storage->m_inCompactInitialization = false;
    191188#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;
    195192        for (size_t i = 0; i < initialCapacity; ++i)
    196193            vector[i] = JSValue();
     
    207204    unsigned initialCapacity = list.size();
    208205
    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;
    211208    m_indexBias = 0;
    212     storage->m_length = initialCapacity;
     209    m_storage->m_length = initialCapacity;
    213210    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;
    218215#if CHECK_ARRAY_CONSISTENCY
    219     storage->m_inCompactInitialization = false;
     216    m_storage->m_inCompactInitialization = false;
    220217#endif
    221     setArrayStorage(storage);
    222218
    223219    size_t i = 0;
    224     JSValue* vector = m_vector;
     220    JSValue* vector = m_storage->m_vector;
    225221    ArgList::const_iterator end = list.end();
    226222    for (ArgList::const_iterator it = list.begin(); it != end; ++it, ++i)
     
    237233    checkConsistency(DestructorConsistencyCheck);
    238234
    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);
    242237}
    243238
    244239bool JSArray::getOwnPropertySlot(ExecState* exec, unsigned i, PropertySlot& slot)
    245240{
    246     ArrayStorage* storage = arrayStorage();
     241    ArrayStorage* storage = m_storage;
    247242   
    248243    if (i >= storage->m_length) {
     
    253248
    254249    if (i < m_vectorLength) {
    255         JSValue& valueSlot = m_vector[i];
     250        JSValue& valueSlot = storage->m_vector[i];
    256251        if (valueSlot) {
    257252            slot.setValueSlot(&valueSlot);
     
    293288    }
    294289
    295     ArrayStorage* storage = arrayStorage();
     290    ArrayStorage* storage = m_storage;
    296291   
    297292    bool isArrayIndex;
     
    301296            return false;
    302297        if (i < m_vectorLength) {
    303             JSValue& value = m_vector[i];
     298            JSValue& value = storage->m_vector[i];
    304299            if (value) {
    305300                descriptor.setDescriptor(value, 0);
     
    346341    checkConsistency();
    347342
    348     ArrayStorage* storage = arrayStorage();
     343    ArrayStorage* storage = m_storage;
    349344
    350345    unsigned length = storage->m_length;
     
    355350
    356351    if (i < m_vectorLength) {
    357         JSValue& valueSlot = m_vector[i];
     352        JSValue& valueSlot = storage->m_vector[i];
    358353        if (valueSlot) {
    359354            valueSlot = value;
     
    372367NEVER_INLINE void JSArray::putSlowCase(ExecState* exec, unsigned i, JSValue value)
    373368{
    374     ArrayStorage* storage = arrayStorage();
     369    ArrayStorage* storage = m_storage;
    375370   
    376371    SparseArrayValueMap* map = storage->m_sparseValueMap;
     
    410405    if (!map || map->isEmpty()) {
    411406        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;
    414410            checkConsistency();
    415411        } else
     
    446442    }
    447443
    448     storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
    449     storage->m_allocBase = baseStorage;
    450     setArrayStorage(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;
    451447   
    452448    unsigned vectorLength = m_vectorLength;
     449    JSValue* vector = storage->m_vector;
    453450
    454451    if (newNumValuesInVector == storage->m_numValuesInVector + 1) {
    455452        for (unsigned j = vectorLength; j < newVectorLength; ++j)
    456             m_vector[j] = JSValue();
     453            vector[j] = JSValue();
    457454        if (i > MIN_SPARSE_ARRAY_INDEX)
    458455            map->remove(i);
    459456    } else {
    460457        for (unsigned j = vectorLength; j < max(vectorLength, MIN_SPARSE_ARRAY_INDEX); ++j)
    461             m_vector[j] = JSValue();
     458            vector[j] = JSValue();
    462459        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);
    464461    }
    465462
     
    469466    storage->m_numValuesInVector = newNumValuesInVector;
    470467
    471     m_vector[i] = value;
     468    storage->m_vector[i] = value;
    472469
    473470    checkConsistency();
     
    493490    checkConsistency();
    494491
    495     ArrayStorage* storage = arrayStorage();
     492    ArrayStorage* storage = m_storage;
    496493   
    497494    if (i < m_vectorLength) {
    498         JSValue& valueSlot = m_vector[i];
     495        JSValue& valueSlot = storage->m_vector[i];
    499496        if (!valueSlot) {
    500497            checkConsistency();
     
    532529    // which almost certainly means a different structure for PropertyNameArray.
    533530
    534     ArrayStorage* storage = arrayStorage();
     531    ArrayStorage* storage = m_storage;
    535532   
    536533    unsigned usedVectorLength = min(storage->m_length, m_vectorLength);
    537534    for (unsigned i = 0; i < usedVectorLength; ++i) {
    538         if (m_vector[i])
     535        if (storage->m_vector[i])
    539536            propertyNames.add(Identifier::from(exec, i));
    540537    }
     
    557554
    558555    unsigned increasedLength;
    559     unsigned length = arrayStorage()->m_length;
     556    unsigned length = m_storage->m_length;
    560557
    561558    if (desiredLength < length)
     
    584581    // to the vector. Callers have to account for that, because they can do it more efficiently.
    585582
    586     ArrayStorage* storage = arrayStorage();
     583    ArrayStorage* storage = m_storage;
    587584
    588585    unsigned vectorLength = m_vectorLength;
     
    595592        return false;
    596593
    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;
    602598    for (unsigned i = vectorLength; i < newVectorLength; ++i)
    603599        vector[i] = JSValue();
     
    615611    // to the vector. Callers have to account for that, because they can do it more efficiently.
    616612   
    617     ArrayStorage* storage = arrayStorage();
    618     ArrayStorage* newStorage;
     613    ArrayStorage* storage = m_storage;
    619614   
    620615    unsigned vectorLength = m_vectorLength;
     
    629624    m_indexBias += newVectorLength - newLength;
    630625   
    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;
    637632    m_vectorLength = newLength;
    638633   
    639634    fastFree(storage->m_allocBase);
    640635
    641     setArrayStorage(newStorage);
    642    
    643636    Heap::heap(this)->reportExtraMemoryCost(storageSize(newVectorLength) - storageSize(vectorLength));
    644637   
     
    649642void JSArray::setLength(unsigned newLength)
    650643{
     644    ArrayStorage* storage = m_storage;
     645   
    651646#if CHECK_ARRAY_CONSISTENCY
    652     if (!m_storage->m_inCompactInitialization)
     647    if (!storage->m_inCompactInitialization)
    653648        checkConsistency();
    654649    else
    655         m_storage->m_inCompactInitialization = false;
     650        storage->m_inCompactInitialization = false;
    656651#endif
    657652
    658     ArrayStorage* storage = arrayStorage();
    659    
    660653    unsigned length = storage->m_length;
    661654
     
    663656        unsigned usedVectorLength = min(length, m_vectorLength);
    664657        for (unsigned i = newLength; i < usedVectorLength; ++i) {
    665             JSValue& valueSlot = m_vector[i];
     658            JSValue& valueSlot = storage->m_vector[i];
    666659            bool hadValue = valueSlot;
    667660            valueSlot = JSValue();
     
    692685    checkConsistency();
    693686
    694     ArrayStorage* storage = arrayStorage();
     687    ArrayStorage* storage = m_storage;
    695688   
    696689    unsigned length = storage->m_length;
     
    703696
    704697    if (length < m_vectorLength) {
    705         JSValue& valueSlot = m_vector[length];
     698        JSValue& valueSlot = storage->m_vector[length];
    706699        if (valueSlot) {
    707700            --storage->m_numValuesInVector;
     
    736729    checkConsistency();
    737730   
    738     ArrayStorage* storage = arrayStorage();
     731    ArrayStorage* storage = m_storage;
    739732
    740733    if (storage->m_length < m_vectorLength) {
    741         m_vector[storage->m_length] = value;
     734        storage->m_vector[storage->m_length] = value;
    742735        ++storage->m_numValuesInVector;
    743736        ++storage->m_length;
     
    750743        if (!map || map->isEmpty()) {
    751744            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;
    754747                ++storage->m_numValuesInVector;
    755748                ++storage->m_length;
     
    770763    ASSERT(count > 0);
    771764   
    772     ArrayStorage* storage = arrayStorage();
     765    ArrayStorage* storage = m_storage;
    773766   
    774767    unsigned oldLength = storage->m_length;
     
    783776        // 15.4.4.9 steps 11 through 13.
    784777        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])) {
    786779                PropertySlot slot(this);
    787780                JSValue p = prototype();
     
    791784        }
    792785
    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.
    794787
    795788        // Need to decrement numValuesInvector based on number of real entries
    796789        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]))
    798791                --storage->m_numValuesInVector;
    799792    } else
     
    810803            char* newBaseStorage = reinterpret_cast<char*>(storage) + count * sizeof(JSValue);
    811804            memmove(newBaseStorage, storage, storageSize(0));
    812             storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);
     805            m_storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);
    813806
    814807            m_indexBias += count;
    815             setArrayStorage(storage);
    816808        }
    817809    }
     
    820812void JSArray::unshiftCount(ExecState* exec, int count)
    821813{
    822     ArrayStorage* storage = arrayStorage();
     814    ArrayStorage* storage = m_storage;
    823815
    824816    ASSERT(m_indexBias >= 0);
     
    833825        // 15.4.4.13 steps 8 through 10.
    834826        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])) {
    836828                PropertySlot slot(this);
    837829                JSValue p = prototype();
     
    842834    }
    843835   
    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.
    845837   
    846838    if (m_indexBias >= count) {
     
    848840        char* newBaseStorage = reinterpret_cast<char*>(storage) - count * sizeof(JSValue);
    849841        memmove(newBaseStorage, storage, storageSize(0));
    850         storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);
    851         setArrayStorage(storage);
     842        m_storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);
    852843        m_vectorLength += count;
    853844    } else if (!increaseVectorPrefixLength(m_vectorLength + count)) {
     
    856847    }
    857848
     849    JSValue* vector = m_storage->m_vector;
    858850    for (int i = 0; i < count; i++)
    859         m_vector[i] = JSValue();
     851        vector[i] = JSValue();
    860852}
    861853
     
    883875void JSArray::sortNumeric(ExecState* exec, JSValue compareFunction, CallType callType, const CallData& callData)
    884876{
    885     ArrayStorage* storage = arrayStorage();
     877    ArrayStorage* storage = m_storage;
    886878
    887879    unsigned lengthNotIncludingUndefined = compactForSorting();
     
    897889    size_t size = storage->m_numValuesInVector;
    898890    for (size_t i = 0; i < size; ++i) {
    899         if (!m_vector[i].isNumber()) {
     891        if (!storage->m_vector[i].isNumber()) {
    900892            allValuesAreNumbers = false;
    901893            break;
     
    909901    // also don't require mergesort's stability, since there's no user visible
    910902    // 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);
    912904
    913905    checkConsistency(SortConsistencyCheck);
     
    916908void JSArray::sort(ExecState* exec)
    917909{
    918     ArrayStorage* storage = arrayStorage();
     910    ArrayStorage* storage = m_storage;
    919911
    920912    unsigned lengthNotIncludingUndefined = compactForSorting();
     
    939931
    940932    for (size_t i = 0; i < lengthNotIncludingUndefined; i++) {
    941         JSValue value = m_vector[i];
     933        JSValue value = storage->m_vector[i];
    942934        ASSERT(!value.isUndefined());
    943935        values[i].first = value;
     
    971963
    972964    for (size_t i = 0; i < lengthNotIncludingUndefined; i++)
    973         m_vector[i] = values[i].first;
     965        storage->m_vector[i] = values[i].first;
    974966
    975967    checkConsistency(SortConsistencyCheck);
     
    10581050    checkConsistency();
    10591051
    1060     ArrayStorage* storage = arrayStorage();
     1052    ArrayStorage* storage = m_storage;
    10611053
    10621054    // FIXME: This ignores exceptions raised in the compare function or in toNumber.
     
    10971089    // Iterate over the array, ignoring missing values, counting undefined ones, and inserting all other ones into the tree.
    10981090    for (; numDefined < usedVectorLength; ++numDefined) {
    1099         JSValue v = m_vector[numDefined];
     1091        JSValue v = storage->m_vector[numDefined];
    11001092        if (!v || v.isUndefined())
    11011093            break;
     
    11041096    }
    11051097    for (unsigned i = numDefined; i < usedVectorLength; ++i) {
    1106         JSValue v = m_vector[i];
     1098        JSValue v = storage->m_vector[i];
    11071099        if (v) {
    11081100            if (v.isUndefined())
     
    11281120        }
    11291121       
    1130         storage = arrayStorage();
     1122        storage = m_storage;
    11311123
    11321124        SparseArrayValueMap::iterator end = map->end();
     
    11501142    iter.start_iter_least(tree);
    11511143    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;
    11531145        ++iter;
    11541146    }
     
    11561148    // Put undefined values back in.
    11571149    for (unsigned i = numDefined; i < newUsedVectorLength; ++i)
    1158         m_vector[i] = jsUndefined();
     1150        storage->m_vector[i] = jsUndefined();
    11591151
    11601152    // Ensure that unused values in the vector are zeroed out.
    11611153    for (unsigned i = newUsedVectorLength; i < usedVectorLength; ++i)
    1162         m_vector[i] = JSValue();
     1154        storage->m_vector[i] = JSValue();
    11631155
    11641156    storage->m_numValuesInVector = newUsedVectorLength;
     
    11691161void JSArray::fillArgList(ExecState* exec, MarkedArgumentBuffer& args)
    11701162{
    1171     ArrayStorage* storage = arrayStorage();
     1163    ArrayStorage* storage = m_storage;
    11721164
    11731165    JSValue* vector = storage->m_vector;
     
    11871179void JSArray::copyToRegisters(ExecState* exec, Register* buffer, uint32_t maxSize)
    11881180{
    1189     ASSERT(arrayStorage()->m_length >= maxSize);
     1181    ASSERT(m_storage->m_length >= maxSize);
    11901182    UNUSED_PARAM(maxSize);
    1191     JSValue* vector = m_vector;
     1183    JSValue* vector = m_storage->m_vector;
    11921184    unsigned vectorEnd = min(maxSize, m_vectorLength);
    11931185    unsigned i = 0;
     
    12071199    checkConsistency();
    12081200
    1209     ArrayStorage* storage = arrayStorage();
     1201    ArrayStorage* storage = m_storage;
    12101202
    12111203    unsigned usedVectorLength = min(storage->m_length, m_vectorLength);
     
    12151207
    12161208    for (; numDefined < usedVectorLength; ++numDefined) {
    1217         JSValue v = m_vector[numDefined];
     1209        JSValue v = storage->m_vector[numDefined];
    12181210        if (!v || v.isUndefined())
    12191211            break;
    12201212    }
    12211213    for (unsigned i = numDefined; i < usedVectorLength; ++i) {
    1222         JSValue v = m_vector[i];
     1214        JSValue v = storage->m_vector[i];
    12231215        if (v) {
    12241216            if (v.isUndefined())
    12251217                ++numUndefined;
    12261218            else
    1227                 m_vector[numDefined++] = v;
     1219                storage->m_vector[numDefined++] = v;
    12281220        }
    12291221    }
     
    12391231                return 0;
    12401232
    1241             storage = arrayStorage();
     1233            storage = m_storage;
    12421234        }
    12431235
    12441236        SparseArrayValueMap::iterator end = map->end();
    12451237        for (SparseArrayValueMap::iterator it = map->begin(); it != end; ++it)
    1246             m_vector[numDefined++] = it->second;
     1238            storage->m_vector[numDefined++] = it->second;
    12471239
    12481240        delete map;
     
    12511243
    12521244    for (unsigned i = numDefined; i < newUsedVectorLength; ++i)
    1253         m_vector[i] = jsUndefined();
     1245        storage->m_vector[i] = jsUndefined();
    12541246    for (unsigned i = newUsedVectorLength; i < usedVectorLength; ++i)
    1255         m_vector[i] = JSValue();
     1247        storage->m_vector[i] = JSValue();
    12561248
    12571249    storage->m_numValuesInVector = newUsedVectorLength;
     
    12641256void* JSArray::subclassData() const
    12651257{
    1266     return arrayStorage()->subclassData;
     1258    return m_storage->subclassData;
    12671259}
    12681260
    12691261void JSArray::setSubclassData(void* d)
    12701262{
    1271     arrayStorage()->subclassData = d;
     1263    m_storage->subclassData = d;
    12721264}
    12731265
     
    12761268void JSArray::checkConsistency(ConsistencyCheckType type)
    12771269{
    1278     ArrayStorage* storage = arrayStorage();
     1270    ArrayStorage* storage = m_storage;
    12791271
    12801272    ASSERT(storage);
     
    12841276    unsigned numValuesInVector = 0;
    12851277    for (unsigned i = 0; i < m_vectorLength; ++i) {
    1286         if (JSValue value = m_vector[i]) {
     1278        if (JSValue value = storage->m_vector[i]) {
    12871279            ASSERT(i < storage->m_length);
    12881280            if (type != DestructorConsistencyCheck)
     
    13021294            unsigned index = it->first;
    13031295            ASSERT(index < storage->m_length);
    1304             ASSERT(index >= m_vectorLength);
     1296            ASSERT(index >= storage->m_vectorLength);
    13051297            ASSERT(index <= MAX_ARRAY_INDEX);
    13061298            ASSERT(it->second);
  • trunk/JavaScriptCore/runtime/JSArray.h

    r64602 r64937  
    7878        static JS_EXPORTDATA const ClassInfo info;
    7979       
    80         unsigned length() const { return arrayStorage()->m_length; }
     80        unsigned length() const { return m_storage->m_length; }
    8181        void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray.
    8282
     
    9191        void unshiftCount(ExecState*, int count);
    9292
    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]; }
    9494        JSValue getIndex(unsigned i)
    9595        {
    9696            ASSERT(canGetIndex(i));
    97             return m_vector[i];
     97            return m_storage->m_vector[i];
    9898        }
    9999
     
    103103            ASSERT(canSetIndex(i));
    104104           
    105             JSValue& x = m_vector[i];
     105            JSValue& x = m_storage->m_vector[i];
    106106            if (!x) {
    107                 ArrayStorage *storage = arrayStorage();
     107                ArrayStorage *storage = m_storage;
    108108                ++storage->m_numValuesInVector;
    109109                if (i >= storage->m_length)
     
    116116        {
    117117            ASSERT(canSetIndex(i));
    118             ArrayStorage *storage = arrayStorage();
     118            ArrayStorage *storage = m_storage;
    119119#if CHECK_ARRAY_CONSISTENCY
    120120            ASSERT(storage->m_inCompactInitialization);
     
    144144        void setSubclassData(void*);
    145145       
    146         inline ArrayStorage *arrayStorage() const
    147         {
    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 
    156146    private:
    157147        virtual const ClassInfo* classInfo() const { return &info; }
     
    171161        unsigned m_vectorLength; // The valid length of m_vector
    172162        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;
    174164    };
    175165
     
    197187        JSObject::markChildrenDirect(markStack);
    198188       
    199         ArrayStorage* storage = arrayStorage();
     189        ArrayStorage* storage = m_storage;
    200190
    201191        unsigned usedVectorLength = std::min(storage->m_length, m_vectorLength);
Note: See TracChangeset for help on using the changeset viewer.