2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "Executable.h"
29 #include "BatchedTransitionOptimizer.h"
30 #include "BytecodeGenerator.h"
31 #include "CodeBlock.h"
32 #include "DFGDriver.h"
33 #include "ExecutionHarness.h"
35 #include "JITDriver.h"
36 #include "Operations.h"
38 #include <wtf/Vector.h>
39 #include <wtf/text/StringBuilder.h>
43 const ClassInfo ExecutableBase::s_info = { "Executable", 0, 0, 0, CREATE_METHOD_TABLE(ExecutableBase) };
46 void ExecutableBase::destroy(JSCell* cell)
48 static_cast<ExecutableBase*>(cell)->ExecutableBase::~ExecutableBase();
52 void ExecutableBase::clearCode()
55 m_jitCodeForCall.clear();
56 m_jitCodeForConstruct.clear();
57 m_jitCodeForCallWithArityCheck = MacroAssemblerCodePtr();
58 m_jitCodeForConstructWithArityCheck = MacroAssemblerCodePtr();
60 m_numParametersForCall = NUM_PARAMETERS_NOT_COMPILED;
61 m_numParametersForConstruct = NUM_PARAMETERS_NOT_COMPILED;
65 Intrinsic ExecutableBase::intrinsic() const
67 if (const NativeExecutable* nativeExecutable = jsDynamicCast<const NativeExecutable*>(this))
68 return nativeExecutable->intrinsic();
72 Intrinsic ExecutableBase::intrinsic() const
78 const ClassInfo NativeExecutable::s_info = { "NativeExecutable", &ExecutableBase::s_info, 0, 0, CREATE_METHOD_TABLE(NativeExecutable) };
81 void NativeExecutable::destroy(JSCell* cell)
83 static_cast<NativeExecutable*>(cell)->NativeExecutable::~NativeExecutable();
88 Intrinsic NativeExecutable::intrinsic() const
95 // Utility method used for jettisoning code blocks.
97 static void jettisonCodeBlock(VM& vm, RefPtr<T>& codeBlock)
99 ASSERT(JITCode::isOptimizingJIT(codeBlock->jitType()));
100 ASSERT(codeBlock->alternative());
101 RefPtr<T> codeBlockToJettison = codeBlock.release();
102 codeBlock = static_pointer_cast<T>(codeBlockToJettison->releaseAlternative());
103 codeBlockToJettison->unlinkIncomingCalls();
104 vm.heap.jettisonDFGCodeBlock(static_pointer_cast<CodeBlock>(codeBlockToJettison.release()));
108 const ClassInfo ScriptExecutable::s_info = { "ScriptExecutable", &ExecutableBase::s_info, 0, 0, CREATE_METHOD_TABLE(ScriptExecutable) };
111 void ScriptExecutable::destroy(JSCell* cell)
113 static_cast<ScriptExecutable*>(cell)->ScriptExecutable::~ScriptExecutable();
117 const ClassInfo EvalExecutable::s_info = { "EvalExecutable", &ScriptExecutable::s_info, 0, 0, CREATE_METHOD_TABLE(EvalExecutable) };
119 EvalExecutable* EvalExecutable::create(ExecState* exec, const SourceCode& source, bool isInStrictContext)
121 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
122 if (!globalObject->evalEnabled()) {
123 exec->vm().throwException(exec, createEvalError(exec, globalObject->evalDisabledErrorMessage()));
127 EvalExecutable* executable = new (NotNull, allocateCell<EvalExecutable>(*exec->heap())) EvalExecutable(exec, source, isInStrictContext);
128 executable->finishCreation(exec->vm());
130 UnlinkedEvalCodeBlock* unlinkedEvalCode = globalObject->createEvalCodeBlock(exec, executable);
131 if (!unlinkedEvalCode)
134 executable->m_unlinkedEvalCodeBlock.set(exec->vm(), executable, unlinkedEvalCode);
139 EvalExecutable::EvalExecutable(ExecState* exec, const SourceCode& source, bool inStrictContext)
140 : ScriptExecutable(exec->vm().evalExecutableStructure.get(), exec, source, inStrictContext)
144 void EvalExecutable::destroy(JSCell* cell)
146 static_cast<EvalExecutable*>(cell)->EvalExecutable::~EvalExecutable();
149 const ClassInfo ProgramExecutable::s_info = { "ProgramExecutable", &ScriptExecutable::s_info, 0, 0, CREATE_METHOD_TABLE(ProgramExecutable) };
151 ProgramExecutable::ProgramExecutable(ExecState* exec, const SourceCode& source)
152 : ScriptExecutable(exec->vm().programExecutableStructure.get(), exec, source, false)
156 void ProgramExecutable::destroy(JSCell* cell)
158 static_cast<ProgramExecutable*>(cell)->ProgramExecutable::~ProgramExecutable();
161 const ClassInfo FunctionExecutable::s_info = { "FunctionExecutable", &ScriptExecutable::s_info, 0, 0, CREATE_METHOD_TABLE(FunctionExecutable) };
163 FunctionExecutable::FunctionExecutable(VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable, unsigned firstLine, unsigned lastLine, unsigned startColumn)
164 : ScriptExecutable(vm.functionExecutableStructure.get(), vm, source, unlinkedExecutable->isInStrictContext())
165 , m_unlinkedExecutable(vm, this, unlinkedExecutable)
167 RELEASE_ASSERT(!source.isNull());
168 ASSERT(source.length());
169 m_firstLine = firstLine;
170 m_lastLine = lastLine;
171 m_startColumn = startColumn;
174 void FunctionExecutable::destroy(JSCell* cell)
176 static_cast<FunctionExecutable*>(cell)->FunctionExecutable::~FunctionExecutable();
180 JSObject* EvalExecutable::compileOptimized(ExecState* exec, JSScope* scope, CompilationResult& result, unsigned bytecodeIndex)
182 ASSERT(exec->vm().dynamicGlobalObject);
183 ASSERT(!!m_evalCodeBlock);
185 if (!JITCode::isOptimizingJIT(m_evalCodeBlock->jitType()))
186 error = compileInternal(exec, scope, JITCode::nextTierJIT(m_evalCodeBlock->jitType()), &result, bytecodeIndex);
188 result = CompilationNotNeeded;
189 ASSERT(!!m_evalCodeBlock);
192 #endif // ENABLE(DFG_JIT)
195 CompilationResult EvalExecutable::jitCompile(ExecState* exec)
197 return jitCompileIfAppropriate(exec, m_evalCodeBlock.get(), m_jitCodeForCall, JITCode::bottomTierJIT(), UINT_MAX, JITCompilationCanFail);
201 inline const char* samplingDescription(JITCode::JITType jitType)
204 case JITCode::InterpreterThunk:
205 return "Interpreter Compilation (TOTAL)";
206 case JITCode::BaselineJIT:
207 return "Baseline Compilation (TOTAL)";
208 case JITCode::DFGJIT:
209 return "DFG Compilation (TOTAL)";
210 case JITCode::FTLJIT:
211 return "FTL Compilation (TOTAL)";
213 RELEASE_ASSERT_NOT_REACHED();
218 JSObject* EvalExecutable::compileInternal(ExecState* exec, JSScope* scope, JITCode::JITType jitType, CompilationResult* result, unsigned bytecodeIndex)
220 SamplingRegion samplingRegion(samplingDescription(jitType));
223 *result = CompilationFailed;
225 RefPtr<EvalCodeBlock> newCodeBlock;
227 if (!!m_evalCodeBlock) {
228 newCodeBlock = adoptRef(new EvalCodeBlock(CodeBlock::CopyParsedBlock, *m_evalCodeBlock));
229 newCodeBlock->setAlternative(static_pointer_cast<CodeBlock>(m_evalCodeBlock));
231 newCodeBlock = adoptRef(new EvalCodeBlock(this, m_unlinkedEvalCodeBlock.get(), scope, source().provider()));
232 ASSERT((jitType == JITCode::bottomTierJIT()) == !m_evalCodeBlock);
235 CompilationResult theResult = prepareForExecution(
236 exec, m_evalCodeBlock, newCodeBlock.get(), m_jitCodeForCall, jitType, bytecodeIndex);
244 CompilationResult EvalExecutable::replaceWithDeferredOptimizedCode(PassRefPtr<DFG::Plan> plan)
246 return JSC::replaceWithDeferredOptimizedCode(
247 plan, m_evalCodeBlock, m_jitCodeForCall, 0, 0);
249 #endif // ENABLE(DFG_JIT)
252 void EvalExecutable::jettisonOptimizedCode(VM& vm)
254 jettisonCodeBlock(vm, m_evalCodeBlock);
255 m_jitCodeForCall = m_evalCodeBlock->jitCode();
256 ASSERT(!m_jitCodeForCallWithArityCheck);
258 #endif // ENABLE(JIT)
260 void EvalExecutable::visitChildren(JSCell* cell, SlotVisitor& visitor)
262 EvalExecutable* thisObject = jsCast<EvalExecutable*>(cell);
263 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
264 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
265 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
266 ScriptExecutable::visitChildren(thisObject, visitor);
267 if (thisObject->m_evalCodeBlock)
268 thisObject->m_evalCodeBlock->visitAggregate(visitor);
269 visitor.append(&thisObject->m_unlinkedEvalCodeBlock);
272 void EvalExecutable::unlinkCalls()
275 if (!m_jitCodeForCall)
277 RELEASE_ASSERT(m_evalCodeBlock);
278 m_evalCodeBlock->unlinkCalls();
282 void EvalExecutable::clearCode()
284 m_evalCodeBlock.clear();
285 m_unlinkedEvalCodeBlock.clear();
289 JSObject* ProgramExecutable::checkSyntax(ExecState* exec)
292 VM* vm = &exec->vm();
293 JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
294 RefPtr<ProgramNode> programNode = parse<ProgramNode>(vm, m_source, 0, Identifier(), JSParseNormal, ProgramNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, error);
297 ASSERT(error.m_type != ParserError::ErrorNone);
298 return error.toErrorObject(lexicalGlobalObject, m_source);
302 JSObject* ProgramExecutable::compileOptimized(ExecState* exec, JSScope* scope, CompilationResult& result, unsigned bytecodeIndex)
304 RELEASE_ASSERT(exec->vm().dynamicGlobalObject);
305 ASSERT(!!m_programCodeBlock);
307 if (!JITCode::isOptimizingJIT(m_programCodeBlock->jitType()))
308 error = compileInternal(exec, scope, JITCode::nextTierJIT(m_programCodeBlock->jitType()), &result, bytecodeIndex);
310 result = CompilationNotNeeded;
311 ASSERT(!!m_programCodeBlock);
314 #endif // ENABLE(DFG_JIT)
317 CompilationResult ProgramExecutable::jitCompile(ExecState* exec)
319 return jitCompileIfAppropriate(exec, m_programCodeBlock.get(), m_jitCodeForCall, JITCode::bottomTierJIT(), UINT_MAX, JITCompilationCanFail);
323 JSObject* ProgramExecutable::compileInternal(ExecState* exec, JSScope* scope, JITCode::JITType jitType, CompilationResult* result, unsigned bytecodeIndex)
325 SamplingRegion samplingRegion(samplingDescription(jitType));
328 *result = CompilationFailed;
330 RefPtr<ProgramCodeBlock> newCodeBlock;
332 if (!!m_programCodeBlock) {
333 newCodeBlock = adoptRef(new ProgramCodeBlock(CodeBlock::CopyParsedBlock, *m_programCodeBlock));
334 newCodeBlock->setAlternative(static_pointer_cast<CodeBlock>(m_programCodeBlock));
336 newCodeBlock = adoptRef(new ProgramCodeBlock(this, m_unlinkedProgramCodeBlock.get(), scope, source().provider(), source().startColumn()));
339 CompilationResult theResult = prepareForExecution(
340 exec, m_programCodeBlock, newCodeBlock.get(), m_jitCodeForCall, jitType, bytecodeIndex);
348 CompilationResult ProgramExecutable::replaceWithDeferredOptimizedCode(PassRefPtr<DFG::Plan> plan)
350 return JSC::replaceWithDeferredOptimizedCode(
351 plan, m_programCodeBlock, m_jitCodeForCall, 0, 0);
353 #endif // ENABLE(DFG_JIT)
356 void ProgramExecutable::jettisonOptimizedCode(VM& vm)
358 jettisonCodeBlock(vm, m_programCodeBlock);
359 m_jitCodeForCall = m_programCodeBlock->jitCode();
360 ASSERT(!m_jitCodeForCallWithArityCheck);
364 void ProgramExecutable::unlinkCalls()
367 if (!m_jitCodeForCall)
369 RELEASE_ASSERT(m_programCodeBlock);
370 m_programCodeBlock->unlinkCalls();
374 JSObject* ProgramExecutable::initializeGlobalProperties(VM& vm, CallFrame* callFrame, JSScope* scope)
376 RELEASE_ASSERT(scope);
377 JSGlobalObject* globalObject = scope->globalObject();
378 RELEASE_ASSERT(globalObject);
379 ASSERT(&globalObject->vm() == &vm);
381 JSObject* exception = 0;
382 UnlinkedProgramCodeBlock* unlinkedCode = globalObject->createProgramCodeBlock(callFrame, this, &exception);
386 m_unlinkedProgramCodeBlock.set(vm, this, unlinkedCode);
388 BatchedTransitionOptimizer optimizer(vm, globalObject);
390 const UnlinkedProgramCodeBlock::VariableDeclations& variableDeclarations = unlinkedCode->variableDeclarations();
391 const UnlinkedProgramCodeBlock::FunctionDeclations& functionDeclarations = unlinkedCode->functionDeclarations();
393 CallFrame* globalExec = globalObject->globalExec();
395 for (size_t i = 0; i < functionDeclarations.size(); ++i) {
396 UnlinkedFunctionExecutable* unlinkedFunctionExecutable = functionDeclarations[i].second.get();
397 JSValue value = JSFunction::create(globalExec, unlinkedFunctionExecutable->link(vm, m_source, lineNo(), 0), scope);
398 globalObject->addFunction(callFrame, functionDeclarations[i].first, value);
401 for (size_t i = 0; i < variableDeclarations.size(); ++i) {
402 if (variableDeclarations[i].second & DeclarationStacks::IsConstant)
403 globalObject->addConst(callFrame, variableDeclarations[i].first);
405 globalObject->addVar(callFrame, variableDeclarations[i].first);
410 void ProgramExecutable::visitChildren(JSCell* cell, SlotVisitor& visitor)
412 ProgramExecutable* thisObject = jsCast<ProgramExecutable*>(cell);
413 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
414 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
415 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
416 ScriptExecutable::visitChildren(thisObject, visitor);
417 visitor.append(&thisObject->m_unlinkedProgramCodeBlock);
418 if (thisObject->m_programCodeBlock)
419 thisObject->m_programCodeBlock->visitAggregate(visitor);
422 void ProgramExecutable::clearCode()
424 m_programCodeBlock.clear();
425 m_unlinkedProgramCodeBlock.clear();
429 FunctionCodeBlock* FunctionExecutable::baselineCodeBlockFor(CodeSpecializationKind kind)
431 FunctionCodeBlock* result;
432 if (kind == CodeForCall)
433 result = m_codeBlockForCall.get();
435 RELEASE_ASSERT(kind == CodeForConstruct);
436 result = m_codeBlockForConstruct.get();
440 while (result->alternative())
441 result = static_cast<FunctionCodeBlock*>(result->alternative());
442 RELEASE_ASSERT(result);
443 ASSERT(JITCode::isBaselineCode(result->jitType()));
448 JSObject* FunctionExecutable::compileOptimizedForCall(ExecState* exec, JSScope* scope, CompilationResult& result, unsigned bytecodeIndex)
450 RELEASE_ASSERT(exec->vm().dynamicGlobalObject);
451 ASSERT(!!m_codeBlockForCall);
453 if (!JITCode::isOptimizingJIT(m_codeBlockForCall->jitType()))
454 error = compileForCallInternal(exec, scope, JITCode::nextTierJIT(m_codeBlockForCall->jitType()), &result, bytecodeIndex);
456 result = CompilationNotNeeded;
457 ASSERT(!!m_codeBlockForCall);
461 JSObject* FunctionExecutable::compileOptimizedForConstruct(ExecState* exec, JSScope* scope, CompilationResult& result, unsigned bytecodeIndex)
463 RELEASE_ASSERT(exec->vm().dynamicGlobalObject);
464 ASSERT(!!m_codeBlockForConstruct);
466 if (!JITCode::isOptimizingJIT(m_codeBlockForConstruct->jitType()))
467 error = compileForConstructInternal(exec, scope, JITCode::nextTierJIT(m_codeBlockForConstruct->jitType()), &result, bytecodeIndex);
469 result = CompilationNotNeeded;
470 ASSERT(!!m_codeBlockForConstruct);
473 #endif // ENABLE(DFG_JIT)
476 CompilationResult FunctionExecutable::jitCompileForCall(ExecState* exec)
478 return jitCompileFunctionIfAppropriate(exec, m_codeBlockForCall.get(), m_jitCodeForCall, m_jitCodeForCallWithArityCheck, JITCode::bottomTierJIT(), UINT_MAX, JITCompilationCanFail);
481 CompilationResult FunctionExecutable::jitCompileForConstruct(ExecState* exec)
483 return jitCompileFunctionIfAppropriate(exec, m_codeBlockForConstruct.get(), m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck, JITCode::bottomTierJIT(), UINT_MAX, JITCompilationCanFail);
487 PassRefPtr<FunctionCodeBlock> FunctionExecutable::produceCodeBlockFor(JSScope* scope, CodeSpecializationKind specializationKind, JSObject*& exception)
489 RefPtr<FunctionCodeBlock> alternative = codeBlockFor(specializationKind);
492 RefPtr<FunctionCodeBlock> result = adoptRef(new FunctionCodeBlock(CodeBlock::CopyParsedBlock, *codeBlockFor(specializationKind)));
493 result->setAlternative(alternative);
494 return result.release();
497 VM* vm = scope->vm();
498 JSGlobalObject* globalObject = scope->globalObject();
500 DebuggerMode debuggerMode = globalObject->hasDebugger() ? DebuggerOn : DebuggerOff;
501 ProfilerMode profilerMode = globalObject->hasProfiler() ? ProfilerOn : ProfilerOff;
502 UnlinkedFunctionCodeBlock* unlinkedCodeBlock = m_unlinkedExecutable->codeBlockFor(*vm, m_source, specializationKind, debuggerMode, profilerMode, error);
503 recordParse(m_unlinkedExecutable->features(), m_unlinkedExecutable->hasCapturedVariables(), lineNo(), lastLine(), startColumn());
505 if (!unlinkedCodeBlock) {
506 exception = vm->throwException(globalObject->globalExec(), error.toErrorObject(globalObject, m_source));
510 SourceProvider* provider = source().provider();
511 unsigned sourceOffset = source().startOffset();
512 unsigned startColumn = source().startColumn();
514 return adoptRef(new FunctionCodeBlock(this, unlinkedCodeBlock, scope, provider, sourceOffset, startColumn));
518 JSObject* FunctionExecutable::compileForCallInternal(ExecState* exec, JSScope* scope, JITCode::JITType jitType, CompilationResult* result, unsigned bytecodeIndex)
520 SamplingRegion samplingRegion(samplingDescription(jitType));
523 *result = CompilationFailed;
525 ASSERT((jitType == JITCode::bottomTierJIT()) == !m_codeBlockForCall);
526 JSObject* exception = 0;
528 RefPtr<FunctionCodeBlock> newCodeBlock = produceCodeBlockFor(scope, CodeForCall, exception);
532 CompilationResult theResult = prepareFunctionForExecution(
533 exec, m_codeBlockForCall, newCodeBlock.get(), m_jitCodeForCall,
534 m_jitCodeForCallWithArityCheck, m_numParametersForCall, jitType,
535 bytecodeIndex, CodeForCall);
542 CompilationResult FunctionExecutable::replaceWithDeferredOptimizedCodeForCall(PassRefPtr<DFG::Plan> plan)
544 return JSC::replaceWithDeferredOptimizedCode(
545 plan, m_codeBlockForCall, m_jitCodeForCall, &m_jitCodeForCallWithArityCheck,
546 &m_numParametersForCall);
548 #endif // ENABLE(DFG_JIT)
550 JSObject* FunctionExecutable::compileForConstructInternal(ExecState* exec, JSScope* scope, JITCode::JITType jitType, CompilationResult* result, unsigned bytecodeIndex)
552 SamplingRegion samplingRegion(samplingDescription(jitType));
555 *result = CompilationFailed;
557 ASSERT((jitType == JITCode::bottomTierJIT()) == !m_codeBlockForConstruct);
558 JSObject* exception = 0;
559 RefPtr<FunctionCodeBlock> newCodeBlock = produceCodeBlockFor(scope, CodeForConstruct, exception);
563 CompilationResult theResult = prepareFunctionForExecution(
564 exec, m_codeBlockForConstruct, newCodeBlock.get(), m_jitCodeForConstruct,
565 m_jitCodeForConstructWithArityCheck, m_numParametersForConstruct, jitType,
566 bytecodeIndex, CodeForConstruct);
574 CompilationResult FunctionExecutable::replaceWithDeferredOptimizedCodeForConstruct(PassRefPtr<DFG::Plan> plan)
576 return JSC::replaceWithDeferredOptimizedCode(
577 plan, m_codeBlockForConstruct, m_jitCodeForConstruct,
578 &m_jitCodeForConstructWithArityCheck, &m_numParametersForConstruct);
580 #endif // ENABLE(DFG_JIT)
583 void FunctionExecutable::jettisonOptimizedCodeForCall(VM& vm)
585 jettisonCodeBlock(vm, m_codeBlockForCall);
586 m_jitCodeForCall = m_codeBlockForCall->jitCode();
587 m_jitCodeForCallWithArityCheck = m_codeBlockForCall->jitCodeWithArityCheck();
590 void FunctionExecutable::jettisonOptimizedCodeForConstruct(VM& vm)
592 jettisonCodeBlock(vm, m_codeBlockForConstruct);
593 m_jitCodeForConstruct = m_codeBlockForConstruct->jitCode();
594 m_jitCodeForConstructWithArityCheck = m_codeBlockForConstruct->jitCodeWithArityCheck();
598 void FunctionExecutable::visitChildren(JSCell* cell, SlotVisitor& visitor)
600 FunctionExecutable* thisObject = jsCast<FunctionExecutable*>(cell);
601 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
602 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
603 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
604 ScriptExecutable::visitChildren(thisObject, visitor);
605 if (thisObject->m_codeBlockForCall)
606 thisObject->m_codeBlockForCall->visitAggregate(visitor);
607 if (thisObject->m_codeBlockForConstruct)
608 thisObject->m_codeBlockForConstruct->visitAggregate(visitor);
609 visitor.append(&thisObject->m_unlinkedExecutable);
612 void FunctionExecutable::clearCodeIfNotCompiling()
619 void FunctionExecutable::clearUnlinkedCodeForRecompilationIfNotCompiling()
623 m_unlinkedExecutable->clearCodeForRecompilation();
626 void FunctionExecutable::clearCode()
628 m_codeBlockForCall.clear();
629 m_codeBlockForConstruct.clear();
633 void FunctionExecutable::unlinkCalls()
636 if (!!m_jitCodeForCall) {
637 RELEASE_ASSERT(m_codeBlockForCall);
638 m_codeBlockForCall->unlinkCalls();
640 if (!!m_jitCodeForConstruct) {
641 RELEASE_ASSERT(m_codeBlockForConstruct);
642 m_codeBlockForConstruct->unlinkCalls();
647 FunctionExecutable* FunctionExecutable::fromGlobalCode(const Identifier& name, ExecState* exec, Debugger* debugger, const SourceCode& source, JSObject** exception)
649 UnlinkedFunctionExecutable* unlinkedFunction = UnlinkedFunctionExecutable::fromGlobalCode(name, exec, debugger, source, exception);
650 if (!unlinkedFunction)
652 unsigned firstLine = source.firstLine() + unlinkedFunction->firstLineOffset();
653 unsigned startOffset = source.startOffset() + unlinkedFunction->startOffset();
654 unsigned startColumn = source.startColumn();
655 unsigned sourceLength = unlinkedFunction->sourceLength();
656 SourceCode functionSource(source.provider(), startOffset, startOffset + sourceLength, firstLine, startColumn);
657 return FunctionExecutable::create(exec->vm(), functionSource, unlinkedFunction, firstLine, unlinkedFunction->lineCount(), startColumn);
660 String FunctionExecutable::paramString() const
662 return m_unlinkedExecutable->paramString();
665 CodeBlockHash ExecutableBase::hashFor(CodeSpecializationKind kind) const
667 if (this->classInfo() == NativeExecutable::info())
668 return jsCast<const NativeExecutable*>(this)->hashFor(kind);
670 return jsCast<const ScriptExecutable*>(this)->hashFor(kind);
673 CodeBlockHash NativeExecutable::hashFor(CodeSpecializationKind kind) const
675 if (kind == CodeForCall)
676 return CodeBlockHash(static_cast<unsigned>(bitwise_cast<size_t>(m_function)));
678 RELEASE_ASSERT(kind == CodeForConstruct);
679 return CodeBlockHash(static_cast<unsigned>(bitwise_cast<size_t>(m_constructor)));
682 CodeBlockHash ScriptExecutable::hashFor(CodeSpecializationKind kind) const
684 return CodeBlockHash(source(), kind);