Changeset 266223 in webkit for trunk/Source/JavaScriptCore


Ignore:
Timestamp:
Aug 26, 2020, 10:27:16 PM (5 years ago)
Author:
Alexey Shvayka
Message:

Use jsTypeofIsObject() in DFG AI and operationTypeOfIsObject()
https://bugs.webkit.org/show_bug.cgi?id=144457

Reviewed by Saam Barati.

Source/JavaScriptCore:

This patch refactors jsTypeofIsObject(), leveraging fast path of isCallable(),
moves it to the header, and utilizes it in operationTypeOfIsObject() & DFG AI
(minding concurrency) to eliminate code duplication.

Also, removes orphaned slow_path_is_object declaration.

No behavior change, typeof microbenchmarks are neutral.

  • dfg/DFGAbstractInterpreterInlines.h:

(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):

  • dfg/DFGOperations.cpp:
  • runtime/CommonSlowPaths.h:
  • runtime/Operations.cpp:

(JSC::jsTypeofIsObject): Deleted.

  • runtime/Operations.h:

(JSC::jsTypeofIsObjectWithConcurrency):
(JSC::jsTypeofIsObject):

Source/WTF:

  • wtf/TriState.h:

(WTF::invert):

Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r266215 r266223  
     12020-08-26  Alexey Shvayka  <[email protected]>
     2
     3        Use jsTypeofIsObject() in DFG AI and operationTypeOfIsObject()
     4        https://bugs.webkit.org/show_bug.cgi?id=144457
     5
     6        Reviewed by Saam Barati.
     7
     8        This patch refactors jsTypeofIsObject(), leveraging fast path of isCallable(),
     9        moves it to the header, and utilizes it in operationTypeOfIsObject() & DFG AI
     10        (minding concurrency) to eliminate code duplication.
     11
     12        Also, removes orphaned slow_path_is_object declaration.
     13
     14        No behavior change, `typeof` microbenchmarks are neutral.
     15
     16        * dfg/DFGAbstractInterpreterInlines.h:
     17        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
     18        * dfg/DFGOperations.cpp:
     19        * runtime/CommonSlowPaths.h:
     20        * runtime/Operations.cpp:
     21        (JSC::jsTypeofIsObject): Deleted.
     22        * runtime/Operations.h:
     23        (JSC::jsTypeofIsObjectWithConcurrency):
     24        (JSC::jsTypeofIsObject):
     25
    1262020-08-26  Alexey Shvayka  <[email protected]>
    227
  • trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h

    r266107 r266223  
    14771477                    : child.value().isUndefined()));
    14781478                break;
    1479             case TypeOfIsObject:
    1480                 if (child.value().isObject()) {
    1481                     JSObject* object = asObject(child.value());
    1482                     if (object->type() == JSFunctionType)
    1483                         setConstant(node, jsBoolean(false));
    1484                     else if (!(object->inlineTypeFlags() & OverridesGetCallData))
    1485                         setConstant(node, jsBoolean(!child.value().asCell()->structure(m_vm)->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))));
    1486                     else {
    1487                         // FIXME: This could just call getCallData.
    1488                         // https://bugs.webkit.org/show_bug.cgi?id=144457
    1489                         constantWasSet = false;
    1490                     }
    1491                 } else
    1492                     setConstant(node, jsBoolean(child.value().isNull()));
    1493                 break;
     1479            case TypeOfIsObject: {
     1480                TriState result = jsTypeofIsObjectWithConcurrency<Concurrency::ConcurrentThread>(m_codeBlock->globalObjectFor(node->origin.semantic), child.value());
     1481                if (result != TriState::Indeterminate)
     1482                    setConstant(node, jsBoolean(result == TriState::True));
     1483                else
     1484                    constantWasSet = false;
     1485                break;
     1486            }
    14941487            case TypeOfIsFunction: {
    14951488                TriState result = jsTypeofIsFunctionWithConcurrency<Concurrency::ConcurrentThread>(m_codeBlock->globalObjectFor(node->origin.semantic), child.value());
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r266019 r266223  
    21332133    ASSERT(jsDynamicCast<JSObject*>(vm, object));
    21342134   
    2135     if (object->structure(vm)->masqueradesAsUndefined(globalObject))
    2136         return false;
    2137     if (object->isCallable(vm))
    2138         return false;
    2139     return true;
     2135    return jsTypeofIsObject(globalObject, object);
    21402136}
    21412137
  • trunk/Source/JavaScriptCore/runtime/CommonSlowPaths.h

    r266019 r266223  
    254254SLOW_PATH_HIDDEN_DECL(slow_path_typeof_is_object);
    255255SLOW_PATH_HIDDEN_DECL(slow_path_typeof_is_function);
    256 SLOW_PATH_HIDDEN_DECL(slow_path_is_object);
    257256SLOW_PATH_HIDDEN_DECL(slow_path_is_callable);
    258257SLOW_PATH_HIDDEN_DECL(slow_path_is_constructor);
  • trunk/Source/JavaScriptCore/runtime/Operations.cpp

    r266107 r266223  
    114114}
    115115
    116 bool jsTypeofIsObject(JSGlobalObject* globalObject, JSValue v)
    117 {
    118     VM& vm = globalObject->vm();
    119     if (!v.isCell())
    120         return v.isNull();
    121 
    122     JSType type = v.asCell()->type();
    123     if (type == StringType || type == SymbolType || type == HeapBigIntType)
    124         return false;
    125     if (type >= ObjectType) {
    126         if (asObject(v)->structure(vm)->masqueradesAsUndefined(globalObject))
    127             return false;
    128         JSObject* object = asObject(v);
    129         if (object->isCallable(vm))
    130             return false;
    131     }
    132     return true;
    133 }
    134 
    135116size_t normalizePrototypeChain(JSGlobalObject* globalObject, JSCell* base, bool& sawPolyProto)
    136117{
  • trunk/Source/JavaScriptCore/runtime/Operations.h

    r266107 r266223  
    3333NEVER_INLINE JSValue jsAddSlowCase(JSGlobalObject*, JSValue, JSValue);
    3434JSString* jsTypeStringForValueWithConcurrency(VM&, JSGlobalObject*, JSValue, Concurrency);
    35 bool jsTypeofIsObject(JSGlobalObject*, JSValue);
    3635size_t normalizePrototypeChain(JSGlobalObject*, JSCell*, bool& sawPolyProto);
     36
     37template<Concurrency concurrency>
     38ALWAYS_INLINE TriState jsTypeofIsObjectWithConcurrency(JSGlobalObject* globalObject, JSValue value)
     39{
     40    VM& vm = globalObject->vm();
     41    if (!value.isObject())
     42        return triState(value.isNull());
     43    JSObject* object = asObject(value);
     44    if (object->structure(vm)->masqueradesAsUndefined(globalObject))
     45        return TriState::False;
     46    return invert(object->isCallableWithConcurrency<concurrency>(vm));
     47}
    3748
    3849template<Concurrency concurrency>
     
    5162{
    5263    return jsTypeStringForValueWithConcurrency(getVM(globalObject), globalObject, value, Concurrency::MainThread);
     64}
     65
     66ALWAYS_INLINE bool jsTypeofIsObject(JSGlobalObject* globalObject, JSValue value)
     67{
     68    auto result = jsTypeofIsObjectWithConcurrency<Concurrency::MainThread>(globalObject, value);
     69    ASSERT(result != TriState::Indeterminate);
     70    return result == TriState::True;
    5371}
    5472
Note: See TracChangeset for help on using the changeset viewer.