Changeset 241741 in webkit


Ignore:
Timestamp:
Feb 18, 2019 2:58:46 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Add LazyClassStructure::getInitializedOnMainThread
https://bugs.webkit.org/show_bug.cgi?id=194784
<rdar://problem/48154820>

Reviewed by Mark Lam.

JSTests:

  • stress/lazy-initialization-done-a-priori-if-jit-enabled.js: Added.

(getProperties):
(getRandomProperty):
(i.catch):

Source/JavaScriptCore:

LazyClassStructure::get and LazyProperty::get functions do not allow compiler threads to call them. But for booleanPrototype, numberPrototype and symbolPrototype cases,
we would like to call them from compiler threads. We eagerly initialize them if VM::canUseJIT() is true, so that compiler threads can safely call LazyClassStructure::get
and LazyProperty::get for booleanPrototype, numberPrototype and symbolPrototype. But still assertion hits because the assertion requires that these functions need to be
called in non compiler threads. Calling getConcurrently() is not possible since symbolPrototype() function is called from both the main thread and compiler threads,
and we would like to lazily initialize SymbolPrototype object if it is called from the main thread, which can happen with non-JIT configuration.

This patch adds getInitializedOnMainThread(). Compiler threads can call it only when we know that the value is already initialized on the main thread. The main thread
can call it at anytime and this function lazily initializes the value. This is useful to make some of prototypes lazy with non-JIT configuration: With non-JIT configuration,
this function is always called from the main thread and it initializes the value lazily. Non-JIT configuration does not care about compiler threads since they do not exist.
With JIT configuration, we eagerly initialize them in JSGlobalObject::init so that getInitializedOnMainThread() always succeeds.

Basically, getInitializedOnMainThread() is get with different assertion location: While get always crashes if it is called from compiler threads, getInitializedOnMainThread()
crashes only when actual initialization happens on compiler threads. We do not merge them since get is still useful to find accidental initialization from compiler threads.

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::booleanPrototype const):
(JSC::JSGlobalObject::numberPrototype const):
(JSC::JSGlobalObject::symbolPrototype const):

  • runtime/LazyClassStructure.h:

(JSC::LazyClassStructure::getInitializedOnMainThread const):
(JSC::LazyClassStructure::prototypeInitializedOnMainThread const):
(JSC::LazyClassStructure::constructorInitializedOnMainThread const):

  • runtime/LazyProperty.h:

(JSC::LazyProperty::get const):
(JSC::LazyProperty::getInitializedOnMainThread const):

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r241662 r241741  
     12019-02-18  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Add LazyClassStructure::getInitializedOnMainThread
     4        https://bugs.webkit.org/show_bug.cgi?id=194784
     5        <rdar://problem/48154820>
     6
     7        Reviewed by Mark Lam.
     8
     9        * stress/lazy-initialization-done-a-priori-if-jit-enabled.js: Added.
     10        (getProperties):
     11        (getRandomProperty):
     12        (i.catch):
     13
    1142019-02-18  Dominik Infuehr  <dinfuehr@igalia.com>
    215
  • trunk/Source/JavaScriptCore/ChangeLog

    r241739 r241741  
     12019-02-18  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Add LazyClassStructure::getInitializedOnMainThread
     4        https://bugs.webkit.org/show_bug.cgi?id=194784
     5        <rdar://problem/48154820>
     6
     7        Reviewed by Mark Lam.
     8
     9        LazyClassStructure::get and LazyProperty::get functions do not allow compiler threads to call them. But for booleanPrototype, numberPrototype and symbolPrototype cases,
     10        we would like to call them from compiler threads. We eagerly initialize them if VM::canUseJIT() is true, so that compiler threads can safely call LazyClassStructure::get
     11        and LazyProperty::get for booleanPrototype, numberPrototype and symbolPrototype. But still assertion hits because the assertion requires that these functions need to be
     12        called in non compiler threads. Calling `getConcurrently()` is not possible since symbolPrototype() function is called from both the main thread and compiler threads,
     13        and we would like to lazily initialize SymbolPrototype object if it is called from the main thread, which can happen with non-JIT configuration.
     14
     15        This patch adds `getInitializedOnMainThread()`. Compiler threads can call it only when we know that the value is already initialized on the main thread. The main thread
     16        can call it at anytime and this function lazily initializes the value. This is useful to make some of prototypes lazy with non-JIT configuration: With non-JIT configuration,
     17        this function is always called from the main thread and it initializes the value lazily. Non-JIT configuration does not care about compiler threads since they do not exist.
     18        With JIT configuration, we eagerly initialize them in JSGlobalObject::init so that `getInitializedOnMainThread()` always succeeds.
     19
     20        Basically, `getInitializedOnMainThread()` is `get` with different assertion location: While `get` always crashes if it is called from compiler threads, `getInitializedOnMainThread()`
     21        crashes only when actual initialization happens on compiler threads. We do not merge them since `get` is still useful to find accidental initialization from compiler threads.
     22
     23        * runtime/JSGlobalObject.h:
     24        (JSC::JSGlobalObject::booleanPrototype const):
     25        (JSC::JSGlobalObject::numberPrototype const):
     26        (JSC::JSGlobalObject::symbolPrototype const):
     27        * runtime/LazyClassStructure.h:
     28        (JSC::LazyClassStructure::getInitializedOnMainThread const):
     29        (JSC::LazyClassStructure::prototypeInitializedOnMainThread const):
     30        (JSC::LazyClassStructure::constructorInitializedOnMainThread const):
     31        * runtime/LazyProperty.h:
     32        (JSC::LazyProperty::get const):
     33        (JSC::LazyProperty::getInitializedOnMainThread const):
     34
    1352019-02-18  Joseph Pecoraro  <pecoraro@apple.com>
    236
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r241637 r241741  
    623623    FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
    624624    ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
    625     JSObject* booleanPrototype() const { return m_booleanObjectStructure.prototype(this); }
     625    JSObject* booleanPrototype() const { return m_booleanObjectStructure.prototypeInitializedOnMainThread(this); }
    626626    StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
    627     JSObject* numberPrototype() const { return m_numberObjectStructure.prototype(this); }
     627    JSObject* numberPrototype() const { return m_numberObjectStructure.prototypeInitializedOnMainThread(this); }
    628628    BigIntPrototype* bigIntPrototype() const { return m_bigIntPrototype.get(); }
    629629    JSObject* datePrototype() const { return m_dateStructure.prototype(this); }
    630     JSObject* symbolPrototype() const { return m_symbolObjectStructure.prototype(this); }
     630    JSObject* symbolPrototype() const { return m_symbolObjectStructure.prototypeInitializedOnMainThread(this); }
    631631    RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
    632632    ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
  • trunk/Source/JavaScriptCore/runtime/LazyClassStructure.h

    r222827 r241741  
    106106        return m_constructor.get();
    107107    }
     108
     109    // Call this "InitializedOnMainThread" function if we would like to (1) get a value from a compiler thread which must be initialized on the main thread and (2) initialize a value if we are on the main thread.
     110    Structure* getInitializedOnMainThread(const JSGlobalObject* global) const
     111    {
     112        return m_structure.getInitializedOnMainThread(global);
     113    }
     114
     115    JSObject* prototypeInitializedOnMainThread(const JSGlobalObject* global) const
     116    {
     117        return getInitializedOnMainThread(global)->storedPrototypeObject();
     118    }
     119
     120    JSObject* constructorInitializedOnMainThread(const JSGlobalObject* global) const
     121    {
     122        m_structure.getInitializedOnMainThread(global);
     123        return m_constructor.get();
     124    }
    108125   
    109126    void visit(SlotVisitor&);
  • trunk/Source/JavaScriptCore/runtime/LazyProperty.h

    r206525 r241741  
    8080    {
    8181        ASSERT(!isCompilationThread());
    82         if (UNLIKELY(m_pointer & lazyTag)) {
    83             FuncType func = *bitwise_cast<FuncType*>(m_pointer & ~(lazyTag | initializingTag));
    84             return func(Initializer(const_cast<OwnerType*>(owner), *const_cast<LazyProperty*>(this)));
    85         }
    86         return bitwise_cast<ElementType*>(m_pointer);
     82        return getInitializedOnMainThread(owner);
    8783    }
    8884   
     
    9389            return nullptr;
    9490        return bitwise_cast<ElementType*>(pointer);
     91    }
     92
     93    ElementType* getInitializedOnMainThread(const OwnerType* owner) const
     94    {
     95        if (UNLIKELY(m_pointer & lazyTag)) {
     96            ASSERT(!isCompilationThread());
     97            FuncType func = *bitwise_cast<FuncType*>(m_pointer & ~(lazyTag | initializingTag));
     98            return func(Initializer(const_cast<OwnerType*>(owner), *const_cast<LazyProperty*>(this)));
     99        }
     100        return bitwise_cast<ElementType*>(m_pointer);
    95101    }
    96102   
Note: See TracChangeset for help on using the changeset viewer.