Changeset 264413 in webkit


Ignore:
Timestamp:
Jul 15, 2020, 12:20:21 PM (5 years ago)
Author:
mark.lam@apple.com
Message:

Add handling of out of memory handling while adding a worklet module.
https://bugs.webkit.org/show_bug.cgi?id=214354
<rdar://problem/65271931>

Reviewed by Yusuke Suzuki and Keith Miller.

Source/JavaScriptCore:

Add VM::tryCreate() that can fail if we encounter an out of memory issue.
As always, we're taking a best effort approach to handling out of memory errors.
Hence, we will not attempt to exhaustively handle every OOME scenario. This patch
only checks for failure to allocate a BigInt due to Gigacage exhaustion. While it
doesn't handle other allocation errors, it does enable us to add handling of other
cases in the future as needed.

  • runtime/VM.cpp:

(JSC::VM::VM):
(JSC::VM::tryCreate):

  • runtime/VM.h:

Source/WebCore:

Test: fast/css-custom-paint/out-of-memory-while-adding-worklet-module.html

  • bindings/js/JSDOMExceptionHandling.cpp:

(WebCore::createDOMException):

  • dom/ExceptionCode.h:
  • worklets/PaintWorkletGlobalScope.cpp:

(WebCore::PaintWorkletGlobalScope::tryCreate):
(WebCore::PaintWorkletGlobalScope::PaintWorkletGlobalScope):
(WebCore::PaintWorkletGlobalScope::create): Deleted.

  • worklets/PaintWorkletGlobalScope.h:
  • worklets/Worklet.cpp:

(WebCore::Worklet::addModule):

  • worklets/Worklet.h:
  • worklets/Worklet.idl:
  • worklets/WorkletGlobalScope.cpp:

(WebCore::WorkletGlobalScope::WorkletGlobalScope):

  • worklets/WorkletGlobalScope.h:
  • worklets/WorkletScriptController.cpp:

(WebCore::WorkletScriptController::WorkletScriptController):

  • worklets/WorkletScriptController.h:

LayoutTests:

We're skipping the new test on Debug builds because it will always run too slow.
The Release build is sufficient to test this OOME handling.

  • TestExpectations:
  • fast/css-custom-paint/out-of-memory-while-adding-worklet-module-expected.txt: Added.
  • fast/css-custom-paint/out-of-memory-while-adding-worklet-module.html: Added.
  • fast/css-custom-paint/script-tests: Added.
  • fast/css-custom-paint/script-tests/out-of-memory-while-adding-worklet-module.js: Added.

(useAllMemory.try.get Object):
(useAllMemory.try.foo):
(useAllMemory):
(catch):

Location:
trunk
Files:
4 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r264409 r264413  
     12020-07-15  Mark Lam  <mark.lam@apple.com>
     2
     3        Add handling of out of memory handling while adding a worklet module.
     4        https://bugs.webkit.org/show_bug.cgi?id=214354
     5        <rdar://problem/65271931>
     6
     7        Reviewed by Yusuke Suzuki and Keith Miller.
     8
     9        We're skipping the new test on Debug builds because it will always run too slow.
     10        The Release build is sufficient to test this OOME handling.
     11
     12        * TestExpectations:
     13        * fast/css-custom-paint/out-of-memory-while-adding-worklet-module-expected.txt: Added.
     14        * fast/css-custom-paint/out-of-memory-while-adding-worklet-module.html: Added.
     15        * fast/css-custom-paint/script-tests: Added.
     16        * fast/css-custom-paint/script-tests/out-of-memory-while-adding-worklet-module.js: Added.
     17        (useAllMemory.try.get Object):
     18        (useAllMemory.try.foo):
     19        (useAllMemory):
     20        (catch):
     21
    1222020-07-15  Hector Lopez  <hector_i_lopez@apple.com>
    223
  • trunk/LayoutTests/TestExpectations

    r264343 r264413  
    11081108webkit.org/b/136078 fast/borders/border-painting-dotted.html [ ImageOnlyFailure ]
    11091109webkit.org/b/136078 fast/borders/border-painting-double.html [ ImageOnlyFailure ]
     1110
     1111# Skip this because it is too slow on debug builds.
     1112[ Debug ] fast/css-custom-paint/out-of-memory-while-adding-worklet-module.html [ Skip ]
    11101113
    11111114# official flexbox tests
  • trunk/Source/JavaScriptCore/ChangeLog

    r264400 r264413  
     12020-07-15  Mark Lam  <mark.lam@apple.com>
     2
     3        Add handling of out of memory handling while adding a worklet module.
     4        https://bugs.webkit.org/show_bug.cgi?id=214354
     5        <rdar://problem/65271931>
     6
     7        Reviewed by Yusuke Suzuki and Keith Miller.
     8
     9        Add VM::tryCreate() that can fail if we encounter an out of memory issue.
     10        As always, we're taking a best effort approach to handling out of memory errors.
     11        Hence, we will not attempt to exhaustively handle every OOME scenario.  This patch
     12        only checks for failure to allocate a BigInt due to Gigacage exhaustion.  While it
     13        doesn't handle other allocation errors, it does enable us to add handling of other
     14        cases in the future as needed.
     15
     16        * runtime/VM.cpp:
     17        (JSC::VM::VM):
     18        (JSC::VM::tryCreate):
     19        * runtime/VM.h:
     20
    1212020-07-15  Jim Mason  <jmason@ibinx.com>
    222
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r264315 r264413  
    263263static bool vmCreationShouldCrash = false;
    264264
    265 VM::VM(VMType vmType, HeapType heapType, WTF::RunLoop* runLoop)
     265VM::VM(VMType vmType, HeapType heapType, WTF::RunLoop* runLoop, bool* success)
    266266    : m_id(nextID())
    267267    , m_apiLock(adoptRef(new JSLock(this)))
     
    465465    {
    466466        auto* bigInt = JSBigInt::tryCreateFrom(*this, 1);
    467         RELEASE_ASSERT(bigInt);
    468         heapBigIntConstantOne.set(*this, bigInt);
     467        if (bigInt)
     468            heapBigIntConstantOne.set(*this, bigInt);
     469        else {
     470            if (success)
     471                *success = false;
     472            else
     473                RELEASE_ASSERT(bigInt);
     474        }
    469475    }
    470476
     
    673679{
    674680    return adoptRef(*new VM(Default, heapType, runLoop));
     681}
     682
     683RefPtr<VM> VM::tryCreate(HeapType heapType, WTF::RunLoop* runLoop)
     684{
     685    bool success = true;
     686    RefPtr<VM> vm = adoptRef(new VM(Default, heapType, runLoop, &success));
     687    if (!success) {
     688        // Here, we're destructing a partially constructed VM and we know that
     689        // no one else can be using it at the same time. So, acquiring the lock
     690        // is superflous. However, we don't want to change how VMs are destructed.
     691        // Just going through the motion of acquiring the lock here allows us to
     692        // use the standard destruction process.
     693
     694        // VM expects us to be holding the VM lock when destructing it. Acquiring
     695        // the lock also puts the VM in a state (e.g. acquiring heap access) that
     696        // is needed for destruction. The lock will hold the last reference to
     697        // the VM after we nullify the refPtr below. The VM will actually be
     698        // destructed in JSLockHolder's destructor.
     699        JSLockHolder lock(vm.get());
     700        vm = nullptr;
     701    }
     702    return vm;
    675703}
    676704
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r264315 r264413  
    315315
    316316    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);
    317318    static Ref<VM> createContextGroup(HeapType = SmallHeap);
    318319    JS_EXPORT_PRIVATE ~VM();
     
    11021103    friend class LLIntOffsetsExtractor;
    11031104
    1104     VM(VMType, HeapType, WTF::RunLoop* = nullptr);
     1105    VM(VMType, HeapType, WTF::RunLoop* = nullptr, bool* success = nullptr);
    11051106    static VM*& sharedInstanceInternal();
    11061107    void createNativeThunk();
  • trunk/Source/WebCore/ChangeLog

    r264403 r264413  
     12020-07-15  Mark Lam  <mark.lam@apple.com>
     2
     3        Add handling of out of memory handling while adding a worklet module.
     4        https://bugs.webkit.org/show_bug.cgi?id=214354
     5        <rdar://problem/65271931>
     6
     7        Reviewed by Yusuke Suzuki and Keith Miller.
     8
     9        Test: fast/css-custom-paint/out-of-memory-while-adding-worklet-module.html
     10
     11        * bindings/js/JSDOMExceptionHandling.cpp:
     12        (WebCore::createDOMException):
     13        * dom/ExceptionCode.h:
     14        * worklets/PaintWorkletGlobalScope.cpp:
     15        (WebCore::PaintWorkletGlobalScope::tryCreate):
     16        (WebCore::PaintWorkletGlobalScope::PaintWorkletGlobalScope):
     17        (WebCore::PaintWorkletGlobalScope::create): Deleted.
     18        * worklets/PaintWorkletGlobalScope.h:
     19        * worklets/Worklet.cpp:
     20        (WebCore::Worklet::addModule):
     21        * worklets/Worklet.h:
     22        * worklets/Worklet.idl:
     23        * worklets/WorkletGlobalScope.cpp:
     24        (WebCore::WorkletGlobalScope::WorkletGlobalScope):
     25        * worklets/WorkletGlobalScope.h:
     26        * worklets/WorkletScriptController.cpp:
     27        (WebCore::WorkletScriptController::WorkletScriptController):
     28        * worklets/WorkletScriptController.h:
     29
    1302020-07-15  Oriol Brufau  <obrufau@igalia.com>
    231
  • trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp

    r263795 r264413  
    11/*
    22 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    3  *  Copyright (C) 2004-2017 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2004-2020 Apple Inc. All rights reserved.
    44 *  Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
    55 *  Copyright (C) 2013 Michael Pruett <michael@68k.org>
     
    140140    if (ec == StackOverflowError)
    141141        return createStackOverflowError(lexicalGlobalObject);
     142    if (ec == OutOfMemoryError)
     143        return createOutOfMemoryError(lexicalGlobalObject);
    142144
    143145    // FIXME: All callers to createDOMException need to pass in the correct global object.
  • trunk/Source/WebCore/dom/ExceptionCode.h

    r262933 r264413  
    11/*
    2  *  Copyright (C) 2006-2017 Apple Inc. All rights reserved.
     2 *  Copyright (C) 2006-2020 Apple Inc. All rights reserved.
    33 *
    44 *  This library is free software; you can redistribute it and/or
     
    6565    // Non-standard error.
    6666    StackOverflowError,
     67    OutOfMemoryError,
    6768
    6869    // Used to indicate to the bindings that a JS exception was thrown below and it should be propagated.
  • trunk/Source/WebCore/worklets/PaintWorkletGlobalScope.cpp

    r260848 r264413  
    11/*
    2  * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4242WTF_MAKE_ISO_ALLOCATED_IMPL(PaintWorkletGlobalScope);
    4343
    44 Ref<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create(Document& document, ScriptSourceCode&& code)
     44RefPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::tryCreate(Document& document, ScriptSourceCode&& code)
    4545{
    46     return adoptRef(*new PaintWorkletGlobalScope(document, WTFMove(code)));
     46    RefPtr<VM> vm = VM::tryCreate();
     47    if (!vm)
     48        return nullptr;
     49    return adoptRef(*new PaintWorkletGlobalScope(document, vm.releaseNonNull(), WTFMove(code)));
    4750}
    4851
    49 PaintWorkletGlobalScope::PaintWorkletGlobalScope(Document& document, ScriptSourceCode&& code)
    50     : WorkletGlobalScope(document, WTFMove(code))
     52PaintWorkletGlobalScope::PaintWorkletGlobalScope(Document& document, Ref<VM>&& vm, ScriptSourceCode&& code)
     53    : WorkletGlobalScope(document, WTFMove(vm), WTFMove(code))
    5154{
    5255}
  • trunk/Source/WebCore/worklets/PaintWorkletGlobalScope.h

    r254087 r264413  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3535namespace JSC {
    3636class JSObject;
     37class VM;
    3738} // namespace JSC
    3839
     
    4344    WTF_MAKE_ISO_ALLOCATED(PaintWorkletGlobalScope);
    4445public:
    45     static Ref<PaintWorkletGlobalScope> create(Document&, ScriptSourceCode&&);
     46    static RefPtr<PaintWorkletGlobalScope> tryCreate(Document&, ScriptSourceCode&&);
    4647
    4748    ExceptionOr<void> registerPaint(JSC::JSGlobalObject&, const String& name, JSC::Strong<JSC::JSObject> paintConstructor);
     
    7374
    7475private:
    75     PaintWorkletGlobalScope(Document&, ScriptSourceCode&&);
     76    PaintWorkletGlobalScope(Document&, Ref<JSC::VM>&&, ScriptSourceCode&&);
    7677
    7778    ~PaintWorkletGlobalScope()
  • trunk/Source/WebCore/worklets/Worklet.cpp

    r243887 r264413  
    4747}
    4848
    49 void Worklet::addModule(Document& document, const String& moduleURL)
     49ExceptionOr<void> Worklet::addModule(Document& document, const String& moduleURL)
    5050{
    5151    // FIXME: We should download the source from the URL
    5252    // https://bugs.webkit.org/show_bug.cgi?id=191136
    53     auto context = PaintWorkletGlobalScope::create(document, ScriptSourceCode(moduleURL));
     53    auto maybeContext = PaintWorkletGlobalScope::tryCreate(document, ScriptSourceCode(moduleURL));
     54    if (UNLIKELY(!maybeContext))
     55        return Exception { OutOfMemoryError };
     56    auto context = maybeContext.releaseNonNull();
    5457    context->evaluate();
    5558
     
    5760    for (auto& name : context->paintDefinitionMap().keys())
    5861        document.setPaintWorkletGlobalScopeForName(name, makeRef(context.get()));
     62
     63    return { };
    5964}
    6065
  • trunk/Source/WebCore/worklets/Worklet.h

    r260415 r264413  
    2626#pragma once
    2727
     28#include "ExceptionOr.h"
    2829#include "ScriptWrappable.h"
    2930#include <wtf/RefCounted.h>
     
    3940    static Ref<Worklet> create();
    4041   
    41     void addModule(Document&, const String& moduleURL);
     42    ExceptionOr<void> addModule(Document&, const String& moduleURL);
    4243
    4344private:
  • trunk/Source/WebCore/worklets/Worklet.idl

    r237766 r264413  
    11/*
    2 * Copyright (C) 2018 Apple Inc. All rights reserved.
     2* Copyright (C) 2018-2020 Apple Inc. All rights reserved.
    33*
    44* Redistribution and use in source and binary forms, with or without
     
    3030    Global=Worklet,
    3131] interface Worklet {
    32     [CallWith=Document] void addModule(USVString moduleURL/*, optional WorkletOptions options*/);
     32    [CallWith=Document, MayThrowException] void addModule(USVString moduleURL/*, optional WorkletOptions options*/);
    3333};
  • trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp

    r256012 r264413  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2018-2020 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4848WTF_MAKE_ISO_ALLOCATED_IMPL(WorkletGlobalScope);
    4949
    50 WorkletGlobalScope::WorkletGlobalScope(Document& document, ScriptSourceCode&& code)
     50WorkletGlobalScope::WorkletGlobalScope(Document& document, Ref<JSC::VM>&& vm, ScriptSourceCode&& code)
    5151    : m_document(makeWeakPtr(document))
    52     , m_script(makeUnique<WorkletScriptController>(this))
     52    , m_script(makeUnique<WorkletScriptController>(WTFMove(vm), this))
    5353    , m_topOrigin(SecurityOrigin::createUnique())
    5454    , m_code(WTFMove(code))
  • trunk/Source/WebCore/worklets/WorkletGlobalScope.h

    r256012 r264413  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8888
    8989protected:
    90     WorkletGlobalScope(Document&, ScriptSourceCode&&);
     90    WorkletGlobalScope(Document&, Ref<JSC::VM>&&, ScriptSourceCode&&);
    9191    WorkletGlobalScope(const WorkletGlobalScope&) = delete;
    9292    WorkletGlobalScope(WorkletGlobalScope&&) = delete;
  • trunk/Source/WebCore/worklets/WorkletScriptController.cpp

    r251691 r264413  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2018-2020 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4848using namespace JSC;
    4949
    50 WorkletScriptController::WorkletScriptController(WorkletGlobalScope* workletGlobalScope)
    51     : m_vm(VM::create())
     50WorkletScriptController::WorkletScriptController(Ref<VM>&& vm, WorkletGlobalScope* workletGlobalScope)
     51    : m_vm(WTFMove(vm))
    5252    , m_workletGlobalScope(workletGlobalScope)
    5353    , m_workletGlobalScopeWrapper(*m_vm)
  • trunk/Source/WebCore/worklets/WorkletScriptController.h

    r237766 r264413  
    5050    WTF_MAKE_NONCOPYABLE(WorkletScriptController); WTF_MAKE_FAST_ALLOCATED;
    5151public:
    52     WorkletScriptController(WorkletGlobalScope*);
     52    WorkletScriptController(Ref<VM>&&, WorkletGlobalScope*);
    5353    ~WorkletScriptController();
    5454
Note: See TracChangeset for help on using the changeset viewer.