Ignore:
Timestamp:
May 2, 2015, 5:15:27 PM (10 years ago)
Author:
[email protected]
Message:

TypeOf should be fast
https://bugs.webkit.org/show_bug.cgi?id=144396

Reviewed by Geoffrey Garen.

Adds comprehensive support for fast typeof to the optimizing JITs. Calls into the runtime
are only used for very exotic objects - they must have either the MasqueradesAsUndefined or
TypeOfShouldCallGetCallData type flags set. All other cases are handled inline.

This means optimizing IsObjectOrNull, IsFunction, and TypeOf - all node types that used to
rely heavily on C++ calls to fulfill their function.

Because TypeOf is now so fast, we no longer need to do any speculations on this node.

In the FTL, we take this further by querying AI for each branch in the TypeOf decision tree.
This means that if the TypeOf is dominated by any type checks, we will automatically prune
out cases that are redundant.

This patch anticipates the addition of SwitchTypeOf or something like that. So, the TypeOf
code generation is designed to be reusable.

This is a speed-up on most typeof benchmarks. But, it is a slow-down on benchmarks that take
the exotic call trap hook. That hook is now in a deeper slow path than before.

(JSC::DFG::clobberize): TypeOf was pure all along, but we failed to realize this.

  • dfg/DFGFixupPhase.cpp:

(JSC::DFG::FixupPhase::fixupNode):

  • dfg/DFGHeapLocation.cpp:

(WTF::printInternal):

  • dfg/DFGHeapLocation.h:
  • dfg/DFGOperations.cpp:
  • dfg/DFGOperations.h:
  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileIsObjectOrNull):
(JSC::DFG::SpeculativeJIT::compileIsFunction):
(JSC::DFG::SpeculativeJIT::compileTypeOf):

  • dfg/DFGSpeculativeJIT.h:

(JSC::DFG::SpeculativeJIT::blessedBooleanResult):
(JSC::DFG::SpeculativeJIT::callOperation):

  • dfg/DFGSpeculativeJIT32_64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • ftl/FTLCapabilities.cpp:

(JSC::FTL::canCompile):

  • ftl/FTLIntrinsicRepository.h:
  • ftl/FTLLowerDFGToLLVM.cpp:

(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::compileIsObjectOrNull):
(JSC::FTL::LowerDFGToLLVM::compileIsFunction):
(JSC::FTL::LowerDFGToLLVM::compileTypeOf):
(JSC::FTL::LowerDFGToLLVM::buildTypeOf): Reusable TypeOf building for the FTL.
(JSC::FTL::LowerDFGToLLVM::isExoticForTypeof):

  • ftl/FTLSwitchCase.h:

(JSC::FTL::SwitchCase::SwitchCase):

  • jit/AssemblyHelpers.h:

(JSC::AssemblyHelpers::branchIfNotEqual):
(JSC::AssemblyHelpers::branchIfEqual):
(JSC::AssemblyHelpers::branchIfNumber):
(JSC::AssemblyHelpers::branchIfNotNumber):
(JSC::AssemblyHelpers::branchIfBoolean):
(JSC::AssemblyHelpers::branchIfNotBoolean):
(JSC::AssemblyHelpers::boxBooleanPayload):
(JSC::AssemblyHelpers::boxBoolean):
(JSC::AssemblyHelpers::emitTypeOf): Reusable TypeOf building for assembly JITs.

  • jit/JITOperations.h:
  • runtime/SmallStrings.h:

(JSC::SmallStrings::typeString):

  • runtime/TypeofType.cpp: Added.

(WTF::printInternal):

  • runtime/TypeofType.h: Added.
  • tests/stress/type-of-functions-and-objects.js: Modified this test to give more comprehensive feedback.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/SmallStrings.h

    r179429 r183724  
    11/*
    2  * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008, 2009, 2015 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#define SmallStrings_h
    2828
     29#include "TypeofType.h"
    2930#include "WriteBarrier.h"
    3031#include <wtf/Noncopyable.h>
     
    8687    JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ACCESSOR_DEFINITION)
    8788#undef JSC_COMMON_STRINGS_ACCESSOR_DEFINITION
     89   
     90    JSString* typeString(TypeofType type) const
     91    {
     92        switch (type) {
     93        case TypeofType::Undefined:
     94            return undefinedString();
     95        case TypeofType::Boolean:
     96            return booleanString();
     97        case TypeofType::Number:
     98            return numberString();
     99        case TypeofType::String:
     100            return stringString();
     101        case TypeofType::Symbol:
     102            return symbolString();
     103        case TypeofType::Object:
     104            return objectString();
     105        case TypeofType::Function:
     106            return functionString();
     107        }
     108       
     109        RELEASE_ASSERT_NOT_REACHED();
     110        return nullptr;
     111    }
    88112
    89113    JSString* nullObjectString() const { return m_nullObjectString; }
Note: See TracChangeset for help on using the changeset viewer.