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