Title: [252177] trunk/Source
Revision
252177
Author
mark....@apple.com
Date
2019-11-06 23:27:52 -0800 (Wed, 06 Nov 2019)

Log 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/_javascript_Core:

* 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (252176 => 252177)


--- trunk/Source/_javascript_Core/ChangeLog	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-11-07 07:27:52 UTC (rev 252177)
@@ -1,3 +1,22 @@
+2019-11-06  Mark Lam  <mark....@apple.com>
+
+        Remove remnants of support code for an upwards growing stack.
+        https://bugs.webkit.org/show_bug.cgi?id=203942
+
+        Reviewed by Yusuke Suzuki.
+
+        * 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):
+
 2019-11-06  Tadeu Zagallo  <tzaga...@apple.com>
 
         [WebAssembly] BBQPlan should retain Wasm::CodeBlock when compiling a single function

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (252176 => 252177)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2019-11-07 07:27:52 UTC (rev 252177)
@@ -896,7 +896,6 @@
     RELEASE_ASSERT(reservedZoneSize >= minimumReservedZoneSize);
 
     if (m_stackPointerAtVMEntry) {
-        ASSERT(stack.isGrowingDownward());
         char* startOfStack = reinterpret_cast<char*>(m_stackPointerAtVMEntry);
         m_softStackLimit = stack.recursionLimit(startOfStack, Options::maxPerThreadStackUsage(), m_currentSoftReservedZoneSize);
         m_stackLimit = stack.recursionLimit(startOfStack, Options::maxPerThreadStackUsage(), reservedZoneSize);
@@ -1170,7 +1169,6 @@
 #if !ENABLE(C_LOOP)
     // When using the C stack, we don't know how many stack pages are actually
     // committed. So, we use the current stack usage as an estimate.
-    ASSERT(Thread::current().stack().isGrowingDownward());
     uint8_t* current = bitwise_cast<uint8_t*>(currentStackPointer());
     uint8_t* high = bitwise_cast<uint8_t*>(Thread::current().stack().origin());
     return high - current;

Modified: trunk/Source/_javascript_Core/runtime/VM.h (252176 => 252177)


--- trunk/Source/_javascript_Core/runtime/VM.h	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2019-11-07 07:27:52 UTC (rev 252177)
@@ -973,7 +973,6 @@
 
     bool isSafeToRecurse(void* stackLimit) const
     {
-        ASSERT(Thread::current().stack().isGrowingDownward());
         void* curr = currentStackPointer();
         return curr >= stackLimit;
     }

Modified: trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp (252176 => 252177)


--- trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp	2019-11-07 07:27:52 UTC (rev 252177)
@@ -42,7 +42,6 @@
     , m_globalObject(globalObject)
 {
     ASSERT(!DisallowVMReentry::isInEffectOnCurrentThread());
-    ASSERT(Thread::current().stack().isGrowingDownward());
     if (!vm.entryScope) {
         vm.entryScope = this;
 

Modified: trunk/Source/_javascript_Core/runtime/VMInlines.h (252176 => 252177)


--- trunk/Source/_javascript_Core/runtime/VMInlines.h	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/_javascript_Core/runtime/VMInlines.h	2019-11-07 07:27:52 UTC (rev 252177)
@@ -35,7 +35,6 @@
 bool VM::ensureStackCapacityFor(Register* newTopOfStack)
 {
 #if !ENABLE(C_LOOP)
-    ASSERT(Thread::current().stack().isGrowingDownward());
     return newTopOfStack >= m_softStackLimit;
 #else
     return ensureStackCapacityForCLoop(newTopOfStack);

Modified: trunk/Source/_javascript_Core/yarr/YarrPattern.cpp (252176 => 252177)


--- trunk/Source/_javascript_Core/yarr/YarrPattern.cpp	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/_javascript_Core/yarr/YarrPattern.cpp	2019-11-07 07:27:52 UTC (rev 252177)
@@ -1122,7 +1122,6 @@
     {
         if (!m_stackLimit)
             return true;
-        ASSERT(Thread::current().stack().isGrowingDownward());
         int8_t* curr = reinterpret_cast<int8_t*>(currentStackPointer());
         int8_t* limit = reinterpret_cast<int8_t*>(m_stackLimit);
         return curr >= limit;

Modified: trunk/Source/WTF/ChangeLog (252176 => 252177)


--- trunk/Source/WTF/ChangeLog	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/WTF/ChangeLog	2019-11-07 07:27:52 UTC (rev 252177)
@@ -1,3 +1,39 @@
+2019-11-06  Mark Lam  <mark....@apple.com>
+
+        Remove remnants of support code for an upwards growing stack.
+        https://bugs.webkit.org/show_bug.cgi?id=203942
+
+        Reviewed by Yusuke Suzuki.
+
+        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):
+
 2019-11-05  Mark Lam  <mark....@apple.com>
 
         WTF::RunLoop should not depend on isMainThread() idiom.

Modified: trunk/Source/WTF/wtf/StackBounds.cpp (252176 => 252177)


--- trunk/Source/WTF/wtf/StackBounds.cpp	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/WTF/wtf/StackBounds.cpp	2019-11-07 07:27:52 UTC (rev 252177)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ *  Copyright (C) 2003-2019 Apple Inc. All rights reserved.
  *  Copyright (C) 2007 Eric Seidel <e...@webkit.org>
  *
  *  This library is free software; you can redistribute it and/or
@@ -45,42 +45,10 @@
 
 namespace WTF {
 
-#if CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)
-ALWAYS_INLINE StackBounds::StackDirection StackBounds::stackDirection()
-{
-    return StackDirection::Downward;
-}
-#else
-static NEVER_INLINE NOT_TAIL_CALLED StackBounds::StackDirection testStackDirection2(volatile const uint8_t* pointer)
-{
-    volatile uint8_t* stackValue = bitwise_cast<uint8_t*>(currentStackPointer());
-    return (pointer < stackValue) ? StackBounds::StackDirection::Upward : StackBounds::StackDirection::Downward;
-}
-
-static NEVER_INLINE NOT_TAIL_CALLED StackBounds::StackDirection testStackDirection()
-{
-    NO_TAIL_CALLS();
-    volatile uint8_t* stackValue = bitwise_cast<uint8_t*>(currentStackPointer());
-    return testStackDirection2(stackValue);
-}
-
-NEVER_INLINE StackBounds::StackDirection StackBounds::stackDirection()
-{
-    static StackBounds::StackDirection result = StackBounds::StackDirection::Downward;
-    static std::once_flag onceKey;
-    std::call_once(onceKey, [] {
-        NO_TAIL_CALLS();
-        result = testStackDirection();
-    });
-    return result;
-}
-#endif
-
 #if OS(DARWIN)
 
 StackBounds StackBounds::newThreadStackBounds(PlatformThreadHandle thread)
 {
-    ASSERT(stackDirection() == StackDirection::Downward);
     void* origin = pthread_get_stackaddr_np(thread);
     rlim_t size = pthread_get_stacksize_np(thread);
     void* bound = static_cast<char*>(origin) - size;
@@ -89,7 +57,6 @@
 
 StackBounds StackBounds::currentThreadStackBoundsInternal()
 {
-    ASSERT(stackDirection() == StackDirection::Downward);
     if (pthread_main_np()) {
         // FIXME: <rdar://problem/13741204>
         // pthread_get_size lies to us when we're the main thread, use get_rlimit instead
@@ -112,11 +79,7 @@
     stack_t stack;
     pthread_stackseg_np(thread, &stack);
     void* origin = stack.ss_sp;
-    void* bound = nullptr;
-    if (stackDirection() == StackDirection::Upward)
-        bound = static_cast<char*>(origin) + stack.ss_size;
-    else
-        bound = static_cast<char*>(origin) - stack.ss_size;
+    void* bound = static_cast<char*>(origin) - stack.ss_size;
     return StackBounds { origin, bound };
 }
 
@@ -142,10 +105,6 @@
     pthread_attr_destroy(&sattr);
     void* origin = static_cast<char*>(bound) + stackSize;
     // pthread_attr_getstack's bound is the lowest accessible pointer of the stack.
-    // If stack grows up, origin and bound in this code should be swapped.
-    if (stackDirection() == StackDirection::Upward)
-        std::swap(origin, bound);
-
     return StackBounds { origin, bound };
 }
 
@@ -160,7 +119,6 @@
 
 StackBounds StackBounds::currentThreadStackBoundsInternal()
 {
-    ASSERT(stackDirection() == StackDirection::Downward);
     MEMORY_BASIC_INFORMATION stackOrigin { };
     VirtualQuery(&stackOrigin, &stackOrigin, sizeof(stackOrigin));
     // stackOrigin.AllocationBase points to the reserved stack memory base address.

Modified: trunk/Source/WTF/wtf/StackBounds.h (252176 => 252177)


--- trunk/Source/WTF/wtf/StackBounds.h	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/WTF/wtf/StackBounds.h	2019-11-07 07:27:52 UTC (rev 252177)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2017 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2010-2019 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -43,8 +43,6 @@
     static constexpr size_t s_defaultAvailabilityDelta = 64 * 1024;
 
 public:
-    enum class StackDirection { Upward, Downward };
-
     static constexpr StackBounds emptyBounds() { return StackBounds(); }
 
 #if HAVE(STACK_BOUNDS_FOR_NEW_THREAD)
@@ -72,9 +70,7 @@
     
     size_t size() const
     {
-        if (isGrowingDownward())
-            return static_cast<char*>(m_origin) - static_cast<char*>(m_bound);
-        return static_cast<char*>(m_bound) - static_cast<char*>(m_origin);
+        return static_cast<char*>(m_origin) - static_cast<char*>(m_bound);
     }
 
     bool isEmpty() const { return !m_origin; }
@@ -83,17 +79,13 @@
     {
         if (isEmpty())
             return false;
-        if (isGrowingDownward())
-            return (m_origin >= p) && (p > m_bound);
-        return (m_bound > p) && (p >= m_origin);
+        return (m_origin >= p) && (p > m_bound);
     }
 
     void* recursionLimit(size_t minAvailableDelta = s_defaultAvailabilityDelta) const
     {
         checkConsistency();
-        if (isGrowingDownward())
-            return static_cast<char*>(m_bound) + minAvailableDelta;
-        return static_cast<char*>(m_bound) - minAvailableDelta;
+        return static_cast<char*>(m_bound) + minAvailableDelta;
     }
 
     void* recursionLimit(char* startOfUserStack, size_t maxUserStack, size_t reservedZoneSize) const
@@ -103,36 +95,21 @@
             reservedZoneSize = maxUserStack;
         size_t maxUserStackWithReservedZone = maxUserStack - reservedZoneSize;
 
-        if (isGrowingDownward()) {
-            char* endOfStackWithReservedZone = reinterpret_cast<char*>(m_bound) + reservedZoneSize;
-            if (startOfUserStack < endOfStackWithReservedZone)
-                return endOfStackWithReservedZone;
-            size_t availableUserStack = startOfUserStack - endOfStackWithReservedZone;
-            if (maxUserStackWithReservedZone > availableUserStack)
-                maxUserStackWithReservedZone = availableUserStack;
-            return startOfUserStack - maxUserStackWithReservedZone;
-        }
-
-        char* endOfStackWithReservedZone = reinterpret_cast<char*>(m_bound) - reservedZoneSize;
-        if (startOfUserStack > endOfStackWithReservedZone)
+        char* endOfStackWithReservedZone = reinterpret_cast<char*>(m_bound) + reservedZoneSize;
+        if (startOfUserStack < endOfStackWithReservedZone)
             return endOfStackWithReservedZone;
-        size_t availableUserStack = endOfStackWithReservedZone - startOfUserStack;
+        size_t availableUserStack = startOfUserStack - endOfStackWithReservedZone;
         if (maxUserStackWithReservedZone > availableUserStack)
             maxUserStackWithReservedZone = availableUserStack;
-        return startOfUserStack + maxUserStackWithReservedZone;
+        return startOfUserStack - maxUserStackWithReservedZone;
     }
 
-    bool isGrowingDownward() const
-    {
-        ASSERT(m_origin && m_bound);
-        return m_bound <= m_origin;
-    }
-
 private:
     StackBounds(void* origin, void* end)
         : m_origin(origin)
         , m_bound(end)
     {
+        ASSERT(isGrowingDownwards());
     }
 
     constexpr StackBounds()
@@ -141,7 +118,11 @@
     {
     }
 
-    static StackDirection stackDirection();
+    inline bool isGrowingDownwards() const
+    {
+        ASSERT(m_origin && m_bound);
+        return m_bound <= m_origin;
+    }
 
     WTF_EXPORT_PRIVATE static StackBounds currentThreadStackBoundsInternal();
 
@@ -150,9 +131,7 @@
 #if !ASSERT_DISABLED
         void* currentPosition = currentStackPointer();
         ASSERT(m_origin != m_bound);
-        ASSERT(isGrowingDownward()
-            ? (currentPosition < m_origin && currentPosition > m_bound)
-            : (currentPosition > m_origin && currentPosition < m_bound));
+        ASSERT(currentPosition < m_origin && currentPosition > m_bound);
 #endif
     }
 

Modified: trunk/Source/WTF/wtf/StackStats.cpp (252176 => 252177)


--- trunk/Source/WTF/wtf/StackStats.cpp	2019-11-07 07:21:38 UTC (rev 252176)
+++ trunk/Source/WTF/wtf/StackStats.cpp	2019-11-07 07:27:52 UTC (rev 252177)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -73,7 +73,6 @@
     StackStats::PerThreadStats& t = thread.stackStats();
     const StackBounds& stack = thread.stack();
 
-    bool isGrowingDownward = stack.isGrowingDownward();
     bool needToLog = false;
     char* current = reinterpret_cast<char*>(this);
     char* last = reinterpret_cast<char*>(t.m_currentCheckPoint);
@@ -91,8 +90,6 @@
 
     // Update the stack height stats:
     int height = t.m_stackStart - current;
-    if (!isGrowingDownward)
-        height = -height;
     if (height > StackStats::s_maxStackHeight) {
         StackStats::s_maxStackHeight = height;
         needToLog = true;
@@ -100,8 +97,6 @@
 
     // Update the checkpoint diff stats:
     int diff = last - current;
-    if (!isGrowingDownward)
-        diff = -diff;
     if (diff > StackStats::s_maxCheckPointDiff) {
         StackStats::s_maxCheckPointDiff = diff;
         needToLog = true;
@@ -138,14 +133,10 @@
 #if ENABLE(VERBOSE_STACK_STATS)
     if (!m_prev) {
         const StackBounds& stack = thread.stack();
-        bool isGrowingDownward = stack.isGrowingDownward();
 
         char* current = reinterpret_cast<char*>(this);
         int height = t.m_stackStart - current;
 
-        if (!isGrowingDownward)
-            height = -height;
-
         dataLogF(" POP to %p diff max %.1fk | reentry %d/%d max | height %.1fk/max %.1fk | stack %p size %.1fk)\n",
             this, StackStats::s_maxCheckPointDiff / 1024.0,
             t.m_reentryDepth, StackStats::s_maxReentryDepth,
@@ -162,8 +153,6 @@
     StackStats::PerThreadStats& t = thread.stackStats();
     const StackBounds& stack = thread.stack();
 
-    bool isGrowingDownward = stack.isGrowingDownward();
-
     bool needToLog = false;
 
     int dummy;
@@ -179,8 +168,6 @@
 
     // Update the stack height stats:
     int height = t.m_stackStart - current;
-    if (!isGrowingDownward)
-        height = -height;
     if (height > StackStats::s_maxStackHeight) {
         StackStats::s_maxStackHeight = height;
         needToLog = true;
@@ -188,8 +175,6 @@
 
     // Update the checkpoint diff stats:
     int diff = last - current;
-    if (!isGrowingDownward)
-        diff = -diff;
     if (diff > StackStats::s_maxCheckPointDiff) {
         StackStats::s_maxCheckPointDiff = diff;
         needToLog = true;
@@ -223,8 +208,6 @@
     StackStats::PerThreadStats& t = thread.stackStats();
     const StackBounds& stack = thread.stack();
 
-    bool isGrowingDownward = stack.isGrowingDownward();
-
     // Push this checkpoint:
     m_prev = StackStats::s_topLayoutCheckPoint;
     if (m_prev)
@@ -250,8 +233,6 @@
 
     // Update the stack height stats:
     int height = t.m_stackStart - current;
-    if (!isGrowingDownward)
-        height = -height;
     if (height > StackStats::s_maxStackHeight) {
         StackStats::s_maxStackHeight = height;
         needToLog = true;
@@ -258,8 +239,6 @@
     }
 
     // Update the layout checkpoint diff stats:
-    if (!isGrowingDownward)
-        diff = -diff;
     if (diff > StackStats::s_maxLayoutCheckPointDiff) {
         StackStats::s_maxLayoutCheckPointDiff = diff;
         needToLog = true;
@@ -266,8 +245,6 @@
     }
 
     // Update the total layout checkpoint diff stats:
-    if (!isGrowingDownward)
-        totalDiff = -totalDiff;
     if (totalDiff > StackStats::s_maxTotalLayoutCheckPointDiff) {
         StackStats::s_maxTotalLayoutCheckPointDiff = totalDiff;
         needToLog = true;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to