⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181486 in webkit


Ignore:
Timestamp:
Mar 13, 2015, 1:14:39 PM (11 years ago)
Author:
ggaren@apple.com
Message:

Prohibit GC while sweeping
https://bugs.webkit.org/show_bug.cgi?id=142638

Reviewed by Andreas Kling.

I noticed in https://bugs.webkit.org/show_bug.cgi?id=142636 that a GC
could trigger a sweep which could trigger another GC. Yo Dawg.

I tried to figure out whether this could cause problems or not and it
made me cross-eyed.

(Some clients like to report extra memory cost during deallocation as a
way to indicate that the GC now owns something exclusively. It's
arguably a bug to communicate with the GC in this way, but we shouldn't
do crazy when this happens.)

This patch makes explicit the fact that we don't allow GC while sweeping.

Usually, sweeping implicitly defers GC by virtue of happening during
allocation. But not always.

  • heap/Heap.cpp:

(JSC::Heap::collectAllGarbage): Defer GC while sweeping due to an
explicit GC request.

(JSC::Heap::didFinishCollection): Make sure that zombifying sweep
defers GC by not returning to the non-GC state until we're all done.

  • heap/IncrementalSweeper.cpp:

(JSC::IncrementalSweeper::sweepNextBlock): Defer GC while sweeping due
to a timer.

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r181485 r181486  
     12015-03-12  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Prohibit GC while sweeping
     4        https://bugs.webkit.org/show_bug.cgi?id=142638
     5
     6        Reviewed by Andreas Kling.
     7
     8        I noticed in https://bugs.webkit.org/show_bug.cgi?id=142636 that a GC
     9        could trigger a sweep which could trigger another GC. Yo Dawg.
     10
     11        I tried to figure out whether this could cause problems or not and it
     12        made me cross-eyed.
     13
     14        (Some clients like to report extra memory cost during deallocation as a
     15        way to indicate that the GC now owns something exclusively. It's
     16        arguably a bug to communicate with the GC in this way, but we shouldn't
     17        do crazy when this happens.)
     18
     19        This patch makes explicit the fact that we don't allow GC while sweeping.
     20
     21        Usually, sweeping implicitly defers GC by virtue of happening during
     22        allocation. But not always.
     23
     24        * heap/Heap.cpp:
     25        (JSC::Heap::collectAllGarbage): Defer GC while sweeping due to an
     26        explicit GC request.
     27
     28        (JSC::Heap::didFinishCollection): Make sure that zombifying sweep
     29        defers GC by not returning to the non-GC state until we're all done.
     30
     31        * heap/IncrementalSweeper.cpp:
     32        (JSC::IncrementalSweeper::sweepNextBlock): Defer GC while sweeping due
     33        to a timer.
     34
    1352015-03-13  Mark Lam  <mark.lam@apple.com>
    236
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r181407 r181486  
    989989
    990990    SamplingRegion samplingRegion("Garbage Collection: Sweeping");
     991
     992    DeferGCForAWhile deferGC(*this);
    991993    m_objectSpace.sweep();
    992994    m_objectSpace.shrink();
     
    12941296    if (Options::recordGCPauseTimes())
    12951297        HeapStatistics::recordGCPauseTime(gcStartTime, gcEndTime);
     1298
     1299    if (Options::useZombieMode())
     1300        zombifyDeadObjects();
     1301
     1302    if (Options::objectsAreImmortal())
     1303        markDeadObjects();
     1304
     1305    if (Options::showObjectStatistics())
     1306        HeapStatistics::showObjectStatistics(this);
     1307
     1308    if (Options::logGC() == GCLogging::Verbose)
     1309        GCLogging::dumpObjectGraph(this);
     1310
    12961311    RELEASE_ASSERT(m_operationInProgress == EdenCollection || m_operationInProgress == FullCollection);
    1297 
    12981312    m_operationInProgress = NoOperation;
    12991313    JAVASCRIPTCORE_GC_END();
    1300 
    1301     if (Options::useZombieMode())
    1302         zombifyDeadObjects();
    1303 
    1304     if (Options::objectsAreImmortal())
    1305         markDeadObjects();
    1306 
    1307     if (Options::showObjectStatistics())
    1308         HeapStatistics::showObjectStatistics(this);
    1309 
    1310     if (Options::logGC() == GCLogging::Verbose)
    1311         GCLogging::dumpObjectGraph(this);
    13121314}
    13131315
  • trunk/Source/JavaScriptCore/heap/IncrementalSweeper.cpp

    r181350 r181486  
    9696            continue;
    9797
     98        DeferGCForAWhile deferGC(m_vm->heap);
    9899        block->sweep();
    99100        m_vm->heap.objectSpace().freeOrShrinkBlock(block);
Note: See TracChangeset for help on using the changeset viewer.