Changeset 252177 in webkit


Ignore:
Timestamp:
Nov 6, 2019 11:27:52 PM (4 years ago)
Author:
mark.lam@apple.com
Message:

Remove remnants of support code for an upwards growing stack.
https://bugs.webkit.org/show_bug.cgi?id=203942

Reviewed by Yusuke Suzuki.

Source/JavaScriptCore:

  • runtime/VM.cpp:

(JSC::VM::updateStackLimits):
(JSC::VM::committedStackByteCount):

  • runtime/VM.h:

(JSC::VM::isSafeToRecurse const):

  • runtime/VMEntryScope.cpp:

(JSC::VMEntryScope::VMEntryScope):

  • runtime/VMInlines.h:

(JSC::VM::ensureStackCapacityFor):

  • yarr/YarrPattern.cpp:

(JSC::Yarr::YarrPatternConstructor::isSafeToRecurse const):

Source/WTF:

We haven't supported an upwards growing stack in years, and a lot of code has
since been written specifically with only a downwards growing stack in mind (e.g.
the LLInt, the JITs). Also, all our currently supported platforms use a downward
growing stack.

We should remove the remnants of support code for an upwards growing stack. The
presence of that code is deceptive in that it conveys support for an upwards
growing stack where this hasn't been the case in years.

  • wtf/StackBounds.cpp:

(WTF::StackBounds::newThreadStackBounds):
(WTF::StackBounds::currentThreadStackBoundsInternal):
(WTF::StackBounds::stackDirection): Deleted.
(WTF::testStackDirection2): Deleted.
(WTF::testStackDirection): Deleted.

  • wtf/StackBounds.h:

(WTF::StackBounds::size const):
(WTF::StackBounds::contains const):
(WTF::StackBounds::recursionLimit const):
(WTF::StackBounds::StackBounds):
(WTF::StackBounds::isGrowingDownwards const):
(WTF::StackBounds::checkConsistency const):
(WTF::StackBounds::isGrowingDownward const): Deleted.

  • wtf/StackStats.cpp:

(WTF::StackStats::CheckPoint::CheckPoint):
(WTF::StackStats::CheckPoint::~CheckPoint):
(WTF::StackStats::probe):
(WTF::StackStats::LayoutCheckPoint::LayoutCheckPoint):

Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r252162 r252177  
     12019-11-06  Mark Lam  <mark.lam@apple.com>
     2
     3        Remove remnants of support code for an upwards growing stack.
     4        https://bugs.webkit.org/show_bug.cgi?id=203942
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * runtime/VM.cpp:
     9        (JSC::VM::updateStackLimits):
     10        (JSC::VM::committedStackByteCount):
     11        * runtime/VM.h:
     12        (JSC::VM::isSafeToRecurse const):
     13        * runtime/VMEntryScope.cpp:
     14        (JSC::VMEntryScope::VMEntryScope):
     15        * runtime/VMInlines.h:
     16        (JSC::VM::ensureStackCapacityFor):
     17        * yarr/YarrPattern.cpp:
     18        (JSC::Yarr::YarrPatternConstructor::isSafeToRecurse const):
     19
    1202019-11-06  Tadeu Zagallo  <tzagallo@apple.com>
    221
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r251691 r252177  
    897897
    898898    if (m_stackPointerAtVMEntry) {
    899         ASSERT(stack.isGrowingDownward());
    900899        char* startOfStack = reinterpret_cast<char*>(m_stackPointerAtVMEntry);
    901900        m_softStackLimit = stack.recursionLimit(startOfStack, Options::maxPerThreadStackUsage(), m_currentSoftReservedZoneSize);
     
    11711170    // When using the C stack, we don't know how many stack pages are actually
    11721171    // committed. So, we use the current stack usage as an estimate.
    1173     ASSERT(Thread::current().stack().isGrowingDownward());
    11741172    uint8_t* current = bitwise_cast<uint8_t*>(currentStackPointer());
    11751173    uint8_t* high = bitwise_cast<uint8_t*>(Thread::current().stack().origin());
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r251691 r252177  
    974974    bool isSafeToRecurse(void* stackLimit) const
    975975    {
    976         ASSERT(Thread::current().stack().isGrowingDownward());
    977976        void* curr = currentStackPointer();
    978977        return curr >= stackLimit;
  • trunk/Source/JavaScriptCore/runtime/VMEntryScope.cpp

    r234082 r252177  
    4343{
    4444    ASSERT(!DisallowVMReentry::isInEffectOnCurrentThread());
    45     ASSERT(Thread::current().stack().isGrowingDownward());
    4645    if (!vm.entryScope) {
    4746        vm.entryScope = this;
  • trunk/Source/JavaScriptCore/runtime/VMInlines.h

    r251584 r252177  
    3636{
    3737#if !ENABLE(C_LOOP)
    38     ASSERT(Thread::current().stack().isGrowingDownward());
    3938    return newTopOfStack >= m_softStackLimit;
    4039#else
  • trunk/Source/JavaScriptCore/yarr/YarrPattern.cpp

    r249777 r252177  
    11231123        if (!m_stackLimit)
    11241124            return true;
    1125         ASSERT(Thread::current().stack().isGrowingDownward());
    11261125        int8_t* curr = reinterpret_cast<int8_t*>(currentStackPointer());
    11271126        int8_t* limit = reinterpret_cast<int8_t*>(m_stackLimit);
  • trunk/Source/WTF/ChangeLog

    r252124 r252177  
     12019-11-06  Mark Lam  <mark.lam@apple.com>
     2
     3        Remove remnants of support code for an upwards growing stack.
     4        https://bugs.webkit.org/show_bug.cgi?id=203942
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        We haven't supported an upwards growing stack in years, and a lot of code has
     9        since been written specifically with only a downwards growing stack in mind (e.g.
     10        the LLInt, the JITs).  Also, all our currently supported platforms use a downward
     11        growing stack.
     12
     13        We should remove the remnants of support code for an upwards growing stack.  The
     14        presence of that code is deceptive in that it conveys support for an upwards
     15        growing stack where this hasn't been the case in years.
     16
     17        * wtf/StackBounds.cpp:
     18        (WTF::StackBounds::newThreadStackBounds):
     19        (WTF::StackBounds::currentThreadStackBoundsInternal):
     20        (WTF::StackBounds::stackDirection): Deleted.
     21        (WTF::testStackDirection2): Deleted.
     22        (WTF::testStackDirection): Deleted.
     23        * wtf/StackBounds.h:
     24        (WTF::StackBounds::size const):
     25        (WTF::StackBounds::contains const):
     26        (WTF::StackBounds::recursionLimit const):
     27        (WTF::StackBounds::StackBounds):
     28        (WTF::StackBounds::isGrowingDownwards const):
     29        (WTF::StackBounds::checkConsistency const):
     30        (WTF::StackBounds::isGrowingDownward const): Deleted.
     31        * wtf/StackStats.cpp:
     32        (WTF::StackStats::CheckPoint::CheckPoint):
     33        (WTF::StackStats::CheckPoint::~CheckPoint):
     34        (WTF::StackStats::probe):
     35        (WTF::StackStats::LayoutCheckPoint::LayoutCheckPoint):
     36
    1372019-11-05  Mark Lam  <mark.lam@apple.com>
    238
  • trunk/Source/WTF/wtf/StackBounds.cpp

    r245876 r252177  
    11/*
    2  *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     2 *  Copyright (C) 2003-2019 Apple Inc. All rights reserved.
    33 *  Copyright (C) 2007 Eric Seidel <eric@webkit.org>
    44 *
     
    4646namespace WTF {
    4747
    48 #if CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)
    49 ALWAYS_INLINE StackBounds::StackDirection StackBounds::stackDirection()
    50 {
    51     return StackDirection::Downward;
    52 }
    53 #else
    54 static NEVER_INLINE NOT_TAIL_CALLED StackBounds::StackDirection testStackDirection2(volatile const uint8_t* pointer)
    55 {
    56     volatile uint8_t* stackValue = bitwise_cast<uint8_t*>(currentStackPointer());
    57     return (pointer < stackValue) ? StackBounds::StackDirection::Upward : StackBounds::StackDirection::Downward;
    58 }
    59 
    60 static NEVER_INLINE NOT_TAIL_CALLED StackBounds::StackDirection testStackDirection()
    61 {
    62     NO_TAIL_CALLS();
    63     volatile uint8_t* stackValue = bitwise_cast<uint8_t*>(currentStackPointer());
    64     return testStackDirection2(stackValue);
    65 }
    66 
    67 NEVER_INLINE StackBounds::StackDirection StackBounds::stackDirection()
    68 {
    69     static StackBounds::StackDirection result = StackBounds::StackDirection::Downward;
    70     static std::once_flag onceKey;
    71     std::call_once(onceKey, [] {
    72         NO_TAIL_CALLS();
    73         result = testStackDirection();
    74     });
    75     return result;
    76 }
    77 #endif
    78 
    7948#if OS(DARWIN)
    8049
    8150StackBounds StackBounds::newThreadStackBounds(PlatformThreadHandle thread)
    8251{
    83     ASSERT(stackDirection() == StackDirection::Downward);
    8452    void* origin = pthread_get_stackaddr_np(thread);
    8553    rlim_t size = pthread_get_stacksize_np(thread);
     
    9058StackBounds StackBounds::currentThreadStackBoundsInternal()
    9159{
    92     ASSERT(stackDirection() == StackDirection::Downward);
    9360    if (pthread_main_np()) {
    9461        // FIXME: <rdar://problem/13741204>
     
    11380    pthread_stackseg_np(thread, &stack);
    11481    void* origin = stack.ss_sp;
    115     void* bound = nullptr;
    116     if (stackDirection() == StackDirection::Upward)
    117         bound = static_cast<char*>(origin) + stack.ss_size;
    118     else
    119         bound = static_cast<char*>(origin) - stack.ss_size;
     82    void* bound = static_cast<char*>(origin) - stack.ss_size;
    12083    return StackBounds { origin, bound };
    12184}
     
    143106    void* origin = static_cast<char*>(bound) + stackSize;
    144107    // pthread_attr_getstack's bound is the lowest accessible pointer of the stack.
    145     // If stack grows up, origin and bound in this code should be swapped.
    146     if (stackDirection() == StackDirection::Upward)
    147         std::swap(origin, bound);
    148 
    149108    return StackBounds { origin, bound };
    150109}
     
    161120StackBounds StackBounds::currentThreadStackBoundsInternal()
    162121{
    163     ASSERT(stackDirection() == StackDirection::Downward);
    164122    MEMORY_BASIC_INFORMATION stackOrigin { };
    165123    VirtualQuery(&stackOrigin, &stackOrigin, sizeof(stackOrigin));
  • trunk/Source/WTF/wtf/StackBounds.h

    r251263 r252177  
    11/*
    2  * Copyright (C) 2010-2017 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2010-2019 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4444
    4545public:
    46     enum class StackDirection { Upward, Downward };
    47 
    4846    static constexpr StackBounds emptyBounds() { return StackBounds(); }
    4947
     
    7371    size_t size() const
    7472    {
    75         if (isGrowingDownward())
    76             return static_cast<char*>(m_origin) - static_cast<char*>(m_bound);
    77         return static_cast<char*>(m_bound) - static_cast<char*>(m_origin);
     73        return static_cast<char*>(m_origin) - static_cast<char*>(m_bound);
    7874    }
    7975
     
    8480        if (isEmpty())
    8581            return false;
    86         if (isGrowingDownward())
    87             return (m_origin >= p) && (p > m_bound);
    88         return (m_bound > p) && (p >= m_origin);
     82        return (m_origin >= p) && (p > m_bound);
    8983    }
    9084
     
    9286    {
    9387        checkConsistency();
    94         if (isGrowingDownward())
    95             return static_cast<char*>(m_bound) + minAvailableDelta;
    96         return static_cast<char*>(m_bound) - minAvailableDelta;
     88        return static_cast<char*>(m_bound) + minAvailableDelta;
    9789    }
    9890
     
    10496        size_t maxUserStackWithReservedZone = maxUserStack - reservedZoneSize;
    10597
    106         if (isGrowingDownward()) {
    107             char* endOfStackWithReservedZone = reinterpret_cast<char*>(m_bound) + reservedZoneSize;
    108             if (startOfUserStack < endOfStackWithReservedZone)
    109                 return endOfStackWithReservedZone;
    110             size_t availableUserStack = startOfUserStack - endOfStackWithReservedZone;
    111             if (maxUserStackWithReservedZone > availableUserStack)
    112                 maxUserStackWithReservedZone = availableUserStack;
    113             return startOfUserStack - maxUserStackWithReservedZone;
    114         }
    115 
    116         char* endOfStackWithReservedZone = reinterpret_cast<char*>(m_bound) - reservedZoneSize;
    117         if (startOfUserStack > endOfStackWithReservedZone)
     98        char* endOfStackWithReservedZone = reinterpret_cast<char*>(m_bound) + reservedZoneSize;
     99        if (startOfUserStack < endOfStackWithReservedZone)
    118100            return endOfStackWithReservedZone;
    119         size_t availableUserStack = endOfStackWithReservedZone - startOfUserStack;
     101        size_t availableUserStack = startOfUserStack - endOfStackWithReservedZone;
    120102        if (maxUserStackWithReservedZone > availableUserStack)
    121103            maxUserStackWithReservedZone = availableUserStack;
    122         return startOfUserStack + maxUserStackWithReservedZone;
    123     }
    124 
    125     bool isGrowingDownward() const
    126     {
    127         ASSERT(m_origin && m_bound);
    128         return m_bound <= m_origin;
     104        return startOfUserStack - maxUserStackWithReservedZone;
    129105    }
    130106
     
    134110        , m_bound(end)
    135111    {
     112        ASSERT(isGrowingDownwards());
    136113    }
    137114
     
    142119    }
    143120
    144     static StackDirection stackDirection();
     121    inline bool isGrowingDownwards() const
     122    {
     123        ASSERT(m_origin && m_bound);
     124        return m_bound <= m_origin;
     125    }
    145126
    146127    WTF_EXPORT_PRIVATE static StackBounds currentThreadStackBoundsInternal();
     
    151132        void* currentPosition = currentStackPointer();
    152133        ASSERT(m_origin != m_bound);
    153         ASSERT(isGrowingDownward()
    154             ? (currentPosition < m_origin && currentPosition > m_bound)
    155             : (currentPosition > m_origin && currentPosition < m_bound));
     134        ASSERT(currentPosition < m_origin && currentPosition > m_bound);
    156135#endif
    157136    }
  • trunk/Source/WTF/wtf/StackStats.cpp

    r237099 r252177  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    7474    const StackBounds& stack = thread.stack();
    7575
    76     bool isGrowingDownward = stack.isGrowingDownward();
    7776    bool needToLog = false;
    7877    char* current = reinterpret_cast<char*>(this);
     
    9291    // Update the stack height stats:
    9392    int height = t.m_stackStart - current;
    94     if (!isGrowingDownward)
    95         height = -height;
    9693    if (height > StackStats::s_maxStackHeight) {
    9794        StackStats::s_maxStackHeight = height;
     
    10198    // Update the checkpoint diff stats:
    10299    int diff = last - current;
    103     if (!isGrowingDownward)
    104         diff = -diff;
    105100    if (diff > StackStats::s_maxCheckPointDiff) {
    106101        StackStats::s_maxCheckPointDiff = diff;
     
    139134    if (!m_prev) {
    140135        const StackBounds& stack = thread.stack();
    141         bool isGrowingDownward = stack.isGrowingDownward();
    142136
    143137        char* current = reinterpret_cast<char*>(this);
    144138        int height = t.m_stackStart - current;
    145 
    146         if (!isGrowingDownward)
    147             height = -height;
    148139
    149140        dataLogF(" POP to %p diff max %.1fk | reentry %d/%d max | height %.1fk/max %.1fk | stack %p size %.1fk)\n",
     
    163154    const StackBounds& stack = thread.stack();
    164155
    165     bool isGrowingDownward = stack.isGrowingDownward();
    166 
    167156    bool needToLog = false;
    168157
     
    180169    // Update the stack height stats:
    181170    int height = t.m_stackStart - current;
    182     if (!isGrowingDownward)
    183         height = -height;
    184171    if (height > StackStats::s_maxStackHeight) {
    185172        StackStats::s_maxStackHeight = height;
     
    189176    // Update the checkpoint diff stats:
    190177    int diff = last - current;
    191     if (!isGrowingDownward)
    192         diff = -diff;
    193178    if (diff > StackStats::s_maxCheckPointDiff) {
    194179        StackStats::s_maxCheckPointDiff = diff;
     
    224209    const StackBounds& stack = thread.stack();
    225210
    226     bool isGrowingDownward = stack.isGrowingDownward();
    227 
    228211    // Push this checkpoint:
    229212    m_prev = StackStats::s_topLayoutCheckPoint;
     
    251234    // Update the stack height stats:
    252235    int height = t.m_stackStart - current;
    253     if (!isGrowingDownward)
    254         height = -height;
    255236    if (height > StackStats::s_maxStackHeight) {
    256237        StackStats::s_maxStackHeight = height;
     
    259240
    260241    // Update the layout checkpoint diff stats:
    261     if (!isGrowingDownward)
    262         diff = -diff;
    263242    if (diff > StackStats::s_maxLayoutCheckPointDiff) {
    264243        StackStats::s_maxLayoutCheckPointDiff = diff;
     
    267246
    268247    // Update the total layout checkpoint diff stats:
    269     if (!isGrowingDownward)
    270         totalDiff = -totalDiff;
    271248    if (totalDiff > StackStats::s_maxTotalLayoutCheckPointDiff) {
    272249        StackStats::s_maxTotalLayoutCheckPointDiff = totalDiff;
Note: See TracChangeset for help on using the changeset viewer.