- while (result->alternative())
- result = static_cast<FunctionCodeBlock*>(result->alternative());
- RELEASE_ASSERT(result);
- ASSERT(JITCode::isBaselineCode(result->getJITType()));
- return result;
-}
-
-JSObject* FunctionExecutable::compileOptimizedForCall(ExecState* exec, JSScope* scope, unsigned bytecodeIndex)
-{
- RELEASE_ASSERT(exec->vm().dynamicGlobalObject);
- ASSERT(!!m_codeBlockForCall);
- JSObject* error = 0;
- if (m_codeBlockForCall->getJITType() != JITCode::topTierJIT())
- error = compileForCallInternal(exec, scope, JITCode::nextTierJIT(m_codeBlockForCall->getJITType()), bytecodeIndex);
- ASSERT(!!m_codeBlockForCall);
- return error;
-}
-
-JSObject* FunctionExecutable::compileOptimizedForConstruct(ExecState* exec, JSScope* scope, unsigned bytecodeIndex)
-{
- RELEASE_ASSERT(exec->vm().dynamicGlobalObject);
- ASSERT(!!m_codeBlockForConstruct);
- JSObject* error = 0;
- if (m_codeBlockForConstruct->getJITType() != JITCode::topTierJIT())
- error = compileForConstructInternal(exec, scope, JITCode::nextTierJIT(m_codeBlockForConstruct->getJITType()), bytecodeIndex);
- ASSERT(!!m_codeBlockForConstruct);
- return error;
-}
-
-#if ENABLE(JIT)
-bool FunctionExecutable::jitCompileForCall(ExecState* exec)
-{
- return jitCompileFunctionIfAppropriate(exec, m_codeBlockForCall, m_jitCodeForCall, m_jitCodeForCallWithArityCheck, JITCode::bottomTierJIT(), UINT_MAX, JITCompilationCanFail);
-}
-
-bool FunctionExecutable::jitCompileForConstruct(ExecState* exec)
-{
- return jitCompileFunctionIfAppropriate(exec, m_codeBlockForConstruct, m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck, JITCode::bottomTierJIT(), UINT_MAX, JITCompilationCanFail);
-}
-#endif
-
-PassOwnPtr<FunctionCodeBlock> FunctionExecutable::produceCodeBlockFor(JSScope* scope, CodeSpecializationKind specializationKind, JSObject*& exception)
-{
- if (!!codeBlockFor(specializationKind))
- return adoptPtr(new FunctionCodeBlock(CodeBlock::CopyParsedBlock, *codeBlockFor(specializationKind)));
-
- VM* vm = scope->vm();
- JSGlobalObject* globalObject = scope->globalObject();
- ParserError error;
- DebuggerMode debuggerMode = globalObject->hasDebugger() ? DebuggerOn : DebuggerOff;
- ProfilerMode profilerMode = globalObject->hasProfiler() ? ProfilerOn : ProfilerOff;
- UnlinkedFunctionCodeBlock* unlinkedCodeBlock = m_unlinkedExecutable->codeBlockFor(*vm, scope, m_source, specializationKind, debuggerMode, profilerMode, error);
- recordParse(m_unlinkedExecutable->features(), m_unlinkedExecutable->hasCapturedVariables(), lineNo(), lastLine(), startColumn());
-
- if (!unlinkedCodeBlock) {
- exception = error.toErrorObject(globalObject, m_source);
- return nullptr;
- }
-
- SourceProvider* provider = source().provider();
- unsigned sourceOffset = source().startOffset();
- unsigned startColumn = source().startColumn();
-
- OwnPtr<FunctionCodeBlock> result = adoptPtr(new FunctionCodeBlock(this, unlinkedCodeBlock, globalObject, provider, sourceOffset, startColumn));
- result->copyPostParseDataFrom(codeBlockFor(specializationKind).get());
- return result.release();
-}
-
-
-JSObject* FunctionExecutable::compileForCallInternal(ExecState* exec, JSScope* scope, JITCode::JITType jitType, unsigned bytecodeIndex)
-{
- SamplingRegion samplingRegion(samplingDescription(jitType));
-
-#if !ENABLE(JIT)
- UNUSED_PARAM(exec);
- UNUSED_PARAM(jitType);
- UNUSED_PARAM(exec);
- UNUSED_PARAM(bytecodeIndex);
-#endif
- ASSERT((jitType == JITCode::bottomTierJIT()) == !m_codeBlockForCall);
- JSObject* exception = 0;
- OwnPtr<FunctionCodeBlock> newCodeBlock = produceCodeBlockFor(scope, CodeForCall, exception);
- if (!newCodeBlock)
- return exception;
-
- newCodeBlock->setAlternative(static_pointer_cast<CodeBlock>(m_codeBlockForCall.release()));
- m_codeBlockForCall = newCodeBlock.release();
-
- m_numParametersForCall = m_codeBlockForCall->numParameters();
- RELEASE_ASSERT(m_numParametersForCall);
-
-#if ENABLE(JIT)
- if (!prepareFunctionForExecution(exec, m_codeBlockForCall, m_jitCodeForCall, m_jitCodeForCallWithArityCheck, jitType, bytecodeIndex, CodeForCall))
- return 0;
-#endif
-
-#if ENABLE(JIT)
- 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, JSScope* scope, JITCode::JITType jitType, unsigned bytecodeIndex)
-{
- SamplingRegion samplingRegion(samplingDescription(jitType));
-
-#if !ENABLE(JIT)
- UNUSED_PARAM(jitType);
- UNUSED_PARAM(exec);
- UNUSED_PARAM(bytecodeIndex);
-#endif
-
- ASSERT((jitType == JITCode::bottomTierJIT()) == !m_codeBlockForConstruct);
- JSObject* exception = 0;
- OwnPtr<FunctionCodeBlock> newCodeBlock = produceCodeBlockFor(scope, CodeForConstruct, exception);
- if (!newCodeBlock)
- return exception;
-
- newCodeBlock->setAlternative(static_pointer_cast<CodeBlock>(m_codeBlockForConstruct.release()));
- m_codeBlockForConstruct = newCodeBlock.release();
-
- m_numParametersForConstruct = m_codeBlockForConstruct->numParameters();
- RELEASE_ASSERT(m_numParametersForConstruct);
-
-#if ENABLE(JIT)
- if (!prepareFunctionForExecution(exec, m_codeBlockForConstruct, m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck, jitType, bytecodeIndex, CodeForConstruct))
- return 0;
-#endif
-
-#if ENABLE(JIT)
- 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(VM& vm)
-{
- jettisonCodeBlock(vm, m_codeBlockForCall);
- m_jitCodeForCall = m_codeBlockForCall->getJITCode();
- m_jitCodeForCallWithArityCheck = m_codeBlockForCall->getJITCodeWithArityCheck();
-}
-
-void FunctionExecutable::jettisonOptimizedCodeForConstruct(VM& vm)
-{
- jettisonCodeBlock(vm, m_codeBlockForConstruct);
- m_jitCodeForConstruct = m_codeBlockForConstruct->getJITCode();
- m_jitCodeForConstructWithArityCheck = m_codeBlockForConstruct->getJITCodeWithArityCheck();