Changeset 63267 in webkit for trunk/JavaScriptCore/interpreter


Ignore:
Timestamp:
Jul 13, 2010, 5:27:13 PM (15 years ago)
Author:
[email protected]
Message:

Bug 42207 - Clean up interface to compile executables, always check for exceptions

Reviewed by Oliver Hunt.

Presently interface to compile executable is inconsistent between eval/program and
function code, and is error prone in allowing a caller to byte compile without JIT
compiling an executable (we rely on all executables with codeblocks having JIT code).
Unify on an interface where all compilation is performed by a single compile (with
ForCall|ForConstruct variants) method, and make all clients check for errors.

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::unwindCallFrame):
(JSC::Interpreter::execute):
(JSC::Interpreter::executeCall):
(JSC::Interpreter::executeConstruct):
(JSC::Interpreter::prepareForRepeatCall):
(JSC::Interpreter::privateExecute):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • parser/Parser.h:

(JSC::Parser::isFunctionBodyNode):
(JSC::Parser::parse):

  • runtime/ArrayPrototype.cpp:

(JSC::isNumericCompareFunction):

  • runtime/ExceptionHelpers.cpp:

(JSC::createStackOverflowError):

  • runtime/ExceptionHelpers.h:
  • runtime/Executable.cpp:

(JSC::EvalExecutable::compileInternal):
(JSC::ProgramExecutable::checkSyntax):
(JSC::ProgramExecutable::compileInternal):
(JSC::FunctionExecutable::compileForCallInternal):
(JSC::FunctionExecutable::compileForConstructInternal):
(JSC::FunctionExecutable::reparseExceptionInfo):
(JSC::EvalExecutable::reparseExceptionInfo):
(JSC::FunctionExecutable::fromGlobalCode):

  • runtime/Executable.h:

(JSC::EvalExecutable::compile):
(JSC::EvalExecutable::generatedBytecode):
(JSC::EvalExecutable::generatedJITCode):
(JSC::ProgramExecutable::compile):
(JSC::ProgramExecutable::generatedBytecode):
(JSC::ProgramExecutable::generatedJITCode):
(JSC::FunctionExecutable::generatedBytecode):
(JSC::FunctionExecutable::compileForCall):
(JSC::FunctionExecutable::compileForConstruct):
(JSC::FunctionExecutable::generatedJITCodeForConstructWithArityCheck):

  • runtime/FunctionConstructor.cpp:

(JSC::constructFunction):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::argumentsGetter):

  • runtime/JSGlobalData.h:

(JSC::JSGlobalData::canUseJIT):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r63056 r63267  
    548548
    549549    codeBlock = callerFrame->codeBlock();
    550 #if ENABLE(JIT)
    551 #if ENABLE(INTERPRETER)
     550#if ENABLE(JIT) && ENABLE(INTERPRETER)
    552551    if (callerFrame->globalData().canUseJIT())
    553 #endif
    554552        bytecodeOffset = codeBlock->bytecodeOffset(callerFrame, callFrame->returnPC());
    555 #if ENABLE(INTERPRETER)
    556553    else
    557554        bytecodeOffset = codeBlock->bytecodeOffset(callerFrame, callFrame->returnVPC());
    558 #endif
     555#elif ENABLE(JIT)
     556    bytecodeOffset = codeBlock->bytecodeOffset(callerFrame, callFrame->returnPC());
    559557#else
    560558    bytecodeOffset = codeBlock->bytecodeOffset(callerFrame, callFrame->returnVPC());
    561559#endif
     560
    562561    callFrame = callerFrame;
    563562    return true;
     
    661660    }
    662661
    663     CodeBlock* codeBlock = &program->bytecode(callFrame, scopeChain);
    664     if (!codeBlock) {
    665         *exception = createStackOverflowError(callFrame);
     662    JSObject* error = program->compile(callFrame, scopeChain);
     663    if (error) {
     664        *exception = error;
    666665        return jsNull();
    667666    }
     667    CodeBlock* codeBlock = &program->generatedBytecode();
    668668
    669669    Register* oldEnd = m_registerFile.end();
     
    698698        m_reentryDepth++; 
    699699#if ENABLE(JIT)
    700 #if ENABLE(INTERPRETER)
    701700        if (callFrame->globalData().canUseJIT())
    702 #endif
    703             result = program->jitCode(newCallFrame, scopeChain).execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
    704 #if ENABLE(INTERPRETER)
     701            result = program->generatedJITCode().execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
    705702        else
    706703#endif
    707 #endif
    708 #if ENABLE(INTERPRETER)
    709704            result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
    710 #endif
    711705
    712706        m_reentryDepth--;
     
    753747    if (callType == CallTypeJS) {
    754748        ScopeChainNode* callDataScopeChain = callData.js.scopeChain;
    755         CodeBlock* newCodeBlock = callData.js.functionExecutable->bytecodeForCall(callFrame, callDataScopeChain);
    756 
    757         if (newCodeBlock)
    758             newCallFrame = slideRegisterWindowForCall(newCodeBlock, &m_registerFile, newCallFrame, registerOffset, argCount);
    759         else
    760             newCallFrame = 0;
     749
     750        JSObject* compileError = callData.js.functionExecutable->compileForCall(callFrame, callDataScopeChain);
     751        if (UNLIKELY(!!compileError)) {
     752            *exception = compileError;
     753            m_registerFile.shrink(oldEnd);
     754            return jsNull();
     755        }
     756
     757        CodeBlock* newCodeBlock = &callData.js.functionExecutable->generatedBytecodeForCall();
     758        newCallFrame = slideRegisterWindowForCall(newCodeBlock, &m_registerFile, newCallFrame, registerOffset, argCount);
    761759        if (UNLIKELY(!newCallFrame)) {
    762760            *exception = createStackOverflowError(callFrame);
     
    779777            m_reentryDepth++; 
    780778#if ENABLE(JIT)
    781 #if ENABLE(INTERPRETER)
    782779            if (callFrame->globalData().canUseJIT())
    783 #endif
    784                 result = callData.js.functionExecutable->jitCodeForCall(newCallFrame, callDataScopeChain).execute(&m_registerFile, newCallFrame, callDataScopeChain->globalData, exception);
    785 #if ENABLE(INTERPRETER)
     780                result = callData.js.functionExecutable->generatedJITCodeForCall().execute(&m_registerFile, newCallFrame, callDataScopeChain->globalData, exception);
    786781            else
    787782#endif
    788 #endif
    789 #if ENABLE(INTERPRETER)
    790783                result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
    791 #endif
    792784            m_reentryDepth--;
    793785        }
     
    852844    if (constructType == ConstructTypeJS) {
    853845        ScopeChainNode* constructDataScopeChain = constructData.js.scopeChain;
    854         CodeBlock* newCodeBlock = constructData.js.functionExecutable->bytecodeForConstruct(callFrame, constructDataScopeChain);
    855         if (newCodeBlock)
    856             newCallFrame = slideRegisterWindowForCall(newCodeBlock, &m_registerFile, newCallFrame, registerOffset, argCount);
    857         else
    858             newCallFrame = 0;
    859 
     846
     847        JSObject* compileError = constructData.js.functionExecutable->compileForConstruct(callFrame, constructDataScopeChain);
     848        if (UNLIKELY(!!compileError)) {
     849            *exception = compileError;
     850            m_registerFile.shrink(oldEnd);
     851            return 0;
     852        }
     853
     854        CodeBlock* newCodeBlock = &constructData.js.functionExecutable->generatedBytecodeForConstruct();
     855        newCallFrame = slideRegisterWindowForCall(newCodeBlock, &m_registerFile, newCallFrame, registerOffset, argCount);
    860856        if (UNLIKELY(!newCallFrame)) {
    861857            *exception = createStackOverflowError(callFrame);
     
    878874            m_reentryDepth++; 
    879875#if ENABLE(JIT)
    880 #if ENABLE(INTERPRETER)
    881876            if (callFrame->globalData().canUseJIT())
    882 #endif
    883                 result = constructData.js.functionExecutable->jitCodeForConstruct(newCallFrame, constructDataScopeChain).execute(&m_registerFile, newCallFrame, constructDataScopeChain->globalData, exception);
    884 #if ENABLE(INTERPRETER)
     877                result = constructData.js.functionExecutable->generatedJITCodeForConstruct().execute(&m_registerFile, newCallFrame, constructDataScopeChain->globalData, exception);
    885878            else
    886879#endif
    887 #endif
    888 #if ENABLE(INTERPRETER)
    889880                result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
    890 #endif
    891881            m_reentryDepth--;
    892882        }
     
    953943        newCallFrame->r(++dst) = jsUndefined();
    954944   
    955     CodeBlock* codeBlock = FunctionExecutable->bytecodeForCall(callFrame, scopeChain);
    956     if (codeBlock)
    957         newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argc + RegisterFile::CallFrameHeaderSize, argc);
    958     else
    959         newCallFrame = 0;
     945    JSObject* error = FunctionExecutable->compileForCall(callFrame, scopeChain);
     946    if (error) {
     947        *exception = error;
     948        m_registerFile.shrink(oldEnd);
     949        return CallFrameClosure();
     950    }
     951    CodeBlock* codeBlock = &FunctionExecutable->generatedBytecodeForCall();
     952
     953    newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argc + RegisterFile::CallFrameHeaderSize, argc);
    960954    if (UNLIKELY(!newCallFrame)) {
    961955        *exception = createStackOverflowError(callFrame);
     
    965959    // a 0 codeBlock indicates a built-in caller
    966960    newCallFrame->init(codeBlock, 0, scopeChain, callFrame->addHostCallFrameFlag(), argc, function); 
    967 #if ENABLE(JIT)
    968 #if ENABLE(INTERPRETER)
    969     if (callFrame->globalData().canUseJIT())
    970 #endif
    971         FunctionExecutable->jitCodeForCall(newCallFrame, scopeChain);
    972 #endif
    973961    CallFrameClosure result = { callFrame, newCallFrame, function, FunctionExecutable, scopeChain->globalData, oldEnd, scopeChain, codeBlock->m_numParameters, argc };
    974962    return result;
     
    10141002JSValue Interpreter::execute(EvalExecutable* eval, CallFrame* callFrame, JSObject* thisObj, ScopeChainNode* scopeChain, JSValue* exception)
    10151003{
    1016     return execute(eval, callFrame, thisObj, m_registerFile.size() + eval->bytecode(callFrame, scopeChain).m_numParameters + RegisterFile::CallFrameHeaderSize, scopeChain, exception);
     1004    JSObject* compileError = eval->compile(callFrame, scopeChain);
     1005    if (UNLIKELY(!!compileError)) {
     1006        *exception = compileError;
     1007        return jsNull();
     1008    }
     1009    return execute(eval, callFrame, thisObj, m_registerFile.size() + eval->generatedBytecode().m_numParameters + RegisterFile::CallFrameHeaderSize, scopeChain, exception);
    10171010}
    10181011
     
    10301023    DynamicGlobalObjectScope globalObjectScope(callFrame, scopeChain->globalObject);
    10311024
    1032     EvalCodeBlock* codeBlock = &eval->bytecode(callFrame, scopeChain);
    1033     if (!codeBlock) {
    1034         *exception = createStackOverflowError(callFrame);
     1025    JSObject* compileError = eval->compile(callFrame, scopeChain);
     1026    if (UNLIKELY(!!compileError)) {
     1027        *exception = compileError;
    10351028        return jsNull();
    10361029    }
     1030    EvalCodeBlock* codeBlock = &eval->generatedBytecode();
    10371031
    10381032    JSVariableObject* variableObject;
     
    10971091        if (callFrame->globalData().canUseJIT())
    10981092#endif
    1099             result = eval->jitCode(newCallFrame, scopeChain).execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
     1093            result = eval->generatedJITCode().execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
    11001094#if ENABLE(INTERPRETER)
    11011095        else
     
    37133707        if (callType == CallTypeJS) {
    37143708            ScopeChainNode* callDataScopeChain = callData.js.scopeChain;
    3715             CodeBlock* newCodeBlock = callData.js.functionExecutable->bytecodeForCall(callFrame, callDataScopeChain);
     3709
     3710            JSObject* error = callData.js.functionExecutable->compileForCall(callFrame, callDataScopeChain);
     3711            if (UNLIKELY(!!error)) {
     3712                exceptionValue = error;
     3713                goto vm_throw;
     3714            }
    37163715
    37173716            CallFrame* previousCallFrame = callFrame;
    3718             if (newCodeBlock)
    3719                 callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
    3720             else
    3721                 callFrame = 0;
     3717            CodeBlock* newCodeBlock = &callData.js.functionExecutable->generatedBytecodeForCall();
     3718            callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
    37223719            if (UNLIKELY(!callFrame)) {
    37233720                callFrame = previousCallFrame;
     
    38713868        if (callType == CallTypeJS) {
    38723869            ScopeChainNode* callDataScopeChain = callData.js.scopeChain;
    3873             CodeBlock* newCodeBlock = callData.js.functionExecutable->bytecodeForCall(callFrame, callDataScopeChain);
    3874            
     3870
     3871            JSObject* error = callData.js.functionExecutable->compileForCall(callFrame, callDataScopeChain);
     3872            if (UNLIKELY(!!error)) {
     3873                exceptionValue = error;
     3874                goto vm_throw;
     3875            }
     3876
    38753877            CallFrame* previousCallFrame = callFrame;
    3876             if (newCodeBlock)
    3877                 callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
    3878             else
    3879                 callFrame = 0;
     3878            CodeBlock* newCodeBlock = &callData.js.functionExecutable->generatedBytecodeForCall();
     3879            callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
    38803880            if (UNLIKELY(!callFrame)) {
    38813881                callFrame = previousCallFrame;
     
    38833883                goto vm_throw;
    38843884            }
    3885            
     3885
    38863886            callFrame->init(newCodeBlock, vPC + OPCODE_LENGTH(op_call_varargs), callDataScopeChain, previousCallFrame, argCount, asFunction(v));
    38873887            codeBlock = newCodeBlock;
     
    41964196        if (constructType == ConstructTypeJS) {
    41974197            ScopeChainNode* callDataScopeChain = constructData.js.scopeChain;
    4198             CodeBlock* newCodeBlock = constructData.js.functionExecutable->bytecodeForConstruct(callFrame, callDataScopeChain);
     4198
     4199            JSObject* error = constructData.js.functionExecutable->compileForConstruct(callFrame, callDataScopeChain);
     4200            if (UNLIKELY(!!error)) {
     4201                exceptionValue = error;
     4202                goto vm_throw;
     4203            }
    41994204
    42004205            CallFrame* previousCallFrame = callFrame;
    4201 
    4202             if (newCodeBlock)
    4203                 callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
    4204             else
    4205                 callFrame = 0;
    4206 
     4206            CodeBlock* newCodeBlock = &constructData.js.functionExecutable->generatedBytecodeForConstruct();
     4207            callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
    42074208            if (UNLIKELY(!callFrame)) {
    42084209                callFrame = previousCallFrame;
Note: See TracChangeset for help on using the changeset viewer.