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/bytecode/CodeBlock.cpp

    r47089 r47412  
    12491249}
    12501250
    1251 CodeBlock::CodeBlock(ScopeNode* ownerNode)
     1251CodeBlock::CodeBlock(ExecutableBase* ownerExecutable)
    12521252    : m_numCalleeRegisters(0)
    12531253    , m_numVars(0)
    12541254    , m_numParameters(0)
    1255     , m_ownerNode(ownerNode)
     1255    , m_ownerExecutable(ownerExecutable)
    12561256    , m_globalData(0)
    12571257#ifndef NDEBUG
     
    12711271}
    12721272
    1273 CodeBlock::CodeBlock(ScopeNode* ownerNode, CodeType codeType, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset)
     1273CodeBlock::CodeBlock(ExecutableBase* ownerExecutable, CodeType codeType, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset)
    12741274    : m_numCalleeRegisters(0)
    12751275    , m_numVars(0)
    12761276    , m_numParameters(0)
    1277     , m_ownerNode(ownerNode)
     1277    , m_ownerExecutable(ownerExecutable)
    12781278    , m_globalData(0)
    12791279#ifndef NDEBUG
    12801280    , m_instructionCount(0)
    12811281#endif
    1282     , m_needsFullScopeChain(ownerNode->needsActivation())
    1283     , m_usesEval(ownerNode->usesEval())
     1282    , m_needsFullScopeChain(ownerExecutable->needsActivation())
     1283    , m_usesEval(ownerExecutable->usesEval())
    12841284    , m_isNumericCompareFunction(false)
    12851285    , m_codeType(codeType)
     
    14381438    }
    14391439
    1440     for (size_t i = 0; i < m_functions.size(); ++i)
    1441         m_functions[i]->markAggregate(markStack);
    1442 
    1443     if (m_rareData)
    1444         m_rareData->m_evalCodeCache.markAggregate(markStack);
     1440    for (size_t i = 0; i < m_functionExprs.size(); ++i)
     1441        m_functionExprs[i]->markAggregate(markStack);
     1442    for (size_t i = 0; i < m_functionDecls.size(); ++i)
     1443        m_functionDecls[i]->markAggregate(markStack);
    14451444}
    14461445
     
    14641463    }
    14651464
    1466     switch (m_codeType) {
    1467         case FunctionCode: {
    1468             FunctionBodyNode* ownerFunctionBodyNode = static_cast<FunctionBodyNode*>(m_ownerNode);
    1469             RefPtr<FunctionBodyNode> newFunctionBody = m_globalData->parser->reparse<FunctionBodyNode>(m_globalData, ownerFunctionBodyNode);
    1470             ASSERT(newFunctionBody);
    1471             newFunctionBody->finishParsing(ownerFunctionBodyNode->copyParameters(), ownerFunctionBodyNode->parameterCount(), ownerFunctionBodyNode->ident());
    1472 
    1473             m_globalData->scopeNodeBeingReparsed = newFunctionBody.get();
    1474 
    1475             CodeBlock& newCodeBlock = newFunctionBody->bytecodeForExceptionInfoReparse(scopeChain, this);
    1476             ASSERT(newCodeBlock.m_exceptionInfo);
    1477             ASSERT(newCodeBlock.m_instructionCount == m_instructionCount);
    1478 
    1479 #if ENABLE(JIT)
    1480             JIT::compile(m_globalData, &newCodeBlock);
    1481             ASSERT(newFunctionBody->generatedJITCode().size() == ownerNode()->generatedJITCode().size());
    1482 #endif
    1483 
    1484             m_exceptionInfo.set(newCodeBlock.m_exceptionInfo.release());
    1485 
    1486             m_globalData->scopeNodeBeingReparsed = 0;
    1487 
    1488             break;
    1489         }
    1490         case EvalCode: {
    1491             EvalNode* ownerEvalNode = static_cast<EvalNode*>(m_ownerNode);
    1492             RefPtr<EvalNode> newEvalBody = m_globalData->parser->reparse<EvalNode>(m_globalData, ownerEvalNode);
    1493 
    1494             m_globalData->scopeNodeBeingReparsed = newEvalBody.get();
    1495 
    1496             EvalCodeBlock& newCodeBlock = newEvalBody->bytecodeForExceptionInfoReparse(scopeChain, this);
    1497             ASSERT(newCodeBlock.m_exceptionInfo);
    1498             ASSERT(newCodeBlock.m_instructionCount == m_instructionCount);
    1499 
    1500 #if ENABLE(JIT)
    1501             JIT::compile(m_globalData, &newCodeBlock);
    1502             ASSERT(newEvalBody->generatedJITCode().size() == ownerNode()->generatedJITCode().size());
    1503 #endif
    1504 
    1505             m_exceptionInfo.set(newCodeBlock.m_exceptionInfo.release());
    1506 
    1507             m_globalData->scopeNodeBeingReparsed = 0;
    1508 
    1509             break;
    1510         }
    1511         default:
    1512             // CodeBlocks for Global code blocks are transient and therefore to not gain from
    1513             // from throwing out there exception information.
    1514             ASSERT_NOT_REACHED();
    1515     }
     1465    m_exceptionInfo.set(m_ownerExecutable->reparseExceptionInfo(m_globalData, scopeChain, this));
    15161466}
    15171467
     
    15441494
    15451495    if (!m_exceptionInfo->m_lineInfo.size())
    1546         return m_ownerNode->source().firstLine(); // Empty function
     1496        return m_ownerExecutable->source().firstLine(); // Empty function
    15471497
    15481498    int low = 0;
     
    15571507   
    15581508    if (!low)
    1559         return m_ownerNode->source().firstLine();
     1509        return m_ownerExecutable->source().firstLine();
    15601510    return m_exceptionInfo->m_lineInfo[low - 1].lineNumber;
    15611511}
     
    16971647        return false;
    16981648    return true;
    1699 }
    1700 #endif
    1701 
    1702 #if ENABLE(JIT)
    1703 void CodeBlock::setJITCode(JITCode jitCode)
    1704 {
    1705     ASSERT(m_codeType != NativeCode);
    1706     ownerNode()->setJITCode(jitCode);
    1707 #if !ENABLE(OPCODE_SAMPLING)
    1708     if (!BytecodeGenerator::dumpsGeneratedCode())
    1709         m_instructions.clear();
    1710 #endif
    17111649}
    17121650#endif
     
    17271665
    17281666    m_identifiers.shrinkToFit();
    1729     m_functions.shrinkToFit();
     1667    m_functionDecls.shrinkToFit();
     1668    m_functionExprs.shrinkToFit();
    17301669    m_constantRegisters.shrinkToFit();
    17311670
Note: See TracChangeset for help on using the changeset viewer.