Ignore:
Timestamp:
Jun 15, 2009, 5:26:53 PM (16 years ago)
Author:
[email protected]
Message:

2009-06-15 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Move repatching methods into a set of methods on a class. This will allow us to
coallesce memory reprotection calls. Really, we want this class to be called
PatchBuffer, we want the class PatchBuffer to be called LinkBuffer, we want both
to be memblers of MacroAssembler rather then AbstractMacroAssembler, we don't
want the CodeLocationFoo types anymore (they are now only really there to provide
type safety, and that is completely undermined by the way we use offsets). Then
the link & patch buffers should delegate the actual patching calls to the
architecture-specific layer of the MacroAssembler. Landing all these changes as a
sequence of patches.

No performance impact.

  • assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::CodeLocationCall::CodeLocationCall): (JSC::AbstractMacroAssembler::CodeLocationNearCall::CodeLocationNearCall): (JSC::AbstractMacroAssembler::CodeLocationNearCall::calleeReturnAddressValue): (JSC::AbstractMacroAssembler::RepatchBuffer::RepatchBuffer): (JSC::AbstractMacroAssembler::RepatchBuffer::relink): (JSC::AbstractMacroAssembler::RepatchBuffer::repatch): (JSC::AbstractMacroAssembler::RepatchBuffer::relinkCallerToTrampoline): (JSC::AbstractMacroAssembler::RepatchBuffer::relinkCallerToFunction): (JSC::AbstractMacroAssembler::RepatchBuffer::relinkNearCallerToTrampoline): (JSC::AbstractMacroAssembler::RepatchBuffer::repatchLoadPtrToLEA):
  • jit/JIT.cpp: (JSC::ctiPatchNearCallByReturnAddress): (JSC::ctiPatchCallByReturnAddress): (JSC::JIT::unlinkCall): (JSC::JIT::linkCall):
  • jit/JITPropertyAccess.cpp: (JSC::JIT::privateCompilePutByIdTransition): (JSC::JIT::patchGetByIdSelf): (JSC::JIT::patchMethodCallProto): (JSC::JIT::patchPutByIdReplace): (JSC::JIT::privateCompilePatchGetArrayLength): (JSC::JIT::privateCompileGetByIdProto): (JSC::JIT::privateCompileGetByIdSelfList): (JSC::JIT::privateCompileGetByIdProtoList): (JSC::JIT::privateCompileGetByIdChainList): (JSC::JIT::privateCompileGetByIdChain):
File:
1 edited

Legend:

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

    r44514 r44700  
    5050    class Jump;
    5151    class PatchBuffer;
     52    class RepatchBuffer;
    5253    class CodeLocationInstruction;
    5354    class CodeLocationLabel;
     
    429430    // instruction stream, without any semantic information.
    430431    class CodeLocationCommon {
     432        friend class RepatchBuffer;
     433
    431434    public:
    432435        CodeLocationCommon()
     
    469472    // An arbitrary instruction in the JIT code.
    470473    class CodeLocationInstruction : public CodeLocationCommon {
    471         friend class CodeLocationCommon;
    472474    public:
    473475        CodeLocationInstruction()
     
    475477        }
    476478
    477         void repatchLoadPtrToLEA()
    478         {
    479             AssemblerType::repatchLoadPtrToLEA(this->dataLocation());
    480         }
    481 
    482     private:
    483479        explicit CodeLocationInstruction(void* location)
    484480            : CodeLocationCommon(CodePtr(location))
     
    496492        friend class CodeLocationNearCall;
    497493        friend class PatchBuffer;
     494        friend class RepatchBuffer;
    498495        friend class ProcessorReturnAddress;
    499496
     
    542539        }
    543540
    544         void relink(CodeLocationLabel destination)
    545         {
    546             AssemblerType::relinkJump(this->dataLocation(), destination.dataLocation());
    547         }
    548 
    549     private:
    550541        explicit CodeLocationJump(void* location)
    551542            : CodeLocationCommon(CodePtr(location))
     
    558549    // A point in the JIT code at which there is a call instruction.
    559550    class CodeLocationCall : public CodeLocationCommon {
    560         friend class CodeLocationCommon;
    561         friend class PatchBuffer;
    562         friend class ProcessorReturnAddress;
    563551    public:
    564552        CodeLocationCall()
     
    566554        }
    567555
    568         void relink(CodeLocationLabel destination)
    569         {
    570 #if PLATFORM(X86_64)
    571             CodeLocationCommon::dataLabelPtrAtOffset(-REPTACH_OFFSET_CALL_R11).repatch(destination.executableAddress());
    572 #else
    573             AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress());
    574 #endif
    575         }
    576 
    577         void relink(FunctionPtr destination)
    578         {
    579 #if PLATFORM(X86_64)
    580             CodeLocationCommon::dataLabelPtrAtOffset(-REPTACH_OFFSET_CALL_R11).repatch(destination.executableAddress());
    581 #else
    582             AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress());
    583 #endif
     556        explicit CodeLocationCall(CodePtr location)
     557            : CodeLocationCommon(location)
     558        {
     559        }
     560
     561        explicit CodeLocationCall(void* location)
     562            : CodeLocationCommon(CodePtr(location))
     563        {
    584564        }
    585565
     
    591571        }
    592572
    593     private:
    594         explicit CodeLocationCall(CodePtr location)
    595             : CodeLocationCommon(location)
    596         {
    597         }
    598 
    599         explicit CodeLocationCall(void* location)
    600             : CodeLocationCommon(CodePtr(location))
    601         {
    602         }
    603573    };
    604574
     
    607577    // A point in the JIT code at which there is a call instruction with near linkage.
    608578    class CodeLocationNearCall : public CodeLocationCommon {
    609         friend class CodeLocationCommon;
    610         friend class PatchBuffer;
    611         friend class ProcessorReturnAddress;
    612579    public:
    613580        CodeLocationNearCall()
     
    615582        }
    616583
    617         void relink(CodePtr destination)
    618         {
    619             AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress());
    620         }
    621 
    622         void relink(CodeLocationLabel destination)
    623         {
    624             AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress());
    625         }
    626 
    627         void relink(FunctionPtr destination)
    628         {
    629             AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress());
     584        explicit CodeLocationNearCall(CodePtr location)
     585            : CodeLocationCommon(location)
     586        {
     587        }
     588
     589        explicit CodeLocationNearCall(void* location)
     590            : CodeLocationCommon(CodePtr(location))
     591        {
    630592        }
    631593
     
    636598            return this->executableAddress();
    637599        }
    638 
    639     private:
    640         explicit CodeLocationNearCall(CodePtr location)
    641             : CodeLocationCommon(location)
    642         {
    643         }
    644 
    645         explicit CodeLocationNearCall(void* location)
    646             : CodeLocationCommon(CodePtr(location))
    647         {
    648         }
    649600    };
    650601
     
    653604    // A point in the JIT code at which there is an int32_t immediate that may be repatched.
    654605    class CodeLocationDataLabel32 : public CodeLocationCommon {
    655         friend class CodeLocationCommon;
    656         friend class PatchBuffer;
    657606    public:
    658607        CodeLocationDataLabel32()
     
    660609        }
    661610
    662         void repatch(int32_t value)
    663         {
    664             AssemblerType::repatchInt32(this->dataLocation(), value);
    665         }
    666 
    667     private:
    668611        explicit CodeLocationDataLabel32(void* location)
    669612            : CodeLocationCommon(CodePtr(location))
     
    676619    // A point in the JIT code at which there is a void* immediate that may be repatched.
    677620    class CodeLocationDataLabelPtr : public CodeLocationCommon {
    678         friend class CodeLocationCommon;
    679         friend class PatchBuffer;
    680621    public:
    681622        CodeLocationDataLabelPtr()
     
    683624        }
    684625
    685         void repatch(void* value)
    686         {
    687             AssemblerType::repatchPointer(this->dataLocation(), value);
    688         }
    689 
    690     private:
    691626        explicit CodeLocationDataLabelPtr(void* location)
    692627            : CodeLocationCommon(CodePtr(location))
     
    699634    // This class can be used to relink a call identified by its return address.
    700635    class ProcessorReturnAddress {
    701         friend class CodeLocationCall;
    702         friend class CodeLocationNearCall;
    703636    public:
    704637        ProcessorReturnAddress(void* location)
     
    707640        }
    708641
    709         void relinkCallerToTrampoline(CodeLocationLabel label)
    710         {
    711             CodeLocationCall(CodePtr(m_location)).relink(label);
    712         }
    713        
    714         void relinkCallerToTrampoline(CodePtr newCalleeFunction)
    715         {
    716             relinkCallerToTrampoline(CodeLocationLabel(newCalleeFunction));
    717         }
    718 
    719         void relinkCallerToFunction(FunctionPtr function)
    720         {
    721             CodeLocationCall(CodePtr(m_location)).relink(function);
    722         }
    723        
    724         void relinkNearCallerToTrampoline(CodeLocationLabel label)
    725         {
    726             CodeLocationNearCall(CodePtr(m_location)).relink(label);
    727         }
    728        
    729         void relinkNearCallerToTrampoline(CodePtr newCalleeFunction)
    730         {
    731             relinkNearCallerToTrampoline(CodeLocationLabel(newCalleeFunction));
    732         }
    733 
    734642        void* addressForLookup()
    735643        {
     
    737645        }
    738646
    739     private:
    740647        ReturnAddressPtr m_location;
    741648    };
     
    902809    };
    903810
     811    class RepatchBuffer {
     812    public:
     813        RepatchBuffer()
     814        {
     815        }
     816
     817        void relink(CodeLocationJump jump, CodeLocationLabel destination)
     818        {
     819            AssemblerType::relinkJump(jump.dataLocation(), destination.dataLocation());
     820        }
     821
     822        void relink(CodeLocationCall call, CodeLocationLabel destination)
     823        {
     824#if PLATFORM(X86_64)
     825            repatch(call.dataLabelPtrAtOffset(-REPTACH_OFFSET_CALL_R11), destination.executableAddress());
     826#else
     827            AssemblerType::relinkCall(call.dataLocation(), destination.executableAddress());
     828#endif
     829        }
     830
     831        void relink(CodeLocationCall call, FunctionPtr destination)
     832        {
     833#if PLATFORM(X86_64)
     834            repatch(call.dataLabelPtrAtOffset(-REPTACH_OFFSET_CALL_R11), destination.executableAddress());
     835#else
     836            AssemblerType::relinkCall(call.dataLocation(), destination.executableAddress());
     837#endif
     838        }
     839
     840        void relink(CodeLocationNearCall nearCall, CodePtr destination)
     841        {
     842            AssemblerType::relinkCall(nearCall.dataLocation(), destination.executableAddress());
     843        }
     844
     845        void relink(CodeLocationNearCall nearCall, CodeLocationLabel destination)
     846        {
     847            AssemblerType::relinkCall(nearCall.dataLocation(), destination.executableAddress());
     848        }
     849
     850        void relink(CodeLocationNearCall nearCall, FunctionPtr destination)
     851        {
     852            AssemblerType::relinkCall(nearCall.dataLocation(), destination.executableAddress());
     853        }
     854
     855        void repatch(CodeLocationDataLabel32 dataLabel32, int32_t value)
     856        {
     857            AssemblerType::repatchInt32(dataLabel32.dataLocation(), value);
     858        }
     859
     860        void repatch(CodeLocationDataLabelPtr dataLabelPtr, void* value)
     861        {
     862            AssemblerType::repatchPointer(dataLabelPtr.dataLocation(), value);
     863        }
     864
     865        void relinkCallerToTrampoline(ProcessorReturnAddress returnAddress, CodeLocationLabel label)
     866        {
     867            relink(CodeLocationCall(CodePtr(returnAddress.m_location)), label);
     868        }
     869       
     870        void relinkCallerToTrampoline(ProcessorReturnAddress returnAddress, CodePtr newCalleeFunction)
     871        {
     872            relinkCallerToTrampoline(returnAddress, CodeLocationLabel(newCalleeFunction));
     873        }
     874
     875        void relinkCallerToFunction(ProcessorReturnAddress returnAddress, FunctionPtr function)
     876        {
     877            relink(CodeLocationCall(CodePtr(returnAddress.m_location)), function);
     878        }
     879       
     880        void relinkNearCallerToTrampoline(ProcessorReturnAddress returnAddress, CodeLocationLabel label)
     881        {
     882            relink(CodeLocationNearCall(CodePtr(returnAddress.m_location)), label);
     883        }
     884       
     885        void relinkNearCallerToTrampoline(ProcessorReturnAddress returnAddress, CodePtr newCalleeFunction)
     886        {
     887            relinkNearCallerToTrampoline(returnAddress, CodeLocationLabel(newCalleeFunction));
     888        }
     889
     890        void repatchLoadPtrToLEA(CodeLocationInstruction instruction)
     891        {
     892            AssemblerType::repatchLoadPtrToLEA(instruction.dataLocation());
     893        }
     894    };
     895
    904896
    905897    // Section 5: Misc admin methods
Note: See TracChangeset for help on using the changeset viewer.