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