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