Changeset 255987 in webkit


Ignore:
Timestamp:
Feb 6, 2020, 3:25:01 PM (6 years ago)
Author:
[email protected]
Message:

[JSC] CodeBlock::shrinkToFit should shrink m_constantRegisters and m_constantsSourceCodeRepresentation in 64bit architectures
https://bugs.webkit.org/show_bug.cgi?id=207356

Reviewed by Mark Lam.

Only 32bit architectures are using m_constantRegisters's address. 64bit architectures are not relying on m_constantRegisters's address.
This patches fixes the thing so that CodeBlock::shrinkToFit will shrink m_constantRegisters and m_constantsSourceCodeRepresentation
regardless of whether this is EarlyShrink or not. We also move DFG/FTL's LateShrink call to the place after calling DFGCommon reallyAdd
since they can add more constant registers.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::shrinkToFit):

  • bytecode/CodeBlock.h:
  • dfg/DFGJITCompiler.cpp:

(JSC::DFG::JITCompiler::compile):
(JSC::DFG::JITCompiler::compileFunction):

  • dfg/DFGJITFinalizer.cpp:

(JSC::DFG::JITFinalizer::finalizeCommon):

  • dfg/DFGPlan.cpp:

(JSC::DFG::Plan::compileInThreadImpl):
(JSC::DFG::Plan::finalizeWithoutNotifyingCallback):

  • jit/JIT.cpp:

(JSC::JIT::link):

  • jit/JIT.h:
  • jit/JITInlines.h:

(JSC::JIT::emitLoadDouble):
(JSC::JIT::emitLoadInt32ToDouble): Deleted.

Location:
trunk/Source/JavaScriptCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r255905 r255987  
     12020-02-06  Yusuke Suzuki  <[email protected]>
     2
     3        [JSC] CodeBlock::shrinkToFit should shrink m_constantRegisters and m_constantsSourceCodeRepresentation in 64bit architectures
     4        https://bugs.webkit.org/show_bug.cgi?id=207356
     5
     6        Reviewed by Mark Lam.
     7
     8        Only 32bit architectures are using m_constantRegisters's address. 64bit architectures are not relying on m_constantRegisters's address.
     9        This patches fixes the thing so that CodeBlock::shrinkToFit will shrink m_constantRegisters and m_constantsSourceCodeRepresentation
     10        regardless of whether this is EarlyShrink or not. We also move DFG/FTL's LateShrink call to the place after calling DFGCommon reallyAdd
     11        since they can add more constant registers.
     12
     13        * bytecode/CodeBlock.cpp:
     14        (JSC::CodeBlock::shrinkToFit):
     15        * bytecode/CodeBlock.h:
     16        * dfg/DFGJITCompiler.cpp:
     17        (JSC::DFG::JITCompiler::compile):
     18        (JSC::DFG::JITCompiler::compileFunction):
     19        * dfg/DFGJITFinalizer.cpp:
     20        (JSC::DFG::JITFinalizer::finalizeCommon):
     21        * dfg/DFGPlan.cpp:
     22        (JSC::DFG::Plan::compileInThreadImpl):
     23        (JSC::DFG::Plan::finalizeWithoutNotifyingCallback):
     24        * jit/JIT.cpp:
     25        (JSC::JIT::link):
     26        * jit/JIT.h:
     27        * jit/JITInlines.h:
     28        (JSC::JIT::emitLoadDouble):
     29        (JSC::JIT::emitLoadInt32ToDouble): Deleted.
     30
    1312020-02-05  Don Olmstead  <[email protected]>
    232
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r255887 r255987  
    19541954}
    19551955
    1956 void CodeBlock::shrinkToFit(ShrinkMode shrinkMode)
     1956void CodeBlock::shrinkToFit(const ConcurrentJSLocker&, ShrinkMode shrinkMode)
    19571957{
    19581958    ConcurrentJSLocker locker(m_lock);
    19591959
    1960     if (shrinkMode == EarlyShrink) {
     1960#if USE(JSVALUE32_64)
     1961    // Only 32bit Baseline JIT is touching m_constantRegisters address directly.
     1962    if (shrinkMode == ShrinkMode::EarlyShrink)
    19611963        m_constantRegisters.shrinkToFit();
    1962         m_constantsSourceCodeRepresentation.shrinkToFit();
    1963        
     1964#else
     1965    m_constantRegisters.shrinkToFit();
     1966#endif
     1967    m_constantsSourceCodeRepresentation.shrinkToFit();
     1968
     1969    if (shrinkMode == ShrinkMode::EarlyShrink) {
    19641970        if (m_rareData) {
    19651971            m_rareData->m_switchJumpTables.shrinkToFit();
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r255687 r255987  
    636636    DirectEvalCodeCache& directEvalCodeCache() { createRareDataIfNecessary(); return m_rareData->m_directEvalCodeCache; }
    637637
    638     enum ShrinkMode {
     638    enum class ShrinkMode {
    639639        // Shrink prior to generating machine code that may point directly into vectors.
    640640        EarlyShrink,
     
    643643        // and appending to others. At this time it is not safe to shrink certain vectors
    644644        // because we would have generated machine code that references them directly.
    645         LateShrink
     645        LateShrink,
    646646    };
    647     void shrinkToFit(ShrinkMode);
     647    void shrinkToFit(const ConcurrentJSLocker&, ShrinkMode);
    648648
    649649    // Functions for controlling when JITting kicks in, in a mixed mode
  • trunk/Source/JavaScriptCore/dfg/DFGJITCompiler.cpp

    r255540 r255987  
    393393    m_speculative->linkOSREntries(*linkBuffer);
    394394
    395     codeBlock()->shrinkToFit(CodeBlock::LateShrink);
    396 
    397395    disassemble(*linkBuffer);
    398396
     
    494492    m_speculative->linkOSREntries(*linkBuffer);
    495493   
    496     codeBlock()->shrinkToFit(CodeBlock::LateShrink);
    497 
    498494    if (requiresArityFixup)
    499495        linkBuffer->link(callArityFixup, FunctionPtr<JITThunkPtrTag>(vm().getCTIStub(arityFixupGenerator).code()));
  • trunk/Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp

    r254464 r255987  
    8484    CodeBlock* codeBlock = m_plan.codeBlock();
    8585
    86     // Some JIT finalizers may have added more constants. Shrink-to-fit those things now.
    87     {
    88         ConcurrentJSLocker locker(codeBlock->m_lock);
    89         codeBlock->constants().shrinkToFit();
    90         codeBlock->constantsSourceCodeRepresentation().shrinkToFit();
    91     }
    92 
    9386#if ENABLE(FTL_JIT)
    9487    m_jitCode->optimizeAfterWarmUp(codeBlock);
  • trunk/Source/JavaScriptCore/dfg/DFGPlan.cpp

    r255542 r255987  
    280280    // powerful than a late one. It's safe to do so because we haven't generated any code
    281281    // that references any of the tables directly, yet.
    282     m_codeBlock->shrinkToFit(CodeBlock::EarlyShrink);
     282    {
     283        ConcurrentJSLocker locker(m_codeBlock->m_lock);
     284        m_codeBlock->shrinkToFit(locker, CodeBlock::ShrinkMode::EarlyShrink);
     285    }
    283286
    284287    if (validationEnabled())
     
    618621            ConcurrentJSLocker locker(m_codeBlock->m_lock);
    619622            m_codeBlock->jitCode()->shrinkToFit(locker);
     623            m_codeBlock->shrinkToFit(locker, CodeBlock::ShrinkMode::LateShrink);
    620624        }
    621625
  • trunk/Source/JavaScriptCore/jit/JIT.cpp

    r255541 r255987  
    944944        static_cast<double>(m_codeBlock->instructionsSize()));
    945945
    946     m_codeBlock->shrinkToFit(CodeBlock::LateShrink);
     946    {
     947        ConcurrentJSLocker locker(m_codeBlock->m_lock);
     948        m_codeBlock->shrinkToFit(locker, CodeBlock::ShrinkMode::LateShrink);
     949    }
    947950    m_codeBlock->setJITCode(
    948951        adoptRef(*new DirectJITCode(result, withArityCheck, JITType::BaselineJIT)));
  • trunk/Source/JavaScriptCore/jit/JIT.h

    r255541 r255987  
    338338        bool isOperandConstantDouble(VirtualRegister);
    339339       
    340         void emitLoadDouble(VirtualRegister, FPRegisterID value);
    341         void emitLoadInt32ToDouble(VirtualRegister, FPRegisterID value);
    342 
    343340        enum WriteBarrierMode { UnconditionalWriteBarrier, ShouldFilterBase, ShouldFilterValue, ShouldFilterBaseAndValue };
    344341        // value register in write barrier is used before any scratch registers
     
    418415        bool getOperandConstantInt(VirtualRegister op1, VirtualRegister op2, VirtualRegister& op, int32_t& constant);
    419416
     417        void emitLoadDouble(VirtualRegister, FPRegisterID value);
    420418        void emitLoadTag(VirtualRegister, RegisterID tag);
    421419        void emitLoadPayload(VirtualRegister, RegisterID payload);
  • trunk/Source/JavaScriptCore/jit/JITInlines.h

    r255040 r255987  
    378378#if USE(JSVALUE32_64)
    379379
     380inline void JIT::emitLoadDouble(VirtualRegister reg, FPRegisterID value)
     381{
     382    if (reg.isConstant()) {
     383        WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(reg);
     384        loadDouble(TrustedImmPtr(&inConstantPool), value);
     385    } else
     386        loadDouble(addressFor(reg), value);
     387}
     388
    380389inline void JIT::emitLoadTag(VirtualRegister reg, RegisterID tag)
    381390{
     
    439448    emitLoad(reg2, tag2, payload2);
    440449    emitLoad(reg1, tag1, payload1);
    441 }
    442 
    443 inline void JIT::emitLoadDouble(VirtualRegister reg, FPRegisterID value)
    444 {
    445     if (reg.isConstant()) {
    446         WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(reg);
    447         loadDouble(TrustedImmPtr(&inConstantPool), value);
    448     } else
    449         loadDouble(addressFor(reg), value);
    450 }
    451 
    452 inline void JIT::emitLoadInt32ToDouble(VirtualRegister reg, FPRegisterID value)
    453 {
    454     if (reg.isConstant()) {
    455         WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(reg);
    456         char* bytePointer = reinterpret_cast<char*>(&inConstantPool);
    457         convertInt32ToDouble(AbsoluteAddress(bytePointer + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), value);
    458     } else
    459         convertInt32ToDouble(payloadFor(reg), value);
    460450}
    461451
     
    615605}
    616606
    617 inline void JIT::emitLoadDouble(VirtualRegister reg, FPRegisterID value)
    618 {
    619     if (reg.isConstant()) {
    620         WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(reg);
    621         loadDouble(TrustedImmPtr(&inConstantPool), value);
    622     } else
    623         loadDouble(addressFor(reg), value);
    624 }
    625 
    626 inline void JIT::emitLoadInt32ToDouble(VirtualRegister reg, FPRegisterID value)
    627 {
    628     if (reg.isConstant()) {
    629         ASSERT(isOperandConstantInt(reg));
    630         convertInt32ToDouble(Imm32(getConstantOperand(reg).asInt32()), value);
    631     } else
    632         convertInt32ToDouble(addressFor(reg), value);
    633 }
    634 
    635607ALWAYS_INLINE JIT::PatchableJump JIT::emitPatchableJumpIfNotInt(RegisterID reg)
    636608{
Note: See TracChangeset for help on using the changeset viewer.