⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 264635 in webkit


Ignore:
Timestamp:
Jul 20, 2020, 4:36:01 PM (6 years ago)
Author:
ggaren@apple.com
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/JavaScriptCore:

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

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r264633 r264635  
     12020-07-20  Geoffrey Garen  <ggaren@apple.com>
     2
     3        REGRESSION (r264242): [ macOS ] imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate.any.html is a flaky crash
     4        https://bugs.webkit.org/show_bug.cgi?id=214572
     5
     6        Unreviewed, reverting r264242.
     7
     8        * runtime/JSRunLoopTimer.cpp:
     9        (JSC::epochTime):
     10        (JSC::JSRunLoopTimer::Manager::timerDidFireCallback):
     11        (JSC::JSRunLoopTimer::Manager::PerVMData::setRunLoop):
     12        (JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData):
     13        (JSC::JSRunLoopTimer::Manager::PerVMData::~PerVMData):
     14        (JSC::JSRunLoopTimer::Manager::timerDidFire):
     15        (JSC::JSRunLoopTimer::Manager::registerVM):
     16        (JSC::JSRunLoopTimer::Manager::scheduleTimer):
     17        (JSC::JSRunLoopTimer::Manager::cancelTimer):
     18        (JSC::JSRunLoopTimer::Manager::didChangeRunLoop):
     19        * runtime/JSRunLoopTimer.h:
     20        (JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData):
     21        * runtime/PromiseTimer.cpp:
     22        (JSC::PromiseTimer::doWork):
     23        (JSC::PromiseTimer::runRunLoop):
     24        * runtime/VM.cpp:
     25        (JSC::VM::VM):
     26        (JSC::VM::create):
     27        (JSC::VM::tryCreate):
     28        (JSC::VM::setRunLoop):
     29        * runtime/VM.h:
     30        (JSC::VM::runLoop const):
     31
    1322020-07-20  Ross Kirsling  <ross.kirsling@sony.com>
    233
  • trunk/Source/JavaScriptCore/runtime/DeferredWorkTimer.cpp

    r264617 r264635  
    8282    }
    8383
    84     if (m_pendingTickets.isEmpty() && m_shouldStopRunLoopWhenAllTicketsFinish)
     84    if (m_pendingTickets.isEmpty() && m_shouldStopRunLoopWhenAllTicketsFinish) {
     85#if USE(CF)
     86        CFRunLoopStop(vm.runLoop());
     87#else
    8588        RunLoop::current().stop();
     89#endif
     90    }
    8691
    8792    m_taskLock.unlock();
    … …  
    9196{
    9297    ASSERT(!m_apiLock->vm()->currentThreadIsHoldingAPILock());
    93     ASSERT(&RunLoop::current() == &m_apiLock->vm()->runLoop());
     98#if USE(CF)
     99    ASSERT(CFRunLoopGetCurrent() == m_apiLock->vm()->runLoop());
     100#endif
    94101    m_shouldStopRunLoopWhenAllTicketsFinish = true;
    95     if (m_pendingTickets.size())
     102    if (m_pendingTickets.size()) {
     103#if USE(CF)
     104        CFRunLoopRun();
     105#else
    96106        RunLoop::run();
     107#endif
     108    }
    97109}
    98110
  • trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp

    r264315 r264635  
    4141static inline JSRunLoopTimer::Manager::EpochTime epochTime(Seconds delay)
    4242{
     43#if USE(CF)
     44    return Seconds { CFAbsoluteTimeGetCurrent() + delay.value() };
     45#else
    4346    return MonotonicTime::now().secondsSinceEpoch() + delay;
    44 }
    45 
    46 JSRunLoopTimer::Manager::PerVMData::PerVMData(Manager& manager, RunLoop& runLoop)
    47     : runLoop(runLoop)
    48     , timer(makeUnique<RunLoop::Timer<Manager>>(runLoop, &manager, &JSRunLoopTimer::Manager::timerDidFireCallback))
     47#endif
     48}
     49
     50#if USE(CF)
     51void JSRunLoopTimer::Manager::timerDidFireCallback(CFRunLoopTimerRef, void* contextPtr)
     52{
     53    static_cast<JSRunLoopTimer::Manager*>(contextPtr)->timerDidFire();
     54}
     55
     56void JSRunLoopTimer::Manager::PerVMData::setRunLoop(Manager* manager, CFRunLoopRef newRunLoop)
     57{
     58    if (runLoop) {
     59        CFRunLoopRemoveTimer(runLoop.get(), timer.get(), kCFRunLoopCommonModes);
     60        CFRunLoopTimerInvalidate(timer.get());
     61        runLoop.clear();
     62        timer.clear();
     63    }
     64
     65    if (newRunLoop) {
     66        runLoop = newRunLoop;
     67        memset(&context, 0, sizeof(CFRunLoopTimerContext));
     68        RELEASE_ASSERT(manager);
     69        context.info = manager;
     70        timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade.seconds(), CFAbsoluteTimeGetCurrent() + s_decade.seconds(), 0, 0, JSRunLoopTimer::Manager::timerDidFireCallback, &context));
     71        CFRunLoopAddTimer(runLoop.get(), timer.get(), kCFRunLoopCommonModes);
     72
     73        EpochTime scheduleTime = epochTime(s_decade);
     74        for (auto& pair : timers)
     75            scheduleTime = std::min(pair.second, scheduleTime);
     76        CFRunLoopTimerSetNextFireDate(timer.get(), scheduleTime.value());
     77    }
     78}
     79#else
     80JSRunLoopTimer::Manager::PerVMData::PerVMData(Manager& manager)
     81    : runLoop(&RunLoop::current())
     82    , timer(makeUnique<RunLoop::Timer<Manager>>(*runLoop, &manager, &JSRunLoopTimer::Manager::timerDidFireCallback))
    4983{
    5084#if USE(GLIB_EVENT_LOOP)
    … …  
    5892    timerDidFire();
    5993}
     94#endif
    6095
    6196JSRunLoopTimer::Manager::PerVMData::~PerVMData()
    6297{
     98#if USE(CF)
     99    setRunLoop(nullptr, nullptr);
     100#endif
    63101}
    64102
    … …  
    69107    {
    70108        auto locker = holdLock(m_lock);
     109#if USE(CF)
     110        CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent();
     111#else
    71112        RunLoop* currentRunLoop = &RunLoop::current();
     113#endif
    72114        EpochTime nowEpochTime = epochTime(0_s);
    73115        for (auto& entry : m_mapping) {
    74116            PerVMData& data = *entry.value;
    75             if (data.runLoop.ptr() != currentRunLoop)
     117#if USE(CF)
     118            if (data.runLoop.get() != currentRunLoop)
    76119                continue;
     120#else
     121            if (data.runLoop != currentRunLoop)
     122                continue;
     123#endif
    77124           
    78125            EpochTime scheduleTime = epochTime(s_decade);
    … …  
    94141            }
    95142
     143#if USE(CF)
     144            CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
     145#else
    96146            data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
     147#endif
    97148        }
    98149    }
    … …  
    114165void JSRunLoopTimer::Manager::registerVM(VM& vm)
    115166{
    116     auto data = makeUnique<PerVMData>(*this, vm.runLoop());
     167    auto data = makeUnique<PerVMData>(*this);
     168#if USE(CF)
     169    data->setRunLoop(this, vm.runLoop());
     170#endif
    117171
    118172    auto locker = holdLock(m_lock);
    … …  
    152206        data.timers.append({ timer, fireEpochTime });
    153207
     208#if USE(CF)
     209    CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
     210#else
    154211    data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
     212#endif
    155213}
    156214
    … …  
    183241    }
    184242
     243#if USE(CF)
     244    CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
     245#else
    185246    data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
     247#endif
    186248}
    187249
    … …  
    202264    return WTF::nullopt;
    203265}
     266
     267#if USE(CF)
     268void JSRunLoopTimer::Manager::didChangeRunLoop(VM& vm, CFRunLoopRef newRunLoop)
     269{
     270    auto locker = holdLock(m_lock);
     271    auto iter = m_mapping.find({ vm.apiLock() });
     272    RELEASE_ASSERT(iter != m_mapping.end());
     273
     274    PerVMData& data = *iter->value;
     275    data.setRunLoop(this, newRunLoop);
     276}
     277#endif
    204278
    205279void JSRunLoopTimer::timerDidFire()
  • trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.h

    r264315 r264635  
    3434#include <wtf/ThreadSafeRefCounted.h>
    3535
     36#if USE(CF)
     37#include <CoreFoundation/CoreFoundation.h>
     38#endif
     39
    3640namespace JSC {
    3741
    … …  
    4751        WTF_MAKE_FAST_ALLOCATED;
    4852        WTF_MAKE_NONCOPYABLE(Manager);
     53#if USE(CF)
     54        static void timerDidFireCallback(CFRunLoopTimerRef, void*);
     55#else
    4956        void timerDidFireCallback();
    50 
     57#endif
    5158        Manager() = default;
    5259
    … …  
    6471        Optional<Seconds> timeUntilFire(JSRunLoopTimer&);
    6572
     73#if USE(CF)
     74        void didChangeRunLoop(VM&, CFRunLoopRef newRunLoop);
     75#endif
     76
    6677    private:
    6778        Lock m_lock;
    … …  
    7182            WTF_MAKE_NONCOPYABLE(PerVMData);
    7283        public:
    73             PerVMData(Manager&, WTF::RunLoop&);
     84#if USE(CF)
     85            PerVMData(Manager&) { }
     86#else
     87            PerVMData(Manager&);
     88#endif
    7489            ~PerVMData();
    7590
    76             Ref<WTF::RunLoop> runLoop;
     91#if USE(CF)
     92            void setRunLoop(Manager*, CFRunLoopRef);
     93            RetainPtr<CFRunLoopTimerRef> timer;
     94            RetainPtr<CFRunLoopRef> runLoop;
     95            CFRunLoopTimerContext context;
     96#else
     97            RunLoop* runLoop;
    7798            std::unique_ptr<RunLoop::Timer<Manager>> timer;
     99#endif
    78100            Vector<std::pair<Ref<JSRunLoopTimer>, EpochTime>> timers;
    79101        };
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r264617 r264635  
    264264static bool vmCreationShouldCrash = false;
    265265
    266 VM::VM(VMType vmType, HeapType heapType, WTF::RunLoop* runLoop, bool* success)
     266VM::VM(VMType vmType, HeapType heapType, bool* success)
    267267    : m_id(nextID())
    268268    , m_apiLock(adoptRef(new JSLock(this)))
    269     , m_runLoop(runLoop ? *runLoop : WTF::RunLoop::current())
     269#if USE(CF)
     270    , m_runLoop(CFRunLoopGetCurrent())
     271#endif // USE(CF)
    270272    , m_random(Options::seedOfVMRandomForFuzzer() ? Options::seedOfVMRandomForFuzzer() : cryptographicallyRandomNumber())
    271273    , m_integrityRandom(*this)
    … …  
    678680}
    679681
    680 Ref<VM> VM::create(HeapType heapType, WTF::RunLoop* runLoop)
    681 {
    682     return adoptRef(*new VM(Default, heapType, runLoop));
    683 }
    684 
    685 RefPtr<VM> VM::tryCreate(HeapType heapType, WTF::RunLoop* runLoop)
     682Ref<VM> VM::create(HeapType heapType)
     683{
     684    return adoptRef(*new VM(Default, heapType));
     685}
     686
     687RefPtr<VM> VM::tryCreate(HeapType heapType)
    686688{
    687689    bool success = true;
    688     RefPtr<VM> vm = adoptRef(new VM(Default, heapType, runLoop, &success));
     690    RefPtr<VM> vm = adoptRef(new VM(Default, heapType, &success));
    689691    if (!success) {
    690692        // Here, we're destructing a partially constructed VM and we know that
    … …  
    13831385}
    13841386#endif
     1387
     1388#if USE(CF)
     1389void VM::setRunLoop(CFRunLoopRef runLoop)
     1390{
     1391    ASSERT(runLoop);
     1392    m_runLoop = runLoop;
     1393    JSRunLoopTimer::Manager::shared().didChangeRunLoop(*this, runLoop);
     1394}
     1395#endif // USE(CF)
    13851396
    13861397ScratchBuffer* VM::scratchBufferForSize(size_t size)
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r264617 r264635  
    9595
    9696namespace WTF {
    97 class RunLoop;
    9897class SimpleStats;
    9998} // namespace WTF
    … …  
    314313    JS_EXPORT_PRIVATE static VM& sharedInstance();
    315314
    316     JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap, WTF::RunLoop* = nullptr);
    317     JS_EXPORT_PRIVATE static RefPtr<VM> tryCreate(HeapType = SmallHeap, WTF::RunLoop* = nullptr);
     315    JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap);
     316    JS_EXPORT_PRIVATE static RefPtr<VM> tryCreate(HeapType = SmallHeap);
    318317    static Ref<VM> createContextGroup(HeapType = SmallHeap);
    319318    JS_EXPORT_PRIVATE ~VM();
    … …  
    356355    unsigned m_id;
    357356    RefPtr<JSLock> m_apiLock;
    358     Ref<WTF::RunLoop> m_runLoop;
     357#if USE(CF)
     358    // These need to be initialized before heap below.
     359    RetainPtr<CFRunLoopRef> m_runLoop;
     360#endif
    359361
    360362    WeakRandom m_random;
    … …  
    10811083#endif
    10821084
    1083     WTF::RunLoop& runLoop() const { return m_runLoop; }
     1085#if USE(CF)
     1086    CFRunLoopRef runLoop() const { return m_runLoop.get(); }
     1087    JS_EXPORT_PRIVATE void setRunLoop(CFRunLoopRef);
     1088#endif // USE(CF)
    10841089
    10851090    static void setCrashOnVMCreation(bool);
    … …  
    11051110    friend class LLIntOffsetsExtractor;
    11061111
    1107     VM(VMType, HeapType, WTF::RunLoop* = nullptr, bool* success = nullptr);
     1112    VM(VMType, HeapType, bool* success = nullptr);
    11081113    static VM*& sharedInstanceInternal();
    11091114    void createNativeThunk();
  • trunk/Source/WebCore/ChangeLog

    r264630 r264635  
     12020-07-20  Geoffrey Garen  <ggaren@apple.com>
     2
     3        REGRESSION (r264242): [ macOS ] imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate.any.html is a flaky crash
     4        https://bugs.webkit.org/show_bug.cgi?id=214572
     5
     6        Unreviewed, reverting r264242.
     7
     8        * bindings/js/CommonVM.cpp:
     9        (WebCore::commonVMSlow):
     10
    1112020-07-20  Adrian Perez de Castro  <aperez@igalia.com>
    212
  • trunk/Source/WebCore/bindings/js/CommonVM.cpp

    r264333 r264635  
    5757    ScriptController::initializeMainThread();
    5858
    59     RunLoop* runLoop = nullptr;
    60 #if PLATFORM(IOS_FAMILY)
    61     if (RunLoop* web = RunLoop::webIfExists())
    62         runLoop = web;
    63 #endif
    64 
    65     auto& vm = JSC::VM::create(JSC::LargeHeap, runLoop).leakRef();
     59    auto& vm = JSC::VM::create(JSC::LargeHeap).leakRef();
    6660
    6761    g_commonVMOrNull = &vm;
    … …  
    7266    if (WebThreadIsEnabled())
    7367        vm.apiLock().makeWebThreadAware();
     68    vm.setRunLoop(WebThreadRunLoop());
    7469    vm.heap.machineThreads().addCurrentThread();
    7570#endif
Note: See TracChangeset for help on using the changeset viewer.