Changeset 120742 in webkit


Ignore:
Timestamp:
Jun 19, 2012, 12:17:31 PM (13 years ago)
Author:
[email protected]
Message:

GCActivityCallback and IncrementalSweeper should share code
https://bugs.webkit.org/show_bug.cgi?id=89400

Reviewed by Geoffrey Garen.

A lot of functionality is duplicated between GCActivityCallback and IncrementalSweeper.
We should extract the common functionality out into a separate class that both of them
can inherit from. This refactoring will be an even greater boon when we add the ability
to shut these two agents down in a thread-safe fashion

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Target.pri:
  • heap/Heap.cpp:

(JSC::Heap::Heap): Move initialization down so that the JSGlobalData has a valid Heap when
we're initializing the GCActivityCallback and the IncrementalSweeper.

  • heap/Heap.h:

(Heap):

  • heap/HeapTimer.cpp: Added.

(JSC):
(JSC::HeapTimer::HeapTimer): Initialize the various base class data that
DefaultGCActivityCallback::commonConstructor() used to do.
(JSC::HeapTimer::~HeapTimer): Call to invalidate().
(JSC::HeapTimer::synchronize): Same functionality as the old DefaultGCActivityCallback::synchronize().
Virtual so that non-CF subclasses can override.
(JSC::HeapTimer::invalidate): Tears down the runloop timer to prevent any future firing.
(JSC::HeapTimer::timerDidFire): Callback to pass to the timer function. Casts and calls the virtual doWork().

  • heap/HeapTimer.h: Added. This is the class that serves as the common base class for

both GCActivityCallback and IncrementalSweeper. It handles setting up and tearing down run loops and synchronizing
across threads for its subclasses.
(JSC):
(HeapTimer):

  • heap/IncrementalSweeper.cpp: Changes to accomodate the extraction of common functionality

between IncrementalSweeper and GCActivityCallback into a common ancestor.
(JSC):
(JSC::IncrementalSweeper::doWork):
(JSC::IncrementalSweeper::IncrementalSweeper):
(JSC::IncrementalSweeper::cancelTimer):
(JSC::IncrementalSweeper::create):

  • heap/IncrementalSweeper.h:

(IncrementalSweeper):

  • runtime/GCActivityCallback.cpp:

(JSC::DefaultGCActivityCallback::DefaultGCActivityCallback):
(JSC::DefaultGCActivityCallback::doWork):

  • runtime/GCActivityCallback.h:

(GCActivityCallback):
(JSC::GCActivityCallback::willCollect):
(JSC::GCActivityCallback::GCActivityCallback):
(JSC):
(DefaultGCActivityCallback): Remove the platform data struct. The platform data should be kept in
the class itself so as to be accessible by doWork(). Most of the platform data for CF is kept in
HeapTimer anyways, so we only need the m_delay field now.

  • runtime/GCActivityCallbackBlackBerry.cpp:

(JSC):
(JSC::DefaultGCActivityCallback::DefaultGCActivityCallback):
(JSC::DefaultGCActivityCallback::doWork):
(JSC::DefaultGCActivityCallback::didAllocate):

  • runtime/GCActivityCallbackCF.cpp:

(JSC):
(JSC::DefaultGCActivityCallback::DefaultGCActivityCallback):
(JSC::DefaultGCActivityCallback::doWork):
(JSC::DefaultGCActivityCallback::scheduleTimer):
(JSC::DefaultGCActivityCallback::cancelTimer):
(JSC::DefaultGCActivityCallback::didAllocate):
(JSC::DefaultGCActivityCallback::willCollect):
(JSC::DefaultGCActivityCallback::cancel):

Location:
trunk/Source/JavaScriptCore
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r120244 r120742  
    9999    heap/HandleStack.cpp
    100100    heap/Heap.cpp
     101    heap/HeapTimer.cpp
    101102    heap/IncrementalSweeper.cpp
    102103    heap/MachineStackMarker.cpp
  • trunk/Source/JavaScriptCore/ChangeLog

    r120698 r120742  
     12012-06-19  Mark Hahnenberg  <[email protected]>
     2
     3        GCActivityCallback and IncrementalSweeper should share code
     4        https://bugs.webkit.org/show_bug.cgi?id=89400
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        A lot of functionality is duplicated between GCActivityCallback and IncrementalSweeper.
     9        We should extract the common functionality out into a separate class that both of them
     10        can inherit from. This refactoring will be an even greater boon when we add the ability
     11        to shut these two agents down in a thread-safe fashion
     12
     13        * CMakeLists.txt:
     14        * GNUmakefile.list.am:
     15        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
     16        * JavaScriptCore.xcodeproj/project.pbxproj:
     17        * Target.pri:
     18        * heap/Heap.cpp:
     19        (JSC::Heap::Heap): Move initialization down so that the JSGlobalData has a valid Heap when
     20        we're initializing the GCActivityCallback and the IncrementalSweeper.
     21        * heap/Heap.h:
     22        (Heap):
     23        * heap/HeapTimer.cpp: Added.
     24        (JSC):
     25        (JSC::HeapTimer::HeapTimer): Initialize the various base class data that
     26        DefaultGCActivityCallback::commonConstructor() used to do.
     27        (JSC::HeapTimer::~HeapTimer): Call to invalidate().
     28        (JSC::HeapTimer::synchronize): Same functionality as the old DefaultGCActivityCallback::synchronize().
     29        Virtual so that non-CF subclasses can override.
     30        (JSC::HeapTimer::invalidate): Tears down the runloop timer to prevent any future firing.
     31        (JSC::HeapTimer::timerDidFire): Callback to pass to the timer function. Casts and calls the virtual doWork().
     32        * heap/HeapTimer.h: Added. This is the class that serves as the common base class for
     33        both GCActivityCallback and IncrementalSweeper. It handles setting up and tearing down run loops and synchronizing
     34        across threads for its subclasses.
     35        (JSC):
     36        (HeapTimer):
     37        * heap/IncrementalSweeper.cpp: Changes to accomodate the extraction of common functionality
     38        between IncrementalSweeper and GCActivityCallback into a common ancestor.
     39        (JSC):
     40        (JSC::IncrementalSweeper::doWork):
     41        (JSC::IncrementalSweeper::IncrementalSweeper):
     42        (JSC::IncrementalSweeper::cancelTimer):
     43        (JSC::IncrementalSweeper::create):
     44        * heap/IncrementalSweeper.h:
     45        (IncrementalSweeper):
     46        * runtime/GCActivityCallback.cpp:
     47        (JSC::DefaultGCActivityCallback::DefaultGCActivityCallback):
     48        (JSC::DefaultGCActivityCallback::doWork):
     49        * runtime/GCActivityCallback.h:
     50        (GCActivityCallback):
     51        (JSC::GCActivityCallback::willCollect):
     52        (JSC::GCActivityCallback::GCActivityCallback):
     53        (JSC):
     54        (DefaultGCActivityCallback): Remove the platform data struct. The platform data should be kept in
     55        the class itself so as to be accessible by doWork(). Most of the platform data for CF is kept in
     56        HeapTimer anyways, so we only need the m_delay field now.
     57        * runtime/GCActivityCallbackBlackBerry.cpp:
     58        (JSC):
     59        (JSC::DefaultGCActivityCallback::DefaultGCActivityCallback):
     60        (JSC::DefaultGCActivityCallback::doWork):
     61        (JSC::DefaultGCActivityCallback::didAllocate):
     62        * runtime/GCActivityCallbackCF.cpp:
     63        (JSC):
     64        (JSC::DefaultGCActivityCallback::DefaultGCActivityCallback):
     65        (JSC::DefaultGCActivityCallback::doWork):
     66        (JSC::DefaultGCActivityCallback::scheduleTimer):
     67        (JSC::DefaultGCActivityCallback::cancelTimer):
     68        (JSC::DefaultGCActivityCallback::didAllocate):
     69        (JSC::DefaultGCActivityCallback::willCollect):
     70        (JSC::DefaultGCActivityCallback::cancel):
     71
     72
    1732012-06-19  Mike West  <[email protected]>
    274
  • trunk/Source/JavaScriptCore/GNUmakefile.list.am

    r120244 r120742  
    237237        Source/JavaScriptCore/heap/HandleSet.h \
    238238        Source/JavaScriptCore/heap/HeapBlock.h \
     239    Source/JavaScriptCore/heap/HeapTimer.h \
     240    Source/JavaScriptCore/heap/HeapTimer.cpp \
    239241        Source/JavaScriptCore/heap/IncrementalSweeper.h \
    240242        Source/JavaScriptCore/heap/IncrementalSweeper.cpp \
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj

    r120244 r120742  
    715715                        </File>
    716716                        <File
    717                                 RelativePath="..\..\runtime\GCActivityCallback.cpp"
     717                                RelativePath="..\..\runtime\GCActivityCallbackCF.cpp"
    718718                                >
    719719                        </File>
     
    21872187                        </File>
    21882188                        <File
     2189                                RelativePath="..\..\heap\HeapTimer.cpp"
     2190                                >
     2191                        </File>
     2192                        <File
     2193                                RelativePath="..\..\heap\HeapTimer.h"
     2194                                >
     2195                        </File>
     2196                        <File
    21892197                                RelativePath="..\..\heap\IncrementalSweeper.h"
    21902198                                >
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r120244 r120742  
    652652                C2C8D03014A3CEFC00578E65 /* CopiedBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02E14A3CEFC00578E65 /* CopiedBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
    653653                C2C8D03114A3CEFC00578E65 /* HeapBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02F14A3CEFC00578E65 /* HeapBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
     654                C2E526BD1590EF000054E48D /* HeapTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2E526BB1590EF000054E48D /* HeapTimer.cpp */; };
     655                C2E526BE1590EF000054E48D /* HeapTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = C2E526BC1590EF000054E48D /* HeapTimer.h */; settings = {ATTRIBUTES = (Private, ); }; };
    654656                C2EAA3FA149A835E00FCE112 /* CopiedSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = C2EAA3F8149A830800FCE112 /* CopiedSpace.h */; settings = {ATTRIBUTES = (Private, ); }; };
    655657                C2EAD2FC14F0249800A4B159 /* CopiedAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = C2EAD2FB14F0249800A4B159 /* CopiedAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    13551357                C2C8D02E14A3CEFC00578E65 /* CopiedBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedBlock.h; sourceTree = "<group>"; };
    13561358                C2C8D02F14A3CEFC00578E65 /* HeapBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapBlock.h; sourceTree = "<group>"; };
     1359                C2E526BB1590EF000054E48D /* HeapTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HeapTimer.cpp; sourceTree = "<group>"; };
     1360                C2E526BC1590EF000054E48D /* HeapTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapTimer.h; sourceTree = "<group>"; };
    13571361                C2EAA3F8149A830800FCE112 /* CopiedSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedSpace.h; sourceTree = "<group>"; };
    13581362                C2EAD2FB14F0249800A4B159 /* CopiedAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedAllocator.h; sourceTree = "<group>"; };
     
    16281632                        isa = PBXGroup;
    16291633                        children = (
     1634                                C2E526BB1590EF000054E48D /* HeapTimer.cpp */,
     1635                                C2E526BC1590EF000054E48D /* HeapTimer.h */,
    16301636                                C25F8BCB157544A900245B71 /* IncrementalSweeper.cpp */,
    16311637                                C25F8BCC157544A900245B71 /* IncrementalSweeper.h */,
     
    23382344                                C2EAD2FC14F0249800A4B159 /* CopiedAllocator.h in Headers */,
    23392345                                C2B916C214DA014E00CBAC86 /* MarkedAllocator.h in Headers */,
     2346                                C2E526BE1590EF000054E48D /* HeapTimer.h in Headers */,
    23402347                                C25F8BCE157544A900245B71 /* IncrementalSweeper.h in Headers */,
    23412348                                BC18C3E60E16F5CD00B34460 /* ArrayConstructor.h in Headers */,
     
    32583265                                0F919D2515853CE0004A4E7D /* Watchpoint.cpp in Sources */,
    32593266                                0F919D2815856773004A4E7D /* SymbolTable.cpp in Sources */,
     3267                                C2E526BD1590EF000054E48D /* HeapTimer.cpp in Sources */,
    32603268                        );
    32613269                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/JavaScriptCore/Target.pri

    r120244 r120742  
    8080    heap/BlockAllocator.cpp \
    8181    heap/Heap.cpp \
     82    heap/HeapTimer.cpp \
    8283    heap/IncrementalSweeper.cpp \
    8384    heap/MachineStackMarker.cpp \
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r119909 r120742  
    246246    , m_objectSpace(this)
    247247    , m_storageSpace(this)
    248     , m_activityCallback(DefaultGCActivityCallback::create(this))
    249     , m_sweeper(IncrementalSweeper::create(this))
    250248    , m_machineThreads(this)
    251249    , m_sharedData(globalData)
     
    256254    , m_lastGCLength(0)
    257255    , m_lastCodeDiscardTime(WTF::currentTime())
     256    , m_activityCallback(DefaultGCActivityCallback::create(this))
     257    , m_sweeper(IncrementalSweeper::create(this))
    258258{
    259259    m_storageSpace.init();
  • trunk/Source/JavaScriptCore/heap/Heap.h

    r120502 r120742  
    222222        OwnPtr<HashSet<MarkedArgumentBuffer*> > m_markListSet;
    223223
    224         OwnPtr<GCActivityCallback> m_activityCallback;
    225         OwnPtr<IncrementalSweeper> m_sweeper;
    226        
    227224        MachineThreads m_machineThreads;
    228225       
     
    241238        double m_lastCodeDiscardTime;
    242239
     240        OwnPtr<GCActivityCallback> m_activityCallback;
     241        OwnPtr<IncrementalSweeper> m_sweeper;
     242       
    243243        DoublyLinkedList<ExecutableBase> m_compiledCode;
    244244    };
  • trunk/Source/JavaScriptCore/heap/IncrementalSweeper.cpp

    r119028 r120742  
    1515#if USE(CF)
    1616
    17 static const CFTimeInterval decade = 60 * 60 * 24 * 365 * 10;
    1817static const CFTimeInterval sweepTimeSlicePerBlock = 0.01;
    1918static const CFTimeInterval sweepTimeMultiplier = 1.0 / sweepTimeSlicePerBlock;
    2019 
    21 void IncrementalSweeper::timerDidFire(CFRunLoopTimerRef, void* info)
     20void IncrementalSweeper::doWork()
    2221{
    23     Heap* heap = static_cast<Heap*>(info);
    24     APIEntryShim shim(heap->globalData());
    25     heap->sweeper()->doSweep(WTF::monotonicallyIncreasingTime());
     22    APIEntryShim shim(m_globalData);
     23    doSweep(WTF::monotonicallyIncreasingTime());
    2624}
    2725   
    2826IncrementalSweeper::IncrementalSweeper(Heap* heap, CFRunLoopRef runLoop)
    29     : m_heap(heap)
     27    : HeapTimer(heap->globalData(), runLoop)
    3028    , m_currentBlockToSweepIndex(0)
    3129    , m_lengthOfLastSweepIncrement(0.0)
    3230{
    33     memset(&m_context, 0, sizeof(CFRunLoopTimerContext));
    34     m_context.info = m_heap;
    35     m_runLoop = runLoop;
    36     m_timer.adoptCF(CFRunLoopTimerCreate(0, CFAbsoluteTimeGetCurrent(), decade, 0, 0, &timerDidFire, &m_context));
    37     CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
    38 }
    39 
    40 IncrementalSweeper::~IncrementalSweeper()
    41 {
    42     CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
    43     CFRunLoopTimerInvalidate(m_timer.get());
    4431}
    4532
     
    5643void IncrementalSweeper::cancelTimer()
    5744{
    58     CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + decade);
     45    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
    5946}
    6047
     
    8673#else
    8774
    88 IncrementalSweeper::IncrementalSweeper()
     75IncrementalSweeper::IncrementalSweeper(JSGlobalData* globalData)
     76    : HeapTimer(globalData)
    8977{
    9078}
    9179
    92 IncrementalSweeper::~IncrementalSweeper()
     80void IncrementalSweeper::doWork()
    9381{
    9482}
    9583
    96 PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap*)
     84PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap* heap)
    9785{
    98     return adoptPtr(new IncrementalSweeper());
     86    return adoptPtr(new IncrementalSweeper(heap->globalData()));
    9987}
    10088
  • trunk/Source/JavaScriptCore/heap/IncrementalSweeper.h

    r119028 r120742  
    22#define IncrementalSweeper_h
    33
     4#include "HeapTimer.h"
    45#include "MarkedBlock.h"
    56#include <wtf/HashSet.h>
     
    89#include <wtf/Vector.h>
    910
    10 #if USE(CF)
    11 #include <CoreFoundation/CoreFoundation.h>
    12 #endif
    13 
    1411namespace JSC {
    1512
    1613class Heap;
    1714   
    18 class IncrementalSweeper {
     15class IncrementalSweeper : public HeapTimer {
    1916public:
    20     ~IncrementalSweeper();
    21 
    2217    static PassOwnPtr<IncrementalSweeper> create(Heap*);
    2318    void startSweeping(const HashSet<MarkedBlock*>& blockSnapshot);
     19    virtual void doWork();
    2420
    2521private:
     
    2723    IncrementalSweeper(Heap*, CFRunLoopRef);
    2824   
    29     static void timerDidFire(CFRunLoopTimerRef, void*);
    3025    void doSweep(double startTime);
    3126    void scheduleTimer();
    3227    void cancelTimer();
    3328   
    34     Heap* m_heap;
    3529    unsigned m_currentBlockToSweepIndex;
    36     RetainPtr<CFRunLoopTimerRef> m_timer;
    37     RetainPtr<CFRunLoopRef> m_runLoop;
    38     CFRunLoopTimerContext m_context;
    39    
    4030    double m_lengthOfLastSweepIncrement;
    4131    Vector<MarkedBlock*> m_blocksToSweep;
    4232#else
    4333   
    44     IncrementalSweeper();
     34    IncrementalSweeper(JSGlobalData*);
    4535   
    4636#endif
  • trunk/Source/JavaScriptCore/runtime/GCActivityCallback.cpp

    r115915 r120742  
    3030#include "GCActivityCallback.h"
    3131
     32#include "Heap.h"
     33
    3234namespace JSC {
    3335
    34 struct DefaultGCActivityCallbackPlatformData {
    35 };
    36 
    37 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap*)
     36DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
     37    : GCActivityCallback(heap->globalData())
    3838{
    3939}
    4040
    41 DefaultGCActivityCallback::~DefaultGCActivityCallback()
     41void DefaultGCActivityCallback::doWork()
    4242{
    4343}
     
    5151}
    5252
    53 void DefaultGCActivityCallback::synchronize()
    54 {
    55 }
    56 
    5753void DefaultGCActivityCallback::cancel()
    5854{
  • trunk/Source/JavaScriptCore/runtime/GCActivityCallback.h

    r117015 r120742  
    3030#define GCActivityCallback_h
    3131
     32#include "HeapTimer.h"
    3233#include <wtf/OwnPtr.h>
    3334#include <wtf/PassOwnPtr.h>
     
    4142class Heap;
    4243
    43 class GCActivityCallback {
     44class GCActivityCallback : public HeapTimer {
    4445public:
    45     virtual ~GCActivityCallback() { }
    4646    virtual void didAllocate(size_t) { }
    4747    virtual void willCollect() { }
    48     virtual void synchronize() { }
    4948    virtual void cancel() { }
    5049    bool isEnabled() const { return m_enabled; }
     
    5251
    5352protected:
    54     GCActivityCallback()
    55         : m_enabled(true)
     53#if USE(CF)
     54    GCActivityCallback(JSGlobalData* globalData, CFRunLoopRef runLoop)
     55        : HeapTimer(globalData, runLoop)
     56        , m_enabled(true)
    5657    {
    5758    }
     59# else
     60    GCActivityCallback(JSGlobalData* globalData)
     61        : HeapTimer(globalData)
     62        , m_enabled(true)
     63    {
     64    }
     65#endif
    5866
    5967    bool m_enabled;
    6068};
    61 
    62 struct DefaultGCActivityCallbackPlatformData;
    6369
    6470class DefaultGCActivityCallback : public GCActivityCallback {
     
    6773
    6874    DefaultGCActivityCallback(Heap*);
    69     virtual ~DefaultGCActivityCallback();
    7075
    7176    virtual void didAllocate(size_t);
    7277    virtual void willCollect();
    73     virtual void synchronize();
    7478    virtual void cancel();
     79   
     80    virtual void doWork();
    7581
    7682#if USE(CF)
    7783protected:
    7884    DefaultGCActivityCallback(Heap*, CFRunLoopRef);
    79     void commonConstructor(Heap*, CFRunLoopRef);
     85   
     86    void cancelTimer();
     87    void scheduleTimer(double);
     88   
     89private:
     90    double m_delay;
    8091#endif
    81 
    82 private:
    83     OwnPtr<DefaultGCActivityCallbackPlatformData> d;
    8492};
    8593
  • trunk/Source/JavaScriptCore/runtime/GCActivityCallbackBlackBerry.cpp

    r120502 r120742  
    2525namespace JSC {
    2626
    27 struct DefaultGCActivityCallbackPlatformData {
    28     explicit DefaultGCActivityCallbackPlatformData(Heap* heap) : m_heap(heap) { }
    29     Heap* m_heap;
    30 };
    31 
    3227DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
    33     : d(adoptPtr(new DefaultGCActivityCallbackPlatformData(heap)))
     28    : GCActivityCallback(heap->globalData())
    3429{
    3530}
    3631
    37 DefaultGCActivityCallback::~DefaultGCActivityCallback()
     32DefaultGCActivityCallback::doWork()
    3833{
    3934}
     
    4742        return;
    4843
    49     if (d->m_heap->isBusy() || !d->m_heap->isSafeToCollect())
     44    if (m_globalData->heap.isBusy() || !m_globalData->heap.isSafeToCollect())
    5045        return;
    5146
    52     d->m_heap->collect(Heap::DoNotSweep);
     47    m_globalData->heap.collect(Heap::DoNotSweep);
    5348}
    5449
    5550void DefaultGCActivityCallback::willCollect()
    56 {
    57 }
    58 
    59 void DefaultGCActivityCallback::synchronize()
    6051{
    6152}
  • trunk/Source/JavaScriptCore/runtime/GCActivityCallbackCF.cpp

    r117015 r120742  
    4545namespace JSC {
    4646
    47 struct DefaultGCActivityCallbackPlatformData {
    48     static void timerDidFire(CFRunLoopTimerRef, void *info);
    49 
    50     RetainPtr<CFRunLoopTimerRef> timer;
    51     RetainPtr<CFRunLoopRef> runLoop;
    52     CFRunLoopTimerContext context;
    53     double delay;
    54 };
    55 
    5647const double gcTimeSlicePerMB = 0.01; // Percentage of CPU time we will spend to reclaim 1 MB
    5748const double maxGCTimeSlice = 0.05; // The maximum amount of CPU time we want to use for opportunistic timer-triggered collections.
    5849const double timerSlop = 2.0; // Fudge factor to avoid performance cost of resetting timer.
    5950const double pagingTimeOut = 0.1; // Time in seconds to allow opportunistic timer to iterate over all blocks to see if the Heap is paged out.
    60 const CFTimeInterval decade = 60 * 60 * 24 * 365 * 10;
    6151const CFTimeInterval hour = 60 * 60;
    6252
    63 void DefaultGCActivityCallbackPlatformData::timerDidFire(CFRunLoopTimerRef, void *info)
     53DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
     54    : GCActivityCallback(heap->globalData(), CFRunLoopGetCurrent())
     55    , m_delay(s_decade)
    6456{
    65     Heap* heap = static_cast<Heap*>(info);
    66     if (!heap->activityCallback()->isEnabled())
     57}
     58
     59DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap, CFRunLoopRef runLoop)
     60    : GCActivityCallback(heap->globalData(), runLoop)
     61    , m_delay(s_decade)
     62{
     63}
     64
     65void DefaultGCActivityCallback::doWork()
     66{
     67    Heap* heap = &m_globalData->heap;
     68    if (!isEnabled())
    6769        return;
    68 
    69     APIEntryShim shim(heap->globalData());
     70   
     71    APIEntryShim shim(m_globalData);
    7072#if !PLATFORM(IOS)
    7173    double startTime = WTF::monotonicallyIncreasingTime();
     
    7880    heap->collectAllGarbage();
    7981}
    80 
    81 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
     82   
     83void DefaultGCActivityCallback::scheduleTimer(double newDelay)
    8284{
    83     commonConstructor(heap, CFRunLoopGetCurrent());
     85    if (newDelay * timerSlop > m_delay)
     86        return;
     87    double delta = m_delay - newDelay;
     88    m_delay = newDelay;
     89    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFRunLoopTimerGetNextFireDate(m_timer.get()) - delta);
    8490}
    8591
    86 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap, CFRunLoopRef runLoop)
     92void DefaultGCActivityCallback::cancelTimer()
    8793{
    88     commonConstructor(heap, runLoop);
    89 }
    90 
    91 DefaultGCActivityCallback::~DefaultGCActivityCallback()
    92 {
    93     CFRunLoopRemoveTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes);
    94     CFRunLoopTimerInvalidate(d->timer.get());
    95 }
    96 
    97 void DefaultGCActivityCallback::commonConstructor(Heap* heap, CFRunLoopRef runLoop)
    98 {
    99     d = adoptPtr(new DefaultGCActivityCallbackPlatformData);
    100 
    101     memset(&d->context, 0, sizeof(CFRunLoopTimerContext));
    102     d->context.info = heap;
    103     d->runLoop = runLoop;
    104     d->timer.adoptCF(CFRunLoopTimerCreate(0, decade, decade, 0, 0, DefaultGCActivityCallbackPlatformData::timerDidFire, &d->context));
    105     d->delay = decade;
    106     CFRunLoopAddTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes);
    107 }
    108 
    109 static void scheduleTimer(DefaultGCActivityCallbackPlatformData* d, double newDelay)
    110 {
    111     if (newDelay * timerSlop > d->delay)
    112         return;
    113     double delta = d->delay - newDelay;
    114     d->delay = newDelay;
    115     CFRunLoopTimerSetNextFireDate(d->timer.get(), CFRunLoopTimerGetNextFireDate(d->timer.get()) - delta);
    116 }
    117 
    118 static void cancelTimer(DefaultGCActivityCallbackPlatformData* d)
    119 {
    120     d->delay = decade;
    121     CFRunLoopTimerSetNextFireDate(d->timer.get(), CFAbsoluteTimeGetCurrent() + decade);
     94    m_delay = s_decade;
     95    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
    12296}
    12397
     
    128102    if (!bytes)
    129103        bytes = 1;
    130     Heap* heap = static_cast<Heap*>(d->context.info);
     104    Heap* heap = static_cast<Heap*>(&m_globalData->heap);
    131105    double gcTimeSlice = std::min((static_cast<double>(bytes) / MB) * gcTimeSlicePerMB, maxGCTimeSlice);
    132106    double newDelay = heap->lastGCLength() / gcTimeSlice;
    133     scheduleTimer(d.get(), newDelay);
     107    scheduleTimer(newDelay);
    134108}
    135109
    136110void DefaultGCActivityCallback::willCollect()
    137111{
    138     cancelTimer(d.get());
    139 }
    140 
    141 void DefaultGCActivityCallback::synchronize()
    142 {
    143     if (CFRunLoopGetCurrent() == d->runLoop.get())
    144         return;
    145     CFRunLoopRemoveTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes);
    146     d->runLoop = CFRunLoopGetCurrent();
    147     CFRunLoopAddTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes);
     112    cancelTimer();
    148113}
    149114
    150115void DefaultGCActivityCallback::cancel()
    151116{
    152     cancelTimer(d.get());
     117    cancelTimer();
    153118}
    154119
Note: See TracChangeset for help on using the changeset viewer.