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