Changeset 120742 in webkit
- Timestamp:
- Jun 19, 2012, 12:17:31 PM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/CMakeLists.txt
r120244 r120742 99 99 heap/HandleStack.cpp 100 100 heap/Heap.cpp 101 heap/HeapTimer.cpp 101 102 heap/IncrementalSweeper.cpp 102 103 heap/MachineStackMarker.cpp -
trunk/Source/JavaScriptCore/ChangeLog
r120698 r120742 1 2012-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 1 73 2012-06-19 Mike West <[email protected]> 2 74 -
trunk/Source/JavaScriptCore/GNUmakefile.list.am
r120244 r120742 237 237 Source/JavaScriptCore/heap/HandleSet.h \ 238 238 Source/JavaScriptCore/heap/HeapBlock.h \ 239 Source/JavaScriptCore/heap/HeapTimer.h \ 240 Source/JavaScriptCore/heap/HeapTimer.cpp \ 239 241 Source/JavaScriptCore/heap/IncrementalSweeper.h \ 240 242 Source/JavaScriptCore/heap/IncrementalSweeper.cpp \ -
trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
r120244 r120742 715 715 </File> 716 716 <File 717 RelativePath="..\..\runtime\GCActivityCallback .cpp"717 RelativePath="..\..\runtime\GCActivityCallbackCF.cpp" 718 718 > 719 719 </File> … … 2187 2187 </File> 2188 2188 <File 2189 RelativePath="..\..\heap\HeapTimer.cpp" 2190 > 2191 </File> 2192 <File 2193 RelativePath="..\..\heap\HeapTimer.h" 2194 > 2195 </File> 2196 <File 2189 2197 RelativePath="..\..\heap\IncrementalSweeper.h" 2190 2198 > -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r120244 r120742 652 652 C2C8D03014A3CEFC00578E65 /* CopiedBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02E14A3CEFC00578E65 /* CopiedBlock.h */; settings = {ATTRIBUTES = (Private, ); }; }; 653 653 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, ); }; }; 654 656 C2EAA3FA149A835E00FCE112 /* CopiedSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = C2EAA3F8149A830800FCE112 /* CopiedSpace.h */; settings = {ATTRIBUTES = (Private, ); }; }; 655 657 C2EAD2FC14F0249800A4B159 /* CopiedAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = C2EAD2FB14F0249800A4B159 /* CopiedAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 1355 1357 C2C8D02E14A3CEFC00578E65 /* CopiedBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedBlock.h; sourceTree = "<group>"; }; 1356 1358 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>"; }; 1357 1361 C2EAA3F8149A830800FCE112 /* CopiedSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedSpace.h; sourceTree = "<group>"; }; 1358 1362 C2EAD2FB14F0249800A4B159 /* CopiedAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedAllocator.h; sourceTree = "<group>"; }; … … 1628 1632 isa = PBXGroup; 1629 1633 children = ( 1634 C2E526BB1590EF000054E48D /* HeapTimer.cpp */, 1635 C2E526BC1590EF000054E48D /* HeapTimer.h */, 1630 1636 C25F8BCB157544A900245B71 /* IncrementalSweeper.cpp */, 1631 1637 C25F8BCC157544A900245B71 /* IncrementalSweeper.h */, … … 2338 2344 C2EAD2FC14F0249800A4B159 /* CopiedAllocator.h in Headers */, 2339 2345 C2B916C214DA014E00CBAC86 /* MarkedAllocator.h in Headers */, 2346 C2E526BE1590EF000054E48D /* HeapTimer.h in Headers */, 2340 2347 C25F8BCE157544A900245B71 /* IncrementalSweeper.h in Headers */, 2341 2348 BC18C3E60E16F5CD00B34460 /* ArrayConstructor.h in Headers */, … … 3258 3265 0F919D2515853CE0004A4E7D /* Watchpoint.cpp in Sources */, 3259 3266 0F919D2815856773004A4E7D /* SymbolTable.cpp in Sources */, 3267 C2E526BD1590EF000054E48D /* HeapTimer.cpp in Sources */, 3260 3268 ); 3261 3269 runOnlyForDeploymentPostprocessing = 0; -
trunk/Source/JavaScriptCore/Target.pri
r120244 r120742 80 80 heap/BlockAllocator.cpp \ 81 81 heap/Heap.cpp \ 82 heap/HeapTimer.cpp \ 82 83 heap/IncrementalSweeper.cpp \ 83 84 heap/MachineStackMarker.cpp \ -
trunk/Source/JavaScriptCore/heap/Heap.cpp
r119909 r120742 246 246 , m_objectSpace(this) 247 247 , m_storageSpace(this) 248 , m_activityCallback(DefaultGCActivityCallback::create(this))249 , m_sweeper(IncrementalSweeper::create(this))250 248 , m_machineThreads(this) 251 249 , m_sharedData(globalData) … … 256 254 , m_lastGCLength(0) 257 255 , m_lastCodeDiscardTime(WTF::currentTime()) 256 , m_activityCallback(DefaultGCActivityCallback::create(this)) 257 , m_sweeper(IncrementalSweeper::create(this)) 258 258 { 259 259 m_storageSpace.init(); -
trunk/Source/JavaScriptCore/heap/Heap.h
r120502 r120742 222 222 OwnPtr<HashSet<MarkedArgumentBuffer*> > m_markListSet; 223 223 224 OwnPtr<GCActivityCallback> m_activityCallback;225 OwnPtr<IncrementalSweeper> m_sweeper;226 227 224 MachineThreads m_machineThreads; 228 225 … … 241 238 double m_lastCodeDiscardTime; 242 239 240 OwnPtr<GCActivityCallback> m_activityCallback; 241 OwnPtr<IncrementalSweeper> m_sweeper; 242 243 243 DoublyLinkedList<ExecutableBase> m_compiledCode; 244 244 }; -
trunk/Source/JavaScriptCore/heap/IncrementalSweeper.cpp
r119028 r120742 15 15 #if USE(CF) 16 16 17 static const CFTimeInterval decade = 60 * 60 * 24 * 365 * 10;18 17 static const CFTimeInterval sweepTimeSlicePerBlock = 0.01; 19 18 static const CFTimeInterval sweepTimeMultiplier = 1.0 / sweepTimeSlicePerBlock; 20 19 21 void IncrementalSweeper:: timerDidFire(CFRunLoopTimerRef, void* info)20 void IncrementalSweeper::doWork() 22 21 { 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()); 26 24 } 27 25 28 26 IncrementalSweeper::IncrementalSweeper(Heap* heap, CFRunLoopRef runLoop) 29 : m_heap(heap)27 : HeapTimer(heap->globalData(), runLoop) 30 28 , m_currentBlockToSweepIndex(0) 31 29 , m_lengthOfLastSweepIncrement(0.0) 32 30 { 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());44 31 } 45 32 … … 56 43 void IncrementalSweeper::cancelTimer() 57 44 { 58 CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + decade);45 CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade); 59 46 } 60 47 … … 86 73 #else 87 74 88 IncrementalSweeper::IncrementalSweeper() 75 IncrementalSweeper::IncrementalSweeper(JSGlobalData* globalData) 76 : HeapTimer(globalData) 89 77 { 90 78 } 91 79 92 IncrementalSweeper::~IncrementalSweeper()80 void IncrementalSweeper::doWork() 93 81 { 94 82 } 95 83 96 PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap* )84 PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap* heap) 97 85 { 98 return adoptPtr(new IncrementalSweeper( ));86 return adoptPtr(new IncrementalSweeper(heap->globalData())); 99 87 } 100 88 -
trunk/Source/JavaScriptCore/heap/IncrementalSweeper.h
r119028 r120742 2 2 #define IncrementalSweeper_h 3 3 4 #include "HeapTimer.h" 4 5 #include "MarkedBlock.h" 5 6 #include <wtf/HashSet.h> … … 8 9 #include <wtf/Vector.h> 9 10 10 #if USE(CF)11 #include <CoreFoundation/CoreFoundation.h>12 #endif13 14 11 namespace JSC { 15 12 16 13 class Heap; 17 14 18 class IncrementalSweeper {15 class IncrementalSweeper : public HeapTimer { 19 16 public: 20 ~IncrementalSweeper();21 22 17 static PassOwnPtr<IncrementalSweeper> create(Heap*); 23 18 void startSweeping(const HashSet<MarkedBlock*>& blockSnapshot); 19 virtual void doWork(); 24 20 25 21 private: … … 27 23 IncrementalSweeper(Heap*, CFRunLoopRef); 28 24 29 static void timerDidFire(CFRunLoopTimerRef, void*);30 25 void doSweep(double startTime); 31 26 void scheduleTimer(); 32 27 void cancelTimer(); 33 28 34 Heap* m_heap;35 29 unsigned m_currentBlockToSweepIndex; 36 RetainPtr<CFRunLoopTimerRef> m_timer;37 RetainPtr<CFRunLoopRef> m_runLoop;38 CFRunLoopTimerContext m_context;39 40 30 double m_lengthOfLastSweepIncrement; 41 31 Vector<MarkedBlock*> m_blocksToSweep; 42 32 #else 43 33 44 IncrementalSweeper( );34 IncrementalSweeper(JSGlobalData*); 45 35 46 36 #endif -
trunk/Source/JavaScriptCore/runtime/GCActivityCallback.cpp
r115915 r120742 30 30 #include "GCActivityCallback.h" 31 31 32 #include "Heap.h" 33 32 34 namespace JSC { 33 35 34 struct DefaultGCActivityCallbackPlatformData { 35 }; 36 37 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap*) 36 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap) 37 : GCActivityCallback(heap->globalData()) 38 38 { 39 39 } 40 40 41 DefaultGCActivityCallback::~DefaultGCActivityCallback()41 void DefaultGCActivityCallback::doWork() 42 42 { 43 43 } … … 51 51 } 52 52 53 void DefaultGCActivityCallback::synchronize()54 {55 }56 57 53 void DefaultGCActivityCallback::cancel() 58 54 { -
trunk/Source/JavaScriptCore/runtime/GCActivityCallback.h
r117015 r120742 30 30 #define GCActivityCallback_h 31 31 32 #include "HeapTimer.h" 32 33 #include <wtf/OwnPtr.h> 33 34 #include <wtf/PassOwnPtr.h> … … 41 42 class Heap; 42 43 43 class GCActivityCallback {44 class GCActivityCallback : public HeapTimer { 44 45 public: 45 virtual ~GCActivityCallback() { }46 46 virtual void didAllocate(size_t) { } 47 47 virtual void willCollect() { } 48 virtual void synchronize() { }49 48 virtual void cancel() { } 50 49 bool isEnabled() const { return m_enabled; } … … 52 51 53 52 protected: 54 GCActivityCallback() 55 : m_enabled(true) 53 #if USE(CF) 54 GCActivityCallback(JSGlobalData* globalData, CFRunLoopRef runLoop) 55 : HeapTimer(globalData, runLoop) 56 , m_enabled(true) 56 57 { 57 58 } 59 # else 60 GCActivityCallback(JSGlobalData* globalData) 61 : HeapTimer(globalData) 62 , m_enabled(true) 63 { 64 } 65 #endif 58 66 59 67 bool m_enabled; 60 68 }; 61 62 struct DefaultGCActivityCallbackPlatformData;63 69 64 70 class DefaultGCActivityCallback : public GCActivityCallback { … … 67 73 68 74 DefaultGCActivityCallback(Heap*); 69 virtual ~DefaultGCActivityCallback();70 75 71 76 virtual void didAllocate(size_t); 72 77 virtual void willCollect(); 73 virtual void synchronize();74 78 virtual void cancel(); 79 80 virtual void doWork(); 75 81 76 82 #if USE(CF) 77 83 protected: 78 84 DefaultGCActivityCallback(Heap*, CFRunLoopRef); 79 void commonConstructor(Heap*, CFRunLoopRef); 85 86 void cancelTimer(); 87 void scheduleTimer(double); 88 89 private: 90 double m_delay; 80 91 #endif 81 82 private:83 OwnPtr<DefaultGCActivityCallbackPlatformData> d;84 92 }; 85 93 -
trunk/Source/JavaScriptCore/runtime/GCActivityCallbackBlackBerry.cpp
r120502 r120742 25 25 namespace JSC { 26 26 27 struct DefaultGCActivityCallbackPlatformData {28 explicit DefaultGCActivityCallbackPlatformData(Heap* heap) : m_heap(heap) { }29 Heap* m_heap;30 };31 32 27 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap) 33 : d(adoptPtr(new DefaultGCActivityCallbackPlatformData(heap)))28 : GCActivityCallback(heap->globalData()) 34 29 { 35 30 } 36 31 37 DefaultGCActivityCallback:: ~DefaultGCActivityCallback()32 DefaultGCActivityCallback::doWork() 38 33 { 39 34 } … … 47 42 return; 48 43 49 if ( d->m_heap->isBusy() || !d->m_heap->isSafeToCollect())44 if (m_globalData->heap.isBusy() || !m_globalData->heap.isSafeToCollect()) 50 45 return; 51 46 52 d->m_heap->collect(Heap::DoNotSweep);47 m_globalData->heap.collect(Heap::DoNotSweep); 53 48 } 54 49 55 50 void DefaultGCActivityCallback::willCollect() 56 {57 }58 59 void DefaultGCActivityCallback::synchronize()60 51 { 61 52 } -
trunk/Source/JavaScriptCore/runtime/GCActivityCallbackCF.cpp
r117015 r120742 45 45 namespace JSC { 46 46 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 56 47 const double gcTimeSlicePerMB = 0.01; // Percentage of CPU time we will spend to reclaim 1 MB 57 48 const double maxGCTimeSlice = 0.05; // The maximum amount of CPU time we want to use for opportunistic timer-triggered collections. 58 49 const double timerSlop = 2.0; // Fudge factor to avoid performance cost of resetting timer. 59 50 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. 60 const CFTimeInterval decade = 60 * 60 * 24 * 365 * 10;61 51 const CFTimeInterval hour = 60 * 60; 62 52 63 void DefaultGCActivityCallbackPlatformData::timerDidFire(CFRunLoopTimerRef, void *info) 53 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap) 54 : GCActivityCallback(heap->globalData(), CFRunLoopGetCurrent()) 55 , m_delay(s_decade) 64 56 { 65 Heap* heap = static_cast<Heap*>(info); 66 if (!heap->activityCallback()->isEnabled()) 57 } 58 59 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap, CFRunLoopRef runLoop) 60 : GCActivityCallback(heap->globalData(), runLoop) 61 , m_delay(s_decade) 62 { 63 } 64 65 void DefaultGCActivityCallback::doWork() 66 { 67 Heap* heap = &m_globalData->heap; 68 if (!isEnabled()) 67 69 return; 68 69 APIEntryShim shim( heap->globalData());70 71 APIEntryShim shim(m_globalData); 70 72 #if !PLATFORM(IOS) 71 73 double startTime = WTF::monotonicallyIncreasingTime(); … … 78 80 heap->collectAllGarbage(); 79 81 } 80 81 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)82 83 void DefaultGCActivityCallback::scheduleTimer(double newDelay) 82 84 { 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); 84 90 } 85 91 86 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap, CFRunLoopRef runLoop)92 void DefaultGCActivityCallback::cancelTimer() 87 93 { 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); 122 96 } 123 97 … … 128 102 if (!bytes) 129 103 bytes = 1; 130 Heap* heap = static_cast<Heap*>( d->context.info);104 Heap* heap = static_cast<Heap*>(&m_globalData->heap); 131 105 double gcTimeSlice = std::min((static_cast<double>(bytes) / MB) * gcTimeSlicePerMB, maxGCTimeSlice); 132 106 double newDelay = heap->lastGCLength() / gcTimeSlice; 133 scheduleTimer( d.get(),newDelay);107 scheduleTimer(newDelay); 134 108 } 135 109 136 110 void DefaultGCActivityCallback::willCollect() 137 111 { 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(); 148 113 } 149 114 150 115 void DefaultGCActivityCallback::cancel() 151 116 { 152 cancelTimer( d.get());117 cancelTimer(); 153 118 } 154 119
Note:
See TracChangeset
for help on using the changeset viewer.