/*
- * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2010, 2013, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#include "Executable.h"
#include "BatchedTransitionOptimizer.h"
-#include "BytecodeGenerator.h"
#include "CodeBlock.h"
#include "DFGDriver.h"
-#include "ExecutionHarness.h"
#include "JIT.h"
-#include "JITDriver.h"
-#include "Operations.h"
+#include "JSCInlines.h"
+#include "JSFunctionNameScope.h"
+#include "LLIntEntrypoint.h"
#include "Parser.h"
+#include "ProfilerDatabase.h"
+#include "TypeProfiler.h"
+#include <wtf/CommaPrinter.h>
#include <wtf/Vector.h>
#include <wtf/text/StringBuilder.h>
namespace JSC {
-const ClassInfo ExecutableBase::s_info = { "Executable", 0, 0, 0, CREATE_METHOD_TABLE(ExecutableBase) };
+const ClassInfo ExecutableBase::s_info = { "Executable", 0, 0, CREATE_METHOD_TABLE(ExecutableBase) };
-#if ENABLE(JIT)
void ExecutableBase::destroy(JSCell* cell)
{
static_cast<ExecutableBase*>(cell)->ExecutableBase::~ExecutableBase();
}
-#endif
void ExecutableBase::clearCode()
{
#if ENABLE(JIT)
- m_jitCodeForCall.clear();
- m_jitCodeForConstruct.clear();
+ m_jitCodeForCall = nullptr;
+ m_jitCodeForConstruct = nullptr;
m_jitCodeForCallWithArityCheck = MacroAssemblerCodePtr();
m_jitCodeForConstructWithArityCheck = MacroAssemblerCodePtr();
+ m_jitCodeForCallWithArityCheckAndPreserveRegs = MacroAssemblerCodePtr();
+ m_jitCodeForConstructWithArityCheckAndPreserveRegs = MacroAssemblerCodePtr();
#endif
m_numParametersForCall = NUM_PARAMETERS_NOT_COMPILED;
m_numParametersForConstruct = NUM_PARAMETERS_NOT_COMPILED;
}
#endif
-const ClassInfo NativeExecutable::s_info = { "NativeExecutable", &ExecutableBase::s_info, 0, 0, CREATE_METHOD_TABLE(NativeExecutable) };
+const ClassInfo NativeExecutable::s_info = { "NativeExecutable", &ExecutableBase::s_info, 0, CREATE_METHOD_TABLE(NativeExecutable) };
-#if ENABLE(JIT)
void NativeExecutable::destroy(JSCell* cell)
{
static_cast<NativeExecutable*>(cell)->NativeExecutable::~NativeExecutable();
}
-#endif
#if ENABLE(DFG_JIT)
Intrinsic NativeExecutable::intrinsic() const
}
#endif
-#if ENABLE(JIT)
-// Utility method used for jettisoning code blocks.
-template<typename T>
-static void jettisonCodeBlock(VM& vm, OwnPtr<T>& codeBlock)
+const ClassInfo ScriptExecutable::s_info = { "ScriptExecutable", &ExecutableBase::s_info, 0, CREATE_METHOD_TABLE(ScriptExecutable) };
+
+ScriptExecutable::ScriptExecutable(Structure* structure, VM& vm, const SourceCode& source, bool isInStrictContext)
+ : ExecutableBase(vm, structure, NUM_PARAMETERS_NOT_COMPILED)
+ , m_source(source)
+ , m_features(isInStrictContext ? StrictModeFeature : 0)
+ , m_hasCapturedVariables(false)
+ , m_neverInline(false)
+ , m_didTryToEnterInLoop(false)
+ , m_overrideLineNumber(-1)
+ , m_firstLine(-1)
+ , m_lastLine(-1)
+ , m_startColumn(UINT_MAX)
+ , m_endColumn(UINT_MAX)
+ , m_typeProfilingStartOffset(UINT_MAX)
+ , m_typeProfilingEndOffset(UINT_MAX)
{
- ASSERT(JITCode::isOptimizingJIT(codeBlock->getJITType()));
- ASSERT(codeBlock->alternative());
- OwnPtr<T> codeBlockToJettison = codeBlock.release();
- codeBlock = static_pointer_cast<T>(codeBlockToJettison->releaseAlternative());
- codeBlockToJettison->unlinkIncomingCalls();
- vm.heap.jettisonDFGCodeBlock(static_pointer_cast<CodeBlock>(codeBlockToJettison.release()));
}
-#endif
-
-const ClassInfo ScriptExecutable::s_info = { "ScriptExecutable", &ExecutableBase::s_info, 0, 0, CREATE_METHOD_TABLE(ScriptExecutable) };
-#if ENABLE(JIT)
void ScriptExecutable::destroy(JSCell* cell)
{
static_cast<ScriptExecutable*>(cell)->ScriptExecutable::~ScriptExecutable();
}
+
+void ScriptExecutable::installCode(CodeBlock* genericCodeBlock)
+{
+ RELEASE_ASSERT(genericCodeBlock->ownerExecutable() == this);
+ RELEASE_ASSERT(JITCode::isExecutableScript(genericCodeBlock->jitType()));
+
+ if (Options::verboseOSR())
+ dataLog("Installing ", *genericCodeBlock, "\n");
+
+ VM& vm = *genericCodeBlock->vm();
+
+ if (vm.m_perBytecodeProfiler)
+ vm.m_perBytecodeProfiler->ensureBytecodesFor(genericCodeBlock);
+
+ ASSERT(vm.heap.isDeferred());
+
+ CodeSpecializationKind kind = genericCodeBlock->specializationKind();
+
+ RefPtr<CodeBlock> oldCodeBlock;
+
+ switch (kind) {
+ case CodeForCall:
+ m_jitCodeForCall = genericCodeBlock->jitCode();
+ m_jitCodeForCallWithArityCheck = MacroAssemblerCodePtr();
+ m_jitCodeForCallWithArityCheckAndPreserveRegs = MacroAssemblerCodePtr();
+ m_numParametersForCall = genericCodeBlock->numParameters();
+ break;
+ case CodeForConstruct:
+ m_jitCodeForConstruct = genericCodeBlock->jitCode();
+ m_jitCodeForConstructWithArityCheck = MacroAssemblerCodePtr();
+ m_jitCodeForConstructWithArityCheckAndPreserveRegs = MacroAssemblerCodePtr();
+ m_numParametersForConstruct = genericCodeBlock->numParameters();
+ break;
+ }
+
+ switch (genericCodeBlock->codeType()) {
+ case GlobalCode: {
+ ProgramExecutable* executable = jsCast<ProgramExecutable*>(this);
+ ProgramCodeBlock* codeBlock = static_cast<ProgramCodeBlock*>(genericCodeBlock);
+
+ ASSERT(kind == CodeForCall);
+
+ oldCodeBlock = executable->m_programCodeBlock;
+ executable->m_programCodeBlock = codeBlock;
+ break;
+ }
+
+ case EvalCode: {
+ EvalExecutable* executable = jsCast<EvalExecutable*>(this);
+ EvalCodeBlock* codeBlock = static_cast<EvalCodeBlock*>(genericCodeBlock);
+
+ ASSERT(kind == CodeForCall);
+
+ oldCodeBlock = executable->m_evalCodeBlock;
+ executable->m_evalCodeBlock = codeBlock;
+ break;
+ }
+
+ case FunctionCode: {
+ FunctionExecutable* executable = jsCast<FunctionExecutable*>(this);
+ FunctionCodeBlock* codeBlock = static_cast<FunctionCodeBlock*>(genericCodeBlock);
+
+ switch (kind) {
+ case CodeForCall:
+ oldCodeBlock = executable->m_codeBlockForCall;
+ executable->m_codeBlockForCall = codeBlock;
+ break;
+ case CodeForConstruct:
+ oldCodeBlock = executable->m_codeBlockForConstruct;
+ executable->m_codeBlockForConstruct = codeBlock;
+ break;
+ }
+ break;
+ } }
+
+ if (oldCodeBlock)
+ oldCodeBlock->unlinkIncomingCalls();
+
+ Debugger* debugger = genericCodeBlock->globalObject()->debugger();
+ if (debugger)
+ debugger->registerCodeBlock(genericCodeBlock);
+
+ Heap::heap(this)->writeBarrier(this);
+}
+
+RefPtr<CodeBlock> ScriptExecutable::newCodeBlockFor(
+ CodeSpecializationKind kind, JSFunction* function, JSScope* scope, JSObject*& exception)
+{
+ VM* vm = scope->vm();
+
+ ASSERT(vm->heap.isDeferred());
+ ASSERT(startColumn() != UINT_MAX);
+ ASSERT(endColumn() != UINT_MAX);
+
+ if (classInfo() == EvalExecutable::info()) {
+ EvalExecutable* executable = jsCast<EvalExecutable*>(this);
+ RELEASE_ASSERT(kind == CodeForCall);
+ RELEASE_ASSERT(!executable->m_evalCodeBlock);
+ RELEASE_ASSERT(!function);
+ return adoptRef(new EvalCodeBlock(
+ executable, executable->m_unlinkedEvalCodeBlock.get(), scope,
+ executable->source().provider()));
+ }
+
+ if (classInfo() == ProgramExecutable::info()) {
+ ProgramExecutable* executable = jsCast<ProgramExecutable*>(this);
+ RELEASE_ASSERT(kind == CodeForCall);
+ RELEASE_ASSERT(!executable->m_programCodeBlock);
+ RELEASE_ASSERT(!function);
+ return adoptRef(new ProgramCodeBlock(
+ executable, executable->m_unlinkedProgramCodeBlock.get(), scope,
+ executable->source().provider(), executable->source().startColumn()));
+ }
+
+ RELEASE_ASSERT(classInfo() == FunctionExecutable::info());
+ RELEASE_ASSERT(function);
+ FunctionExecutable* executable = jsCast<FunctionExecutable*>(this);
+ RELEASE_ASSERT(!executable->codeBlockFor(kind));
+ JSGlobalObject* globalObject = scope->globalObject();
+ ParserError error;
+ DebuggerMode debuggerMode = globalObject->hasDebugger() ? DebuggerOn : DebuggerOff;
+ ProfilerMode profilerMode = globalObject->hasProfiler() ? ProfilerOn : ProfilerOff;
+ UnlinkedFunctionCodeBlock* unlinkedCodeBlock =
+ executable->m_unlinkedExecutable->codeBlockFor(
+ *vm, executable->m_source, kind, debuggerMode, profilerMode, error);
+ recordParse(executable->m_unlinkedExecutable->features(), executable->m_unlinkedExecutable->hasCapturedVariables(), firstLine(), lastLine(), startColumn(), endColumn());
+ if (!unlinkedCodeBlock) {
+ exception = vm->throwException(
+ globalObject->globalExec(),
+ error.toErrorObject(globalObject, executable->m_source));
+ return nullptr;
+ }
+
+ // Parsing reveals whether our function uses features that require a separate function name object in the scope chain.
+ // Be sure to add this scope before linking the bytecode because this scope will change the resolution depth of non-local variables.
+ if (functionNameIsInScope(executable->name(), executable->functionMode())
+ && functionNameScopeIsDynamic(executable->usesEval(), executable->isStrictMode())) {
+ // We shouldn't have to do this. But we do, because bytecode linking requires a real scope
+ // chain.
+ // FIXME: https://bugs.webkit.org/show_bug.cgi?id=141885
+ SymbolTable* symbolTable =
+ SymbolTable::createNameScopeTable(*vm, executable->name(), ReadOnly | DontDelete);
+ scope = JSFunctionNameScope::create(
+ *vm, scope->globalObject(), scope, symbolTable, function);
+ }
+
+ SourceProvider* provider = executable->source().provider();
+ unsigned sourceOffset = executable->source().startOffset();
+ unsigned startColumn = executable->source().startColumn();
+
+ return adoptRef(new FunctionCodeBlock(
+ executable, unlinkedCodeBlock, scope, provider, sourceOffset, startColumn));
+}
+
+PassRefPtr<CodeBlock> ScriptExecutable::newReplacementCodeBlockFor(
+ CodeSpecializationKind kind)
+{
+ if (classInfo() == EvalExecutable::info()) {
+ RELEASE_ASSERT(kind == CodeForCall);
+ EvalExecutable* executable = jsCast<EvalExecutable*>(this);
+ EvalCodeBlock* baseline = static_cast<EvalCodeBlock*>(
+ executable->m_evalCodeBlock->baselineVersion());
+ RefPtr<EvalCodeBlock> result = adoptRef(new EvalCodeBlock(
+ CodeBlock::CopyParsedBlock, *baseline));
+ result->setAlternative(baseline);
+ return result;
+ }
+
+ if (classInfo() == ProgramExecutable::info()) {
+ RELEASE_ASSERT(kind == CodeForCall);
+ ProgramExecutable* executable = jsCast<ProgramExecutable*>(this);
+ ProgramCodeBlock* baseline = static_cast<ProgramCodeBlock*>(
+ executable->m_programCodeBlock->baselineVersion());
+ RefPtr<ProgramCodeBlock> result = adoptRef(new ProgramCodeBlock(
+ CodeBlock::CopyParsedBlock, *baseline));
+ result->setAlternative(baseline);
+ return result;
+ }
+
+ RELEASE_ASSERT(classInfo() == FunctionExecutable::info());
+ FunctionExecutable* executable = jsCast<FunctionExecutable*>(this);
+ FunctionCodeBlock* baseline = static_cast<FunctionCodeBlock*>(
+ executable->codeBlockFor(kind)->baselineVersion());
+ RefPtr<FunctionCodeBlock> result = adoptRef(new FunctionCodeBlock(
+ CodeBlock::CopyParsedBlock, *baseline));
+ result->setAlternative(baseline);
+ return result;
+}
+
+static void setupLLInt(VM& vm, CodeBlock* codeBlock)
+{
+ LLInt::setEntrypoint(vm, codeBlock);
+}
+
+static void setupJIT(VM& vm, CodeBlock* codeBlock)
+{
+#if ENABLE(JIT)
+ CompilationResult result = JIT::compile(&vm, codeBlock, JITCompilationMustSucceed);
+ RELEASE_ASSERT(result == CompilationSuccessful);
+#else
+ UNUSED_PARAM(vm);
+ UNUSED_PARAM(codeBlock);
+ UNREACHABLE_FOR_PLATFORM();
#endif
+}
-const ClassInfo EvalExecutable::s_info = { "EvalExecutable", &ScriptExecutable::s_info, 0, 0, CREATE_METHOD_TABLE(EvalExecutable) };
+JSObject* ScriptExecutable::prepareForExecutionImpl(
+ ExecState* exec, JSFunction* function, JSScope* scope, CodeSpecializationKind kind)
+{
+ VM& vm = exec->vm();
+ DeferGC deferGC(vm.heap);
+
+ JSObject* exception = 0;
+ RefPtr<CodeBlock> codeBlock = newCodeBlockFor(kind, function, scope, exception);
+ if (!codeBlock) {
+ RELEASE_ASSERT(exception);
+ return exception;
+ }
+
+ if (Options::validateBytecode())
+ codeBlock->validate();
+
+ if (Options::useLLInt())
+ setupLLInt(vm, codeBlock.get());
+ else
+ setupJIT(vm, codeBlock.get());
+
+ installCode(codeBlock.get());
+ return 0;
+}
+
+const ClassInfo EvalExecutable::s_info = { "EvalExecutable", &ScriptExecutable::s_info, 0, CREATE_METHOD_TABLE(EvalExecutable) };
-EvalExecutable::EvalExecutable(ExecState* exec, PassRefPtr<CodeCache> codeCache, const SourceCode& source, bool inStrictContext)
- : ScriptExecutable(exec->vm().evalExecutableStructure.get(), exec, source, inStrictContext)
- , m_codeCache(codeCache)
+EvalExecutable* EvalExecutable::create(ExecState* exec, const SourceCode& source, bool isInStrictContext, ThisTDZMode thisTDZMode)
+{
+ JSGlobalObject* globalObject = exec->lexicalGlobalObject();
+ if (!globalObject->evalEnabled()) {
+ exec->vm().throwException(exec, createEvalError(exec, globalObject->evalDisabledErrorMessage()));
+ return 0;
+ }
+
+ EvalExecutable* executable = new (NotNull, allocateCell<EvalExecutable>(*exec->heap())) EvalExecutable(exec, source, isInStrictContext);
+ executable->finishCreation(exec->vm());
+
+ UnlinkedEvalCodeBlock* unlinkedEvalCode = globalObject->createEvalCodeBlock(exec, executable, thisTDZMode);
+ if (!unlinkedEvalCode)
+ return 0;
+
+ executable->m_unlinkedEvalCodeBlock.set(exec->vm(), executable, unlinkedEvalCode);
+
+ return executable;
+}
+
+EvalExecutable::EvalExecutable(ExecState* exec, const SourceCode& source, bool inStrictContext)
+ : ScriptExecutable(exec->vm().evalExecutableStructure.get(), exec->vm(), source, inStrictContext)
{
}
static_cast<EvalExecutable*>(cell)->EvalExecutable::~EvalExecutable();
}
-const ClassInfo ProgramExecutable::s_info = { "ProgramExecutable", &ScriptExecutable::s_info, 0, 0, CREATE_METHOD_TABLE(ProgramExecutable) };
+const ClassInfo ProgramExecutable::s_info = { "ProgramExecutable", &ScriptExecutable::s_info, 0, CREATE_METHOD_TABLE(ProgramExecutable) };
ProgramExecutable::ProgramExecutable(ExecState* exec, const SourceCode& source)
- : ScriptExecutable(exec->vm().programExecutableStructure.get(), exec, source, false)
+ : ScriptExecutable(exec->vm().programExecutableStructure.get(), exec->vm(), source, false)
{
+ m_typeProfilingStartOffset = 0;
+ m_typeProfilingEndOffset = source.length() - 1;
+ if (exec->vm().typeProfiler() || exec->vm().controlFlowProfiler())
+ exec->vm().functionHasExecutedCache()->insertUnexecutedRange(sourceID(), m_typeProfilingStartOffset, m_typeProfilingEndOffset);
}
void ProgramExecutable::destroy(JSCell* cell)
static_cast<ProgramExecutable*>(cell)->ProgramExecutable::~ProgramExecutable();
}
-const ClassInfo FunctionExecutable::s_info = { "FunctionExecutable", &ScriptExecutable::s_info, 0, 0, CREATE_METHOD_TABLE(FunctionExecutable) };
+const ClassInfo FunctionExecutable::s_info = { "FunctionExecutable", &ScriptExecutable::s_info, 0, CREATE_METHOD_TABLE(FunctionExecutable) };
-FunctionExecutable::FunctionExecutable(VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable, unsigned firstLine, unsigned lastLine, unsigned startColumn)
+FunctionExecutable::FunctionExecutable(VM& vm, const SourceCode& source,
+ UnlinkedFunctionExecutable* unlinkedExecutable, unsigned firstLine,
+ unsigned lastLine, unsigned startColumn, unsigned endColumn)
: ScriptExecutable(vm.functionExecutableStructure.get(), vm, source, unlinkedExecutable->isInStrictContext())
, m_unlinkedExecutable(vm, this, unlinkedExecutable)
{
ASSERT(source.length());
m_firstLine = firstLine;
m_lastLine = lastLine;
+ ASSERT(startColumn != UINT_MAX);
+ ASSERT(endColumn != UINT_MAX);
m_startColumn = startColumn;
+ m_endColumn = endColumn;
+ m_parametersStartOffset = unlinkedExecutable->parametersStartOffset();
+ m_typeProfilingStartOffset = unlinkedExecutable->typeProfilingStartOffset();
+ m_typeProfilingEndOffset = unlinkedExecutable->typeProfilingEndOffset();
}
-void FunctionExecutable::destroy(JSCell* cell)
-{
- static_cast<FunctionExecutable*>(cell)->FunctionExecutable::~FunctionExecutable();
-}
-
-JSObject* EvalExecutable::compileOptimized(ExecState* exec, JSScope* scope, unsigned bytecodeIndex)
+void FunctionExecutable::finishCreation(VM& vm)
{
- ASSERT(exec->vm().dynamicGlobalObject);
- ASSERT(!!m_evalCodeBlock);
- JSObject* error = 0;
- if (m_evalCodeBlock->getJITType() != JITCode::topTierJIT())
- error = compileInternal(exec, scope, JITCode::nextTierJIT(m_evalCodeBlock->getJITType()), bytecodeIndex);
- ASSERT(!!m_evalCodeBlock);
- return error;
+ Base::finishCreation(vm);
+ m_singletonFunction.set(vm, this, InferredValue::create(vm));
}
-#if ENABLE(JIT)
-bool EvalExecutable::jitCompile(ExecState* exec)
+void FunctionExecutable::destroy(JSCell* cell)
{
- return jitCompileIfAppropriate(exec, m_evalCodeBlock, m_jitCodeForCall, JITCode::bottomTierJIT(), UINT_MAX, JITCompilationCanFail);
+ static_cast<FunctionExecutable*>(cell)->FunctionExecutable::~FunctionExecutable();
}
-#endif
inline const char* samplingDescription(JITCode::JITType jitType)
{
return "Baseline Compilation (TOTAL)";
case JITCode::DFGJIT:
return "DFG Compilation (TOTAL)";
+ case JITCode::FTLJIT:
+ return "FTL Compilation (TOTAL)";
default:
RELEASE_ASSERT_NOT_REACHED();
return 0;
}
}
-JSObject* EvalExecutable::compileInternal(ExecState* exec, JSScope* scope, JITCode::JITType jitType, unsigned bytecodeIndex)
-{
- SamplingRegion samplingRegion(samplingDescription(jitType));
-
-#if !ENABLE(JIT)
- UNUSED_PARAM(jitType);
- UNUSED_PARAM(bytecodeIndex);
-#endif
- VM* vm = &exec->vm();
- JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
-
- if (!!m_evalCodeBlock) {
- OwnPtr<EvalCodeBlock> newCodeBlock = adoptPtr(new EvalCodeBlock(CodeBlock::CopyParsedBlock, *m_evalCodeBlock));
- newCodeBlock->setAlternative(static_pointer_cast<CodeBlock>(m_evalCodeBlock.release()));
- m_evalCodeBlock = newCodeBlock.release();
- } else {
- UNUSED_PARAM(scope);
- UNUSED_PARAM(vm);
- UNUSED_PARAM(lexicalGlobalObject);
- if (!lexicalGlobalObject->evalEnabled())
- return throwError(exec, createEvalError(exec, lexicalGlobalObject->evalDisabledErrorMessage()));
-
- JSObject* exception = 0;
- UnlinkedEvalCodeBlock* unlinkedEvalCode = lexicalGlobalObject->createEvalCodeBlock(m_codeCache.get(), exec, scope, this, &exception);
- if (!unlinkedEvalCode)
- return exception;
-
- OwnPtr<CodeBlock> previousCodeBlock = m_evalCodeBlock.release();
- ASSERT((jitType == JITCode::bottomTierJIT()) == !previousCodeBlock);
- m_unlinkedEvalCodeBlock.set(*vm, this, unlinkedEvalCode);
- m_evalCodeBlock = adoptPtr(new EvalCodeBlock(this, unlinkedEvalCode, lexicalGlobalObject, source().provider(), scope->localDepth(), previousCodeBlock.release()));
- m_evalCodeBlock->copyPostParseDataFromAlternative();
- }
-
-#if ENABLE(JIT)
- if (!prepareForExecution(exec, m_evalCodeBlock, m_jitCodeForCall, jitType, bytecodeIndex))
- return 0;
-#endif
-
-#if ENABLE(JIT)
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_evalCodeBlock) + m_jitCodeForCall.size());
-#else
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_evalCodeBlock));
-#endif
-
- return 0;
-}
-
-#if ENABLE(JIT)
-void EvalExecutable::jettisonOptimizedCode(VM& vm)
-{
- jettisonCodeBlock(vm, m_evalCodeBlock);
- m_jitCodeForCall = m_evalCodeBlock->getJITCode();
- ASSERT(!m_jitCodeForCallWithArityCheck);
-}
-#endif
-
void EvalExecutable::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
EvalExecutable* thisObject = jsCast<EvalExecutable*>(cell);
- ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
- COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
- ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
ScriptExecutable::visitChildren(thisObject, visitor);
if (thisObject->m_evalCodeBlock)
thisObject->m_evalCodeBlock->visitAggregate(visitor);
void EvalExecutable::clearCode()
{
- m_evalCodeBlock.clear();
+ m_evalCodeBlock = nullptr;
m_unlinkedEvalCodeBlock.clear();
Base::clearCode();
}
ParserError error;
VM* vm = &exec->vm();
JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
- RefPtr<ProgramNode> programNode = parse<ProgramNode>(vm, m_source, 0, Identifier(), JSParseNormal, ProgramNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, error);
+ std::unique_ptr<ProgramNode> programNode = parse<ProgramNode>(
+ vm, m_source, 0, Identifier(), JSParserBuiltinMode::NotBuiltin,
+ JSParserStrictMode::NotStrict, JSParserCodeType::Program, error);
if (programNode)
return 0;
- ASSERT(error.m_type != ParserError::ErrorNone);
+ ASSERT(error.isValid());
return error.toErrorObject(lexicalGlobalObject, m_source);
}
-JSObject* ProgramExecutable::compileOptimized(ExecState* exec, JSScope* scope, unsigned bytecodeIndex)
-{
- RELEASE_ASSERT(exec->vm().dynamicGlobalObject);
- ASSERT(!!m_programCodeBlock);
- JSObject* error = 0;
- if (m_programCodeBlock->getJITType() != JITCode::topTierJIT())
- error = compileInternal(exec, scope, JITCode::nextTierJIT(m_programCodeBlock->getJITType()), bytecodeIndex);
- ASSERT(!!m_programCodeBlock);
- return error;
-}
-
-#if ENABLE(JIT)
-bool ProgramExecutable::jitCompile(ExecState* exec)
-{
- return jitCompileIfAppropriate(exec, m_programCodeBlock, m_jitCodeForCall, JITCode::bottomTierJIT(), UINT_MAX, JITCompilationCanFail);
-}
-#endif
-
-JSObject* ProgramExecutable::compileInternal(ExecState* exec, JSScope* scope, JITCode::JITType jitType, unsigned bytecodeIndex)
-{
- SamplingRegion samplingRegion(samplingDescription(jitType));
-
-#if !ENABLE(JIT)
- UNUSED_PARAM(exec);
- UNUSED_PARAM(jitType);
- UNUSED_PARAM(bytecodeIndex);
-#endif
- if (!!m_programCodeBlock) {
- OwnPtr<ProgramCodeBlock> newCodeBlock = adoptPtr(new ProgramCodeBlock(CodeBlock::CopyParsedBlock, *m_programCodeBlock));
- newCodeBlock->setAlternative(static_pointer_cast<CodeBlock>(m_programCodeBlock.release()));
- m_programCodeBlock = newCodeBlock.release();
- } else {
- JSGlobalObject* globalObject = scope->globalObject();
- m_programCodeBlock = adoptPtr(new ProgramCodeBlock(this, m_unlinkedProgramCodeBlock.get(), globalObject, source().provider(), source().startColumn(), m_programCodeBlock.release()));
- m_programCodeBlock->copyPostParseDataFromAlternative();
- }
-
-#if ENABLE(JIT)
- if (!prepareForExecution(exec, m_programCodeBlock, m_jitCodeForCall, jitType, bytecodeIndex))
- return 0;
-#endif
-
-#if ENABLE(JIT)
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_programCodeBlock) + m_jitCodeForCall.size());
-#else
- Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_programCodeBlock));
-#endif
-
- return 0;
-}
-
-#if ENABLE(JIT)
-void ProgramExecutable::jettisonOptimizedCode(VM& vm)
-{
- jettisonCodeBlock(vm, m_programCodeBlock);
- m_jitCodeForCall = m_programCodeBlock->getJITCode();
- ASSERT(!m_jitCodeForCallWithArityCheck);
-}
-#endif
-
void ProgramExecutable::unlinkCalls()
{
#if ENABLE(JIT)
#endif
}
-int ProgramExecutable::addGlobalVar(JSGlobalObject* globalObject, const Identifier& ident, ConstantMode constantMode, FunctionMode functionMode)
-{
- // Try to share the symbolTable if possible
- SharedSymbolTable* symbolTable = globalObject->symbolTable();
- UNUSED_PARAM(functionMode);
- int index = symbolTable->size();
- SymbolTableEntry newEntry(index, (constantMode == IsConstant) ? ReadOnly : 0);
- if (functionMode == IsFunctionToSpecialize)
- newEntry.attemptToWatch();
- SymbolTable::AddResult result = symbolTable->add(ident.impl(), newEntry);
- if (!result.isNewEntry) {
- result.iterator->value.notifyWrite();
- index = result.iterator->value.getIndex();
- }
- return index;
-}
-
JSObject* ProgramExecutable::initializeGlobalProperties(VM& vm, CallFrame* callFrame, JSScope* scope)
{
RELEASE_ASSERT(scope);
ASSERT(&globalObject->vm() == &vm);
JSObject* exception = 0;
- UnlinkedProgramCodeBlock* unlinkedCode = globalObject->createProgramCodeBlock(callFrame, this, &exception);
+ UnlinkedProgramCodeBlock* unlinkedCodeBlock = globalObject->createProgramCodeBlock(callFrame, this, &exception);
if (exception)
return exception;
- m_unlinkedProgramCodeBlock.set(vm, this, unlinkedCode);
+ m_unlinkedProgramCodeBlock.set(vm, this, unlinkedCodeBlock);
BatchedTransitionOptimizer optimizer(vm, globalObject);
- const UnlinkedProgramCodeBlock::VariableDeclations& variableDeclarations = unlinkedCode->variableDeclarations();
- const UnlinkedProgramCodeBlock::FunctionDeclations& functionDeclarations = unlinkedCode->functionDeclarations();
-
- size_t newGlobals = variableDeclarations.size() + functionDeclarations.size();
- if (!newGlobals)
- return 0;
- globalObject->addRegisters(newGlobals);
- CallFrame* globalExec = globalObject->globalExec();
-
- for (size_t i = 0; i < functionDeclarations.size(); ++i) {
- bool propertyDidExist = globalObject->removeDirect(vm, functionDeclarations[i].first); // Newly declared functions overwrite existing properties.
- UnlinkedFunctionExecutable* unlinkedFunctionExecutable = functionDeclarations[i].second.get();
- JSValue value = JSFunction::create(globalExec, unlinkedFunctionExecutable->link(vm, m_source, lineNo(), 0), scope);
- int index = addGlobalVar(globalObject, functionDeclarations[i].first, IsVariable,
- !propertyDidExist ? IsFunctionToSpecialize : NotFunctionOrNotSpecializable);
- globalObject->registerAt(index).set(vm, globalObject, value);
+ const UnlinkedProgramCodeBlock::VariableDeclations& variableDeclarations = unlinkedCodeBlock->variableDeclarations();
+
+ for (size_t i = 0, numberOfFunctions = unlinkedCodeBlock->numberOfFunctionDecls(); i < numberOfFunctions; ++i) {
+ UnlinkedFunctionExecutable* unlinkedFunctionExecutable = unlinkedCodeBlock->functionDecl(i);
+ ASSERT(!unlinkedFunctionExecutable->name().isEmpty());
+ globalObject->addFunction(callFrame, unlinkedFunctionExecutable->name());
+ if (vm.typeProfiler() || vm.controlFlowProfiler()) {
+ vm.functionHasExecutedCache()->insertUnexecutedRange(sourceID(),
+ unlinkedFunctionExecutable->typeProfilingStartOffset(),
+ unlinkedFunctionExecutable->typeProfilingEndOffset());
+ }
}
for (size_t i = 0; i < variableDeclarations.size(); ++i) {
- if (globalObject->hasProperty(globalExec, variableDeclarations[i].first))
- continue;
- addGlobalVar(globalObject, variableDeclarations[i].first,
- (variableDeclarations[i].second & DeclarationStacks::IsConstant) ? IsConstant : IsVariable,
- NotFunctionOrNotSpecializable);
+ if (variableDeclarations[i].second & DeclarationStacks::IsConstant)
+ globalObject->addConst(callFrame, variableDeclarations[i].first);
+ else
+ globalObject->addVar(callFrame, variableDeclarations[i].first);
}
return 0;
}
void ProgramExecutable::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
ProgramExecutable* thisObject = jsCast<ProgramExecutable*>(cell);
- ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
- COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
- ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
ScriptExecutable::visitChildren(thisObject, visitor);
visitor.append(&thisObject->m_unlinkedProgramCodeBlock);
if (thisObject->m_programCodeBlock)
void ProgramExecutable::clearCode()
{
- m_programCodeBlock.clear();
+ m_programCodeBlock = nullptr;
m_unlinkedProgramCodeBlock.clear();
Base::clearCode();
}
}
if (!result)
return 0;
- 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;
+ return static_cast<FunctionCodeBlock*>(result->baselineAlternative());
}
-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();
-}
-#endif
-
void FunctionExecutable::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
FunctionExecutable* thisObject = jsCast<FunctionExecutable*>(cell);
- ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
- COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
- ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
ScriptExecutable::visitChildren(thisObject, visitor);
if (thisObject->m_codeBlockForCall)
thisObject->m_codeBlockForCall->visitAggregate(visitor);
if (thisObject->m_codeBlockForConstruct)
thisObject->m_codeBlockForConstruct->visitAggregate(visitor);
visitor.append(&thisObject->m_unlinkedExecutable);
+ visitor.append(&thisObject->m_singletonFunction);
}
-void FunctionExecutable::clearCodeIfNotCompiling()
+SymbolTable* FunctionExecutable::symbolTable(CodeSpecializationKind kind)
{
- if (isCompiling())
- return;
- clearCode();
+ return codeBlockFor(kind)->symbolTable();
}
-void FunctionExecutable::clearUnlinkedCodeForRecompilationIfNotCompiling()
+void FunctionExecutable::clearUnlinkedCodeForRecompilation()
{
- if (isCompiling())
- return;
m_unlinkedExecutable->clearCodeForRecompilation();
}
void FunctionExecutable::clearCode()
{
- m_codeBlockForCall.clear();
- m_codeBlockForConstruct.clear();
+ m_codeBlockForCall = nullptr;
+ m_codeBlockForConstruct = nullptr;
Base::clearCode();
}
#endif
}
-FunctionExecutable* FunctionExecutable::fromGlobalCode(const Identifier& name, ExecState* exec, Debugger* debugger, const SourceCode& source, JSObject** exception)
+FunctionExecutable* FunctionExecutable::fromGlobalCode(
+ const Identifier& name, ExecState& exec, const SourceCode& source,
+ JSObject*& exception, int overrideLineNumber)
{
- UnlinkedFunctionExecutable* unlinkedFunction = UnlinkedFunctionExecutable::fromGlobalCode(name, exec, debugger, source, exception);
- if (!unlinkedFunction)
- return 0;
- unsigned firstLine = source.firstLine() + unlinkedFunction->firstLineOffset();
- unsigned startOffset = source.startOffset() + unlinkedFunction->startOffset();
- unsigned startColumn = source.startColumn();
- unsigned sourceLength = unlinkedFunction->sourceLength();
- SourceCode functionSource(source.provider(), startOffset, startOffset + sourceLength, firstLine, startColumn);
- return FunctionExecutable::create(exec->vm(), functionSource, unlinkedFunction, firstLine, unlinkedFunction->lineCount(), startColumn);
+ UnlinkedFunctionExecutable* unlinkedExecutable =
+ UnlinkedFunctionExecutable::fromGlobalCode(
+ name, exec, source, exception, overrideLineNumber);
+ if (!unlinkedExecutable)
+ return nullptr;
+
+ return unlinkedExecutable->link(exec.vm(), source, overrideLineNumber);
}
-String FunctionExecutable::paramString() const
+void ExecutableBase::dump(PrintStream& out) const
{
- return m_unlinkedExecutable->paramString();
+ ExecutableBase* realThis = const_cast<ExecutableBase*>(this);
+
+ if (classInfo() == NativeExecutable::info()) {
+ NativeExecutable* native = jsCast<NativeExecutable*>(realThis);
+ out.print("NativeExecutable:", RawPointer(bitwise_cast<void*>(native->function())), "/", RawPointer(bitwise_cast<void*>(native->constructor())));
+ return;
+ }
+
+ if (classInfo() == EvalExecutable::info()) {
+ EvalExecutable* eval = jsCast<EvalExecutable*>(realThis);
+ if (CodeBlock* codeBlock = eval->codeBlock())
+ out.print(*codeBlock);
+ else
+ out.print("EvalExecutable w/o CodeBlock");
+ return;
+ }
+
+ if (classInfo() == ProgramExecutable::info()) {
+ ProgramExecutable* eval = jsCast<ProgramExecutable*>(realThis);
+ if (CodeBlock* codeBlock = eval->codeBlock())
+ out.print(*codeBlock);
+ else
+ out.print("ProgramExecutable w/o CodeBlock");
+ return;
+ }
+
+ FunctionExecutable* function = jsCast<FunctionExecutable*>(realThis);
+ if (!function->eitherCodeBlock())
+ out.print("FunctionExecutable w/o CodeBlock");
+ else {
+ CommaPrinter comma("/");
+ if (function->codeBlockForCall())
+ out.print(comma, *function->codeBlockForCall());
+ if (function->codeBlockForConstruct())
+ out.print(comma, *function->codeBlockForConstruct());
+ }
}
CodeBlockHash ExecutableBase::hashFor(CodeSpecializationKind kind) const
{
- if (this->classInfo() == &NativeExecutable::s_info)
+ if (this->classInfo() == NativeExecutable::info())
return jsCast<const NativeExecutable*>(this)->hashFor(kind);
return jsCast<const ScriptExecutable*>(this)->hashFor(kind);