Ignore:
Timestamp:
Aug 17, 2009, 10:34:52 PM (16 years ago)
Author:
[email protected]
Message:

No, silly runtime, AST nodes are not for you.

Reviewed by Sam Weinig.

We still use AST nodes (ScopeNodes, particularly FunctionBodyNodes) within
the runtime, which means that these nodes must be persisted outside of the
arena, contain both parser & runtime data, etc. This is all a bit of a mess.

Move functionality into a new FunctionExecutable class.

(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::markAggregate):
(JSC::CodeBlock::reparseForExceptionInfoIfNecessary):
(JSC::CodeBlock::lineNumberForBytecodeOffset):
(JSC::CodeBlock::shrinkToFit):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::getBytecodeIndex):
(JSC::CodeBlock::discardBytecode):
(JSC::CodeBlock::instructionCount):
(JSC::CodeBlock::getJITCode):
(JSC::CodeBlock::executablePool):
(JSC::CodeBlock::ownerExecutable):
(JSC::CodeBlock::extractExceptionInfo):
(JSC::CodeBlock::addFunctionDecl):
(JSC::CodeBlock::functionDecl):
(JSC::CodeBlock::numberOfFunctionDecls):
(JSC::CodeBlock::addFunctionExpr):
(JSC::CodeBlock::functionExpr):
(JSC::GlobalCodeBlock::GlobalCodeBlock):
(JSC::ProgramCodeBlock::ProgramCodeBlock):
(JSC::EvalCodeBlock::EvalCodeBlock):
(JSC::FunctionCodeBlock::FunctionCodeBlock):
(JSC::NativeCodeBlock::NativeCodeBlock):

  • bytecode/EvalCodeCache.h:
  • bytecode/SamplingTool.cpp:

(JSC::SamplingTool::doRun):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitNewFunction):
(JSC::BytecodeGenerator::emitNewFunctionExpression):

  • bytecompiler/BytecodeGenerator.h:
  • debugger/Debugger.cpp:

(JSC::Debugger::recompileAllJSFunctions):

  • interpreter/CachedCall.h:

(JSC::CachedCall::CachedCall):

  • interpreter/CallFrameClosure.h:
  • interpreter/Interpreter.cpp:

(JSC::Interpreter::unwindCallFrame):
(JSC::Interpreter::throwException):
(JSC::Interpreter::execute):
(JSC::Interpreter::prepareForRepeatCall):
(JSC::Interpreter::debug):
(JSC::Interpreter::privateExecute):
(JSC::Interpreter::retrieveLastCaller):

  • interpreter/Interpreter.h:
  • jit/JIT.cpp:

(JSC::JIT::privateCompile):

  • jit/JIT.h:

(JSC::JIT::compile):

  • jit/JITOpcodes.cpp:

(JSC::JIT::privateCompileCTIMachineTrampolines):
(JSC::JIT::emit_op_new_func):
(JSC::JIT::emit_op_new_func_exp):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • jit/JITStubs.h:

(JSC::):

  • parser/Nodes.cpp:

(JSC::FunctionBodyNode::reparseDataIfNecessary):

  • parser/Nodes.h:

(JSC::EvalNode::partialDestroyData):

  • parser/Parser.h:
  • profiler/ProfileGenerator.cpp:
  • profiler/Profiler.cpp:

(JSC::Profiler::createCallIdentifier):
(JSC::createCallIdentifierFromFunctionImp):

  • runtime/Arguments.h:

(JSC::Arguments::getArgumentsData):
(JSC::Arguments::Arguments):
(JSC::JSActivation::copyRegisters):

  • runtime/ArrayPrototype.cpp:

(JSC::isNumericCompareFunction):

  • runtime/CallData.h:

(JSC::):

  • runtime/Collector.cpp:

(JSC::Heap::collect):

  • runtime/ConstructData.h:

(JSC::):

  • runtime/ExceptionHelpers.cpp:

(JSC::createUndefinedVariableError):
(JSC::createInvalidParamError):
(JSC::createNotAConstructorError):
(JSC::createNotAFunctionError):
(JSC::createNotAnObjectError):

  • runtime/Executable.cpp: Added.

(JSC::EvalExecutable::generateBytecode):
(JSC::ProgramExecutable::generateBytecode):
(JSC::FunctionExecutable::generateBytecode):
(JSC::EvalExecutable::generateJITCode):
(JSC::ProgramExecutable::generateJITCode):
(JSC::FunctionExecutable::generateJITCode):
(JSC::FunctionExecutable::isHostFunction):
(JSC::FunctionExecutable::markAggregate):
(JSC::FunctionExecutable::reparseExceptionInfo):
(JSC::EvalExecutable::reparseExceptionInfo):
(JSC::FunctionExecutable::recompile):
(JSC::FunctionExecutable::FunctionExecutable):

  • runtime/Executable.h:

(JSC::ExecutableBase::~ExecutableBase):
(JSC::ExecutableBase::ExecutableBase):
(JSC::ExecutableBase::source):
(JSC::ExecutableBase::sourceID):
(JSC::ExecutableBase::lastLine):
(JSC::ExecutableBase::usesEval):
(JSC::ExecutableBase::usesArguments):
(JSC::ExecutableBase::needsActivation):
(JSC::ExecutableBase::astNode):
(JSC::ExecutableBase::generatedJITCode):
(JSC::ExecutableBase::getExecutablePool):
(JSC::EvalExecutable::EvalExecutable):
(JSC::EvalExecutable::bytecode):
(JSC::EvalExecutable::varStack):
(JSC::EvalExecutable::evalNode):
(JSC::EvalExecutable::jitCode):
(JSC::ProgramExecutable::ProgramExecutable):
(JSC::ProgramExecutable::reparseExceptionInfo):
(JSC::ProgramExecutable::bytecode):
(JSC::ProgramExecutable::programNode):
(JSC::ProgramExecutable::jitCode):
(JSC::FunctionExecutable::FunctionExecutable):
(JSC::FunctionExecutable::name):
(JSC::FunctionExecutable::bytecode):
(JSC::FunctionExecutable::generatedBytecode):
(JSC::FunctionExecutable::usesEval):
(JSC::FunctionExecutable::usesArguments):
(JSC::FunctionExecutable::parameterCount):
(JSC::FunctionExecutable::paramString):
(JSC::FunctionExecutable::isGenerated):
(JSC::FunctionExecutable::body):
(JSC::FunctionExecutable::jitCode):
(JSC::FunctionExecutable::createNativeThunk):

  • runtime/FunctionConstructor.cpp:

(JSC::constructFunction):

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::JSActivation):
(JSC::JSActivation::markChildren):
(JSC::JSActivation::isDynamicScope):
(JSC::JSActivation::argumentsGetter):

  • runtime/JSActivation.h:

(JSC::JSActivation::JSActivationData::JSActivationData):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::isHostFunction):
(JSC::JSFunction::JSFunction):
(JSC::JSFunction::~JSFunction):
(JSC::JSFunction::markChildren):
(JSC::JSFunction::getCallData):
(JSC::JSFunction::call):
(JSC::JSFunction::lengthGetter):
(JSC::JSFunction::getConstructData):
(JSC::JSFunction::construct):

  • runtime/JSFunction.h:

(JSC::JSFunction::executable):
(JSC::FunctionExecutable::make):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::numericCompareFunction):

  • runtime/JSGlobalData.h:
File:
1 edited

Legend:

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

    r47405 r47412  
    490490        DebuggerCallFrame debuggerCallFrame(callFrame, exceptionValue);
    491491        if (callFrame->callee())
    492             debugger->returnEvent(debuggerCallFrame, codeBlock->ownerNode()->sourceID(), codeBlock->ownerNode()->lastLine());
     492            debugger->returnEvent(debuggerCallFrame, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->lastLine());
    493493        else
    494             debugger->didExecuteProgram(debuggerCallFrame, codeBlock->ownerNode()->sourceID(), codeBlock->ownerNode()->lastLine());
     494            debugger->didExecuteProgram(debuggerCallFrame, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->lastLine());
    495495    }
    496496
     
    499499            profiler->didExecute(callFrame, callFrame->callee());
    500500        else
    501             profiler->didExecute(callFrame, codeBlock->ownerNode()->sourceURL(), codeBlock->ownerNode()->lineNo());
     501            profiler->didExecute(callFrame, codeBlock->ownerExecutable()->sourceURL(), codeBlock->ownerExecutable()->lineNo());
    502502    }
    503503
     
    555555                } else
    556556                    exception->putWithAttributes(callFrame, Identifier(callFrame, "line"), jsNumber(callFrame, codeBlock->lineNumberForBytecodeOffset(callFrame, bytecodeOffset)), ReadOnly | DontDelete);
    557                 exception->putWithAttributes(callFrame, Identifier(callFrame, "sourceId"), jsNumber(callFrame, codeBlock->ownerNode()->sourceID()), ReadOnly | DontDelete);
    558                 exception->putWithAttributes(callFrame, Identifier(callFrame, "sourceURL"), jsOwnedString(callFrame, codeBlock->ownerNode()->sourceURL()), ReadOnly | DontDelete);
     557                exception->putWithAttributes(callFrame, Identifier(callFrame, "sourceId"), jsNumber(callFrame, codeBlock->ownerExecutable()->sourceID()), ReadOnly | DontDelete);
     558                exception->putWithAttributes(callFrame, Identifier(callFrame, "sourceURL"), jsOwnedString(callFrame, codeBlock->ownerExecutable()->sourceURL()), ReadOnly | DontDelete);
    559559            }
    560560           
     
    570570    if (Debugger* debugger = callFrame->dynamicGlobalObject()->debugger()) {
    571571        DebuggerCallFrame debuggerCallFrame(callFrame, exceptionValue);
    572         debugger->exception(debuggerCallFrame, codeBlock->ownerNode()->sourceID(), codeBlock->lineNumberForBytecodeOffset(callFrame, bytecodeOffset));
     572        debugger->exception(debuggerCallFrame, codeBlock->ownerExecutable()->sourceID(), codeBlock->lineNumberForBytecodeOffset(callFrame, bytecodeOffset));
    573573    }
    574574
     
    671671}
    672672
    673 JSValue Interpreter::execute(FunctionBodyNode* functionBodyNode, CallFrame* callFrame, JSFunction* function, JSObject* thisObj, const ArgList& args, ScopeChainNode* scopeChain, JSValue* exception)
     673JSValue Interpreter::execute(FunctionExecutable* functionExecutable, CallFrame* callFrame, JSFunction* function, JSObject* thisObj, const ArgList& args, ScopeChainNode* scopeChain, JSValue* exception)
    674674{
    675675    ASSERT(!scopeChain->globalData->exception);
     
    699699        newCallFrame->r(++dst) = *it;
    700700
    701     CodeBlock* codeBlock = &functionBodyNode->bytecode(scopeChain);
     701    CodeBlock* codeBlock = &functionExecutable->bytecode(scopeChain);
    702702    newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argc + RegisterFile::CallFrameHeaderSize, argc);
    703703    if (UNLIKELY(!newCallFrame)) {
     
    719719        m_reentryDepth++;
    720720#if ENABLE(JIT)
    721         result = functionBodyNode->jitCode(scopeChain).execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
     721        result = functionExecutable->jitCode(scopeChain).execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
    722722#else
    723723        result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
     
    733733}
    734734
    735 CallFrameClosure Interpreter::prepareForRepeatCall(FunctionBodyNode* functionBodyNode, CallFrame* callFrame, JSFunction* function, int argCount, ScopeChainNode* scopeChain, JSValue* exception)
     735CallFrameClosure Interpreter::prepareForRepeatCall(FunctionExecutable* FunctionExecutable, CallFrame* callFrame, JSFunction* function, int argCount, ScopeChainNode* scopeChain, JSValue* exception)
    736736{
    737737    ASSERT(!scopeChain->globalData->exception);
     
    757757        newCallFrame->r(++dst) = jsUndefined();
    758758   
    759     CodeBlock* codeBlock = &functionBodyNode->bytecode(scopeChain);
     759    CodeBlock* codeBlock = &FunctionExecutable->bytecode(scopeChain);
    760760    newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argc + RegisterFile::CallFrameHeaderSize, argc);
    761761    if (UNLIKELY(!newCallFrame)) {
     
    767767    newCallFrame->init(codeBlock, 0, scopeChain, callFrame->addHostCallFrameFlag(), 0, argc, function);
    768768#if ENABLE(JIT)
    769     functionBodyNode->jitCode(scopeChain);
     769    FunctionExecutable->jitCode(scopeChain);
    770770#endif
    771771
    772     CallFrameClosure result = { callFrame, newCallFrame, function, functionBodyNode, scopeChain->globalData, oldEnd, scopeChain, codeBlock->m_numParameters, argc };
     772    CallFrameClosure result = { callFrame, newCallFrame, function, FunctionExecutable, scopeChain->globalData, oldEnd, scopeChain, codeBlock->m_numParameters, argc };
    773773    return result;
    774774}
     
    787787        m_reentryDepth++;
    788788#if ENABLE(JIT)
    789         result = closure.functionBody->generatedJITCode().execute(&m_registerFile, closure.newCallFrame, closure.globalData, exception);
     789        result = closure.functionExecutable->generatedJITCode().execute(&m_registerFile, closure.newCallFrame, closure.globalData, exception);
    790790#else
    791791        result = privateExecute(Normal, &m_registerFile, closure.newCallFrame, exception);
     
    837837        BatchedTransitionOptimizer optimizer(variableObject);
    838838
    839         const DeclarationStacks::VarStack& varStack = codeBlock->ownerNode()->varStack();
     839        const DeclarationStacks::VarStack& varStack = static_cast<EvalExecutable*>(codeBlock->ownerExecutable())->varStack();
    840840        DeclarationStacks::VarStack::const_iterator varStackEnd = varStack.end();
    841841        for (DeclarationStacks::VarStack::const_iterator it = varStack.begin(); it != varStackEnd; ++it) {
     
    847847        }
    848848
    849         const DeclarationStacks::FunctionStack& functionStack = codeBlock->ownerNode()->functionStack();
    850         DeclarationStacks::FunctionStack::const_iterator functionStackEnd = functionStack.end();
    851         for (DeclarationStacks::FunctionStack::const_iterator it = functionStack.begin(); it != functionStackEnd; ++it) {
     849        int numFunctions = codeBlock->numberOfFunctionDecls();
     850        for (int i = 0; i < numFunctions; ++i) {
     851            FunctionExecutable* function = codeBlock->functionDecl(i);
    852852            PutPropertySlot slot;
    853             variableObject->put(callFrame, (*it)->ident(), (*it)->make(callFrame, scopeChain), slot);
     853            variableObject->put(callFrame, function->name(), function->make(callFrame, scopeChain), slot);
    854854        }
    855855
     
    904904    switch (debugHookID) {
    905905        case DidEnterCallFrame:
    906             debugger->callEvent(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), firstLine);
     906            debugger->callEvent(callFrame, callFrame->codeBlock()->ownerExecutable()->sourceID(), firstLine);
    907907            return;
    908908        case WillLeaveCallFrame:
    909             debugger->returnEvent(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), lastLine);
     909            debugger->returnEvent(callFrame, callFrame->codeBlock()->ownerExecutable()->sourceID(), lastLine);
    910910            return;
    911911        case WillExecuteStatement:
    912             debugger->atStatement(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), firstLine);
     912            debugger->atStatement(callFrame, callFrame->codeBlock()->ownerExecutable()->sourceID(), firstLine);
    913913            return;
    914914        case WillExecuteProgram:
    915             debugger->willExecuteProgram(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), firstLine);
     915            debugger->willExecuteProgram(callFrame, callFrame->codeBlock()->ownerExecutable()->sourceID(), firstLine);
    916916            return;
    917917        case DidExecuteProgram:
    918             debugger->didExecuteProgram(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), lastLine);
     918            debugger->didExecuteProgram(callFrame, callFrame->codeBlock()->ownerExecutable()->sourceID(), lastLine);
    919919            return;
    920920        case DidReachBreakpoint:
    921             debugger->didReachBreakpoint(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), lastLine);
     921            debugger->didReachBreakpoint(callFrame, callFrame->codeBlock()->ownerExecutable()->sourceID(), lastLine);
    922922            return;
    923923    }
     
    29212921        int func = (++vPC)->u.operand;
    29222922
    2923         callFrame->r(dst) = JSValue(callFrame->codeBlock()->function(func)->make(callFrame, callFrame->scopeChain()));
     2923        callFrame->r(dst) = JSValue(callFrame->codeBlock()->functionDecl(func)->make(callFrame, callFrame->scopeChain()));
    29242924
    29252925        ++vPC;
     
    29372937        int funcIndex = (++vPC)->u.operand;
    29382938
    2939         FunctionBodyNode* body = callFrame->codeBlock()->function(funcIndex);
    2940         JSFunction* func = body->make(callFrame, callFrame->scopeChain());
     2939        FunctionExecutable* function = callFrame->codeBlock()->functionExpr(funcIndex);
     2940        JSFunction* func = function->make(callFrame, callFrame->scopeChain());
    29412941
    29422942        /*
     
    29472947            does not affect the scope enclosing the FunctionExpression.
    29482948         */
    2949         if (!body->ident().isNull()) {
    2950             JSStaticScopeObject* functionScopeObject = new (callFrame) JSStaticScopeObject(callFrame, body->ident(), func, ReadOnly | DontDelete);
     2949        if (!function->name().isNull()) {
     2950            JSStaticScopeObject* functionScopeObject = new (callFrame) JSStaticScopeObject(callFrame, function->name(), func, ReadOnly | DontDelete);
    29512951            func->scope().push(functionScopeObject);
    29522952        }
     
    30183018        if (callType == CallTypeJS) {
    30193019            ScopeChainNode* callDataScopeChain = callData.js.scopeChain;
    3020             FunctionBodyNode* functionBodyNode = callData.js.functionBody;
    3021             CodeBlock* newCodeBlock = &functionBodyNode->bytecode(callDataScopeChain);
     3020            CodeBlock* newCodeBlock = &callData.js.functionExecutable->bytecode(callDataScopeChain);
    30223021
    30233022            CallFrame* previousCallFrame = callFrame;
     
    30853084                goto vm_throw;
    30863085            }
    3087             int32_t expectedParams = callFrame->callee()->body()->parameterCount();
     3086            int32_t expectedParams = callFrame->callee()->executable()->parameterCount();
    30883087            int32_t inplaceArgs = min(argCount, expectedParams);
    30893088            int32_t i = 0;
     
    31723171        if (callType == CallTypeJS) {
    31733172            ScopeChainNode* callDataScopeChain = callData.js.scopeChain;
    3174             FunctionBodyNode* functionBodyNode = callData.js.functionBody;
    3175             CodeBlock* newCodeBlock = &functionBodyNode->bytecode(callDataScopeChain);
     3173            CodeBlock* newCodeBlock = &callData.js.functionExecutable->bytecode(callDataScopeChain);
    31763174           
    31773175            CallFrame* previousCallFrame = callFrame;
     
    33353333
    33363334        int dst = (++vPC)->u.operand;
    3337         JSActivation* activation = new (globalData) JSActivation(callFrame, static_cast<FunctionBodyNode*>(codeBlock->ownerNode()));
     3335        JSActivation* activation = new (globalData) JSActivation(callFrame, static_cast<FunctionExecutable*>(codeBlock->ownerExecutable()));
    33383336        callFrame->r(dst) = JSValue(activation);
    33393337        callFrame->setScopeChain(callFrame->scopeChain()->copy()->push(activation));
     
    34213419        if (constructType == ConstructTypeJS) {
    34223420            ScopeChainNode* callDataScopeChain = constructData.js.scopeChain;
    3423             FunctionBodyNode* functionBodyNode = constructData.js.functionBody;
    3424             CodeBlock* newCodeBlock = &functionBodyNode->bytecode(callDataScopeChain);
     3421            CodeBlock* newCodeBlock = &constructData.js.functionExecutable->bytecode(callDataScopeChain);
    34253422
    34263423            Structure* structure;
     
    36723669
    36733670        CodeBlock* codeBlock = callFrame->codeBlock();
    3674         callFrame->r(dst) = JSValue(Error::create(callFrame, (ErrorType)type, callFrame->r(message).jsValue().toString(callFrame), codeBlock->lineNumberForBytecodeOffset(callFrame, vPC - codeBlock->instructions().begin()), codeBlock->ownerNode()->sourceID(), codeBlock->ownerNode()->sourceURL()));
     3671        callFrame->r(dst) = JSValue(Error::create(callFrame, (ErrorType)type, callFrame->r(message).jsValue().toString(callFrame), codeBlock->lineNumberForBytecodeOffset(callFrame, vPC - codeBlock->instructions().begin()), codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL()));
    36753672
    36763673        ++vPC;
     
    39003897    unsigned bytecodeOffset = bytecodeOffsetForPC(callerFrame, callerCodeBlock, callFrame->returnPC());
    39013898    lineNumber = callerCodeBlock->lineNumberForBytecodeOffset(callerFrame, bytecodeOffset - 1);
    3902     sourceID = callerCodeBlock->ownerNode()->sourceID();
    3903     sourceURL = callerCodeBlock->ownerNode()->sourceURL();
     3899    sourceID = callerCodeBlock->ownerExecutable()->sourceID();
     3900    sourceURL = callerCodeBlock->ownerExecutable()->sourceURL();
    39043901    function = callerFrame->callee();
    39053902}
Note: See TracChangeset for help on using the changeset viewer.