Changeset 40813 in webkit


Ignore:
Timestamp:
Feb 10, 2009 12:43:32 AM (15 years ago)
Author:
barraclough@apple.com
Message:

2009-02-09 Gavin Barraclough <barraclough@apple.com>

Reviewed by Oliver Hunt.

Provide a class type for a generated block of JIT code.
Also changes the return address -> bytecode index map to
track the return addess as an unsigned offset into the code
instead of a ptrdiff_t in terms of voids - the latter is
equal to the actual offset / sizeof(void*), making it a
potentially lossy representation.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::PatchBuffer::returnAddressOffset):
  • assembler/X86Assembler.h: (JSC::X86Assembler::getCallReturnOffset):
  • bytecode/CodeBlock.h: (JSC::CallReturnOffsetToBytecodeIndex::CallReturnOffsetToBytecodeIndex): (JSC::getCallReturnOffset): (JSC::CodeBlock::getBytecodeIndex): (JSC::CodeBlock::jitCode): (JSC::CodeBlock::callReturnIndexVector):
  • interpreter/Interpreter.cpp: (JSC::Interpreter::execute): (JSC::Interpreter::cti_vm_dontLazyLinkCall): (JSC::Interpreter::cti_vm_lazyLinkCall):
  • jit/JIT.cpp: (JSC::JIT::privateCompile):
  • jit/JIT.h: (JSC::):
  • jit/JITCall.cpp: (JSC::JIT::linkCall):
  • jit/JITCode.h: Added. (JSC::): (JSC::JITCode::JITCode): (JSC::JITCode::operator bool): (JSC::JITCode::addressForCall): (JSC::JITCode::offsetOf): (JSC::JITCode::execute):
Location:
trunk/JavaScriptCore
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r40811 r40813  
     12009-02-09  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Provide a class type for a generated block of JIT code.
     6        Also changes the return address -> bytecode index map to
     7        track the return addess as an unsigned offset into the code
     8        instead of a ptrdiff_t in terms of void**s - the latter is
     9        equal to the actual offset / sizeof(void*), making it a
     10        potentially lossy representation.
     11
     12        * JavaScriptCore.xcodeproj/project.pbxproj:
     13        * assembler/AbstractMacroAssembler.h:
     14        (JSC::AbstractMacroAssembler::PatchBuffer::returnAddressOffset):
     15        * assembler/X86Assembler.h:
     16        (JSC::X86Assembler::getCallReturnOffset):
     17        * bytecode/CodeBlock.h:
     18        (JSC::CallReturnOffsetToBytecodeIndex::CallReturnOffsetToBytecodeIndex):
     19        (JSC::getCallReturnOffset):
     20        (JSC::CodeBlock::getBytecodeIndex):
     21        (JSC::CodeBlock::jitCode):
     22        (JSC::CodeBlock::callReturnIndexVector):
     23        * interpreter/Interpreter.cpp:
     24        (JSC::Interpreter::execute):
     25        (JSC::Interpreter::cti_vm_dontLazyLinkCall):
     26        (JSC::Interpreter::cti_vm_lazyLinkCall):
     27        * jit/JIT.cpp:
     28        (JSC::JIT::privateCompile):
     29        * jit/JIT.h:
     30        (JSC::):
     31        * jit/JITCall.cpp:
     32        (JSC::JIT::linkCall):
     33        * jit/JITCode.h: Added.
     34        (JSC::):
     35        (JSC::JITCode::JITCode):
     36        (JSC::JITCode::operator bool):
     37        (JSC::JITCode::addressForCall):
     38        (JSC::JITCode::offsetOf):
     39        (JSC::JITCode::execute):
     40
    1412009-02-09  John Grabowski  <jrg@chromium.org>
    242
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r40678 r40813  
    121121                86CC85A30EE79B7400288682 /* JITCall.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86CC85A20EE79B7400288682 /* JITCall.cpp */; };
    122122                86CC85C40EE7A89400288682 /* JITPropertyAccess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86CC85C30EE7A89400288682 /* JITPropertyAccess.cpp */; };
     123                86CCEFDE0F413F8900FD7F9E /* JITCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 86CCEFDD0F413F8900FD7F9E /* JITCode.h */; };
    123124                905B02AE0E28640F006DF882 /* RefCountedLeakCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 905B02AD0E28640F006DF882 /* RefCountedLeakCounter.cpp */; };
    124125                90D3469C0E285280009492EE /* RefCountedLeakCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = 90D3469B0E285280009492EE /* RefCountedLeakCounter.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    596597                86CC85A20EE79B7400288682 /* JITCall.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITCall.cpp; sourceTree = "<group>"; };
    597598                86CC85C30EE7A89400288682 /* JITPropertyAccess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITPropertyAccess.cpp; sourceTree = "<group>"; };
     599                86CCEFDD0F413F8900FD7F9E /* JITCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITCode.h; sourceTree = "<group>"; };
    598600                905B02AD0E28640F006DF882 /* RefCountedLeakCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCountedLeakCounter.cpp; sourceTree = "<group>"; };
    599601                90D3469B0E285280009492EE /* RefCountedLeakCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCountedLeakCounter.h; sourceTree = "<group>"; };
     
    973975                        isa = PBXGroup;
    974976                        children = (
     977                                86CCEFDD0F413F8900FD7F9E /* JITCode.h */,
    975978                                A7B48DB60EE74CFC00DCBDB6 /* ExecutableAllocator.cpp */,
    976979                                A7B48DB50EE74CFC00DCBDB6 /* ExecutableAllocator.h */,
     
    17311734                                860161E50F3A83C100F84710 /* MacroAssemblerX86_64.h in Headers */,
    17321735                                860161E60F3A83C100F84710 /* MacroAssemblerX86Common.h in Headers */,
     1736                                86CCEFDE0F413F8900FD7F9E /* JITCode.h in Headers */,
    17331737                        );
    17341738                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h

    r40660 r40813  
    359359        }
    360360
     361        ptrdiff_t returnAddressOffset(Jump call)
     362        {
     363            return AssemblerType::getCallReturnOffset(call.m_jmp);
     364        }
     365
    361366        void setPtr(DataLabelPtr label, void* value)
    362367        {
  • trunk/JavaScriptCore/assembler/X86Assembler.h

    r40562 r40813  
    12471247    }
    12481248   
     1249    static ptrdiff_t getCallReturnOffset(JmpSrc call)
     1250    {
     1251        return call.m_offset;
     1252    }
     1253
    12491254    static void* getRelocatedAddress(void* code, JmpSrc jump)
    12501255    {
  • trunk/JavaScriptCore/bytecode/CodeBlock.h

    r40046 r40813  
    3333#include "EvalCodeCache.h"
    3434#include "Instruction.h"
     35#include "JITCode.h"
    3536#include "JSGlobalObject.h"
    3637#include "JumpTable.h"
     
    6667    // The code, and the associated pool from which it was allocated.
    6768    struct JITCodeRef {
    68         void* code;
     69        JITCode code;
    6970#ifndef NDEBUG
    7071        unsigned codeSize;
     
    162163    };
    163164
    164     struct PC {
    165         PC(ptrdiff_t nativePCOffset, unsigned bytecodeIndex)
    166             : nativePCOffset(nativePCOffset)
     165    // This structure is used to map from a call return location
     166    // (given as an offset in bytes into the JIT code) back to
     167    // the bytecode index of the corresponding bytecode operation.
     168    // This is then used to look up the corresponding handler.
     169    struct CallReturnOffsetToBytecodeIndex {
     170        CallReturnOffsetToBytecodeIndex(unsigned callReturnOffset, unsigned bytecodeIndex)
     171            : callReturnOffset(callReturnOffset)
    167172            , bytecodeIndex(bytecodeIndex)
    168173        {
    169174        }
    170175
    171         ptrdiff_t nativePCOffset;
     176        unsigned callReturnOffset;
    172177        unsigned bytecodeIndex;
    173178    };
     
    185190    }
    186191
    187     inline ptrdiff_t getNativePCOffset(PC* pc)
     192    inline unsigned getCallReturnOffset(CallReturnOffsetToBytecodeIndex* pc)
    188193    {
    189         return pc->nativePCOffset;
     194        return pc->callReturnOffset;
    190195    }
    191196
     
    312317        {
    313318            reparseForExceptionInfoIfNecessary(callFrame);
    314             ptrdiff_t nativePCOffset = reinterpret_cast<void**>(nativePC) - reinterpret_cast<void**>(m_jitCode.code);
    315             return binaryChop<PC, ptrdiff_t, getNativePCOffset>(m_exceptionInfo->m_pcVector.begin(), m_exceptionInfo->m_pcVector.size(), nativePCOffset)->bytecodeIndex;
     319            return binaryChop<CallReturnOffsetToBytecodeIndex, unsigned, getCallReturnOffset>(m_exceptionInfo->m_callReturnIndexVector.begin(), m_exceptionInfo->m_callReturnIndexVector.size(), m_jitCode.code.offsetOf(nativePC))->bytecodeIndex;
    316320        }
    317321
     
    326330#if ENABLE(JIT)
    327331        void setJITCode(JITCodeRef& jitCode);
    328         void* jitCode() { return m_jitCode.code; }
     332        JITCode jitCode() { return m_jitCode.code; }
    329333        ExecutablePool* executablePool() { return m_jitCode.executablePool.get(); }
    330334#endif
     
    391395
    392396#if ENABLE(JIT)
    393         Vector<PC>& pcVector() { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_pcVector; }
     397        Vector<CallReturnOffsetToBytecodeIndex>& callReturnIndexVector() { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_callReturnIndexVector; }
    394398#endif
    395399
     
    511515
    512516#if ENABLE(JIT)
    513             Vector<PC> m_pcVector;
     517            Vector<CallReturnOffsetToBytecodeIndex> m_callReturnIndexVector;
    514518#endif
    515519        };
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r40396 r40813  
    866866        if (!codeBlock->jitCode())
    867867            JIT::compile(scopeChain->globalData, codeBlock);
    868         result = JIT::execute(codeBlock->jitCode(), &m_registerFile, newCallFrame, scopeChain->globalData, exception);
     868        result = codeBlock->jitCode().execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
    869869#else
    870870        result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
     
    932932        if (!codeBlock->jitCode())
    933933            JIT::compile(scopeChain->globalData, codeBlock);
    934         result = JIT::execute(codeBlock->jitCode(), &m_registerFile, newCallFrame, scopeChain->globalData, exception);
     934        result = codeBlock->jitCode().execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
    935935#else
    936936        result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
     
    10241024        if (!codeBlock->jitCode())
    10251025            JIT::compile(scopeChain->globalData, codeBlock);
    1026         result = JIT::execute(codeBlock->jitCode(), &m_registerFile, newCallFrame, scopeChain->globalData, exception);
     1026        result = codeBlock->jitCode().execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
    10271027#else
    10281028        result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
     
    48304830    ctiPatchCallByReturnAddress(ARG_returnAddress2, ARG_globalData->interpreter->m_ctiVirtualCallLink);
    48314831
    4832     return codeBlock->jitCode();
     4832    return codeBlock->jitCode().addressForCall();
    48334833}
    48344834
     
    48454845    JIT::linkCall(callee, codeBlock, codeBlock->jitCode(), callLinkInfo, ARG_int3);
    48464846
    4847     return codeBlock->jitCode();
     4847    return codeBlock->jitCode().addressForCall();
    48484848}
    48494849
  • trunk/JavaScriptCore/jit/JIT.cpp

    r40562 r40813  
    17091709
    17101710    if (m_codeBlock->hasExceptionInfo()) {
    1711         m_codeBlock->pcVector().reserveCapacity(m_calls.size());
     1711        m_codeBlock->callReturnIndexVector().reserveCapacity(m_calls.size());
    17121712        for (Vector<CallRecord>::iterator iter = m_calls.begin(); iter != m_calls.end(); ++iter)
    1713             m_codeBlock->pcVector().append(PC(reinterpret_cast<void**>(patchBuffer.addressOf(iter->from)) - reinterpret_cast<void**>(code), iter->bytecodeIndex));
     1713            m_codeBlock->callReturnIndexVector().append(CallReturnOffsetToBytecodeIndex(patchBuffer.returnAddressOffset(iter->from), iter->bytecodeIndex));
    17141714    }
    17151715
  • trunk/JavaScriptCore/jit/JIT.h

    r40004 r40813  
    2828
    2929#include <wtf/Platform.h>
    30 #include <bytecode/SamplingTool.h>
    3130
    3231#if ENABLE(JIT)
     
    3534
    3635#include "Interpreter.h"
     36#include "JITCode.h"
    3737#include "Opcode.h"
    3838#include "RegisterFile.h"
    3939#include "MacroAssembler.h"
    4040#include "Profiler.h"
     41#include <bytecode/SamplingTool.h>
    4142#include <wtf/AlwaysInline.h>
    4243#include <wtf/Vector.h>
     
    201202
    202203    extern "C" {
    203         JSValueEncodedAsPointer* ctiTrampoline(
    204 #if PLATFORM(X86_64)
    205             // FIXME: (bug #22910) this will force all arguments onto the stack (regparm(0) does not appear to have any effect).
    206             // We can allow register passing here, and move the writes of these values into the trampoline.
    207             void*, void*, void*, void*, void*, void*,
    208 #endif
    209             void* code, RegisterFile*, CallFrame*, JSValuePtr* exception, Profiler**, JSGlobalData*);
    210204        void ctiVMThrowTrampoline();
    211205    };
     
    348342        }
    349343
    350         static void linkCall(JSFunction* callee, CodeBlock* calleeCodeBlock, void* ctiCode, CallLinkInfo* callLinkInfo, int callerArgCount);
     344        static void linkCall(JSFunction* callee, CodeBlock* calleeCodeBlock, JITCode ctiCode, CallLinkInfo* callLinkInfo, int callerArgCount);
    351345        static void unlinkCall(CallLinkInfo*);
    352 
    353         inline static JSValuePtr execute(void* code, RegisterFile* registerFile, CallFrame* callFrame, JSGlobalData* globalData, JSValuePtr* exception)
    354         {
    355             return JSValuePtr::decode(ctiTrampoline(
    356 #if PLATFORM(X86_64)
    357                 0, 0, 0, 0, 0, 0,
    358 #endif
    359                 code, registerFile, callFrame, exception, Profiler::enabledProfilerReference(), globalData));
    360         }
    361346
    362347    private:
  • trunk/JavaScriptCore/jit/JITCall.cpp

    r40562 r40813  
    5353}
    5454
    55 void JIT::linkCall(JSFunction* callee, CodeBlock* calleeCodeBlock, void* ctiCode, CallLinkInfo* callLinkInfo, int callerArgCount)
     55void JIT::linkCall(JSFunction* callee, CodeBlock* calleeCodeBlock, JITCode ctiCode, CallLinkInfo* callLinkInfo, int callerArgCount)
    5656{
    5757    // Currently we only link calls with the exact number of arguments.
     
    6262   
    6363        DataLabelPtr::patch(callLinkInfo->hotPathBegin, callee);
    64         Jump::patch(callLinkInfo->hotPathOther, ctiCode);
     64        Jump::patch(callLinkInfo->hotPathOther, ctiCode.addressForCall());
    6565    }
    6666
Note: See TracChangeset for help on using the changeset viewer.