We should be able to eliminate rest parameter allocations
[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         case op_create_rest: {
2364             int numberOfArgumentsToSkip = instructions[i + 3].u.operand;
2365             ASSERT_UNUSED(numberOfArgumentsToSkip, numberOfArgumentsToSkip >= 0);
2366             ASSERT_WITH_MESSAGE(numberOfArgumentsToSkip == numParameters() - 1, "We assume that this is true when rematerializing the rest parameter during OSR exit in the FTL JIT.");
2367             break;
2368         }
2369
2370         default:
2371             break;
2372         }
2373         i += opLength;
2374     }
2375
2376     if (vm.controlFlowProfiler())
2377         insertBasicBlockBoundariesForControlFlowProfiler(instructions);
2378
2379     m_instructions = WTFMove(instructions);
2380
2381     // Set optimization thresholds only after m_instructions is initialized, since these
2382     // rely on the instruction count (and are in theory permitted to also inspect the
2383     // instruction stream to more accurate assess the cost of tier-up).
2384     optimizeAfterWarmUp();
2385     jitAfterWarmUp();
2386
2387     // If the concurrent thread will want the code block's hash, then compute it here
2388     // synchronously.
2389     if (Options::alwaysComputeHash())
2390         hash();
2391
2392     if (Options::dumpGeneratedBytecodes())
2393         dumpBytecode();
2394     
2395     heap()->m_codeBlocks->add(this);
2396     heap()->reportExtraMemoryAllocated(m_instructions.size() * sizeof(Instruction));
2397 }
2398
2399 #if ENABLE(WEBASSEMBLY)
2400 CodeBlock::CodeBlock(VM* vm, Structure* structure, WebAssemblyExecutable* ownerExecutable, JSGlobalObject* globalObject)
2401     : JSCell(*vm, structure)
2402     , m_globalObject(globalObject->vm(), this, globalObject)
2403     , m_numCalleeLocals(0)
2404     , m_numVars(0)
2405     , m_shouldAlwaysBeInlined(false)
2406 #if ENABLE(JIT)
2407     , m_capabilityLevelState(DFG::CannotCompile)
2408 #endif
2409     , m_didFailJITCompilation(false)
2410     , m_didFailFTLCompilation(false)
2411     , m_hasBeenCompiledWithFTL(false)
2412     , m_isConstructor(false)
2413     , m_isStrictMode(false)
2414     , m_codeType(FunctionCode)
2415     , m_hasDebuggerStatement(false)
2416     , m_steppingMode(SteppingModeDisabled)
2417     , m_numBreakpoints(0)
2418     , m_ownerExecutable(m_globalObject->vm(), this, ownerExecutable)
2419     , m_vm(vm)
2420     , m_osrExitCounter(0)
2421     , m_optimizationDelayCounter(0)
2422     , m_reoptimizationRetryCounter(0)
2423     , m_creationTime(std::chrono::steady_clock::now())
2424 {
2425     ASSERT(heap()->isDeferred());
2426 }
2427
2428 void CodeBlock::finishCreation(VM& vm, WebAssemblyExecutable*, JSGlobalObject*)
2429 {
2430     Base::finishCreation(vm);
2431
2432     heap()->m_codeBlocks->add(this);
2433 }
2434 #endif
2435
2436 CodeBlock::~CodeBlock()
2437 {
2438     if (m_vm->m_perBytecodeProfiler)
2439         m_vm->m_perBytecodeProfiler->notifyDestruction(this);
2440
2441     if (unlinkedCodeBlock()->didOptimize() == MixedTriState)
2442         unlinkedCodeBlock()->setDidOptimize(FalseTriState);
2443
2444 #if ENABLE(VERBOSE_VALUE_PROFILE)
2445     dumpValueProfiles();
2446 #endif
2447
2448     // We may be destroyed before any CodeBlocks that refer to us are destroyed.
2449     // Consider that two CodeBlocks become unreachable at the same time. There
2450     // is no guarantee about the order in which the CodeBlocks are destroyed.
2451     // So, if we don't remove incoming calls, and get destroyed before the
2452     // CodeBlock(s) that have calls into us, then the CallLinkInfo vector's
2453     // destructor will try to remove nodes from our (no longer valid) linked list.
2454     unlinkIncomingCalls();
2455     
2456     // Note that our outgoing calls will be removed from other CodeBlocks'
2457     // m_incomingCalls linked lists through the execution of the ~CallLinkInfo
2458     // destructors.
2459
2460 #if ENABLE(JIT)
2461     for (Bag<StructureStubInfo>::iterator iter = m_stubInfos.begin(); !!iter; ++iter) {
2462         StructureStubInfo* stub = *iter;
2463         stub->aboutToDie();
2464         stub->deref();
2465     }
2466 #endif // ENABLE(JIT)
2467 }
2468
2469 void CodeBlock::setConstantRegisters(const Vector<WriteBarrier<Unknown>>& constants, const Vector<SourceCodeRepresentation>& constantsSourceCodeRepresentation)
2470 {
2471     ASSERT(constants.size() == constantsSourceCodeRepresentation.size());
2472     size_t count = constants.size();
2473     m_constantRegisters.resizeToFit(count);
2474     bool hasTypeProfiler = !!m_vm->typeProfiler();
2475     for (size_t i = 0; i < count; i++) {
2476         JSValue constant = constants[i].get();
2477
2478         if (!constant.isEmpty()) {
2479             if (SymbolTable* symbolTable = jsDynamicCast<SymbolTable*>(constant)) {
2480                 if (hasTypeProfiler) {
2481                     ConcurrentJITLocker locker(symbolTable->m_lock);
2482                     symbolTable->prepareForTypeProfiling(locker);
2483                 }
2484
2485                 SymbolTable* clone = symbolTable->cloneScopePart(*m_vm);
2486                 if (wasCompiledWithDebuggingOpcodes())
2487                     clone->setRareDataCodeBlock(this);
2488
2489                 constant = clone;
2490             }
2491         }
2492
2493         m_constantRegisters[i].set(*m_vm, this, constant);
2494     }
2495
2496     m_constantsSourceCodeRepresentation = constantsSourceCodeRepresentation;
2497 }
2498
2499 void CodeBlock::setAlternative(VM& vm, CodeBlock* alternative)
2500 {
2501     m_alternative.set(vm, this, alternative);
2502 }
2503
2504 void CodeBlock::setNumParameters(int newValue)
2505 {
2506     m_numParameters = newValue;
2507
2508     m_argumentValueProfiles = RefCountedArray<ValueProfile>(newValue);
2509 }
2510
2511 void EvalCodeCache::visitAggregate(SlotVisitor& visitor)
2512 {
2513     EvalCacheMap::iterator end = m_cacheMap.end();
2514     for (EvalCacheMap::iterator ptr = m_cacheMap.begin(); ptr != end; ++ptr)
2515         visitor.append(&ptr->value);
2516 }
2517
2518 CodeBlock* CodeBlock::specialOSREntryBlockOrNull()
2519 {
2520 #if ENABLE(FTL_JIT)
2521     if (jitType() != JITCode::DFGJIT)
2522         return 0;
2523     DFG::JITCode* jitCode = m_jitCode->dfg();
2524     return jitCode->osrEntryBlock();
2525 #else // ENABLE(FTL_JIT)
2526     return 0;
2527 #endif // ENABLE(FTL_JIT)
2528 }
2529
2530 void CodeBlock::visitWeakly(SlotVisitor& visitor)
2531 {
2532     bool setByMe = m_visitWeaklyHasBeenCalled.compareExchangeStrong(false, true);
2533     if (!setByMe)
2534         return;
2535
2536     if (Heap::isMarkedConcurrently(this))
2537         return;
2538
2539     if (shouldVisitStrongly()) {
2540         visitor.appendUnbarrieredReadOnlyPointer(this);
2541         return;
2542     }
2543
2544     // There are two things that may use unconditional finalizers: inline cache clearing
2545     // and jettisoning. The probability of us wanting to do at least one of those things
2546     // is probably quite close to 1. So we add one no matter what and when it runs, it
2547     // figures out whether it has any work to do.
2548     visitor.addUnconditionalFinalizer(&m_unconditionalFinalizer);
2549
2550     if (!JITCode::isOptimizingJIT(jitType()))
2551         return;
2552
2553     // If we jettison ourselves we'll install our alternative, so make sure that it
2554     // survives GC even if we don't.
2555     visitor.append(&m_alternative);
2556     
2557     // There are two things that we use weak reference harvesters for: DFG fixpoint for
2558     // jettisoning, and trying to find structures that would be live based on some
2559     // inline cache. So it makes sense to register them regardless.
2560     visitor.addWeakReferenceHarvester(&m_weakReferenceHarvester);
2561
2562 #if ENABLE(DFG_JIT)
2563     // We get here if we're live in the sense that our owner executable is live,
2564     // but we're not yet live for sure in another sense: we may yet decide that this
2565     // code block should be jettisoned based on its outgoing weak references being
2566     // stale. Set a flag to indicate that we're still assuming that we're dead, and
2567     // perform one round of determining if we're live. The GC may determine, based on
2568     // either us marking additional objects, or by other objects being marked for
2569     // other reasons, that this iteration should run again; it will notify us of this
2570     // decision by calling harvestWeakReferences().
2571
2572     m_allTransitionsHaveBeenMarked = false;
2573     propagateTransitions(visitor);
2574
2575     m_jitCode->dfgCommon()->livenessHasBeenProved = false;
2576     determineLiveness(visitor);
2577 #endif // ENABLE(DFG_JIT)
2578 }
2579
2580 size_t CodeBlock::estimatedSize(JSCell* cell)
2581 {
2582     CodeBlock* thisObject = jsCast<CodeBlock*>(cell);
2583     size_t extraMemoryAllocated = thisObject->m_instructions.size() * sizeof(Instruction);
2584     if (thisObject->m_jitCode)
2585         extraMemoryAllocated += thisObject->m_jitCode->size();
2586     return Base::estimatedSize(cell) + extraMemoryAllocated;
2587 }
2588
2589 void CodeBlock::visitChildren(JSCell* cell, SlotVisitor& visitor)
2590 {
2591     CodeBlock* thisObject = jsCast<CodeBlock*>(cell);
2592     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
2593     JSCell::visitChildren(thisObject, visitor);
2594     thisObject->visitChildren(visitor);
2595 }
2596
2597 void CodeBlock::visitChildren(SlotVisitor& visitor)
2598 {
2599     // There are two things that may use unconditional finalizers: inline cache clearing
2600     // and jettisoning. The probability of us wanting to do at least one of those things
2601     // is probably quite close to 1. So we add one no matter what and when it runs, it
2602     // figures out whether it has any work to do.
2603     visitor.addUnconditionalFinalizer(&m_unconditionalFinalizer);
2604
2605     if (CodeBlock* otherBlock = specialOSREntryBlockOrNull())
2606         visitor.appendUnbarrieredReadOnlyPointer(otherBlock);
2607
2608     if (m_jitCode)
2609         visitor.reportExtraMemoryVisited(m_jitCode->size());
2610     if (m_instructions.size())
2611         visitor.reportExtraMemoryVisited(m_instructions.size() * sizeof(Instruction) / m_instructions.refCount());
2612
2613     stronglyVisitStrongReferences(visitor);
2614     stronglyVisitWeakReferences(visitor);
2615
2616     m_allTransitionsHaveBeenMarked = false;
2617     propagateTransitions(visitor);
2618 }
2619
2620 bool CodeBlock::shouldVisitStrongly()
2621 {
2622     if (Options::forceCodeBlockLiveness())
2623         return true;
2624
2625     if (shouldJettisonDueToOldAge())
2626         return false;
2627
2628     // Interpreter and Baseline JIT CodeBlocks don't need to be jettisoned when
2629     // their weak references go stale. So if a basline JIT CodeBlock gets
2630     // scanned, we can assume that this means that it's live.
2631     if (!JITCode::isOptimizingJIT(jitType()))
2632         return true;
2633
2634     return false;
2635 }
2636
2637 bool CodeBlock::shouldJettisonDueToWeakReference()
2638 {
2639     if (!JITCode::isOptimizingJIT(jitType()))
2640         return false;
2641     return !Heap::isMarked(this);
2642 }
2643
2644 static std::chrono::milliseconds timeToLive(JITCode::JITType jitType)
2645 {
2646     if (UNLIKELY(Options::useEagerCodeBlockJettisonTiming())) {
2647         switch (jitType) {
2648         case JITCode::InterpreterThunk:
2649             return std::chrono::milliseconds(10);
2650         case JITCode::BaselineJIT:
2651             return std::chrono::milliseconds(10 + 20);
2652         case JITCode::DFGJIT:
2653             return std::chrono::milliseconds(40);
2654         case JITCode::FTLJIT:
2655             return std::chrono::milliseconds(120);
2656         default:
2657             return std::chrono::milliseconds::max();
2658         }
2659     }
2660
2661     switch (jitType) {
2662     case JITCode::InterpreterThunk:
2663         return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(5));
2664     case JITCode::BaselineJIT:
2665         // Effectively 10 additional seconds, since BaselineJIT and
2666         // InterpreterThunk share a CodeBlock.
2667         return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(5 + 10));
2668     case JITCode::DFGJIT:
2669         return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(20));
2670     case JITCode::FTLJIT:
2671         return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(60));
2672     default:
2673         return std::chrono::milliseconds::max();
2674     }
2675 }
2676
2677 bool CodeBlock::shouldJettisonDueToOldAge()
2678 {
2679     if (Heap::isMarkedConcurrently(this))
2680         return false;
2681
2682     if (UNLIKELY(Options::forceCodeBlockToJettisonDueToOldAge()))
2683         return true;
2684     
2685     if (timeSinceCreation() < timeToLive(jitType()))
2686         return false;
2687     
2688     return true;
2689 }
2690
2691 #if ENABLE(DFG_JIT)
2692 static bool shouldMarkTransition(DFG::WeakReferenceTransition& transition)
2693 {
2694     if (transition.m_codeOrigin && !Heap::isMarkedConcurrently(transition.m_codeOrigin.get()))
2695         return false;
2696     
2697     if (!Heap::isMarkedConcurrently(transition.m_from.get()))
2698         return false;
2699     
2700     return true;
2701 }
2702 #endif // ENABLE(DFG_JIT)
2703
2704 void CodeBlock::propagateTransitions(SlotVisitor& visitor)
2705 {
2706     UNUSED_PARAM(visitor);
2707
2708     if (m_allTransitionsHaveBeenMarked)
2709         return;
2710
2711     bool allAreMarkedSoFar = true;
2712         
2713     Interpreter* interpreter = m_vm->interpreter;
2714     if (jitType() == JITCode::InterpreterThunk) {
2715         const Vector<unsigned>& propertyAccessInstructions = m_unlinkedCode->propertyAccessInstructions();
2716         for (size_t i = 0; i < propertyAccessInstructions.size(); ++i) {
2717             Instruction* instruction = &instructions()[propertyAccessInstructions[i]];
2718             switch (interpreter->getOpcodeID(instruction[0].u.opcode)) {
2719             case op_put_by_id: {
2720                 StructureID oldStructureID = instruction[4].u.structureID;
2721                 StructureID newStructureID = instruction[6].u.structureID;
2722                 if (!oldStructureID || !newStructureID)
2723                     break;
2724                 Structure* oldStructure =
2725                     m_vm->heap.structureIDTable().get(oldStructureID);
2726                 Structure* newStructure =
2727                     m_vm->heap.structureIDTable().get(newStructureID);
2728                 if (Heap::isMarkedConcurrently(oldStructure))
2729                     visitor.appendUnbarrieredReadOnlyPointer(newStructure);
2730                 else
2731                     allAreMarkedSoFar = false;
2732                 break;
2733             }
2734             default:
2735                 break;
2736             }
2737         }
2738     }
2739
2740 #if ENABLE(JIT)
2741     if (JITCode::isJIT(jitType())) {
2742         for (Bag<StructureStubInfo>::iterator iter = m_stubInfos.begin(); !!iter; ++iter)
2743             allAreMarkedSoFar &= (*iter)->propagateTransitions(visitor);
2744     }
2745 #endif // ENABLE(JIT)
2746     
2747 #if ENABLE(DFG_JIT)
2748     if (JITCode::isOptimizingJIT(jitType())) {
2749         DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
2750         for (auto& weakReference : dfgCommon->weakStructureReferences)
2751             allAreMarkedSoFar &= weakReference->markIfCheap(visitor);
2752         
2753         for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
2754             if (shouldMarkTransition(dfgCommon->transitions[i])) {
2755                 // If the following three things are live, then the target of the
2756                 // transition is also live:
2757                 //
2758                 // - This code block. We know it's live already because otherwise
2759                 //   we wouldn't be scanning ourselves.
2760                 //
2761                 // - The code origin of the transition. Transitions may arise from
2762                 //   code that was inlined. They are not relevant if the user's
2763                 //   object that is required for the inlinee to run is no longer
2764                 //   live.
2765                 //
2766                 // - The source of the transition. The transition checks if some
2767                 //   heap location holds the source, and if so, stores the target.
2768                 //   Hence the source must be live for the transition to be live.
2769                 //
2770                 // We also short-circuit the liveness if the structure is harmless
2771                 // to mark (i.e. its global object and prototype are both already
2772                 // live).
2773                 
2774                 visitor.append(&dfgCommon->transitions[i].m_to);
2775             } else
2776                 allAreMarkedSoFar = false;
2777         }
2778     }
2779 #endif // ENABLE(DFG_JIT)
2780     
2781     if (allAreMarkedSoFar)
2782         m_allTransitionsHaveBeenMarked = true;
2783 }
2784
2785 void CodeBlock::determineLiveness(SlotVisitor& visitor)
2786 {
2787     UNUSED_PARAM(visitor);
2788     
2789 #if ENABLE(DFG_JIT)
2790     // Check if we have any remaining work to do.
2791     DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
2792     if (dfgCommon->livenessHasBeenProved)
2793         return;
2794     
2795     // Now check all of our weak references. If all of them are live, then we
2796     // have proved liveness and so we scan our strong references. If at end of
2797     // GC we still have not proved liveness, then this code block is toast.
2798     bool allAreLiveSoFar = true;
2799     for (unsigned i = 0; i < dfgCommon->weakReferences.size(); ++i) {
2800         if (!Heap::isMarkedConcurrently(dfgCommon->weakReferences[i].get())) {
2801             allAreLiveSoFar = false;
2802             break;
2803         }
2804     }
2805     if (allAreLiveSoFar) {
2806         for (unsigned i = 0; i < dfgCommon->weakStructureReferences.size(); ++i) {
2807             if (!Heap::isMarkedConcurrently(dfgCommon->weakStructureReferences[i].get())) {
2808                 allAreLiveSoFar = false;
2809                 break;
2810             }
2811         }
2812     }
2813     
2814     // If some weak references are dead, then this fixpoint iteration was
2815     // unsuccessful.
2816     if (!allAreLiveSoFar)
2817         return;
2818     
2819     // All weak references are live. Record this information so we don't
2820     // come back here again, and scan the strong references.
2821     dfgCommon->livenessHasBeenProved = true;
2822     visitor.appendUnbarrieredReadOnlyPointer(this);
2823 #endif // ENABLE(DFG_JIT)
2824 }
2825
2826 void CodeBlock::WeakReferenceHarvester::visitWeakReferences(SlotVisitor& visitor)
2827 {
2828     CodeBlock* codeBlock =
2829         bitwise_cast<CodeBlock*>(
2830             bitwise_cast<char*>(this) - OBJECT_OFFSETOF(CodeBlock, m_weakReferenceHarvester));
2831
2832     codeBlock->propagateTransitions(visitor);
2833     codeBlock->determineLiveness(visitor);
2834 }
2835
2836 void CodeBlock::clearLLIntGetByIdCache(Instruction* instruction)
2837 {
2838     instruction[0].u.opcode = LLInt::getOpcode(op_get_by_id);
2839     instruction[4].u.pointer = nullptr;
2840     instruction[5].u.pointer = nullptr;
2841     instruction[6].u.pointer = nullptr;
2842 }
2843
2844 void CodeBlock::finalizeLLIntInlineCaches()
2845 {
2846 #if ENABLE(WEBASSEMBLY)
2847     if (m_ownerExecutable->isWebAssemblyExecutable())
2848         return;
2849 #endif
2850
2851     Interpreter* interpreter = m_vm->interpreter;
2852     const Vector<unsigned>& propertyAccessInstructions = m_unlinkedCode->propertyAccessInstructions();
2853     for (size_t size = propertyAccessInstructions.size(), i = 0; i < size; ++i) {
2854         Instruction* curInstruction = &instructions()[propertyAccessInstructions[i]];
2855         switch (interpreter->getOpcodeID(curInstruction[0].u.opcode)) {
2856         case op_get_by_id:
2857         case op_get_by_id_proto_load:
2858         case op_get_by_id_unset: {
2859             StructureID oldStructureID = curInstruction[4].u.structureID;
2860             if (!oldStructureID || Heap::isMarked(m_vm->heap.structureIDTable().get(oldStructureID)))
2861                 break;
2862             if (Options::verboseOSR())
2863                 dataLogF("Clearing LLInt property access.\n");
2864             clearLLIntGetByIdCache(curInstruction);
2865             break;
2866         }
2867         case op_put_by_id: {
2868             StructureID oldStructureID = curInstruction[4].u.structureID;
2869             StructureID newStructureID = curInstruction[6].u.structureID;
2870             StructureChain* chain = curInstruction[7].u.structureChain.get();
2871             if ((!oldStructureID || Heap::isMarked(m_vm->heap.structureIDTable().get(oldStructureID))) &&
2872                 (!newStructureID || Heap::isMarked(m_vm->heap.structureIDTable().get(newStructureID))) &&
2873                 (!chain || Heap::isMarked(chain)))
2874                 break;
2875             if (Options::verboseOSR())
2876                 dataLogF("Clearing LLInt put transition.\n");
2877             curInstruction[4].u.structureID = 0;
2878             curInstruction[5].u.operand = 0;
2879             curInstruction[6].u.structureID = 0;
2880             curInstruction[7].u.structureChain.clear();
2881             break;
2882         }
2883         case op_get_array_length:
2884             break;
2885         case op_to_this:
2886             if (!curInstruction[2].u.structure || Heap::isMarked(curInstruction[2].u.structure.get()))
2887                 break;
2888             if (Options::verboseOSR())
2889                 dataLogF("Clearing LLInt to_this with structure %p.\n", curInstruction[2].u.structure.get());
2890             curInstruction[2].u.structure.clear();
2891             curInstruction[3].u.toThisStatus = merge(
2892                 curInstruction[3].u.toThisStatus, ToThisClearedByGC);
2893             break;
2894         case op_create_this: {
2895             auto& cacheWriteBarrier = curInstruction[4].u.jsCell;
2896             if (!cacheWriteBarrier || cacheWriteBarrier.unvalidatedGet() == JSCell::seenMultipleCalleeObjects())
2897                 break;
2898             JSCell* cachedFunction = cacheWriteBarrier.get();
2899             if (Heap::isMarked(cachedFunction))
2900                 break;
2901             if (Options::verboseOSR())
2902                 dataLogF("Clearing LLInt create_this with cached callee %p.\n", cachedFunction);
2903             cacheWriteBarrier.clear();
2904             break;
2905         }
2906         case op_resolve_scope: {
2907             // Right now this isn't strictly necessary. Any symbol tables that this will refer to
2908             // are for outer functions, and we refer to those functions strongly, and they refer
2909             // to the symbol table strongly. But it's nice to be on the safe side.
2910             WriteBarrierBase<SymbolTable>& symbolTable = curInstruction[6].u.symbolTable;
2911             if (!symbolTable || Heap::isMarked(symbolTable.get()))
2912                 break;
2913             if (Options::verboseOSR())
2914                 dataLogF("Clearing dead symbolTable %p.\n", symbolTable.get());
2915             symbolTable.clear();
2916             break;
2917         }
2918         case op_get_from_scope:
2919         case op_put_to_scope: {
2920             GetPutInfo getPutInfo = GetPutInfo(curInstruction[4].u.operand);
2921             if (getPutInfo.resolveType() == GlobalVar || getPutInfo.resolveType() == GlobalVarWithVarInjectionChecks 
2922                 || getPutInfo.resolveType() == LocalClosureVar || getPutInfo.resolveType() == GlobalLexicalVar || getPutInfo.resolveType() == GlobalLexicalVarWithVarInjectionChecks)
2923                 continue;
2924             WriteBarrierBase<Structure>& structure = curInstruction[5].u.structure;
2925             if (!structure || Heap::isMarked(structure.get()))
2926                 break;
2927             if (Options::verboseOSR())
2928                 dataLogF("Clearing scope access with structure %p.\n", structure.get());
2929             structure.clear();
2930             break;
2931         }
2932         default:
2933             OpcodeID opcodeID = interpreter->getOpcodeID(curInstruction[0].u.opcode);
2934             ASSERT_WITH_MESSAGE_UNUSED(opcodeID, false, "Unhandled opcode in CodeBlock::finalizeUnconditionally, %s(%d) at bc %u", opcodeNames[opcodeID], opcodeID, propertyAccessInstructions[i]);
2935         }
2936     }
2937
2938     // We can't just remove all the sets when we clear the caches since we might have created a watchpoint set
2939     // then cleared the cache without GCing in between.
2940     m_llintGetByIdWatchpointMap.removeIf([](const StructureWatchpointMap::KeyValuePairType& pair) -> bool {
2941         return !Heap::isMarked(pair.key);
2942     });
2943
2944     for (unsigned i = 0; i < m_llintCallLinkInfos.size(); ++i) {
2945         if (m_llintCallLinkInfos[i].isLinked() && !Heap::isMarked(m_llintCallLinkInfos[i].callee.get())) {
2946             if (Options::verboseOSR())
2947                 dataLog("Clearing LLInt call from ", *this, "\n");
2948             m_llintCallLinkInfos[i].unlink();
2949         }
2950         if (!!m_llintCallLinkInfos[i].lastSeenCallee && !Heap::isMarked(m_llintCallLinkInfos[i].lastSeenCallee.get()))
2951             m_llintCallLinkInfos[i].lastSeenCallee.clear();
2952     }
2953 }
2954
2955 void CodeBlock::finalizeBaselineJITInlineCaches()
2956 {
2957 #if ENABLE(JIT)
2958     for (auto iter = callLinkInfosBegin(); !!iter; ++iter)
2959         (*iter)->visitWeak(*vm());
2960
2961     for (Bag<StructureStubInfo>::iterator iter = m_stubInfos.begin(); !!iter; ++iter) {
2962         StructureStubInfo& stubInfo = **iter;
2963         stubInfo.visitWeakReferences(this);
2964     }
2965 #endif
2966 }
2967
2968 void CodeBlock::UnconditionalFinalizer::finalizeUnconditionally()
2969 {
2970     CodeBlock* codeBlock = bitwise_cast<CodeBlock*>(
2971         bitwise_cast<char*>(this) - OBJECT_OFFSETOF(CodeBlock, m_unconditionalFinalizer));
2972
2973 #if ENABLE(DFG_JIT)
2974     if (codeBlock->shouldJettisonDueToWeakReference()) {
2975         codeBlock->jettison(Profiler::JettisonDueToWeakReference);
2976         return;
2977     }
2978 #endif // ENABLE(DFG_JIT)
2979
2980     if (codeBlock->shouldJettisonDueToOldAge()) {
2981         codeBlock->jettison(Profiler::JettisonDueToOldAge);
2982         return;
2983     }
2984
2985     if (JITCode::couldBeInterpreted(codeBlock->jitType()))
2986         codeBlock->finalizeLLIntInlineCaches();
2987
2988 #if ENABLE(JIT)
2989     if (!!codeBlock->jitCode())
2990         codeBlock->finalizeBaselineJITInlineCaches();
2991 #endif
2992 }
2993
2994 void CodeBlock::getStubInfoMap(const ConcurrentJITLocker&, StubInfoMap& result)
2995 {
2996 #if ENABLE(JIT)
2997     if (JITCode::isJIT(jitType()))
2998         toHashMap(m_stubInfos, getStructureStubInfoCodeOrigin, result);
2999 #else
3000     UNUSED_PARAM(result);
3001 #endif
3002 }
3003
3004 void CodeBlock::getStubInfoMap(StubInfoMap& result)
3005 {
3006     ConcurrentJITLocker locker(m_lock);
3007     getStubInfoMap(locker, result);
3008 }
3009
3010 void CodeBlock::getCallLinkInfoMap(const ConcurrentJITLocker&, CallLinkInfoMap& result)
3011 {
3012 #if ENABLE(JIT)
3013     if (JITCode::isJIT(jitType()))
3014         toHashMap(m_callLinkInfos, getCallLinkInfoCodeOrigin, result);
3015 #else
3016     UNUSED_PARAM(result);
3017 #endif
3018 }
3019
3020 void CodeBlock::getCallLinkInfoMap(CallLinkInfoMap& result)
3021 {
3022     ConcurrentJITLocker locker(m_lock);
3023     getCallLinkInfoMap(locker, result);
3024 }
3025
3026 void CodeBlock::getByValInfoMap(const ConcurrentJITLocker&, ByValInfoMap& result)
3027 {
3028 #if ENABLE(JIT)
3029     if (JITCode::isJIT(jitType())) {
3030         for (auto* byValInfo : m_byValInfos)
3031             result.add(CodeOrigin(byValInfo->bytecodeIndex), byValInfo);
3032     }
3033 #else
3034     UNUSED_PARAM(result);
3035 #endif
3036 }
3037
3038 void CodeBlock::getByValInfoMap(ByValInfoMap& result)
3039 {
3040     ConcurrentJITLocker locker(m_lock);
3041     getByValInfoMap(locker, result);
3042 }
3043
3044 #if ENABLE(JIT)
3045 StructureStubInfo* CodeBlock::addStubInfo(AccessType accessType)
3046 {
3047     ConcurrentJITLocker locker(m_lock);
3048     return m_stubInfos.add(accessType);
3049 }
3050
3051 JITAddIC* CodeBlock::addJITAddIC(ArithProfile* arithProfile)
3052 {
3053     return m_addICs.add(arithProfile);
3054 }
3055
3056 JITMulIC* CodeBlock::addJITMulIC(ArithProfile* arithProfile)
3057 {
3058     return m_mulICs.add(arithProfile);
3059 }
3060
3061 JITSubIC* CodeBlock::addJITSubIC(ArithProfile* arithProfile)
3062 {
3063     return m_subICs.add(arithProfile);
3064 }
3065
3066 JITNegIC* CodeBlock::addJITNegIC(ArithProfile* arithProfile)
3067 {
3068     return m_negICs.add(arithProfile);
3069 }
3070
3071 StructureStubInfo* CodeBlock::findStubInfo(CodeOrigin codeOrigin)
3072 {
3073     for (StructureStubInfo* stubInfo : m_stubInfos) {
3074         if (stubInfo->codeOrigin == codeOrigin)
3075             return stubInfo;
3076     }
3077     return nullptr;
3078 }
3079
3080 ByValInfo* CodeBlock::addByValInfo()
3081 {
3082     ConcurrentJITLocker locker(m_lock);
3083     return m_byValInfos.add();
3084 }
3085
3086 CallLinkInfo* CodeBlock::addCallLinkInfo()
3087 {
3088     ConcurrentJITLocker locker(m_lock);
3089     return m_callLinkInfos.add();
3090 }
3091
3092 CallLinkInfo* CodeBlock::getCallLinkInfoForBytecodeIndex(unsigned index)
3093 {
3094     for (auto iter = m_callLinkInfos.begin(); !!iter; ++iter) {
3095         if ((*iter)->codeOrigin() == CodeOrigin(index))
3096             return *iter;
3097     }
3098     return nullptr;
3099 }
3100
3101 void CodeBlock::resetJITData()
3102 {
3103     RELEASE_ASSERT(!JITCode::isJIT(jitType()));
3104     ConcurrentJITLocker locker(m_lock);
3105     
3106     // We can clear these because no other thread will have references to any stub infos, call
3107     // link infos, or by val infos if we don't have JIT code. Attempts to query these data
3108     // structures using the concurrent API (getStubInfoMap and friends) will return nothing if we
3109     // don't have JIT code.
3110     m_stubInfos.clear();
3111     m_callLinkInfos.clear();
3112     m_byValInfos.clear();
3113     
3114     // We can clear this because the DFG's queries to these data structures are guarded by whether
3115     // there is JIT code.
3116     m_rareCaseProfiles.clear();
3117 }
3118 #endif
3119
3120 void CodeBlock::visitOSRExitTargets(SlotVisitor& visitor)
3121 {
3122     // We strongly visit OSR exits targets because we don't want to deal with
3123     // the complexity of generating an exit target CodeBlock on demand and
3124     // guaranteeing that it matches the details of the CodeBlock we compiled
3125     // the OSR exit against.
3126
3127     visitor.append(&m_alternative);
3128
3129 #if ENABLE(DFG_JIT)
3130     DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
3131     if (dfgCommon->inlineCallFrames) {
3132         for (auto* inlineCallFrame : *dfgCommon->inlineCallFrames) {
3133             ASSERT(inlineCallFrame->baselineCodeBlock);
3134             visitor.append(&inlineCallFrame->baselineCodeBlock);
3135         }
3136     }
3137 #endif
3138 }
3139
3140 void CodeBlock::stronglyVisitStrongReferences(SlotVisitor& visitor)
3141 {
3142     visitor.append(&m_globalObject);
3143     visitor.append(&m_ownerExecutable);
3144     visitor.append(&m_unlinkedCode);
3145     if (m_rareData)
3146         m_rareData->m_evalCodeCache.visitAggregate(visitor);
3147     visitor.appendValues(m_constantRegisters.data(), m_constantRegisters.size());
3148     for (size_t i = 0; i < m_functionExprs.size(); ++i)
3149         visitor.append(&m_functionExprs[i]);
3150     for (size_t i = 0; i < m_functionDecls.size(); ++i)
3151         visitor.append(&m_functionDecls[i]);
3152     for (unsigned i = 0; i < m_objectAllocationProfiles.size(); ++i)
3153         m_objectAllocationProfiles[i].visitAggregate(visitor);
3154
3155 #if ENABLE(JIT)
3156     for (ByValInfo* byValInfo : m_byValInfos)
3157         visitor.append(&byValInfo->cachedSymbol);
3158 #endif
3159
3160 #if ENABLE(DFG_JIT)
3161     if (JITCode::isOptimizingJIT(jitType()))
3162         visitOSRExitTargets(visitor);
3163 #endif
3164
3165     updateAllPredictions();
3166 }
3167
3168 void CodeBlock::stronglyVisitWeakReferences(SlotVisitor& visitor)
3169 {
3170     UNUSED_PARAM(visitor);
3171
3172 #if ENABLE(DFG_JIT)
3173     if (!JITCode::isOptimizingJIT(jitType()))
3174         return;
3175     
3176     DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
3177
3178     for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
3179         if (!!dfgCommon->transitions[i].m_codeOrigin)
3180             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.
3181         visitor.append(&dfgCommon->transitions[i].m_from);
3182         visitor.append(&dfgCommon->transitions[i].m_to);
3183     }
3184     
3185     for (unsigned i = 0; i < dfgCommon->weakReferences.size(); ++i)
3186         visitor.append(&dfgCommon->weakReferences[i]);
3187
3188     for (unsigned i = 0; i < dfgCommon->weakStructureReferences.size(); ++i)
3189         visitor.append(&dfgCommon->weakStructureReferences[i]);
3190
3191     dfgCommon->livenessHasBeenProved = true;
3192 #endif    
3193 }
3194
3195 CodeBlock* CodeBlock::baselineAlternative()
3196 {
3197 #if ENABLE(JIT)
3198     CodeBlock* result = this;
3199     while (result->alternative())
3200         result = result->alternative();
3201     RELEASE_ASSERT(result);
3202     RELEASE_ASSERT(JITCode::isBaselineCode(result->jitType()) || result->jitType() == JITCode::None);
3203     return result;
3204 #else
3205     return this;
3206 #endif
3207 }
3208
3209 CodeBlock* CodeBlock::baselineVersion()
3210 {
3211 #if ENABLE(JIT)
3212     if (JITCode::isBaselineCode(jitType()))
3213         return this;
3214     CodeBlock* result = replacement();
3215     if (!result) {
3216         // This can happen if we're creating the original CodeBlock for an executable.
3217         // Assume that we're the baseline CodeBlock.
3218         RELEASE_ASSERT(jitType() == JITCode::None);
3219         return this;
3220     }
3221     result = result->baselineAlternative();
3222     return result;
3223 #else
3224     return this;
3225 #endif
3226 }
3227
3228 #if ENABLE(JIT)
3229 bool CodeBlock::hasOptimizedReplacement(JITCode::JITType typeToReplace)
3230 {
3231     return JITCode::isHigherTier(replacement()->jitType(), typeToReplace);
3232 }
3233
3234 bool CodeBlock::hasOptimizedReplacement()
3235 {
3236     return hasOptimizedReplacement(jitType());
3237 }
3238 #endif
3239
3240 HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset, RequiredHandler requiredHandler)
3241 {
3242     RELEASE_ASSERT(bytecodeOffset < instructions().size());
3243     return handlerForIndex(bytecodeOffset, requiredHandler);
3244 }
3245
3246 HandlerInfo* CodeBlock::handlerForIndex(unsigned index, RequiredHandler requiredHandler)
3247 {
3248     if (!m_rareData)
3249         return 0;
3250     return HandlerInfo::handlerForIndex(m_rareData->m_exceptionHandlers, index, requiredHandler);
3251 }
3252
3253 CallSiteIndex CodeBlock::newExceptionHandlingCallSiteIndex(CallSiteIndex originalCallSite)
3254 {
3255 #if ENABLE(DFG_JIT)
3256     RELEASE_ASSERT(JITCode::isOptimizingJIT(jitType()));
3257     RELEASE_ASSERT(canGetCodeOrigin(originalCallSite));
3258     ASSERT(!!handlerForIndex(originalCallSite.bits()));
3259     CodeOrigin originalOrigin = codeOrigin(originalCallSite);
3260     return m_jitCode->dfgCommon()->addUniqueCallSiteIndex(originalOrigin);
3261 #else
3262     // We never create new on-the-fly exception handling
3263     // call sites outside the DFG/FTL inline caches.
3264     UNUSED_PARAM(originalCallSite);
3265     RELEASE_ASSERT_NOT_REACHED();
3266     return CallSiteIndex(0u);
3267 #endif
3268 }
3269
3270 void CodeBlock::removeExceptionHandlerForCallSite(CallSiteIndex callSiteIndex)
3271 {
3272     RELEASE_ASSERT(m_rareData);
3273     Vector<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers;
3274     unsigned index = callSiteIndex.bits();
3275     for (size_t i = 0; i < exceptionHandlers.size(); ++i) {
3276         HandlerInfo& handler = exceptionHandlers[i];
3277         if (handler.start <= index && handler.end > index) {
3278             exceptionHandlers.remove(i);
3279             return;
3280         }
3281     }
3282
3283     RELEASE_ASSERT_NOT_REACHED();
3284 }
3285
3286 unsigned CodeBlock::lineNumberForBytecodeOffset(unsigned bytecodeOffset)
3287 {
3288     RELEASE_ASSERT(bytecodeOffset < instructions().size());
3289     return ownerScriptExecutable()->firstLine() + m_unlinkedCode->lineNumberForBytecodeOffset(bytecodeOffset);
3290 }
3291
3292 unsigned CodeBlock::columnNumberForBytecodeOffset(unsigned bytecodeOffset)
3293 {
3294     int divot;
3295     int startOffset;
3296     int endOffset;
3297     unsigned line;
3298     unsigned column;
3299     expressionRangeForBytecodeOffset(bytecodeOffset, divot, startOffset, endOffset, line, column);
3300     return column;
3301 }
3302
3303 void CodeBlock::expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset, unsigned& line, unsigned& column) const
3304 {
3305     m_unlinkedCode->expressionRangeForBytecodeOffset(bytecodeOffset, divot, startOffset, endOffset, line, column);
3306     divot += m_sourceOffset;
3307     column += line ? 1 : firstLineColumnOffset();
3308     line += ownerScriptExecutable()->firstLine();
3309 }
3310
3311 bool CodeBlock::hasOpDebugForLineAndColumn(unsigned line, unsigned column)
3312 {
3313     Interpreter* interpreter = vm()->interpreter;
3314     const Instruction* begin = instructions().begin();
3315     const Instruction* end = instructions().end();
3316     for (const Instruction* it = begin; it != end;) {
3317         OpcodeID opcodeID = interpreter->getOpcodeID(it->u.opcode);
3318         if (opcodeID == op_debug) {
3319             unsigned bytecodeOffset = it - begin;
3320             int unused;
3321             unsigned opDebugLine;
3322             unsigned opDebugColumn;
3323             expressionRangeForBytecodeOffset(bytecodeOffset, unused, unused, unused, opDebugLine, opDebugColumn);
3324             if (line == opDebugLine && (column == Breakpoint::unspecifiedColumn || column == opDebugColumn))
3325                 return true;
3326         }
3327         it += opcodeLengths[opcodeID];
3328     }
3329     return false;
3330 }
3331
3332 void CodeBlock::shrinkToFit(ShrinkMode shrinkMode)
3333 {
3334     ConcurrentJITLocker locker(m_lock);
3335
3336     m_rareCaseProfiles.shrinkToFit();
3337     
3338     if (shrinkMode == EarlyShrink) {
3339         m_constantRegisters.shrinkToFit();
3340         m_constantsSourceCodeRepresentation.shrinkToFit();
3341         
3342         if (m_rareData) {
3343             m_rareData->m_switchJumpTables.shrinkToFit();
3344             m_rareData->m_stringSwitchJumpTables.shrinkToFit();
3345         }
3346     } // else don't shrink these, because we would have already pointed pointers into these tables.
3347 }
3348
3349 #if ENABLE(JIT)
3350 void CodeBlock::linkIncomingCall(ExecState* callerFrame, CallLinkInfo* incoming)
3351 {
3352     noticeIncomingCall(callerFrame);
3353     m_incomingCalls.push(incoming);
3354 }
3355
3356 void CodeBlock::linkIncomingPolymorphicCall(ExecState* callerFrame, PolymorphicCallNode* incoming)
3357 {
3358     noticeIncomingCall(callerFrame);
3359     m_incomingPolymorphicCalls.push(incoming);
3360 }
3361 #endif // ENABLE(JIT)
3362
3363 void CodeBlock::unlinkIncomingCalls()
3364 {
3365     while (m_incomingLLIntCalls.begin() != m_incomingLLIntCalls.end())
3366         m_incomingLLIntCalls.begin()->unlink();
3367 #if ENABLE(JIT)
3368     while (m_incomingCalls.begin() != m_incomingCalls.end())
3369         m_incomingCalls.begin()->unlink(*vm());
3370     while (m_incomingPolymorphicCalls.begin() != m_incomingPolymorphicCalls.end())
3371         m_incomingPolymorphicCalls.begin()->unlink(*vm());
3372 #endif // ENABLE(JIT)
3373 }
3374
3375 void CodeBlock::linkIncomingCall(ExecState* callerFrame, LLIntCallLinkInfo* incoming)
3376 {
3377     noticeIncomingCall(callerFrame);
3378     m_incomingLLIntCalls.push(incoming);
3379 }
3380
3381 CodeBlock* CodeBlock::newReplacement()
3382 {
3383     return ownerScriptExecutable()->newReplacementCodeBlockFor(specializationKind());
3384 }
3385
3386 #if ENABLE(JIT)
3387 CodeBlock* CodeBlock::replacement()
3388 {
3389     const ClassInfo* classInfo = this->classInfo();
3390
3391     if (classInfo == FunctionCodeBlock::info())
3392         return jsCast<FunctionExecutable*>(ownerExecutable())->codeBlockFor(m_isConstructor ? CodeForConstruct : CodeForCall);
3393
3394     if (classInfo == EvalCodeBlock::info())
3395         return jsCast<EvalExecutable*>(ownerExecutable())->codeBlock();
3396
3397     if (classInfo == ProgramCodeBlock::info())
3398         return jsCast<ProgramExecutable*>(ownerExecutable())->codeBlock();
3399
3400     if (classInfo == ModuleProgramCodeBlock::info())
3401         return jsCast<ModuleProgramExecutable*>(ownerExecutable())->codeBlock();
3402
3403 #if ENABLE(WEBASSEMBLY)
3404     if (classInfo == WebAssemblyCodeBlock::info())
3405         return nullptr;
3406 #endif
3407
3408     RELEASE_ASSERT_NOT_REACHED();
3409     return nullptr;
3410 }
3411
3412 DFG::CapabilityLevel CodeBlock::computeCapabilityLevel()
3413 {
3414     const ClassInfo* classInfo = this->classInfo();
3415
3416     if (classInfo == FunctionCodeBlock::info()) {
3417         if (m_isConstructor)
3418             return DFG::functionForConstructCapabilityLevel(this);
3419         return DFG::functionForCallCapabilityLevel(this);
3420     }
3421
3422     if (classInfo == EvalCodeBlock::info())
3423         return DFG::evalCapabilityLevel(this);
3424
3425     if (classInfo == ProgramCodeBlock::info())
3426         return DFG::programCapabilityLevel(this);
3427
3428     if (classInfo == ModuleProgramCodeBlock::info())
3429         return DFG::programCapabilityLevel(this);
3430
3431 #if ENABLE(WEBASSEMBLY)
3432     if (classInfo == WebAssemblyCodeBlock::info())
3433         return DFG::CannotCompile;
3434 #endif
3435
3436     RELEASE_ASSERT_NOT_REACHED();
3437     return DFG::CannotCompile;
3438 }
3439
3440 #endif // ENABLE(JIT)
3441
3442 void CodeBlock::jettison(Profiler::JettisonReason reason, ReoptimizationMode mode, const FireDetail* detail)
3443 {
3444 #if !ENABLE(DFG_JIT)
3445     UNUSED_PARAM(mode);
3446     UNUSED_PARAM(detail);
3447 #endif
3448     
3449     CODEBLOCK_LOG_EVENT(this, "jettison", ("due to ", reason, ", counting = ", mode == CountReoptimization, ", detail = ", pointerDump(detail)));
3450
3451     RELEASE_ASSERT(reason != Profiler::NotJettisoned);
3452     
3453 #if ENABLE(DFG_JIT)
3454     if (DFG::shouldDumpDisassembly()) {
3455         dataLog("Jettisoning ", *this);
3456         if (mode == CountReoptimization)
3457             dataLog(" and counting reoptimization");
3458         dataLog(" due to ", reason);
3459         if (detail)
3460             dataLog(", ", *detail);
3461         dataLog(".\n");
3462     }
3463     
3464     if (reason == Profiler::JettisonDueToWeakReference) {
3465         if (DFG::shouldDumpDisassembly()) {
3466             dataLog(*this, " will be jettisoned because of the following dead references:\n");
3467             DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
3468             for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
3469                 DFG::WeakReferenceTransition& transition = dfgCommon->transitions[i];
3470                 JSCell* origin = transition.m_codeOrigin.get();
3471                 JSCell* from = transition.m_from.get();
3472                 JSCell* to = transition.m_to.get();
3473                 if ((!origin || Heap::isMarked(origin)) && Heap::isMarked(from))
3474                     continue;
3475                 dataLog("    Transition under ", RawPointer(origin), ", ", RawPointer(from), " -> ", RawPointer(to), ".\n");
3476             }
3477             for (unsigned i = 0; i < dfgCommon->weakReferences.size(); ++i) {
3478                 JSCell* weak = dfgCommon->weakReferences[i].get();
3479                 if (Heap::isMarked(weak))
3480                     continue;
3481                 dataLog("    Weak reference ", RawPointer(weak), ".\n");
3482             }
3483         }
3484     }
3485 #endif // ENABLE(DFG_JIT)
3486
3487     DeferGCForAWhile deferGC(*heap());
3488     
3489     // We want to accomplish two things here:
3490     // 1) Make sure that if this CodeBlock is on the stack right now, then if we return to it
3491     //    we should OSR exit at the top of the next bytecode instruction after the return.
3492     // 2) Make sure that if we call the owner executable, then we shouldn't call this CodeBlock.
3493
3494 #if ENABLE(DFG_JIT)
3495     if (reason != Profiler::JettisonDueToOldAge) {
3496         if (Profiler::Compilation* compilation = jitCode()->dfgCommon()->compilation.get())
3497             compilation->setJettisonReason(reason, detail);
3498         
3499         // This accomplishes (1), and does its own book-keeping about whether it has already happened.
3500         if (!jitCode()->dfgCommon()->invalidate()) {
3501             // We've already been invalidated.
3502             RELEASE_ASSERT(this != replacement() || (m_vm->heap.isCurrentThreadBusy() && !Heap::isMarked(ownerScriptExecutable())));
3503             return;
3504         }
3505     }
3506     
3507     if (DFG::shouldDumpDisassembly())
3508         dataLog("    Did invalidate ", *this, "\n");
3509     
3510     // Count the reoptimization if that's what the user wanted.
3511     if (mode == CountReoptimization) {
3512         // FIXME: Maybe this should call alternative().
3513         // https://bugs.webkit.org/show_bug.cgi?id=123677
3514         baselineAlternative()->countReoptimization();
3515         if (DFG::shouldDumpDisassembly())
3516             dataLog("    Did count reoptimization for ", *this, "\n");
3517     }
3518     
3519     if (this != replacement()) {
3520         // This means that we were never the entrypoint. This can happen for OSR entry code
3521         // blocks.
3522         return;
3523     }
3524
3525     if (alternative())
3526         alternative()->optimizeAfterWarmUp();
3527
3528     if (reason != Profiler::JettisonDueToOldAge)
3529         tallyFrequentExitSites();
3530 #endif // ENABLE(DFG_JIT)
3531
3532     // Jettison can happen during GC. We don't want to install code to a dead executable
3533     // because that would add a dead object to the remembered set.
3534     if (m_vm->heap.isCurrentThreadBusy() && !Heap::isMarked(ownerScriptExecutable()))
3535         return;
3536
3537     // This accomplishes (2).
3538     ownerScriptExecutable()->installCode(
3539         m_globalObject->vm(), alternative(), codeType(), specializationKind());
3540
3541 #if ENABLE(DFG_JIT)
3542     if (DFG::shouldDumpDisassembly())
3543         dataLog("    Did install baseline version of ", *this, "\n");
3544 #endif // ENABLE(DFG_JIT)
3545 }
3546
3547 JSGlobalObject* CodeBlock::globalObjectFor(CodeOrigin codeOrigin)
3548 {
3549     if (!codeOrigin.inlineCallFrame)
3550         return globalObject();
3551     return codeOrigin.inlineCallFrame->baselineCodeBlock->globalObject();
3552 }
3553
3554 class RecursionCheckFunctor {
3555 public:
3556     RecursionCheckFunctor(CallFrame* startCallFrame, CodeBlock* codeBlock, unsigned depthToCheck)
3557         : m_startCallFrame(startCallFrame)
3558         , m_codeBlock(codeBlock)
3559         , m_depthToCheck(depthToCheck)
3560         , m_foundStartCallFrame(false)
3561         , m_didRecurse(false)
3562     { }
3563
3564     StackVisitor::Status operator()(StackVisitor& visitor) const
3565     {
3566         CallFrame* currentCallFrame = visitor->callFrame();
3567
3568         if (currentCallFrame == m_startCallFrame)
3569             m_foundStartCallFrame = true;
3570
3571         if (m_foundStartCallFrame) {
3572             if (visitor->callFrame()->codeBlock() == m_codeBlock) {
3573                 m_didRecurse = true;
3574                 return StackVisitor::Done;
3575             }
3576
3577             if (!m_depthToCheck--)
3578                 return StackVisitor::Done;
3579         }
3580
3581         return StackVisitor::Continue;
3582     }
3583
3584     bool didRecurse() const { return m_didRecurse; }
3585
3586 private:
3587     CallFrame* m_startCallFrame;
3588     CodeBlock* m_codeBlock;
3589     mutable unsigned m_depthToCheck;
3590     mutable bool m_foundStartCallFrame;
3591     mutable bool m_didRecurse;
3592 };
3593
3594 void CodeBlock::noticeIncomingCall(ExecState* callerFrame)
3595 {
3596     CodeBlock* callerCodeBlock = callerFrame->codeBlock();
3597     
3598     if (Options::verboseCallLink())
3599         dataLog("Noticing call link from ", pointerDump(callerCodeBlock), " to ", *this, "\n");
3600     
3601 #if ENABLE(DFG_JIT)
3602     if (!m_shouldAlwaysBeInlined)
3603         return;
3604     
3605     if (!callerCodeBlock) {
3606         m_shouldAlwaysBeInlined = false;
3607         if (Options::verboseCallLink())
3608             dataLog("    Clearing SABI because caller is native.\n");
3609         return;
3610     }
3611
3612     if (!hasBaselineJITProfiling())
3613         return;
3614
3615     if (!DFG::mightInlineFunction(this))
3616         return;
3617
3618     if (!canInline(capabilityLevelState()))
3619         return;
3620     
3621     if (!DFG::isSmallEnoughToInlineCodeInto(callerCodeBlock)) {
3622         m_shouldAlwaysBeInlined = false;
3623         if (Options::verboseCallLink())
3624             dataLog("    Clearing SABI because caller is too large.\n");
3625         return;
3626     }
3627
3628     if (callerCodeBlock->jitType() == JITCode::InterpreterThunk) {
3629         // If the caller is still in the interpreter, then we can't expect inlining to
3630         // happen anytime soon. Assume it's profitable to optimize it separately. This
3631         // ensures that a function is SABI only if it is called no more frequently than
3632         // any of its callers.
3633         m_shouldAlwaysBeInlined = false;
3634         if (Options::verboseCallLink())
3635             dataLog("    Clearing SABI because caller is in LLInt.\n");
3636         return;
3637     }
3638     
3639     if (JITCode::isOptimizingJIT(callerCodeBlock->jitType())) {
3640         m_shouldAlwaysBeInlined = false;
3641         if (Options::verboseCallLink())
3642             dataLog("    Clearing SABI bcause caller was already optimized.\n");
3643         return;
3644     }
3645     
3646     if (callerCodeBlock->codeType() != FunctionCode) {
3647         // If the caller is either eval or global code, assume that that won't be
3648         // optimized anytime soon. For eval code this is particularly true since we
3649         // delay eval optimization by a *lot*.
3650         m_shouldAlwaysBeInlined = false;
3651         if (Options::verboseCallLink())
3652             dataLog("    Clearing SABI because caller is not a function.\n");
3653         return;
3654     }
3655
3656     // Recursive calls won't be inlined.
3657     RecursionCheckFunctor functor(callerFrame, this, Options::maximumInliningDepth());
3658     vm()->topCallFrame->iterate(functor);
3659
3660     if (functor.didRecurse()) {
3661         if (Options::verboseCallLink())
3662             dataLog("    Clearing SABI because recursion was detected.\n");
3663         m_shouldAlwaysBeInlined = false;
3664         return;
3665     }
3666     
3667     if (callerCodeBlock->capabilityLevelState() == DFG::CapabilityLevelNotSet) {
3668         dataLog("In call from ", *callerCodeBlock, " ", callerFrame->codeOrigin(), " to ", *this, ": caller's DFG capability level is not set.\n");
3669         CRASH();
3670     }
3671     
3672     if (canCompile(callerCodeBlock->capabilityLevelState()))
3673         return;
3674     
3675     if (Options::verboseCallLink())
3676         dataLog("    Clearing SABI because the caller is not a DFG candidate.\n");
3677     
3678     m_shouldAlwaysBeInlined = false;
3679 #endif
3680 }
3681
3682 unsigned CodeBlock::reoptimizationRetryCounter() const
3683 {
3684 #if ENABLE(JIT)
3685     ASSERT(m_reoptimizationRetryCounter <= Options::reoptimizationRetryCounterMax());
3686     return m_reoptimizationRetryCounter;
3687 #else
3688     return 0;
3689 #endif // ENABLE(JIT)
3690 }
3691
3692 #if ENABLE(JIT)
3693 void CodeBlock::setCalleeSaveRegisters(RegisterSet calleeSaveRegisters)
3694 {
3695     m_calleeSaveRegisters = std::make_unique<RegisterAtOffsetList>(calleeSaveRegisters);
3696 }
3697
3698 void CodeBlock::setCalleeSaveRegisters(std::unique_ptr<RegisterAtOffsetList> registerAtOffsetList)
3699 {
3700     m_calleeSaveRegisters = WTFMove(registerAtOffsetList);
3701 }
3702     
3703 static size_t roundCalleeSaveSpaceAsVirtualRegisters(size_t calleeSaveRegisters)
3704 {
3705     static const unsigned cpuRegisterSize = sizeof(void*);
3706     return (WTF::roundUpToMultipleOf(sizeof(Register), calleeSaveRegisters * cpuRegisterSize) / sizeof(Register));
3707
3708 }
3709
3710 size_t CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters()
3711 {
3712     return roundCalleeSaveSpaceAsVirtualRegisters(numberOfLLIntBaselineCalleeSaveRegisters());
3713 }
3714
3715 size_t CodeBlock::calleeSaveSpaceAsVirtualRegisters()
3716 {
3717     return roundCalleeSaveSpaceAsVirtualRegisters(m_calleeSaveRegisters->size());
3718 }
3719
3720 void CodeBlock::countReoptimization()
3721 {
3722     m_reoptimizationRetryCounter++;
3723     if (m_reoptimizationRetryCounter > Options::reoptimizationRetryCounterMax())
3724         m_reoptimizationRetryCounter = Options::reoptimizationRetryCounterMax();
3725 }
3726
3727 unsigned CodeBlock::numberOfDFGCompiles()
3728 {
3729     ASSERT(JITCode::isBaselineCode(jitType()));
3730     if (Options::testTheFTL()) {
3731         if (m_didFailFTLCompilation)
3732             return 1000000;
3733         return (m_hasBeenCompiledWithFTL ? 1 : 0) + m_reoptimizationRetryCounter;
3734     }
3735     return (JITCode::isOptimizingJIT(replacement()->jitType()) ? 1 : 0) + m_reoptimizationRetryCounter;
3736 }
3737
3738 int32_t CodeBlock::codeTypeThresholdMultiplier() const
3739 {
3740     if (codeType() == EvalCode)
3741         return Options::evalThresholdMultiplier();
3742     
3743     return 1;
3744 }
3745
3746 double CodeBlock::optimizationThresholdScalingFactor()
3747 {
3748     // This expression arises from doing a least-squares fit of
3749     //
3750     // F[x_] =: a * Sqrt[x + b] + Abs[c * x] + d
3751     //
3752     // against the data points:
3753     //
3754     //    x       F[x_]
3755     //    10       0.9          (smallest reasonable code block)
3756     //   200       1.0          (typical small-ish code block)
3757     //   320       1.2          (something I saw in 3d-cube that I wanted to optimize)
3758     //  1268       5.0          (something I saw in 3d-cube that I didn't want to optimize)
3759     //  4000       5.5          (random large size, used to cause the function to converge to a shallow curve of some sort)
3760     // 10000       6.0          (similar to above)
3761     //
3762     // I achieve the minimization using the following Mathematica code:
3763     //
3764     // MyFunctionTemplate[x_, a_, b_, c_, d_] := a*Sqrt[x + b] + Abs[c*x] + d
3765     //
3766     // samples = {{10, 0.9}, {200, 1}, {320, 1.2}, {1268, 5}, {4000, 5.5}, {10000, 6}}
3767     //
3768     // solution = 
3769     //     Minimize[Plus @@ ((MyFunctionTemplate[#[[1]], a, b, c, d] - #[[2]])^2 & /@ samples),
3770     //         {a, b, c, d}][[2]]
3771     //
3772     // And the code below (to initialize a, b, c, d) is generated by:
3773     //
3774     // Print["const double " <> ToString[#[[1]]] <> " = " <>
3775     //     If[#[[2]] < 0.00001, "0.0", ToString[#[[2]]]] <> ";"] & /@ solution
3776     //
3777     // We've long known the following to be true:
3778     // - Small code blocks are cheap to optimize and so we should do it sooner rather
3779     //   than later.
3780     // - Large code blocks are expensive to optimize and so we should postpone doing so,
3781     //   and sometimes have a large enough threshold that we never optimize them.
3782     // - The difference in cost is not totally linear because (a) just invoking the
3783     //   DFG incurs some base cost and (b) for large code blocks there is enough slop
3784     //   in the correlation between instruction count and the actual compilation cost
3785     //   that for those large blocks, the instruction count should not have a strong
3786     //   influence on our threshold.
3787     //
3788     // I knew the goals but I didn't know how to achieve them; so I picked an interesting
3789     // example where the heuristics were right (code block in 3d-cube with instruction
3790     // count 320, which got compiled early as it should have been) and one where they were
3791     // totally wrong (code block in 3d-cube with instruction count 1268, which was expensive
3792     // to compile and didn't run often enough to warrant compilation in my opinion), and
3793     // then threw in additional data points that represented my own guess of what our
3794     // heuristics should do for some round-numbered examples.
3795     //
3796     // The expression to which I decided to fit the data arose because I started with an
3797     // affine function, and then did two things: put the linear part in an Abs to ensure
3798     // that the fit didn't end up choosing a negative value of c (which would result in
3799     // the function turning over and going negative for large x) and I threw in a Sqrt
3800     // term because Sqrt represents my intution that the function should be more sensitive
3801     // to small changes in small values of x, but less sensitive when x gets large.
3802     
3803     // Note that the current fit essentially eliminates the linear portion of the
3804     // expression (c == 0.0).
3805     const double a = 0.061504;
3806     const double b = 1.02406;
3807     const double c = 0.0;
3808     const double d = 0.825914;
3809     
3810     double instructionCount = this->instructionCount();
3811     
3812     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.
3813     
3814     double result = d + a * sqrt(instructionCount + b) + c * instructionCount;
3815     
3816     result *= codeTypeThresholdMultiplier();
3817     
3818     if (Options::verboseOSR()) {
3819         dataLog(
3820             *this, ": instruction count is ", instructionCount,
3821             ", scaling execution counter by ", result, " * ", codeTypeThresholdMultiplier(),
3822             "\n");
3823     }
3824     return result;
3825 }
3826
3827 static int32_t clipThreshold(double threshold)
3828 {
3829     if (threshold < 1.0)
3830         return 1;
3831     
3832     if (threshold > static_cast<double>(std::numeric_limits<int32_t>::max()))
3833         return std::numeric_limits<int32_t>::max();
3834