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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.