Ignore:
Timestamp:
Jun 5, 2009, 12:55:38 AM (16 years ago)
Author:
[email protected]
Message:

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

Reviewed by Oliver Hunt.

Encapsulate many uses of void* in the assembler & jit with types that provide
more semantic information. The new types are:


  • MacroAssemblerCodePtr - this wraps a pointer into JIT generated code.
  • FunctionPtr - this wraps a pointer to a C/C++ function in JSC.
  • ReturnAddressPtr - this wraps a return address resulting from a 'call' instruction.

Wrapping these types allows for stronger type-checking than is possible with everything
represented a void*. For example, it is now enforced by the type system that near
calls can only be linked to JIT code and not to C functions in JSC (this was previously
required, but could not be enforced on the interface).

  • assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::CodeLocationCommon::CodeLocationCommon): (JSC::AbstractMacroAssembler::CodeLocationCommon::dataLocation): (JSC::AbstractMacroAssembler::CodeLocationCommon::executableAddress): (JSC::AbstractMacroAssembler::CodeLocationCommon::reset): (JSC::AbstractMacroAssembler::CodeLocationInstruction::repatchLoadToLEA): (JSC::AbstractMacroAssembler::CodeLocationInstruction::CodeLocationInstruction): (JSC::AbstractMacroAssembler::CodeLocationLabel::addressForSwitch): (JSC::AbstractMacroAssembler::CodeLocationLabel::addressForExceptionHandler): (JSC::AbstractMacroAssembler::CodeLocationLabel::addressForJSR): (JSC::AbstractMacroAssembler::CodeLocationLabel::operator!): (JSC::AbstractMacroAssembler::CodeLocationLabel::reset): (JSC::AbstractMacroAssembler::CodeLocationLabel::CodeLocationLabel): (JSC::AbstractMacroAssembler::CodeLocationLabel::getJumpDestination): (JSC::AbstractMacroAssembler::CodeLocationJump::relink): (JSC::AbstractMacroAssembler::CodeLocationJump::CodeLocationJump): (JSC::AbstractMacroAssembler::CodeLocationCall::relink): (JSC::AbstractMacroAssembler::CodeLocationCall::calleeReturnAddressValue): (JSC::AbstractMacroAssembler::CodeLocationCall::CodeLocationCall): (JSC::AbstractMacroAssembler::CodeLocationNearCall::relink): (JSC::AbstractMacroAssembler::CodeLocationNearCall::calleeReturnAddressValue): (JSC::AbstractMacroAssembler::CodeLocationNearCall::CodeLocationNearCall): (JSC::AbstractMacroAssembler::CodeLocationDataLabel32::repatch): (JSC::AbstractMacroAssembler::CodeLocationDataLabel32::CodeLocationDataLabel32): (JSC::AbstractMacroAssembler::CodeLocationDataLabelPtr::repatch): (JSC::AbstractMacroAssembler::CodeLocationDataLabelPtr::CodeLocationDataLabelPtr): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::relinkCallerToTrampoline): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::relinkCallerToFunction): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::relinkNearCallerToTrampoline): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::addressForLookup): (JSC::AbstractMacroAssembler::trampolineAt): (JSC::AbstractMacroAssembler::PatchBuffer::link): (JSC::AbstractMacroAssembler::PatchBuffer::performFinalization): (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::FunctionPtr::FunctionPtr): (JSC::FunctionPtr::value): (JSC::FunctionPtr::executableAddress): (JSC::ReturnAddressPtr::ReturnAddressPtr): (JSC::ReturnAddressPtr::value): (JSC::MacroAssemblerCodePtr::MacroAssemblerCodePtr): (JSC::MacroAssemblerCodePtr::executableAddress): (JSC::MacroAssemblerCodePtr::dataLocation): (JSC::MacroAssemblerCodeRef::MacroAssemblerCodeRef):
  • assembler/X86Assembler.h: (JSC::X86Assembler::patchPointerForCall):
  • jit/JIT.cpp: (JSC::ctiPatchNearCallByReturnAddress): (JSC::ctiPatchCallByReturnAddress): (JSC::JIT::privateCompile): (JSC::JIT::privateCompileCTIMachineTrampolines):
  • jit/JIT.h: (JSC::JIT::compileCTIMachineTrampolines):
  • jit/JITCall.cpp: (JSC::JIT::compileOpCall):
  • jit/JITCode.h: (JSC::JITCode::operator !): (JSC::JITCode::addressForCall): (JSC::JITCode::offsetOf): (JSC::JITCode::execute): (JSC::JITCode::size): (JSC::JITCode::HostFunction):
  • jit/JITInlineMethods.h: (JSC::JIT::emitNakedCall):
  • jit/JITPropertyAccess.cpp: (JSC::JIT::privateCompilePutByIdTransition): (JSC::JIT::patchGetByIdSelf): (JSC::JIT::patchPutByIdReplace): (JSC::JIT::privateCompilePatchGetArrayLength): (JSC::JIT::privateCompileGetByIdProto): (JSC::JIT::privateCompileGetByIdChain):
  • jit/JITStubs.cpp: (JSC::JITThunks::JITThunks): (JSC::JITThunks::tryCachePutByID): (JSC::JITThunks::tryCacheGetByID): (JSC::JITStubs::DEFINE_STUB_FUNCTION):
  • jit/JITStubs.h: (JSC::JITThunks::ctiArrayLengthTrampoline): (JSC::JITThunks::ctiStringLengthTrampoline): (JSC::JITThunks::ctiVirtualCallPreLink): (JSC::JITThunks::ctiVirtualCallLink): (JSC::JITThunks::ctiVirtualCall): (JSC::JITThunks::ctiNativeCallThunk):
  • yarr/RegexJIT.h: (JSC::Yarr::RegexCodeBlock::operator!): (JSC::Yarr::RegexCodeBlock::execute):
File:
1 edited

Legend:

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

    r44030 r44455  
    3838namespace JSC {
    3939
     40// FunctionPtr:
     41//
     42// FunctionPtr should be used to wrap pointers to C/C++ functions in JSC
     43// (particularly, the stub functions).
     44class FunctionPtr {
     45public:
     46    FunctionPtr()
     47        : m_value(0)
     48    {
     49    }
     50
     51    template<typename FunctionType>
     52    explicit FunctionPtr(FunctionType* value)
     53        : m_value(reinterpret_cast<void*>(value))
     54    {
     55        ASSERT(m_value);
     56    }
     57
     58    void* value() const { return m_value; }
     59    void* executableAddress() const { return m_value; }
     60
     61
     62private:
     63    void* m_value;
     64};
     65
     66// ReturnAddressPtr:
     67//
     68// ReturnAddressPtr should be used to wrap return addresses generated by processor
     69// 'call' instructions exectued in JIT code.  We use return addresses to look up
     70// exception and optimization information, and to repatch the call instruction
     71// that is the source of the return address.
     72class ReturnAddressPtr {
     73public:
     74    ReturnAddressPtr()
     75        : m_value(0)
     76    {
     77    }
     78
     79    explicit ReturnAddressPtr(void* value)
     80        : m_value(value)
     81    {
     82        ASSERT(m_value);
     83    }
     84
     85    void* value() const { return m_value; }
     86
     87private:
     88    void* m_value;
     89};
     90
     91// MacroAssemblerCodePtr:
     92//
     93// MacroAssemblerCodePtr should be used to wrap pointers to JIT generated code.
     94class MacroAssemblerCodePtr {
     95public:
     96    MacroAssemblerCodePtr()
     97        : m_value(0)
     98    {
     99    }
     100
     101    explicit MacroAssemblerCodePtr(void* value)
     102        : m_value(value)
     103    {
     104        ASSERT(m_value);
     105    }
     106
     107    explicit MacroAssemblerCodePtr(ReturnAddressPtr ra)
     108        : m_value(ra.value())
     109    {
     110        ASSERT(m_value);
     111    }
     112
     113    void* executableAddress() const { return m_value; }
     114    void* dataLocation() const { ASSERT(m_value); return m_value; }
     115
     116private:
     117    void* m_value;
     118};
     119
    40120// MacroAssemblerCodeRef:
    41121//
     
    46126public:
    47127    MacroAssemblerCodeRef()
    48         : m_code(0)
    49128#ifndef NDEBUG
    50         , m_size(0)
     129        : m_size(0)
    51130#endif
    52131    {
     
    64143    }
    65144
    66     void* m_code;
     145    MacroAssemblerCodePtr m_code;
    67146    RefPtr<ExecutablePool> m_executablePool;
    68147#ifndef NDEBUG
Note: See TracChangeset for help on using the changeset viewer.