Ignore:
Timestamp:
May 5, 2009, 4:34:23 AM (16 years ago)
Author:
[email protected]
Message:

Bug 25559: Improve native function call performance
<https://bugs.webkit.org/show_bug.cgi?id=25559>

Reviewed by Gavin Barraclough

In order to cache calls to native functions we now make the standard
prototype functions use a small assembly thunk that converts the JS
calling convention into the native calling convention. As this is
only beneficial in the JIT we use the NativeFunctionWrapper typedef
to alternate between PrototypeFunction and JSFunction to keep the
code sane. This change from PrototypeFunction to NativeFunctionWrapper
is the bulk of this patch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/jit/JITStubs.cpp

    r43153 r43220  
    7575    , m_ctiVirtualCallLink(0)
    7676    , m_ctiVirtualCall(0)
    77 {
    78     JIT::compileCTIMachineTrampolines(globalData, &m_executablePool, &m_ctiArrayLengthTrampoline, &m_ctiStringLengthTrampoline, &m_ctiVirtualCallPreLink, &m_ctiVirtualCallLink, &m_ctiVirtualCall);
     77    , m_ctiNativeCallThunk(0)
     78{
     79    JIT::compileCTIMachineTrampolines(globalData, &m_executablePool, &m_ctiArrayLengthTrampoline, &m_ctiStringLengthTrampoline, &m_ctiVirtualCallPreLink, &m_ctiVirtualCallLink, &m_ctiVirtualCall, &m_ctiNativeCallThunk);
    7980}
    8081
     
    820821#endif
    821822
    822     ScopeChainNode* callDataScopeChain = asFunction(ARG_src1)->scope().node();
    823     CodeBlock* newCodeBlock = &asFunction(ARG_src1)->body()->bytecode(callDataScopeChain);
    824 
    825     if (!newCodeBlock->jitCode())
    826         JIT::compile(ARG_globalData, newCodeBlock);
    827 
    828     return newCodeBlock;
     823    JSFunction* function = asFunction(ARG_src1);
     824    FunctionBodyNode* body = function->body();
     825    ScopeChainNode* callDataScopeChain = function->scope().node();
     826    body->jitCode(callDataScopeChain);
     827
     828    return &(body->generatedBytecode());
    829829}
    830830
     
    880880    JSGlobalData* globalData = ARG_globalData;
    881881    JSFunction* callee = asFunction(ARG_src1);
    882     CodeBlock* codeBlock = &callee->body()->bytecode(callee->scope().node());
    883     if (!codeBlock->jitCode())
    884         JIT::compile(globalData, codeBlock);
     882    JITCode jitCode = callee->body()->generatedJITCode();
     883    ASSERT(jitCode);
    885884
    886885    ctiPatchNearCallByReturnAddress(ARG_returnAddress2, globalData->jitStubs.ctiVirtualCallLink());
    887886
    888     return codeBlock->jitCode().addressForCall();
     887    return jitCode.addressForCall();
    889888}
    890889
     
    894893
    895894    JSFunction* callee = asFunction(ARG_src1);
    896     CodeBlock* codeBlock = &callee->body()->bytecode(callee->scope().node());
    897     if (!codeBlock->jitCode())
    898         JIT::compile(ARG_globalData, codeBlock);
     895    JITCode jitCode = callee->body()->generatedJITCode();
     896    ASSERT(jitCode);
     897   
     898    CodeBlock* codeBlock = 0;
     899    if (!callee->isHostFunction())
     900        codeBlock = &callee->body()->bytecode(callee->scope().node());
    899901
    900902    CallLinkInfo* callLinkInfo = &ARG_callFrame->callerFrame()->codeBlock()->getCallLinkInfo(ARG_returnAddress2);
    901     JIT::linkCall(callee, codeBlock, codeBlock->jitCode(), callLinkInfo, ARG_int3);
    902 
    903     return codeBlock->jitCode().addressForCall();
     903    JIT::linkCall(callee, codeBlock, jitCode, callLinkInfo, ARG_int3);
     904
     905    return jitCode.addressForCall();
    904906}
    905907
     
    10601062    BEGIN_STUB_FUNCTION();
    10611063
     1064    JSFunction* constructor = asFunction(ARG_src1);
     1065    if (constructor->isHostFunction()) {
     1066        CallFrame* callFrame = ARG_callFrame;
     1067        CodeBlock* codeBlock = callFrame->codeBlock();
     1068        unsigned vPCIndex = codeBlock->getBytecodeIndex(callFrame, STUB_RETURN_ADDRESS);
     1069        ARG_globalData->exception = createNotAConstructorError(callFrame, constructor, vPCIndex, codeBlock);
     1070        VM_THROW_EXCEPTION();
     1071    }
     1072
    10621073#ifndef NDEBUG
    10631074    ConstructData constructData;
    1064     ASSERT(asFunction(ARG_src1)->getConstructData(constructData) == ConstructTypeJS);
     1075    ASSERT(constructor->getConstructData(constructData) == ConstructTypeJS);
    10651076#endif
    10661077
     
    10691080        structure = asObject(ARG_src4)->inheritorID();
    10701081    else
    1071         structure = asFunction(ARG_src1)->scope().node()->globalObject()->emptyObjectStructure();
     1082        structure = constructor->scope().node()->globalObject()->emptyObjectStructure();
    10721083    return new (ARG_globalData) JSObject(structure);
    10731084}
Note: See TracChangeset for help on using the changeset viewer.