Ignore:
Timestamp:
Jun 15, 2009, 10:35:32 PM (16 years ago)
Author:
[email protected]
Message:

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

Reviewed by Sam Weinig.

Having moved most of their functionality into the RepatchBuffer class,
we can simplify the CodeLocation* classes.

The CodeLocation* classes are currently a tangle of templatey and friendly
badness, burried in the middle of AbstractMacroAssembler. Having moved
the ability to repatch out into RepatchBufer they are now do-nothing wrappers
on CodePtr (MacroAssemblerCodePtr), that only exist to provide type-safety.

Simplify the code, and move them off into their own header.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::PatchBuffer::patch):
  • assembler/CodeLocation.h: Copied from assembler/AbstractMacroAssembler.h. (JSC::CodeLocationCommon::CodeLocationCommon): (JSC::CodeLocationInstruction::CodeLocationInstruction): (JSC::CodeLocationLabel::CodeLocationLabel): (JSC::CodeLocationJump::CodeLocationJump): (JSC::CodeLocationCall::CodeLocationCall): (JSC::CodeLocationNearCall::CodeLocationNearCall): (JSC::CodeLocationDataLabel32::CodeLocationDataLabel32): (JSC::CodeLocationDataLabelPtr::CodeLocationDataLabelPtr): (JSC::CodeLocationCommon::instructionAtOffset): (JSC::CodeLocationCommon::labelAtOffset): (JSC::CodeLocationCommon::jumpAtOffset): (JSC::CodeLocationCommon::callAtOffset): (JSC::CodeLocationCommon::nearCallAtOffset): (JSC::CodeLocationCommon::dataLabelPtrAtOffset): (JSC::CodeLocationCommon::dataLabel32AtOffset):
  • assembler/MacroAssemblerCodeRef.h: (JSC::MacroAssemblerCodePtr::operator!):
  • bytecode/CodeBlock.h: (JSC::getStructureStubInfoReturnLocation): (JSC::getCallLinkInfoReturnLocation): (JSC::getMethodCallLinkInfoReturnLocation):
  • bytecode/Instruction.h:
  • bytecode/JumpTable.h: (JSC::StringJumpTable::ctiForValue): (JSC::SimpleJumpTable::ctiForValue):
  • bytecode/StructureStubInfo.h:
  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitCatch):
  • jit/JIT.cpp: (JSC::JIT::privateCompile):
  • jit/JITStubs.cpp: (JSC::JITStubs::DEFINE_STUB_FUNCTION): (JSC::JITStubs::getPolymorphicAccessStructureListSlot):
File:
1 edited

Legend:

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

    r44705 r44711  
    3030
    3131#include <MacroAssemblerCodeRef.h>
     32#include <CodeLocation.h>
    3233#include <wtf/Noncopyable.h>
    3334#include <wtf/UnusedParam.h>
     
    5152    class PatchBuffer;
    5253    class RepatchBuffer;
    53     class CodeLocationInstruction;
    54     class CodeLocationLabel;
    55     class CodeLocationJump;
    56     class CodeLocationCall;
    57     class CodeLocationNearCall;
    58     class CodeLocationDataLabel32;
    59     class CodeLocationDataLabelPtr;
    6054
    6155    typedef typename AssemblerType::RegisterID RegisterID;
     
    413407
    414408
    415     // Section 3: MacroAssembler JIT instruction stream handles.
    416     //
    417     // The MacroAssembler supported facilities to modify a JIT generated
    418     // instruction stream after it has been generated (relinking calls and
    419     // jumps, and repatching data values).  The following types are used
    420     // to store handles into the underlying instruction stream, the type
    421     // providing semantic information as to what it is that is in the
    422     // instruction stream at this point, and thus what operations may be
    423     // performed on it.
    424 
    425 
    426     // CodeLocationCommon:
    427     //
    428     // Base type for other CodeLocation* types.  A postion in the JIT genertaed
    429     // instruction stream, without any semantic information.
    430     class CodeLocationCommon {
    431         friend class RepatchBuffer;
    432 
    433     public:
    434         CodeLocationCommon()
    435         {
    436         }
    437 
    438         // In order to avoid the need to store multiple handles into the
    439         // instructions stream, where the code generation is deterministic
    440         // and the labels will always be a fixed distance apart, these
    441         // methods may be used to recover a handle that has nopw been
    442         // retained, based on a known fixed relative offset from one that has.
    443         CodeLocationInstruction instructionAtOffset(int offset);
    444         CodeLocationLabel labelAtOffset(int offset);
    445         CodeLocationJump jumpAtOffset(int offset);
    446         CodeLocationCall callAtOffset(int offset);
    447         CodeLocationNearCall nearCallAtOffset(int offset);
    448         CodeLocationDataLabelPtr dataLabelPtrAtOffset(int offset);
    449         CodeLocationDataLabel32 dataLabel32AtOffset(int offset);
    450 
    451     protected:
    452         explicit CodeLocationCommon(CodePtr location)
    453             : m_location(location)
    454         {
    455         }
    456 
    457         void* dataLocation() { return m_location.dataLocation(); }
    458         void* executableAddress() { return m_location.executableAddress(); }
    459    
    460         void reset()
    461         {
    462             m_location = CodePtr();
    463         }
    464 
    465     private:
    466         CodePtr m_location;
    467     };
    468 
    469     // CodeLocationInstruction:
    470     //
    471     // An arbitrary instruction in the JIT code.
    472     class CodeLocationInstruction : public CodeLocationCommon {
    473     public:
    474         CodeLocationInstruction()
    475         {
    476         }
    477 
    478         explicit CodeLocationInstruction(void* location)
    479             : CodeLocationCommon(CodePtr(location))
    480         {
    481         }
    482     };
    483 
    484     // CodeLocationLabel:
    485     //
    486     // A point in the JIT code maked with a label.
    487     class CodeLocationLabel : public CodeLocationCommon {
    488         friend class CodeLocationCommon;
    489         friend class CodeLocationJump;
    490         friend class CodeLocationCall;
    491         friend class CodeLocationNearCall;
    492         friend class PatchBuffer;
    493         friend class RepatchBuffer;
    494 
    495     public:
    496         CodeLocationLabel()
    497         {
    498         }
    499 
    500         void* addressForSwitch() { return this->executableAddress(); }
    501         void* addressForExceptionHandler() { return this->executableAddress(); }
    502         void* addressForJSR() { return this->executableAddress(); }
    503 
    504         bool operator!()
    505         {
    506             return !this->executableAddress();
    507         }
    508 
    509         void reset()
    510         {
    511             CodeLocationCommon::reset();
    512         }
    513 
    514     private:
    515         explicit CodeLocationLabel(CodePtr location)
    516             : CodeLocationCommon(location)
    517         {
    518         }
    519 
    520         explicit CodeLocationLabel(void* location)
    521             : CodeLocationCommon(CodePtr(location))
    522         {
    523         }
    524 
    525         void* getJumpDestination() { return this->executableAddress(); }
    526     };
    527 
    528     // CodeLocationJump:
    529     //
    530     // A point in the JIT code at which there is a jump instruction.
    531     class CodeLocationJump : public CodeLocationCommon {
    532         friend class CodeLocationCommon;
    533         friend class PatchBuffer;
    534     public:
    535         CodeLocationJump()
    536         {
    537         }
    538 
    539         explicit CodeLocationJump(void* location)
    540             : CodeLocationCommon(CodePtr(location))
    541         {
    542         }
    543     };
    544 
    545     // CodeLocationCall:
    546     //
    547     // A point in the JIT code at which there is a call instruction.
    548     class CodeLocationCall : public CodeLocationCommon {
    549     public:
    550         CodeLocationCall()
    551         {
    552         }
    553 
    554         explicit CodeLocationCall(CodePtr location)
    555             : CodeLocationCommon(location)
    556         {
    557         }
    558 
    559         explicit CodeLocationCall(void* location)
    560             : CodeLocationCommon(CodePtr(location))
    561         {
    562         }
    563 
    564         // This methods returns the value that will be set as the return address
    565         // within a function that has been called from this call instruction.
    566         void* calleeReturnAddressValue()
    567         {
    568             return this->executableAddress();
    569         }
    570 
    571     };
    572 
    573     // CodeLocationNearCall:
    574     //
    575     // A point in the JIT code at which there is a call instruction with near linkage.
    576     class CodeLocationNearCall : public CodeLocationCommon {
    577     public:
    578         CodeLocationNearCall()
    579         {
    580         }
    581 
    582         explicit CodeLocationNearCall(CodePtr location)
    583             : CodeLocationCommon(location)
    584         {
    585         }
    586 
    587         explicit CodeLocationNearCall(void* location)
    588             : CodeLocationCommon(CodePtr(location))
    589         {
    590         }
    591 
    592         // This methods returns the value that will be set as the return address
    593         // within a function that has been called from this call instruction.
    594         void* calleeReturnAddressValue()
    595         {
    596             return this->executableAddress();
    597         }
    598     };
    599 
    600     // CodeLocationDataLabel32:
    601     //
    602     // A point in the JIT code at which there is an int32_t immediate that may be repatched.
    603     class CodeLocationDataLabel32 : public CodeLocationCommon {
    604     public:
    605         CodeLocationDataLabel32()
    606         {
    607         }
    608 
    609         explicit CodeLocationDataLabel32(void* location)
    610             : CodeLocationCommon(CodePtr(location))
    611         {
    612         }
    613     };
    614 
    615     // CodeLocationDataLabelPtr:
    616     //
    617     // A point in the JIT code at which there is a void* immediate that may be repatched.
    618     class CodeLocationDataLabelPtr : public CodeLocationCommon {
    619     public:
    620         CodeLocationDataLabelPtr()
    621         {
    622         }
    623 
    624         explicit CodeLocationDataLabelPtr(void* location)
    625             : CodeLocationCommon(CodePtr(location))
    626         {
    627         }
    628     };
    629 
    630 
    631     // Section 4: PatchBuffer - utility to finalize code generation.
     409    // Section 3: PatchBuffer - utility to finalize code generation.
    632410
    633411    static CodePtr trampolineAt(CodeRef ref, Label label)
     
    705483        void patch(DataLabelPtr label, CodeLocationLabel value)
    706484        {
    707             AssemblerType::patchPointer(code(), label.m_label, value.getJumpDestination());
     485            AssemblerType::patchPointer(code(), label.m_label, value.executableAddress());
    708486        }
    709487
     
    875653
    876654
    877     // Section 5: Misc admin methods
     655    // Section 4: Misc admin methods
    878656
    879657    size_t size()
     
    937715};
    938716
    939 
    940 template <class AssemblerType>
    941 typename AbstractMacroAssembler<AssemblerType>::CodeLocationInstruction AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::instructionAtOffset(int offset)
    942 {
    943     return typename AbstractMacroAssembler::CodeLocationInstruction(reinterpret_cast<char*>(dataLocation()) + offset);
    944 }
    945 
    946 template <class AssemblerType>
    947 typename AbstractMacroAssembler<AssemblerType>::CodeLocationLabel AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::labelAtOffset(int offset)
    948 {
    949     return typename AbstractMacroAssembler::CodeLocationLabel(reinterpret_cast<char*>(dataLocation()) + offset);
    950 }
    951 
    952 template <class AssemblerType>
    953 typename AbstractMacroAssembler<AssemblerType>::CodeLocationJump AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::jumpAtOffset(int offset)
    954 {
    955     return typename AbstractMacroAssembler::CodeLocationJump(reinterpret_cast<char*>(dataLocation()) + offset);
    956 }
    957 
    958 template <class AssemblerType>
    959 typename AbstractMacroAssembler<AssemblerType>::CodeLocationCall AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::callAtOffset(int offset)
    960 {
    961     return typename AbstractMacroAssembler::CodeLocationCall(reinterpret_cast<char*>(dataLocation()) + offset);
    962 }
    963 
    964 template <class AssemblerType>
    965 typename AbstractMacroAssembler<AssemblerType>::CodeLocationNearCall AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::nearCallAtOffset(int offset)
    966 {
    967     return typename AbstractMacroAssembler::CodeLocationNearCall(reinterpret_cast<char*>(dataLocation()) + offset);
    968 }
    969 
    970 template <class AssemblerType>
    971 typename AbstractMacroAssembler<AssemblerType>::CodeLocationDataLabelPtr AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::dataLabelPtrAtOffset(int offset)
    972 {
    973     return typename AbstractMacroAssembler::CodeLocationDataLabelPtr(reinterpret_cast<char*>(dataLocation()) + offset);
    974 }
    975 
    976 template <class AssemblerType>
    977 typename AbstractMacroAssembler<AssemblerType>::CodeLocationDataLabel32 AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::dataLabel32AtOffset(int offset)
    978 {
    979     return typename AbstractMacroAssembler::CodeLocationDataLabel32(reinterpret_cast<char*>(dataLocation()) + offset);
    980 }
    981 
    982717} // namespace JSC
    983718
Note: See TracChangeset for help on using the changeset viewer.