Ignore:
Timestamp:
Aug 22, 2013, 5:45:38 PM (12 years ago)
Author:
[email protected]
Message:

JSObject and JSArray code shouldn't have to tiptoe around garbage collection
https://bugs.webkit.org/show_bug.cgi?id=120179

Reviewed by Geoffrey Garen.

There are many places in the code for JSObject and JSArray where they are manipulating their
Butterfly/Structure, e.g. after expanding their out-of-line backing storage via allocating. Within
these places there are certain "critical sections" where a GC would be disastrous. Gen GC looks
like it will make this dance even more intricate. To make everybody's lives easier we should use
the DeferGC mechanism in these functions to make these GC critical sections both obvious in the
code and trivially safe. Deferring collections will usually only last marginally longer, thus we
should not incur any additional overhead.

  • heap/Heap.h:
  • runtime/JSArray.cpp:

(JSC::JSArray::unshiftCountSlowCase):

  • runtime/JSObject.cpp:

(JSC::JSObject::enterDictionaryIndexingModeWhenArrayStorageAlreadyExists):
(JSC::JSObject::createInitialUndecided):
(JSC::JSObject::createInitialInt32):
(JSC::JSObject::createInitialDouble):
(JSC::JSObject::createInitialContiguous):
(JSC::JSObject::createArrayStorage):
(JSC::JSObject::convertUndecidedToArrayStorage):
(JSC::JSObject::convertInt32ToArrayStorage):
(JSC::JSObject::convertDoubleToArrayStorage):
(JSC::JSObject::convertContiguousToArrayStorage):
(JSC::JSObject::increaseVectorLength):
(JSC::JSObject::ensureLengthSlow):

  • runtime/JSObject.h:

(JSC::JSObject::putDirectInternal):
(JSC::JSObject::setStructureAndReallocateStorageIfNecessary):
(JSC::JSObject::putDirectWithoutTransition):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r154459 r154471  
    547547    }
    548548
     549    DeferGC deferGC(vm.heap);
    549550    Butterfly* newButterfly = storage->butterfly()->resizeArray(vm, this, structure(), 0, ArrayStorage::sizeFor(0));
    550551    RELEASE_ASSERT(newButterfly);
     
    610611Butterfly* JSObject::createInitialUndecided(VM& vm, unsigned length)
    611612{
     613    DeferGC deferGC(vm.heap);
    612614    Butterfly* newButterfly = createInitialIndexedStorage(vm, length, sizeof(EncodedJSValue));
    613615    Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), AllocateUndecided);
     
    618620ContiguousJSValues JSObject::createInitialInt32(VM& vm, unsigned length)
    619621{
     622    DeferGC deferGC(vm.heap);
    620623    Butterfly* newButterfly = createInitialIndexedStorage(vm, length, sizeof(EncodedJSValue));
    621624    Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), AllocateInt32);
     
    626629ContiguousDoubles JSObject::createInitialDouble(VM& vm, unsigned length)
    627630{
     631    DeferGC deferGC(vm.heap);
    628632    Butterfly* newButterfly = createInitialIndexedStorage(vm, length, sizeof(double));
    629633    for (unsigned i = newButterfly->vectorLength(); i--;)
     
    636640ContiguousJSValues JSObject::createInitialContiguous(VM& vm, unsigned length)
    637641{
     642    DeferGC deferGC(vm.heap);
    638643    Butterfly* newButterfly = createInitialIndexedStorage(vm, length, sizeof(EncodedJSValue));
    639644    Structure* newStructure = Structure::nonPropertyTransition(vm, structure(), AllocateContiguous);
     
    644649ArrayStorage* JSObject::createArrayStorage(VM& vm, unsigned length, unsigned vectorLength)
    645650{
     651    DeferGC deferGC(vm.heap);
    646652    IndexingType oldType = structure()->indexingType();
    647653    ASSERT_UNUSED(oldType, !hasIndexedProperties(oldType));
     
    718724ArrayStorage* JSObject::convertUndecidedToArrayStorage(VM& vm, NonPropertyTransition transition, unsigned neededLength)
    719725{
     726    DeferGC deferGC(vm.heap);
    720727    ASSERT(hasUndecided(structure()->indexingType()));
    721728   
     
    770777    ASSERT(hasInt32(structure()->indexingType()));
    771778   
     779    DeferGC deferGC(vm.heap);
    772780    ArrayStorage* newStorage = constructConvertedArrayStorageWithoutCopyingElements(vm, neededLength);
    773781    for (unsigned i = m_butterfly->publicLength(); i--;) {
     
    836844ArrayStorage* JSObject::convertDoubleToArrayStorage(VM& vm, NonPropertyTransition transition, unsigned neededLength)
    837845{
     846    DeferGC deferGC(vm.heap);
    838847    ASSERT(hasDouble(structure()->indexingType()));
    839848   
     
    864873ArrayStorage* JSObject::convertContiguousToArrayStorage(VM& vm, NonPropertyTransition transition, unsigned neededLength)
    865874{
     875    DeferGC deferGC(vm.heap);
    866876    ASSERT(hasContiguous(structure()->indexingType()));
    867877   
     
    23112321    // Fast case - there is no precapacity. In these cases a realloc makes sense.
    23122322    if (LIKELY(!indexBias)) {
     2323        DeferGC deferGC(vm.heap);
    23132324        Butterfly* newButterfly = storage->butterfly()->growArrayRight(
    23142325            vm, this, structure(), structure()->outOfLineCapacity(), true,
     
    23222333   
    23232334    // Remove some, but not all of the precapacity. Atomic decay, & capped to not overflow array length.
     2335    DeferGC deferGC(vm.heap);
    23242336    unsigned newIndexBias = std::min(indexBias >> 1, MAX_STORAGE_VECTOR_LENGTH - newVectorLength);
    23252337    Butterfly* newButterfly = storage->butterfly()->resizeArray(
     
    23462358        MAX_STORAGE_VECTOR_LENGTH);
    23472359    unsigned oldVectorLength = m_butterfly->vectorLength();
     2360    DeferGC deferGC(vm.heap);
    23482361    m_butterfly = m_butterfly->growArrayRight(
    23492362        vm, this, structure(), structure()->outOfLineCapacity(), true,
Note: See TracChangeset for help on using the changeset viewer.