Diff
Modified: trunk/Source/_javascript_Core/CMakeLists.txt (120741 => 120742)
--- trunk/Source/_javascript_Core/CMakeLists.txt 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/CMakeLists.txt 2012-06-19 19:17:31 UTC (rev 120742)
@@ -98,6 +98,7 @@
heap/HandleSet.cpp
heap/HandleStack.cpp
heap/Heap.cpp
+ heap/HeapTimer.cpp
heap/IncrementalSweeper.cpp
heap/MachineStackMarker.cpp
heap/MarkedAllocator.cpp
Modified: trunk/Source/_javascript_Core/ChangeLog (120741 => 120742)
--- trunk/Source/_javascript_Core/ChangeLog 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/ChangeLog 2012-06-19 19:17:31 UTC (rev 120742)
@@ -1,3 +1,75 @@
+2012-06-19 Mark Hahnenberg <[email protected]>
+
+ 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:
+ * _javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj:
+ * _javascript_Core.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):
+
+
2012-06-19 Mike West <[email protected]>
Introduce ENABLE_CSP_NEXT configuration flag.
Modified: trunk/Source/_javascript_Core/GNUmakefile.list.am (120741 => 120742)
--- trunk/Source/_javascript_Core/GNUmakefile.list.am 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/GNUmakefile.list.am 2012-06-19 19:17:31 UTC (rev 120742)
@@ -236,6 +236,8 @@
Source/_javascript_Core/heap/HandleSet.cpp \
Source/_javascript_Core/heap/HandleSet.h \
Source/_javascript_Core/heap/HeapBlock.h \
+ Source/_javascript_Core/heap/HeapTimer.h \
+ Source/_javascript_Core/heap/HeapTimer.cpp \
Source/_javascript_Core/heap/IncrementalSweeper.h \
Source/_javascript_Core/heap/IncrementalSweeper.cpp \
Source/_javascript_Core/heap/SlotVisitor.h \
Modified: trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj (120741 => 120742)
--- trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj 2012-06-19 19:17:31 UTC (rev 120742)
@@ -714,7 +714,7 @@
>
</File>
<File
- RelativePath="..\..\runtime\GCActivityCallback.cpp"
+ RelativePath="..\..\runtime\GCActivityCallbackCF.cpp"
>
</File>
<File
@@ -2186,6 +2186,14 @@
>
</File>
<File
+ RelativePath="..\..\heap\HeapTimer.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\heap\HeapTimer.h"
+ >
+ </File>
+ <File
RelativePath="..\..\heap\IncrementalSweeper.h"
>
</File>
Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (120741 => 120742)
--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2012-06-19 19:17:31 UTC (rev 120742)
@@ -651,6 +651,8 @@
C2C8D02D14A3C6E000578E65 /* CopiedSpaceInlineMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02B14A3C6B200578E65 /* CopiedSpaceInlineMethods.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2C8D03014A3CEFC00578E65 /* CopiedBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02E14A3CEFC00578E65 /* CopiedBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2C8D03114A3CEFC00578E65 /* HeapBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02F14A3CEFC00578E65 /* HeapBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ C2E526BD1590EF000054E48D /* HeapTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2E526BB1590EF000054E48D /* HeapTimer.cpp */; };
+ C2E526BE1590EF000054E48D /* HeapTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = C2E526BC1590EF000054E48D /* HeapTimer.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2EAA3FA149A835E00FCE112 /* CopiedSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = C2EAA3F8149A830800FCE112 /* CopiedSpace.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2EAD2FC14F0249800A4B159 /* CopiedAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = C2EAD2FB14F0249800A4B159 /* CopiedAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
DDF7ABD411F60ED200108E36 /* GCActivityCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = DDF7ABD211F60ED200108E36 /* GCActivityCallback.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1354,6 +1356,8 @@
C2C8D02B14A3C6B200578E65 /* CopiedSpaceInlineMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedSpaceInlineMethods.h; sourceTree = "<group>"; };
C2C8D02E14A3CEFC00578E65 /* CopiedBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedBlock.h; sourceTree = "<group>"; };
C2C8D02F14A3CEFC00578E65 /* HeapBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapBlock.h; sourceTree = "<group>"; };
+ C2E526BB1590EF000054E48D /* HeapTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HeapTimer.cpp; sourceTree = "<group>"; };
+ C2E526BC1590EF000054E48D /* HeapTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapTimer.h; sourceTree = "<group>"; };
C2EAA3F8149A830800FCE112 /* CopiedSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedSpace.h; sourceTree = "<group>"; };
C2EAD2FB14F0249800A4B159 /* CopiedAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedAllocator.h; sourceTree = "<group>"; };
D21202280AD4310C00ED79B6 /* DateConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DateConversion.cpp; sourceTree = "<group>"; };
@@ -1627,6 +1631,8 @@
142E312A134FF0A600AFADB5 /* heap */ = {
isa = PBXGroup;
children = (
+ C2E526BB1590EF000054E48D /* HeapTimer.cpp */,
+ C2E526BC1590EF000054E48D /* HeapTimer.h */,
C25F8BCB157544A900245B71 /* IncrementalSweeper.cpp */,
C25F8BCC157544A900245B71 /* IncrementalSweeper.h */,
14816E19154CC56C00B8054C /* BlockAllocator.cpp */,
@@ -2337,6 +2343,7 @@
86ADD1450FDDEA980006EEC2 /* ARMv7Assembler.h in Headers */,
C2EAD2FC14F0249800A4B159 /* CopiedAllocator.h in Headers */,
C2B916C214DA014E00CBAC86 /* MarkedAllocator.h in Headers */,
+ C2E526BE1590EF000054E48D /* HeapTimer.h in Headers */,
C25F8BCE157544A900245B71 /* IncrementalSweeper.h in Headers */,
BC18C3E60E16F5CD00B34460 /* ArrayConstructor.h in Headers */,
BC18C3E70E16F5CD00B34460 /* ArrayPrototype.h in Headers */,
@@ -3257,6 +3264,7 @@
0F919D10157F3329004A4E7D /* JSSegmentedVariableObject.cpp in Sources */,
0F919D2515853CE0004A4E7D /* Watchpoint.cpp in Sources */,
0F919D2815856773004A4E7D /* SymbolTable.cpp in Sources */,
+ C2E526BD1590EF000054E48D /* HeapTimer.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: trunk/Source/_javascript_Core/Target.pri (120741 => 120742)
--- trunk/Source/_javascript_Core/Target.pri 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/Target.pri 2012-06-19 19:17:31 UTC (rev 120742)
@@ -79,6 +79,7 @@
heap/HandleStack.cpp \
heap/BlockAllocator.cpp \
heap/Heap.cpp \
+ heap/HeapTimer.cpp \
heap/IncrementalSweeper.cpp \
heap/MachineStackMarker.cpp \
heap/MarkStack.cpp \
Modified: trunk/Source/_javascript_Core/heap/Heap.cpp (120741 => 120742)
--- trunk/Source/_javascript_Core/heap/Heap.cpp 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/heap/Heap.cpp 2012-06-19 19:17:31 UTC (rev 120742)
@@ -245,8 +245,6 @@
, m_operationInProgress(NoOperation)
, m_objectSpace(this)
, m_storageSpace(this)
- , m_activityCallback(DefaultGCActivityCallback::create(this))
- , m_sweeper(IncrementalSweeper::create(this))
, m_machineThreads(this)
, m_sharedData(globalData)
, m_slotVisitor(m_sharedData)
@@ -255,6 +253,8 @@
, m_globalData(globalData)
, m_lastGCLength(0)
, m_lastCodeDiscardTime(WTF::currentTime())
+ , m_activityCallback(DefaultGCActivityCallback::create(this))
+ , m_sweeper(IncrementalSweeper::create(this))
{
m_storageSpace.init();
}
Modified: trunk/Source/_javascript_Core/heap/Heap.h (120741 => 120742)
--- trunk/Source/_javascript_Core/heap/Heap.h 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/heap/Heap.h 2012-06-19 19:17:31 UTC (rev 120742)
@@ -221,9 +221,6 @@
Vector<Vector<ValueStringPair>* > m_tempSortingVectors;
OwnPtr<HashSet<MarkedArgumentBuffer*> > m_markListSet;
- OwnPtr<GCActivityCallback> m_activityCallback;
- OwnPtr<IncrementalSweeper> m_sweeper;
-
MachineThreads m_machineThreads;
MarkStackThreadSharedData m_sharedData;
@@ -240,6 +237,9 @@
double m_lastGCLength;
double m_lastCodeDiscardTime;
+ OwnPtr<GCActivityCallback> m_activityCallback;
+ OwnPtr<IncrementalSweeper> m_sweeper;
+
DoublyLinkedList<ExecutableBase> m_compiledCode;
};
Added: trunk/Source/_javascript_Core/heap/HeapTimer.cpp (0 => 120742)
--- trunk/Source/_javascript_Core/heap/HeapTimer.cpp (rev 0)
+++ trunk/Source/_javascript_Core/heap/HeapTimer.cpp 2012-06-19 19:17:31 UTC (rev 120742)
@@ -0,0 +1,71 @@
+#include "config.h"
+#include "HeapTimer.h"
+
+#include <wtf/Threading.h>
+
+namespace JSC {
+
+#if USE(CF)
+
+const CFTimeInterval HeapTimer::s_decade = 60 * 60 * 24 * 365 * 10;
+
+HeapTimer::HeapTimer(JSGlobalData* globalData, CFRunLoopRef runLoop)
+ : m_globalData(globalData)
+ , m_runLoop(runLoop)
+{
+ memset(&m_context, 0, sizeof(CFRunLoopTimerContext));
+ m_context.info = this;
+ m_timer.adoptCF(CFRunLoopTimerCreate(0, s_decade, s_decade, 0, 0, HeapTimer::timerDidFire, &m_context));
+ CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
+}
+
+HeapTimer::~HeapTimer()
+{
+ invalidate();
+}
+
+void HeapTimer::synchronize()
+{
+ if (CFRunLoopGetCurrent() == m_runLoop.get())
+ return;
+ CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
+ m_runLoop = CFRunLoopGetCurrent();
+ CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
+}
+
+void HeapTimer::invalidate()
+{
+ CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
+ CFRunLoopTimerInvalidate(m_timer.get());
+}
+
+void HeapTimer::timerDidFire(CFRunLoopTimerRef, void* info)
+{
+ HeapTimer* agent = static_cast<HeapTimer*>(info);
+ agent->doWork();
+}
+
+#else
+
+HeapTimer::HeapTimer(JSGlobalData* globalData)
+ : m_globalData(globalData)
+{
+}
+
+HeapTimer::~HeapTimer()
+{
+}
+
+void HeapTimer::synchronize()
+{
+}
+
+void HeapTimer::invalidate()
+{
+}
+
+
+#endif
+
+
+} // namespace JSC
Added: trunk/Source/_javascript_Core/heap/HeapTimer.h (0 => 120742)
--- trunk/Source/_javascript_Core/heap/HeapTimer.h (rev 0)
+++ trunk/Source/_javascript_Core/heap/HeapTimer.h 2012-06-19 19:17:31 UTC (rev 120742)
@@ -0,0 +1,45 @@
+#ifndef HeapTimer_h
+#define HeapTimer_h
+
+#include <wtf/RetainPtr.h>
+
+#if USE(CF)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
+namespace JSC {
+
+class JSGlobalData;
+
+class HeapTimer {
+public:
+#if USE(CF)
+ HeapTimer(JSGlobalData*, CFRunLoopRef);
+ static void timerDidFire(CFRunLoopTimerRef, void*);
+#else
+ HeapTimer(JSGlobalData*);
+#endif
+
+ virtual ~HeapTimer();
+
+ virtual void synchronize();
+ virtual void doWork() = 0;
+
+protected:
+ JSGlobalData* m_globalData;
+
+#if USE(CF)
+ static const CFTimeInterval s_decade;
+
+ RetainPtr<CFRunLoopTimerRef> m_timer;
+ RetainPtr<CFRunLoopRef> m_runLoop;
+ CFRunLoopTimerContext m_context;
+#endif
+
+private:
+ void invalidate();
+};
+
+} // namespace JSC
+
+#endif
Modified: trunk/Source/_javascript_Core/heap/IncrementalSweeper.cpp (120741 => 120742)
--- trunk/Source/_javascript_Core/heap/IncrementalSweeper.cpp 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/heap/IncrementalSweeper.cpp 2012-06-19 19:17:31 UTC (rev 120742)
@@ -14,35 +14,22 @@
#if USE(CF)
-static const CFTimeInterval decade = 60 * 60 * 24 * 365 * 10;
static const CFTimeInterval sweepTimeSlicePerBlock = 0.01;
static const CFTimeInterval sweepTimeMultiplier = 1.0 / sweepTimeSlicePerBlock;
-void IncrementalSweeper::timerDidFire(CFRunLoopTimerRef, void* info)
+void IncrementalSweeper::doWork()
{
- Heap* heap = static_cast<Heap*>(info);
- APIEntryShim shim(heap->globalData());
- heap->sweeper()->doSweep(WTF::monotonicallyIncreasingTime());
+ APIEntryShim shim(m_globalData);
+ doSweep(WTF::monotonicallyIncreasingTime());
}
IncrementalSweeper::IncrementalSweeper(Heap* heap, CFRunLoopRef runLoop)
- : m_heap(heap)
+ : HeapTimer(heap->globalData(), runLoop)
, m_currentBlockToSweepIndex(0)
, m_lengthOfLastSweepIncrement(0.0)
{
- memset(&m_context, 0, sizeof(CFRunLoopTimerContext));
- m_context.info = m_heap;
- m_runLoop = runLoop;
- m_timer.adoptCF(CFRunLoopTimerCreate(0, CFAbsoluteTimeGetCurrent(), decade, 0, 0, &timerDidFire, &m_context));
- CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
}
-IncrementalSweeper::~IncrementalSweeper()
-{
- CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
- CFRunLoopTimerInvalidate(m_timer.get());
-}
-
PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap* heap)
{
return adoptPtr(new IncrementalSweeper(heap, CFRunLoopGetCurrent()));
@@ -55,7 +42,7 @@
void IncrementalSweeper::cancelTimer()
{
- CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + decade);
+ CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
}
void IncrementalSweeper::doSweep(double sweepBeginTime)
@@ -85,17 +72,18 @@
#else
-IncrementalSweeper::IncrementalSweeper()
+IncrementalSweeper::IncrementalSweeper(JSGlobalData* globalData)
+ : HeapTimer(globalData)
{
}
-IncrementalSweeper::~IncrementalSweeper()
+void IncrementalSweeper::doWork()
{
}
-PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap*)
+PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap* heap)
{
- return adoptPtr(new IncrementalSweeper());
+ return adoptPtr(new IncrementalSweeper(heap->globalData()));
}
void IncrementalSweeper::startSweeping(const HashSet<MarkedBlock*>&)
Modified: trunk/Source/_javascript_Core/heap/IncrementalSweeper.h (120741 => 120742)
--- trunk/Source/_javascript_Core/heap/IncrementalSweeper.h 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/heap/IncrementalSweeper.h 2012-06-19 19:17:31 UTC (rev 120742)
@@ -1,47 +1,37 @@
#ifndef IncrementalSweeper_h
#define IncrementalSweeper_h
+#include "HeapTimer.h"
#include "MarkedBlock.h"
#include <wtf/HashSet.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/RetainPtr.h>
#include <wtf/Vector.h>
-#if USE(CF)
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
namespace JSC {
class Heap;
-class IncrementalSweeper {
+class IncrementalSweeper : public HeapTimer {
public:
- ~IncrementalSweeper();
-
static PassOwnPtr<IncrementalSweeper> create(Heap*);
void startSweeping(const HashSet<MarkedBlock*>& blockSnapshot);
+ virtual void doWork();
private:
#if USE(CF)
IncrementalSweeper(Heap*, CFRunLoopRef);
- static void timerDidFire(CFRunLoopTimerRef, void*);
void doSweep(double startTime);
void scheduleTimer();
void cancelTimer();
- Heap* m_heap;
unsigned m_currentBlockToSweepIndex;
- RetainPtr<CFRunLoopTimerRef> m_timer;
- RetainPtr<CFRunLoopRef> m_runLoop;
- CFRunLoopTimerContext m_context;
-
double m_lengthOfLastSweepIncrement;
Vector<MarkedBlock*> m_blocksToSweep;
#else
- IncrementalSweeper();
+ IncrementalSweeper(JSGlobalData*);
#endif
};
Modified: trunk/Source/_javascript_Core/runtime/GCActivityCallback.cpp (120741 => 120742)
--- trunk/Source/_javascript_Core/runtime/GCActivityCallback.cpp 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/runtime/GCActivityCallback.cpp 2012-06-19 19:17:31 UTC (rev 120742)
@@ -29,16 +29,16 @@
#include "config.h"
#include "GCActivityCallback.h"
+#include "Heap.h"
+
namespace JSC {
-struct DefaultGCActivityCallbackPlatformData {
-};
-
-DefaultGCActivityCallback::DefaultGCActivityCallback(Heap*)
+DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
+ : GCActivityCallback(heap->globalData())
{
}
-DefaultGCActivityCallback::~DefaultGCActivityCallback()
+void DefaultGCActivityCallback::doWork()
{
}
@@ -50,10 +50,6 @@
{
}
-void DefaultGCActivityCallback::synchronize()
-{
-}
-
void DefaultGCActivityCallback::cancel()
{
}
Modified: trunk/Source/_javascript_Core/runtime/GCActivityCallback.h (120741 => 120742)
--- trunk/Source/_javascript_Core/runtime/GCActivityCallback.h 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/runtime/GCActivityCallback.h 2012-06-19 19:17:31 UTC (rev 120742)
@@ -29,6 +29,7 @@
#ifndef GCActivityCallback_h
#define GCActivityCallback_h
+#include "HeapTimer.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
@@ -40,47 +41,54 @@
class Heap;
-class GCActivityCallback {
+class GCActivityCallback : public HeapTimer {
public:
- virtual ~GCActivityCallback() { }
virtual void didAllocate(size_t) { }
virtual void willCollect() { }
- virtual void synchronize() { }
virtual void cancel() { }
bool isEnabled() const { return m_enabled; }
void setEnabled(bool enabled) { m_enabled = enabled; }
protected:
- GCActivityCallback()
- : m_enabled(true)
+#if USE(CF)
+ GCActivityCallback(JSGlobalData* globalData, CFRunLoopRef runLoop)
+ : HeapTimer(globalData, runLoop)
+ , m_enabled(true)
{
}
+# else
+ GCActivityCallback(JSGlobalData* globalData)
+ : HeapTimer(globalData)
+ , m_enabled(true)
+ {
+ }
+#endif
bool m_enabled;
};
-struct DefaultGCActivityCallbackPlatformData;
-
class DefaultGCActivityCallback : public GCActivityCallback {
public:
static PassOwnPtr<DefaultGCActivityCallback> create(Heap*);
DefaultGCActivityCallback(Heap*);
- virtual ~DefaultGCActivityCallback();
virtual void didAllocate(size_t);
virtual void willCollect();
- virtual void synchronize();
virtual void cancel();
+
+ virtual void doWork();
#if USE(CF)
protected:
DefaultGCActivityCallback(Heap*, CFRunLoopRef);
- void commonConstructor(Heap*, CFRunLoopRef);
+
+ void cancelTimer();
+ void scheduleTimer(double);
+
+private:
+ double m_delay;
#endif
-
-private:
- OwnPtr<DefaultGCActivityCallbackPlatformData> d;
};
inline PassOwnPtr<DefaultGCActivityCallback> DefaultGCActivityCallback::create(Heap* heap)
Modified: trunk/Source/_javascript_Core/runtime/GCActivityCallbackBlackBerry.cpp (120741 => 120742)
--- trunk/Source/_javascript_Core/runtime/GCActivityCallbackBlackBerry.cpp 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/runtime/GCActivityCallbackBlackBerry.cpp 2012-06-19 19:17:31 UTC (rev 120742)
@@ -24,17 +24,12 @@
namespace JSC {
-struct DefaultGCActivityCallbackPlatformData {
- explicit DefaultGCActivityCallbackPlatformData(Heap* heap) : m_heap(heap) { }
- Heap* m_heap;
-};
-
DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
- : d(adoptPtr(new DefaultGCActivityCallbackPlatformData(heap)))
+ : GCActivityCallback(heap->globalData())
{
}
-DefaultGCActivityCallback::~DefaultGCActivityCallback()
+DefaultGCActivityCallback::doWork()
{
}
@@ -46,20 +41,16 @@
if (bytesAllocated < 1 * 1024 * 1024)
return;
- if (d->m_heap->isBusy() || !d->m_heap->isSafeToCollect())
+ if (m_globalData->heap.isBusy() || !m_globalData->heap.isSafeToCollect())
return;
- d->m_heap->collect(Heap::DoNotSweep);
+ m_globalData->heap.collect(Heap::DoNotSweep);
}
void DefaultGCActivityCallback::willCollect()
{
}
-void DefaultGCActivityCallback::synchronize()
-{
-}
-
void DefaultGCActivityCallback::cancel()
{
}
Modified: trunk/Source/_javascript_Core/runtime/GCActivityCallbackCF.cpp (120741 => 120742)
--- trunk/Source/_javascript_Core/runtime/GCActivityCallbackCF.cpp 2012-06-19 19:09:49 UTC (rev 120741)
+++ trunk/Source/_javascript_Core/runtime/GCActivityCallbackCF.cpp 2012-06-19 19:17:31 UTC (rev 120742)
@@ -44,29 +44,31 @@
namespace JSC {
-struct DefaultGCActivityCallbackPlatformData {
- static void timerDidFire(CFRunLoopTimerRef, void *info);
-
- RetainPtr<CFRunLoopTimerRef> timer;
- RetainPtr<CFRunLoopRef> runLoop;
- CFRunLoopTimerContext context;
- double delay;
-};
-
const double gcTimeSlicePerMB = 0.01; // Percentage of CPU time we will spend to reclaim 1 MB
const double maxGCTimeSlice = 0.05; // The maximum amount of CPU time we want to use for opportunistic timer-triggered collections.
const double timerSlop = 2.0; // Fudge factor to avoid performance cost of resetting timer.
const double pagingTimeOut = 0.1; // Time in seconds to allow opportunistic timer to iterate over all blocks to see if the Heap is paged out.
-const CFTimeInterval decade = 60 * 60 * 24 * 365 * 10;
const CFTimeInterval hour = 60 * 60;
-void DefaultGCActivityCallbackPlatformData::timerDidFire(CFRunLoopTimerRef, void *info)
+DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
+ : GCActivityCallback(heap->globalData(), CFRunLoopGetCurrent())
+ , m_delay(s_decade)
{
- Heap* heap = static_cast<Heap*>(info);
- if (!heap->activityCallback()->isEnabled())
- return;
+}
- APIEntryShim shim(heap->globalData());
+DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap, CFRunLoopRef runLoop)
+ : GCActivityCallback(heap->globalData(), runLoop)
+ , m_delay(s_decade)
+{
+}
+
+void DefaultGCActivityCallback::doWork()
+{
+ Heap* heap = &m_globalData->heap;
+ if (!isEnabled())
+ return;
+
+ APIEntryShim shim(m_globalData);
#if !PLATFORM(IOS)
double startTime = WTF::monotonicallyIncreasingTime();
if (heap->isPagedOut(startTime + pagingTimeOut)) {
@@ -77,48 +79,20 @@
#endif
heap->collectAllGarbage();
}
-
-DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
+
+void DefaultGCActivityCallback::scheduleTimer(double newDelay)
{
- commonConstructor(heap, CFRunLoopGetCurrent());
-}
-
-DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap, CFRunLoopRef runLoop)
-{
- commonConstructor(heap, runLoop);
-}
-
-DefaultGCActivityCallback::~DefaultGCActivityCallback()
-{
- CFRunLoopRemoveTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes);
- CFRunLoopTimerInvalidate(d->timer.get());
-}
-
-void DefaultGCActivityCallback::commonConstructor(Heap* heap, CFRunLoopRef runLoop)
-{
- d = adoptPtr(new DefaultGCActivityCallbackPlatformData);
-
- memset(&d->context, 0, sizeof(CFRunLoopTimerContext));
- d->context.info = heap;
- d->runLoop = runLoop;
- d->timer.adoptCF(CFRunLoopTimerCreate(0, decade, decade, 0, 0, DefaultGCActivityCallbackPlatformData::timerDidFire, &d->context));
- d->delay = decade;
- CFRunLoopAddTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes);
-}
-
-static void scheduleTimer(DefaultGCActivityCallbackPlatformData* d, double newDelay)
-{
- if (newDelay * timerSlop > d->delay)
+ if (newDelay * timerSlop > m_delay)
return;
- double delta = d->delay - newDelay;
- d->delay = newDelay;
- CFRunLoopTimerSetNextFireDate(d->timer.get(), CFRunLoopTimerGetNextFireDate(d->timer.get()) - delta);
+ double delta = m_delay - newDelay;
+ m_delay = newDelay;
+ CFRunLoopTimerSetNextFireDate(m_timer.get(), CFRunLoopTimerGetNextFireDate(m_timer.get()) - delta);
}
-static void cancelTimer(DefaultGCActivityCallbackPlatformData* d)
+void DefaultGCActivityCallback::cancelTimer()
{
- d->delay = decade;
- CFRunLoopTimerSetNextFireDate(d->timer.get(), CFAbsoluteTimeGetCurrent() + decade);
+ m_delay = s_decade;
+ CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
}
void DefaultGCActivityCallback::didAllocate(size_t bytes)
@@ -127,29 +101,20 @@
// We pretend it's one byte so that we don't ignore this allocation entirely.
if (!bytes)
bytes = 1;
- Heap* heap = static_cast<Heap*>(d->context.info);
+ Heap* heap = static_cast<Heap*>(&m_globalData->heap);
double gcTimeSlice = std::min((static_cast<double>(bytes) / MB) * gcTimeSlicePerMB, maxGCTimeSlice);
double newDelay = heap->lastGCLength() / gcTimeSlice;
- scheduleTimer(d.get(), newDelay);
+ scheduleTimer(newDelay);
}
void DefaultGCActivityCallback::willCollect()
{
- cancelTimer(d.get());
+ cancelTimer();
}
-void DefaultGCActivityCallback::synchronize()
-{
- if (CFRunLoopGetCurrent() == d->runLoop.get())
- return;
- CFRunLoopRemoveTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes);
- d->runLoop = CFRunLoopGetCurrent();
- CFRunLoopAddTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes);
-}
-
void DefaultGCActivityCallback::cancel()
{
- cancelTimer(d.get());
+ cancelTimer();
}
}