-JSObject* FunctionExecutable::compileOptimizedForCall(ExecState* exec, ScopeChainNode* scopeChainNode)
-{
- ASSERT(exec->globalData().dynamicGlobalObject);
- ASSERT(!!m_codeBlockForCall);
- JSObject* error = 0;
- if (m_codeBlockForCall->getJITType() != JITCode::topTierJIT())
- error = compileForCallInternal(exec, scopeChainNode, JITCode::nextTierJIT(m_codeBlockForCall->getJITType()));
- ASSERT(!!m_codeBlockForCall);
- return error;
-}
-
-JSObject* FunctionExecutable::compileOptimizedForConstruct(ExecState* exec, ScopeChainNode* scopeChainNode)
-{
- ASSERT(exec->globalData().dynamicGlobalObject);
- ASSERT(!!m_codeBlockForConstruct);
- JSObject* error = 0;
- if (m_codeBlockForConstruct->getJITType() != JITCode::topTierJIT())
- error = compileForConstructInternal(exec, scopeChainNode, JITCode::nextTierJIT(m_codeBlockForConstruct->getJITType()));
- ASSERT(!!m_codeBlockForConstruct);
- return error;
-}
-
-#if ENABLE(JIT)
-bool FunctionExecutable::jitCompileForCall(JSGlobalData& globalData)
-{
- return jitCompileFunctionIfAppropriate(globalData, m_codeBlockForCall, m_jitCodeForCall, m_jitCodeForCallWithArityCheck, m_symbolTable, JITCode::bottomTierJIT(), JITCompilationCanFail);
-}
-
-bool FunctionExecutable::jitCompileForConstruct(JSGlobalData& globalData)
-{
- return jitCompileFunctionIfAppropriate(globalData, m_codeBlockForConstruct, m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck, m_symbolTable, JITCode::bottomTierJIT(), JITCompilationCanFail);
-}
-#endif
-
-FunctionCodeBlock* FunctionExecutable::codeBlockWithBytecodeFor(CodeSpecializationKind kind)
-{
- return baselineCodeBlockFor(kind);
-}
-
-PassOwnPtr<FunctionCodeBlock> FunctionExecutable::produceCodeBlockFor(ScopeChainNode* scopeChainNode, CompilationKind compilationKind, CodeSpecializationKind specializationKind, JSObject*& exception)
-{
- if (!!codeBlockFor(specializationKind))
- return adoptPtr(new FunctionCodeBlock(CodeBlock::CopyParsedBlock, *codeBlockFor(specializationKind)));
-
- exception = 0;
- JSGlobalData* globalData = scopeChainNode->globalData;
- JSGlobalObject* globalObject = scopeChainNode->globalObject.get();
- RefPtr<FunctionBodyNode> body = parse<FunctionBodyNode>(globalData, globalObject, m_source, m_parameters.get(), isStrictMode() ? JSParseStrict : JSParseNormal, FunctionBodyNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, 0, 0, &exception);
-
- if (!body) {
- ASSERT(exception);
- return nullptr;
- }
- if (m_forceUsesArguments)
- body->setUsesArguments();
- body->finishParsing(m_parameters, m_name);
- recordParse(body->features(), body->hasCapturedVariables(), body->lineNo(), body->lastLine());
-
- OwnPtr<FunctionCodeBlock> result;
- ASSERT((compilationKind == FirstCompilation) == !codeBlockFor(specializationKind));
- result = adoptPtr(new FunctionCodeBlock(this, FunctionCode, globalObject, source().provider(), source().startOffset(), specializationKind == CodeForConstruct));
- OwnPtr<BytecodeGenerator> generator(adoptPtr(new BytecodeGenerator(body.get(), scopeChainNode, result->symbolTable(), result.get(), compilationKind)));
- exception = generator->generate();
- body->destroyData();
- if (exception)
- return nullptr;
-
- result->copyPostParseDataFrom(codeBlockFor(specializationKind).get());
- return result.release();
-}
-
-JSObject* FunctionExecutable::compileForCallInternal(ExecState* exec, ScopeChainNode* scopeChainNode, JITCode::JITType jitType)
-{
- SamplingRegion samplingRegion(samplingDescription(jitType));
-
-#if !ENABLE(JIT)
- UNUSED_PARAM(exec);
- UNUSED_PARAM(jitType);
- UNUSED_PARAM(exec);
-#endif
- ASSERT((jitType == JITCode::bottomTierJIT()) == !m_codeBlockForCall);
- JSObject* exception;
- OwnPtr<FunctionCodeBlock> newCodeBlock = produceCodeBlockFor(scopeChainNode, !!m_codeBlockForCall ? OptimizingCompilation : FirstCompilation, CodeForCall, exception);
- if (!newCodeBlock)
- return exception;
-
- newCodeBlock->setAlternative(static_pointer_cast<CodeBlock>(m_codeBlockForCall.release()));
- m_codeBlockForCall = newCodeBlock.release();
-
- m_numParametersForCall = m_codeBlockForCall->numParameters();
- ASSERT(m_numParametersForCall);
- m_numCapturedVariables = m_codeBlockForCall->m_numCapturedVars;
- m_symbolTable = m_codeBlockForCall->sharedSymbolTable();
-
-#if ENABLE(JIT)
- if (!prepareFunctionForExecution(exec->globalData(), m_codeBlockForCall, m_jitCodeForCall, m_jitCodeForCallWithArityCheck, m_symbolTable, jitType, CodeForCall))
- return 0;
-#endif
-
-#if ENABLE(JIT)
-#if ENABLE(CLASSIC_INTERPRETER)
- if (!m_jitCodeForCall)
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForCall));
- else
-#endif
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForCall) + m_jitCodeForCall.size());
-#else
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForCall));
-#endif
-
- return 0;
-}
-
-JSObject* FunctionExecutable::compileForConstructInternal(ExecState* exec, ScopeChainNode* scopeChainNode, JITCode::JITType jitType)
-{
- SamplingRegion samplingRegion(samplingDescription(jitType));
-
-#if !ENABLE(JIT)
- UNUSED_PARAM(jitType);
- UNUSED_PARAM(exec);
-#endif
-
- ASSERT((jitType == JITCode::bottomTierJIT()) == !m_codeBlockForConstruct);
- JSObject* exception;
- OwnPtr<FunctionCodeBlock> newCodeBlock = produceCodeBlockFor(scopeChainNode, !!m_codeBlockForConstruct ? OptimizingCompilation : FirstCompilation, CodeForConstruct, exception);
- if (!newCodeBlock)
- return exception;
-
- newCodeBlock->setAlternative(static_pointer_cast<CodeBlock>(m_codeBlockForConstruct.release()));
- m_codeBlockForConstruct = newCodeBlock.release();
-
- m_numParametersForConstruct = m_codeBlockForConstruct->numParameters();
- ASSERT(m_numParametersForConstruct);
- m_numCapturedVariables = m_codeBlockForConstruct->m_numCapturedVars;
- m_symbolTable = m_codeBlockForConstruct->sharedSymbolTable();
-
-#if ENABLE(JIT)
- if (!prepareFunctionForExecution(exec->globalData(), m_codeBlockForConstruct, m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck, m_symbolTable, jitType, CodeForConstruct))
- return 0;
-#endif
-
-#if ENABLE(JIT)
-#if ENABLE(CLASSIC_INTERPRETER)
- if (!m_jitCodeForConstruct)
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForConstruct));
- else
-#endif
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForConstruct) + m_jitCodeForConstruct.size());
-#else
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForConstruct));
-#endif
-
- return 0;
-}
-
-#if ENABLE(JIT)
-void FunctionExecutable::jettisonOptimizedCodeForCall(JSGlobalData& globalData)
-{
- jettisonCodeBlock(globalData, m_codeBlockForCall);
- m_jitCodeForCall = m_codeBlockForCall->getJITCode();
- m_jitCodeForCallWithArityCheck = m_codeBlockForCall->getJITCodeWithArityCheck();
-}
-
-void FunctionExecutable::jettisonOptimizedCodeForConstruct(JSGlobalData& globalData)
-{
- jettisonCodeBlock(globalData, m_codeBlockForConstruct);
- m_jitCodeForConstruct = m_codeBlockForConstruct->getJITCode();
- m_jitCodeForConstructWithArityCheck = m_codeBlockForConstruct->getJITCodeWithArityCheck();
-}
-#endif
-