2  * Copyright (C) 2009, 2011 Apple Inc. All rights reserved. 
   4  * Redistribution and use in source and binary forms, with or without 
   5  * modification, are permitted provided that the following conditions 
   7  * 1. Redistributions of source code must retain the above copyright 
   8  *    notice, this list of conditions and the following disclaimer. 
   9  * 2. Redistributions in binary form must reproduce the above copyright 
  10  *    notice, this list of conditions and the following disclaimer in the 
  11  *    documentation and/or other materials provided with the distribution. 
  13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 
  14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
  15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR 
  17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
  19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
  20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
  21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
  22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
  23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
  26 #ifndef GCThreadSharedData_h 
  27 #define GCThreadSharedData_h 
  29 #include "ListableHandler.h" 
  30 #include "MarkStack.h" 
  31 #include "MarkedBlock.h" 
  32 #include "UnconditionalFinalizer.h" 
  33 #include "WeakReferenceHarvester.h" 
  34 #include <condition_variable> 
  35 #include <wtf/HashSet.h> 
  36 #include <wtf/TCSpinLock.h> 
  37 #include <wtf/Vector.h> 
  53 class GCThreadSharedData 
{ 
  54     WTF_MAKE_FAST_ALLOCATED
; 
  56     GCThreadSharedData(VM
*); 
  57     ~GCThreadSharedData(); 
  61     void didStartMarking(); 
  62     void didFinishMarking(); 
  63     void didStartCopying(); 
  64     void didFinishCopying(); 
  66 #if ENABLE(PARALLEL_GC) 
  68     size_t childVisitCount(); 
  69     size_t childBytesVisited(); 
  70     size_t childBytesCopied(); 
  71     size_t childDupStrings(); 
  75     friend class GCThread
; 
  76     friend class SlotVisitor
; 
  77     friend class CopyVisitor
; 
  79     void getNextBlocksToCopy(size_t&, size_t&); 
  80     void startNextPhase(GCPhase
); 
  81     void endCurrentPhase(); 
  84     CopiedSpace
* m_copiedSpace
; 
  86     bool m_shouldHashCons
; 
  88     Vector
<GCThread
*> m_gcThreads
; 
  90     std::mutex m_markingMutex
; 
  91     std::condition_variable m_markingConditionVariable
; 
  92     MarkStackArray m_sharedMarkStack
; 
  93     unsigned m_numberOfActiveParallelMarkers
; 
  94     bool m_parallelMarkersShouldExit
; 
  96     std::mutex m_opaqueRootsMutex
; 
  97     HashSet
<void*> m_opaqueRoots
; 
 100     Vector
<CopiedBlock
*> m_blocksToCopy
; 
 102     static const size_t s_blockFragmentLength 
= 32; 
 104     std::mutex m_phaseMutex
; 
 105     std::condition_variable m_phaseConditionVariable
; 
 106     std::condition_variable m_activityConditionVariable
; 
 107     unsigned m_numberOfActiveGCThreads
; 
 108     bool m_gcThreadsShouldWait
; 
 109     GCPhase m_currentPhase
; 
 111     ListableHandler
<WeakReferenceHarvester
>::List m_weakReferenceHarvesters
; 
 112     ListableHandler
<UnconditionalFinalizer
>::List m_unconditionalFinalizers
; 
 115 inline void GCThreadSharedData::getNextBlocksToCopy(size_t& start
, size_t& end
) 
 117     SpinLockHolder 
locker(&m_copyLock
); 
 119     end 
= std::min(m_blocksToCopy
.size(), m_copyIndex 
+ s_blockFragmentLength
);