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