Ignore:
Timestamp:
Feb 19, 2009, 2:51:40 PM (16 years ago)
Author:
[email protected]
Message:

2009-02-19 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Fix for x86-64. Where the JavaScriptCore text segment lies outside
a 2gb range of the heap containing JIT generated code, callbacks
from JIT code to the stub functions in Interpreter will be incorrectly
linked.

No performance impact on Sunspider, 1% regression on v8-tests,
due to a 3% regression on richards.

  • assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::Call::Call): (JSC::AbstractMacroAssembler::Jump::link): (JSC::AbstractMacroAssembler::Jump::linkTo): (JSC::AbstractMacroAssembler::CodeLocationJump::relink): (JSC::AbstractMacroAssembler::CodeLocationCall::relink): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::relinkCallerToFunction): (JSC::AbstractMacroAssembler::PatchBuffer::link): (JSC::AbstractMacroAssembler::PatchBuffer::linkTailRecursive): (JSC::AbstractMacroAssembler::differenceBetween):
  • assembler/MacroAssembler.h: (JSC::MacroAssembler::tailRecursiveCall): (JSC::MacroAssembler::makeTailRecursiveCall):
  • assembler/MacroAssemblerX86.h: (JSC::MacroAssemblerX86::call):
  • assembler/MacroAssemblerX86Common.h:
  • assembler/MacroAssemblerX86_64.h: (JSC::MacroAssemblerX86_64::call): (JSC::MacroAssemblerX86_64::moveWithPatch): (JSC::MacroAssemblerX86_64::branchPtrWithPatch): (JSC::MacroAssemblerX86_64::storePtrWithPatch):
  • assembler/X86Assembler.h: (JSC::X86Assembler::jmp_r): (JSC::X86Assembler::linkJump): (JSC::X86Assembler::patchJump): (JSC::X86Assembler::patchCall): (JSC::X86Assembler::linkCall): (JSC::X86Assembler::patchAddress):
  • interpreter/Interpreter.cpp: (JSC::Interpreter::tryCTICachePutByID):
  • jit/JIT.cpp: (JSC::JIT::privateCompile): (JSC::JIT::privateCompileCTIMachineTrampolines):
  • jit/JIT.h:
  • jit/JITArithmetic.cpp: (JSC::JIT::putDoubleResultToJSNumberCellOrJSImmediate): (JSC::JIT::compileBinaryArithOp):
  • jit/JITPropertyAccess.cpp: (JSC::JIT::privateCompilePutByIdTransition): (JSC::JIT::privateCompileGetByIdSelf): (JSC::JIT::privateCompilePutByIdReplace):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h

    r40879 r41089  
    266266        friend class AbstractMacroAssembler;
    267267    public:
     268        enum Flags {
     269            None = 0x0,
     270            Linkable = 0x1,
     271            Near = 0x2,
     272            LinkableNear = 0x3,
     273        };
     274
    268275        Call()
    269         {
    270         }
    271        
    272         Call(JmpSrc jmp, bool isRelative)
     276            : m_flags(None)
     277        {
     278        }
     279       
     280        Call(JmpSrc jmp, Flags flags)
    273281            : m_jmp(jmp)
    274 #ifndef NDEBUG
    275             , isRelative(isRelative)
    276 #endif
    277         {
    278 #ifdef NDEBUG
    279 #pragma unused(isRelative)
    280 #endif
    281         }
    282        
    283         void link(AbstractMacroAssembler<AssemblerType>* masm)
    284         {
    285             ASSERT(isRelative);
    286             masm->m_assembler.link(m_jmp, masm->m_assembler.label());
    287         }
    288        
    289         void linkTo(Label label, AbstractMacroAssembler<AssemblerType>* masm)
    290         {
    291             ASSERT(isRelative);
    292             masm->m_assembler.link(m_jmp, label.m_label);
     282            , m_flags(flags)
     283        {
     284        }
     285
     286        bool isFlagSet(Flags flag)
     287        {
     288            return m_flags & flag;
     289        }
     290
     291        static Call fromTailJump(Jump jump)
     292        {
     293            return Call(jump.m_jmp, Linkable);
    293294        }
    294295
    295296    private:
    296297        JmpSrc m_jmp;
    297 #ifndef NDEBUG
    298         bool isRelative;
    299 #endif
     298        Flags m_flags;
    300299    };
    301300
     
    310309        template<class AssemblerType_T>
    311310        friend class AbstractMacroAssembler;
     311        friend class Call;
    312312    public:
    313313        Jump()
     
    322322        void link(AbstractMacroAssembler<AssemblerType>* masm)
    323323        {
    324             masm->m_assembler.link(m_jmp, masm->m_assembler.label());
     324            masm->m_assembler.linkJump(m_jmp, masm->m_assembler.label());
    325325        }
    326326       
    327327        void linkTo(Label label, AbstractMacroAssembler<AssemblerType>* masm)
    328328        {
    329             masm->m_assembler.link(m_jmp, label.m_label);
     329            masm->m_assembler.linkJump(m_jmp, label.m_label);
    330330        }
    331331
     
    461461        void relink(CodeLocationLabel destination)
    462462        {
    463             AssemblerType::patchBranchOffset(reinterpret_cast<intptr_t>(this->m_location), destination.m_location);
     463            AssemblerType::patchJump(reinterpret_cast<intptr_t>(this->m_location), destination.m_location);
    464464        }
    465465
     
    485485        void relink(FunctionSig* function)
    486486        {
    487             AssemblerType::patchBranchOffset(reinterpret_cast<intptr_t>(this->m_location), reinterpret_cast<void*>(function));
     487            AssemblerType::patchMacroAssemblerCall(reinterpret_cast<intptr_t>(this->m_location), reinterpret_cast<void*>(function));
    488488        }
    489489
     
    502502    };
    503503
     504    // CodeLocationNearCall:
     505    //
     506    // A point in the JIT code at which there is a call instruction with near linkage.
     507    class CodeLocationNearCall : public CodeLocationCommon {
     508        friend class CodeLocationCommon;
     509        friend class PatchBuffer;
     510    public:
     511        CodeLocationNearCall()
     512        {
     513        }
     514
     515        template<typename FunctionSig>
     516        void relink(FunctionSig* function)
     517        {
     518            AssemblerType::patchCall(reinterpret_cast<intptr_t>(this->m_location), reinterpret_cast<void*>(function));
     519        }
     520
     521        // This methods returns the value that will be set as the return address
     522        // within a function that has been called from this call instruction.
     523        void* calleeReturnAddressValue()
     524        {
     525            return this->m_location;
     526        }
     527
     528    private:
     529        explicit CodeLocationNearCall(void* location)
     530            : CodeLocationCommon(location)
     531        {
     532        }
     533    };
     534
    504535    // CodeLocationDataLabel32:
    505536    //
     
    561592        void relinkCallerToFunction(FunctionSig* newCalleeFunction)
    562593        {
    563             AssemblerType::patchBranchOffset(reinterpret_cast<intptr_t>(this->m_location), reinterpret_cast<void*>(newCalleeFunction));
     594            AssemblerType::patchMacroAssemblerCall(reinterpret_cast<intptr_t>(this->m_location), reinterpret_cast<void*>(newCalleeFunction));
     595        }
     596       
     597        template<typename FunctionSig>
     598        void relinkNearCallerToFunction(FunctionSig* newCalleeFunction)
     599        {
     600            AssemblerType::patchCall(reinterpret_cast<intptr_t>(this->m_location), reinterpret_cast<void*>(newCalleeFunction));
    564601        }
    565602       
     
    616653        void link(Call call, FunctionSig* function)
    617654        {
    618             AssemblerType::link(m_code, call.m_jmp, reinterpret_cast<void*>(function));
     655            ASSERT(call.isFlagSet(Call::Linkable));
     656#if PLATFORM(X86_64)
     657            if (call.isFlagSet(Call::Near)) {
     658                AssemblerType::linkCall(m_code, call.m_jmp, reinterpret_cast<void*>(function));
     659            } else {
     660                intptr_t callLocation = reinterpret_cast<intptr_t>(AssemblerType::getRelocatedAddress(m_code, call.m_jmp));
     661                AssemblerType::patchMacroAssemblerCall(callLocation, reinterpret_cast<void*>(function));
     662            }
     663#else
     664            AssemblerType::linkCall(m_code, call.m_jmp, reinterpret_cast<void*>(function));
     665#endif
    619666        }
    620667       
     
    622669        void linkTailRecursive(Jump jump, FunctionSig* function)
    623670        {
    624             AssemblerType::link(m_code, jump.m_jmp, reinterpret_cast<void*>(function));
     671            AssemblerType::linkJump(m_code, jump.m_jmp, reinterpret_cast<void*>(function));
    625672        }
    626673
     
    628675        void linkTailRecursive(JumpList list, FunctionSig* function)
    629676        {
     677            for (unsigned i = 0; i < list.m_jumps.size(); ++i) {
     678                AssemblerType::linkJump(m_code, list.m_jumps[i].m_jmp, reinterpret_cast<void*>(function));
     679            }
     680        }
     681
     682        void link(Jump jump, CodeLocationLabel label)
     683        {
     684            AssemblerType::linkJump(m_code, jump.m_jmp, label.m_location);
     685        }
     686
     687        void link(JumpList list, CodeLocationLabel label)
     688        {
    630689            for (unsigned i = 0; i < list.m_jumps.size(); ++i)
    631                 AssemblerType::link(m_code, list.m_jumps[i].m_jmp, reinterpret_cast<void*>(function));
    632         }
    633 
    634         void link(Jump jump, CodeLocationLabel label)
    635         {
    636             AssemblerType::link(m_code, jump.m_jmp, label.m_location);
    637         }
    638 
    639         void link(JumpList list, CodeLocationLabel label)
    640         {
    641             for (unsigned i = 0; i < list.m_jumps.size(); ++i)
    642                 AssemblerType::link(m_code, list.m_jumps[i].m_jmp, label.m_location);
     690                AssemblerType::linkJump(m_code, list.m_jumps[i].m_jmp, label.m_location);
    643691        }
    644692
     
    652700        CodeLocationCall locationOf(Call call)
    653701        {
    654             ASSERT(call.isRelative);
     702            ASSERT(call.isFlagSet(Call::Linkable));
     703            ASSERT(!call.isFlagSet(Call::Near));
    655704            return CodeLocationCall(AssemblerType::getRelocatedAddress(m_code, call.m_jmp));
     705        }
     706
     707        CodeLocationNearCall locationOfNearCall(Call call)
     708        {
     709            ASSERT(call.isFlagSet(Call::Linkable));
     710            ASSERT(call.isFlagSet(Call::Near));
     711            return CodeLocationNearCall(AssemblerType::getRelocatedAddress(m_code, call.m_jmp));
    656712        }
    657713
     
    732788
    733789    ptrdiff_t differenceBetween(DataLabelPtr from, Jump to)
     790    {
     791        return AssemblerType::getDifferenceBetweenLabels(from.m_label, to.m_jmp);
     792    }
     793
     794    ptrdiff_t differenceBetween(DataLabelPtr from, Call to)
    734795    {
    735796        return AssemblerType::getDifferenceBetweenLabels(from.m_label, to.m_jmp);
Note: See TracChangeset for help on using the changeset viewer.