Changeset 235517 in webkit


Ignore:
Timestamp:
Aug 30, 2018 12:46:56 PM (6 years ago)
Author:
sbarati@apple.com
Message:

InlineAccess should do StringLength
https://bugs.webkit.org/show_bug.cgi?id=158911

Reviewed by Yusuke Suzuki.

This patch extends InlineAccess to support StringLength. This patch also
fixes AccessCase::fromStructureStubInfo to support ArrayLength and StringLength.
I forgot to implement this for ArrayLength in the initial InlineAccess
implementation. Supporting StringLength is a natural extension of the
InlineAccess machinery.

  • assembler/MacroAssembler.h:

(JSC::MacroAssembler::patchableBranch8):

  • assembler/MacroAssemblerARM64.h:

(JSC::MacroAssemblerARM64::patchableBranch8):

  • bytecode/AccessCase.cpp:

(JSC::AccessCase::fromStructureStubInfo):

  • bytecode/BytecodeDumper.cpp:

(JSC::BytecodeDumper<Block>::printGetByIdCacheStatus):

  • bytecode/InlineAccess.cpp:

(JSC::InlineAccess::dumpCacheSizesAndCrash):
(JSC::InlineAccess::generateSelfPropertyAccess):
(JSC::getScratchRegister):
(JSC::InlineAccess::generateSelfPropertyReplace):
(JSC::InlineAccess::generateArrayLength):
(JSC::InlineAccess::generateSelfInAccess):
(JSC::InlineAccess::generateStringLength):

  • bytecode/InlineAccess.h:
  • bytecode/PolymorphicAccess.cpp:

(JSC::PolymorphicAccess::regenerate):

  • bytecode/StructureStubInfo.cpp:

(JSC::StructureStubInfo::initStringLength):
(JSC::StructureStubInfo::deref):
(JSC::StructureStubInfo::aboutToDie):
(JSC::StructureStubInfo::propagateTransitions):

  • bytecode/StructureStubInfo.h:

(JSC::StructureStubInfo::baseGPR const):

  • jit/Repatch.cpp:

(JSC::tryCacheGetByID):

Location:
trunk/Source/JavaScriptCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r235515 r235517  
     12018-08-30  Saam barati  <sbarati@apple.com>
     2
     3        InlineAccess should do StringLength
     4        https://bugs.webkit.org/show_bug.cgi?id=158911
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        This patch extends InlineAccess to support StringLength. This patch also
     9        fixes AccessCase::fromStructureStubInfo to support ArrayLength and StringLength.
     10        I forgot to implement this for ArrayLength in the initial InlineAccess
     11        implementation.  Supporting StringLength is a natural extension of the
     12        InlineAccess machinery.
     13
     14        * assembler/MacroAssembler.h:
     15        (JSC::MacroAssembler::patchableBranch8):
     16        * assembler/MacroAssemblerARM64.h:
     17        (JSC::MacroAssemblerARM64::patchableBranch8):
     18        * bytecode/AccessCase.cpp:
     19        (JSC::AccessCase::fromStructureStubInfo):
     20        * bytecode/BytecodeDumper.cpp:
     21        (JSC::BytecodeDumper<Block>::printGetByIdCacheStatus):
     22        * bytecode/InlineAccess.cpp:
     23        (JSC::InlineAccess::dumpCacheSizesAndCrash):
     24        (JSC::InlineAccess::generateSelfPropertyAccess):
     25        (JSC::getScratchRegister):
     26        (JSC::InlineAccess::generateSelfPropertyReplace):
     27        (JSC::InlineAccess::generateArrayLength):
     28        (JSC::InlineAccess::generateSelfInAccess):
     29        (JSC::InlineAccess::generateStringLength):
     30        * bytecode/InlineAccess.h:
     31        * bytecode/PolymorphicAccess.cpp:
     32        (JSC::PolymorphicAccess::regenerate):
     33        * bytecode/StructureStubInfo.cpp:
     34        (JSC::StructureStubInfo::initStringLength):
     35        (JSC::StructureStubInfo::deref):
     36        (JSC::StructureStubInfo::aboutToDie):
     37        (JSC::StructureStubInfo::propagateTransitions):
     38        * bytecode/StructureStubInfo.h:
     39        (JSC::StructureStubInfo::baseGPR const):
     40        * jit/Repatch.cpp:
     41        (JSC::tryCacheGetByID):
     42
    1432018-08-30  Saam barati  <sbarati@apple.com>
    244
  • trunk/Source/JavaScriptCore/assembler/MacroAssembler.h

    r235160 r235517  
    449449    {
    450450        return PatchableJump(branch32(cond, reg, imm));
     451    }
     452
     453    PatchableJump patchableBranch8(RelationalCondition cond, Address address, TrustedImm32 imm)
     454    {
     455        return PatchableJump(branch8(cond, address, imm));
    451456    }
    452457
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerARM64.h

    r235106 r235517  
    33893389    }
    33903390
     3391    PatchableJump patchableBranch8(RelationalCondition cond, Address left, TrustedImm32 imm)
     3392    {
     3393        m_makeJumpPatchable = true;
     3394        Jump result = branch8(cond, left, imm);
     3395        m_makeJumpPatchable = false;
     3396        return PatchableJump(result);
     3397    }
     3398
    33913399    PatchableJump patchableBranchTest32(ResultCondition cond, RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
    33923400    {
  • trunk/Source/JavaScriptCore/bytecode/AccessCase.cpp

    r232337 r235517  
    121121    case CacheType::InByIdSelf:
    122122        return AccessCase::create(vm, owner, InHit, stubInfo.u.byIdSelf.offset, stubInfo.u.byIdSelf.baseObjectStructure.get());
     123
     124    case CacheType::ArrayLength:
     125        return AccessCase::create(vm, owner, AccessCase::ArrayLength);
     126
     127    case CacheType::StringLength:
     128        return AccessCase::create(vm, owner, AccessCase::StringLength);
    123129
    124130    default:
  • trunk/Source/JavaScriptCore/bytecode/BytecodeDumper.cpp

    r235450 r235517  
    447447        case CacheType::ArrayLength:
    448448            out.printf("ArrayLength");
     449            break;
     450        case CacheType::StringLength:
     451            out.printf("StringLength");
    449452            break;
    450453        default:
  • trunk/Source/JavaScriptCore/bytecode/InlineAccess.cpp

    r232070 r235517  
    4848    JSValueRegs regs(base);
    4949#endif
     50    {
     51        CCallHelpers jit;
     52
     53        jit.patchableBranch8(
     54            CCallHelpers::NotEqual,
     55            CCallHelpers::Address(base, JSCell::typeInfoTypeOffset()),
     56            CCallHelpers::TrustedImm32(StringType));
     57        jit.load32(CCallHelpers::Address(base, JSString::offsetOfLength()), regs.payloadGPR());
     58        jit.boxInt32(regs.payloadGPR(), regs);
     59
     60        dataLog("string length size: ", jit.m_assembler.buffer().codeSize(), "\n");
     61    }
    5062
    5163    {
     
    159171    CCallHelpers jit;
    160172   
    161     GPRReg base = static_cast<GPRReg>(stubInfo.patch.baseGPR);
     173    GPRReg base = stubInfo.baseGPR();
    162174    JSValueRegs value = stubInfo.valueRegs();
    163175
     
    186198{
    187199    ScratchRegisterAllocator allocator(stubInfo.patch.usedRegisters);
    188     allocator.lock(static_cast<GPRReg>(stubInfo.patch.baseGPR));
     200    allocator.lock(stubInfo.baseGPR());
    189201    allocator.lock(static_cast<GPRReg>(stubInfo.patch.valueGPR));
    190202#if USE(JSVALUE32_64)
     
    217229    CCallHelpers jit;
    218230
    219     GPRReg base = static_cast<GPRReg>(stubInfo.patch.baseGPR);
     231    GPRReg base = stubInfo.baseGPR();
    220232    JSValueRegs value = stubInfo.valueRegs();
    221233
     
    259271    CCallHelpers jit;
    260272
    261     GPRReg base = static_cast<GPRReg>(stubInfo.patch.baseGPR);
     273    GPRReg base = stubInfo.baseGPR();
    262274    JSValueRegs value = stubInfo.valueRegs();
    263275    GPRReg scratch = getScratchRegister(stubInfo);
     
    277289}
    278290
     291bool InlineAccess::generateStringLength(StructureStubInfo& stubInfo)
     292{
     293    CCallHelpers jit;
     294
     295    GPRReg base = stubInfo.baseGPR();
     296    JSValueRegs value = stubInfo.valueRegs();
     297
     298    auto branchToSlowPath = jit.patchableBranch8(
     299        CCallHelpers::NotEqual,
     300        CCallHelpers::Address(base, JSCell::typeInfoTypeOffset()),
     301        CCallHelpers::TrustedImm32(StringType));
     302    jit.load32(CCallHelpers::Address(base, JSString::offsetOfLength()), value.payloadGPR());
     303    jit.boxInt32(value.payloadGPR(), value);
     304
     305    bool linkedCodeInline = linkCodeInline("string length", jit, stubInfo, [&] (LinkBuffer& linkBuffer) {
     306        linkBuffer.link(branchToSlowPath, stubInfo.slowPathStartLocation());
     307    });
     308    return linkedCodeInline;
     309}
     310
     311
    279312bool InlineAccess::generateSelfInAccess(StructureStubInfo& stubInfo, Structure* structure)
    280313{
    281314    CCallHelpers jit;
    282315
    283     GPRReg base = static_cast<GPRReg>(stubInfo.patch.baseGPR);
     316    GPRReg base = stubInfo.baseGPR();
    284317    JSValueRegs value = stubInfo.valueRegs();
    285318
  • trunk/Source/JavaScriptCore/bytecode/InlineAccess.h

    r232047 r235517  
    8888    // https://bugs.webkit.org/show_bug.cgi?id=159436
    8989    //
    90     // This is the maximum between the size for array length access, and the size for regular self access.
     90    // This is the maximum between array length, string length, and regular self access sizes.
    9191    ALWAYS_INLINE static size_t sizeForLengthAccess()
    9292    {
     
    118118    static void rewireStubAsJump(StructureStubInfo&, CodeLocationLabel<JITStubRoutinePtrTag>);
    119119    static bool generateSelfInAccess(StructureStubInfo&, Structure*);
     120    static bool generateStringLength(StructureStubInfo&);
    120121
    121122    // This is helpful when determining the size of an IC on
  • trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp

    r231961 r235517  
    382382    state.ident = &ident;
    383383   
    384     state.baseGPR = static_cast<GPRReg>(stubInfo.patch.baseGPR);
     384    state.baseGPR = stubInfo.baseGPR();
    385385    state.thisGPR = static_cast<GPRReg>(stubInfo.patch.thisGPR);
    386386    state.valueRegs = stubInfo.valueRegs();
  • trunk/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp

    r234086 r235517  
    7474}
    7575
     76void StructureStubInfo::initStringLength()
     77{
     78    cacheType = CacheType::StringLength;
     79}
     80
    7681void StructureStubInfo::initPutByIdReplace(CodeBlock* codeBlock, Structure* baseObjectStructure, PropertyOffset offset)
    7782{
     
    103108    case CacheType::InByIdSelf:
    104109    case CacheType::ArrayLength:
     110    case CacheType::StringLength:
    105111        return;
    106112    }
     
    120126    case CacheType::InByIdSelf:
    121127    case CacheType::ArrayLength:
     128    case CacheType::StringLength:
    122129        return;
    123130    }
     
    293300    case CacheType::Unset:
    294301    case CacheType::ArrayLength:
     302    case CacheType::StringLength:
    295303        return true;
    296304    case CacheType::GetByIdSelf:
  • trunk/Source/JavaScriptCore/bytecode/StructureStubInfo.h

    r234086 r235517  
    6262    InByIdSelf,
    6363    Stub,
    64     ArrayLength
     64    ArrayLength,
     65    StringLength
    6566};
    6667
     
    7475    void initGetByIdSelf(CodeBlock*, Structure* baseObjectStructure, PropertyOffset);
    7576    void initArrayLength();
     77    void initStringLength();
    7678    void initPutByIdReplace(CodeBlock*, Structure* baseObjectStructure, PropertyOffset);
    7779    void initInByIdSelf(CodeBlock*, Structure* baseObjectStructure, PropertyOffset);
     
    200202    } patch;
    201203
     204    GPRReg baseGPR() const
     205    {
     206        return static_cast<GPRReg>(patch.baseGPR);
     207    }
     208
    202209    CodeLocationCall<JSInternalPtrTag> slowPathCallLocation() { return patch.start.callAtOffset<JSInternalPtrTag>(patch.deltaFromStartToSlowPathCallLocation); }
    203210    CodeLocationLabel<JSInternalPtrTag> doneLocation() { return patch.start.labelAtOffset<JSInternalPtrTag>(patch.inlineSize); }
  • trunk/Source/JavaScriptCore/jit/Repatch.cpp

    r234086 r235517  
    216216
    217217                newCase = AccessCase::create(vm, codeBlock, AccessCase::ArrayLength);
    218             } else if (isJSString(baseCell))
     218            } else if (isJSString(baseCell)) {
     219                if (stubInfo.cacheType == CacheType::Unset) {
     220                    bool generatedCodeInline = InlineAccess::generateStringLength(stubInfo);
     221                    if (generatedCodeInline) {
     222                        ftlThunkAwareRepatchCall(codeBlock, stubInfo.slowPathCallLocation(), appropriateOptimizingGetByIdFunction(kind));
     223                        stubInfo.initStringLength();
     224                        return RetryCacheLater;
     225                    }
     226                }
     227
    219228                newCase = AccessCase::create(vm, codeBlock, AccessCase::StringLength);
     229            }
    220230            else if (DirectArguments* arguments = jsDynamicCast<DirectArguments*>(vm, baseCell)) {
    221231                // If there were overrides, then we can handle this as a normal property load! Guarding
Note: See TracChangeset for help on using the changeset viewer.