Changeset 38209 in webkit for trunk/JavaScriptCore/VM/Machine.cpp


Ignore:
Timestamp:
Nov 6, 2008, 5:30:03 PM (17 years ago)
Author:
[email protected]
Message:

2008-11-06 Gavin Barraclough [email protected]

Reviewed by Oliver Hunt.

Do not make a cti_* call to perform an op_call unless either:
(1) The codeblock for the function body has not been generated.
(2) The number of arguments passed does not match the callee arity.

~1% progression on sunspider --v8

  • VM/CTI.cpp: (JSC::CTI::compileOpCallInitializeCallFrame): (JSC::CTI::compileOpCall): (JSC::CTI::privateCompileSlowCases):
  • VM/CTI.h:
  • VM/Machine.cpp: (JSC::Machine::cti_op_call_JSFunction): (JSC::Machine::cti_op_call_arityCheck): (JSC::Machine::cti_op_construct_JSConstruct):
  • VM/Machine.h:
  • kjs/nodes.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/Machine.cpp

    r38148 r38209  
    47094709}
    47104710
    4711 VoidPtrPair Machine::cti_op_call_JSFunction(CTI_ARGS)
     4711void* Machine::cti_op_call_JSFunction(CTI_ARGS)
    47124712{
    47134713    CTI_STACK_HACK();
     
    47204720    ScopeChainNode* callDataScopeChain = asFunction(ARG_src1)->m_scopeChain.node();
    47214721    CodeBlock* newCodeBlock = &asFunction(ARG_src1)->m_body->byteCode(callDataScopeChain);
    4722     CallFrame* callFrame = ARG_callFrame;
    4723     size_t registerOffset = ARG_int2;
     4722
     4723    if (!newCodeBlock->ctiCode)
     4724        CTI::compile(ARG_globalData->machine, ARG_callFrame, newCodeBlock);
     4725
     4726    return newCodeBlock;
     4727}
     4728
     4729VoidPtrPair Machine::cti_op_call_arityCheck(CTI_ARGS)
     4730{
     4731    CTI_STACK_HACK();
     4732
     4733    CallFrame* callFrame = ARG_callFrame;
     4734    CodeBlock* newCodeBlock = ARG_codeBlock4;
    47244735    int argCount = ARG_int3;
    47254736
    4726     if (LIKELY(argCount == newCodeBlock->numParameters)) {
    4727         VoidPtrPairValue pair = {{ newCodeBlock, CallFrame::create(callFrame->registers() + registerOffset) }};
    4728         return pair.i;
    4729     }
     4737    ASSERT(argCount != newCodeBlock->numParameters);
     4738
     4739    CallFrame* oldCallFrame = callFrame->callerFrame();
    47304740
    47314741    if (argCount > newCodeBlock->numParameters) {
    47324742        size_t numParameters = newCodeBlock->numParameters;
    4733         Register* r = callFrame->registers() + registerOffset + numParameters;
     4743        Register* r = callFrame->registers() + numParameters;
    47344744
    47354745        Register* argv = r - RegisterFile::CallFrameHeaderSize - numParameters - argCount;
     
    47374747            argv[i + argCount] = argv[i];
    47384748
    4739         VoidPtrPairValue pair = {{ newCodeBlock, CallFrame::create(r) }};
    4740         return pair.i;
    4741     }
    4742 
    4743     size_t omittedArgCount = newCodeBlock->numParameters - argCount;
    4744     Register* r = callFrame->registers() + registerOffset + omittedArgCount;
    4745     Register* newEnd = r + newCodeBlock->numCalleeRegisters;
    4746     if (!ARG_registerFile->grow(newEnd)) {
    4747         ARG_globalData->exception = createStackOverflowError(callFrame);
    4748         VM_THROW_EXCEPTION_2();
    4749     }
    4750 
    4751     Register* argv = r - RegisterFile::CallFrameHeaderSize - omittedArgCount;
    4752     for (size_t i = 0; i < omittedArgCount; ++i)
    4753         argv[i] = jsUndefined();
    4754 
    4755     VoidPtrPairValue pair = {{ newCodeBlock, CallFrame::create(r) }};
     4749        callFrame = CallFrame::create(r);
     4750        callFrame->setCallerFrame(oldCallFrame);
     4751    } else {
     4752        size_t omittedArgCount = newCodeBlock->numParameters - argCount;
     4753        Register* r = callFrame->registers() + omittedArgCount;
     4754        Register* newEnd = r + newCodeBlock->numCalleeRegisters;
     4755        if (!ARG_registerFile->grow(newEnd)) {
     4756            ARG_globalData->exception = createStackOverflowError(oldCallFrame);
     4757            VM_THROW_EXCEPTION_2();
     4758        }
     4759
     4760        Register* argv = r - RegisterFile::CallFrameHeaderSize - omittedArgCount;
     4761        for (size_t i = 0; i < omittedArgCount; ++i)
     4762            argv[i] = jsUndefined();
     4763
     4764        callFrame = CallFrame::create(r);
     4765        callFrame->setCallerFrame(oldCallFrame);
     4766    }
     4767
     4768    VoidPtrPairValue pair = {{ newCodeBlock, callFrame }};
    47564769    return pair.i;
    47574770}
     
    47714784    CTI::linkCall(callee, codeBlock, codeBlock->ctiCode, ARG_linkInfo2, ARG_int3);
    47724785
    4773     return codeBlock->ctiCode;
    4774 }
    4775 
    4776 void* Machine::cti_vm_compile(CTI_ARGS)
    4777 {
    4778     CTI_STACK_HACK();
    4779 
    4780     CodeBlock* codeBlock = ARG_callFrame->codeBlock();
    4781     if (!codeBlock->ctiCode)
    4782         CTI::compile(ARG_globalData->machine, ARG_callFrame, codeBlock);
    47834786    return codeBlock->ctiCode;
    47844787}
     
    49344937}
    49354938
    4936 JSObject* Machine::cti_op_construct_JSConstructFast(CTI_ARGS)
     4939JSObject* Machine::cti_op_construct_JSConstruct(CTI_ARGS)
    49374940{
    49384941    CTI_STACK_HACK();
     
    49444947
    49454948    StructureID* structure;
    4946     if (ARG_src2->isObject())
    4947         structure = asObject(ARG_src2)->inheritorID();
     4949    if (ARG_src5->isObject())
     4950        structure = asObject(ARG_src5)->inheritorID();
    49484951    else
    49494952        structure = asFunction(ARG_src1)->m_scopeChain.node()->globalObject()->emptyObjectStructure();
    49504953    return new (ARG_globalData) JSObject(structure);
    4951 }
    4952 
    4953 VoidPtrPair Machine::cti_op_construct_JSConstruct(CTI_ARGS)
    4954 {
    4955     CTI_STACK_HACK();
    4956 
    4957     CallFrame* callFrame = ARG_callFrame;
    4958 
    4959     JSFunction* constructor = asFunction(ARG_src1);
    4960     int registerOffset = ARG_int2;
    4961     int argCount = ARG_int3;
    4962     JSValue* constrProtoVal = ARG_src5;
    4963     int firstArg = ARG_int6;
    4964 
    4965 #ifndef NDEBUG
    4966     ConstructData constructData;
    4967     ASSERT(constructor->getConstructData(constructData) == ConstructTypeJS);
    4968 #endif
    4969 
    4970     ScopeChainNode* callDataScopeChain = constructor->m_scopeChain.node();
    4971     FunctionBodyNode* functionBodyNode = constructor->m_body.get();
    4972     CodeBlock* newCodeBlock = &functionBodyNode->byteCode(callDataScopeChain);
    4973 
    4974     StructureID* structure;
    4975     if (constrProtoVal->isObject())
    4976         structure = asObject(constrProtoVal)->inheritorID();
    4977     else
    4978         structure = callDataScopeChain->globalObject()->emptyObjectStructure();
    4979     JSObject* newObject = new (ARG_globalData) JSObject(structure);
    4980     callFrame[firstArg] = newObject; // "this" value
    4981 
    4982     if (LIKELY(argCount == newCodeBlock->numParameters)) {
    4983         VoidPtrPairValue pair = {{ newCodeBlock, CallFrame::create(callFrame->registers() + registerOffset) }};
    4984         return pair.i;
    4985     }
    4986 
    4987     if (argCount > newCodeBlock->numParameters) {
    4988         size_t numParameters = newCodeBlock->numParameters;
    4989         Register* r = callFrame->registers() + registerOffset + numParameters;
    4990 
    4991         Register* argv = r - RegisterFile::CallFrameHeaderSize - numParameters - argCount;
    4992         for (size_t i = 0; i < numParameters; ++i)
    4993             argv[i + argCount] = argv[i];
    4994 
    4995         VoidPtrPairValue pair = {{ newCodeBlock, CallFrame::create(r) }};
    4996         return pair.i;
    4997     }
    4998 
    4999     size_t omittedArgCount = newCodeBlock->numParameters - argCount;
    5000     Register* r = callFrame->registers() + registerOffset + omittedArgCount;
    5001     Register* newEnd = r + newCodeBlock->numCalleeRegisters;
    5002     if (!ARG_registerFile->grow(newEnd)) {
    5003         ARG_globalData->exception = createStackOverflowError(callFrame);
    5004         VM_THROW_EXCEPTION_2();
    5005     }
    5006 
    5007     Register* argv = r - RegisterFile::CallFrameHeaderSize - omittedArgCount;
    5008     for (size_t i = 0; i < omittedArgCount; ++i)
    5009         argv[i] = jsUndefined();
    5010 
    5011     VoidPtrPairValue pair = {{ newCodeBlock, CallFrame::create(r) }};
    5012     return pair.i;
    50134954}
    50144955
Note: See TracChangeset for help on using the changeset viewer.