Changeset 87230 in webkit


Ignore:
Timestamp:
May 24, 2011, 4:46:35 PM (14 years ago)
Author:
ggaren@apple.com
Message:

2011-05-24 Geoffrey Garen <ggaren@apple.com>

Reviewed by Oliver Hunt.

Split HeapRootVisitor into its own class
https://bugs.webkit.org/show_bug.cgi?id=61399

  • GNUmakefile.list.am:
  • JavaScriptCore.gypi:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • heap/HandleHeap.cpp:
  • heap/HandleStack.cpp:
  • heap/Heap.cpp:
  • heap/HeapRootVisitor.h: Copied from Source/JavaScriptCore/heap/MarkStack.h.
  • heap/MarkStack.h:
  • runtime/ArgList.cpp:
  • runtime/SmallStrings.cpp:
Location:
trunk/Source/JavaScriptCore
Files:
11 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r87213 r87230  
     12011-05-24  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Split HeapRootVisitor into its own class
     6        https://bugs.webkit.org/show_bug.cgi?id=61399
     7
     8        * GNUmakefile.list.am:
     9        * JavaScriptCore.gypi:
     10        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
     11        * JavaScriptCore.xcodeproj/project.pbxproj:
     12        * heap/HandleHeap.cpp:
     13        * heap/HandleStack.cpp:
     14        * heap/Heap.cpp:
     15        * heap/HeapRootVisitor.h: Copied from Source/JavaScriptCore/heap/MarkStack.h.
     16        * heap/MarkStack.h:
     17        * runtime/ArgList.cpp:
     18        * runtime/SmallStrings.cpp:
     19
    1202011-05-24  Jay Civelli  <jcivelli@chromium.org>
    221
  • trunk/Source/JavaScriptCore/GNUmakefile.list.am

    r87198 r87230  
    113113        Source/JavaScriptCore/heap/MarkStack.cpp \
    114114        Source/JavaScriptCore/heap/MarkStack.h \
     115        Source/JavaScriptCore/heap/HeapRootVisitor.h \
    115116        Source/JavaScriptCore/heap/MarkedBlock.cpp \
    116117        Source/JavaScriptCore/heap/MarkedBlock.h \
  • trunk/Source/JavaScriptCore/JavaScriptCore.gypi

    r87198 r87230  
    320320            'heap/MarkStack.cpp',
    321321            'heap/MarkStack.h',
     322            'heap/HeapRootVisitor.h',
    322323            'heap/MarkedBlock.cpp',
    323324            'heap/MarkedBlock.h',
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj

    r87198 r87230  
    19151915                            </File>
    19161916                            <File
     1917                                    RelativePath="..\..\heap\HeapRootVisitor.h"
     1918                                    >
     1919                            </File>
     1920                            <File
    19171921                                    RelativePath="..\..\heap\Heap.cpp"
    19181922                                    >
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r87199 r87230  
    165165                1482B74E0A43032800517CFC /* JSStringRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1482B74C0A43032800517CFC /* JSStringRef.cpp */; };
    166166                1482B7E40A43076000517CFC /* JSObjectRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1482B7E20A43076000517CFC /* JSObjectRef.cpp */; };
     167                1486300A138C61F800B42E16 /* HeapRootVisitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 14863009138C61F800B42E16 /* HeapRootVisitor.h */; };
    167168                148CD1D8108CF902008163C6 /* JSContextRefPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 148CD1D7108CF902008163C6 /* JSContextRefPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
    168169                148F21AA107EC53A0042EC2C /* BytecodeGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 969A07200ED1CE3300F1F681 /* BytecodeGenerator.cpp */; };
     
    784785                1482B7E20A43076000517CFC /* JSObjectRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSObjectRef.cpp; sourceTree = "<group>"; };
    785786                1483B589099BC1950016E4F0 /* JSImmediate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSImmediate.h; sourceTree = "<group>"; };
     787                14863009138C61F800B42E16 /* HeapRootVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HeapRootVisitor.h; path = ../../../webkit/Source/JavaScriptCore/heap/HeapRootVisitor.h; sourceTree = SOURCE_ROOT; };
    786788                148A1626095D16BB00666D0D /* ListRefPtr.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ListRefPtr.h; sourceTree = "<group>"; };
    787789                148A1ECD0D10C23B0069A47C /* RefPtrHashMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefPtrHashMap.h; sourceTree = "<group>"; };
     
    14811483                                142E312E134FF0A600AFADB5 /* HandleStack.cpp */,
    14821484                                142E312F134FF0A600AFADB5 /* HandleStack.h */,
     1485                                146FA5A81378F6B0003627A3 /* HandleTypes.h */,
    14831486                                14FB986B135225410085A5DB /* Heap.cpp */,
    14841487                                14FB986C135225410085A5DB /* Heap.h */,
     1488                                14863009138C61F800B42E16 /* HeapRootVisitor.h */,
    14851489                                142E3130134FF0A600AFADB5 /* Local.h */,
    14861490                                142E3131134FF0A600AFADB5 /* LocalScope.h */,
     
    14951499                                142E3132134FF0A600AFADB5 /* Strong.h */,
    14961500                                142E3133134FF0A600AFADB5 /* Weak.h */,
    1497                                 146FA5A81378F6B0003627A3 /* HandleTypes.h */,
    14981501                        );
    14991502                        path = heap;
     
    25372540                                7934BB7F1361979400CB99A1 /* ParallelJobsOpenMP.h in Headers */,
    25382541                                651DCA04136A6FEF00F74194 /* PassTraits.h in Headers */,
     2542                                1486300A138C61F800B42E16 /* HeapRootVisitor.h in Headers */,
    25392543                        );
    25402544                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/JavaScriptCore/heap/HandleHeap.cpp

    r84660 r87230  
    2727#include "HandleHeap.h"
    2828
     29#include "HeapRootVisitor.h"
    2930#include "JSObject.h"
    3031
  • trunk/Source/JavaScriptCore/heap/HandleStack.cpp

    r84660 r87230  
    2525
    2626#include "config.h"
    27 
    2827#include "HandleStack.h"
    2928
    30 #include "MarkStack.h"
     29#include "HeapRootVisitor.h"
    3130
    3231namespace JSC {
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r86727 r87230  
    2525#include "ConservativeRoots.h"
    2626#include "GCActivityCallback.h"
     27#include "HeapRootVisitor.h"
    2728#include "Interpreter.h"
    2829#include "JSGlobalData.h"
  • trunk/Source/JavaScriptCore/heap/HeapRootVisitor.h

    r87198 r87230  
    2424 */
    2525
    26 #ifndef MarkStack_h
    27 #define MarkStack_h
     26#ifndef HeapRootVisitor_h
     27#define HeapRootVisitor_h
    2828
    29 #include "HandleTypes.h"
    30 #include "JSValue.h"
    31 #include "Register.h"
    32 #include <wtf/HashSet.h>
    33 #include <wtf/Vector.h>
    34 #include <wtf/Noncopyable.h>
    35 #include <wtf/OSAllocator.h>
    36 #include <wtf/PageBlock.h>
     29#include "MarkStack.h"
    3730
    3831namespace JSC {
    39 
    40     class ConservativeRoots;
    41     class JSGlobalData;
    42     class MarkStack;
    43     class Register;
    44     template<typename T> class WriteBarrierBase;
    45    
    46     typedef MarkStack SlotVisitor;
    47 
    48     enum MarkSetProperties { MayContainNullValues, NoNullValues };
    49    
    50     struct MarkSet {
    51         MarkSet(JSValue* values, JSValue* end, MarkSetProperties);
    52 
    53         JSValue* m_values;
    54         JSValue* m_end;
    55         MarkSetProperties m_properties;
    56     };
    57 
    58     template<typename T> class MarkStackArray {
    59     public:
    60         MarkStackArray();
    61         ~MarkStackArray();
    62 
    63         void expand();
    64         void append(const T&);
    65 
    66         T removeLast();
    67         T& last();
    68 
    69         bool isEmpty();
    70         size_t size();
    71 
    72         void shrinkAllocation(size_t);
    73 
    74     private:
    75         size_t m_top;
    76         size_t m_allocated;
    77         size_t m_capacity;
    78         T* m_data;
    79     };
    80 
    81     class MarkStack {
    82         WTF_MAKE_NONCOPYABLE(MarkStack);
    83         friend class HeapRootVisitor; // Allowed to mark a JSValue* or JSCell** directly.
    84 
    85     public:
    86         static void* allocateStack(size_t);
    87         static void releaseStack(void*, size_t);
    88 
    89         MarkStack(void* jsArrayVPtr);
    90         ~MarkStack();
    91 
    92         void append(ConservativeRoots&);
    93 
    94         template<typename T> inline void append(WriteBarrierBase<T>*);
    95         inline void appendValues(WriteBarrierBase<Unknown>*, size_t count, MarkSetProperties = NoNullValues);
    96        
    97         bool addOpaqueRoot(void*);
    98         bool containsOpaqueRoot(void*);
    99         int opaqueRootCount();
    100 
    101         void drain();
    102         void reset();
    103 
    104     private:
    105 #if ENABLE(GC_VALIDATION)
    106         static void validateSet(JSValue*, size_t);
    107         static void validateValue(JSValue);
    108 #endif
    109 
    110         void append(JSValue*);
    111         void append(JSValue*, size_t count);
    112         void append(JSCell**);
    113 
    114         void internalAppend(JSCell*);
    115         void internalAppend(JSValue);
    116         void visitChildren(JSCell*);
    117 
    118         void* m_jsArrayVPtr;
    119         MarkStackArray<MarkSet> m_markSets;
    120         MarkStackArray<JSCell*> m_values;
    121         HashSet<void*> m_opaqueRoots; // Handle-owning data structures not visible to the garbage collector.
    122 
    123 #if !ASSERT_DISABLED
    124     public:
    125         bool m_isCheckingForDefaultMarkViolation;
    126         bool m_isDraining;
    127 #endif
    128     };
    129 
    130     inline MarkStack::MarkStack(void* jsArrayVPtr)
    131         : m_jsArrayVPtr(jsArrayVPtr)
    132 #if !ASSERT_DISABLED
    133         , m_isCheckingForDefaultMarkViolation(false)
    134         , m_isDraining(false)
    135 #endif
    136     {
    137     }
    138 
    139     inline MarkStack::~MarkStack()
    140     {
    141         ASSERT(m_markSets.isEmpty());
    142         ASSERT(m_values.isEmpty());
    143     }
    144 
    145     inline bool MarkStack::addOpaqueRoot(void* root)
    146     {
    147         return m_opaqueRoots.add(root).second;
    148     }
    149 
    150     inline bool MarkStack::containsOpaqueRoot(void* root)
    151     {
    152         return m_opaqueRoots.contains(root);
    153     }
    154 
    155     inline int MarkStack::opaqueRootCount()
    156     {
    157         return m_opaqueRoots.size();
    158     }
    159 
    160     inline MarkSet::MarkSet(JSValue* values, JSValue* end, MarkSetProperties properties)
    161             : m_values(values)
    162             , m_end(end)
    163             , m_properties(properties)
    164         {
    165             ASSERT(values);
    166         }
    167 
    168     inline void* MarkStack::allocateStack(size_t size)
    169     {
    170         return OSAllocator::reserveAndCommit(size);
    171     }
    172 
    173     inline void MarkStack::releaseStack(void* addr, size_t size)
    174     {
    175         OSAllocator::decommitAndRelease(addr, size);
    176     }
    177 
    178     template <typename T> inline MarkStackArray<T>::MarkStackArray()
    179         : m_top(0)
    180         , m_allocated(pageSize())
    181         , m_capacity(m_allocated / sizeof(T))
    182     {
    183         m_data = reinterpret_cast<T*>(MarkStack::allocateStack(m_allocated));
    184     }
    185 
    186     template <typename T> inline MarkStackArray<T>::~MarkStackArray()
    187     {
    188         MarkStack::releaseStack(m_data, m_allocated);
    189     }
    190 
    191     template <typename T> inline void MarkStackArray<T>::expand()
    192     {
    193         size_t oldAllocation = m_allocated;
    194         m_allocated *= 2;
    195         m_capacity = m_allocated / sizeof(T);
    196         void* newData = MarkStack::allocateStack(m_allocated);
    197         memcpy(newData, m_data, oldAllocation);
    198         MarkStack::releaseStack(m_data, oldAllocation);
    199         m_data = reinterpret_cast<T*>(newData);
    200     }
    201 
    202     template <typename T> inline void MarkStackArray<T>::append(const T& v)
    203     {
    204         if (m_top == m_capacity)
    205             expand();
    206         m_data[m_top++] = v;
    207     }
    208 
    209     template <typename T> inline T MarkStackArray<T>::removeLast()
    210     {
    211         ASSERT(m_top);
    212         return m_data[--m_top];
    213     }
    214    
    215     template <typename T> inline T& MarkStackArray<T>::last()
    216     {
    217         ASSERT(m_top);
    218         return m_data[m_top - 1];
    219     }
    220 
    221     template <typename T> inline bool MarkStackArray<T>::isEmpty()
    222     {
    223         return m_top == 0;
    224     }
    225 
    226     template <typename T> inline size_t MarkStackArray<T>::size()
    227     {
    228         return m_top;
    229     }
    230 
    231     template <typename T> inline void MarkStackArray<T>::shrinkAllocation(size_t size)
    232     {
    233         ASSERT(size <= m_allocated);
    234         ASSERT(isPageAligned(size));
    235         if (size == m_allocated)
    236             return;
    237 #if OS(WINDOWS) || OS(SYMBIAN) || PLATFORM(BREWMP)
    238         // We cannot release a part of a region with VirtualFree.  To get around this,
    239         // we'll release the entire region and reallocate the size that we want.
    240         MarkStack::releaseStack(m_data, m_allocated);
    241         m_data = reinterpret_cast<T*>(MarkStack::allocateStack(size));
    242 #else
    243         MarkStack::releaseStack(reinterpret_cast<char*>(m_data) + size, m_allocated - size);
    244 #endif
    245         m_allocated = size;
    246         m_capacity = m_allocated / sizeof(T);
    247     }
    248 
    249     inline void MarkStack::append(JSValue* slot, size_t count)
    250     {
    251         if (!count)
    252             return;
    253 #if ENABLE(GC_VALIDATION)
    254         validateSet(slot, count);
    255 #endif
    256         m_markSets.append(MarkSet(slot, slot + count, NoNullValues));
    257     }
    258    
    259     ALWAYS_INLINE void MarkStack::append(JSValue* value)
    260     {
    261         ASSERT(value);
    262         internalAppend(*value);
    263     }
    264 
    265     ALWAYS_INLINE void MarkStack::append(JSCell** value)
    266     {
    267         ASSERT(value);
    268         internalAppend(*value);
    269     }
    270 
    271     ALWAYS_INLINE void MarkStack::internalAppend(JSValue value)
    272     {
    273         ASSERT(value);
    274 #if ENABLE(GC_VALIDATION)
    275         validateValue(value);
    276 #endif
    277         if (value.isCell())
    278             internalAppend(value.asCell());
    279     }
    28032
    28133    // Privileged class for marking JSValues directly. It is only safe to use
     
    33284} // namespace JSC
    33385
    334 #endif
     86#endif // HeapRootVisitor_h
  • trunk/Source/JavaScriptCore/heap/MarkStack.h

    r87198 r87230  
    4444    template<typename T> class WriteBarrierBase;
    4545   
    46     typedef MarkStack SlotVisitor;
    47 
    4846    enum MarkSetProperties { MayContainNullValues, NoNullValues };
    4947   
     
    279277    }
    280278
    281     // Privileged class for marking JSValues directly. It is only safe to use
    282     // this class to mark direct heap roots that are marked during every GC pass.
    283     // All other references should be wrapped in WriteBarriers and marked through
    284     // the MarkStack.
    285     class HeapRootVisitor {
    286     private:
    287         friend class Heap;
    288         HeapRootVisitor(SlotVisitor&);
    289 
    290     public:
    291         void mark(JSValue*);
    292         void mark(JSValue*, size_t);
    293         void mark(JSString**);
    294         void mark(JSCell**);
    295        
    296         SlotVisitor& visitor();
    297 
    298     private:
    299         SlotVisitor& m_visitor;
    300     };
    301 
    302     inline HeapRootVisitor::HeapRootVisitor(SlotVisitor& visitor)
    303         : m_visitor(visitor)
    304     {
    305     }
    306 
    307     inline void HeapRootVisitor::mark(JSValue* slot)
    308     {
    309         m_visitor.append(slot);
    310     }
    311 
    312     inline void HeapRootVisitor::mark(JSValue* slot, size_t count)
    313     {
    314         m_visitor.append(slot, count);
    315     }
    316 
    317     inline void HeapRootVisitor::mark(JSString** slot)
    318     {
    319         m_visitor.append(reinterpret_cast<JSCell**>(slot));
    320     }
    321 
    322     inline void HeapRootVisitor::mark(JSCell** slot)
    323     {
    324         m_visitor.append(slot);
    325     }
    326 
    327     inline SlotVisitor& HeapRootVisitor::visitor()
    328     {
    329         return m_visitor;
    330     }
     279    typedef MarkStack SlotVisitor;
    331280
    332281} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/ArgList.cpp

    r84556 r87230  
    2222#include "ArgList.h"
    2323
     24#include "HeapRootVisitor.h"
    2425#include "JSValue.h"
    25 #include "JSCell.h"
    2626#include "JSObject.h"
    2727#include "ScopeChain.h"
  • trunk/Source/JavaScriptCore/runtime/SmallStrings.cpp

    r84556 r87230  
    2727#include "SmallStrings.h"
    2828
     29#include "HeapRootVisitor.h"
    2930#include "JSGlobalObject.h"
    3031#include "JSString.h"
Note: See TracChangeset for help on using the changeset viewer.