Changeset 81262 in webkit


Ignore:
Timestamp:
Mar 16, 2011 11:35:49 AM (13 years ago)
Author:
ggaren@apple.com
Message:

2011-03-16 Geoffrey Garen <ggaren@apple.com>

Reviewed by Oliver Hunt.

Some conservative root gathering cleanup
https://bugs.webkit.org/show_bug.cgi?id=56447


SunSpider says 0.5% - 1.8% faster.

  • interpreter/RegisterFile.cpp: (JSC::RegisterFile::gatherConservativeRoots):
  • interpreter/RegisterFile.h: New helper function for doing the conservative gathering of the register file. It's still conservative, since the register file may contain uninitialized values, but it's moving-safe, because it only visits values tagged as pointers, so there's no risk of mistaking an integer for a pointer and accidentally changing it.
  • runtime/ConservativeSet.cpp: (JSC::ConservativeRoots::add):
  • runtime/ConservativeSet.h: Added a single-value add function, used above.
  • runtime/Heap.cpp: (JSC::Heap::markRoots): Separated machine stack conservative roots from register file conservative roots because machine stack roots must be pinned, but register file roots need not be pinned.


Adopted new interface for passing the current stack extent to the machine
stack root gathering routine. This allows us to exclude marking-related
data structures on the stack, and thus avoid double-marking the set of
machine roots.

  • runtime/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots):
  • runtime/MachineStackMarker.h: Added new interface, described above.
  • runtime/MarkedBlock.h: (JSC::MarkedBlock::firstAtom):
  • wtf/StdLibExtras.h: (WTF::roundUpToMultipleOf): Moved roundUpToMultipleOf so it could be used by MachineStacks.
Location:
trunk/Source/JavaScriptCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r81261 r81262  
     12011-03-16  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Some conservative root gathering cleanup
     6        https://bugs.webkit.org/show_bug.cgi?id=56447
     7       
     8        SunSpider says 0.5% - 1.8% faster.
     9
     10        * interpreter/RegisterFile.cpp:
     11        (JSC::RegisterFile::gatherConservativeRoots):
     12        * interpreter/RegisterFile.h: New helper function for doing the
     13        conservative gathering of the register file. It's still conservative,
     14        since the register file may contain uninitialized values, but it's
     15        moving-safe, because it only visits values tagged as pointers, so there's
     16        no risk of mistaking an integer for a pointer and accidentally changing it.
     17
     18        * runtime/ConservativeSet.cpp:
     19        (JSC::ConservativeRoots::add):
     20        * runtime/ConservativeSet.h: Added a single-value add function, used above.
     21
     22        * runtime/Heap.cpp:
     23        (JSC::Heap::markRoots): Separated machine stack conservative roots from
     24        register file conservative roots because machine stack roots must be
     25        pinned, but register file roots need not be pinned.
     26       
     27        Adopted new interface for passing the current stack extent to the machine
     28        stack root gathering routine. This allows us to exclude marking-related
     29        data structures on the stack, and thus avoid double-marking the set of
     30        machine roots.
     31
     32        * runtime/MachineStackMarker.cpp:
     33        (JSC::MachineThreads::gatherFromCurrentThread):
     34        (JSC::MachineThreads::gatherConservativeRoots):
     35        * runtime/MachineStackMarker.h: Added new interface, described above.
     36
     37        * runtime/MarkedBlock.h:
     38        (JSC::MarkedBlock::firstAtom):
     39        * wtf/StdLibExtras.h:
     40        (WTF::roundUpToMultipleOf): Moved roundUpToMultipleOf so it could be used
     41        by MachineStacks.
     42
    1432011-03-16  Geoffrey Garen  <ggaren@apple.com>
    244
  • trunk/Source/JavaScriptCore/interpreter/RegisterFile.cpp

    r79601 r81262  
    3030#include "RegisterFile.h"
    3131
     32#include "ConservativeSet.h"
    3233#include "Interpreter.h"
    3334#include "JSGlobalData.h"
     
    5051    addToCommittedByteCount(-(reinterpret_cast<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(base)));
    5152    m_reservation.deallocate();
     53}
     54
     55void RegisterFile::gatherConservativeRoots(ConservativeRoots& conservativeRoots)
     56{
     57    for (Register* it = start(); it != end(); ++it) {
     58        JSValue v = it->jsValue();
     59        if (!v.isCell())
     60            continue;
     61        conservativeRoots.add(v.asCell());
     62    }
    5263}
    5364
  • trunk/Source/JavaScriptCore/interpreter/RegisterFile.h

    r80969 r81262  
    114114        RegisterFile(JSGlobalData&, size_t capacity = defaultCapacity, size_t maxGlobals = defaultMaxGlobals);
    115115        ~RegisterFile();
     116       
     117        void gatherConservativeRoots(ConservativeRoots&);
    116118
    117119        Register* start() const { return m_start; }
  • trunk/Source/JavaScriptCore/runtime/ConservativeSet.cpp

    r80995 r81262  
    2727#include "ConservativeSet.h"
    2828
    29 #include "Heap.h"
    30 
    3129namespace JSC {
    3230
     
    5452    ASSERT(isPointerAligned(end));
    5553
    56     for (char** it = static_cast<char**>(begin); it != static_cast<char**>(end); ++it) {
    57         if (!m_heap->contains(*it))
    58             continue;
    59 
    60         if (m_size == m_capacity)
    61             grow();
    62 
    63         m_roots[m_size++] = reinterpret_cast<JSCell*>(*it);
    64     }
     54    for (char** it = static_cast<char**>(begin); it != static_cast<char**>(end); ++it)
     55        add(*it);
    6556}
    6657
  • trunk/Source/JavaScriptCore/runtime/ConservativeSet.h

    r80995 r81262  
    2727#define ConservativeRoots_h
    2828
     29#include "Heap.h"
    2930#include <wtf/OSAllocator.h>
    3031#include <wtf/Vector.h>
     
    4243    ~ConservativeRoots();
    4344
     45    void add(void*);
    4446    void add(void* begin, void* end);
    4547   
     
    7476}
    7577
     78inline void ConservativeRoots::add(void* p)
     79{
     80    if (!m_heap->contains(p))
     81        return;
     82
     83    if (m_size == m_capacity)
     84        grow();
     85
     86    m_roots[m_size++] = reinterpret_cast<JSCell*>(p);
     87}
     88
    7689inline size_t ConservativeRoots::size()
    7790{
  • trunk/Source/JavaScriptCore/runtime/Heap.cpp

    r81196 r81262  
    200200#endif
    201201
     202    void* dummy;
     203
    202204    ASSERT(m_operationInProgress == NoOperation);
    203205    if (m_operationInProgress != NoOperation)
     
    206208    m_operationInProgress = Collection;
    207209
    208     // We gather the conservative set before clearing mark bits, because
     210    MarkStack& markStack = m_markStack;
     211    HeapRootMarker heapRootMarker(markStack);
     212   
     213    // We gather conservative roots before clearing mark bits because
    209214    // conservative gathering uses the mark bits from our last mark pass to
    210215    // determine whether a reference is valid.
    211     ConservativeRoots conservativeRoots(this);
    212     m_machineThreads.gatherConservativeRoots(conservativeRoots);
    213     conservativeRoots.add(registerFile().start(), registerFile().end());
     216    ConservativeRoots machineThreadRoots(this);
     217    m_machineThreads.gatherConservativeRoots(machineThreadRoots, &dummy);
     218
     219    ConservativeRoots registerFileRoots(this);
     220    registerFile().gatherConservativeRoots(registerFileRoots);
    214221
    215222    m_markedSpace.clearMarks();
    216223
    217     MarkStack& markStack = m_markStack;
    218     HeapRootMarker heapRootMarker(markStack);
    219 
    220     markStack.append(conservativeRoots);
     224    markStack.append(machineThreadRoots);
     225    markStack.drain();
     226
     227    markStack.append(registerFileRoots);
    221228    markStack.drain();
    222229
  • trunk/Source/JavaScriptCore/runtime/MachineStackMarker.cpp

    r80995 r81262  
    2929#include <setjmp.h>
    3030#include <stdlib.h>
     31#include <wtf/StdLibExtras.h>
    3132
    3233#if USE(PTHREAD_BASED_QT) && !defined(WTF_USE_PTHREADS)
     
    8485
    8586#endif
     87
     88using namespace WTF;
    8689
    8790namespace JSC {
     
    245248#endif
    246249
    247 void NEVER_INLINE MachineThreads::gatherFromCurrentThreadInternal(ConservativeRoots& conservativeRoots)
    248 {
    249     void* begin = m_heap->globalData()->stack().current();
    250     void* end = m_heap->globalData()->stack().origin();
    251     swapIfBackwards(begin, end);
    252     conservativeRoots.add(begin, end);
    253 }
    254 
    255250#if COMPILER(GCC)
    256251#define REGISTER_BUFFER_ALIGNMENT __attribute__ ((aligned (sizeof(void*))))
     
    259254#endif
    260255
    261 void MachineThreads::gatherFromCurrentThread(ConservativeRoots& conservativeRoots)
     256void MachineThreads::gatherFromCurrentThread(ConservativeRoots& conservativeRoots, void* stackCurrent)
    262257{
    263258    // setjmp forces volatile registers onto the stack
     
    272267#endif
    273268
    274     gatherFromCurrentThreadInternal(conservativeRoots);
     269    void* registersBegin = &registers;
     270    void* registersEnd = reinterpret_cast<void*>(roundUpToMultipleOf<sizeof(void*)>(reinterpret_cast<uintptr_t>(&registers + 1)));
     271    swapIfBackwards(registersBegin, registersEnd);
     272    conservativeRoots.add(registersBegin, registersEnd);
     273
     274    void* stackBegin = stackCurrent;
     275    void* stackEnd = m_heap->globalData()->stack().origin();
     276    swapIfBackwards(stackBegin, stackEnd);
     277    conservativeRoots.add(stackBegin, stackEnd);
    275278}
    276279
     
    457460#endif
    458461
    459 void MachineThreads::gatherConservativeRoots(ConservativeRoots& conservativeRoots)
    460 {
    461     gatherFromCurrentThread(conservativeRoots);
     462void MachineThreads::gatherConservativeRoots(ConservativeRoots& conservativeRoots, void* stackCurrent)
     463{
     464    gatherFromCurrentThread(conservativeRoots, stackCurrent);
    462465
    463466#if ENABLE(JSC_MULTIPLE_THREADS)
  • trunk/Source/JavaScriptCore/runtime/MachineStackMarker.h

    r80995 r81262  
    4141        ~MachineThreads();
    4242
    43         void gatherConservativeRoots(ConservativeRoots&);
     43        void gatherConservativeRoots(ConservativeRoots&, void* stackCurrent);
    4444
    4545#if ENABLE(JSC_MULTIPLE_THREADS)
     
    4949
    5050    private:
    51         void gatherFromCurrentThread(ConservativeRoots&);
    52         void gatherFromCurrentThreadInternal(ConservativeRoots&);
     51        void gatherFromCurrentThread(ConservativeRoots&, void* stackCurrent);
    5352
    5453#if ENABLE(JSC_MULTIPLE_THREADS)
  • trunk/Source/JavaScriptCore/runtime/MarkStack.cpp

    r81261 r81262  
    2727#include "MarkStack.h"
    2828
     29#include "ConservativeSet.h"
    2930#include "Heap.h"
    3031#include "JSArray.h"
    3132#include "JSCell.h"
     33#include "JSObject.h"
     34#include "ScopeChain.h"
    3235#include "Structure.h"
    3336
     
    4144    m_values.shrinkAllocation(s_pageSize);
    4245    m_markSets.shrinkAllocation(s_pageSize);
     46}
     47
     48void MarkStack::append(ConservativeRoots& conservativeRoots)
     49{
     50    JSCell** roots = conservativeRoots.roots();
     51    size_t size = conservativeRoots.size();
     52    for (size_t i = 0; i < size; ++i)
     53        internalAppend(roots[i]);
    4354}
    4455
  • trunk/Source/JavaScriptCore/runtime/MarkStack.h

    r81261 r81262  
    2727#define MarkStack_h
    2828
    29 #include "ConservativeSet.h"
    3029#include "JSValue.h"
    3130#include "Register.h"
     
    3736namespace JSC {
    3837
     38    class ConservativeRoots;
    3939    class JSGlobalData;
    4040    class Register;
     
    8080        }
    8181       
    82         void append(ConservativeRoots& conservativeRoots)
    83         {
    84             JSCell** roots = conservativeRoots.roots();
    85             size_t size = conservativeRoots.size();
    86             for (size_t i = 0; i < size; ++i)
    87                 internalAppend(roots[i]);
    88         }
     82        void append(ConservativeRoots&);
    8983
    9084        void drain();
  • trunk/Source/JavaScriptCore/runtime/MarkedBlock.h

    r80052 r81262  
    2525#include <wtf/Bitmap.h>
    2626#include <wtf/PageAllocationAligned.h>
     27#include <wtf/StdLibExtras.h>
    2728
    2829namespace JSC {
     
    3536
    3637    static const size_t KB = 1024;
    37 
    38     // Efficient implementation that takes advantage of powers of two.
    39     template<size_t divisor> inline size_t roundUpToMultipleOf(size_t x)
    40     {
    41         COMPILE_ASSERT(divisor && !(divisor & (divisor - 1)), divisor_is_a_power_of_two);
    42 
    43         size_t remainderMask = divisor - 1;
    44         return (x + remainderMask) & ~remainderMask;
    45     }
    4638
    4739    class MarkedBlock {
     
    110102    inline size_t MarkedBlock::firstAtom()
    111103    {
    112         return roundUpToMultipleOf<atomSize>(sizeof(MarkedBlock)) / atomSize;
     104        return WTF::roundUpToMultipleOf<atomSize>(sizeof(MarkedBlock)) / atomSize;
    113105    }
    114106
  • trunk/Source/JavaScriptCore/wtf/StdLibExtras.h

    r72289 r81262  
    115115#define WTF_ARRAY_LENGTH(array) sizeof(::WTF::ArrayLengthHelperFunction(array))
    116116
     117// Efficient implementation that takes advantage of powers of two.
     118template<size_t divisor> inline size_t roundUpToMultipleOf(size_t x)
     119{
     120    COMPILE_ASSERT(divisor && !(divisor & (divisor - 1)), divisor_is_a_power_of_two);
     121
     122    size_t remainderMask = divisor - 1;
     123    return (x + remainderMask) & ~remainderMask;
     124}
     125
    117126} // namespace WTF
    118127
Note: See TracChangeset for help on using the changeset viewer.