Title: [264635] trunk/Source
Revision
264635
Author
[email protected]
Date
2020-07-20 16:36:01 -0700 (Mon, 20 Jul 2020)

Log Message

REGRESSION (r264242): [ macOS ] imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate.any.html is a flaky crash
https://bugs.webkit.org/show_bug.cgi?id=214572

Unreviewed, reverting r264242.


Source/_javascript_Core:

* runtime/JSRunLoopTimer.cpp:
(JSC::epochTime):
(JSC::JSRunLoopTimer::Manager::timerDidFireCallback):
(JSC::JSRunLoopTimer::Manager::PerVMData::setRunLoop):
(JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData):
(JSC::JSRunLoopTimer::Manager::PerVMData::~PerVMData):
(JSC::JSRunLoopTimer::Manager::timerDidFire):
(JSC::JSRunLoopTimer::Manager::registerVM):
(JSC::JSRunLoopTimer::Manager::scheduleTimer):
(JSC::JSRunLoopTimer::Manager::cancelTimer):
(JSC::JSRunLoopTimer::Manager::didChangeRunLoop):
* runtime/JSRunLoopTimer.h:
(JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData):
* runtime/PromiseTimer.cpp:
(JSC::PromiseTimer::doWork):
(JSC::PromiseTimer::runRunLoop):
* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::create):
(JSC::VM::tryCreate):
(JSC::VM::setRunLoop):
* runtime/VM.h:
(JSC::VM::runLoop const):

Source/WebCore:

* bindings/js/CommonVM.cpp:
(WebCore::commonVMSlow):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (264634 => 264635)


--- trunk/Source/_javascript_Core/ChangeLog	2020-07-20 23:32:35 UTC (rev 264634)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-07-20 23:36:01 UTC (rev 264635)
@@ -1,3 +1,34 @@
+2020-07-20  Geoffrey Garen  <[email protected]>
+
+        REGRESSION (r264242): [ macOS ] imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate.any.html is a flaky crash
+        https://bugs.webkit.org/show_bug.cgi?id=214572
+
+        Unreviewed, reverting r264242.
+
+        * runtime/JSRunLoopTimer.cpp:
+        (JSC::epochTime):
+        (JSC::JSRunLoopTimer::Manager::timerDidFireCallback):
+        (JSC::JSRunLoopTimer::Manager::PerVMData::setRunLoop):
+        (JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData):
+        (JSC::JSRunLoopTimer::Manager::PerVMData::~PerVMData):
+        (JSC::JSRunLoopTimer::Manager::timerDidFire):
+        (JSC::JSRunLoopTimer::Manager::registerVM):
+        (JSC::JSRunLoopTimer::Manager::scheduleTimer):
+        (JSC::JSRunLoopTimer::Manager::cancelTimer):
+        (JSC::JSRunLoopTimer::Manager::didChangeRunLoop):
+        * runtime/JSRunLoopTimer.h:
+        (JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData):
+        * runtime/PromiseTimer.cpp:
+        (JSC::PromiseTimer::doWork):
+        (JSC::PromiseTimer::runRunLoop):
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        (JSC::VM::create):
+        (JSC::VM::tryCreate):
+        (JSC::VM::setRunLoop):
+        * runtime/VM.h:
+        (JSC::VM::runLoop const):
+
 2020-07-20  Ross Kirsling  <[email protected]>
 
         [JSC] eval?.() should be indirect eval

Modified: trunk/Source/_javascript_Core/runtime/DeferredWorkTimer.cpp (264634 => 264635)


--- trunk/Source/_javascript_Core/runtime/DeferredWorkTimer.cpp	2020-07-20 23:32:35 UTC (rev 264634)
+++ trunk/Source/_javascript_Core/runtime/DeferredWorkTimer.cpp	2020-07-20 23:36:01 UTC (rev 264635)
@@ -81,8 +81,13 @@
         }
     }
 
-    if (m_pendingTickets.isEmpty() && m_shouldStopRunLoopWhenAllTicketsFinish)
+    if (m_pendingTickets.isEmpty() && m_shouldStopRunLoopWhenAllTicketsFinish) {
+#if USE(CF)
+        CFRunLoopStop(vm.runLoop());
+#else
         RunLoop::current().stop();
+#endif
+    }
 
     m_taskLock.unlock();
 }
@@ -90,10 +95,17 @@
 void DeferredWorkTimer::runRunLoop()
 {
     ASSERT(!m_apiLock->vm()->currentThreadIsHoldingAPILock());
-    ASSERT(&RunLoop::current() == &m_apiLock->vm()->runLoop());
+#if USE(CF)
+    ASSERT(CFRunLoopGetCurrent() == m_apiLock->vm()->runLoop());
+#endif
     m_shouldStopRunLoopWhenAllTicketsFinish = true;
-    if (m_pendingTickets.size())
+    if (m_pendingTickets.size()) {
+#if USE(CF)
+        CFRunLoopRun();
+#else
         RunLoop::run();
+#endif
+    }
 }
 
 void DeferredWorkTimer::addPendingWork(VM& vm, Ticket ticket, Vector<Strong<JSCell>>&& dependencies)

Modified: trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp (264634 => 264635)


--- trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp	2020-07-20 23:32:35 UTC (rev 264634)
+++ trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp	2020-07-20 23:36:01 UTC (rev 264635)
@@ -40,13 +40,47 @@
 
 static inline JSRunLoopTimer::Manager::EpochTime epochTime(Seconds delay)
 {
+#if USE(CF)
+    return Seconds { CFAbsoluteTimeGetCurrent() + delay.value() };
+#else
     return MonotonicTime::now().secondsSinceEpoch() + delay;
+#endif
 }
 
-JSRunLoopTimer::Manager::PerVMData::PerVMData(Manager& manager, RunLoop& runLoop)
-    : runLoop(runLoop)
-    , timer(makeUnique<RunLoop::Timer<Manager>>(runLoop, &manager, &JSRunLoopTimer::Manager::timerDidFireCallback))
+#if USE(CF)
+void JSRunLoopTimer::Manager::timerDidFireCallback(CFRunLoopTimerRef, void* contextPtr)
 {
+    static_cast<JSRunLoopTimer::Manager*>(contextPtr)->timerDidFire();
+}
+
+void JSRunLoopTimer::Manager::PerVMData::setRunLoop(Manager* manager, CFRunLoopRef newRunLoop)
+{
+    if (runLoop) {
+        CFRunLoopRemoveTimer(runLoop.get(), timer.get(), kCFRunLoopCommonModes);
+        CFRunLoopTimerInvalidate(timer.get());
+        runLoop.clear();
+        timer.clear();
+    }
+
+    if (newRunLoop) {
+        runLoop = newRunLoop;
+        memset(&context, 0, sizeof(CFRunLoopTimerContext));
+        RELEASE_ASSERT(manager);
+        context.info = manager;
+        timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade.seconds(), CFAbsoluteTimeGetCurrent() + s_decade.seconds(), 0, 0, JSRunLoopTimer::Manager::timerDidFireCallback, &context));
+        CFRunLoopAddTimer(runLoop.get(), timer.get(), kCFRunLoopCommonModes);
+
+        EpochTime scheduleTime = epochTime(s_decade);
+        for (auto& pair : timers)
+            scheduleTime = std::min(pair.second, scheduleTime);
+        CFRunLoopTimerSetNextFireDate(timer.get(), scheduleTime.value());
+    }
+}
+#else
+JSRunLoopTimer::Manager::PerVMData::PerVMData(Manager& manager)
+    : runLoop(&RunLoop::current())
+    , timer(makeUnique<RunLoop::Timer<Manager>>(*runLoop, &manager, &JSRunLoopTimer::Manager::timerDidFireCallback))
+{
 #if USE(GLIB_EVENT_LOOP)
     timer->setPriority(RunLoopSourcePriority::_javascript_Timer);
     timer->setName("[_javascript_Core] JSRunLoopTimer");
@@ -57,9 +91,13 @@
 {
     timerDidFire();
 }
+#endif
 
 JSRunLoopTimer::Manager::PerVMData::~PerVMData()
 {
+#if USE(CF)
+    setRunLoop(nullptr, nullptr);
+#endif
 }
 
 void JSRunLoopTimer::Manager::timerDidFire()
@@ -68,12 +106,21 @@
 
     {
         auto locker = holdLock(m_lock);
+#if USE(CF)
+        CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent();
+#else
         RunLoop* currentRunLoop = &RunLoop::current();
+#endif
         EpochTime nowEpochTime = epochTime(0_s);
         for (auto& entry : m_mapping) {
             PerVMData& data = ""
-            if (data.runLoop.ptr() != currentRunLoop)
+#if USE(CF)
+            if (data.runLoop.get() != currentRunLoop)
                 continue;
+#else
+            if (data.runLoop != currentRunLoop)
+                continue;
+#endif
             
             EpochTime scheduleTime = epochTime(s_decade);
             for (size_t i = 0; i < data.timers.size(); ++i) {
@@ -93,7 +140,11 @@
                 timersToFire.append(WTFMove(pair.first));
             }
 
+#if USE(CF)
+            CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
+#else
             data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
+#endif
         }
     }
 
@@ -113,7 +164,10 @@
 
 void JSRunLoopTimer::Manager::registerVM(VM& vm)
 {
-    auto data = "" vm.runLoop());
+    auto data = ""
+#if USE(CF)
+    data->setRunLoop(this, vm.runLoop());
+#endif
 
     auto locker = holdLock(m_lock);
     auto addResult = m_mapping.add({ vm.apiLock() }, WTFMove(data));
@@ -151,7 +205,11 @@
     if (!found)
         data.timers.append({ timer, fireEpochTime });
 
+#if USE(CF)
+    CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
+#else
     data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
+#endif
 }
 
 void JSRunLoopTimer::Manager::cancelTimer(JSRunLoopTimer& timer)
@@ -182,7 +240,11 @@
         scheduleTime = std::min(scheduleTime, data.timers[i].second);
     }
 
+#if USE(CF)
+    CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
+#else
     data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
+#endif
 }
 
 Optional<Seconds> JSRunLoopTimer::Manager::timeUntilFire(JSRunLoopTimer& timer)
@@ -202,6 +264,18 @@
     return WTF::nullopt;
 }
 
+#if USE(CF)
+void JSRunLoopTimer::Manager::didChangeRunLoop(VM& vm, CFRunLoopRef newRunLoop)
+{
+    auto locker = holdLock(m_lock);
+    auto iter = m_mapping.find({ vm.apiLock() });
+    RELEASE_ASSERT(iter != m_mapping.end());
+
+    PerVMData& data = ""
+    data.setRunLoop(this, newRunLoop);
+}
+#endif
+
 void JSRunLoopTimer::timerDidFire()
 {
     NO_TAIL_CALLS();

Modified: trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h (264634 => 264635)


--- trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h	2020-07-20 23:32:35 UTC (rev 264634)
+++ trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h	2020-07-20 23:36:01 UTC (rev 264635)
@@ -33,6 +33,10 @@
 #include <wtf/SharedTask.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
+#if USE(CF)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
 namespace JSC {
 
 class JSLock;
@@ -46,8 +50,11 @@
     class Manager {
         WTF_MAKE_FAST_ALLOCATED;
         WTF_MAKE_NONCOPYABLE(Manager);
+#if USE(CF)
+        static void timerDidFireCallback(CFRunLoopTimerRef, void*);
+#else
         void timerDidFireCallback();
-
+#endif
         Manager() = default;
 
         void timerDidFire();
@@ -63,6 +70,10 @@
 
         Optional<Seconds> timeUntilFire(JSRunLoopTimer&);
 
+#if USE(CF)
+        void didChangeRunLoop(VM&, CFRunLoopRef newRunLoop);
+#endif
+
     private:
         Lock m_lock;
 
@@ -70,11 +81,22 @@
             WTF_MAKE_FAST_ALLOCATED;
             WTF_MAKE_NONCOPYABLE(PerVMData);
         public:
-            PerVMData(Manager&, WTF::RunLoop&);
+#if USE(CF)
+            PerVMData(Manager&) { }
+#else
+            PerVMData(Manager&);
+#endif
             ~PerVMData();
 
-            Ref<WTF::RunLoop> runLoop;
+#if USE(CF)
+            void setRunLoop(Manager*, CFRunLoopRef);
+            RetainPtr<CFRunLoopTimerRef> timer;
+            RetainPtr<CFRunLoopRef> runLoop;
+            CFRunLoopTimerContext context;
+#else
+            RunLoop* runLoop;
             std::unique_ptr<RunLoop::Timer<Manager>> timer;
+#endif
             Vector<std::pair<Ref<JSRunLoopTimer>, EpochTime>> timers;
         };
 

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (264634 => 264635)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2020-07-20 23:32:35 UTC (rev 264634)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2020-07-20 23:36:01 UTC (rev 264635)
@@ -263,10 +263,12 @@
 
 static bool vmCreationShouldCrash = false;
 
-VM::VM(VMType vmType, HeapType heapType, WTF::RunLoop* runLoop, bool* success)
+VM::VM(VMType vmType, HeapType heapType, bool* success)
     : m_id(nextID())
     , m_apiLock(adoptRef(new JSLock(this)))
-    , m_runLoop(runLoop ? *runLoop : WTF::RunLoop::current())
+#if USE(CF)
+    , m_runLoop(CFRunLoopGetCurrent())
+#endif // USE(CF)
     , m_random(Options::seedOfVMRandomForFuzzer() ? Options::seedOfVMRandomForFuzzer() : cryptographicallyRandomNumber())
     , m_integrityRandom(*this)
     , heap(*this, heapType)
@@ -677,15 +679,15 @@
     return adoptRef(*new VM(APIContextGroup, heapType));
 }
 
-Ref<VM> VM::create(HeapType heapType, WTF::RunLoop* runLoop)
+Ref<VM> VM::create(HeapType heapType)
 {
-    return adoptRef(*new VM(Default, heapType, runLoop));
+    return adoptRef(*new VM(Default, heapType));
 }
 
-RefPtr<VM> VM::tryCreate(HeapType heapType, WTF::RunLoop* runLoop)
+RefPtr<VM> VM::tryCreate(HeapType heapType)
 {
     bool success = true;
-    RefPtr<VM> vm = adoptRef(new VM(Default, heapType, runLoop, &success));
+    RefPtr<VM> vm = adoptRef(new VM(Default, heapType, &success));
     if (!success) {
         // Here, we're destructing a partially constructed VM and we know that
         // no one else can be using it at the same time. So, acquiring the lock
@@ -1383,6 +1385,15 @@
 }
 #endif
 
+#if USE(CF)
+void VM::setRunLoop(CFRunLoopRef runLoop)
+{
+    ASSERT(runLoop);
+    m_runLoop = runLoop;
+    JSRunLoopTimer::Manager::shared().didChangeRunLoop(*this, runLoop);
+}
+#endif // USE(CF)
+
 ScratchBuffer* VM::scratchBufferForSize(size_t size)
 {
     if (!size)

Modified: trunk/Source/_javascript_Core/runtime/VM.h (264634 => 264635)


--- trunk/Source/_javascript_Core/runtime/VM.h	2020-07-20 23:32:35 UTC (rev 264634)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2020-07-20 23:36:01 UTC (rev 264635)
@@ -94,7 +94,6 @@
 #endif
 
 namespace WTF {
-class RunLoop;
 class SimpleStats;
 } // namespace WTF
 using WTF::SimpleStats;
@@ -313,8 +312,8 @@
     JS_EXPORT_PRIVATE static bool sharedInstanceExists();
     JS_EXPORT_PRIVATE static VM& sharedInstance();
 
-    JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap, WTF::RunLoop* = nullptr);
-    JS_EXPORT_PRIVATE static RefPtr<VM> tryCreate(HeapType = SmallHeap, WTF::RunLoop* = nullptr);
+    JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap);
+    JS_EXPORT_PRIVATE static RefPtr<VM> tryCreate(HeapType = SmallHeap);
     static Ref<VM> createContextGroup(HeapType = SmallHeap);
     JS_EXPORT_PRIVATE ~VM();
 
@@ -355,7 +354,10 @@
 
     unsigned m_id;
     RefPtr<JSLock> m_apiLock;
-    Ref<WTF::RunLoop> m_runLoop;
+#if USE(CF)
+    // These need to be initialized before heap below.
+    RetainPtr<CFRunLoopRef> m_runLoop;
+#endif
 
     WeakRandom m_random;
     Integrity::Random m_integrityRandom;
@@ -1080,7 +1082,10 @@
     bool needExceptionCheck() const { return m_needExceptionCheck; }
 #endif
 
-    WTF::RunLoop& runLoop() const { return m_runLoop; }
+#if USE(CF)
+    CFRunLoopRef runLoop() const { return m_runLoop.get(); }
+    JS_EXPORT_PRIVATE void setRunLoop(CFRunLoopRef);
+#endif // USE(CF)
 
     static void setCrashOnVMCreation(bool);
 
@@ -1104,7 +1109,7 @@
 private:
     friend class LLIntOffsetsExtractor;
 
-    VM(VMType, HeapType, WTF::RunLoop* = nullptr, bool* success = nullptr);
+    VM(VMType, HeapType, bool* success = nullptr);
     static VM*& sharedInstanceInternal();
     void createNativeThunk();
 

Modified: trunk/Source/WebCore/ChangeLog (264634 => 264635)


--- trunk/Source/WebCore/ChangeLog	2020-07-20 23:32:35 UTC (rev 264634)
+++ trunk/Source/WebCore/ChangeLog	2020-07-20 23:36:01 UTC (rev 264635)
@@ -1,3 +1,13 @@
+2020-07-20  Geoffrey Garen  <[email protected]>
+
+        REGRESSION (r264242): [ macOS ] imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate.any.html is a flaky crash
+        https://bugs.webkit.org/show_bug.cgi?id=214572
+
+        Unreviewed, reverting r264242.
+
+        * bindings/js/CommonVM.cpp:
+        (WebCore::commonVMSlow):
+
 2020-07-20  Adrian Perez de Castro  <[email protected]>
 
         Non unified build fixes, midsummer 2020 edition

Modified: trunk/Source/WebCore/bindings/js/CommonVM.cpp (264634 => 264635)


--- trunk/Source/WebCore/bindings/js/CommonVM.cpp	2020-07-20 23:32:35 UTC (rev 264634)
+++ trunk/Source/WebCore/bindings/js/CommonVM.cpp	2020-07-20 23:36:01 UTC (rev 264635)
@@ -56,14 +56,8 @@
     // Also, initializeMainThread() does nothing on iOS.
     ScriptController::initializeMainThread();
 
-    RunLoop* runLoop = nullptr;
-#if PLATFORM(IOS_FAMILY)
-    if (RunLoop* web = RunLoop::webIfExists())
-        runLoop = web;
-#endif
+    auto& vm = JSC::VM::create(JSC::LargeHeap).leakRef();
 
-    auto& vm = JSC::VM::create(JSC::LargeHeap, runLoop).leakRef();
-
     g_commonVMOrNull = &vm;
 
     vm.heap.acquireAccess(); // At any time, we may do things that affect the GC.
@@ -71,6 +65,7 @@
 #if PLATFORM(IOS_FAMILY)
     if (WebThreadIsEnabled())
         vm.apiLock().makeWebThreadAware();
+    vm.setRunLoop(WebThreadRunLoop());
     vm.heap.machineThreads().addCurrentThread();
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to