Changeset 161036 in webkit


Ignore:
Timestamp:
Dec 23, 2013, 4:25:14 PM (11 years ago)
Author:
mark.lam@apple.com
Message:

CStack: Fix JSStack::grow(), shrink(), growSlowCase(), and setStackLimit().
https://bugs.webkit.org/show_bug.cgi?id=126188.

Not yet reviewed.

These functions were inappropriately mixing "end" and "top" pointer idioms.
Specifically:

  1. growSlowCase() was comparing a newEnd pointer against m_commitTop, and using this to compute the size that the stack needs to grow.
  2. shrink() was wrongly computing excess capacity by subtracting baseOfStack() (which is at high memory) from m_commitTop (which points to lower memory). Also, baseOfStack() is an "end" pointer while m_commitTop is a "top" pointer. This is a mismatch.

To fix this and simplify the code a bit, I changed all of these functions
to take a newTopOfStack pointer instead of a newEnd pointer, and adjusted
their callers where needed to pass the appropropriate pointer values.

  • interpreter/JSStack.cpp:

(JSC::JSStack::growSlowCase):

  • interpreter/JSStack.h:
  • interpreter/JSStackInlines.h:

(JSC::JSStack::popFrame):
(JSC::JSStack::shrink):
(JSC::JSStack::grow):
(JSC::JSStack::setStackLimit):

Location:
branches/jsCStack/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/jsCStack/Source/JavaScriptCore/ChangeLog

    r161030 r161036  
     12013-12-23  Mark Lam  <mark.lam@apple.com>
     2
     3        CStack: Fix JSStack::grow(), shrink(), growSlowCase(), and setStackLimit().
     4        https://bugs.webkit.org/show_bug.cgi?id=126188.
     5
     6        Not yet reviewed.
     7
     8        These functions were inappropriately mixing "end" and "top" pointer idioms.
     9        Specifically:
     10        1. growSlowCase() was comparing a newEnd pointer against m_commitTop, and
     11           using this to compute the size that the stack needs to grow.
     12        2. shrink() was wrongly computing excess capacity by subtracting
     13           baseOfStack() (which is at high memory) from m_commitTop (which points
     14           to lower memory). Also, baseOfStack() is an "end" pointer while
     15           m_commitTop is a "top" pointer. This is a mismatch.
     16
     17        To fix this and simplify the code a bit, I changed all of these functions
     18        to take a newTopOfStack pointer instead of a newEnd pointer, and adjusted
     19        their callers where needed to pass the appropropriate pointer values.
     20
     21        * interpreter/JSStack.cpp:
     22        (JSC::JSStack::growSlowCase):
     23        * interpreter/JSStack.h:
     24        * interpreter/JSStackInlines.h:
     25        (JSC::JSStack::popFrame):
     26        (JSC::JSStack::shrink):
     27        (JSC::JSStack::grow):
     28        (JSC::JSStack::setStackLimit):
     29
    1302013-12-23  Mark Lam  <mark.lam@apple.com>
    231
  • branches/jsCStack/Source/JavaScriptCore/interpreter/JSStack.cpp

    r161030 r161036  
    7878}
    7979
    80 bool JSStack::growSlowCase(Register* newEnd)
     80bool JSStack::growSlowCase(Register* newTopOfStack)
    8181{
    8282    // If we have already committed enough memory to satisfy this request,
    8383    // just update the end pointer and return.
    84     if (newEnd >= m_commitTop) {
    85         setStackLimit(newEnd);
     84    if (newTopOfStack >= m_commitTop) {
     85        setStackLimit(newTopOfStack);
    8686        return true;
    8787    }
     
    9090    // have it is still within our budget. If not, we'll fail to grow and
    9191    // return false.
    92     long delta = roundUpAllocationSize(reinterpret_cast<char*>(m_commitTop) - reinterpret_cast<char*>(newEnd), commitSize);
     92    long delta = roundUpAllocationSize(reinterpret_cast<char*>(m_commitTop) - reinterpret_cast<char*>(newTopOfStack), commitSize);
    9393    if (reinterpret_cast<char*>(m_commitTop) - delta <= reinterpret_cast<char*>(m_useableTop))
    9494        return false;
     
    9999    addToCommittedByteCount(delta);
    100100    m_commitTop = reinterpret_cast_ptr<Register*>(reinterpret_cast<char*>(m_commitTop) - delta);
    101     setStackLimit(newEnd);
     101    setStackLimit(newTopOfStack);
    102102    return true;
    103103}
  • branches/jsCStack/Source/JavaScriptCore/interpreter/JSStack.h

    r161030 r161036  
    161161#endif
    162162
    163         bool grow(Register* topOfStack);
    164         bool growSlowCase(Register*);
    165         void shrink(Register*);
     163        bool grow(Register* newTopOfStack);
     164        bool growSlowCase(Register* newTopOfStack);
     165        void shrink(Register* newTopOfStack);
    166166        void releaseExcessCapacity();
    167167        void addToCommittedByteCount(long);
    168168
    169         void setStackLimit(Register* newEnd);
     169        void setStackLimit(Register* newTopOfStack);
    170170#endif // ENABLE(LLINT_C_LOOP)
    171171
  • branches/jsCStack/Source/JavaScriptCore/interpreter/JSStackInlines.h

    r161030 r161036  
    167167    // are no more frames on the stack.
    168168    if (!callerFrame)
    169         shrink(baseOfStack());
     169        shrink(highAddress());
    170170
    171171    installTrapsAfterFrame(callerFrame);
    172172}
    173173
    174 inline void JSStack::shrink(Register* newEnd)
    175 {
     174inline void JSStack::shrink(Register* newTopOfStack)
     175{
     176    Register* newEnd = newTopOfStack - 1;
    176177    if (newEnd >= m_end)
    177178        return;
    178     setStackLimit(newEnd);
    179     if (m_end == baseOfStack() && (m_commitTop - baseOfStack()) >= maxExcessCapacity)
     179    setStackLimit(newTopOfStack);
     180    if (m_end == baseOfStack() && (highAddress() - m_commitTop) >= maxExcessCapacity)
    180181        releaseExcessCapacity();
    181182}
    182183
    183 inline bool JSStack::grow(Register* topOfStack)
    184 {
    185     Register* newEnd = topOfStack - 1;
     184inline bool JSStack::grow(Register* newTopOfStack)
     185{
     186    Register* newEnd = newTopOfStack - 1;
    186187    if (newEnd >= m_end)
    187188        return true;
    188     return growSlowCase(newEnd);
    189 }
    190 
    191 inline void JSStack::setStackLimit(Register* newEnd)
    192 {
     189    return growSlowCase(newTopOfStack);
     190}
     191
     192inline void JSStack::setStackLimit(Register* newTopOfStack)
     193{
     194    Register* newEnd = newTopOfStack - 1;
    193195    m_end = newEnd;
    194196#if ENABLE(LLINT_C_LOOP)
    195     m_vm.setJSStackLimit(newEnd + 1);
     197    m_vm.setJSStackLimit(newTopOfStack);
    196198#endif
    197199}
Note: See TracChangeset for help on using the changeset viewer.