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/parser/Nodes.cpp

    r47304 r47412  
    18251825}
    18261826
    1827 void ScopeNodeData::markAggregate(MarkStack& markStack)
    1828 {
    1829     FunctionStack::iterator end = m_functionStack.end();
    1830     for (FunctionStack::iterator ptr = m_functionStack.begin(); ptr != end; ++ptr) {
    1831         FunctionBodyNode* body = *ptr;
    1832         if (!body->isGenerated())
    1833             continue;
    1834         body->generatedBytecode().markAggregate(markStack);
    1835     }
    1836 }
    1837 
    18381827// ------------------------------ ScopeNode -----------------------------
    18391828
     
    18931882}
    18941883
    1895 void ProgramNode::generateBytecode(ScopeChainNode* scopeChainNode)
    1896 {
    1897     ScopeChain scopeChain(scopeChainNode);
    1898     JSGlobalObject* globalObject = scopeChain.globalObject();
    1899    
    1900     m_code.set(new ProgramCodeBlock(this, GlobalCode, globalObject, source().provider()));
    1901    
    1902     OwnPtr<BytecodeGenerator> generator(new BytecodeGenerator(this, globalObject->debugger(), scopeChain, &globalObject->symbolTable(), m_code.get()));
    1903     generator->generate();
    1904 
    1905     destroyData();
    1906 }
    1907 
    1908 #if ENABLE(JIT)
    1909 void ProgramNode::generateJITCode(ScopeChainNode* scopeChainNode)
    1910 {
    1911     bytecode(scopeChainNode);
    1912     ASSERT(m_code);
    1913     ASSERT(!m_jitCode);
    1914     JIT::compile(scopeChainNode->globalData, m_code.get());
    1915     ASSERT(m_jitCode);
    1916 }
    1917 #endif
    1918 
    19191884// ------------------------------ EvalNode -----------------------------
    19201885
     
    19471912    return 0;
    19481913}
    1949 
    1950 void EvalNode::generateBytecode(ScopeChainNode* scopeChainNode)
    1951 {
    1952     ScopeChain scopeChain(scopeChainNode);
    1953     JSGlobalObject* globalObject = scopeChain.globalObject();
    1954 
    1955     m_code.set(new EvalCodeBlock(this, globalObject, source().provider(), scopeChain.localDepth()));
    1956 
    1957     OwnPtr<BytecodeGenerator> generator(new BytecodeGenerator(this, globalObject->debugger(), scopeChain, &m_code->symbolTable(), m_code.get()));
    1958     generator->generate();
    1959 
    1960     // Eval code needs to hang on to its declaration stacks to keep declaration info alive until Interpreter::execute time,
    1961     // so the entire ScopeNodeData cannot be destoyed.
    1962     children().clear();
    1963 }
    1964 
    1965 EvalCodeBlock& EvalNode::bytecodeForExceptionInfoReparse(ScopeChainNode* scopeChainNode, CodeBlock* codeBlockBeingRegeneratedFrom)
    1966 {
    1967     ASSERT(!m_code);
    1968 
    1969     ScopeChain scopeChain(scopeChainNode);
    1970     JSGlobalObject* globalObject = scopeChain.globalObject();
    1971 
    1972     m_code.set(new EvalCodeBlock(this, globalObject, source().provider(), scopeChain.localDepth()));
    1973 
    1974     OwnPtr<BytecodeGenerator> generator(new BytecodeGenerator(this, globalObject->debugger(), scopeChain, &m_code->symbolTable(), m_code.get()));
    1975     generator->setRegeneratingForExceptionInfo(codeBlockBeingRegeneratedFrom);
    1976     generator->generate();
    1977 
    1978     return *m_code;
    1979 }
    1980 
    1981 void EvalNode::markAggregate(MarkStack& markStack)
    1982 {
    1983     // We don't need to mark our own CodeBlock as the JSGlobalObject takes care of that
    1984     data()->markAggregate(markStack);
    1985 }
    1986 
    1987 #if ENABLE(JIT)
    1988 void EvalNode::generateJITCode(ScopeChainNode* scopeChainNode)
    1989 {
    1990     bytecode(scopeChainNode);
    1991     ASSERT(m_code);
    1992     ASSERT(!m_jitCode);
    1993     JIT::compile(scopeChainNode->globalData, m_code.get());
    1994     ASSERT(m_jitCode);
    1995 }
    1996 #endif
    19971914
    19981915// ------------------------------ FunctionBodyNode -----------------------------
     
    20381955}
    20391956
    2040 void FunctionBodyNode::markAggregate(MarkStack& markStack)
    2041 {
    2042     if (m_code)
    2043         m_code->markAggregate(markStack);
    2044 }
    2045 
    2046 #if ENABLE(JIT)
    2047 PassRefPtr<FunctionBodyNode> FunctionBodyNode::createNativeThunk(JSGlobalData* globalData)
    2048 {
    2049     RefPtr<FunctionBodyNode> body = new FunctionBodyNode(globalData);
    2050     globalData->parser->arena().reset();
    2051     body->m_code.set(new NativeCodeBlock(body.get()));
    2052     body->m_jitCode = JITCode(JITCode::HostFunction(globalData->jitStubs.ctiNativeCallThunk()));
    2053     return body.release();
    2054 }
    2055 #endif
    2056 
    2057 bool FunctionBodyNode::isHostFunction() const
    2058 {
    2059     return m_code && m_code->codeType() == NativeCode;
    2060 }
    2061 
    20621957FunctionBodyNode* FunctionBodyNode::create(JSGlobalData* globalData)
    20631958{
     
    20761971}
    20771972
    2078 void FunctionBodyNode::generateBytecode(ScopeChainNode* scopeChainNode)
     1973void FunctionBodyNode::reparseDataIfNecessary(ScopeChainNode* scopeChainNode)
    20791974{
    20801975    // This branch is only necessary since you can still create a non-stub FunctionBodyNode by
     
    20831978        scopeChainNode->globalData->parser->reparseInPlace(scopeChainNode->globalData, this);
    20841979    ASSERT(data());
    2085 
    2086     ScopeChain scopeChain(scopeChainNode);
    2087     JSGlobalObject* globalObject = scopeChain.globalObject();
    2088 
    2089     m_code.set(new FunctionCodeBlock(this, FunctionCode, source().provider(), source().startOffset()));
    2090 
    2091     OwnPtr<BytecodeGenerator> generator(new BytecodeGenerator(this, globalObject->debugger(), scopeChain, &m_code->symbolTable(), m_code.get()));
    2092     generator->generate();
    2093 
    2094     destroyData();
    2095 }
    2096 
    2097 #if ENABLE(JIT)
    2098 void FunctionBodyNode::generateJITCode(ScopeChainNode* scopeChainNode)
    2099 {
    2100     bytecode(scopeChainNode);
    2101     ASSERT(m_code);
    2102     ASSERT(!m_jitCode);
    2103     JIT::compile(scopeChainNode->globalData, m_code.get());
    2104     ASSERT(m_jitCode);
    2105 }
    2106 #endif
    2107 
    2108 CodeBlock& FunctionBodyNode::bytecodeForExceptionInfoReparse(ScopeChainNode* scopeChainNode, CodeBlock* codeBlockBeingRegeneratedFrom)
    2109 {
    2110     ASSERT(!m_code);
    2111 
    2112     ScopeChain scopeChain(scopeChainNode);
    2113     JSGlobalObject* globalObject = scopeChain.globalObject();
    2114 
    2115     m_code.set(new FunctionCodeBlock(this, FunctionCode, source().provider(), source().startOffset()));
    2116 
    2117     OwnPtr<BytecodeGenerator> generator(new BytecodeGenerator(this, globalObject->debugger(), scopeChain, &m_code->symbolTable(), m_code.get()));
    2118     generator->setRegeneratingForExceptionInfo(codeBlockBeingRegeneratedFrom);
    2119     generator->generate();
    2120 
    2121     return *m_code;
    21221980}
    21231981
     
    21572015}
    21582016
    2159 JSFunction* FunctionBodyNode::make(ExecState* exec, ScopeChainNode* scopeChain)
    2160 {
    2161     return new (exec) JSFunction(exec, m_ident, this, scopeChain);
    2162 }
    2163 
    21642017// ------------------------------ FuncDeclNode ---------------------------------
    21652018
Note: See TracChangeset for help on using the changeset viewer.