Make some methods const.
[WebKit.git] / Source / JavaScriptCore / bytecode / CodeBlock.cpp
1 /*
2  * Copyright (C) 2008-2010, 2012-2016 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
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 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.
17  *
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.
28  */
29
30 #include "config.h"
31 #include "CodeBlock.h"
32
33 #include "BasicBlockLocation.h"
34 #include "BytecodeGenerator.h"
35 #include "BytecodeUseDef.h"
36 #include "CallLinkStatus.h"
37 #include "DFGCapabilities.h"
38 #include "DFGCommon.h"
39 #include "DFGDriver.h"
40 #include "DFGJITCode.h"
41 #include "DFGWorklist.h"
42 #include "Debugger.h"
43 #include "FunctionExecutableDump.h"
44 #include "GetPutInfo.h"
45 #include "InlineCallFrame.h"
46 #include "Interpreter.h"
47 #include "JIT.h"
48 #include "JSCJSValue.h"
49 #include "JSFunction.h"
50 #include "JSLexicalEnvironment.h"
51 #include "JSModuleEnvironment.h"
52 #include "LLIntEntrypoint.h"
53 #include "LLIntPrototypeLoadAdaptiveStructureWatchpoint.h"
54 #include "LowLevelInterpreter.h"
55 #include "JSCInlines.h"
56 #include "PCToCodeOriginMap.h"
57 #include "PolymorphicAccess.h"
58 #include "ProfilerDatabase.h"
59 #include "ReduceWhitespace.h"
60 #include "Repatch.h"
61 #include "SlotVisitorInlines.h"
62 #include "StackVisitor.h"
63 #include "StructureStubInfo.h"
64 #include "TypeLocationCache.h"
65 #include "TypeProfiler.h"
66 #include "UnlinkedInstructionStream.h"
67 #include "VMInlines.h"
68 #include <wtf/BagToHashMap.h>
69 #include <wtf/CommaPrinter.h>
70 #include <wtf/StringExtras.h>
71 #include <wtf/StringPrintStream.h>
72 #include <wtf/text/UniquedStringImpl.h>
73
74 #if ENABLE(JIT)
75 #include "RegisterAtOffsetList.h"
76 #endif
77
78 #if ENABLE(DFG_JIT)
79 #include "DFGOperations.h"
80 #endif
81
82 #if ENABLE(FTL_JIT)
83 #include "FTLJITCode.h"
84 #endif
85
86 namespace JSC {
87
88 const ClassInfo CodeBlock::s_info = {
89     "CodeBlock", 0, 0,
90     CREATE_METHOD_TABLE(CodeBlock)
91 };
92
93 const ClassInfo FunctionCodeBlock::s_info = {
94     "FunctionCodeBlock", &Base::s_info, 0,
95     CREATE_METHOD_TABLE(FunctionCodeBlock)
96 };
97
98 #if ENABLE(WEBASSEMBLY)
99 const ClassInfo WebAssemblyCodeBlock::s_info = {
100     "WebAssemblyCodeBlock", &Base::s_info, 0,
101     CREATE_METHOD_TABLE(WebAssemblyCodeBlock)
102 };
103 #endif
104
105 const ClassInfo GlobalCodeBlock::s_info = {
106     "GlobalCodeBlock", &Base::s_info, 0,
107     CREATE_METHOD_TABLE(GlobalCodeBlock)
108 };
109
110 const ClassInfo ProgramCodeBlock::s_info = {
111     "ProgramCodeBlock", &Base::s_info, 0,
112     CREATE_METHOD_TABLE(ProgramCodeBlock)
113 };
114
115 const ClassInfo ModuleProgramCodeBlock::s_info = {
116     "ModuleProgramCodeBlock", &Base::s_info, 0,
117     CREATE_METHOD_TABLE(ModuleProgramCodeBlock)
118 };
119
120 const ClassInfo EvalCodeBlock::s_info = {
121     "EvalCodeBlock", &Base::s_info, 0,
122     CREATE_METHOD_TABLE(EvalCodeBlock)
123 };
124
125 void FunctionCodeBlock::destroy(JSCell* cell)
126 {
127     jsCast<FunctionCodeBlock*>(cell)->~FunctionCodeBlock();
128 }
129
130 #if ENABLE(WEBASSEMBLY)
131 void WebAssemblyCodeBlock::destroy(JSCell* cell)
132 {
133     jsCast<WebAssemblyCodeBlock*>(cell)->~WebAssemblyCodeBlock();
134 }
135 #endif
136
137 void ProgramCodeBlock::destroy(JSCell* cell)
138 {
139     jsCast<ProgramCodeBlock*>(cell)->~ProgramCodeBlock();
140 }
141
142 void ModuleProgramCodeBlock::destroy(JSCell* cell)
143 {
144     jsCast<ModuleProgramCodeBlock*>(cell)->~ModuleProgramCodeBlock();
145 }
146
147 void EvalCodeBlock::destroy(JSCell* cell)
148 {
149     jsCast<EvalCodeBlock*>(cell)->~EvalCodeBlock();
150 }
151
152 CString CodeBlock::inferredName() const
153 {
154     switch (codeType()) {
155     case GlobalCode:
156         return "<global>";
157     case EvalCode:
158         return "<eval>";
159     case FunctionCode:
160         return jsCast<FunctionExecutable*>(ownerExecutable())->inferredName().utf8();
161     case ModuleCode:
162         return "<module>";
163     default:
164         CRASH();
165         return CString("", 0);
166     }
167 }
168
169 bool CodeBlock::hasHash() const
170 {
171     return !!m_hash;
172 }
173
174 bool CodeBlock::isSafeToComputeHash() const
175 {
176     return !isCompilationThread();
177 }
178
179 CodeBlockHash CodeBlock::hash() const
180 {
181     if (!m_hash) {
182         RELEASE_ASSERT(isSafeToComputeHash());
183         m_hash = CodeBlockHash(ownerScriptExecutable()->source(), specializationKind());
184     }
185     return m_hash;
186 }
187
188 CString CodeBlock::sourceCodeForTools() const
189 {
190     if (codeType() != FunctionCode)
191         return ownerScriptExecutable()->source().toUTF8();
192     
193     SourceProvider* provider = source();
194     FunctionExecutable* executable = jsCast<FunctionExecutable*>(ownerExecutable());
195     UnlinkedFunctionExecutable* unlinked = executable->unlinkedExecutable();
196     unsigned unlinkedStartOffset = unlinked->startOffset();
197     unsigned linkedStartOffset = executable->source().startOffset();
198     int delta = linkedStartOffset - unlinkedStartOffset;
199     unsigned rangeStart = delta + unlinked->unlinkedFunctionNameStart();
200     unsigned rangeEnd = delta + unlinked->startOffset() + unlinked->sourceLength();
201     return toCString(
202         "function ",
203         provider->source().substring(rangeStart, rangeEnd - rangeStart).utf8());
204 }
205
206 CString CodeBlock::sourceCodeOnOneLine() const
207 {
208     return reduceWhitespace(sourceCodeForTools());
209 }
210
211 CString CodeBlock::hashAsStringIfPossible() const
212 {
213     if (hasHash() || isSafeToComputeHash())
214         return toCString(hash());
215     return "<no-hash>";
216 }
217
218 void CodeBlock::dumpAssumingJITType(PrintStream& out, JITCode::JITType jitType) const
219 {
220     out.print(inferredName(), "#", hashAsStringIfPossible());
221     out.print(":[", RawPointer(this), "->");
222     if (!!m_alternative)
223         out.print(RawPointer(alternative()), "->");
224     out.print(RawPointer(ownerExecutable()), ", ", jitType, codeType());
225
226     if (codeType() == FunctionCode)
227         out.print(specializationKind());
228     out.print(", ", instructionCount());
229     if (this->jitType() == JITCode::BaselineJIT && m_shouldAlwaysBeInlined)
230         out.print(" (ShouldAlwaysBeInlined)");
231     if (ownerScriptExecutable()->neverInline())
232         out.print(" (NeverInline)");
233     if (ownerScriptExecutable()->neverOptimize())
234         out.print(" (NeverOptimize)");
235     else if (ownerScriptExecutable()->neverFTLOptimize())
236         out.print(" (NeverFTLOptimize)");
237     if (ownerScriptExecutable()->didTryToEnterInLoop())
238         out.print(" (DidTryToEnterInLoop)");
239     if (ownerScriptExecutable()->isStrictMode())
240         out.print(" (StrictMode)");
241     if (this->jitType() == JITCode::BaselineJIT && m_didFailFTLCompilation)
242         out.print(" (FTLFail)");
243     if (this->jitType() == JITCode::BaselineJIT && m_hasBeenCompiledWithFTL)
244         out.print(" (HadFTLReplacement)");
245     out.print("]");
246 }
247
248 void CodeBlock::dump(PrintStream& out) const
249 {
250     dumpAssumingJITType(out, jitType());
251 }
252
253 static CString idName(int id0, const Identifier& ident)
254 {
255     return toCString(ident.impl(), "(@id", id0, ")");
256 }
257
258 CString CodeBlock::registerName(int r) const
259 {
260     if (isConstantRegisterIndex(r))
261         return constantName(r);
262
263     return toCString(VirtualRegister(r));
264 }
265
266 CString CodeBlock::constantName(int index) const
267 {
268     JSValue value = getConstant(index);
269     return toCString(value, "(", VirtualRegister(index), ")");
270 }
271
272 static CString regexpToSourceString(RegExp* regExp)
273 {
274     char postfix[5] = { '/', 0, 0, 0, 0 };
275     int index = 1;
276     if (regExp->global())
277         postfix[index++] = 'g';
278     if (regExp->ignoreCase())
279         postfix[index++] = 'i';
280     if (regExp->multiline())
281         postfix[index] = 'm';
282     if (regExp->sticky())
283         postfix[index++] = 'y';
284     if (regExp->unicode())
285         postfix[index++] = 'u';
286
287     return toCString("/", regExp->pattern().impl(), postfix);
288 }
289
290 static CString regexpName(int re, RegExp* regexp)
291 {
292     return toCString(regexpToSourceString(regexp), "(@re", re, ")");
293 }
294
295 NEVER_INLINE static const char* debugHookName(int debugHookID)
296 {
297     switch (static_cast<DebugHookID>(debugHookID)) {
298         case DidEnterCallFrame:
299             return "didEnterCallFrame";
300         case WillLeaveCallFrame:
301             return "willLeaveCallFrame";
302         case WillExecuteStatement:
303             return "willExecuteStatement";
304         case WillExecuteProgram:
305             return "willExecuteProgram";
306         case DidExecuteProgram:
307             return "didExecuteProgram";
308         case DidReachBreakpoint:
309             return "didReachBreakpoint";
310     }
311
312     RELEASE_ASSERT_NOT_REACHED();
313     return "";
314 }
315
316 void CodeBlock::printUnaryOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
317 {
318     int r0 = (++it)->u.operand;
319     int r1 = (++it)->u.operand;
320
321     printLocationAndOp(out, exec, location, it, op);
322     out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
323 }
324
325 void CodeBlock::printBinaryOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
326 {
327     int r0 = (++it)->u.operand;
328     int r1 = (++it)->u.operand;
329     int r2 = (++it)->u.operand;
330     printLocationAndOp(out, exec, location, it, op);
331     out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
332 }
333
334 void CodeBlock::printConditionalJump(PrintStream& out, ExecState* exec, const Instruction*, const Instruction*& it, int location, const char* op)
335 {
336     int r0 = (++it)->u.operand;
337     int offset = (++it)->u.operand;
338     printLocationAndOp(out, exec, location, it, op);
339     out.printf("%s, %d(->%d)", registerName(r0).data(), offset, location + offset);
340 }
341
342 void CodeBlock::printGetByIdOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it)
343 {
344     const char* op;
345     switch (exec->interpreter()->getOpcodeID(it->u.opcode)) {
346     case op_get_by_id:
347         op = "get_by_id";
348         break;
349     case op_get_by_id_proto_load:
350         op = "get_by_id_proto_load";
351         break;
352     case op_get_by_id_unset:
353         op = "get_by_id_unset";
354         break;
355     case op_get_array_length:
356         op = "array_length";
357         break;
358     default:
359         RELEASE_ASSERT_NOT_REACHED();
360 #if COMPILER_QUIRK(CONSIDERS_UNREACHABLE_CODE)
361         op = 0;
362 #endif
363     }
364     int r0 = (++it)->u.operand;
365     int r1 = (++it)->u.operand;
366     int id0 = (++it)->u.operand;
367     printLocationAndOp(out, exec, location, it, op);
368     out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), idName(id0, identifier(id0)).data());
369     it += 4; // Increment up to the value profiler.
370 }
371
372 static void dumpStructure(PrintStream& out, const char* name, Structure* structure, const Identifier& ident)
373 {
374     if (!structure)
375         return;
376     
377     out.printf("%s = %p", name, structure);
378     
379     PropertyOffset offset = structure->getConcurrently(ident.impl());
380     if (offset != invalidOffset)
381         out.printf(" (offset = %d)", offset);
382 }
383
384 static void dumpChain(PrintStream& out, StructureChain* chain, const Identifier& ident)
385 {
386     out.printf("chain = %p: [", chain);
387     bool first = true;
388     for (WriteBarrier<Structure>* currentStructure = chain->head();
389          *currentStructure;
390          ++currentStructure) {
391         if (first)
392             first = false;
393         else
394             out.printf(", ");
395         dumpStructure(out, "struct", currentStructure->get(), ident);
396     }
397     out.printf("]");
398 }
399
400 void CodeBlock::printGetByIdCacheStatus(PrintStream& out, ExecState* exec, int location, const StubInfoMap& map)
401 {
402     Instruction* instruction = instructions().begin() + location;
403
404     const Identifier& ident = identifier(instruction[3].u.operand);
405     
406     UNUSED_PARAM(ident); // tell the compiler to shut up in certain platform configurations.
407     
408     if (exec->interpreter()->getOpcodeID(instruction[0].u.opcode) == op_get_array_length)
409         out.printf(" llint(array_length)");
410     else if (StructureID structureID = instruction[4].u.structureID) {
411         Structure* structure = m_vm->heap.structureIDTable().get(structureID);
412         out.printf(" llint(");
413         dumpStructure(out, "struct", structure, ident);
414         out.printf(")");
415         if (exec->interpreter()->getOpcodeID(instruction[0].u.opcode) == op_get_by_id_proto_load)
416             out.printf(" proto(%p)", instruction[6].u.pointer);
417     }
418
419 #if ENABLE(JIT)
420     if (StructureStubInfo* stubPtr = map.get(CodeOrigin(location))) {
421         StructureStubInfo& stubInfo = *stubPtr;
422         if (stubInfo.resetByGC)
423             out.print(" (Reset By GC)");
424         
425         out.printf(" jit(");
426             
427         Structure* baseStructure = nullptr;
428         PolymorphicAccess* stub = nullptr;
429             
430         switch (stubInfo.cacheType) {
431         case CacheType::GetByIdSelf:
432             out.printf("self");
433             baseStructure = stubInfo.u.byIdSelf.baseObjectStructure.get();
434             break;
435         case CacheType::Stub:
436             out.printf("stub");
437             stub = stubInfo.u.stub;
438             break;
439         case CacheType::Unset:
440             out.printf("unset");
441             break;
442         default:
443             RELEASE_ASSERT_NOT_REACHED();
444             break;
445         }
446             
447         if (baseStructure) {
448             out.printf(", ");
449             dumpStructure(out, "struct", baseStructure, ident);
450         }
451
452         if (stub)
453             out.print(", ", *stub);
454
455         out.printf(")");
456     }
457 #else
458     UNUSED_PARAM(map);
459 #endif
460 }
461
462 void CodeBlock::printPutByIdCacheStatus(PrintStream& out, int location, const StubInfoMap& map)
463 {
464     Instruction* instruction = instructions().begin() + location;
465
466     const Identifier& ident = identifier(instruction[2].u.operand);
467     
468     UNUSED_PARAM(ident); // tell the compiler to shut up in certain platform configurations.
469
470     out.print(", ", instruction[8].u.putByIdFlags);
471     
472     if (StructureID structureID = instruction[4].u.structureID) {
473         Structure* structure = m_vm->heap.structureIDTable().get(structureID);
474         out.print(" llint(");
475         if (StructureID newStructureID = instruction[6].u.structureID) {
476             Structure* newStructure = m_vm->heap.structureIDTable().get(newStructureID);
477             dumpStructure(out, "prev", structure, ident);
478             out.print(", ");
479             dumpStructure(out, "next", newStructure, ident);
480             if (StructureChain* chain = instruction[7].u.structureChain.get()) {
481                 out.print(", ");
482                 dumpChain(out, chain, ident);
483             }
484         } else
485             dumpStructure(out, "struct", structure, ident);
486         out.print(")");
487     }
488
489 #if ENABLE(JIT)
490     if (StructureStubInfo* stubPtr = map.get(CodeOrigin(location))) {
491         StructureStubInfo& stubInfo = *stubPtr;
492         if (stubInfo.resetByGC)
493             out.print(" (Reset By GC)");
494         
495         out.printf(" jit(");
496         
497         switch (stubInfo.cacheType) {
498         case CacheType::PutByIdReplace:
499             out.print("replace, ");
500             dumpStructure(out, "struct", stubInfo.u.byIdSelf.baseObjectStructure.get(), ident);
501             break;
502         case CacheType::Stub: {
503             out.print("stub, ", *stubInfo.u.stub);
504             break;
505         }
506         case CacheType::Unset:
507             out.printf("unset");
508             break;
509         default:
510             RELEASE_ASSERT_NOT_REACHED();
511             break;
512         }
513         out.printf(")");
514     }
515 #else
516     UNUSED_PARAM(map);
517 #endif
518 }
519
520 void CodeBlock::printCallOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op, CacheDumpMode cacheDumpMode, bool& hasPrintedProfiling, const CallLinkInfoMap& map)
521 {
522     int dst = (++it)->u.operand;
523     int func = (++it)->u.operand;
524     int argCount = (++it)->u.operand;
525     int registerOffset = (++it)->u.operand;
526     printLocationAndOp(out, exec, location, it, op);
527     out.printf("%s, %s, %d, %d", registerName(dst).data(), registerName(func).data(), argCount, registerOffset);
528     if (cacheDumpMode == DumpCaches) {
529         LLIntCallLinkInfo* callLinkInfo = it[1].u.callLinkInfo;
530         if (callLinkInfo->lastSeenCallee) {
531             out.printf(
532                 " llint(%p, exec %p)",
533                 callLinkInfo->lastSeenCallee.get(),
534                 callLinkInfo->lastSeenCallee->executable());
535         }
536 #if ENABLE(JIT)
537         if (CallLinkInfo* info = map.get(CodeOrigin(location))) {
538             JSFunction* target = info->lastSeenCallee();
539             if (target)
540                 out.printf(" jit(%p, exec %p)", target, target->executable());
541         }
542         
543         if (jitType() != JITCode::FTLJIT)
544             out.print(" status(", CallLinkStatus::computeFor(this, location, map), ")");
545 #else
546         UNUSED_PARAM(map);
547 #endif
548     }
549     ++it;
550     ++it;
551     dumpArrayProfiling(out, it, hasPrintedProfiling);
552     dumpValueProfiling(out, it, hasPrintedProfiling);
553 }
554
555 void CodeBlock::printPutByIdOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
556 {
557     int r0 = (++it)->u.operand;
558     int id0 = (++it)->u.operand;
559     int r1 = (++it)->u.operand;
560     printLocationAndOp(out, exec, location, it, op);
561     out.printf("%s, %s, %s", registerName(r0).data(), idName(id0, identifier(id0)).data(), registerName(r1).data());
562     it += 5;
563 }
564
565 void CodeBlock::dumpSource()
566 {
567     dumpSource(WTF::dataFile());
568 }
569
570 void CodeBlock::dumpSource(PrintStream& out)
571 {
572     ScriptExecutable* executable = ownerScriptExecutable();
573     if (executable->isFunctionExecutable()) {
574         FunctionExecutable* functionExecutable = reinterpret_cast<FunctionExecutable*>(executable);
575         StringView source = functionExecutable->source().provider()->getRange(
576             functionExecutable->parametersStartOffset(),
577             functionExecutable->typeProfilingEndOffset() + 1); // Type profiling end offset is the character before the '}'.
578         
579         out.print("function ", inferredName(), source);
580         return;
581     }
582     out.print(executable->source().view());
583 }
584
585 void CodeBlock::dumpBytecode()
586 {
587     dumpBytecode(WTF::dataFile());
588 }
589
590 void CodeBlock::dumpBytecode(PrintStream& out)
591 {
592     // We only use the ExecState* for things that don't actually lead to JS execution,
593     // like converting a JSString to a String. Hence the globalExec is appropriate.
594     ExecState* exec = m_globalObject->globalExec();
595     
596     size_t instructionCount = 0;
597
598     for (size_t i = 0; i < instructions().size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(instructions()[i].u.opcode)])
599         ++instructionCount;
600
601     out.print(*this);
602     out.printf(
603         ": %lu m_instructions; %lu bytes; %d parameter(s); %d callee register(s); %d variable(s)",
604         static_cast<unsigned long>(instructions().size()),
605         static_cast<unsigned long>(instructions().size() * sizeof(Instruction)),
606         m_numParameters, m_numCalleeLocals, m_numVars);
607     out.printf("\n");
608     
609     StubInfoMap stubInfos;
610     CallLinkInfoMap callLinkInfos;
611     getStubInfoMap(stubInfos);
612     getCallLinkInfoMap(callLinkInfos);
613     
614     const Instruction* begin = instructions().begin();
615     const Instruction* end = instructions().end();
616     for (const Instruction* it = begin; it != end; ++it)
617         dumpBytecode(out, exec, begin, it, stubInfos, callLinkInfos);
618     
619     if (numberOfIdentifiers()) {
620         out.printf("\nIdentifiers:\n");
621         size_t i = 0;
622         do {
623             out.printf("  id%u = %s\n", static_cast<unsigned>(i), identifier(i).string().utf8().data());
624             ++i;
625         } while (i != numberOfIdentifiers());
626     }
627
628     if (!m_constantRegisters.isEmpty()) {
629         out.printf("\nConstants:\n");
630         size_t i = 0;
631         do {
632             const char* sourceCodeRepresentationDescription = nullptr;
633             switch (m_constantsSourceCodeRepresentation[i]) {
634             case SourceCodeRepresentation::Double:
635                 sourceCodeRepresentationDescription = ": in source as double";
636                 break;
637             case SourceCodeRepresentation::Integer:
638                 sourceCodeRepresentationDescription = ": in source as integer";
639                 break;
640             case SourceCodeRepresentation::Other:
641                 sourceCodeRepresentationDescription = "";
642                 break;
643             }
644             out.printf("   k%u = %s%s\n", static_cast<unsigned>(i), toCString(m_constantRegisters[i].get()).data(), sourceCodeRepresentationDescription);
645             ++i;
646         } while (i < m_constantRegisters.size());
647     }
648
649     if (size_t count = m_unlinkedCode->numberOfRegExps()) {
650         out.printf("\nm_regexps:\n");
651         size_t i = 0;
652         do {
653             out.printf("  re%u = %s\n", static_cast<unsigned>(i), regexpToSourceString(m_unlinkedCode->regexp(i)).data());
654             ++i;
655         } while (i < count);
656     }
657
658     dumpExceptionHandlers(out);
659     
660     if (m_rareData && !m_rareData->m_switchJumpTables.isEmpty()) {
661         out.printf("Switch Jump Tables:\n");
662         unsigned i = 0;
663         do {
664             out.printf("  %1d = {\n", i);
665             int entry = 0;
666             Vector<int32_t>::const_iterator end = m_rareData->m_switchJumpTables[i].branchOffsets.end();
667             for (Vector<int32_t>::const_iterator iter = m_rareData->m_switchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) {
668                 if (!*iter)
669                     continue;
670                 out.printf("\t\t%4d => %04d\n", entry + m_rareData->m_switchJumpTables[i].min, *iter);
671             }
672             out.printf("      }\n");
673             ++i;
674         } while (i < m_rareData->m_switchJumpTables.size());
675     }
676     
677     if (m_rareData && !m_rareData->m_stringSwitchJumpTables.isEmpty()) {
678         out.printf("\nString Switch Jump Tables:\n");
679         unsigned i = 0;
680         do {
681             out.printf("  %1d = {\n", i);
682             StringJumpTable::StringOffsetTable::const_iterator end = m_rareData->m_stringSwitchJumpTables[i].offsetTable.end();
683             for (StringJumpTable::StringOffsetTable::const_iterator iter = m_rareData->m_stringSwitchJumpTables[i].offsetTable.begin(); iter != end; ++iter)
684                 out.printf("\t\t\"%s\" => %04d\n", iter->key->utf8().data(), iter->value.branchOffset);
685             out.printf("      }\n");
686             ++i;
687         } while (i < m_rareData->m_stringSwitchJumpTables.size());
688     }
689
690     if (m_rareData && !m_rareData->m_liveCalleeLocalsAtYield.isEmpty()) {
691         out.printf("\nLive Callee Locals:\n");
692         unsigned i = 0;
693         do {
694             const FastBitVector& liveness = m_rareData->m_liveCalleeLocalsAtYield[i];
695             out.printf("  live%1u = ", i);
696             liveness.dump(out);
697             out.printf("\n");
698             ++i;
699         } while (i < m_rareData->m_liveCalleeLocalsAtYield.size());
700     }
701
702     out.printf("\n");
703 }
704
705 void CodeBlock::dumpExceptionHandlers(PrintStream& out)
706 {
707     if (m_rareData && !m_rareData->m_exceptionHandlers.isEmpty()) {
708         out.printf("\nException Handlers:\n");
709         unsigned i = 0;
710         do {
711             HandlerInfo& handler = m_rareData->m_exceptionHandlers[i];
712             out.printf("\t %d: { start: [%4d] end: [%4d] target: [%4d] } %s\n",
713                 i + 1, handler.start, handler.end, handler.target, handler.typeName());
714             ++i;
715         } while (i < m_rareData->m_exceptionHandlers.size());
716     }
717 }
718
719 void CodeBlock::beginDumpProfiling(PrintStream& out, bool& hasPrintedProfiling)
720 {
721     if (hasPrintedProfiling) {
722         out.print("; ");
723         return;
724     }
725     
726     out.print("    ");
727     hasPrintedProfiling = true;
728 }
729
730 void CodeBlock::dumpValueProfiling(PrintStream& out, const Instruction*& it, bool& hasPrintedProfiling)
731 {
732     ConcurrentJITLocker locker(m_lock);
733     
734     ++it;
735     CString description = it->u.profile->briefDescription(locker);
736     if (!description.length())
737         return;
738     beginDumpProfiling(out, hasPrintedProfiling);
739     out.print(description);
740 }
741
742 void CodeBlock::dumpArrayProfiling(PrintStream& out, const Instruction*& it, bool& hasPrintedProfiling)
743 {
744     ConcurrentJITLocker locker(m_lock);
745     
746     ++it;
747     if (!it->u.arrayProfile)
748         return;
749     CString description = it->u.arrayProfile->briefDescription(locker, this);
750     if (!description.length())
751         return;
752     beginDumpProfiling(out, hasPrintedProfiling);
753     out.print(description);
754 }
755
756 void CodeBlock::dumpRareCaseProfile(PrintStream& out, const char* name, RareCaseProfile* profile, bool& hasPrintedProfiling)
757 {
758     if (!profile || !profile->m_counter)
759         return;
760
761     beginDumpProfiling(out, hasPrintedProfiling);
762     out.print(name, profile->m_counter);
763 }
764
765 void CodeBlock::dumpResultProfile(PrintStream& out, ResultProfile* profile, bool& hasPrintedProfiling)
766 {
767     if (!profile)
768         return;
769     
770     beginDumpProfiling(out, hasPrintedProfiling);
771     out.print("results: ", *profile);
772 }
773
774 void CodeBlock::printLocationAndOp(PrintStream& out, ExecState*, int location, const Instruction*&, const char* op)
775 {
776     out.printf("[%4d] %-17s ", location, op);
777 }
778
779 void CodeBlock::printLocationOpAndRegisterOperand(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op, int operand)
780 {
781     printLocationAndOp(out, exec, location, it, op);
782     out.printf("%s", registerName(operand).data());
783 }
784
785 void CodeBlock::dumpBytecode(
786     PrintStream& out, ExecState* exec, const Instruction* begin, const Instruction*& it,
787     const StubInfoMap& stubInfos, const CallLinkInfoMap& callLinkInfos)
788 {
789     int location = it - begin;
790     bool hasPrintedProfiling = false;
791     OpcodeID opcode = exec->interpreter()->getOpcodeID(it->u.opcode);
792     switch (opcode) {
793         case op_enter: {
794             printLocationAndOp(out, exec, location, it, "enter");
795             break;
796         }
797         case op_get_scope: {
798             int r0 = (++it)->u.operand;
799             printLocationOpAndRegisterOperand(out, exec, location, it, "get_scope", r0);
800             break;
801         }
802         case op_create_direct_arguments: {
803             int r0 = (++it)->u.operand;
804             printLocationAndOp(out, exec, location, it, "create_direct_arguments");
805             out.printf("%s", registerName(r0).data());
806             break;
807         }
808         case op_create_scoped_arguments: {
809             int r0 = (++it)->u.operand;
810             int r1 = (++it)->u.operand;
811             printLocationAndOp(out, exec, location, it, "create_scoped_arguments");
812             out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
813             break;
814         }
815         case op_create_cloned_arguments: {
816             int r0 = (++it)->u.operand;
817             printLocationAndOp(out, exec, location, it, "create_cloned_arguments");
818             out.printf("%s", registerName(r0).data());
819             break;
820         }
821         case op_argument_count: {
822             int r0 = (++it)->u.operand;
823             printLocationOpAndRegisterOperand(out, exec, location, it, "argument_count", r0);
824             break;
825         }
826         case op_copy_rest: {
827             int r0 = (++it)->u.operand;
828             int r1 = (++it)->u.operand;
829             unsigned argumentOffset = (++it)->u.unsignedValue;
830             printLocationAndOp(out, exec, location, it, "copy_rest");
831             out.printf("%s, %s, ", registerName(r0).data(), registerName(r1).data());
832             out.printf("ArgumentsOffset: %u", argumentOffset);
833             break;
834         }
835         case op_get_rest_length: {
836             int r0 = (++it)->u.operand;
837             printLocationAndOp(out, exec, location, it, "get_rest_length");
838             out.printf("%s, ", registerName(r0).data());
839             unsigned argumentOffset = (++it)->u.unsignedValue;
840             out.printf("ArgumentsOffset: %u", argumentOffset);
841             break;
842         }
843         case op_create_this: {
844             int r0 = (++it)->u.operand;
845             int r1 = (++it)->u.operand;
846             unsigned inferredInlineCapacity = (++it)->u.operand;
847             unsigned cachedFunction = (++it)->u.operand;
848             printLocationAndOp(out, exec, location, it, "create_this");
849             out.printf("%s, %s, %u, %u", registerName(r0).data(), registerName(r1).data(), inferredInlineCapacity, cachedFunction);
850             break;
851         }
852         case op_to_this: {
853             int r0 = (++it)->u.operand;
854             printLocationOpAndRegisterOperand(out, exec, location, it, "to_this", r0);
855             Structure* structure = (++it)->u.structure.get();
856             if (structure)
857                 out.print(", cache(struct = ", RawPointer(structure), ")");
858             out.print(", ", (++it)->u.toThisStatus);
859             break;
860         }
861         case op_check_tdz: {
862             int r0 = (++it)->u.operand;
863             printLocationOpAndRegisterOperand(out, exec, location, it, "op_check_tdz", r0);
864             break;
865         }
866         case op_new_object: {
867             int r0 = (++it)->u.operand;
868             unsigned inferredInlineCapacity = (++it)->u.operand;
869             printLocationAndOp(out, exec, location, it, "new_object");
870             out.printf("%s, %u", registerName(r0).data(), inferredInlineCapacity);
871             ++it; // Skip object allocation profile.
872             break;
873         }
874         case op_new_array: {
875             int dst = (++it)->u.operand;
876             int argv = (++it)->u.operand;
877             int argc = (++it)->u.operand;
878             printLocationAndOp(out, exec, location, it, "new_array");
879             out.printf("%s, %s, %d", registerName(dst).data(), registerName(argv).data(), argc);
880             ++it; // Skip array allocation profile.
881             break;
882         }
883         case op_new_array_with_size: {
884             int dst = (++it)->u.operand;
885             int length = (++it)->u.operand;
886             printLocationAndOp(out, exec, location, it, "new_array_with_size");
887             out.printf("%s, %s", registerName(dst).data(), registerName(length).data());
888             ++it; // Skip array allocation profile.
889             break;
890         }
891         case op_new_array_buffer: {
892             int dst = (++it)->u.operand;
893             int argv = (++it)->u.operand;
894             int argc = (++it)->u.operand;
895             printLocationAndOp(out, exec, location, it, "new_array_buffer");
896             out.printf("%s, %d, %d", registerName(dst).data(), argv, argc);
897             ++it; // Skip array allocation profile.
898             break;
899         }
900         case op_new_regexp: {
901             int r0 = (++it)->u.operand;
902             int re0 = (++it)->u.operand;
903             printLocationAndOp(out, exec, location, it, "new_regexp");
904             out.printf("%s, ", registerName(r0).data());
905             if (r0 >=0 && r0 < (int)m_unlinkedCode->numberOfRegExps())
906                 out.printf("%s", regexpName(re0, regexp(re0)).data());
907             else
908                 out.printf("bad_regexp(%d)", re0);
909             break;
910         }
911         case op_mov: {
912             int r0 = (++it)->u.operand;
913             int r1 = (++it)->u.operand;
914             printLocationAndOp(out, exec, location, it, "mov");
915             out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
916             break;
917         }
918         case op_profile_type: {
919             int r0 = (++it)->u.operand;
920             ++it;
921             ++it;
922             ++it;
923             ++it;
924             printLocationAndOp(out, exec, location, it, "op_profile_type");
925             out.printf("%s", registerName(r0).data());
926             break;
927         }
928         case op_profile_control_flow: {
929             BasicBlockLocation* basicBlockLocation = (++it)->u.basicBlockLocation;
930             printLocationAndOp(out, exec, location, it, "profile_control_flow");
931             out.printf("[%d, %d]", basicBlockLocation->startOffset(), basicBlockLocation->endOffset());
932             break;
933         }
934         case op_not: {
935             printUnaryOp(out, exec, location, it, "not");
936             break;
937         }
938         case op_eq: {
939             printBinaryOp(out, exec, location, it, "eq");
940             break;
941         }
942         case op_eq_null: {
943             printUnaryOp(out, exec, location, it, "eq_null");
944             break;
945         }
946         case op_neq: {
947             printBinaryOp(out, exec, location, it, "neq");
948             break;
949         }
950         case op_neq_null: {
951             printUnaryOp(out, exec, location, it, "neq_null");
952             break;
953         }
954         case op_stricteq: {
955             printBinaryOp(out, exec, location, it, "stricteq");
956             break;
957         }
958         case op_nstricteq: {
959             printBinaryOp(out, exec, location, it, "nstricteq");
960             break;
961         }
962         case op_less: {
963             printBinaryOp(out, exec, location, it, "less");
964             break;
965         }
966         case op_lesseq: {
967             printBinaryOp(out, exec, location, it, "lesseq");
968             break;
969         }
970         case op_greater: {
971             printBinaryOp(out, exec, location, it, "greater");
972             break;
973         }
974         case op_greatereq: {
975             printBinaryOp(out, exec, location, it, "greatereq");
976             break;
977         }
978         case op_inc: {
979             int r0 = (++it)->u.operand;
980             printLocationOpAndRegisterOperand(out, exec, location, it, "inc", r0);
981             break;
982         }
983         case op_dec: {
984             int r0 = (++it)->u.operand;
985             printLocationOpAndRegisterOperand(out, exec, location, it, "dec", r0);
986             break;
987         }
988         case op_to_number: {
989             printUnaryOp(out, exec, location, it, "to_number");
990             break;
991         }
992         case op_to_string: {
993             printUnaryOp(out, exec, location, it, "to_string");
994             break;
995         }
996         case op_negate: {
997             printUnaryOp(out, exec, location, it, "negate");
998             break;
999         }
1000         case op_add: {
1001             printBinaryOp(out, exec, location, it, "add");
1002             ++it;
1003             break;
1004         }
1005         case op_mul: {
1006             printBinaryOp(out, exec, location, it, "mul");
1007             ++it;
1008             break;
1009         }
1010         case op_div: {
1011             printBinaryOp(out, exec, location, it, "div");
1012             ++it;
1013             break;
1014         }
1015         case op_mod: {
1016             printBinaryOp(out, exec, location, it, "mod");
1017             break;
1018         }
1019         case op_sub: {
1020             printBinaryOp(out, exec, location, it, "sub");
1021             ++it;
1022             break;
1023         }
1024         case op_lshift: {
1025             printBinaryOp(out, exec, location, it, "lshift");
1026             break;            
1027         }
1028         case op_rshift: {
1029             printBinaryOp(out, exec, location, it, "rshift");
1030             break;
1031         }
1032         case op_urshift: {
1033             printBinaryOp(out, exec, location, it, "urshift");
1034             break;
1035         }
1036         case op_bitand: {
1037             printBinaryOp(out, exec, location, it, "bitand");
1038             ++it;
1039             break;
1040         }
1041         case op_bitxor: {
1042             printBinaryOp(out, exec, location, it, "bitxor");
1043             ++it;
1044             break;
1045         }
1046         case op_bitor: {
1047             printBinaryOp(out, exec, location, it, "bitor");
1048             ++it;
1049             break;
1050         }
1051         case op_overrides_has_instance: {
1052             int r0 = (++it)->u.operand;
1053             int r1 = (++it)->u.operand;
1054             int r2 = (++it)->u.operand;
1055             printLocationAndOp(out, exec, location, it, "overrides_has_instance");
1056             out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
1057             break;
1058         }
1059         case op_instanceof: {
1060             int r0 = (++it)->u.operand;
1061             int r1 = (++it)->u.operand;
1062             int r2 = (++it)->u.operand;
1063             printLocationAndOp(out, exec, location, it, "instanceof");
1064             out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
1065             break;
1066         }
1067         case op_instanceof_custom: {
1068             int r0 = (++it)->u.operand;
1069             int r1 = (++it)->u.operand;
1070             int r2 = (++it)->u.operand;
1071             int r3 = (++it)->u.operand;
1072             printLocationAndOp(out, exec, location, it, "instanceof_custom");
1073             out.printf("%s, %s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data(), registerName(r3).data());
1074             break;
1075         }
1076         case op_unsigned: {
1077             printUnaryOp(out, exec, location, it, "unsigned");
1078             break;
1079         }
1080         case op_typeof: {
1081             printUnaryOp(out, exec, location, it, "typeof");
1082             break;
1083         }
1084         case op_is_empty: {
1085             printUnaryOp(out, exec, location, it, "is_empty");
1086             break;
1087         }
1088         case op_is_undefined: {
1089             printUnaryOp(out, exec, location, it, "is_undefined");
1090             break;
1091         }
1092         case op_is_boolean: {
1093             printUnaryOp(out, exec, location, it, "is_boolean");
1094             break;
1095         }
1096         case op_is_number: {
1097             printUnaryOp(out, exec, location, it, "is_number");
1098             break;
1099         }
1100         case op_is_string: {
1101             printUnaryOp(out, exec, location, it, "is_string");
1102             break;
1103         }
1104         case op_is_object: {
1105             printUnaryOp(out, exec, location, it, "is_object");
1106             break;
1107         }
1108         case op_is_object_or_null: {
1109             printUnaryOp(out, exec, location, it, "is_object_or_null");
1110             break;
1111         }
1112         case op_is_function: {
1113             printUnaryOp(out, exec, location, it, "is_function");
1114             break;
1115         }
1116         case op_in: {
1117             printBinaryOp(out, exec, location, it, "in");
1118             break;
1119         }
1120         case op_try_get_by_id: {
1121             int r0 = (++it)->u.operand;
1122             int r1 = (++it)->u.operand;
1123             int id0 = (++it)->u.operand;
1124             printLocationAndOp(out, exec, location, it, "try_get_by_id");
1125             out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), idName(id0, identifier(id0)).data());
1126             break;
1127         }
1128         case op_get_by_id:
1129         case op_get_by_id_proto_load:
1130         case op_get_by_id_unset:
1131         case op_get_array_length: {
1132             printGetByIdOp(out, exec, location, it);
1133             printGetByIdCacheStatus(out, exec, location, stubInfos);
1134             dumpValueProfiling(out, it, hasPrintedProfiling);
1135             break;
1136         }
1137         case op_get_by_id_with_this: {
1138             printLocationAndOp(out, exec, location, it, "get_by_id_with_this");
1139             int r0 = (++it)->u.operand;
1140             int r1 = (++it)->u.operand;
1141             int r2 = (++it)->u.operand;
1142             int id0 = (++it)->u.operand;
1143             out.printf("%s, %s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data(), idName(id0, identifier(id0)).data());
1144             break;
1145         }
1146         case op_get_by_val_with_this: {
1147             int r0 = (++it)->u.operand;
1148             int r1 = (++it)->u.operand;
1149             int r2 = (++it)->u.operand;
1150             int r3 = (++it)->u.operand;
1151             printLocationAndOp(out, exec, location, it, "get_by_val_with_this");
1152             out.printf("%s, %s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data(), registerName(r3).data());
1153             break;
1154         }
1155         case op_put_by_id: {
1156             printPutByIdOp(out, exec, location, it, "put_by_id");
1157             printPutByIdCacheStatus(out, location, stubInfos);
1158             break;
1159         }
1160         case op_put_by_id_with_this: {
1161             int r0 = (++it)->u.operand;
1162             int r1 = (++it)->u.operand;
1163             int id0 = (++it)->u.operand;
1164             int r2 = (++it)->u.operand;
1165             printLocationAndOp(out, exec, location, it, "put_by_id_with_this");
1166             out.printf("%s, %s, %s, %s", registerName(r0).data(), registerName(r1).data(), idName(id0, identifier(id0)).data(), registerName(r2).data());
1167             break;
1168         }
1169         case op_put_by_val_with_this: {
1170             int r0 = (++it)->u.operand;
1171             int r1 = (++it)->u.operand;
1172             int r2 = (++it)->u.operand;
1173             int r3 = (++it)->u.operand;
1174             printLocationAndOp(out, exec, location, it, "put_by_val_with_this");
1175             out.printf("%s, %s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data(), registerName(r3).data());
1176             break;
1177         }
1178         case op_put_getter_by_id: {
1179             int r0 = (++it)->u.operand;
1180             int id0 = (++it)->u.operand;
1181             int n0 = (++it)->u.operand;
1182             int r1 = (++it)->u.operand;
1183             printLocationAndOp(out, exec, location, it, "put_getter_by_id");
1184             out.printf("%s, %s, %d, %s", registerName(r0).data(), idName(id0, identifier(id0)).data(), n0, registerName(r1).data());
1185             break;
1186         }
1187         case op_put_setter_by_id: {
1188             int r0 = (++it)->u.operand;
1189             int id0 = (++it)->u.operand;
1190             int n0 = (++it)->u.operand;
1191             int r1 = (++it)->u.operand;
1192             printLocationAndOp(out, exec, location, it, "put_setter_by_id");
1193             out.printf("%s, %s, %d, %s", registerName(r0).data(), idName(id0, identifier(id0)).data(), n0, registerName(r1).data());
1194             break;
1195         }
1196         case op_put_getter_setter_by_id: {
1197             int r0 = (++it)->u.operand;
1198             int id0 = (++it)->u.operand;
1199             int n0 = (++it)->u.operand;
1200             int r1 = (++it)->u.operand;
1201             int r2 = (++it)->u.operand;
1202             printLocationAndOp(out, exec, location, it, "put_getter_setter_by_id");
1203             out.printf("%s, %s, %d, %s, %s", registerName(r0).data(), idName(id0, identifier(id0)).data(), n0, registerName(r1).data(), registerName(r2).data());
1204             break;
1205         }
1206         case op_put_getter_by_val: {
1207             int r0 = (++it)->u.operand;
1208             int r1 = (++it)->u.operand;
1209             int n0 = (++it)->u.operand;
1210             int r2 = (++it)->u.operand;
1211             printLocationAndOp(out, exec, location, it, "put_getter_by_val");
1212             out.printf("%s, %s, %d, %s", registerName(r0).data(), registerName(r1).data(), n0, registerName(r2).data());
1213             break;
1214         }
1215         case op_put_setter_by_val: {
1216             int r0 = (++it)->u.operand;
1217             int r1 = (++it)->u.operand;
1218             int n0 = (++it)->u.operand;
1219             int r2 = (++it)->u.operand;
1220             printLocationAndOp(out, exec, location, it, "put_setter_by_val");
1221             out.printf("%s, %s, %d, %s", registerName(r0).data(), registerName(r1).data(), n0, registerName(r2).data());
1222             break;
1223         }
1224         case op_del_by_id: {
1225             int r0 = (++it)->u.operand;
1226             int r1 = (++it)->u.operand;
1227             int id0 = (++it)->u.operand;
1228             printLocationAndOp(out, exec, location, it, "del_by_id");
1229             out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), idName(id0, identifier(id0)).data());
1230             break;
1231         }
1232         case op_get_by_val: {
1233             int r0 = (++it)->u.operand;
1234             int r1 = (++it)->u.operand;
1235             int r2 = (++it)->u.operand;
1236             printLocationAndOp(out, exec, location, it, "get_by_val");
1237             out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
1238             dumpArrayProfiling(out, it, hasPrintedProfiling);
1239             dumpValueProfiling(out, it, hasPrintedProfiling);
1240             break;
1241         }
1242         case op_put_by_val: {
1243             int r0 = (++it)->u.operand;
1244             int r1 = (++it)->u.operand;
1245             int r2 = (++it)->u.operand;
1246             printLocationAndOp(out, exec, location, it, "put_by_val");
1247             out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
1248             dumpArrayProfiling(out, it, hasPrintedProfiling);
1249             break;
1250         }
1251         case op_put_by_val_direct: {
1252             int r0 = (++it)->u.operand;
1253             int r1 = (++it)->u.operand;
1254             int r2 = (++it)->u.operand;
1255             printLocationAndOp(out, exec, location, it, "put_by_val_direct");
1256             out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
1257             dumpArrayProfiling(out, it, hasPrintedProfiling);
1258             break;
1259         }
1260         case op_del_by_val: {
1261             int r0 = (++it)->u.operand;
1262             int r1 = (++it)->u.operand;
1263             int r2 = (++it)->u.operand;
1264             printLocationAndOp(out, exec, location, it, "del_by_val");
1265             out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
1266             break;
1267         }
1268         case op_put_by_index: {
1269             int r0 = (++it)->u.operand;
1270             unsigned n0 = (++it)->u.operand;
1271             int r1 = (++it)->u.operand;
1272             printLocationAndOp(out, exec, location, it, "put_by_index");
1273             out.printf("%s, %u, %s", registerName(r0).data(), n0, registerName(r1).data());
1274             break;
1275         }
1276         case op_jmp: {
1277             int offset = (++it)->u.operand;
1278             printLocationAndOp(out, exec, location, it, "jmp");
1279             out.printf("%d(->%d)", offset, location + offset);
1280             break;
1281         }
1282         case op_jtrue: {
1283             printConditionalJump(out, exec, begin, it, location, "jtrue");
1284             break;
1285         }
1286         case op_jfalse: {
1287             printConditionalJump(out, exec, begin, it, location, "jfalse");
1288             break;
1289         }
1290         case op_jeq_null: {
1291             printConditionalJump(out, exec, begin, it, location, "jeq_null");
1292             break;
1293         }
1294         case op_jneq_null: {
1295             printConditionalJump(out, exec, begin, it, location, "jneq_null");
1296             break;
1297         }
1298         case op_jneq_ptr: {
1299             int r0 = (++it)->u.operand;
1300             Special::Pointer pointer = (++it)->u.specialPointer;
1301             int offset = (++it)->u.operand;
1302             printLocationAndOp(out, exec, location, it, "jneq_ptr");
1303             out.printf("%s, %d (%p), %d(->%d)", registerName(r0).data(), pointer, m_globalObject->actualPointerFor(pointer), offset, location + offset);
1304             break;
1305         }
1306         case op_jless: {
1307             int r0 = (++it)->u.operand;
1308             int r1 = (++it)->u.operand;
1309             int offset = (++it)->u.operand;
1310             printLocationAndOp(out, exec, location, it, "jless");
1311             out.printf("%s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), offset, location + offset);
1312             break;
1313         }
1314         case op_jlesseq: {
1315             int r0 = (++it)->u.operand;
1316             int r1 = (++it)->u.operand;
1317             int offset = (++it)->u.operand;
1318             printLocationAndOp(out, exec, location, it, "jlesseq");
1319             out.printf("%s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), offset, location + offset);
1320             break;
1321         }
1322         case op_jgreater: {
1323             int r0 = (++it)->u.operand;
1324             int r1 = (++it)->u.operand;
1325             int offset = (++it)->u.operand;
1326             printLocationAndOp(out, exec, location, it, "jgreater");
1327             out.printf("%s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), offset, location + offset);
1328             break;
1329         }
1330         case op_jgreatereq: {
1331             int r0 = (++it)->u.operand;
1332             int r1 = (++it)->u.operand;
1333             int offset = (++it)->u.operand;
1334             printLocationAndOp(out, exec, location, it, "jgreatereq");
1335             out.printf("%s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), offset, location + offset);
1336             break;
1337         }
1338         case op_jnless: {
1339             int r0 = (++it)->u.operand;
1340             int r1 = (++it)->u.operand;
1341             int offset = (++it)->u.operand;
1342             printLocationAndOp(out, exec, location, it, "jnless");
1343             out.printf("%s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), offset, location + offset);
1344             break;
1345         }
1346         case op_jnlesseq: {
1347             int r0 = (++it)->u.operand;
1348             int r1 = (++it)->u.operand;
1349             int offset = (++it)->u.operand;
1350             printLocationAndOp(out, exec, location, it, "jnlesseq");
1351             out.printf("%s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), offset, location + offset);
1352             break;
1353         }
1354         case op_jngreater: {
1355             int r0 = (++it)->u.operand;
1356             int r1 = (++it)->u.operand;
1357             int offset = (++it)->u.operand;
1358             printLocationAndOp(out, exec, location, it, "jngreater");
1359             out.printf("%s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), offset, location + offset);
1360             break;
1361         }
1362         case op_jngreatereq: {
1363             int r0 = (++it)->u.operand;
1364             int r1 = (++it)->u.operand;
1365             int offset = (++it)->u.operand;
1366             printLocationAndOp(out, exec, location, it, "jngreatereq");
1367             out.printf("%s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), offset, location + offset);
1368             break;
1369         }
1370         case op_loop_hint: {
1371             printLocationAndOp(out, exec, location, it, "loop_hint");
1372             break;
1373         }
1374         case op_watchdog: {
1375             printLocationAndOp(out, exec, location, it, "watchdog");
1376             break;
1377         }
1378         case op_log_shadow_chicken_prologue: {
1379             int r0 = (++it)->u.operand;
1380             printLocationAndOp(out, exec, location, it, "log_shadow_chicken_prologue");
1381             out.printf("%s", registerName(r0).data());
1382             break;
1383         }
1384         case op_log_shadow_chicken_tail: {
1385             int r0 = (++it)->u.operand;
1386             int r1 = (++it)->u.operand;
1387             printLocationAndOp(out, exec, location, it, "log_shadow_chicken_tail");
1388             out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
1389             break;
1390         }
1391         case op_switch_imm: {
1392             int tableIndex = (++it)->u.operand;
1393             int defaultTarget = (++it)->u.operand;
1394             int scrutineeRegister = (++it)->u.operand;
1395             printLocationAndOp(out, exec, location, it, "switch_imm");
1396             out.printf("%d, %d(->%d), %s", tableIndex, defaultTarget, location + defaultTarget, registerName(scrutineeRegister).data());
1397             break;
1398         }
1399         case op_switch_char: {
1400             int tableIndex = (++it)->u.operand;
1401             int defaultTarget = (++it)->u.operand;
1402             int scrutineeRegister = (++it)->u.operand;
1403             printLocationAndOp(out, exec, location, it, "switch_char");
1404             out.printf("%d, %d(->%d), %s", tableIndex, defaultTarget, location + defaultTarget, registerName(scrutineeRegister).data());
1405             break;
1406         }
1407         case op_switch_string: {
1408             int tableIndex = (++it)->u.operand;
1409             int defaultTarget = (++it)->u.operand;
1410             int scrutineeRegister = (++it)->u.operand;
1411             printLocationAndOp(out, exec, location, it, "switch_string");
1412             out.printf("%d, %d(->%d), %s", tableIndex, defaultTarget, location + defaultTarget, registerName(scrutineeRegister).data());
1413             break;
1414         }
1415         case op_new_func: {
1416             int r0 = (++it)->u.operand;
1417             int r1 = (++it)->u.operand;
1418             int f0 = (++it)->u.operand;
1419             printLocationAndOp(out, exec, location, it, "new_func");
1420             out.printf("%s, %s, f%d", registerName(r0).data(), registerName(r1).data(), f0);
1421             break;
1422         }
1423         case op_new_generator_func: {
1424             int r0 = (++it)->u.operand;
1425             int r1 = (++it)->u.operand;
1426             int f0 = (++it)->u.operand;
1427             printLocationAndOp(out, exec, location, it, "new_generator_func");
1428             out.printf("%s, %s, f%d", registerName(r0).data(), registerName(r1).data(), f0);
1429             break;
1430         }
1431         case op_new_func_exp: {
1432             int r0 = (++it)->u.operand;
1433             int r1 = (++it)->u.operand;
1434             int f0 = (++it)->u.operand;
1435             printLocationAndOp(out, exec, location, it, "new_func_exp");
1436             out.printf("%s, %s, f%d", registerName(r0).data(), registerName(r1).data(), f0);
1437             break;
1438         }
1439         case op_new_generator_func_exp: {
1440             int r0 = (++it)->u.operand;
1441             int r1 = (++it)->u.operand;
1442             int f0 = (++it)->u.operand;
1443             printLocationAndOp(out, exec, location, it, "new_generator_func_exp");
1444             out.printf("%s, %s, f%d", registerName(r0).data(), registerName(r1).data(), f0);
1445             break;
1446         }
1447         case op_set_function_name: {
1448             int funcReg = (++it)->u.operand;
1449             int nameReg = (++it)->u.operand;
1450             printLocationAndOp(out, exec, location, it, "set_function_name");
1451             out.printf("%s, %s", registerName(funcReg).data(), registerName(nameReg).data());
1452             break;
1453         }
1454         case op_call: {
1455             printCallOp(out, exec, location, it, "call", DumpCaches, hasPrintedProfiling, callLinkInfos);
1456             break;
1457         }
1458         case op_tail_call: {
1459             printCallOp(out, exec, location, it, "tail_call", DumpCaches, hasPrintedProfiling, callLinkInfos);
1460             break;
1461         }
1462         case op_call_eval: {
1463             printCallOp(out, exec, location, it, "call_eval", DontDumpCaches, hasPrintedProfiling, callLinkInfos);
1464             break;
1465         }
1466             
1467         case op_construct_varargs:
1468         case op_call_varargs:
1469         case op_tail_call_varargs: {
1470             int result = (++it)->u.operand;
1471             int callee = (++it)->u.operand;
1472             int thisValue = (++it)->u.operand;
1473             int arguments = (++it)->u.operand;
1474             int firstFreeRegister = (++it)->u.operand;
1475             int varArgOffset = (++it)->u.operand;
1476             ++it;
1477             printLocationAndOp(out, exec, location, it, opcode == op_call_varargs ? "call_varargs" : opcode == op_construct_varargs ? "construct_varargs" : "tail_call_varargs");
1478             out.printf("%s, %s, %s, %s, %d, %d", registerName(result).data(), registerName(callee).data(), registerName(thisValue).data(), registerName(arguments).data(), firstFreeRegister, varArgOffset);
1479             dumpValueProfiling(out, it, hasPrintedProfiling);
1480             break;
1481         }
1482
1483         case op_ret: {
1484             int r0 = (++it)->u.operand;
1485             printLocationOpAndRegisterOperand(out, exec, location, it, "ret", r0);
1486             break;
1487         }
1488         case op_construct: {
1489             printCallOp(out, exec, location, it, "construct", DumpCaches, hasPrintedProfiling, callLinkInfos);
1490             break;
1491         }
1492         case op_strcat: {
1493             int r0 = (++it)->u.operand;
1494             int r1 = (++it)->u.operand;
1495             int count = (++it)->u.operand;
1496             printLocationAndOp(out, exec, location, it, "strcat");
1497             out.printf("%s, %s, %d", registerName(r0).data(), registerName(r1).data(), count);
1498             break;
1499         }
1500         case op_to_primitive: {
1501             int r0 = (++it)->u.operand;
1502             int r1 = (++it)->u.operand;
1503             printLocationAndOp(out, exec, location, it, "to_primitive");
1504             out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
1505             break;
1506         }
1507         case op_get_enumerable_length: {
1508             int dst = it[1].u.operand;
1509             int base = it[2].u.operand;
1510             printLocationAndOp(out, exec, location, it, "op_get_enumerable_length");
1511             out.printf("%s, %s", registerName(dst).data(), registerName(base).data());
1512             it += OPCODE_LENGTH(op_get_enumerable_length) - 1;
1513             break;
1514         }
1515         case op_has_indexed_property: {
1516             int dst = it[1].u.operand;
1517             int base = it[2].u.operand;
1518             int propertyName = it[3].u.operand;
1519             ArrayProfile* arrayProfile = it[4].u.arrayProfile;
1520             printLocationAndOp(out, exec, location, it, "op_has_indexed_property");
1521             out.printf("%s, %s, %s, %p", registerName(dst).data(), registerName(base).data(), registerName(propertyName).data(), arrayProfile);
1522             it += OPCODE_LENGTH(op_has_indexed_property) - 1;
1523             break;
1524         }
1525         case op_has_structure_property: {
1526             int dst = it[1].u.operand;
1527             int base = it[2].u.operand;
1528             int propertyName = it[3].u.operand;
1529             int enumerator = it[4].u.operand;
1530             printLocationAndOp(out, exec, location, it, "op_has_structure_property");
1531             out.printf("%s, %s, %s, %s", registerName(dst).data(), registerName(base).data(), registerName(propertyName).data(), registerName(enumerator).data());
1532             it += OPCODE_LENGTH(op_has_structure_property) - 1;
1533             break;
1534         }
1535         case op_has_generic_property: {
1536             int dst = it[1].u.operand;
1537             int base = it[2].u.operand;
1538             int propertyName = it[3].u.operand;
1539             printLocationAndOp(out, exec, location, it, "op_has_generic_property");
1540             out.printf("%s, %s, %s", registerName(dst).data(), registerName(base).data(), registerName(propertyName).data());
1541             it += OPCODE_LENGTH(op_has_generic_property) - 1;
1542             break;
1543         }
1544         case op_get_direct_pname: {
1545             int dst = it[1].u.operand;
1546             int base = it[2].u.operand;
1547             int propertyName = it[3].u.operand;
1548             int index = it[4].u.operand;
1549             int enumerator = it[5].u.operand;
1550             ValueProfile* profile = it[6].u.profile;
1551             printLocationAndOp(out, exec, location, it, "op_get_direct_pname");
1552             out.printf("%s, %s, %s, %s, %s, %p", registerName(dst).data(), registerName(base).data(), registerName(propertyName).data(), registerName(index).data(), registerName(enumerator).data(), profile);
1553             it += OPCODE_LENGTH(op_get_direct_pname) - 1;
1554             break;
1555
1556         }
1557         case op_get_property_enumerator: {
1558             int dst = it[1].u.operand;
1559             int base = it[2].u.operand;
1560             printLocationAndOp(out, exec, location, it, "op_get_property_enumerator");
1561             out.printf("%s, %s", registerName(dst).data(), registerName(base).data());
1562             it += OPCODE_LENGTH(op_get_property_enumerator) - 1;
1563             break;
1564         }
1565         case op_enumerator_structure_pname: {
1566             int dst = it[1].u.operand;
1567             int enumerator = it[2].u.operand;
1568             int index = it[3].u.operand;
1569             printLocationAndOp(out, exec, location, it, "op_enumerator_structure_pname");
1570             out.printf("%s, %s, %s", registerName(dst).data(), registerName(enumerator).data(), registerName(index).data());
1571             it += OPCODE_LENGTH(op_enumerator_structure_pname) - 1;
1572             break;
1573         }
1574         case op_enumerator_generic_pname: {
1575             int dst = it[1].u.operand;
1576             int enumerator = it[2].u.operand;
1577             int index = it[3].u.operand;
1578             printLocationAndOp(out, exec, location, it, "op_enumerator_generic_pname");
1579             out.printf("%s, %s, %s", registerName(dst).data(), registerName(enumerator).data(), registerName(index).data());
1580             it += OPCODE_LENGTH(op_enumerator_generic_pname) - 1;
1581             break;
1582         }
1583         case op_to_index_string: {
1584             int dst = it[1].u.operand;
1585             int index = it[2].u.operand;
1586             printLocationAndOp(out, exec, location, it, "op_to_index_string");
1587             out.printf("%s, %s", registerName(dst).data(), registerName(index).data());
1588             it += OPCODE_LENGTH(op_to_index_string) - 1;
1589             break;
1590         }
1591         case op_push_with_scope: {
1592             int dst = (++it)->u.operand;
1593             int newScope = (++it)->u.operand;
1594             int currentScope = (++it)->u.operand;
1595             printLocationAndOp(out, exec, location, it, "push_with_scope");
1596             out.printf("%s, %s, %s", registerName(dst).data(), registerName(newScope).data(), registerName(currentScope).data());
1597             break;
1598         }
1599         case op_get_parent_scope: {
1600             int dst = (++it)->u.operand;
1601             int parentScope = (++it)->u.operand;
1602             printLocationAndOp(out, exec, location, it, "get_parent_scope");
1603             out.printf("%s, %s", registerName(dst).data(), registerName(parentScope).data());
1604             break;
1605         }
1606         case op_create_lexical_environment: {
1607             int dst = (++it)->u.operand;
1608             int scope = (++it)->u.operand;
1609             int symbolTable = (++it)->u.operand;
1610             int initialValue = (++it)->u.operand;
1611             printLocationAndOp(out, exec, location, it, "create_lexical_environment");
1612             out.printf("%s, %s, %s, %s", 
1613                 registerName(dst).data(), registerName(scope).data(), registerName(symbolTable).data(), registerName(initialValue).data());
1614             break;
1615         }
1616         case op_catch: {
1617             int r0 = (++it)->u.operand;
1618             int r1 = (++it)->u.operand;
1619             printLocationAndOp(out, exec, location, it, "catch");
1620             out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
1621             break;
1622         }
1623         case op_throw: {
1624             int r0 = (++it)->u.operand;
1625             printLocationOpAndRegisterOperand(out, exec, location, it, "throw", r0);
1626             break;
1627         }
1628         case op_throw_static_error: {
1629             int k0 = (++it)->u.operand;
1630             int k1 = (++it)->u.operand;
1631             printLocationAndOp(out, exec, location, it, "throw_static_error");
1632             out.printf("%s, %s", constantName(k0).data(), k1 ? "true" : "false");
1633             break;
1634         }
1635         case op_debug: {
1636             int debugHookID = (++it)->u.operand;
1637             int hasBreakpointFlag = (++it)->u.operand;
1638             printLocationAndOp(out, exec, location, it, "debug");
1639             out.printf("%s, %d", debugHookName(debugHookID), hasBreakpointFlag);
1640             break;
1641         }
1642         case op_save: {
1643             int generator = (++it)->u.operand;
1644             unsigned liveCalleeLocalsIndex = (++it)->u.unsignedValue;
1645             int offset = (++it)->u.operand;
1646             const FastBitVector& liveness = m_rareData->m_liveCalleeLocalsAtYield[liveCalleeLocalsIndex];
1647             printLocationAndOp(out, exec, location, it, "save");
1648             out.printf("%s, ", registerName(generator).data());
1649             liveness.dump(out);
1650             out.printf("(@live%1u), %d(->%d)", liveCalleeLocalsIndex, offset, location + offset);
1651             break;
1652         }
1653         case op_resume: {
1654             int generator = (++it)->u.operand;
1655             unsigned liveCalleeLocalsIndex = (++it)->u.unsignedValue;
1656             const FastBitVector& liveness = m_rareData->m_liveCalleeLocalsAtYield[liveCalleeLocalsIndex];
1657             printLocationAndOp(out, exec, location, it, "resume");
1658             out.printf("%s, ", registerName(generator).data());
1659             liveness.dump(out);
1660             out.printf("(@live%1u)", liveCalleeLocalsIndex);
1661             break;
1662         }
1663         case op_assert: {
1664             int condition = (++it)->u.operand;
1665             int line = (++it)->u.operand;
1666             printLocationAndOp(out, exec, location, it, "assert");
1667             out.printf("%s, %d", registerName(condition).data(), line);
1668             break;
1669         }
1670         case op_end: {
1671             int r0 = (++it)->u.operand;
1672             printLocationOpAndRegisterOperand(out, exec, location, it, "end", r0);
1673             break;
1674         }
1675         case op_resolve_scope: {
1676             int r0 = (++it)->u.operand;
1677             int scope = (++it)->u.operand;
1678             int id0 = (++it)->u.operand;
1679             ResolveType resolveType = static_cast<ResolveType>((++it)->u.operand);
1680             int depth = (++it)->u.operand;
1681             void* pointer = (++it)->u.pointer;
1682             printLocationAndOp(out, exec, location, it, "resolve_scope");
1683             out.printf("%s, %s, %s, <%s>, %d, %p", registerName(r0).data(), registerName(scope).data(), idName(id0, identifier(id0)).data(), resolveTypeName(resolveType), depth, pointer);
1684             break;
1685         }
1686         case op_get_from_scope: {
1687             int r0 = (++it)->u.operand;
1688             int r1 = (++it)->u.operand;
1689             int id0 = (++it)->u.operand;
1690             GetPutInfo getPutInfo = GetPutInfo((++it)->u.operand);
1691             ++it; // Structure
1692             int operand = (++it)->u.operand; // Operand
1693             printLocationAndOp(out, exec, location, it, "get_from_scope");
1694             out.print(registerName(r0), ", ", registerName(r1));
1695             if (static_cast<unsigned>(id0) == UINT_MAX)
1696                 out.print(", anonymous");
1697             else
1698                 out.print(", ", idName(id0, identifier(id0)));
1699             out.print(", ", getPutInfo.operand(), "<", resolveModeName(getPutInfo.resolveMode()), "|", resolveTypeName(getPutInfo.resolveType()), "|", initializationModeName(getPutInfo.initializationMode()), ">, ", operand);
1700             dumpValueProfiling(out, it, hasPrintedProfiling);
1701             break;
1702         }
1703         case op_put_to_scope: {
1704             int r0 = (++it)->u.operand;
1705             int id0 = (++it)->u.operand;
1706             int r1 = (++it)->u.operand;
1707             GetPutInfo getPutInfo = GetPutInfo((++it)->u.operand);
1708             ++it; // Structure
1709             int operand = (++it)->u.operand; // Operand
1710             printLocationAndOp(out, exec, location, it, "put_to_scope");
1711             out.print(registerName(r0));
1712             if (static_cast<unsigned>(id0) == UINT_MAX)
1713                 out.print(", anonymous");
1714             else
1715                 out.print(", ", idName(id0, identifier(id0)));
1716             out.print(", ", registerName(r1), ", ", getPutInfo.operand(), "<", resolveModeName(getPutInfo.resolveMode()), "|", resolveTypeName(getPutInfo.resolveType()), "|", initializationModeName(getPutInfo.initializationMode()), ">, <structure>, ", operand);
1717             break;
1718         }
1719         case op_get_from_arguments: {
1720             int r0 = (++it)->u.operand;
1721             int r1 = (++it)->u.operand;
1722             int offset = (++it)->u.operand;
1723             printLocationAndOp(out, exec, location, it, "get_from_arguments");
1724             out.printf("%s, %s, %d", registerName(r0).data(), registerName(r1).data(), offset);
1725             dumpValueProfiling(out, it, hasPrintedProfiling);
1726             break;
1727         }
1728         case op_put_to_arguments: {
1729             int r0 = (++it)->u.operand;
1730             int offset = (++it)->u.operand;
1731             int r1 = (++it)->u.operand;
1732             printLocationAndOp(out, exec, location, it, "put_to_arguments");
1733             out.printf("%s, %d, %s", registerName(r0).data(), offset, registerName(r1).data());
1734             break;
1735         }
1736         default:
1737             RELEASE_ASSERT_NOT_REACHED();
1738     }
1739
1740     dumpRareCaseProfile(out, "rare case: ", rareCaseProfileForBytecodeOffset(location), hasPrintedProfiling);
1741     dumpResultProfile(out, resultProfileForBytecodeOffset(location), hasPrintedProfiling);
1742     
1743 #if ENABLE(DFG_JIT)
1744     Vector<DFG::FrequentExitSite> exitSites = exitProfile().exitSitesFor(location);
1745     if (!exitSites.isEmpty()) {
1746         out.print(" !! frequent exits: ");
1747         CommaPrinter comma;
1748         for (unsigned i = 0; i < exitSites.size(); ++i)
1749             out.print(comma, exitSites[i].kind(), " ", exitSites[i].jitType());
1750     }
1751 #else // ENABLE(DFG_JIT)
1752     UNUSED_PARAM(location);
1753 #endif // ENABLE(DFG_JIT)
1754     out.print("\n");
1755 }
1756
1757 void CodeBlock::dumpBytecode(
1758     PrintStream& out, unsigned bytecodeOffset,
1759     const StubInfoMap& stubInfos, const CallLinkInfoMap& callLinkInfos)
1760 {
1761     ExecState* exec = m_globalObject->globalExec();
1762     const Instruction* it = instructions().begin() + bytecodeOffset;
1763     dumpBytecode(out, exec, instructions().begin(), it, stubInfos, callLinkInfos);
1764 }
1765
1766 #define FOR_EACH_MEMBER_VECTOR(macro) \
1767     macro(instructions) \
1768     macro(callLinkInfos) \
1769     macro(linkedCallerList) \
1770     macro(identifiers) \
1771     macro(functionExpressions) \
1772     macro(constantRegisters)
1773
1774 #define FOR_EACH_MEMBER_VECTOR_RARE_DATA(macro) \
1775     macro(regexps) \
1776     macro(functions) \
1777     macro(exceptionHandlers) \
1778     macro(switchJumpTables) \
1779     macro(stringSwitchJumpTables) \
1780     macro(evalCodeCache) \
1781     macro(expressionInfo) \
1782     macro(lineInfo) \
1783     macro(callReturnIndexVector)
1784
1785 template<typename T>
1786 static size_t sizeInBytes(const Vector<T>& vector)
1787 {
1788     return vector.capacity() * sizeof(T);
1789 }
1790
1791 namespace {
1792
1793 class PutToScopeFireDetail : public FireDetail {
1794 public:
1795     PutToScopeFireDetail(CodeBlock* codeBlock, const Identifier& ident)
1796         : m_codeBlock(codeBlock)
1797         , m_ident(ident)
1798     {
1799     }
1800     
1801     void dump(PrintStream& out) const override
1802     {
1803         out.print("Linking put_to_scope in ", FunctionExecutableDump(jsCast<FunctionExecutable*>(m_codeBlock->ownerExecutable())), " for ", m_ident);
1804     }
1805     
1806 private:
1807     CodeBlock* m_codeBlock;
1808     const Identifier& m_ident;
1809 };
1810
1811 } // anonymous namespace
1812
1813 CodeBlock::CodeBlock(VM* vm, Structure* structure, CopyParsedBlockTag, CodeBlock& other)
1814     : JSCell(*vm, structure)
1815     , m_globalObject(other.m_globalObject)
1816     , m_numCalleeLocals(other.m_numCalleeLocals)
1817     , m_numVars(other.m_numVars)
1818     , m_shouldAlwaysBeInlined(true)
1819 #if ENABLE(JIT)
1820     , m_capabilityLevelState(DFG::CapabilityLevelNotSet)
1821 #endif
1822     , m_didFailFTLCompilation(false)
1823     , m_hasBeenCompiledWithFTL(false)
1824     , m_isConstructor(other.m_isConstructor)
1825     , m_isStrictMode(other.m_isStrictMode)
1826     , m_codeType(other.m_codeType)
1827     , m_unlinkedCode(*other.m_vm, this, other.m_unlinkedCode.get())
1828     , m_hasDebuggerStatement(false)
1829     , m_steppingMode(SteppingModeDisabled)
1830     , m_numBreakpoints(0)
1831     , m_ownerExecutable(*other.m_vm, this, other.m_ownerExecutable.get())
1832     , m_vm(other.m_vm)
1833     , m_instructions(other.m_instructions)
1834     , m_thisRegister(other.m_thisRegister)
1835     , m_scopeRegister(other.m_scopeRegister)
1836     , m_hash(other.m_hash)
1837     , m_source(other.m_source)
1838     , m_sourceOffset(other.m_sourceOffset)
1839     , m_firstLineColumnOffset(other.m_firstLineColumnOffset)
1840     , m_constantRegisters(other.m_constantRegisters)
1841     , m_constantsSourceCodeRepresentation(other.m_constantsSourceCodeRepresentation)
1842     , m_functionDecls(other.m_functionDecls)
1843     , m_functionExprs(other.m_functionExprs)
1844     , m_osrExitCounter(0)
1845     , m_optimizationDelayCounter(0)
1846     , m_reoptimizationRetryCounter(0)
1847     , m_creationTime(std::chrono::steady_clock::now())
1848 {
1849     m_visitWeaklyHasBeenCalled.store(false, std::memory_order_relaxed);
1850
1851     ASSERT(heap()->isDeferred());
1852     ASSERT(m_scopeRegister.isLocal());
1853
1854     setNumParameters(other.numParameters());
1855 }
1856
1857 void CodeBlock::finishCreation(VM& vm, CopyParsedBlockTag, CodeBlock& other)
1858 {
1859     Base::finishCreation(vm);
1860
1861     optimizeAfterWarmUp();
1862     jitAfterWarmUp();
1863
1864     if (other.m_rareData) {
1865         createRareDataIfNecessary();
1866         
1867         m_rareData->m_exceptionHandlers = other.m_rareData->m_exceptionHandlers;
1868         m_rareData->m_constantBuffers = other.m_rareData->m_constantBuffers;
1869         m_rareData->m_switchJumpTables = other.m_rareData->m_switchJumpTables;
1870         m_rareData->m_stringSwitchJumpTables = other.m_rareData->m_stringSwitchJumpTables;
1871         m_rareData->m_liveCalleeLocalsAtYield = other.m_rareData->m_liveCalleeLocalsAtYield;
1872     }
1873     
1874     heap()->m_codeBlocks.add(this);
1875 }
1876
1877 CodeBlock::CodeBlock(VM* vm, Structure* structure, ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock,
1878     JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
1879     : JSCell(*vm, structure)
1880     , m_globalObject(scope->globalObject()->vm(), this, scope->globalObject())
1881     , m_numCalleeLocals(unlinkedCodeBlock->m_numCalleeLocals)
1882     , m_numVars(unlinkedCodeBlock->m_numVars)
1883     , m_shouldAlwaysBeInlined(true)
1884 #if ENABLE(JIT)
1885     , m_capabilityLevelState(DFG::CapabilityLevelNotSet)
1886 #endif
1887     , m_didFailFTLCompilation(false)
1888     , m_hasBeenCompiledWithFTL(false)
1889     , m_isConstructor(unlinkedCodeBlock->isConstructor())
1890     , m_isStrictMode(unlinkedCodeBlock->isStrictMode())
1891     , m_codeType(unlinkedCodeBlock->codeType())
1892     , m_unlinkedCode(m_globalObject->vm(), this, unlinkedCodeBlock)
1893     , m_hasDebuggerStatement(false)
1894     , m_steppingMode(SteppingModeDisabled)
1895     , m_numBreakpoints(0)
1896     , m_ownerExecutable(m_globalObject->vm(), this, ownerExecutable)
1897     , m_vm(unlinkedCodeBlock->vm())
1898     , m_thisRegister(unlinkedCodeBlock->thisRegister())
1899     , m_scopeRegister(unlinkedCodeBlock->scopeRegister())
1900     , m_source(sourceProvider)
1901     , m_sourceOffset(sourceOffset)
1902     , m_firstLineColumnOffset(firstLineColumnOffset)
1903     , m_osrExitCounter(0)
1904     , m_optimizationDelayCounter(0)
1905     , m_reoptimizationRetryCounter(0)
1906     , m_creationTime(std::chrono::steady_clock::now())
1907 {
1908     m_visitWeaklyHasBeenCalled.store(false, std::memory_order_relaxed);
1909
1910     ASSERT(heap()->isDeferred());
1911     ASSERT(m_scopeRegister.isLocal());
1912
1913     ASSERT(m_source);
1914     setNumParameters(unlinkedCodeBlock->numParameters());
1915 }
1916
1917 void CodeBlock::finishCreation(VM& vm, ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock,
1918     JSScope* scope)
1919 {
1920     Base::finishCreation(vm);
1921
1922     if (vm.typeProfiler() || vm.controlFlowProfiler())
1923         vm.functionHasExecutedCache()->removeUnexecutedRange(ownerExecutable->sourceID(), ownerExecutable->typeProfilingStartOffset(), ownerExecutable->typeProfilingEndOffset());
1924
1925     setConstantRegisters(unlinkedCodeBlock->constantRegisters(), unlinkedCodeBlock->constantsSourceCodeRepresentation());
1926     if (unlinkedCodeBlock->usesGlobalObject())
1927         m_constantRegisters[unlinkedCodeBlock->globalObjectRegister().toConstantIndex()].set(*m_vm, this, m_globalObject.get());
1928
1929     for (unsigned i = 0; i < LinkTimeConstantCount; i++) {
1930         LinkTimeConstant type = static_cast<LinkTimeConstant>(i);
1931         if (unsigned registerIndex = unlinkedCodeBlock->registerIndexForLinkTimeConstant(type))
1932             m_constantRegisters[registerIndex].set(*m_vm, this, m_globalObject->jsCellForLinkTimeConstant(type));
1933     }
1934
1935     // We already have the cloned symbol table for the module environment since we need to instantiate
1936     // the module environments before linking the code block. We replace the stored symbol table with the already cloned one.
1937     if (UnlinkedModuleProgramCodeBlock* unlinkedModuleProgramCodeBlock = jsDynamicCast<UnlinkedModuleProgramCodeBlock*>(unlinkedCodeBlock)) {
1938         SymbolTable* clonedSymbolTable = jsCast<ModuleProgramExecutable*>(ownerExecutable)->moduleEnvironmentSymbolTable();
1939         if (m_vm->typeProfiler()) {
1940             ConcurrentJITLocker locker(clonedSymbolTable->m_lock);
1941             clonedSymbolTable->prepareForTypeProfiling(locker);
1942         }
1943         replaceConstant(unlinkedModuleProgramCodeBlock->moduleEnvironmentSymbolTableConstantRegisterOffset(), clonedSymbolTable);
1944     }
1945
1946     bool shouldUpdateFunctionHasExecutedCache = vm.typeProfiler() || vm.controlFlowProfiler();
1947     m_functionDecls = RefCountedArray<WriteBarrier<FunctionExecutable>>(unlinkedCodeBlock->numberOfFunctionDecls());
1948     for (size_t count = unlinkedCodeBlock->numberOfFunctionDecls(), i = 0; i < count; ++i) {
1949         UnlinkedFunctionExecutable* unlinkedExecutable = unlinkedCodeBlock->functionDecl(i);
1950         if (shouldUpdateFunctionHasExecutedCache)
1951             vm.functionHasExecutedCache()->insertUnexecutedRange(ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
1952         m_functionDecls[i].set(*m_vm, this, unlinkedExecutable->link(*m_vm, ownerExecutable->source()));
1953     }
1954
1955     m_functionExprs = RefCountedArray<WriteBarrier<FunctionExecutable>>(unlinkedCodeBlock->numberOfFunctionExprs());
1956     for (size_t count = unlinkedCodeBlock->numberOfFunctionExprs(), i = 0; i < count; ++i) {
1957         UnlinkedFunctionExecutable* unlinkedExecutable = unlinkedCodeBlock->functionExpr(i);
1958         if (shouldUpdateFunctionHasExecutedCache)
1959             vm.functionHasExecutedCache()->insertUnexecutedRange(ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
1960         m_functionExprs[i].set(*m_vm, this, unlinkedExecutable->link(*m_vm, ownerExecutable->source()));
1961     }
1962
1963     if (unlinkedCodeBlock->hasRareData()) {
1964         createRareDataIfNecessary();
1965         if (size_t count = unlinkedCodeBlock->constantBufferCount()) {
1966             m_rareData->m_constantBuffers.grow(count);
1967             for (size_t i = 0; i < count; i++) {
1968                 const UnlinkedCodeBlock::ConstantBuffer& buffer = unlinkedCodeBlock->constantBuffer(i);
1969                 m_rareData->m_constantBuffers[i] = buffer;
1970             }
1971         }
1972         if (size_t count = unlinkedCodeBlock->numberOfExceptionHandlers()) {
1973             m_rareData->m_exceptionHandlers.resizeToFit(count);
1974             for (size_t i = 0; i < count; i++) {
1975                 const UnlinkedHandlerInfo& unlinkedHandler = unlinkedCodeBlock->exceptionHandler(i);
1976                 HandlerInfo& handler = m_rareData->m_exceptionHandlers[i];
1977 #if ENABLE(JIT)
1978                 handler.initialize(unlinkedHandler, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(LLInt::getCodePtr(op_catch))));
1979 #else
1980                 handler.initialize(unlinkedHandler);
1981 #endif
1982             }
1983         }
1984
1985         if (size_t count = unlinkedCodeBlock->numberOfStringSwitchJumpTables()) {
1986             m_rareData->m_stringSwitchJumpTables.grow(count);
1987             for (size_t i = 0; i < count; i++) {
1988                 UnlinkedStringJumpTable::StringOffsetTable::iterator ptr = unlinkedCodeBlock->stringSwitchJumpTable(i).offsetTable.begin();
1989                 UnlinkedStringJumpTable::StringOffsetTable::iterator end = unlinkedCodeBlock->stringSwitchJumpTable(i).offsetTable.end();
1990                 for (; ptr != end; ++ptr) {
1991                     OffsetLocation offset;
1992                     offset.branchOffset = ptr->value;
1993                     m_rareData->m_stringSwitchJumpTables[i].offsetTable.add(ptr->key, offset);
1994                 }
1995             }
1996         }
1997
1998         if (size_t count = unlinkedCodeBlock->numberOfSwitchJumpTables()) {
1999             m_rareData->m_switchJumpTables.grow(count);
2000             for (size_t i = 0; i < count; i++) {
2001                 UnlinkedSimpleJumpTable& sourceTable = unlinkedCodeBlock->switchJumpTable(i);
2002                 SimpleJumpTable& destTable = m_rareData->m_switchJumpTables[i];
2003                 destTable.branchOffsets = sourceTable.branchOffsets;
2004                 destTable.min = sourceTable.min;
2005             }
2006         }
2007     }
2008
2009     // Allocate metadata buffers for the bytecode
2010     if (size_t size = unlinkedCodeBlock->numberOfLLintCallLinkInfos())
2011         m_llintCallLinkInfos = RefCountedArray<LLIntCallLinkInfo>(size);
2012     if (size_t size = unlinkedCodeBlock->numberOfArrayProfiles())
2013         m_arrayProfiles.grow(size);
2014     if (size_t size = unlinkedCodeBlock->numberOfArrayAllocationProfiles())
2015         m_arrayAllocationProfiles = RefCountedArray<ArrayAllocationProfile>(size);
2016     if (size_t size = unlinkedCodeBlock->numberOfValueProfiles())
2017         m_valueProfiles = RefCountedArray<ValueProfile>(size);
2018     if (size_t size = unlinkedCodeBlock->numberOfObjectAllocationProfiles())
2019         m_objectAllocationProfiles = RefCountedArray<ObjectAllocationProfile>(size);
2020
2021 #if ENABLE(JIT)
2022     setCalleeSaveRegisters(RegisterSet::llintBaselineCalleeSaveRegisters());
2023 #endif
2024
2025     // Copy and translate the UnlinkedInstructions
2026     unsigned instructionCount = unlinkedCodeBlock->instructions().count();
2027     UnlinkedInstructionStream::Reader instructionReader(unlinkedCodeBlock->instructions());
2028
2029     // Bookkeep the strongly referenced module environments.
2030     HashSet<JSModuleEnvironment*> stronglyReferencedModuleEnvironments;
2031
2032     // Bookkeep the merge point bytecode offsets.
2033     Vector<size_t> mergePointBytecodeOffsets;
2034
2035     RefCountedArray<Instruction> instructions(instructionCount);
2036
2037     for (unsigned i = 0; !instructionReader.atEnd(); ) {
2038         const UnlinkedInstruction* pc = instructionReader.next();
2039
2040         unsigned opLength = opcodeLength(pc[0].u.opcode);
2041
2042         instructions[i] = vm.interpreter->getOpcode(pc[0].u.opcode);
2043         for (size_t j = 1; j < opLength; ++j) {
2044             if (sizeof(int32_t) != sizeof(intptr_t))
2045                 instructions[i + j].u.pointer = 0;
2046             instructions[i + j].u.operand = pc[j].u.operand;
2047         }
2048         switch (pc[0].u.opcode) {
2049         case op_has_indexed_property: {
2050             int arrayProfileIndex = pc[opLength - 1].u.operand;
2051             m_arrayProfiles[arrayProfileIndex] = ArrayProfile(i);
2052
2053             instructions[i + opLength - 1] = &m_arrayProfiles[arrayProfileIndex];
2054             break;
2055         }
2056         case op_call_varargs:
2057         case op_tail_call_varargs:
2058         case op_construct_varargs:
2059         case op_get_by_val: {
2060             int arrayProfileIndex = pc[opLength - 2].u.operand;
2061             m_arrayProfiles[arrayProfileIndex] = ArrayProfile(i);
2062
2063             instructions[i + opLength - 2] = &m_arrayProfiles[arrayProfileIndex];
2064             FALLTHROUGH;
2065         }
2066         case op_get_direct_pname:
2067         case op_get_by_id:
2068         case op_get_from_arguments: {
2069             ValueProfile* profile = &m_valueProfiles[pc[opLength - 1].u.operand];
2070             ASSERT(profile->m_bytecodeOffset == -1);
2071             profile->m_bytecodeOffset = i;
2072             instructions[i + opLength - 1] = profile;
2073             break;
2074         }
2075         case op_put_by_val: {
2076             int arrayProfileIndex = pc[opLength - 1].u.operand;
2077             m_arrayProfiles[arrayProfileIndex] = ArrayProfile(i);
2078             instructions[i + opLength - 1] = &m_arrayProfiles[arrayProfileIndex];
2079             break;
2080         }
2081         case op_put_by_val_direct: {
2082             int arrayProfileIndex = pc[opLength - 1].u.operand;
2083             m_arrayProfiles[arrayProfileIndex] = ArrayProfile(i);
2084             instructions[i + opLength - 1] = &m_arrayProfiles[arrayProfileIndex];
2085             break;
2086         }
2087
2088         case op_new_array:
2089         case op_new_array_buffer:
2090         case op_new_array_with_size: {
2091             int arrayAllocationProfileIndex = pc[opLength - 1].u.operand;
2092             instructions[i + opLength - 1] = &m_arrayAllocationProfiles[arrayAllocationProfileIndex];
2093             break;
2094         }
2095         case op_new_object: {
2096             int objectAllocationProfileIndex = pc[opLength - 1].u.operand;
2097             ObjectAllocationProfile* objectAllocationProfile = &m_objectAllocationProfiles[objectAllocationProfileIndex];
2098             int inferredInlineCapacity = pc[opLength - 2].u.operand;
2099
2100             instructions[i + opLength - 1] = objectAllocationProfile;
2101             objectAllocationProfile->initialize(vm,
2102                 this, m_globalObject->objectPrototype(), inferredInlineCapacity);
2103             break;
2104         }
2105
2106         case op_call:
2107         case op_tail_call:
2108         case op_call_eval: {
2109             ValueProfile* profile = &m_valueProfiles[pc[opLength - 1].u.operand];
2110             ASSERT(profile->m_bytecodeOffset == -1);
2111             profile->m_bytecodeOffset = i;
2112             instructions[i + opLength - 1] = profile;
2113             int arrayProfileIndex = pc[opLength - 2].u.operand;
2114             m_arrayProfiles[arrayProfileIndex] = ArrayProfile(i);
2115             instructions[i + opLength - 2] = &m_arrayProfiles[arrayProfileIndex];
2116             instructions[i + 5] = &m_llintCallLinkInfos[pc[5].u.operand];
2117             break;
2118         }
2119         case op_construct: {
2120             instructions[i + 5] = &m_llintCallLinkInfos[pc[5].u.operand];
2121             ValueProfile* profile = &m_valueProfiles[pc[opLength - 1].u.operand];
2122             ASSERT(profile->m_bytecodeOffset == -1);
2123             profile->m_bytecodeOffset = i;
2124             instructions[i + opLength - 1] = profile;
2125             break;
2126         }
2127         case op_get_array_length:
2128             CRASH();
2129
2130         case op_resolve_scope: {
2131             const Identifier& ident = identifier(pc[3].u.operand);
2132             ResolveType type = static_cast<ResolveType>(pc[4].u.operand);
2133             RELEASE_ASSERT(type != LocalClosureVar);
2134             int localScopeDepth = pc[5].u.operand;
2135
2136             ResolveOp op = JSScope::abstractResolve(m_globalObject->globalExec(), localScopeDepth, scope, ident, Get, type, InitializationMode::NotInitialization);
2137             instructions[i + 4].u.operand = op.type;
2138             instructions[i + 5].u.operand = op.depth;
2139             if (op.lexicalEnvironment) {
2140                 if (op.type == ModuleVar) {
2141                     // Keep the linked module environment strongly referenced.
2142                     if (stronglyReferencedModuleEnvironments.add(jsCast<JSModuleEnvironment*>(op.lexicalEnvironment)).isNewEntry)
2143                         addConstant(op.lexicalEnvironment);
2144                     instructions[i + 6].u.jsCell.set(vm, this, op.lexicalEnvironment);
2145                 } else
2146                     instructions[i + 6].u.symbolTable.set(vm, this, op.lexicalEnvironment->symbolTable());
2147             } else if (JSScope* constantScope = JSScope::constantScopeForCodeBlock(op.type, this))
2148                 instructions[i + 6].u.jsCell.set(vm, this, constantScope);
2149             else
2150                 instructions[i + 6].u.pointer = nullptr;
2151             break;
2152         }
2153
2154         case op_get_from_scope: {
2155             ValueProfile* profile = &m_valueProfiles[pc[opLength - 1].u.operand];
2156             ASSERT(profile->m_bytecodeOffset == -1);
2157             profile->m_bytecodeOffset = i;
2158             instructions[i + opLength - 1] = profile;
2159
2160             // get_from_scope dst, scope, id, GetPutInfo, Structure, Operand
2161
2162             int localScopeDepth = pc[5].u.operand;
2163             instructions[i + 5].u.pointer = nullptr;
2164
2165             GetPutInfo getPutInfo = GetPutInfo(pc[4].u.operand);
2166             ASSERT(!isInitialization(getPutInfo.initializationMode()));
2167             if (getPutInfo.resolveType() == LocalClosureVar) {
2168                 instructions[i + 4] = GetPutInfo(getPutInfo.resolveMode(), ClosureVar, getPutInfo.initializationMode()).operand();
2169                 break;
2170             }
2171
2172             const Identifier& ident = identifier(pc[3].u.operand);
2173             ResolveOp op = JSScope::abstractResolve(m_globalObject->globalExec(), localScopeDepth, scope, ident, Get, getPutInfo.resolveType(), InitializationMode::NotInitialization);
2174
2175             instructions[i + 4].u.operand = GetPutInfo(getPutInfo.resolveMode(), op.type, getPutInfo.initializationMode()).operand();
2176             if (op.type == ModuleVar)
2177                 instructions[i + 4].u.operand = GetPutInfo(getPutInfo.resolveMode(), ClosureVar, getPutInfo.initializationMode()).operand();
2178             if (op.type == GlobalVar || op.type == GlobalVarWithVarInjectionChecks || op.type == GlobalLexicalVar || op.type == GlobalLexicalVarWithVarInjectionChecks)
2179                 instructions[i + 5].u.watchpointSet = op.watchpointSet;
2180             else if (op.structure)
2181                 instructions[i + 5].u.structure.set(vm, this, op.structure);
2182             instructions[i + 6].u.pointer = reinterpret_cast<void*>(op.operand);
2183             break;
2184         }
2185
2186         case op_put_to_scope: {
2187             // put_to_scope scope, id, value, GetPutInfo, Structure, Operand
2188             GetPutInfo getPutInfo = GetPutInfo(pc[4].u.operand);
2189             if (getPutInfo.resolveType() == LocalClosureVar) {
2190                 // Only do watching if the property we're putting to is not anonymous.
2191                 if (static_cast<unsigned>(pc[2].u.operand) != UINT_MAX) {
2192                     int symbolTableIndex = pc[5].u.operand;
2193                     SymbolTable* symbolTable = jsCast<SymbolTable*>(getConstant(symbolTableIndex));
2194                     const Identifier& ident = identifier(pc[2].u.operand);
2195                     ConcurrentJITLocker locker(symbolTable->m_lock);
2196                     auto iter = symbolTable->find(locker, ident.impl());
2197                     ASSERT(iter != symbolTable->end(locker));
2198                     iter->value.prepareToWatch();
2199                     instructions[i + 5].u.watchpointSet = iter->value.watchpointSet();
2200                 } else
2201                     instructions[i + 5].u.watchpointSet = nullptr;
2202                 break;
2203             }
2204
2205             const Identifier& ident = identifier(pc[2].u.operand);
2206             int localScopeDepth = pc[5].u.operand;
2207             instructions[i + 5].u.pointer = nullptr;
2208             ResolveOp op = JSScope::abstractResolve(m_globalObject->globalExec(), localScopeDepth, scope, ident, Put, getPutInfo.resolveType(), getPutInfo.initializationMode());
2209
2210             instructions[i + 4].u.operand = GetPutInfo(getPutInfo.resolveMode(), op.type, getPutInfo.initializationMode()).operand();
2211             if (op.type == GlobalVar || op.type == GlobalVarWithVarInjectionChecks || op.type == GlobalLexicalVar || op.type == GlobalLexicalVarWithVarInjectionChecks)
2212                 instructions[i + 5].u.watchpointSet = op.watchpointSet;
2213             else if (op.type == ClosureVar || op.type == ClosureVarWithVarInjectionChecks) {
2214                 if (op.watchpointSet)
2215                     op.watchpointSet->invalidate(PutToScopeFireDetail(this, ident));
2216             } else if (op.structure)
2217                 instructions[i + 5].u.structure.set(vm, this, op.structure);
2218             instructions[i + 6].u.pointer = reinterpret_cast<void*>(op.operand);
2219
2220             break;
2221         }
2222
2223         case op_profile_type: {
2224             RELEASE_ASSERT(vm.typeProfiler());
2225             // The format of this instruction is: op_profile_type regToProfile, TypeLocation*, flag, identifier?, resolveType?
2226             size_t instructionOffset = i + opLength - 1;
2227             unsigned divotStart, divotEnd;
2228             GlobalVariableID globalVariableID = 0;
2229             RefPtr<TypeSet> globalTypeSet;
2230             bool shouldAnalyze = m_unlinkedCode->typeProfilerExpressionInfoForBytecodeOffset(instructionOffset, divotStart, divotEnd);
2231             VirtualRegister profileRegister(pc[1].u.operand);
2232             ProfileTypeBytecodeFlag flag = static_cast<ProfileTypeBytecodeFlag>(pc[3].u.operand);
2233             SymbolTable* symbolTable = nullptr;
2234
2235             switch (flag) {
2236             case ProfileTypeBytecodeClosureVar: {
2237                 const Identifier& ident = identifier(pc[4].u.operand);
2238                 int localScopeDepth = pc[2].u.operand;
2239                 ResolveType type = static_cast<ResolveType>(pc[5].u.operand);
2240                 // Even though type profiling may be profiling either a Get or a Put, we can always claim a Get because
2241                 // we're abstractly "read"ing from a JSScope.
2242                 ResolveOp op = JSScope::abstractResolve(m_globalObject->globalExec(), localScopeDepth, scope, ident, Get, type, InitializationMode::NotInitialization);
2243
2244                 if (op.type == ClosureVar || op.type == ModuleVar)
2245                     symbolTable = op.lexicalEnvironment->symbolTable();
2246                 else if (op.type == GlobalVar)
2247                     symbolTable = m_globalObject.get()->symbolTable();
2248
2249                 UniquedStringImpl* impl = (op.type == ModuleVar) ? op.importedName.get() : ident.impl();
2250                 if (symbolTable) {
2251                     ConcurrentJITLocker locker(symbolTable->m_lock);
2252                     // If our parent scope was created while profiling was disabled, it will not have prepared for profiling yet.
2253                     symbolTable->prepareForTypeProfiling(locker);
2254                     globalVariableID = symbolTable->uniqueIDForVariable(locker, impl, vm);
2255                     globalTypeSet = symbolTable->globalTypeSetForVariable(locker, impl, vm);
2256                 } else
2257                     globalVariableID = TypeProfilerNoGlobalIDExists;
2258
2259                 break;
2260             }
2261             case ProfileTypeBytecodeLocallyResolved: {
2262                 int symbolTableIndex = pc[2].u.operand;
2263                 SymbolTable* symbolTable = jsCast<SymbolTable*>(getConstant(symbolTableIndex));
2264                 const Identifier& ident = identifier(pc[4].u.operand);
2265                 ConcurrentJITLocker locker(symbolTable->m_lock);
2266                 // If our parent scope was created while profiling was disabled, it will not have prepared for profiling yet.
2267                 globalVariableID = symbolTable->uniqueIDForVariable(locker, ident.impl(), vm);
2268                 globalTypeSet = symbolTable->globalTypeSetForVariable(locker, ident.impl(), vm);
2269
2270                 break;
2271             }
2272             case ProfileTypeBytecodeDoesNotHaveGlobalID: 
2273             case ProfileTypeBytecodeFunctionArgument: {
2274                 globalVariableID = TypeProfilerNoGlobalIDExists;
2275                 break;
2276             }
2277             case ProfileTypeBytecodeFunctionReturnStatement: {
2278                 RELEASE_ASSERT(ownerExecutable->isFunctionExecutable());
2279                 globalTypeSet = jsCast<FunctionExecutable*>(ownerExecutable)->returnStatementTypeSet();
2280                 globalVariableID = TypeProfilerReturnStatement;
2281                 if (!shouldAnalyze) {
2282                     // Because a return statement can be added implicitly to return undefined at the end of a function,
2283                     // and these nodes don't emit expression ranges because they aren't in the actual source text of
2284                     // the user's program, give the type profiler some range to identify these return statements.
2285                     // Currently, the text offset that is used as identification is "f" in the function keyword
2286                     // and is stored on TypeLocation's m_divotForFunctionOffsetIfReturnStatement member variable.
2287                     divotStart = divotEnd = ownerExecutable->typeProfilingStartOffset();
2288                     shouldAnalyze = true;
2289                 }
2290                 break;
2291             }
2292             }
2293
2294             std::pair<TypeLocation*, bool> locationPair = vm.typeProfiler()->typeLocationCache()->getTypeLocation(globalVariableID,
2295                 ownerExecutable->sourceID(), divotStart, divotEnd, globalTypeSet, &vm);
2296             TypeLocation* location = locationPair.first;
2297             bool isNewLocation = locationPair.second;
2298
2299             if (flag == ProfileTypeBytecodeFunctionReturnStatement)
2300                 location->m_divotForFunctionOffsetIfReturnStatement = ownerExecutable->typeProfilingStartOffset();
2301
2302             if (shouldAnalyze && isNewLocation)
2303                 vm.typeProfiler()->insertNewLocation(location);
2304
2305             instructions[i + 2].u.location = location;
2306             break;
2307         }
2308
2309         case op_debug: {
2310             if (pc[1].u.index == DidReachBreakpoint)
2311                 m_hasDebuggerStatement = true;
2312             break;
2313         }
2314
2315         case op_save: {
2316             unsigned liveCalleeLocalsIndex = pc[2].u.index;
2317             int offset = pc[3].u.operand;
2318             if (liveCalleeLocalsIndex >= mergePointBytecodeOffsets.size())
2319                 mergePointBytecodeOffsets.resize(liveCalleeLocalsIndex + 1);
2320             mergePointBytecodeOffsets[liveCalleeLocalsIndex] = i + offset;
2321             break;
2322         }
2323
2324         default:
2325             break;
2326         }
2327         i += opLength;
2328     }
2329
2330     if (vm.controlFlowProfiler())
2331         insertBasicBlockBoundariesForControlFlowProfiler(instructions);
2332
2333     m_instructions = WTFMove(instructions);
2334
2335     // Perform bytecode liveness analysis to determine which locals are live and should be resumed when executing op_resume.
2336     if (unlinkedCodeBlock->parseMode() == SourceParseMode::GeneratorBodyMode) {
2337         if (size_t count = mergePointBytecodeOffsets.size()) {
2338             createRareDataIfNecessary();
2339             BytecodeLivenessAnalysis liveness(this);
2340             m_rareData->m_liveCalleeLocalsAtYield.grow(count);
2341             size_t liveCalleeLocalsIndex = 0;
2342             for (size_t bytecodeOffset : mergePointBytecodeOffsets) {
2343                 m_rareData->m_liveCalleeLocalsAtYield[liveCalleeLocalsIndex] = liveness.getLivenessInfoAtBytecodeOffset(bytecodeOffset);
2344                 ++liveCalleeLocalsIndex;
2345             }
2346         }
2347     }
2348
2349     // Set optimization thresholds only after m_instructions is initialized, since these
2350     // rely on the instruction count (and are in theory permitted to also inspect the
2351     // instruction stream to more accurate assess the cost of tier-up).
2352     optimizeAfterWarmUp();
2353     jitAfterWarmUp();
2354
2355     // If the concurrent thread will want the code block's hash, then compute it here
2356     // synchronously.
2357     if (Options::alwaysComputeHash())
2358         hash();
2359
2360     if (Options::dumpGeneratedBytecodes())
2361         dumpBytecode();
2362     
2363     heap()->m_codeBlocks.add(this);
2364     heap()->reportExtraMemoryAllocated(m_instructions.size() * sizeof(Instruction));
2365 }
2366
2367 #if ENABLE(WEBASSEMBLY)
2368 CodeBlock::CodeBlock(VM* vm, Structure* structure, WebAssemblyExecutable* ownerExecutable, JSGlobalObject* globalObject)
2369     : JSCell(*vm, structure)
2370     , m_globalObject(globalObject->vm(), this, globalObject)
2371     , m_numCalleeLocals(0)
2372     , m_numVars(0)
2373     , m_shouldAlwaysBeInlined(false)
2374 #if ENABLE(JIT)
2375     , m_capabilityLevelState(DFG::CannotCompile)
2376 #endif
2377     , m_didFailFTLCompilation(false)
2378     , m_hasBeenCompiledWithFTL(false)
2379     , m_isConstructor(false)
2380     , m_isStrictMode(false)
2381     , m_codeType(FunctionCode)
2382     , m_hasDebuggerStatement(false)
2383     , m_steppingMode(SteppingModeDisabled)
2384     , m_numBreakpoints(0)
2385     , m_ownerExecutable(m_globalObject->vm(), this, ownerExecutable)
2386     , m_vm(vm)
2387     , m_osrExitCounter(0)
2388     , m_optimizationDelayCounter(0)
2389     , m_reoptimizationRetryCounter(0)
2390     , m_creationTime(std::chrono::steady_clock::now())
2391 {
2392     ASSERT(heap()->isDeferred());
2393 }
2394
2395 void CodeBlock::finishCreation(VM& vm, WebAssemblyExecutable*, JSGlobalObject*)
2396 {
2397     Base::finishCreation(vm);
2398
2399     heap()->m_codeBlocks.add(this);
2400 }
2401 #endif
2402
2403 CodeBlock::~CodeBlock()
2404 {
2405     if (m_vm->m_perBytecodeProfiler)
2406         m_vm->m_perBytecodeProfiler->notifyDestruction(this);
2407     
2408 #if ENABLE(VERBOSE_VALUE_PROFILE)
2409     dumpValueProfiles();
2410 #endif
2411
2412     // We may be destroyed before any CodeBlocks that refer to us are destroyed.
2413     // Consider that two CodeBlocks become unreachable at the same time. There
2414     // is no guarantee about the order in which the CodeBlocks are destroyed.
2415     // So, if we don't remove incoming calls, and get destroyed before the
2416     // CodeBlock(s) that have calls into us, then the CallLinkInfo vector's
2417     // destructor will try to remove nodes from our (no longer valid) linked list.
2418     unlinkIncomingCalls();
2419     
2420     // Note that our outgoing calls will be removed from other CodeBlocks'
2421     // m_incomingCalls linked lists through the execution of the ~CallLinkInfo
2422     // destructors.
2423
2424 #if ENABLE(JIT)
2425     for (Bag<StructureStubInfo>::iterator iter = m_stubInfos.begin(); !!iter; ++iter) {
2426         StructureStubInfo* stub = *iter;
2427         stub->aboutToDie();
2428         stub->deref();
2429     }
2430 #endif // ENABLE(JIT)
2431 }
2432
2433 void CodeBlock::setConstantRegisters(const Vector<WriteBarrier<Unknown>>& constants, const Vector<SourceCodeRepresentation>& constantsSourceCodeRepresentation)
2434 {
2435     ASSERT(constants.size() == constantsSourceCodeRepresentation.size());
2436     size_t count = constants.size();
2437     m_constantRegisters.resizeToFit(count);
2438     bool hasTypeProfiler = !!m_vm->typeProfiler();
2439     for (size_t i = 0; i < count; i++) {
2440         JSValue constant = constants[i].get();
2441
2442         if (!constant.isEmpty()) {
2443             if (SymbolTable* symbolTable = jsDynamicCast<SymbolTable*>(constant)) {
2444                 if (hasTypeProfiler) {
2445                     ConcurrentJITLocker locker(symbolTable->m_lock);
2446                     symbolTable->prepareForTypeProfiling(locker);
2447                 }
2448                 constant = symbolTable->cloneScopePart(*m_vm);
2449             }
2450         }
2451
2452         m_constantRegisters[i].set(*m_vm, this, constant);
2453     }
2454
2455     m_constantsSourceCodeRepresentation = constantsSourceCodeRepresentation;
2456 }
2457
2458 void CodeBlock::setAlternative(VM& vm, CodeBlock* alternative)
2459 {
2460     m_alternative.set(vm, this, alternative);
2461 }
2462
2463 void CodeBlock::setNumParameters(int newValue)
2464 {
2465     m_numParameters = newValue;
2466
2467     m_argumentValueProfiles = RefCountedArray<ValueProfile>(newValue);
2468 }
2469
2470 void EvalCodeCache::visitAggregate(SlotVisitor& visitor)
2471 {
2472     EvalCacheMap::iterator end = m_cacheMap.end();
2473     for (EvalCacheMap::iterator ptr = m_cacheMap.begin(); ptr != end; ++ptr)
2474         visitor.append(&ptr->value);
2475 }
2476
2477 CodeBlock* CodeBlock::specialOSREntryBlockOrNull()
2478 {
2479 #if ENABLE(FTL_JIT)
2480     if (jitType() != JITCode::DFGJIT)
2481         return 0;
2482     DFG::JITCode* jitCode = m_jitCode->dfg();
2483     return jitCode->osrEntryBlock();
2484 #else // ENABLE(FTL_JIT)
2485     return 0;
2486 #endif // ENABLE(FTL_JIT)
2487 }
2488
2489 void CodeBlock::visitWeakly(SlotVisitor& visitor)
2490 {
2491     bool setByMe = m_visitWeaklyHasBeenCalled.compareExchangeStrong(false, true);
2492     if (!setByMe)
2493         return;
2494
2495     if (Heap::isMarked(this))
2496         return;
2497
2498     if (shouldVisitStrongly()) {
2499         visitor.appendUnbarrieredReadOnlyPointer(this);
2500         return;
2501     }
2502
2503     // There are two things that may use unconditional finalizers: inline cache clearing
2504     // and jettisoning. The probability of us wanting to do at least one of those things
2505     // is probably quite close to 1. So we add one no matter what and when it runs, it
2506     // figures out whether it has any work to do.
2507     visitor.addUnconditionalFinalizer(&m_unconditionalFinalizer);
2508
2509     if (!JITCode::isOptimizingJIT(jitType()))
2510         return;
2511
2512     // If we jettison ourselves we'll install our alternative, so make sure that it
2513     // survives GC even if we don't.
2514     visitor.append(&m_alternative);
2515     
2516     // There are two things that we use weak reference harvesters for: DFG fixpoint for
2517     // jettisoning, and trying to find structures that would be live based on some
2518     // inline cache. So it makes sense to register them regardless.
2519     visitor.addWeakReferenceHarvester(&m_weakReferenceHarvester);
2520
2521 #if ENABLE(DFG_JIT)
2522     // We get here if we're live in the sense that our owner executable is live,
2523     // but we're not yet live for sure in another sense: we may yet decide that this
2524     // code block should be jettisoned based on its outgoing weak references being
2525     // stale. Set a flag to indicate that we're still assuming that we're dead, and
2526     // perform one round of determining if we're live. The GC may determine, based on
2527     // either us marking additional objects, or by other objects being marked for
2528     // other reasons, that this iteration should run again; it will notify us of this
2529     // decision by calling harvestWeakReferences().
2530
2531     m_allTransitionsHaveBeenMarked = false;
2532     propagateTransitions(visitor);
2533
2534     m_jitCode->dfgCommon()->livenessHasBeenProved = false;
2535     determineLiveness(visitor);
2536 #endif // ENABLE(DFG_JIT)
2537 }
2538
2539 size_t CodeBlock::estimatedSize(JSCell* cell)
2540 {
2541     CodeBlock* thisObject = jsCast<CodeBlock*>(cell);
2542     size_t extraMemoryAllocated = thisObject->m_instructions.size() * sizeof(Instruction);
2543     if (thisObject->m_jitCode)
2544         extraMemoryAllocated += thisObject->m_jitCode->size();
2545     return Base::estimatedSize(cell) + extraMemoryAllocated;
2546 }
2547
2548 void CodeBlock::visitChildren(JSCell* cell, SlotVisitor& visitor)
2549 {
2550     CodeBlock* thisObject = jsCast<CodeBlock*>(cell);
2551     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
2552     JSCell::visitChildren(thisObject, visitor);
2553     thisObject->visitChildren(visitor);
2554 }
2555
2556 void CodeBlock::visitChildren(SlotVisitor& visitor)
2557 {
2558     // There are two things that may use unconditional finalizers: inline cache clearing
2559     // and jettisoning. The probability of us wanting to do at least one of those things
2560     // is probably quite close to 1. So we add one no matter what and when it runs, it
2561     // figures out whether it has any work to do.
2562     visitor.addUnconditionalFinalizer(&m_unconditionalFinalizer);
2563
2564     if (CodeBlock* otherBlock = specialOSREntryBlockOrNull())
2565         visitor.appendUnbarrieredReadOnlyPointer(otherBlock);
2566
2567     if (m_jitCode)
2568         visitor.reportExtraMemoryVisited(m_jitCode->size());
2569     if (m_instructions.size())
2570         visitor.reportExtraMemoryVisited(m_instructions.size() * sizeof(Instruction) / m_instructions.refCount());
2571
2572     stronglyVisitStrongReferences(visitor);
2573     stronglyVisitWeakReferences(visitor);
2574
2575     m_allTransitionsHaveBeenMarked = false;
2576     propagateTransitions(visitor);
2577 }
2578
2579 bool CodeBlock::shouldVisitStrongly()
2580 {
2581     if (Options::forceCodeBlockLiveness())
2582         return true;
2583
2584     if (shouldJettisonDueToOldAge())
2585         return false;
2586
2587     // Interpreter and Baseline JIT CodeBlocks don't need to be jettisoned when
2588     // their weak references go stale. So if a basline JIT CodeBlock gets
2589     // scanned, we can assume that this means that it's live.
2590     if (!JITCode::isOptimizingJIT(jitType()))
2591         return true;
2592
2593     return false;
2594 }
2595
2596 bool CodeBlock::shouldJettisonDueToWeakReference()
2597 {
2598     if (!JITCode::isOptimizingJIT(jitType()))
2599         return false;
2600     return !Heap::isMarked(this);
2601 }
2602
2603 bool CodeBlock::shouldJettisonDueToOldAge()
2604 {
2605     return false;
2606 }
2607
2608 #if ENABLE(DFG_JIT)
2609 static bool shouldMarkTransition(DFG::WeakReferenceTransition& transition)
2610 {
2611     if (transition.m_codeOrigin && !Heap::isMarked(transition.m_codeOrigin.get()))
2612         return false;
2613     
2614     if (!Heap::isMarked(transition.m_from.get()))
2615         return false;
2616     
2617     return true;
2618 }
2619 #endif // ENABLE(DFG_JIT)
2620
2621 void CodeBlock::propagateTransitions(SlotVisitor& visitor)
2622 {
2623     UNUSED_PARAM(visitor);
2624
2625     if (m_allTransitionsHaveBeenMarked)
2626         return;
2627
2628     bool allAreMarkedSoFar = true;
2629         
2630     Interpreter* interpreter = m_vm->interpreter;
2631     if (jitType() == JITCode::InterpreterThunk) {
2632         const Vector<unsigned>& propertyAccessInstructions = m_unlinkedCode->propertyAccessInstructions();
2633         for (size_t i = 0; i < propertyAccessInstructions.size(); ++i) {
2634             Instruction* instruction = &instructions()[propertyAccessInstructions[i]];
2635             switch (interpreter->getOpcodeID(instruction[0].u.opcode)) {
2636             case op_put_by_id: {
2637                 StructureID oldStructureID = instruction[4].u.structureID;
2638                 StructureID newStructureID = instruction[6].u.structureID;
2639                 if (!oldStructureID || !newStructureID)
2640                     break;
2641                 Structure* oldStructure =
2642                     m_vm->heap.structureIDTable().get(oldStructureID);
2643                 Structure* newStructure =
2644                     m_vm->heap.structureIDTable().get(newStructureID);
2645                 if (Heap::isMarked(oldStructure))
2646                     visitor.appendUnbarrieredReadOnlyPointer(newStructure);
2647                 else
2648                     allAreMarkedSoFar = false;
2649                 break;
2650             }
2651             default:
2652                 break;
2653             }
2654         }
2655     }
2656
2657 #if ENABLE(JIT)
2658     if (JITCode::isJIT(jitType())) {
2659         for (Bag<StructureStubInfo>::iterator iter = m_stubInfos.begin(); !!iter; ++iter)
2660             allAreMarkedSoFar &= (*iter)->propagateTransitions(visitor);
2661     }
2662 #endif // ENABLE(JIT)
2663     
2664 #if ENABLE(DFG_JIT)
2665     if (JITCode::isOptimizingJIT(jitType())) {
2666         DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
2667         for (auto& weakReference : dfgCommon->weakStructureReferences)
2668             allAreMarkedSoFar &= weakReference->markIfCheap(visitor);
2669         
2670         for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
2671             if (shouldMarkTransition(dfgCommon->transitions[i])) {
2672                 // If the following three things are live, then the target of the
2673                 // transition is also live:
2674                 //
2675                 // - This code block. We know it's live already because otherwise
2676                 //   we wouldn't be scanning ourselves.
2677                 //
2678                 // - The code origin of the transition. Transitions may arise from
2679                 //   code that was inlined. They are not relevant if the user's
2680                 //   object that is required for the inlinee to run is no longer
2681                 //   live.
2682                 //
2683                 // - The source of the transition. The transition checks if some
2684                 //   heap location holds the source, and if so, stores the target.
2685                 //   Hence the source must be live for the transition to be live.
2686                 //
2687                 // We also short-circuit the liveness if the structure is harmless
2688                 // to mark (i.e. its global object and prototype are both already
2689                 // live).
2690                 
2691                 visitor.append(&dfgCommon->transitions[i].m_to);
2692             } else
2693                 allAreMarkedSoFar = false;
2694         }
2695     }
2696 #endif // ENABLE(DFG_JIT)
2697     
2698     if (allAreMarkedSoFar)
2699         m_allTransitionsHaveBeenMarked = true;
2700 }
2701
2702 void CodeBlock::determineLiveness(SlotVisitor& visitor)
2703 {
2704     UNUSED_PARAM(visitor);
2705     
2706 #if ENABLE(DFG_JIT)
2707     // Check if we have any remaining work to do.
2708     DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
2709     if (dfgCommon->livenessHasBeenProved)
2710         return;
2711     
2712     // Now check all of our weak references. If all of them are live, then we
2713     // have proved liveness and so we scan our strong references. If at end of
2714     // GC we still have not proved liveness, then this code block is toast.
2715     bool allAreLiveSoFar = true;
2716     for (unsigned i = 0; i < dfgCommon->weakReferences.size(); ++i) {
2717         if (!Heap::isMarked(dfgCommon->weakReferences[i].get())) {
2718             allAreLiveSoFar = false;
2719             break;
2720         }
2721     }
2722     if (allAreLiveSoFar) {
2723         for (unsigned i = 0; i < dfgCommon->weakStructureReferences.size(); ++i) {
2724             if (!Heap::isMarked(dfgCommon->weakStructureReferences[i].get())) {
2725                 allAreLiveSoFar = false;
2726                 break;
2727             }
2728         }
2729     }
2730     
2731     // If some weak references are dead, then this fixpoint iteration was
2732     // unsuccessful.
2733     if (!allAreLiveSoFar)
2734         return;
2735     
2736     // All weak references are live. Record this information so we don't
2737     // come back here again, and scan the strong references.
2738     dfgCommon->livenessHasBeenProved = true;
2739     visitor.appendUnbarrieredReadOnlyPointer(this);
2740 #endif // ENABLE(DFG_JIT)
2741 }
2742
2743 void CodeBlock::WeakReferenceHarvester::visitWeakReferences(SlotVisitor& visitor)
2744 {
2745     CodeBlock* codeBlock =
2746         bitwise_cast<CodeBlock*>(
2747             bitwise_cast<char*>(this) - OBJECT_OFFSETOF(CodeBlock, m_weakReferenceHarvester));
2748
2749     codeBlock->propagateTransitions(visitor);
2750     codeBlock->determineLiveness(visitor);
2751 }
2752
2753 void CodeBlock::finalizeLLIntInlineCaches()
2754 {
2755 #if ENABLE(WEBASSEMBLY)
2756     if (m_ownerExecutable->isWebAssemblyExecutable())
2757         return;
2758 #endif
2759
2760     Interpreter* interpreter = m_vm->interpreter;
2761     const Vector<unsigned>& propertyAccessInstructions = m_unlinkedCode->propertyAccessInstructions();
2762     for (size_t size = propertyAccessInstructions.size(), i = 0; i < size; ++i) {
2763         Instruction* curInstruction = &instructions()[propertyAccessInstructions[i]];
2764         switch (interpreter->getOpcodeID(curInstruction[0].u.opcode)) {
2765         case op_get_by_id:
2766         case op_get_by_id_proto_load:
2767         case op_get_by_id_unset: {
2768             StructureID oldStructureID = curInstruction[4].u.structureID;
2769             if (!oldStructureID || Heap::isMarked(m_vm->heap.structureIDTable().get(oldStructureID)))
2770                 break;
2771             if (Options::verboseOSR())
2772                 dataLogF("Clearing LLInt property access.\n");
2773             clearLLIntGetByIdCache(curInstruction);
2774             break;
2775         }
2776         case op_put_by_id: {
2777             StructureID oldStructureID = curInstruction[4].u.structureID;
2778             StructureID newStructureID = curInstruction[6].u.structureID;
2779             StructureChain* chain = curInstruction[7].u.structureChain.get();
2780             if ((!oldStructureID || Heap::isMarked(m_vm->heap.structureIDTable().get(oldStructureID))) &&
2781                 (!newStructureID || Heap::isMarked(m_vm->heap.structureIDTable().get(newStructureID))) &&
2782                 (!chain || Heap::isMarked(chain)))
2783                 break;
2784             if (Options::verboseOSR())
2785                 dataLogF("Clearing LLInt put transition.\n");
2786             curInstruction[4].u.structureID = 0;
2787             curInstruction[5].u.operand = 0;
2788             curInstruction[6].u.structureID = 0;
2789             curInstruction[7].u.structureChain.clear();
2790             break;
2791         }
2792         case op_get_array_length:
2793             break;
2794         case op_to_this:
2795             if (!curInstruction[2].u.structure || Heap::isMarked(curInstruction[2].u.structure.get()))
2796                 break;
2797             if (Options::verboseOSR())
2798                 dataLogF("Clearing LLInt to_this with structure %p.\n", curInstruction[2].u.structure.get());
2799             curInstruction[2].u.structure.clear();
2800             curInstruction[3].u.toThisStatus = merge(
2801                 curInstruction[3].u.toThisStatus, ToThisClearedByGC);
2802             break;
2803         case op_create_this: {
2804             auto& cacheWriteBarrier = curInstruction[4].u.jsCell;
2805             if (!cacheWriteBarrier || cacheWriteBarrier.unvalidatedGet() == JSCell::seenMultipleCalleeObjects())
2806                 break;
2807             JSCell* cachedFunction = cacheWriteBarrier.get();
2808             if (Heap::isMarked(cachedFunction))
2809                 break;
2810             if (Options::verboseOSR())
2811                 dataLogF("Clearing LLInt create_this with cached callee %p.\n", cachedFunction);
2812             cacheWriteBarrier.clear();
2813             break;
2814         }
2815         case op_resolve_scope: {
2816             // Right now this isn't strictly necessary. Any symbol tables that this will refer to
2817             // are for outer functions, and we refer to those functions strongly, and they refer
2818             // to the symbol table strongly. But it's nice to be on the safe side.
2819             WriteBarrierBase<SymbolTable>& symbolTable = curInstruction[6].u.symbolTable;
2820             if (!symbolTable || Heap::isMarked(symbolTable.get()))
2821                 break;
2822             if (Options::verboseOSR())
2823                 dataLogF("Clearing dead symbolTable %p.\n", symbolTable.get());
2824             symbolTable.clear();
2825             break;
2826         }
2827         case op_get_from_scope:
2828         case op_put_to_scope: {
2829             GetPutInfo getPutInfo = GetPutInfo(curInstruction[4].u.operand);
2830             if (getPutInfo.resolveType() == GlobalVar || getPutInfo.resolveType() == GlobalVarWithVarInjectionChecks 
2831                 || getPutInfo.resolveType() == LocalClosureVar || getPutInfo.resolveType() == GlobalLexicalVar || getPutInfo.resolveType() == GlobalLexicalVarWithVarInjectionChecks)
2832                 continue;
2833             WriteBarrierBase<Structure>& structure = curInstruction[5].u.structure;
2834             if (!structure || Heap::isMarked(structure.get()))
2835                 break;
2836             if (Options::verboseOSR())
2837                 dataLogF("Clearing scope access with structure %p.\n", structure.get());
2838             structure.clear();
2839             break;
2840         }
2841         default:
2842             OpcodeID opcodeID = interpreter->getOpcodeID(curInstruction[0].u.opcode);
2843             ASSERT_WITH_MESSAGE_UNUSED(opcodeID, false, "Unhandled opcode in CodeBlock::finalizeUnconditionally, %s(%d) at bc %u", opcodeNames[opcodeID], opcodeID, propertyAccessInstructions[i]);
2844         }
2845     }
2846
2847     // We can't just remove all the sets when we clear the caches since we might have created a watchpoint set
2848     // then cleared the cache without GCing in between.
2849     m_llintGetByIdWatchpointMap.removeIf([](const StructureWatchpointMap::KeyValuePairType& pair) -> bool {
2850         return !Heap::isMarked(pair.key);
2851     });
2852
2853     for (unsigned i = 0; i < m_llintCallLinkInfos.size(); ++i) {
2854         if (m_llintCallLinkInfos[i].isLinked() && !Heap::isMarked(m_llintCallLinkInfos[i].callee.get())) {
2855             if (Options::verboseOSR())
2856                 dataLog("Clearing LLInt call from ", *this, "\n");
2857             m_llintCallLinkInfos[i].unlink();
2858         }
2859         if (!!m_llintCallLinkInfos[i].lastSeenCallee && !Heap::isMarked(m_llintCallLinkInfos[i].lastSeenCallee.get()))
2860             m_llintCallLinkInfos[i].lastSeenCallee.clear();
2861     }
2862 }
2863
2864 void CodeBlock::finalizeBaselineJITInlineCaches()
2865 {
2866 #if ENABLE(JIT)
2867     for (auto iter = callLinkInfosBegin(); !!iter; ++iter)
2868         (*iter)->visitWeak(*vm());
2869
2870     for (Bag<StructureStubInfo>::iterator iter = m_stubInfos.begin(); !!iter; ++iter) {
2871         StructureStubInfo& stubInfo = **iter;
2872         stubInfo.visitWeakReferences(this);
2873     }
2874 #endif
2875 }
2876
2877 void CodeBlock::UnconditionalFinalizer::finalizeUnconditionally()
2878 {
2879     CodeBlock* codeBlock = bitwise_cast<CodeBlock*>(
2880         bitwise_cast<char*>(this) - OBJECT_OFFSETOF(CodeBlock, m_unconditionalFinalizer));
2881
2882 #if ENABLE(DFG_JIT)
2883     if (codeBlock->shouldJettisonDueToWeakReference()) {
2884         codeBlock->jettison(Profiler::JettisonDueToWeakReference);
2885         return;
2886     }
2887 #endif // ENABLE(DFG_JIT)
2888
2889     if (codeBlock->shouldJettisonDueToOldAge()) {
2890         codeBlock->jettison(Profiler::JettisonDueToOldAge);
2891         return;
2892     }
2893
2894     if (JITCode::couldBeInterpreted(codeBlock->jitType()))
2895         codeBlock->finalizeLLIntInlineCaches();
2896
2897 #if ENABLE(JIT)
2898     if (!!codeBlock->jitCode())
2899         codeBlock->finalizeBaselineJITInlineCaches();
2900 #endif
2901 }
2902
2903 void CodeBlock::getStubInfoMap(const ConcurrentJITLocker&, StubInfoMap& result)
2904 {
2905 #if ENABLE(JIT)
2906     toHashMap(m_stubInfos, getStructureStubInfoCodeOrigin, result);
2907 #else
2908     UNUSED_PARAM(result);
2909 #endif
2910 }
2911
2912 void CodeBlock::getStubInfoMap(StubInfoMap& result)
2913 {
2914     ConcurrentJITLocker locker(m_lock);
2915     getStubInfoMap(locker, result);
2916 }
2917
2918 void CodeBlock::getCallLinkInfoMap(const ConcurrentJITLocker&, CallLinkInfoMap& result)
2919 {
2920 #if ENABLE(JIT)
2921     toHashMap(m_callLinkInfos, getCallLinkInfoCodeOrigin, result);
2922 #else
2923     UNUSED_PARAM(result);
2924 #endif
2925 }
2926
2927 void CodeBlock::getCallLinkInfoMap(CallLinkInfoMap& result)
2928 {
2929     ConcurrentJITLocker locker(m_lock);
2930     getCallLinkInfoMap(locker, result);
2931 }
2932
2933 void CodeBlock::getByValInfoMap(const ConcurrentJITLocker&, ByValInfoMap& result)
2934 {
2935 #if ENABLE(JIT)
2936     for (auto* byValInfo : m_byValInfos)
2937         result.add(CodeOrigin(byValInfo->bytecodeIndex), byValInfo);
2938 #else
2939     UNUSED_PARAM(result);
2940 #endif
2941 }
2942
2943 void CodeBlock::getByValInfoMap(ByValInfoMap& result)
2944 {
2945     ConcurrentJITLocker locker(m_lock);
2946     getByValInfoMap(locker, result);
2947 }
2948
2949 #if ENABLE(JIT)
2950 StructureStubInfo* CodeBlock::addStubInfo(AccessType accessType)
2951 {
2952     ConcurrentJITLocker locker(m_lock);
2953     return m_stubInfos.add(accessType);
2954 }
2955
2956 StructureStubInfo* CodeBlock::findStubInfo(CodeOrigin codeOrigin)
2957 {
2958     for (StructureStubInfo* stubInfo : m_stubInfos) {
2959         if (stubInfo->codeOrigin == codeOrigin)
2960             return stubInfo;
2961     }
2962     return nullptr;
2963 }
2964
2965 ByValInfo* CodeBlock::addByValInfo()
2966 {
2967     ConcurrentJITLocker locker(m_lock);
2968     return m_byValInfos.add();
2969 }
2970
2971 CallLinkInfo* CodeBlock::addCallLinkInfo()
2972 {
2973     ConcurrentJITLocker locker(m_lock);
2974     return m_callLinkInfos.add();
2975 }
2976
2977 CallLinkInfo* CodeBlock::getCallLinkInfoForBytecodeIndex(unsigned index)
2978 {
2979     for (auto iter = m_callLinkInfos.begin(); !!iter; ++iter) {
2980         if ((*iter)->codeOrigin() == CodeOrigin(index))
2981             return *iter;
2982     }
2983     return nullptr;
2984 }
2985 #endif
2986
2987 void CodeBlock::visitOSRExitTargets(SlotVisitor& visitor)
2988 {
2989     // We strongly visit OSR exits targets because we don't want to deal with
2990     // the complexity of generating an exit target CodeBlock on demand and
2991     // guaranteeing that it matches the details of the CodeBlock we compiled
2992     // the OSR exit against.
2993
2994     visitor.append(&m_alternative);
2995
2996 #if ENABLE(DFG_JIT)
2997     DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
2998     if (dfgCommon->inlineCallFrames) {
2999         for (auto* inlineCallFrame : *dfgCommon->inlineCallFrames) {
3000             ASSERT(inlineCallFrame->baselineCodeBlock);
3001             visitor.append(&inlineCallFrame->baselineCodeBlock);
3002         }
3003     }
3004 #endif
3005 }
3006
3007 void CodeBlock::stronglyVisitStrongReferences(SlotVisitor& visitor)
3008 {
3009     visitor.append(&m_globalObject);
3010     visitor.append(&m_ownerExecutable);
3011     visitor.append(&m_unlinkedCode);
3012     if (m_rareData)
3013         m_rareData->m_evalCodeCache.visitAggregate(visitor);
3014     visitor.appendValues(m_constantRegisters.data(), m_constantRegisters.size());
3015     for (size_t i = 0; i < m_functionExprs.size(); ++i)
3016         visitor.append(&m_functionExprs[i]);
3017     for (size_t i = 0; i < m_functionDecls.size(); ++i)
3018         visitor.append(&m_functionDecls[i]);
3019     for (unsigned i = 0; i < m_objectAllocationProfiles.size(); ++i)
3020         m_objectAllocationProfiles[i].visitAggregate(visitor);
3021
3022 #if ENABLE(DFG_JIT)
3023     if (JITCode::isOptimizingJIT(jitType()))
3024         visitOSRExitTargets(visitor);
3025 #endif
3026
3027     updateAllPredictions();
3028 }
3029
3030 void CodeBlock::stronglyVisitWeakReferences(SlotVisitor& visitor)
3031 {
3032     UNUSED_PARAM(visitor);
3033
3034 #if ENABLE(DFG_JIT)
3035     if (!JITCode::isOptimizingJIT(jitType()))
3036         return;
3037     
3038     DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
3039
3040     for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
3041         if (!!dfgCommon->transitions[i].m_codeOrigin)
3042             visitor.append(&dfgCommon->transitions[i].m_codeOrigin); // Almost certainly not necessary, since the code origin should also be a weak reference. Better to be safe, though.
3043         visitor.append(&dfgCommon->transitions[i].m_from);
3044         visitor.append(&dfgCommon->transitions[i].m_to);
3045     }
3046     
3047     for (unsigned i = 0; i < dfgCommon->weakReferences.size(); ++i)
3048         visitor.append(&dfgCommon->weakReferences[i]);
3049
3050     for (unsigned i = 0; i < dfgCommon->weakStructureReferences.size(); ++i)
3051         visitor.append(&dfgCommon->weakStructureReferences[i]);
3052
3053     dfgCommon->livenessHasBeenProved = true;
3054 #endif    
3055 }
3056
3057 CodeBlock* CodeBlock::baselineAlternative()
3058 {
3059 #if ENABLE(JIT)
3060     CodeBlock* result = this;
3061     while (result->alternative())
3062         result = result->alternative();
3063     RELEASE_ASSERT(result);
3064     RELEASE_ASSERT(JITCode::isBaselineCode(result->jitType()) || result->jitType() == JITCode::None);
3065     return result;
3066 #else
3067     return this;
3068 #endif
3069 }
3070
3071 CodeBlock* CodeBlock::baselineVersion()
3072 {
3073 #if ENABLE(JIT)
3074     if (JITCode::isBaselineCode(jitType()))
3075         return this;
3076     CodeBlock* result = replacement();
3077     if (!result) {
3078         // This can happen if we're creating the original CodeBlock for an executable.
3079         // Assume that we're the baseline CodeBlock.
3080         RELEASE_ASSERT(jitType() == JITCode::None);
3081         return this;
3082     }
3083     result = result->baselineAlternative();
3084     return result;
3085 #else
3086     return this;
3087 #endif
3088 }
3089
3090 #if ENABLE(JIT)
3091 bool CodeBlock::hasOptimizedReplacement(JITCode::JITType typeToReplace)
3092 {
3093     return JITCode::isHigherTier(replacement()->jitType(), typeToReplace);
3094 }
3095
3096 bool CodeBlock::hasOptimizedReplacement()
3097 {
3098     return hasOptimizedReplacement(jitType());
3099 }
3100 #endif
3101
3102 HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset, RequiredHandler requiredHandler)
3103 {
3104     RELEASE_ASSERT(bytecodeOffset < instructions().size());
3105     return handlerForIndex(bytecodeOffset, requiredHandler);
3106 }
3107
3108 HandlerInfo* CodeBlock::handlerForIndex(unsigned index, RequiredHandler requiredHandler)
3109 {
3110     if (!m_rareData)
3111         return 0;
3112     
3113     Vector<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers;
3114     for (size_t i = 0; i < exceptionHandlers.size(); ++i) {
3115         HandlerInfo& handler = exceptionHandlers[i];
3116         if ((requiredHandler == RequiredHandler::CatchHandler) && !handler.isCatchHandler())
3117             continue;
3118
3119         // Handlers are ordered innermost first, so the first handler we encounter
3120         // that contains the source address is the correct handler to use.
3121         // This index used is either the BytecodeOffset or a CallSiteIndex.
3122         if (handler.start <= index && handler.end > index)
3123             return &handler;
3124     }
3125
3126     return 0;
3127 }
3128
3129 CallSiteIndex CodeBlock::newExceptionHandlingCallSiteIndex(CallSiteIndex originalCallSite)
3130 {
3131 #if ENABLE(DFG_JIT)
3132     RELEASE_ASSERT(JITCode::isOptimizingJIT(jitType()));
3133     RELEASE_ASSERT(canGetCodeOrigin(originalCallSite));
3134     ASSERT(!!handlerForIndex(originalCallSite.bits()));
3135     CodeOrigin originalOrigin = codeOrigin(originalCallSite);
3136     return m_jitCode->dfgCommon()->addUniqueCallSiteIndex(originalOrigin);
3137 #else
3138     // We never create new on-the-fly exception handling
3139     // call sites outside the DFG/FTL inline caches.
3140     UNUSED_PARAM(originalCallSite);
3141     RELEASE_ASSERT_NOT_REACHED();
3142     return CallSiteIndex(0u);
3143 #endif
3144 }
3145
3146 void CodeBlock::removeExceptionHandlerForCallSite(CallSiteIndex callSiteIndex)
3147 {
3148     RELEASE_ASSERT(m_rareData);
3149     Vector<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers;
3150     unsigned index = callSiteIndex.bits();
3151     for (size_t i = 0; i < exceptionHandlers.size(); ++i) {
3152         HandlerInfo& handler = exceptionHandlers[i];
3153         if (handler.start <= index && handler.end > index) {
3154             exceptionHandlers.remove(i);
3155             return;
3156         }
3157     }
3158
3159     RELEASE_ASSERT_NOT_REACHED();
3160 }
3161
3162 unsigned CodeBlock::lineNumberForBytecodeOffset(unsigned bytecodeOffset)
3163 {
3164     RELEASE_ASSERT(bytecodeOffset < instructions().size());
3165     return ownerScriptExecutable()->firstLine() + m_unlinkedCode->lineNumberForBytecodeOffset(bytecodeOffset);
3166 }
3167
3168 unsigned CodeBlock::columnNumberForBytecodeOffset(unsigned bytecodeOffset)
3169 {
3170     int divot;
3171     int startOffset;
3172     int endOffset;
3173     unsigned line;
3174     unsigned column;
3175     expressionRangeForBytecodeOffset(bytecodeOffset, divot, startOffset, endOffset, line, column);
3176     return column;
3177 }
3178
3179 void CodeBlock::expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset, unsigned& line, unsigned& column) const
3180 {
3181     m_unlinkedCode->expressionRangeForBytecodeOffset(bytecodeOffset, divot, startOffset, endOffset, line, column);
3182     divot += m_sourceOffset;
3183     column += line ? 1 : firstLineColumnOffset();
3184     line += ownerScriptExecutable()->firstLine();
3185 }
3186
3187 bool CodeBlock::hasOpDebugForLineAndColumn(unsigned line, unsigned column)
3188 {
3189     Interpreter* interpreter = vm()->interpreter;
3190     const Instruction* begin = instructions().begin();
3191     const Instruction* end = instructions().end();
3192     for (const Instruction* it = begin; it != end;) {
3193         OpcodeID opcodeID = interpreter->getOpcodeID(it->u.opcode);
3194         if (opcodeID == op_debug) {
3195             unsigned bytecodeOffset = it - begin;
3196             int unused;
3197             unsigned opDebugLine;
3198             unsigned opDebugColumn;
3199             expressionRangeForBytecodeOffset(bytecodeOffset, unused, unused, unused, opDebugLine, opDebugColumn);
3200             if (line == opDebugLine && (column == Breakpoint::unspecifiedColumn || column == opDebugColumn))
3201                 return true;
3202         }
3203         it += opcodeLengths[opcodeID];
3204     }
3205     return false;
3206 }
3207
3208 void CodeBlock::shrinkToFit(ShrinkMode shrinkMode)
3209 {
3210     m_rareCaseProfiles.shrinkToFit();
3211     m_resultProfiles.shrinkToFit();
3212     
3213     if (shrinkMode == EarlyShrink) {
3214         m_constantRegisters.shrinkToFit();
3215         m_constantsSourceCodeRepresentation.shrinkToFit();
3216         
3217         if (m_rareData) {
3218             m_rareData->m_switchJumpTables.shrinkToFit();
3219             m_rareData->m_stringSwitchJumpTables.shrinkToFit();
3220             m_rareData->m_liveCalleeLocalsAtYield.shrinkToFit();
3221         }
3222     } // else don't shrink these, because we would have already pointed pointers into these tables.
3223 }
3224
3225 #if ENABLE(JIT)
3226 void CodeBlock::linkIncomingCall(ExecState* callerFrame, CallLinkInfo* incoming)
3227 {
3228     noticeIncomingCall(callerFrame);
3229     m_incomingCalls.push(incoming);
3230 }
3231
3232 void CodeBlock::linkIncomingPolymorphicCall(ExecState* callerFrame, PolymorphicCallNode* incoming)
3233 {
3234     noticeIncomingCall(callerFrame);
3235     m_incomingPolymorphicCalls.push(incoming);
3236 }
3237 #endif // ENABLE(JIT)
3238
3239 void CodeBlock::unlinkIncomingCalls()
3240 {
3241     while (m_incomingLLIntCalls.begin() != m_incomingLLIntCalls.end())
3242         m_incomingLLIntCalls.begin()->unlink();
3243 #if ENABLE(JIT)
3244     while (m_incomingCalls.begin() != m_incomingCalls.end())
3245         m_incomingCalls.begin()->unlink(*vm());
3246     while (m_incomingPolymorphicCalls.begin() != m_incomingPolymorphicCalls.end())
3247         m_incomingPolymorphicCalls.begin()->unlink(*vm());
3248 #endif // ENABLE(JIT)
3249 }
3250
3251 void CodeBlock::linkIncomingCall(ExecState* callerFrame, LLIntCallLinkInfo* incoming)
3252 {
3253     noticeIncomingCall(callerFrame);
3254     m_incomingLLIntCalls.push(incoming);
3255 }
3256
3257 CodeBlock* CodeBlock::newReplacement()
3258 {
3259     return ownerScriptExecutable()->newReplacementCodeBlockFor(specializationKind());
3260 }
3261
3262 #if ENABLE(JIT)
3263 CodeBlock* CodeBlock::replacement()
3264 {
3265     const ClassInfo* classInfo = this->classInfo();
3266
3267     if (classInfo == FunctionCodeBlock::info())
3268         return jsCast<FunctionExecutable*>(ownerExecutable())->codeBlockFor(m_isConstructor ? CodeForConstruct : CodeForCall);
3269
3270     if (classInfo == EvalCodeBlock::info())
3271         return jsCast<EvalExecutable*>(ownerExecutable())->codeBlock();
3272
3273     if (classInfo == ProgramCodeBlock::info())
3274         return jsCast<ProgramExecutable*>(ownerExecutable())->codeBlock();
3275
3276     if (classInfo == ModuleProgramCodeBlock::info())
3277         return jsCast<ModuleProgramExecutable*>(ownerExecutable())->codeBlock();
3278
3279 #if ENABLE(WEBASSEMBLY)
3280     if (classInfo == WebAssemblyCodeBlock::info())
3281         return nullptr;
3282 #endif
3283
3284     RELEASE_ASSERT_NOT_REACHED();
3285     return nullptr;
3286 }
3287
3288 DFG::CapabilityLevel CodeBlock::computeCapabilityLevel()
3289 {
3290     const ClassInfo* classInfo = this->classInfo();
3291
3292     if (classInfo == FunctionCodeBlock::info()) {
3293         if (m_isConstructor)
3294             return DFG::functionForConstructCapabilityLevel(this);
3295         return DFG::functionForCallCapabilityLevel(this);
3296     }
3297
3298     if (classInfo == EvalCodeBlock::info())
3299         return DFG::evalCapabilityLevel(this);
3300
3301     if (classInfo == ProgramCodeBlock::info())
3302         return DFG::programCapabilityLevel(this);
3303
3304     if (classInfo == ModuleProgramCodeBlock::info())
3305         return DFG::programCapabilityLevel(this);
3306
3307 #if ENABLE(WEBASSEMBLY)
3308     if (classInfo == WebAssemblyCodeBlock::info())
3309         return DFG::CannotCompile;
3310 #endif
3311
3312     RELEASE_ASSERT_NOT_REACHED();
3313     return DFG::CannotCompile;
3314 }
3315
3316 #endif // ENABLE(JIT)
3317
3318 void CodeBlock::jettison(Profiler::JettisonReason reason, ReoptimizationMode mode, const FireDetail* detail)
3319 {
3320 #if !ENABLE(DFG_JIT)
3321     UNUSED_PARAM(mode);
3322     UNUSED_PARAM(detail);
3323 #endif
3324     
3325     CODEBLOCK_LOG_EVENT(this, "jettison", ("due to ", reason, ", counting = ", mode == CountReoptimization, ", detail = ", pointerDump(detail)));
3326
3327     RELEASE_ASSERT(reason != Profiler::NotJettisoned);
3328     
3329 #if ENABLE(DFG_JIT)
3330     if (DFG::shouldDumpDisassembly()) {
3331         dataLog("Jettisoning ", *this);
3332         if (mode == CountReoptimization)
3333             dataLog(" and counting reoptimization");
3334         dataLog(" due to ", reason);
3335         if (detail)
3336             dataLog(", ", *detail);
3337         dataLog(".\n");
3338     }
3339     
3340     if (reason == Profiler::JettisonDueToWeakReference) {
3341         if (DFG::shouldDumpDisassembly()) {
3342             dataLog(*this, " will be jettisoned because of the following dead references:\n");
3343             DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
3344             for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
3345                 DFG::WeakReferenceTransition& transition = dfgCommon->transitions[i];
3346                 JSCell* origin = transition.m_codeOrigin.get();
3347                 JSCell* from = transition.m_from.get();
3348                 JSCell* to = transition.m_to.get();
3349                 if ((!origin || Heap::isMarked(origin)) && Heap::isMarked(from))
3350                     continue;
3351                 dataLog("    Transition under ", RawPointer(origin), ", ", RawPointer(from), " -> ", RawPointer(to), ".\n");
3352             }
3353             for (unsigned i = 0; i < dfgCommon->weakReferences.size(); ++i) {
3354                 JSCell* weak = dfgCommon->weakReferences[i].get();
3355                 if (Heap::isMarked(weak))
3356                     continue;
3357                 dataLog("    Weak reference ", RawPointer(weak), ".\n");
3358             }
3359         }
3360     }
3361 #endif // ENABLE(DFG_JIT)
3362
3363     DeferGCForAWhile deferGC(*heap());
3364     
3365     // We want to accomplish two things here:
3366     // 1) Make sure that if this CodeBlock is on the stack right now, then if we return to it
3367     //    we should OSR exit at the top of the next bytecode instruction after the return.
3368     // 2) Make sure that if we call the owner executable, then we shouldn't call this CodeBlock.
3369
3370 #if ENABLE(DFG_JIT)
3371     if (reason != Profiler::JettisonDueToOldAge) {
3372         if (Profiler::Compilation* compilation = jitCode()->dfgCommon()->compilation.get())
3373             compilation->setJettisonReason(reason, detail);
3374         
3375         // This accomplishes (1), and does its own book-keeping about whether it has already happened.
3376         if (!jitCode()->dfgCommon()->invalidate()) {
3377             // We've already been invalidated.
3378             RELEASE_ASSERT(this != replacement());
3379             return;
3380         }
3381     }
3382     
3383     if (DFG::shouldDumpDisassembly())
3384         dataLog("    Did invalidate ", *this, "\n");
3385     
3386     // Count the reoptimization if that's what the user wanted.
3387     if (mode == CountReoptimization) {
3388         // FIXME: Maybe this should call alternative().
3389         // https://bugs.webkit.org/show_bug.cgi?id=123677
3390         baselineAlternative()->countReoptimization();
3391         if (DFG::shouldDumpDisassembly())
3392             dataLog("    Did count reoptimization for ", *this, "\n");
3393     }
3394     
3395     if (this != replacement()) {
3396         // This means that we were never the entrypoint. This can happen for OSR entry code
3397         // blocks.
3398         return;
3399     }
3400
3401     if (alternative())
3402         alternative()->optimizeAfterWarmUp();
3403
3404     if (reason != Profiler::JettisonDueToOldAge)
3405         tallyFrequentExitSites();
3406 #endif // ENABLE(DFG_JIT)
3407
3408     // This accomplishes (2).
3409     ownerScriptExecutable()->installCode(
3410         m_globalObject->vm(), alternative(), codeType(), specializationKind());
3411
3412 #if ENABLE(DFG_JIT)
3413     if (DFG::shouldDumpDisassembly())
3414         dataLog("    Did install baseline version of ", *this, "\n");
3415 #endif // ENABLE(DFG_JIT)
3416 }
3417
3418 JSGlobalObject* CodeBlock::globalObjectFor(CodeOrigin codeOrigin)
3419 {
3420     if (!codeOrigin.inlineCallFrame)
3421         return globalObject();
3422     return codeOrigin.inlineCallFrame->baselineCodeBlock->globalObject();
3423 }
3424
3425 class RecursionCheckFunctor {
3426 public:
3427     RecursionCheckFunctor(CallFrame* startCallFrame, CodeBlock* codeBlock, unsigned depthToCheck)
3428         : m_startCallFrame(startCallFrame)
3429         , m_codeBlock(codeBlock)
3430         , m_depthToCheck(depthToCheck)
3431         , m_foundStartCallFrame(false)
3432         , m_didRecurse(false)
3433     { }
3434
3435     StackVisitor::Status operator()(StackVisitor& visitor) const
3436     {
3437         CallFrame* currentCallFrame = visitor->callFrame();
3438
3439         if (currentCallFrame == m_startCallFrame)
3440             m_foundStartCallFrame = true;
3441
3442         if (m_foundStartCallFrame) {
3443             if (visitor->callFrame()->codeBlock() == m_codeBlock) {
3444                 m_didRecurse = true;
3445                 return StackVisitor::Done;
3446             }
3447
3448             if (!m_depthToCheck--)
3449                 return StackVisitor::Done;
3450         }
3451
3452         return StackVisitor::Continue;
3453     }
3454
3455     bool didRecurse() const { return m_didRecurse; }
3456
3457 private:
3458     CallFrame* m_startCallFrame;
3459     CodeBlock* m_codeBlock;
3460     mutable unsigned m_depthToCheck;
3461     mutable bool m_foundStartCallFrame;
3462     mutable bool m_didRecurse;
3463 };
3464
3465 void CodeBlock::noticeIncomingCall(ExecState* callerFrame)
3466 {
3467     CodeBlock* callerCodeBlock = callerFrame->codeBlock();
3468     
3469     if (Options::verboseCallLink())
3470         dataLog("Noticing call link from ", pointerDump(callerCodeBlock), " to ", *this, "\n");
3471     
3472 #if ENABLE(DFG_JIT)
3473     if (!m_shouldAlwaysBeInlined)
3474         return;
3475     
3476     if (!callerCodeBlock) {
3477         m_shouldAlwaysBeInlined = false;
3478         if (Options::verboseCallLink())
3479             dataLog("    Clearing SABI because caller is native.\n");
3480         return;
3481     }
3482
3483     if (!hasBaselineJITProfiling())
3484         return;
3485
3486     if (!DFG::mightInlineFunction(this))
3487         return;
3488
3489     if (!canInline(capabilityLevelState()))
3490         return;
3491     
3492     if (!DFG::isSmallEnoughToInlineCodeInto(callerCodeBlock)) {
3493         m_shouldAlwaysBeInlined = false;
3494         if (Options::verboseCallLink())
3495             dataLog("    Clearing SABI because caller is too large.\n");
3496         return;
3497     }
3498
3499     if (callerCodeBlock->jitType() == JITCode::InterpreterThunk) {
3500         // If the caller is still in the interpreter, then we can't expect inlining to
3501         // happen anytime soon. Assume it's profitable to optimize it separately. This
3502         // ensures that a function is SABI only if it is called no more frequently than
3503         // any of its callers.
3504         m_shouldAlwaysBeInlined = false;
3505         if (Options::verboseCallLink())
3506             dataLog("    Clearing SABI because caller is in LLInt.\n");
3507         return;
3508     }
3509     
3510     if (JITCode::isOptimizingJIT(callerCodeBlock->jitType())) {
3511         m_shouldAlwaysBeInlined = false;
3512         if (Options::verboseCallLink())
3513             dataLog("    Clearing SABI bcause caller was already optimized.\n");
3514         return;
3515     }
3516     
3517     if (callerCodeBlock->codeType() != FunctionCode) {
3518         // If the caller is either eval or global code, assume that that won't be
3519         // optimized anytime soon. For eval code this is particularly true since we
3520         // delay eval optimization by a *lot*.
3521         m_shouldAlwaysBeInlined = false;
3522         if (Options::verboseCallLink())
3523             dataLog("    Clearing SABI because caller is not a function.\n");
3524         return;
3525     }
3526
3527     // Recursive calls won't be inlined.
3528     RecursionCheckFunctor functor(callerFrame, this, Options::maximumInliningDepth());
3529     vm()->topCallFrame->iterate(functor);
3530
3531     if (functor.didRecurse()) {
3532         if (Options::verboseCallLink())
3533             dataLog("    Clearing SABI because recursion was detected.\n");
3534         m_shouldAlwaysBeInlined = false;
3535         return;
3536     }
3537     
3538     if (callerCodeBlock->capabilityLevelState() == DFG::CapabilityLevelNotSet) {
3539         dataLog("In call from ", *callerCodeBlock, " ", callerFrame->codeOrigin(), " to ", *this, ": caller's DFG capability level is not set.\n");
3540         CRASH();
3541     }
3542     
3543     if (canCompile(callerCodeBlock->capabilityLevelState()))
3544         return;
3545     
3546     if (Options::verboseCallLink())
3547         dataLog("    Clearing SABI because the caller is not a DFG candidate.\n");
3548     
3549     m_shouldAlwaysBeInlined = false;
3550 #endif
3551 }
3552
3553 unsigned CodeBlock::reoptimizationRetryCounter() const
3554 {
3555 #if ENABLE(JIT)
3556     ASSERT(m_reoptimizationRetryCounter <= Options::reoptimizationRetryCounterMax());
3557     return m_reoptimizationRetryCounter;
3558 #else
3559     return 0;
3560 #endif // ENABLE(JIT)
3561 }
3562
3563 #if ENABLE(JIT)
3564 void CodeBlock::setCalleeSaveRegisters(RegisterSet calleeSaveRegisters)
3565 {
3566     m_calleeSaveRegisters = std::make_unique<RegisterAtOffsetList>(calleeSaveRegisters);
3567 }
3568
3569 void CodeBlock::setCalleeSaveRegisters(std::unique_ptr<RegisterAtOffsetList> registerAtOffsetList)
3570 {
3571     m_calleeSaveRegisters = WTFMove(registerAtOffsetList);
3572 }
3573     
3574 static size_t roundCalleeSaveSpaceAsVirtualRegisters(size_t calleeSaveRegisters)
3575 {
3576     static const unsigned cpuRegisterSize = sizeof(void*);
3577     return (WTF::roundUpToMultipleOf(sizeof(Register), calleeSaveRegisters * cpuRegisterSize) / sizeof(Register));
3578
3579 }
3580
3581 size_t CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters()
3582 {
3583     return roundCalleeSaveSpaceAsVirtualRegisters(numberOfLLIntBaselineCalleeSaveRegisters());
3584 }
3585
3586 size_t CodeBlock::calleeSaveSpaceAsVirtualRegisters()
3587 {
3588     return roundCalleeSaveSpaceAsVirtualRegisters(m_calleeSaveRegisters->size());
3589 }
3590
3591 void CodeBlock::countReoptimization()
3592 {
3593     m_reoptimizationRetryCounter++;
3594     if (m_reoptimizationRetryCounter > Options::reoptimizationRetryCounterMax())
3595         m_reoptimizationRetryCounter = Options::reoptimizationRetryCounterMax();
3596 }
3597
3598 unsigned CodeBlock::numberOfDFGCompiles()
3599 {
3600     ASSERT(JITCode::isBaselineCode(jitType()));
3601     if (Options::testTheFTL()) {
3602         if (m_didFailFTLCompilation)
3603             return 1000000;
3604         return (m_hasBeenCompiledWithFTL ? 1 : 0) + m_reoptimizationRetryCounter;
3605     }
3606     return (JITCode::isOptimizingJIT(replacement()->jitType()) ? 1 : 0) + m_reoptimizationRetryCounter;
3607 }
3608
3609 int32_t CodeBlock::codeTypeThresholdMultiplier() const
3610 {
3611     if (codeType() == EvalCode)
3612         return Options::evalThresholdMultiplier();
3613     
3614     return 1;
3615 }
3616
3617 double CodeBlock::optimizationThresholdScalingFactor()
3618 {
3619     // This expression arises from doing a least-squares fit of
3620     //
3621     // F[x_] =: a * Sqrt[x + b] + Abs[c * x] + d
3622     //
3623     // against the data points:
3624     //
3625     //    x       F[x_]
3626     //    10       0.9          (smallest reasonable code block)
3627     //   200       1.0          (typical small-ish code block)
3628     //   320       1.2          (something I saw in 3d-cube that I wanted to optimize)
3629     //  1268       5.0          (something I saw in 3d-cube that I didn't want to optimize)
3630     //  4000       5.5          (random large size, used to cause the function to converge to a shallow curve of some sort)
3631     // 10000       6.0          (similar to above)
3632     //
3633     // I achieve the minimization using the following Mathematica code:
3634     //
3635     // MyFunctionTemplate[x_, a_, b_, c_, d_] := a*Sqrt[x + b] + Abs[c*x] + d
3636     //
3637     // samples = {{10, 0.9}, {200, 1}, {320, 1.2}, {1268, 5}, {4000, 5.5}, {10000, 6}}
3638     //
3639     // solution = 
3640     //     Minimize[Plus @@ ((MyFunctionTemplate[#[[1]], a, b, c, d] - #[[2]])^2 & /@ samples),
3641     //         {a, b, c, d}][[2]]
3642     //
3643     // And the code below (to initialize a, b, c, d) is generated by:
3644     //
3645     // Print["const double " <> ToString[#[[1]]] <> " = " <>
3646     //     If[#[[2]] < 0.00001, "0.0", ToString[#[[2]]]] <> ";"] & /@ solution
3647     //
3648     // We've long known the following to be true:
3649     // - Small code blocks are cheap to optimize and so we should do it sooner rather
3650     //   than later.
3651     // - Large code blocks are expensive to optimize and so we should postpone doing so,
3652     //   and sometimes have a large enough threshold that we never optimize them.
3653     // - The difference in cost is not totally linear because (a) just invoking the
3654     //   DFG incurs some base cost and (b) for large code blocks there is enough slop
3655     //   in the correlation between instruction count and the actual compilation cost
3656     //   that for those large blocks, the instruction count should not have a strong
3657     //   influence on our threshold.
3658     //
3659     // I knew the goals but I didn't know how to achieve them; so I picked an interesting
3660     // example where the heuristics were right (code block in 3d-cube with instruction
3661     // count 320, which got compiled early as it should have been) and one where they were
3662     // totally wrong (code block in 3d-cube with instruction count 1268, which was expensive
3663     // to compile and didn't run often enough to warrant compilation in my opinion), and
3664     // then threw in additional data points that represented my own guess of what our
3665     // heuristics should do for some round-numbered examples.
3666     //
3667     // The expression to which I decided to fit the data arose because I started with an
3668     // affine function, and then did two things: put the linear part in an Abs to ensure
3669     // that the fit didn't end up choosing a negative value of c (which would result in
3670     // the function turning over and going negative for large x) and I threw in a Sqrt
3671     // term because Sqrt represents my intution that the function should be more sensitive
3672     // to small changes in small values of x, but less sensitive when x gets large.
3673     
3674     // Note that the current fit essentially eliminates the linear portion of the
3675     // expression (c == 0.0).
3676     const double a = 0.061504;
3677     const double b = 1.02406;
3678     const double c = 0.0;
3679     const double d = 0.825914;
3680     
3681     double instructionCount = this->instructionCount();
3682     
3683     ASSERT(instructionCount); // Make sure this is called only after we have an instruction stream; otherwise it'll just return the value of d, which makes no sense.
3684     
3685     double result = d + a * sqrt(instructionCount + b) + c * instructionCount;
3686     
3687     result *= codeTypeThresholdMultiplier();
3688     
3689     if (Options::verboseOSR()) {
3690         dataLog(
3691             *this, ": instruction count is ", instructionCount,
3692             ", scaling execution counter by ", result, " * ", codeTypeThresholdMultiplier(),
3693             "\n");
3694     }
3695     return result;
3696 }
3697
3698 static int32_t clipThreshold(double threshold)
3699 {
3700     if (threshold < 1.0)
3701         return 1;
3702     
3703     if (threshold > static_cast<double>(std::numeric_limits<int32_t>::max()))
3704         return std::numeric_limits<int32_t>::max();
3705     
3706     return static_cast<int32_t>(threshold);
3707 }
3708
3709 int32_t CodeBlock::adjustedCounterValue(int32_t desiredThreshold)
3710 {
3711     return clipThreshold(
3712         static_cast<double>(desiredThreshold) *
3713         optimizationThresholdScalingFactor() *
3714         (1 << reoptimizationRetryCounter()));
3715 }
3716
3717 bool CodeBlock::checkIfOptimizationThresholdReached()
3718 {
3719 #if ENABLE(DFG_JIT)
3720     if (DFG::Worklist* worklist = DFG::existingGlobalDFGWorklistOrNull()) {
3721         if (worklist->compilationState(DFG::CompilationKey(this, DFG::DFGMode))
3722             == DFG::Worklist::Compiled) {
3723             optimizeNextInvocation();
3724             return true;
3725         }
3726     }
3727 #endif
3728     
3729     return m_jitExecuteCounter.checkIfThresholdCrossedAndSet(this);
3730 }
3731
3732 void CodeBlock::optimizeNextInvocation()
3733 {
3734     if (Options::verboseOSR())
3735         dataLog(*this, ": Optimizing next invocation.\n");
3736     m_jitExecuteCounter.setNewThreshold(0, this);
3737 }
3738
3739 void CodeBlock::dontOptimizeAnytimeSoon()
3740 {
3741     if (Options::verboseOSR())
3742         dataLog(*this, ": Not optimizing anytime soon.\n");
3743     m_jitExecuteCounter.deferIndefinitely();
3744 }
3745
3746 void CodeBlock::optimizeAfterWarmUp()
3747 {
3748     if (Options::verboseOSR())
3749         dataLog(*this, ": Optimizing after warm-up.\n");
3750 #if ENABLE(DFG_JIT)
3751     m_jitExecuteCounter.setNewThreshold(
3752         adjustedCounterValue(Options::thresholdForOptimizeAfterWarmUp()), this);
3753 #endif
3754 }
3755
3756 void CodeBlock::optimizeAfterLongWarmUp()
3757 {
3758     if (Options::verboseOSR())
3759         dataLog(*this, ": Optimizing after long warm-up.\n");
3760 #if ENABLE(DFG_JIT)
3761     m_jitExecuteCounter.setNewThreshold(
3762         adjustedCounterValue(Options::thresholdForOptimizeAfterLongWarmUp()), this);
3763 #endif
3764 }
3765
3766 void CodeBlock::optimizeSoon()
3767 {
3768     if (Options::verboseOSR())
3769         dataLog(*this, ": Optimizing soon.\n");
3770 #if ENABLE(DFG_JIT)
3771     m_jitExecuteCounter.setNewThreshold(
3772         adjustedCounterValue(Options::thresholdForOptimizeSoon()), this);
3773 #endif
3774 }
3775
3776 void CodeBlock::forceOptimizationSlowPathConcurrently()
3777 {
3778     if (Options::verboseOSR())
3779         dataLog(*this, ": Forcing slow path concurrently.\n");
3780     m_jitExecuteCounter.forceSlowPathConcurrently();
3781 }
3782
3783 #if ENABLE(DFG_JIT)
3784 void CodeBlock::setOptimizationThresholdBasedOnCompilationResult(CompilationResult result)
3785 {
3786     JITCode::JITType type = jitType();
3787     if (type != JITCode::BaselineJIT) {
3788         dataLog(*this, ": expected to have baseline code but have ", type, "\n");
3789         RELEASE_ASSERT_NOT_REACHED();
3790     }
3791     
3792     CodeBlock* theReplacement = replacement();
3793     if ((result == CompilationSuccessful) != (theReplacement != this)) {
3794         dataLog(*this, ": we have result = ", result, " but ");
3795         if (theReplacement == this)
3796             dataLog("we are our own replacement.\n");
3797         else
3798             dataLog("our replacement is ", pointerDump(theReplacement), "\n");
3799         RELEASE_ASSERT_NOT_REACHED();
3800     }
3801     
3802     switch (result) {
3803     case CompilationSuccessful:
3804         RELEASE_ASSERT(JITCode::isOptimizingJIT(replacement()->jitType()));
3805         optimizeNextInvocation();
3806         return;
3807     case CompilationFailed:
3808         dontOptimizeAnytimeSoon();
3809         return;
3810     case CompilationDeferred:
3811         // We'd like to do dontOptimizeAnytimeSoon() but we cannot because
3812         // forceOptimizationSlowPathConcurrently() is inherently racy. It won't
3813         // necessarily guarantee anything. So, we make sure that even if that
3814         // function ends up being a no-op, we still eventually retry and realize
3815         // that we have optimized code ready.
3816         optimizeAfterWarmUp();
3817         return;
3818     case CompilationInvalidated:
3819         // Retry with exponential backoff.
3820         countReoptimization();
3821         optimizeAfterWarmUp();
3822         return;
3823     }
3824     
3825     dataLog("Unrecognized result: ", static_cast<int>(result), "\n");
3826     RELEASE_ASSERT_NOT_REACHED();
3827 }
3828
3829 #endif
3830     
3831 uint32_t CodeBlock::adjustedExitCountThreshold(uint32_t desiredThreshold)
3832 {
3833     ASSERT(JITCode::isOptimizingJIT(jitType()));
3834     // Compute this the lame way so we don't saturate. This is called infrequently
3835     // enough that this loop won't hurt us.
3836     unsigned result = desiredThreshold;
3837     for (unsigned&n