Changeset 47412 in webkit for trunk/JavaScriptCore/parser


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:
Location:
trunk/JavaScriptCore/parser
Files:
2 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
  • trunk/JavaScriptCore/parser/Nodes.h

    r47259 r47412  
    4040
    4141    class ArgumentListNode;
     42    class BytecodeGenerator;
    4243    class CodeBlock;
    43     class BytecodeGenerator;
     44    class EvalCodeBlock;
     45    class EvalExecutable;
    4446    class FuncDeclNode;
    45     class EvalCodeBlock;
     47    class FunctionBodyNode;
     48    class FunctionCodeBlock;
    4649    class JSFunction;
    4750    class ProgramCodeBlock;
     51    class ProgramExecutable;
    4852    class PropertyListNode;
    4953    class ReadModifyResolveNode;
     
    13911395        int m_numConstants;
    13921396        StatementVector m_children;
    1393 
    1394         void markAggregate(MarkStack&);
    13951397    };
    13961398
     
    14381440        }
    14391441
    1440         virtual void markAggregate(MarkStack&) { }
    1441 
    1442 #if ENABLE(JIT)
    1443         JITCode& generatedJITCode()
    1444         {
    1445             ASSERT(m_jitCode);
    1446             return m_jitCode;
    1447         }
    1448 
    1449         ExecutablePool* getExecutablePool()
    1450         {
    1451             return m_jitCode.getExecutablePool();
    1452         }
    1453 
    1454         void setJITCode(const JITCode jitCode)
    1455         {
    1456             m_jitCode = jitCode;
    1457         }
    1458 #endif
    1459 
    14601442    protected:
    14611443        void setSource(const SourceCode& source) { m_source = source; }
    1462 
    1463 #if ENABLE(JIT)
    1464         JITCode m_jitCode;
    1465 #endif
    14661444
    14671445    private:
     
    14751453        static PassRefPtr<ProgramNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
    14761454
    1477         ProgramCodeBlock& bytecode(ScopeChainNode* scopeChain)
     1455    private:
     1456        ProgramNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
     1457
     1458        virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
     1459    };
     1460
     1461    class EvalNode : public ScopeNode {
     1462    public:
     1463        static PassRefPtr<EvalNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
     1464
     1465        void partialDestroyData()
    14781466        {
    1479             if (!m_code)
    1480                 generateBytecode(scopeChain);
    1481             return *m_code;
     1467            // Eval code needs to hang on to its declaration stacks to keep declaration info alive until Interpreter::execute time,
     1468            // so the entire ScopeNodeData cannot be destoyed.
     1469            children().clear();
    14821470        }
    14831471
    1484 #if ENABLE(JIT)
    1485         JITCode& jitCode(ScopeChainNode* scopeChain)
    1486         {
    1487             if (!m_jitCode)
    1488                 generateJITCode(scopeChain);
    1489             return m_jitCode;
    1490         }
    1491 #endif
    1492 
    1493     private:
    1494         ProgramNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
    1495 
    1496         void generateBytecode(ScopeChainNode*);
    1497         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
    1498 
    1499 #if ENABLE(JIT)
    1500         void generateJITCode(ScopeChainNode*);
    1501 #endif
    1502 
    1503         OwnPtr<ProgramCodeBlock> m_code;
    1504     };
    1505 
    1506     class EvalNode : public ScopeNode {
    1507     public:
    1508         static PassRefPtr<EvalNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
    1509 
    1510         EvalCodeBlock& bytecode(ScopeChainNode* scopeChain)
    1511         {
    1512             if (!m_code)
    1513                 generateBytecode(scopeChain);
    1514             return *m_code;
    1515         }
    1516 
    1517         EvalCodeBlock& bytecodeForExceptionInfoReparse(ScopeChainNode*, CodeBlock*);
    1518 
    1519         virtual void markAggregate(MarkStack&);
    1520 
    1521 #if ENABLE(JIT)
    1522         JITCode& jitCode(ScopeChainNode* scopeChain)
    1523         {
    1524             if (!m_jitCode)
    1525                 generateJITCode(scopeChain);
    1526             return m_jitCode;
    1527         }
    1528 #endif
    1529 
    15301472    private:
    15311473        EvalNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
    15321474
    1533         void generateBytecode(ScopeChainNode*);
    1534         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
    1535 
    1536 #if ENABLE(JIT)
    1537         void generateJITCode(ScopeChainNode*);
    1538 #endif
    1539        
    1540         OwnPtr<EvalCodeBlock> m_code;
     1475        virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
    15411476    };
    15421477
     
    15441479        friend class JIT;
    15451480    public:
    1546 #if ENABLE(JIT)
    1547         static PassRefPtr<FunctionBodyNode> createNativeThunk(JSGlobalData*);
    1548 #endif
    15491481        static FunctionBodyNode* create(JSGlobalData*);
    15501482        static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
     
    15581490        virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
    15591491
    1560         bool isGenerated() const
    1561         {
    1562             return m_code;
    1563         }
    1564 
    1565         bool isHostFunction() const;
    1566 
    1567         virtual void markAggregate(MarkStack&);
    1568 
    15691492        void finishParsing(const SourceCode&, ParameterNode*, const Identifier& ident);
    15701493        void finishParsing(Identifier* parameters, size_t parameterCount, const Identifier& ident);
    15711494       
    1572         UString toSourceString() const { return source().toString(); }
    1573 
    1574         CodeBlock& bytecodeForExceptionInfoReparse(ScopeChainNode*, CodeBlock*);
    1575 #if ENABLE(JIT)
    1576         JITCode& jitCode(ScopeChainNode* scopeChain)
    1577         {
    1578             if (!m_jitCode)
    1579                 generateJITCode(scopeChain);
    1580             return m_jitCode;
    1581         }
    1582 #endif
    1583 
    1584         CodeBlock& bytecode(ScopeChainNode* scopeChain)
    1585         {
    1586             ASSERT(scopeChain);
    1587             if (!m_code)
    1588                 generateBytecode(scopeChain);
    1589             return *m_code;
    1590         }
    1591        
    1592         CodeBlock& generatedBytecode()
    1593         {
    1594             ASSERT(m_code);
    1595             return *m_code;
    1596         }
    1597 
    15981495        const Identifier& ident() { return m_ident; }
    15991496
    1600         JSFunction* make(ExecState*, ScopeChainNode*);
     1497        void reparseDataIfNecessary(ScopeChainNode* scopeChainNode);
    16011498
    16021499    private:
    16031500        FunctionBodyNode(JSGlobalData*);
    16041501        FunctionBodyNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
    1605 
    1606         void generateBytecode(ScopeChainNode*);
    1607 #if ENABLE(JIT)
    1608         void generateJITCode(ScopeChainNode*);
    1609 #endif
    16101502        Identifier m_ident;
    16111503        Identifier* m_parameters;
    16121504        size_t m_parameterCount;
    1613         OwnPtr<CodeBlock> m_code;
    16141505    };
    16151506
Note: See TracChangeset for help on using the changeset viewer.