2 * Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "ArrayProfile.h"
34 #include "ByValInfo.h"
35 #include "BytecodeConventions.h"
36 #include "CallLinkInfo.h"
37 #include "CallReturnOffsetToBytecodeOffset.h"
38 #include "CodeBlockHash.h"
39 #include "ConcurrentJITLock.h"
40 #include "CodeOrigin.h"
42 #include "CompactJITCodeMap.h"
43 #include "DFGCodeBlocks.h"
44 #include "DFGCommon.h"
45 #include "DFGCommonData.h"
46 #include "DFGExitProfile.h"
47 #include "DFGMinifiedGraph.h"
48 #include "DFGOSREntry.h"
49 #include "DFGOSRExit.h"
50 #include "DFGVariableEventStream.h"
51 #include "DeferredCompilationCallback.h"
52 #include "EvalCodeCache.h"
53 #include "ExecutionCounter.h"
54 #include "ExpressionRangeInfo.h"
55 #include "HandlerInfo.h"
56 #include "ObjectAllocationProfile.h"
58 #include "Operations.h"
59 #include "PutPropertySlot.h"
60 #include "Instruction.h"
62 #include "JITWriteBarrier.h"
63 #include "JSGlobalObject.h"
64 #include "JumpReplacementWatchpoint.h"
65 #include "JumpTable.h"
66 #include "LLIntCallLinkInfo.h"
67 #include "LazyOperandValueProfile.h"
69 #include "ProfilerCompilation.h"
70 #include "RegExpObject.h"
71 #include "StructureStubInfo.h"
72 #include "UnconditionalFinalizer.h"
73 #include "ValueProfile.h"
74 #include "Watchpoint.h"
75 #include <wtf/RefCountedArray.h>
76 #include <wtf/FastAllocBase.h>
77 #include <wtf/PassOwnPtr.h>
78 #include <wtf/Platform.h>
79 #include <wtf/RefPtr.h>
80 #include <wtf/SegmentedVector.h>
81 #include <wtf/Vector.h>
82 #include <wtf/text/WTFString.h>
88 class LLIntOffsetsExtractor;
91 inline int unmodifiedArgumentsRegister(int argumentsRegister) { return argumentsRegister - 1; }
93 static ALWAYS_INLINE int missingThisObjectMarker() { return std::numeric_limits<int>::max(); }
95 class CodeBlock : public ThreadSafeRefCounted<CodeBlock>, public UnconditionalFinalizer, public WeakReferenceHarvester {
96 WTF_MAKE_FAST_ALLOCATED;
98 friend class LLIntOffsetsExtractor;
100 enum CopyParsedBlockTag { CopyParsedBlock };
102 CodeBlock(CopyParsedBlockTag, CodeBlock& other);
104 CodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock*, JSScope*, PassRefPtr<SourceProvider>, unsigned sourceOffset, unsigned firstLineColumnOffset);
106 WriteBarrier<JSGlobalObject> m_globalObject;
110 JS_EXPORT_PRIVATE virtual ~CodeBlock();
112 UnlinkedCodeBlock* unlinkedCodeBlock() const { return m_unlinkedCode.get(); }
114 CString inferredName() const;
115 CodeBlockHash hash() const;
116 bool hasHash() const;
117 bool isSafeToComputeHash() const;
118 CString sourceCodeForTools() const; // Not quite the actual source we parsed; this will do things like prefix the source for a function with a reified signature.
119 CString sourceCodeOnOneLine() const; // As sourceCodeForTools(), but replaces all whitespace runs with a single space.
120 void dumpAssumingJITType(PrintStream&, JITCode::JITType) const;
121 void dump(PrintStream&) const;
123 int numParameters() const { return m_numParameters; }
124 void setNumParameters(int newValue);
126 int* addressOfNumParameters() { return &m_numParameters; }
127 static ptrdiff_t offsetOfNumParameters() { return OBJECT_OFFSETOF(CodeBlock, m_numParameters); }
129 CodeBlock* alternative() { return m_alternative.get(); }
130 PassRefPtr<CodeBlock> releaseAlternative() { return m_alternative.release(); }
131 void setAlternative(PassRefPtr<CodeBlock> alternative) { m_alternative = alternative; }
133 CodeSpecializationKind specializationKind() const
135 return specializationFromIsConstruct(m_isConstructor);
138 CodeBlock* baselineVersion();
140 void visitAggregate(SlotVisitor&);
142 static void dumpStatistics();
144 void dumpBytecode(PrintStream& = WTF::dataFile());
145 void dumpBytecode(PrintStream&, unsigned bytecodeOffset);
146 void printStructures(PrintStream&, const Instruction*);
147 void printStructure(PrintStream&, const char* name, const Instruction*, int operand);
149 bool isStrictMode() const { return m_isStrictMode; }
151 inline bool isKnownNotImmediate(int index)
153 if (index == m_thisRegister && !m_isStrictMode)
156 if (isConstantRegisterIndex(index))
157 return getConstant(index).isCell();
162 ALWAYS_INLINE bool isTemporaryRegisterIndex(int index)
164 return index >= m_numVars;
167 HandlerInfo* handlerForBytecodeOffset(unsigned bytecodeOffset);
168 unsigned lineNumberForBytecodeOffset(unsigned bytecodeOffset);
169 unsigned columnNumberForBytecodeOffset(unsigned bytecodeOffset);
170 void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot,
171 int& startOffset, int& endOffset, unsigned& line, unsigned& column);
175 StructureStubInfo& getStubInfo(ReturnAddressPtr returnAddress)
177 return *(binarySearch<StructureStubInfo, void*>(m_structureStubInfos, m_structureStubInfos.size(), returnAddress.value(), getStructureStubInfoReturnLocation));
180 StructureStubInfo& getStubInfo(unsigned bytecodeIndex)
182 return *(binarySearch<StructureStubInfo, unsigned>(m_structureStubInfos, m_structureStubInfos.size(), bytecodeIndex, getStructureStubInfoBytecodeIndex));
185 void resetStub(StructureStubInfo&);
187 ByValInfo& getByValInfo(unsigned bytecodeIndex)
189 return *(binarySearch<ByValInfo, unsigned>(m_byValInfos, m_byValInfos.size(), bytecodeIndex, getByValInfoBytecodeIndex));
192 CallLinkInfo& getCallLinkInfo(ReturnAddressPtr returnAddress)
194 return *(binarySearch<CallLinkInfo, void*>(m_callLinkInfos, m_callLinkInfos.size(), returnAddress.value(), getCallLinkInfoReturnLocation));
197 CallLinkInfo& getCallLinkInfo(unsigned bytecodeIndex)
199 ASSERT(JITCode::isBaselineCode(jitType()));
200 return *(binarySearch<CallLinkInfo, unsigned>(m_callLinkInfos, m_callLinkInfos.size(), bytecodeIndex, getCallLinkInfoBytecodeIndex));
202 #endif // ENABLE(JIT)
204 unsigned bytecodeOffset(ExecState*, ReturnAddressPtr);
206 void unlinkIncomingCalls();
209 unsigned bytecodeOffsetForCallAtIndex(unsigned index)
213 Vector<CallReturnOffsetToBytecodeOffset, 0, UnsafeVectorOverflow>& callIndices = m_rareData->m_callReturnIndexVector;
214 if (!callIndices.size())
216 // FIXME: Fix places in DFG that call out to C that don't set the CodeOrigin. https://bugs.webkit.org/show_bug.cgi?id=118315
217 ASSERT(index < m_rareData->m_callReturnIndexVector.size());
218 if (index >= m_rareData->m_callReturnIndexVector.size())
220 return m_rareData->m_callReturnIndexVector[index].bytecodeOffset;
225 void linkIncomingCall(ExecState* callerFrame, CallLinkInfo*);
227 bool isIncomingCallAlreadyLinked(CallLinkInfo* incoming)
229 return m_incomingCalls.isOnList(incoming);
231 #endif // ENABLE(JIT)
234 void linkIncomingCall(ExecState* callerFrame, LLIntCallLinkInfo*);
235 #endif // ENABLE(LLINT)
237 #if ENABLE(DFG_JIT) || ENABLE(LLINT)
238 void setJITCodeMap(PassOwnPtr<CompactJITCodeMap> jitCodeMap)
240 m_jitCodeMap = jitCodeMap;
242 CompactJITCodeMap* jitCodeMap()
244 return m_jitCodeMap.get();
248 unsigned bytecodeOffset(Instruction* returnAddress)
250 RELEASE_ASSERT(returnAddress >= instructions().begin() && returnAddress < instructions().end());
251 return static_cast<Instruction*>(returnAddress) - instructions().begin();
254 bool isNumericCompareFunction() { return m_unlinkedCode->isNumericCompareFunction(); }
256 unsigned numberOfInstructions() const { return m_instructions.size(); }
257 RefCountedArray<Instruction>& instructions() { return m_instructions; }
258 const RefCountedArray<Instruction>& instructions() const { return m_instructions; }
260 size_t predictedMachineCodeSize();
262 bool usesOpcode(OpcodeID);
264 unsigned instructionCount() { return m_instructions.size(); }
266 int argumentIndexAfterCapture(size_t argument);
268 // Prepares this code block for execution. This is synchronous. This compile
269 // may fail, if you passed JITCompilationCanFail.
270 CompilationResult prepareForExecution(
271 ExecState*, JITCode::JITType,
272 JITCompilationEffort = JITCompilationMustSucceed,
273 unsigned bytecodeIndex = UINT_MAX);
275 // Use this method for asynchronous compiles. This will do a compile at some
276 // point in time between when you called into this method and some point in the
277 // future. If you're lucky then it might complete before this method returns.
278 // Once it completes, the callback is called with the result. If the compile
279 // did happen to complete before the method returns, the result of the compile
280 // may be returned. If the compile didn't happen to complete yet, or if we
281 // didn't happen to notice that the compile already completed, we return
282 // CompilationDeferred.
284 // Note that asynchronous compiles don't actually complete unless you call into
285 // DFG::Worklist::completeAllReadyPlansForVM(). You usually force a call to
286 // this on the main thread by listening to the callback's
287 // compilationDidBecomeReadyAsynchronously() notification. Note that this call
288 // happens on another thread.
289 CompilationResult prepareForExecutionAsynchronously(
290 ExecState*, JITCode::JITType, PassRefPtr<DeferredCompilationCallback>,
291 JITCompilationEffort = JITCompilationMustSucceed,
292 unsigned bytecodeIndex = UINT_MAX);
294 // Exactly equivalent to codeBlock->ownerExecutable()->installCode(codeBlock);
297 // Exactly equivalent to codeBlock->ownerExecutable()->newReplacementCodeBlockFor(codeBlock->specializationKind())
298 PassRefPtr<CodeBlock> newReplacement();
300 void setJITCode(PassRefPtr<JITCode> code, MacroAssemblerCodePtr codeWithArityCheck)
302 ConcurrentJITLocker locker(m_lock);
303 WTF::storeStoreFence(); // This is probably not needed because the lock will also do something similar, but it's good to be paranoid.
305 m_jitCodeWithArityCheck = codeWithArityCheck;
307 if (JITCode::isOptimizingJIT(JITCode::jitTypeFor(m_jitCode)))
308 m_vm->heap.m_dfgCodeBlocks.m_set.add(this);
311 PassRefPtr<JITCode> jitCode() { return m_jitCode; }
312 MacroAssemblerCodePtr jitCodeWithArityCheck() { return m_jitCodeWithArityCheck; }
313 JITCode::JITType jitType() const
315 JITCode* jitCode = m_jitCode.get();
316 WTF::loadLoadFence();
317 JITCode::JITType result = JITCode::jitTypeFor(jitCode);
318 WTF::loadLoadFence(); // This probably isn't needed. Oh well, paranoia is good.
323 bool hasBaselineJITProfiling() const
325 return jitType() == JITCode::BaselineJIT;
329 virtual CodeBlock* replacement() = 0;
331 virtual DFG::CapabilityLevel capabilityLevelInternal() = 0;
332 DFG::CapabilityLevel capabilityLevel()
334 DFG::CapabilityLevel result = capabilityLevelInternal();
335 m_capabilityLevelState = result;
338 DFG::CapabilityLevel capabilityLevelState() { return m_capabilityLevelState; }
340 bool hasOptimizedReplacement();
343 ScriptExecutable* ownerExecutable() const { return m_ownerExecutable.get(); }
345 void setVM(VM* vm) { m_vm = vm; }
346 VM* vm() { return m_vm; }
348 void setThisRegister(int thisRegister) { m_thisRegister = thisRegister; }
349 int thisRegister() const { return m_thisRegister; }
351 bool needsFullScopeChain() const { return m_unlinkedCode->needsFullScopeChain(); }
352 bool usesEval() const { return m_unlinkedCode->usesEval(); }
354 void setArgumentsRegister(int argumentsRegister)
356 ASSERT(argumentsRegister != -1);
357 m_argumentsRegister = argumentsRegister;
358 ASSERT(usesArguments());
360 int argumentsRegister() const
362 ASSERT(usesArguments());
363 return m_argumentsRegister;
365 int uncheckedArgumentsRegister()
367 if (!usesArguments())
368 return InvalidVirtualRegister;
369 return argumentsRegister();
371 void setActivationRegister(int activationRegister)
373 m_activationRegister = activationRegister;
375 int activationRegister() const
377 ASSERT(needsFullScopeChain());
378 return m_activationRegister;
380 int uncheckedActivationRegister()
382 if (!needsFullScopeChain())
383 return InvalidVirtualRegister;
384 return activationRegister();
386 bool usesArguments() const { return m_argumentsRegister != -1; }
388 bool needsActivation() const
390 return m_needsActivation;
393 bool isCaptured(int operand, InlineCallFrame* inlineCallFrame = 0) const
395 if (operandIsArgument(operand))
396 return operandToArgument(operand) && usesArguments();
399 return inlineCallFrame->capturedVars.get(operand);
401 // The activation object isn't in the captured region, but it's "captured"
402 // in the sense that stores to its location can be observed indirectly.
403 if (needsActivation() && operand == activationRegister())
406 // Ditto for the arguments object.
407 if (usesArguments() && operand == argumentsRegister())
410 // Ditto for the arguments object.
411 if (usesArguments() && operand == unmodifiedArgumentsRegister(argumentsRegister()))
414 // We're in global code so there are no locals to capture
418 return operand >= symbolTable()->captureStart()
419 && operand < symbolTable()->captureEnd();
422 CodeType codeType() const { return m_unlinkedCode->codeType(); }
423 PutPropertySlot::Context putByIdContext() const
425 if (codeType() == EvalCode)
426 return PutPropertySlot::PutByIdEval;
427 return PutPropertySlot::PutById;
430 SourceProvider* source() const { return m_source.get(); }
431 unsigned sourceOffset() const { return m_sourceOffset; }
432 unsigned firstLineColumnOffset() const { return m_firstLineColumnOffset; }
434 size_t numberOfJumpTargets() const { return m_unlinkedCode->numberOfJumpTargets(); }
435 unsigned jumpTarget(int index) const { return m_unlinkedCode->jumpTarget(index); }
437 void createActivation(CallFrame*);
439 void clearEvalCache();
441 String nameForRegister(int registerNumber);
444 void setNumberOfStructureStubInfos(size_t size) { m_structureStubInfos.grow(size); }
445 void sortStructureStubInfos();
446 size_t numberOfStructureStubInfos() const { return m_structureStubInfos.size(); }
447 StructureStubInfo& structureStubInfo(int index) { return m_structureStubInfos[index]; }
449 void setNumberOfByValInfos(size_t size) { m_byValInfos.grow(size); }
450 size_t numberOfByValInfos() const { return m_byValInfos.size(); }
451 ByValInfo& byValInfo(size_t index) { return m_byValInfos[index]; }
453 void setNumberOfCallLinkInfos(size_t size) { m_callLinkInfos.grow(size); }
454 size_t numberOfCallLinkInfos() const { return m_callLinkInfos.size(); }
455 CallLinkInfo& callLinkInfo(int index) { return m_callLinkInfos[index]; }
458 #if ENABLE(VALUE_PROFILER)
459 unsigned numberOfArgumentValueProfiles()
461 ASSERT(m_numParameters >= 0);
462 ASSERT(m_argumentValueProfiles.size() == static_cast<unsigned>(m_numParameters));
463 return m_argumentValueProfiles.size();
465 ValueProfile* valueProfileForArgument(unsigned argumentIndex)
467 ValueProfile* result = &m_argumentValueProfiles[argumentIndex];
468 ASSERT(result->m_bytecodeOffset == -1);
472 unsigned numberOfValueProfiles() { return m_valueProfiles.size(); }
473 ValueProfile* valueProfile(int index) { return &m_valueProfiles[index]; }
474 ValueProfile* valueProfileForBytecodeOffset(int bytecodeOffset)
476 ValueProfile* result = binarySearch<ValueProfile, int>(
477 m_valueProfiles, m_valueProfiles.size(), bytecodeOffset,
478 getValueProfileBytecodeOffset<ValueProfile>);
479 ASSERT(result->m_bytecodeOffset != -1);
480 ASSERT(instructions()[bytecodeOffset + opcodeLength(
481 m_vm->interpreter->getOpcodeID(
483 bytecodeOffset].u.opcode)) - 1].u.profile == result);
486 SpeculatedType valueProfilePredictionForBytecodeOffset(const ConcurrentJITLocker& locker, int bytecodeOffset)
488 return valueProfileForBytecodeOffset(bytecodeOffset)->computeUpdatedPrediction(locker);
491 unsigned totalNumberOfValueProfiles()
493 return numberOfArgumentValueProfiles() + numberOfValueProfiles();
495 ValueProfile* getFromAllValueProfiles(unsigned index)
497 if (index < numberOfArgumentValueProfiles())
498 return valueProfileForArgument(index);
499 return valueProfile(index - numberOfArgumentValueProfiles());
502 RareCaseProfile* addRareCaseProfile(int bytecodeOffset)
504 m_rareCaseProfiles.append(RareCaseProfile(bytecodeOffset));
505 return &m_rareCaseProfiles.last();
507 unsigned numberOfRareCaseProfiles() { return m_rareCaseProfiles.size(); }
508 RareCaseProfile* rareCaseProfile(int index) { return &m_rareCaseProfiles[index]; }
509 RareCaseProfile* rareCaseProfileForBytecodeOffset(int bytecodeOffset)
511 return tryBinarySearch<RareCaseProfile, int>(
512 m_rareCaseProfiles, m_rareCaseProfiles.size(), bytecodeOffset,
513 getRareCaseProfileBytecodeOffset);
516 bool likelyToTakeSlowCase(int bytecodeOffset)
518 if (!hasBaselineJITProfiling())
520 unsigned value = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
521 return value >= Options::likelyToTakeSlowCaseMinimumCount();
524 bool couldTakeSlowCase(int bytecodeOffset)
526 if (!hasBaselineJITProfiling())
528 unsigned value = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
529 return value >= Options::couldTakeSlowCaseMinimumCount();
532 RareCaseProfile* addSpecialFastCaseProfile(int bytecodeOffset)
534 m_specialFastCaseProfiles.append(RareCaseProfile(bytecodeOffset));
535 return &m_specialFastCaseProfiles.last();
537 unsigned numberOfSpecialFastCaseProfiles() { return m_specialFastCaseProfiles.size(); }
538 RareCaseProfile* specialFastCaseProfile(int index) { return &m_specialFastCaseProfiles[index]; }
539 RareCaseProfile* specialFastCaseProfileForBytecodeOffset(int bytecodeOffset)
541 return tryBinarySearch<RareCaseProfile, int>(
542 m_specialFastCaseProfiles, m_specialFastCaseProfiles.size(), bytecodeOffset,
543 getRareCaseProfileBytecodeOffset);
546 bool likelyToTakeSpecialFastCase(int bytecodeOffset)
548 if (!hasBaselineJITProfiling())
550 unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
551 return specialFastCaseCount >= Options::likelyToTakeSlowCaseMinimumCount();
554 bool couldTakeSpecialFastCase(int bytecodeOffset)
556 if (!hasBaselineJITProfiling())
558 unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
559 return specialFastCaseCount >= Options::couldTakeSlowCaseMinimumCount();
562 bool likelyToTakeDeepestSlowCase(int bytecodeOffset)
564 if (!hasBaselineJITProfiling())
566 unsigned slowCaseCount = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
567 unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
568 unsigned value = slowCaseCount - specialFastCaseCount;
569 return value >= Options::likelyToTakeSlowCaseMinimumCount();
572 bool likelyToTakeAnySlowCase(int bytecodeOffset)
574 if (!hasBaselineJITProfiling())
576 unsigned slowCaseCount = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
577 unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
578 unsigned value = slowCaseCount + specialFastCaseCount;
579 return value >= Options::likelyToTakeSlowCaseMinimumCount();
582 unsigned numberOfArrayProfiles() const { return m_arrayProfiles.size(); }
583 const ArrayProfileVector& arrayProfiles() { return m_arrayProfiles; }
584 ArrayProfile* addArrayProfile(unsigned bytecodeOffset)
586 m_arrayProfiles.append(ArrayProfile(bytecodeOffset));
587 return &m_arrayProfiles.last();
589 ArrayProfile* getArrayProfile(unsigned bytecodeOffset);
590 ArrayProfile* getOrAddArrayProfile(unsigned bytecodeOffset);
593 // Exception handling support
595 size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
596 void allocateHandlers(const Vector<UnlinkedHandlerInfo>& unlinkedHandlers)
598 size_t count = unlinkedHandlers.size();
601 createRareDataIfNecessary();
602 m_rareData->m_exceptionHandlers.resize(count);
603 for (size_t i = 0; i < count; ++i) {
604 m_rareData->m_exceptionHandlers[i].start = unlinkedHandlers[i].start;
605 m_rareData->m_exceptionHandlers[i].end = unlinkedHandlers[i].end;
606 m_rareData->m_exceptionHandlers[i].target = unlinkedHandlers[i].target;
607 m_rareData->m_exceptionHandlers[i].scopeDepth = unlinkedHandlers[i].scopeDepth;
611 HandlerInfo& exceptionHandler(int index) { RELEASE_ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
613 bool hasExpressionInfo() { return m_unlinkedCode->hasExpressionInfo(); }
616 Vector<CallReturnOffsetToBytecodeOffset, 0, UnsafeVectorOverflow>& callReturnIndexVector()
618 createRareDataIfNecessary();
619 return m_rareData->m_callReturnIndexVector;
624 SegmentedVector<InlineCallFrame, 4>& inlineCallFrames()
626 createRareDataIfNecessary();
627 return m_rareData->m_inlineCallFrames;
630 Vector<CodeOrigin, 0, UnsafeVectorOverflow>& codeOrigins()
632 createRareDataIfNecessary();
633 return m_rareData->m_codeOrigins;
636 unsigned addCodeOrigin(CodeOrigin codeOrigin)
638 createRareDataIfNecessary();
639 unsigned result = m_rareData->m_codeOrigins.size();
640 m_rareData->m_codeOrigins.append(codeOrigin);
644 // Having code origins implies that there has been some inlining.
645 bool hasCodeOrigins()
647 return m_rareData && !!m_rareData->m_codeOrigins.size();
650 bool canGetCodeOrigin(unsigned index)
654 return m_rareData->m_codeOrigins.size() > index;
657 CodeOrigin codeOrigin(unsigned index)
659 RELEASE_ASSERT(m_rareData);
660 return m_rareData->m_codeOrigins[index];
663 bool addFrequentExitSite(const DFG::FrequentExitSite& site)
665 ASSERT(JITCode::isBaselineCode(jitType()));
666 ConcurrentJITLocker locker(m_lock);
667 return m_exitProfile.add(locker, site);
670 bool hasExitSite(const DFG::FrequentExitSite& site) const
672 ConcurrentJITLocker locker(m_lock);
673 return m_exitProfile.hasExitSite(locker, site);
676 DFG::ExitProfile& exitProfile() { return m_exitProfile; }
678 CompressedLazyOperandValueProfileHolder& lazyOperandValueProfiles()
680 return m_lazyOperandValueProfiles;
686 size_t numberOfIdentifiers() const { return m_unlinkedCode->numberOfIdentifiers() + numberOfDFGIdentifiers(); }
687 size_t numberOfDFGIdentifiers() const
689 if (!JITCode::isOptimizingJIT(jitType()))
692 return m_jitCode->dfgCommon()->dfgIdentifiers.size();
695 const Identifier& identifier(int index) const
697 size_t unlinkedIdentifiers = m_unlinkedCode->numberOfIdentifiers();
698 if (static_cast<unsigned>(index) < unlinkedIdentifiers)
699 return m_unlinkedCode->identifier(index);
700 ASSERT(JITCode::isOptimizingJIT(jitType()));
701 return m_jitCode->dfgCommon()->dfgIdentifiers[index - unlinkedIdentifiers];
704 size_t numberOfIdentifiers() const { return m_unlinkedCode->numberOfIdentifiers(); }
705 const Identifier& identifier(int index) const { return m_unlinkedCode->identifier(index); }
708 Vector<WriteBarrier<Unknown> >& constants() { return m_constantRegisters; }
709 size_t numberOfConstantRegisters() const { return m_constantRegisters.size(); }
710 unsigned addConstant(JSValue v)
712 unsigned result = m_constantRegisters.size();
713 m_constantRegisters.append(WriteBarrier<Unknown>());
714 m_constantRegisters.last().set(m_globalObject->vm(), m_ownerExecutable.get(), v);
718 unsigned addConstantLazily()
720 unsigned result = m_constantRegisters.size();
721 m_constantRegisters.append(WriteBarrier<Unknown>());
725 bool findConstant(JSValue, unsigned& result);
726 unsigned addOrFindConstant(JSValue);
727 WriteBarrier<Unknown>& constantRegister(int index) { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
728 ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
729 ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].get(); }
731 FunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); }
732 int numberOfFunctionDecls() { return m_functionDecls.size(); }
733 FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
735 RegExp* regexp(int index) const { return m_unlinkedCode->regexp(index); }
737 unsigned numberOfConstantBuffers() const
741 return m_rareData->m_constantBuffers.size();
743 unsigned addConstantBuffer(const Vector<JSValue>& buffer)
745 createRareDataIfNecessary();
746 unsigned size = m_rareData->m_constantBuffers.size();
747 m_rareData->m_constantBuffers.append(buffer);
751 Vector<JSValue>& constantBufferAsVector(unsigned index)
754 return m_rareData->m_constantBuffers[index];
756 JSValue* constantBuffer(unsigned index)
758 return constantBufferAsVector(index).data();
761 JSGlobalObject* globalObject() { return m_globalObject.get(); }
763 JSGlobalObject* globalObjectFor(CodeOrigin);
767 size_t numberOfSwitchJumpTables() const { return m_rareData ? m_rareData->m_switchJumpTables.size() : 0; }
768 SimpleJumpTable& addSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_switchJumpTables.append(SimpleJumpTable()); return m_rareData->m_switchJumpTables.last(); }
769 SimpleJumpTable& switchJumpTable(int tableIndex) { RELEASE_ASSERT(m_rareData); return m_rareData->m_switchJumpTables[tableIndex]; }
770 void clearSwitchJumpTables()
774 m_rareData->m_switchJumpTables.clear();
777 size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; }
778 StringJumpTable& addStringSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_stringSwitchJumpTables.append(StringJumpTable()); return m_rareData->m_stringSwitchJumpTables.last(); }
779 StringJumpTable& stringSwitchJumpTable(int tableIndex) { RELEASE_ASSERT(m_rareData); return m_rareData->m_stringSwitchJumpTables[tableIndex]; }
782 SharedSymbolTable* symbolTable() const { return m_unlinkedCode->symbolTable(); }
784 EvalCodeCache& evalCodeCache() { createRareDataIfNecessary(); return m_rareData->m_evalCodeCache; }
787 // Shrink prior to generating machine code that may point directly into vectors.
790 // Shrink after generating machine code, and after possibly creating new vectors
791 // and appending to others. At this time it is not safe to shrink certain vectors
792 // because we would have generated machine code that references them directly.
795 void shrinkToFit(ShrinkMode);
797 void copyPostParseDataFrom(CodeBlock* alternative);
798 void copyPostParseDataFromAlternative();
800 // Functions for controlling when JITting kicks in, in a mixed mode
803 bool checkIfJITThresholdReached()
805 return m_llintExecuteCounter.checkIfThresholdCrossedAndSet(this);
808 void dontJITAnytimeSoon()
810 m_llintExecuteCounter.deferIndefinitely();
813 void jitAfterWarmUp()
815 m_llintExecuteCounter.setNewThreshold(Options::thresholdForJITAfterWarmUp(), this);
820 m_llintExecuteCounter.setNewThreshold(Options::thresholdForJITSoon(), this);
823 const ExecutionCounter& llintExecuteCounter() const
825 return m_llintExecuteCounter;
828 // Functions for controlling when tiered compilation kicks in. This
829 // controls both when the optimizing compiler is invoked and when OSR
830 // entry happens. Two triggers exist: the loop trigger and the return
831 // trigger. In either case, when an addition to m_jitExecuteCounter
832 // causes it to become non-negative, the optimizing compiler is
833 // invoked. This includes a fast check to see if this CodeBlock has
834 // already been optimized (i.e. replacement() returns a CodeBlock
835 // that was optimized with a higher tier JIT than this one). In the
836 // case of the loop trigger, if the optimized compilation succeeds
837 // (or has already succeeded in the past) then OSR is attempted to
838 // redirect program flow into the optimized code.
840 // These functions are called from within the optimization triggers,
841 // and are used as a single point at which we define the heuristics
842 // for how much warm-up is mandated before the next optimization
843 // trigger files. All CodeBlocks start out with optimizeAfterWarmUp(),
844 // as this is called from the CodeBlock constructor.
846 // When we observe a lot of speculation failures, we trigger a
847 // reoptimization. But each time, we increase the optimization trigger
848 // to avoid thrashing.
849 unsigned reoptimizationRetryCounter() const;
850 void countReoptimization();
852 unsigned numberOfDFGCompiles();
854 int32_t codeTypeThresholdMultiplier() const;
856 int32_t counterValueForOptimizeAfterWarmUp();
857 int32_t counterValueForOptimizeAfterLongWarmUp();
858 int32_t counterValueForOptimizeSoon();
860 int32_t* addressOfJITExecuteCounter()
862 return &m_jitExecuteCounter.m_counter;
865 static ptrdiff_t offsetOfJITExecuteCounter() { return OBJECT_OFFSETOF(CodeBlock, m_jitExecuteCounter) + OBJECT_OFFSETOF(ExecutionCounter, m_counter); }
866 static ptrdiff_t offsetOfJITExecutionActiveThreshold() { return OBJECT_OFFSETOF(CodeBlock, m_jitExecuteCounter) + OBJECT_OFFSETOF(ExecutionCounter, m_activeThreshold); }
867 static ptrdiff_t offsetOfJITExecutionTotalCount() { return OBJECT_OFFSETOF(CodeBlock, m_jitExecuteCounter) + OBJECT_OFFSETOF(ExecutionCounter, m_totalCount); }
869 const ExecutionCounter& jitExecuteCounter() const { return m_jitExecuteCounter; }
871 unsigned optimizationDelayCounter() const { return m_optimizationDelayCounter; }
873 // Check if the optimization threshold has been reached, and if not,
874 // adjust the heuristics accordingly. Returns true if the threshold has
876 bool checkIfOptimizationThresholdReached();
878 // Call this to force the next optimization trigger to fire. This is
879 // rarely wise, since optimization triggers are typically more
880 // expensive than executing baseline code.
881 void optimizeNextInvocation();
883 // Call this to prevent optimization from happening again. Note that
884 // optimization will still happen after roughly 2^29 invocations,
885 // so this is really meant to delay that as much as possible. This
886 // is called if optimization failed, and we expect it to fail in
887 // the future as well.
888 void dontOptimizeAnytimeSoon();
890 // Call this to reinitialize the counter to its starting state,
891 // forcing a warm-up to happen before the next optimization trigger
892 // fires. This is called in the CodeBlock constructor. It also
893 // makes sense to call this if an OSR exit occurred. Note that
894 // OSR exit code is code generated, so the value of the execute
895 // counter that this corresponds to is also available directly.
896 void optimizeAfterWarmUp();
898 // Call this to force an optimization trigger to fire only after
900 void optimizeAfterLongWarmUp();
902 // Call this to cause an optimization trigger to fire soon, but
903 // not necessarily the next one. This makes sense if optimization
904 // succeeds. Successfuly optimization means that all calls are
905 // relinked to the optimized code, so this only affects call
906 // frames that are still executing this CodeBlock. The value here
907 // is tuned to strike a balance between the cost of OSR entry
908 // (which is too high to warrant making every loop back edge to
909 // trigger OSR immediately) and the cost of executing baseline
910 // code (which is high enough that we don't necessarily want to
911 // have a full warm-up). The intuition for calling this instead of
912 // optimizeNextInvocation() is for the case of recursive functions
913 // with loops. Consider that there may be N call frames of some
914 // recursive function, for a reasonably large value of N. The top
915 // one triggers optimization, and then returns, and then all of
916 // the others return. We don't want optimization to be triggered on
917 // each return, as that would be superfluous. It only makes sense
918 // to trigger optimization if one of those functions becomes hot
919 // in the baseline code.
922 void forceOptimizationSlowPathConcurrently();
924 void setOptimizationThresholdBasedOnCompilationResult(CompilationResult);
926 uint32_t osrExitCounter() const { return m_osrExitCounter; }
928 void countOSRExit() { m_osrExitCounter++; }
930 uint32_t* addressOfOSRExitCounter() { return &m_osrExitCounter; }
932 static ptrdiff_t offsetOfOSRExitCounter() { return OBJECT_OFFSETOF(CodeBlock, m_osrExitCounter); }
934 uint32_t adjustedExitCountThreshold(uint32_t desiredThreshold);
935 uint32_t exitCountThresholdForReoptimization();
936 uint32_t exitCountThresholdForReoptimizationFromLoop();
937 bool shouldReoptimizeNow();
938 bool shouldReoptimizeFromLoopNow();
940 void optimizeAfterWarmUp() { }
941 unsigned numberOfDFGCompiles() { return 0; }
944 #if ENABLE(VALUE_PROFILER)
945 bool shouldOptimizeNow();
946 void updateAllValueProfilePredictions(OperationInProgress = NoOperation);
947 void updateAllArrayPredictions();
948 void updateAllPredictions(OperationInProgress = NoOperation);
950 bool updateAllPredictionsAndCheckIfShouldOptimizeNow() { return false; }
951 void updateAllValueProfilePredictions(OperationInProgress = NoOperation) { }
952 void updateAllArrayPredictions() { }
953 void updateAllPredictions(OperationInProgress = NoOperation) { }
960 #if ENABLE(VERBOSE_VALUE_PROFILE)
961 void dumpValueProfiles();
964 // FIXME: Make these remaining members private.
966 int m_numCalleeRegisters;
968 bool m_isConstructor;
970 // This is intentionally public; it's the responsibility of anyone doing any
971 // of the following to hold the lock:
973 // - Modifying any inline cache in this code block.
975 // - Quering any inline cache in this code block, from a thread other than
978 // Additionally, it's only legal to modify the inline cache on the main
979 // thread. This means that the main thread can query the inline cache without
980 // locking. This is crucial since executing the inline cache is effectively
983 // Another exception to the rules is that the GC can do whatever it wants
984 // without holding any locks, because the GC is guaranteed to wait until any
985 // concurrent compilation threads finish what they're doing.
986 mutable ConcurrentJITLock m_lock;
988 bool m_shouldAlwaysBeInlined;
989 bool m_allTransitionsHaveBeenMarked; // Initialized and used on every GC.
993 virtual void jettisonImpl() = 0;
995 virtual void visitWeakReferences(SlotVisitor&);
996 virtual void finalizeUnconditionally();
999 void tallyFrequentExitSites();
1001 void tallyFrequentExitSites() { }
1005 friend class DFGCodeBlocks;
1007 CompilationResult prepareForExecutionImpl(
1008 ExecState*, JITCode::JITType, JITCompilationEffort, unsigned bytecodeIndex,
1009 PassRefPtr<DeferredCompilationCallback>);
1011 void noticeIncomingCall(ExecState* callerFrame);
1013 double optimizationThresholdScalingFactor();
1016 ClosureCallStubRoutine* findClosureCallForReturnPC(ReturnAddressPtr);
1019 #if ENABLE(VALUE_PROFILER)
1020 void updateAllPredictionsAndCountLiveness(OperationInProgress, unsigned& numberOfLiveNonArgumentValueProfiles, unsigned& numberOfSamplesInProfiles);
1023 void setConstantRegisters(const Vector<WriteBarrier<Unknown> >& constants)
1025 size_t count = constants.size();
1026 m_constantRegisters.resize(count);
1027 for (size_t i = 0; i < count; i++)
1028 m_constantRegisters[i].set(*m_vm, ownerExecutable(), constants[i].get());
1031 void dumpBytecode(PrintStream&, ExecState*, const Instruction* begin, const Instruction*&);
1033 CString registerName(int r) const;
1034 void printUnaryOp(PrintStream&, ExecState*, int location, const Instruction*&, const char* op);
1035 void printBinaryOp(PrintStream&, ExecState*, int location, const Instruction*&, const char* op);
1036 void printConditionalJump(PrintStream&, ExecState*, const Instruction*, const Instruction*&, int location, const char* op);
1037 void printGetByIdOp(PrintStream&, ExecState*, int location, const Instruction*&);
1038 void printGetByIdCacheStatus(PrintStream&, ExecState*, int location);
1039 enum CacheDumpMode { DumpCaches, DontDumpCaches };
1040 void printCallOp(PrintStream&, ExecState*, int location, const Instruction*&, const char* op, CacheDumpMode, bool& hasPrintedProfiling);
1041 void printPutByIdOp(PrintStream&, ExecState*, int location, const Instruction*&, const char* op);
1042 void beginDumpProfiling(PrintStream&, bool& hasPrintedProfiling);
1043 void dumpValueProfiling(PrintStream&, const Instruction*&, bool& hasPrintedProfiling);
1044 void dumpArrayProfiling(PrintStream&, const Instruction*&, bool& hasPrintedProfiling);
1045 #if ENABLE(VALUE_PROFILER)
1046 void dumpRareCaseProfile(PrintStream&, const char* name, RareCaseProfile*, bool& hasPrintedProfiling);
1050 bool shouldImmediatelyAssumeLivenessDuringScan()
1052 // Null m_dfgData means that this is a baseline JIT CodeBlock. Baseline JIT
1053 // CodeBlocks don't need to be jettisoned when their weak references go
1054 // stale. So if a basline JIT CodeBlock gets scanned, we can assume that
1055 // this means that it's live.
1056 if (!JITCode::isOptimizingJIT(jitType()))
1059 // For simplicity, we don't attempt to jettison code blocks during GC if
1060 // they are executing. Instead we strongly mark their weak references to
1061 // allow them to continue to execute soundly.
1062 if (m_jitCode->dfgCommon()->mayBeExecuting)
1065 if (Options::forceDFGCodeBlockLiveness())
1071 bool shouldImmediatelyAssumeLivenessDuringScan() { return true; }
1074 void propagateTransitions(SlotVisitor&);
1075 void determineLiveness(SlotVisitor&);
1077 void stronglyVisitStrongReferences(SlotVisitor&);
1078 void stronglyVisitWeakReferences(SlotVisitor&);
1080 void createRareDataIfNecessary()
1083 m_rareData = adoptPtr(new RareData);
1087 void resetStubInternal(RepatchBuffer&, StructureStubInfo&);
1088 void resetStubDuringGCInternal(RepatchBuffer&, StructureStubInfo&);
1090 WriteBarrier<UnlinkedCodeBlock> m_unlinkedCode;
1091 int m_numParameters;
1092 WriteBarrier<ScriptExecutable> m_ownerExecutable;
1095 RefCountedArray<Instruction> m_instructions;
1097 int m_argumentsRegister;
1098 int m_activationRegister;
1100 bool m_isStrictMode;
1101 bool m_needsActivation;
1103 RefPtr<SourceProvider> m_source;
1104 unsigned m_sourceOffset;
1105 unsigned m_firstLineColumnOffset;
1106 unsigned m_codeType;
1109 SegmentedVector<LLIntCallLinkInfo, 8> m_llintCallLinkInfos;
1110 SentinelLinkedList<LLIntCallLinkInfo, BasicRawSentinelNode<LLIntCallLinkInfo> > m_incomingLLIntCalls;
1112 RefPtr<JITCode> m_jitCode;
1113 MacroAssemblerCodePtr m_jitCodeWithArityCheck;
1115 Vector<StructureStubInfo> m_structureStubInfos;
1116 Vector<ByValInfo> m_byValInfos;
1117 Vector<CallLinkInfo> m_callLinkInfos;
1118 SentinelLinkedList<CallLinkInfo, BasicRawSentinelNode<CallLinkInfo> > m_incomingCalls;
1120 #if ENABLE(DFG_JIT) || ENABLE(LLINT)
1121 OwnPtr<CompactJITCodeMap> m_jitCodeMap;
1124 // This is relevant to non-DFG code blocks that serve as the profiled code block
1125 // for DFG code blocks.
1126 DFG::ExitProfile m_exitProfile;
1127 CompressedLazyOperandValueProfileHolder m_lazyOperandValueProfiles;
1129 #if ENABLE(VALUE_PROFILER)
1130 Vector<ValueProfile> m_argumentValueProfiles;
1131 SegmentedVector<ValueProfile, 8> m_valueProfiles;
1132 SegmentedVector<RareCaseProfile, 8> m_rareCaseProfiles;
1133 SegmentedVector<RareCaseProfile, 8> m_specialFastCaseProfiles;
1134 SegmentedVector<ArrayAllocationProfile, 8> m_arrayAllocationProfiles;
1135 ArrayProfileVector m_arrayProfiles;
1137 SegmentedVector<ObjectAllocationProfile, 8> m_objectAllocationProfiles;
1140 Vector<Identifier> m_additionalIdentifiers;
1141 COMPILE_ASSERT(sizeof(Register) == sizeof(WriteBarrier<Unknown>), Register_must_be_same_size_as_WriteBarrier_Unknown);
1142 // TODO: This could just be a pointer to m_unlinkedCodeBlock's data, but the DFG mutates
1143 // it, so we're stuck with it for now.
1144 Vector<WriteBarrier<Unknown> > m_constantRegisters;
1145 Vector<WriteBarrier<FunctionExecutable> > m_functionDecls;
1146 Vector<WriteBarrier<FunctionExecutable> > m_functionExprs;
1148 RefPtr<CodeBlock> m_alternative;
1150 ExecutionCounter m_llintExecuteCounter;
1152 ExecutionCounter m_jitExecuteCounter;
1153 int32_t m_totalJITExecutions;
1154 uint32_t m_osrExitCounter;
1155 uint16_t m_optimizationDelayCounter;
1156 uint16_t m_reoptimizationRetryCounter;
1158 mutable CodeBlockHash m_hash;
1161 WTF_MAKE_FAST_ALLOCATED;
1163 Vector<HandlerInfo> m_exceptionHandlers;
1165 // Buffers used for large array literals
1166 Vector<Vector<JSValue> > m_constantBuffers;
1169 Vector<SimpleJumpTable> m_switchJumpTables;
1170 Vector<StringJumpTable> m_stringSwitchJumpTables;
1172 EvalCodeCache m_evalCodeCache;
1175 Vector<CallReturnOffsetToBytecodeOffset, 0, UnsafeVectorOverflow> m_callReturnIndexVector;
1178 SegmentedVector<InlineCallFrame, 4> m_inlineCallFrames;
1179 Vector<CodeOrigin, 0, UnsafeVectorOverflow> m_codeOrigins;
1183 friend void WTF::deleteOwnedPtr<RareData>(RareData*);
1185 OwnPtr<RareData> m_rareData;
1187 DFG::CapabilityLevel m_capabilityLevelState;
1191 // Program code is not marked by any function, so we make the global object
1192 // responsible for marking it.
1194 class GlobalCodeBlock : public CodeBlock {
1196 GlobalCodeBlock(CopyParsedBlockTag, GlobalCodeBlock& other)
1197 : CodeBlock(CopyParsedBlock, other)
1201 GlobalCodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
1202 : CodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, sourceOffset, firstLineColumnOffset)
1207 class ProgramCodeBlock : public GlobalCodeBlock {
1209 ProgramCodeBlock(CopyParsedBlockTag, ProgramCodeBlock& other)
1210 : GlobalCodeBlock(CopyParsedBlock, other)
1214 ProgramCodeBlock(ProgramExecutable* ownerExecutable, UnlinkedProgramCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned firstLineColumnOffset)
1215 : GlobalCodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, 0, firstLineColumnOffset)
1221 virtual void jettisonImpl();
1222 virtual CodeBlock* replacement();
1223 virtual DFG::CapabilityLevel capabilityLevelInternal();
1227 class EvalCodeBlock : public GlobalCodeBlock {
1229 EvalCodeBlock(CopyParsedBlockTag, EvalCodeBlock& other)
1230 : GlobalCodeBlock(CopyParsedBlock, other)
1234 EvalCodeBlock(EvalExecutable* ownerExecutable, UnlinkedEvalCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider)
1235 : GlobalCodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, 0, 1)
1239 const Identifier& variable(unsigned index) { return unlinkedEvalCodeBlock()->variable(index); }
1240 unsigned numVariables() { return unlinkedEvalCodeBlock()->numVariables(); }
1244 virtual void jettisonImpl();
1245 virtual CodeBlock* replacement();
1246 virtual DFG::CapabilityLevel capabilityLevelInternal();
1250 UnlinkedEvalCodeBlock* unlinkedEvalCodeBlock() const { return jsCast<UnlinkedEvalCodeBlock*>(unlinkedCodeBlock()); }
1253 class FunctionCodeBlock : public CodeBlock {
1255 FunctionCodeBlock(CopyParsedBlockTag, FunctionCodeBlock& other)
1256 : CodeBlock(CopyParsedBlock, other)
1260 FunctionCodeBlock(FunctionExecutable* ownerExecutable, UnlinkedFunctionCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
1261 : CodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, sourceOffset, firstLineColumnOffset)
1267 virtual void jettisonImpl();
1268 virtual CodeBlock* replacement();
1269 virtual DFG::CapabilityLevel capabilityLevelInternal();
1273 inline CodeBlock* baselineCodeBlockForInlineCallFrame(InlineCallFrame* inlineCallFrame)
1275 RELEASE_ASSERT(inlineCallFrame);
1276 ExecutableBase* executable = inlineCallFrame->executable.get();
1277 RELEASE_ASSERT(executable->structure()->classInfo() == FunctionExecutable::info());
1278 return static_cast<FunctionExecutable*>(executable)->baselineCodeBlockFor(inlineCallFrame->isCall ? CodeForCall : CodeForConstruct);
1281 inline CodeBlock* baselineCodeBlockForOriginAndBaselineCodeBlock(const CodeOrigin& codeOrigin, CodeBlock* baselineCodeBlock)
1283 if (codeOrigin.inlineCallFrame)
1284 return baselineCodeBlockForInlineCallFrame(codeOrigin.inlineCallFrame);
1285 return baselineCodeBlock;
1288 inline int CodeBlock::argumentIndexAfterCapture(size_t argument)
1290 if (argument >= static_cast<size_t>(symbolTable()->parameterCount()))
1291 return CallFrame::argumentOffset(argument);
1293 const SlowArgument* slowArguments = symbolTable()->slowArguments();
1294 if (!slowArguments || slowArguments[argument].status == SlowArgument::Normal)
1295 return CallFrame::argumentOffset(argument);
1297 ASSERT(slowArguments[argument].status == SlowArgument::Captured);
1298 return slowArguments[argument].index;
1301 inline Register& ExecState::r(int index)
1303 CodeBlock* codeBlock = this->codeBlock();
1304 if (codeBlock->isConstantRegisterIndex(index))
1305 return *reinterpret_cast<Register*>(&codeBlock->constantRegister(index));
1309 inline Register& ExecState::uncheckedR(int index)
1311 RELEASE_ASSERT(index < FirstConstantRegisterIndex);
1315 inline JSValue ExecState::argumentAfterCapture(size_t argument)
1317 if (argument >= argumentCount())
1318 return jsUndefined();
1321 return this[argumentOffset(argument)].jsValue();
1323 return this[codeBlock()->argumentIndexAfterCapture(argument)].jsValue();
1327 inline void DFGCodeBlocks::mark(void* candidateCodeBlock)
1329 // We have to check for 0 and -1 because those are used by the HashMap as markers.
1330 uintptr_t value = reinterpret_cast<uintptr_t>(candidateCodeBlock);
1332 // This checks for both of those nasty cases in one go.
1338 HashSet<CodeBlock*>::iterator iter = m_set.find(static_cast<CodeBlock*>(candidateCodeBlock));
1339 if (iter == m_set.end())
1342 (*iter)->m_jitCode->dfgCommon()->mayBeExecuting = true;
1348 #endif // CodeBlock_h