7c8eab96e52a7f53e7d089abd9fb06fa2a83057c
[WebKit-https.git] / Source / JavaScriptCore / bytecode / CodeBlock.cpp
1 /*
2  * Copyright (C) 2008, 2009, 2010 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 Computer, 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 "BytecodeGenerator.h"
34 #include "DFGCapabilities.h"
35 #include "DFGNode.h"
36 #include "DFGRepatch.h"
37 #include "Debugger.h"
38 #include "Interpreter.h"
39 #include "JIT.h"
40 #include "JITStubs.h"
41 #include "JSActivation.h"
42 #include "JSFunction.h"
43 #include "JSStaticScopeObject.h"
44 #include "JSValue.h"
45 #include "LowLevelInterpreter.h"
46 #include "RepatchBuffer.h"
47 #include "UStringConcatenate.h"
48 #include <stdio.h>
49 #include <wtf/StringExtras.h>
50
51 #if ENABLE(DFG_JIT)
52 #include "DFGOperations.h"
53 #endif
54
55 #define DUMP_CODE_BLOCK_STATISTICS 0
56
57 namespace JSC {
58
59 #if ENABLE(DFG_JIT)
60 using namespace DFG;
61 #endif
62
63 static UString escapeQuotes(const UString& str)
64 {
65     UString result = str;
66     size_t pos = 0;
67     while ((pos = result.find('\"', pos)) != notFound) {
68         result = makeUString(result.substringSharingImpl(0, pos), "\"\\\"\"", result.substringSharingImpl(pos + 1));
69         pos += 4;
70     }
71     return result;
72 }
73
74 static UString valueToSourceString(ExecState* exec, JSValue val)
75 {
76     if (!val)
77         return "0";
78
79     if (val.isString())
80         return makeUString("\"", escapeQuotes(val.toString(exec)->value(exec)), "\"");
81
82     return val.description();
83 }
84
85 static CString constantName(ExecState* exec, int k, JSValue value)
86 {
87     return makeUString(valueToSourceString(exec, value), "(@k", UString::number(k - FirstConstantRegisterIndex), ")").utf8();
88 }
89
90 static CString idName(int id0, const Identifier& ident)
91 {
92     return makeUString(ident.ustring(), "(@id", UString::number(id0), ")").utf8();
93 }
94
95 CString CodeBlock::registerName(ExecState* exec, int r) const
96 {
97     if (r == missingThisObjectMarker())
98         return "<null>";
99
100     if (isConstantRegisterIndex(r))
101         return constantName(exec, r, getConstant(r));
102
103     return makeUString("r", UString::number(r)).utf8();
104 }
105
106 static UString regexpToSourceString(RegExp* regExp)
107 {
108     char postfix[5] = { '/', 0, 0, 0, 0 };
109     int index = 1;
110     if (regExp->global())
111         postfix[index++] = 'g';
112     if (regExp->ignoreCase())
113         postfix[index++] = 'i';
114     if (regExp->multiline())
115         postfix[index] = 'm';
116
117     return makeUString("/", regExp->pattern(), postfix);
118 }
119
120 static CString regexpName(int re, RegExp* regexp)
121 {
122     return makeUString(regexpToSourceString(regexp), "(@re", UString::number(re), ")").utf8();
123 }
124
125 static UString pointerToSourceString(void* p)
126 {
127     char buffer[2 + 2 * sizeof(void*) + 1]; // 0x [two characters per byte] \0
128     snprintf(buffer, sizeof(buffer), "%p", p);
129     return buffer;
130 }
131
132 NEVER_INLINE static const char* debugHookName(int debugHookID)
133 {
134     switch (static_cast<DebugHookID>(debugHookID)) {
135         case DidEnterCallFrame:
136             return "didEnterCallFrame";
137         case WillLeaveCallFrame:
138             return "willLeaveCallFrame";
139         case WillExecuteStatement:
140             return "willExecuteStatement";
141         case WillExecuteProgram:
142             return "willExecuteProgram";
143         case DidExecuteProgram:
144             return "didExecuteProgram";
145         case DidReachBreakpoint:
146             return "didReachBreakpoint";
147     }
148
149     ASSERT_NOT_REACHED();
150     return "";
151 }
152
153 void CodeBlock::printUnaryOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
154 {
155     int r0 = (++it)->u.operand;
156     int r1 = (++it)->u.operand;
157
158     dataLog("[%4d] %s\t\t %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data());
159 }
160
161 void CodeBlock::printBinaryOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
162 {
163     int r0 = (++it)->u.operand;
164     int r1 = (++it)->u.operand;
165     int r2 = (++it)->u.operand;
166     dataLog("[%4d] %s\t\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
167 }
168
169 void CodeBlock::printConditionalJump(ExecState* exec, const Vector<Instruction>::const_iterator&, Vector<Instruction>::const_iterator& it, int location, const char* op) const
170 {
171     int r0 = (++it)->u.operand;
172     int offset = (++it)->u.operand;
173     dataLog("[%4d] %s\t\t %s, %d(->%d)\n", location, op, registerName(exec, r0).data(), offset, location + offset);
174 }
175
176 void CodeBlock::printGetByIdOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
177 {
178     int r0 = (++it)->u.operand;
179     int r1 = (++it)->u.operand;
180     int id0 = (++it)->u.operand;
181     dataLog("[%4d] %s\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
182     it += 5;
183 }
184
185 void CodeBlock::printCallOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
186 {
187     int func = (++it)->u.operand;
188     int argCount = (++it)->u.operand;
189     int registerOffset = (++it)->u.operand;
190     dataLog("[%4d] %s\t %s, %d, %d\n", location, op, registerName(exec, func).data(), argCount, registerOffset);
191     it += 2;
192 }
193
194 void CodeBlock::printPutByIdOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
195 {
196     int r0 = (++it)->u.operand;
197     int id0 = (++it)->u.operand;
198     int r1 = (++it)->u.operand;
199     dataLog("[%4d] %s\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data());
200     it += 5;
201 }
202
203 #if ENABLE(JIT)
204 static bool isGlobalResolve(OpcodeID opcodeID)
205 {
206     return opcodeID == op_resolve_global || opcodeID == op_resolve_global_dynamic;
207 }
208
209 static bool isPropertyAccess(OpcodeID opcodeID)
210 {
211     switch (opcodeID) {
212         case op_get_by_id_self:
213         case op_get_by_id_proto:
214         case op_get_by_id_chain:
215         case op_put_by_id_transition:
216         case op_put_by_id_replace:
217         case op_get_by_id:
218         case op_put_by_id:
219         case op_get_by_id_generic:
220         case op_put_by_id_generic:
221         case op_get_array_length:
222         case op_get_string_length:
223             return true;
224         default:
225             return false;
226     }
227 }
228
229 static unsigned instructionOffsetForNth(ExecState* exec, const Vector<Instruction>& instructions, int nth, bool (*predicate)(OpcodeID))
230 {
231     size_t i = 0;
232     while (i < instructions.size()) {
233         OpcodeID currentOpcode = exec->interpreter()->getOpcodeID(instructions[i].u.opcode);
234         if (predicate(currentOpcode)) {
235             if (!--nth)
236                 return i;
237         }
238         i += opcodeLengths[currentOpcode];
239     }
240
241     ASSERT_NOT_REACHED();
242     return 0;
243 }
244
245 static void printGlobalResolveInfo(const GlobalResolveInfo& resolveInfo, unsigned instructionOffset)
246 {
247     dataLog("  [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure).utf8().data());
248 }
249
250 static void printStructureStubInfo(const StructureStubInfo& stubInfo, unsigned instructionOffset)
251 {
252     switch (stubInfo.accessType) {
253     case access_get_by_id_self:
254         dataLog("  [%4d] %s: %s\n", instructionOffset, "get_by_id_self", pointerToSourceString(stubInfo.u.getByIdSelf.baseObjectStructure).utf8().data());
255         return;
256     case access_get_by_id_proto:
257         dataLog("  [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(stubInfo.u.getByIdProto.baseObjectStructure).utf8().data(), pointerToSourceString(stubInfo.u.getByIdProto.prototypeStructure).utf8().data());
258         return;
259     case access_get_by_id_chain:
260         dataLog("  [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(stubInfo.u.getByIdChain.baseObjectStructure).utf8().data(), pointerToSourceString(stubInfo.u.getByIdChain.chain).utf8().data());
261         return;
262     case access_get_by_id_self_list:
263         dataLog("  [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_self_list", pointerToSourceString(stubInfo.u.getByIdSelfList.structureList).utf8().data(), stubInfo.u.getByIdSelfList.listSize);
264         return;
265     case access_get_by_id_proto_list:
266         dataLog("  [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_proto_list", pointerToSourceString(stubInfo.u.getByIdProtoList.structureList).utf8().data(), stubInfo.u.getByIdProtoList.listSize);
267         return;
268     case access_put_by_id_transition_normal:
269     case access_put_by_id_transition_direct:
270         dataLog("  [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(stubInfo.u.putByIdTransition.previousStructure).utf8().data(), pointerToSourceString(stubInfo.u.putByIdTransition.structure).utf8().data(), pointerToSourceString(stubInfo.u.putByIdTransition.chain).utf8().data());
271         return;
272     case access_put_by_id_replace:
273         dataLog("  [%4d] %s: %s\n", instructionOffset, "put_by_id_replace", pointerToSourceString(stubInfo.u.putByIdReplace.baseObjectStructure).utf8().data());
274         return;
275     case access_unset:
276         dataLog("  [%4d] %s\n", instructionOffset, "unset");
277         return;
278     case access_get_by_id_generic:
279         dataLog("  [%4d] %s\n", instructionOffset, "op_get_by_id_generic");
280         return;
281     case access_put_by_id_generic:
282         dataLog("  [%4d] %s\n", instructionOffset, "op_put_by_id_generic");
283         return;
284     case access_get_array_length:
285         dataLog("  [%4d] %s\n", instructionOffset, "op_get_array_length");
286         return;
287     case access_get_string_length:
288         dataLog("  [%4d] %s\n", instructionOffset, "op_get_string_length");
289         return;
290     default:
291         ASSERT_NOT_REACHED();
292     }
293 }
294 #endif
295
296 void CodeBlock::printStructure(const char* name, const Instruction* vPC, int operand) const
297 {
298     unsigned instructionOffset = vPC - instructions().begin();
299     dataLog("  [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure).utf8().data());
300 }
301
302 void CodeBlock::printStructures(const Instruction* vPC) const
303 {
304     Interpreter* interpreter = m_globalData->interpreter;
305     unsigned instructionOffset = vPC - instructions().begin();
306
307     if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id)) {
308         printStructure("get_by_id", vPC, 4);
309         return;
310     }
311     if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self)) {
312         printStructure("get_by_id_self", vPC, 4);
313         return;
314     }
315     if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto)) {
316         dataLog("  [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structure).utf8().data());
317         return;
318     }
319     if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) {
320         dataLog("  [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structure).utf8().data(), pointerToSourceString(vPC[6].u.structureChain).utf8().data());
321         return;
322     }
323     if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain)) {
324         dataLog("  [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structureChain).utf8().data());
325         return;
326     }
327     if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id)) {
328         printStructure("put_by_id", vPC, 4);
329         return;
330     }
331     if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) {
332         printStructure("put_by_id_replace", vPC, 4);
333         return;
334     }
335     if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global)) {
336         printStructure("resolve_global", vPC, 4);
337         return;
338     }
339     if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) {
340         printStructure("resolve_global_dynamic", vPC, 4);
341         return;
342     }
343
344     // These m_instructions doesn't ref Structures.
345     ASSERT(vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_call) || vPC[0].u.opcode == interpreter->getOpcode(op_call_eval) || vPC[0].u.opcode == interpreter->getOpcode(op_construct));
346 }
347
348 void CodeBlock::dump(ExecState* exec) const
349 {
350     if (!m_instructions) {
351         dataLog("No instructions available.\n");
352         return;
353     }
354
355     size_t instructionCount = 0;
356
357     for (size_t i = 0; i < instructions().size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(instructions()[i].u.opcode)])
358         ++instructionCount;
359
360     dataLog("%lu m_instructions; %lu bytes at %p; %d parameter(s); %d callee register(s); %d variable(s)\n\n",
361         static_cast<unsigned long>(instructionCount),
362         static_cast<unsigned long>(instructions().size() * sizeof(Instruction)),
363         this, m_numParameters, m_numCalleeRegisters, m_numVars);
364
365     Vector<Instruction>::const_iterator begin = instructions().begin();
366     Vector<Instruction>::const_iterator end = instructions().end();
367     for (Vector<Instruction>::const_iterator it = begin; it != end; ++it)
368         dump(exec, begin, it);
369
370     if (!m_identifiers.isEmpty()) {
371         dataLog("\nIdentifiers:\n");
372         size_t i = 0;
373         do {
374             dataLog("  id%u = %s\n", static_cast<unsigned>(i), m_identifiers[i].ustring().utf8().data());
375             ++i;
376         } while (i != m_identifiers.size());
377     }
378
379     if (!m_constantRegisters.isEmpty()) {
380         dataLog("\nConstants:\n");
381         size_t i = 0;
382         do {
383             dataLog("   k%u = %s\n", static_cast<unsigned>(i), valueToSourceString(exec, m_constantRegisters[i].get()).utf8().data());
384             ++i;
385         } while (i < m_constantRegisters.size());
386     }
387
388     if (m_rareData && !m_rareData->m_regexps.isEmpty()) {
389         dataLog("\nm_regexps:\n");
390         size_t i = 0;
391         do {
392             dataLog("  re%u = %s\n", static_cast<unsigned>(i), regexpToSourceString(m_rareData->m_regexps[i].get()).utf8().data());
393             ++i;
394         } while (i < m_rareData->m_regexps.size());
395     }
396
397 #if ENABLE(JIT)
398     if (!m_globalResolveInfos.isEmpty() || !m_structureStubInfos.isEmpty())
399         dataLog("\nStructures:\n");
400
401     if (!m_globalResolveInfos.isEmpty()) {
402         size_t i = 0;
403         do {
404              printGlobalResolveInfo(m_globalResolveInfos[i], instructionOffsetForNth(exec, instructions(), i + 1, isGlobalResolve));
405              ++i;
406         } while (i < m_globalResolveInfos.size());
407     }
408     if (!m_structureStubInfos.isEmpty()) {
409         size_t i = 0;
410         do {
411             printStructureStubInfo(m_structureStubInfos[i], instructionOffsetForNth(exec, instructions(), i + 1, isPropertyAccess));
412              ++i;
413         } while (i < m_structureStubInfos.size());
414     }
415 #endif
416 #if ENABLE(CLASSIC_INTERPRETER)
417     if (!m_globalResolveInstructions.isEmpty() || !m_propertyAccessInstructions.isEmpty())
418         dataLog("\nStructures:\n");
419
420     if (!m_globalResolveInstructions.isEmpty()) {
421         size_t i = 0;
422         do {
423              printStructures(&instructions()[m_globalResolveInstructions[i]]);
424              ++i;
425         } while (i < m_globalResolveInstructions.size());
426     }
427     if (!m_propertyAccessInstructions.isEmpty()) {
428         size_t i = 0;
429         do {
430             printStructures(&instructions()[m_propertyAccessInstructions[i]]);
431              ++i;
432         } while (i < m_propertyAccessInstructions.size());
433     }
434 #endif
435
436     if (m_rareData && !m_rareData->m_exceptionHandlers.isEmpty()) {
437         dataLog("\nException Handlers:\n");
438         unsigned i = 0;
439         do {
440             dataLog("\t %d: { start: [%4d] end: [%4d] target: [%4d] }\n", i + 1, m_rareData->m_exceptionHandlers[i].start, m_rareData->m_exceptionHandlers[i].end, m_rareData->m_exceptionHandlers[i].target);
441             ++i;
442         } while (i < m_rareData->m_exceptionHandlers.size());
443     }
444     
445     if (m_rareData && !m_rareData->m_immediateSwitchJumpTables.isEmpty()) {
446         dataLog("Immediate Switch Jump Tables:\n");
447         unsigned i = 0;
448         do {
449             dataLog("  %1d = {\n", i);
450             int entry = 0;
451             Vector<int32_t>::const_iterator end = m_rareData->m_immediateSwitchJumpTables[i].branchOffsets.end();
452             for (Vector<int32_t>::const_iterator iter = m_rareData->m_immediateSwitchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) {
453                 if (!*iter)
454                     continue;
455                 dataLog("\t\t%4d => %04d\n", entry + m_rareData->m_immediateSwitchJumpTables[i].min, *iter);
456             }
457             dataLog("      }\n");
458             ++i;
459         } while (i < m_rareData->m_immediateSwitchJumpTables.size());
460     }
461     
462     if (m_rareData && !m_rareData->m_characterSwitchJumpTables.isEmpty()) {
463         dataLog("\nCharacter Switch Jump Tables:\n");
464         unsigned i = 0;
465         do {
466             dataLog("  %1d = {\n", i);
467             int entry = 0;
468             Vector<int32_t>::const_iterator end = m_rareData->m_characterSwitchJumpTables[i].branchOffsets.end();
469             for (Vector<int32_t>::const_iterator iter = m_rareData->m_characterSwitchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) {
470                 if (!*iter)
471                     continue;
472                 ASSERT(!((i + m_rareData->m_characterSwitchJumpTables[i].min) & ~0xFFFF));
473                 UChar ch = static_cast<UChar>(entry + m_rareData->m_characterSwitchJumpTables[i].min);
474                 dataLog("\t\t\"%s\" => %04d\n", UString(&ch, 1).utf8().data(), *iter);
475         }
476             dataLog("      }\n");
477             ++i;
478         } while (i < m_rareData->m_characterSwitchJumpTables.size());
479     }
480     
481     if (m_rareData && !m_rareData->m_stringSwitchJumpTables.isEmpty()) {
482         dataLog("\nString Switch Jump Tables:\n");
483         unsigned i = 0;
484         do {
485             dataLog("  %1d = {\n", i);
486             StringJumpTable::StringOffsetTable::const_iterator end = m_rareData->m_stringSwitchJumpTables[i].offsetTable.end();
487             for (StringJumpTable::StringOffsetTable::const_iterator iter = m_rareData->m_stringSwitchJumpTables[i].offsetTable.begin(); iter != end; ++iter)
488                 dataLog("\t\t\"%s\" => %04d\n", UString(iter->first).utf8().data(), iter->second.branchOffset);
489             dataLog("      }\n");
490             ++i;
491         } while (i < m_rareData->m_stringSwitchJumpTables.size());
492     }
493
494     dataLog("\n");
495 }
496
497 void CodeBlock::dump(ExecState* exec, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator& it) const
498 {
499     int location = it - begin;
500     switch (exec->interpreter()->getOpcodeID(it->u.opcode)) {
501         case op_enter: {
502             dataLog("[%4d] enter\n", location);
503             break;
504         }
505         case op_create_activation: {
506             int r0 = (++it)->u.operand;
507             dataLog("[%4d] create_activation %s\n", location, registerName(exec, r0).data());
508             break;
509         }
510         case op_create_arguments: {
511             int r0 = (++it)->u.operand;
512             dataLog("[%4d] create_arguments\t %s\n", location, registerName(exec, r0).data());
513             break;
514         }
515         case op_init_lazy_reg: {
516             int r0 = (++it)->u.operand;
517             dataLog("[%4d] init_lazy_reg\t %s\n", location, registerName(exec, r0).data());
518             break;
519         }
520         case op_get_callee: {
521             int r0 = (++it)->u.operand;
522             dataLog("[%4d] op_get_callee %s\n", location, registerName(exec, r0).data());
523             break;
524         }
525         case op_create_this: {
526             int r0 = (++it)->u.operand;
527             int r1 = (++it)->u.operand;
528             dataLog("[%4d] create_this %s %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
529             break;
530         }
531         case op_convert_this: {
532             int r0 = (++it)->u.operand;
533             dataLog("[%4d] convert_this\t %s\n", location, registerName(exec, r0).data());
534             break;
535         }
536         case op_new_object: {
537             int r0 = (++it)->u.operand;
538             dataLog("[%4d] new_object\t %s\n", location, registerName(exec, r0).data());
539             break;
540         }
541         case op_new_array: {
542             int dst = (++it)->u.operand;
543             int argv = (++it)->u.operand;
544             int argc = (++it)->u.operand;
545             dataLog("[%4d] new_array\t %s, %s, %d\n", location, registerName(exec, dst).data(), registerName(exec, argv).data(), argc);
546             break;
547         }
548         case op_new_array_buffer: {
549             int dst = (++it)->u.operand;
550             int argv = (++it)->u.operand;
551             int argc = (++it)->u.operand;
552             dataLog("[%4d] new_array_buffer %s, %d, %d\n", location, registerName(exec, dst).data(), argv, argc);
553             break;
554         }
555         case op_new_regexp: {
556             int r0 = (++it)->u.operand;
557             int re0 = (++it)->u.operand;
558             dataLog("[%4d] new_regexp\t %s, ", location, registerName(exec, r0).data());
559             if (r0 >=0 && r0 < (int)numberOfRegExps())
560                 dataLog("%s\n", regexpName(re0, regexp(re0)).data());
561             else
562                 dataLog("bad_regexp(%d)\n", re0);
563             break;
564         }
565         case op_mov: {
566             int r0 = (++it)->u.operand;
567             int r1 = (++it)->u.operand;
568             dataLog("[%4d] mov\t\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
569             break;
570         }
571         case op_not: {
572             printUnaryOp(exec, location, it, "not");
573             break;
574         }
575         case op_eq: {
576             printBinaryOp(exec, location, it, "eq");
577             break;
578         }
579         case op_eq_null: {
580             printUnaryOp(exec, location, it, "eq_null");
581             break;
582         }
583         case op_neq: {
584             printBinaryOp(exec, location, it, "neq");
585             break;
586         }
587         case op_neq_null: {
588             printUnaryOp(exec, location, it, "neq_null");
589             break;
590         }
591         case op_stricteq: {
592             printBinaryOp(exec, location, it, "stricteq");
593             break;
594         }
595         case op_nstricteq: {
596             printBinaryOp(exec, location, it, "nstricteq");
597             break;
598         }
599         case op_less: {
600             printBinaryOp(exec, location, it, "less");
601             break;
602         }
603         case op_lesseq: {
604             printBinaryOp(exec, location, it, "lesseq");
605             break;
606         }
607         case op_greater: {
608             printBinaryOp(exec, location, it, "greater");
609             break;
610         }
611         case op_greatereq: {
612             printBinaryOp(exec, location, it, "greatereq");
613             break;
614         }
615         case op_pre_inc: {
616             int r0 = (++it)->u.operand;
617             dataLog("[%4d] pre_inc\t\t %s\n", location, registerName(exec, r0).data());
618             break;
619         }
620         case op_pre_dec: {
621             int r0 = (++it)->u.operand;
622             dataLog("[%4d] pre_dec\t\t %s\n", location, registerName(exec, r0).data());
623             break;
624         }
625         case op_post_inc: {
626             printUnaryOp(exec, location, it, "post_inc");
627             break;
628         }
629         case op_post_dec: {
630             printUnaryOp(exec, location, it, "post_dec");
631             break;
632         }
633         case op_to_jsnumber: {
634             printUnaryOp(exec, location, it, "to_jsnumber");
635             break;
636         }
637         case op_negate: {
638             printUnaryOp(exec, location, it, "negate");
639             break;
640         }
641         case op_add: {
642             printBinaryOp(exec, location, it, "add");
643             ++it;
644             break;
645         }
646         case op_mul: {
647             printBinaryOp(exec, location, it, "mul");
648             ++it;
649             break;
650         }
651         case op_div: {
652             printBinaryOp(exec, location, it, "div");
653             ++it;
654             break;
655         }
656         case op_mod: {
657             printBinaryOp(exec, location, it, "mod");
658             break;
659         }
660         case op_sub: {
661             printBinaryOp(exec, location, it, "sub");
662             ++it;
663             break;
664         }
665         case op_lshift: {
666             printBinaryOp(exec, location, it, "lshift");
667             break;            
668         }
669         case op_rshift: {
670             printBinaryOp(exec, location, it, "rshift");
671             break;
672         }
673         case op_urshift: {
674             printBinaryOp(exec, location, it, "urshift");
675             break;
676         }
677         case op_bitand: {
678             printBinaryOp(exec, location, it, "bitand");
679             ++it;
680             break;
681         }
682         case op_bitxor: {
683             printBinaryOp(exec, location, it, "bitxor");
684             ++it;
685             break;
686         }
687         case op_bitor: {
688             printBinaryOp(exec, location, it, "bitor");
689             ++it;
690             break;
691         }
692         case op_bitnot: {
693             printUnaryOp(exec, location, it, "bitnot");
694             break;
695         }
696         case op_check_has_instance: {
697             int base = (++it)->u.operand;
698             dataLog("[%4d] check_has_instance\t\t %s\n", location, registerName(exec, base).data());
699             break;
700         }
701         case op_instanceof: {
702             int r0 = (++it)->u.operand;
703             int r1 = (++it)->u.operand;
704             int r2 = (++it)->u.operand;
705             int r3 = (++it)->u.operand;
706             dataLog("[%4d] instanceof\t\t %s, %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), registerName(exec, r3).data());
707             break;
708         }
709         case op_typeof: {
710             printUnaryOp(exec, location, it, "typeof");
711             break;
712         }
713         case op_is_undefined: {
714             printUnaryOp(exec, location, it, "is_undefined");
715             break;
716         }
717         case op_is_boolean: {
718             printUnaryOp(exec, location, it, "is_boolean");
719             break;
720         }
721         case op_is_number: {
722             printUnaryOp(exec, location, it, "is_number");
723             break;
724         }
725         case op_is_string: {
726             printUnaryOp(exec, location, it, "is_string");
727             break;
728         }
729         case op_is_object: {
730             printUnaryOp(exec, location, it, "is_object");
731             break;
732         }
733         case op_is_function: {
734             printUnaryOp(exec, location, it, "is_function");
735             break;
736         }
737         case op_in: {
738             printBinaryOp(exec, location, it, "in");
739             break;
740         }
741         case op_resolve: {
742             int r0 = (++it)->u.operand;
743             int id0 = (++it)->u.operand;
744             dataLog("[%4d] resolve\t\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data());
745             it++;
746             break;
747         }
748         case op_resolve_skip: {
749             int r0 = (++it)->u.operand;
750             int id0 = (++it)->u.operand;
751             int skipLevels = (++it)->u.operand;
752             dataLog("[%4d] resolve_skip\t %s, %s, %d\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), skipLevels);
753             it++;
754             break;
755         }
756         case op_resolve_global: {
757             int r0 = (++it)->u.operand;
758             int id0 = (++it)->u.operand;
759             dataLog("[%4d] resolve_global\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data());
760             it += 3;
761             break;
762         }
763         case op_resolve_global_dynamic: {
764             int r0 = (++it)->u.operand;
765             int id0 = (++it)->u.operand;
766             JSValue scope = JSValue((++it)->u.jsCell.get());
767             ++it;
768             int depth = (++it)->u.operand;
769             dataLog("[%4d] resolve_global_dynamic\t %s, %s, %s, %d\n", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).utf8().data(), idName(id0, m_identifiers[id0]).data(), depth);
770             ++it;
771             break;
772         }
773         case op_get_scoped_var: {
774             int r0 = (++it)->u.operand;
775             int index = (++it)->u.operand;
776             int skipLevels = (++it)->u.operand;
777             dataLog("[%4d] get_scoped_var\t %s, %d, %d\n", location, registerName(exec, r0).data(), index, skipLevels);
778             it++;
779             break;
780         }
781         case op_put_scoped_var: {
782             int index = (++it)->u.operand;
783             int skipLevels = (++it)->u.operand;
784             int r0 = (++it)->u.operand;
785             dataLog("[%4d] put_scoped_var\t %d, %d, %s\n", location, index, skipLevels, registerName(exec, r0).data());
786             break;
787         }
788         case op_get_global_var: {
789             int r0 = (++it)->u.operand;
790             int index = (++it)->u.operand;
791             dataLog("[%4d] get_global_var\t %s, %d\n", location, registerName(exec, r0).data(), index);
792             it++;
793             break;
794         }
795         case op_put_global_var: {
796             int index = (++it)->u.operand;
797             int r0 = (++it)->u.operand;
798             dataLog("[%4d] put_global_var\t %d, %s\n", location, index, registerName(exec, r0).data());
799             break;
800         }
801         case op_resolve_base: {
802             int r0 = (++it)->u.operand;
803             int id0 = (++it)->u.operand;
804             int isStrict = (++it)->u.operand;
805             dataLog("[%4d] resolve_base%s\t %s, %s\n", location, isStrict ? "_strict" : "", registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data());
806             it++;
807             break;
808         }
809         case op_ensure_property_exists: {
810             int r0 = (++it)->u.operand;
811             int id0 = (++it)->u.operand;
812             dataLog("[%4d] ensure_property_exists\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data());
813             break;
814         }
815         case op_resolve_with_base: {
816             int r0 = (++it)->u.operand;
817             int r1 = (++it)->u.operand;
818             int id0 = (++it)->u.operand;
819             dataLog("[%4d] resolve_with_base %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
820             it++;
821             break;
822         }
823         case op_resolve_with_this: {
824             int r0 = (++it)->u.operand;
825             int r1 = (++it)->u.operand;
826             int id0 = (++it)->u.operand;
827             dataLog("[%4d] resolve_with_this %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
828             it++;
829             break;
830         }
831         case op_get_by_id: {
832             printGetByIdOp(exec, location, it, "get_by_id");
833             break;
834         }
835         case op_get_by_id_self: {
836             printGetByIdOp(exec, location, it, "get_by_id_self");
837             break;
838         }
839         case op_get_by_id_proto: {
840             printGetByIdOp(exec, location, it, "get_by_id_proto");
841             break;
842         }
843         case op_get_by_id_chain: {
844             printGetByIdOp(exec, location, it, "get_by_id_chain");
845             break;
846         }
847         case op_get_by_id_getter_self: {
848             printGetByIdOp(exec, location, it, "get_by_id_getter_self");
849             break;
850         }
851         case op_get_by_id_getter_proto: {
852             printGetByIdOp(exec, location, it, "get_by_id_getter_proto");
853             break;
854         }
855         case op_get_by_id_getter_chain: {
856             printGetByIdOp(exec, location, it, "get_by_id_getter_chain");
857             break;
858         }
859         case op_get_by_id_custom_self: {
860             printGetByIdOp(exec, location, it, "get_by_id_custom_self");
861             break;
862         }
863         case op_get_by_id_custom_proto: {
864             printGetByIdOp(exec, location, it, "get_by_id_custom_proto");
865             break;
866         }
867         case op_get_by_id_custom_chain: {
868             printGetByIdOp(exec, location, it, "get_by_id_custom_chain");
869             break;
870         }
871         case op_get_by_id_generic: {
872             printGetByIdOp(exec, location, it, "get_by_id_generic");
873             break;
874         }
875         case op_get_array_length: {
876             printGetByIdOp(exec, location, it, "get_array_length");
877             break;
878         }
879         case op_get_string_length: {
880             printGetByIdOp(exec, location, it, "get_string_length");
881             break;
882         }
883         case op_get_arguments_length: {
884             printUnaryOp(exec, location, it, "get_arguments_length");
885             it++;
886             break;
887         }
888         case op_put_by_id: {
889             printPutByIdOp(exec, location, it, "put_by_id");
890             break;
891         }
892         case op_put_by_id_replace: {
893             printPutByIdOp(exec, location, it, "put_by_id_replace");
894             break;
895         }
896         case op_put_by_id_transition: {
897             printPutByIdOp(exec, location, it, "put_by_id_transition");
898             break;
899         }
900         case op_put_by_id_transition_direct: {
901             printPutByIdOp(exec, location, it, "put_by_id_transition_direct");
902             break;
903         }
904         case op_put_by_id_transition_normal: {
905             printPutByIdOp(exec, location, it, "put_by_id_transition_normal");
906             break;
907         }
908         case op_put_by_id_generic: {
909             printPutByIdOp(exec, location, it, "put_by_id_generic");
910             break;
911         }
912         case op_put_getter_setter: {
913             int r0 = (++it)->u.operand;
914             int id0 = (++it)->u.operand;
915             int r1 = (++it)->u.operand;
916             int r2 = (++it)->u.operand;
917             dataLog("[%4d] put_getter_setter\t %s, %s, %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
918             break;
919         }
920         case op_method_check: {
921             dataLog("[%4d] method_check\n", location);
922             break;
923         }
924         case op_del_by_id: {
925             int r0 = (++it)->u.operand;
926             int r1 = (++it)->u.operand;
927             int id0 = (++it)->u.operand;
928             dataLog("[%4d] del_by_id\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
929             break;
930         }
931         case op_get_by_val: {
932             int r0 = (++it)->u.operand;
933             int r1 = (++it)->u.operand;
934             int r2 = (++it)->u.operand;
935             dataLog("[%4d] get_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
936             it++;
937             break;
938         }
939         case op_get_argument_by_val: {
940             int r0 = (++it)->u.operand;
941             int r1 = (++it)->u.operand;
942             int r2 = (++it)->u.operand;
943             dataLog("[%4d] get_argument_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
944             ++it;
945             break;
946         }
947         case op_get_by_pname: {
948             int r0 = (++it)->u.operand;
949             int r1 = (++it)->u.operand;
950             int r2 = (++it)->u.operand;
951             int r3 = (++it)->u.operand;
952             int r4 = (++it)->u.operand;
953             int r5 = (++it)->u.operand;
954             dataLog("[%4d] get_by_pname\t %s, %s, %s, %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), registerName(exec, r3).data(), registerName(exec, r4).data(), registerName(exec, r5).data());
955             break;
956         }
957         case op_put_by_val: {
958             int r0 = (++it)->u.operand;
959             int r1 = (++it)->u.operand;
960             int r2 = (++it)->u.operand;
961             dataLog("[%4d] put_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
962             break;
963         }
964         case op_del_by_val: {
965             int r0 = (++it)->u.operand;
966             int r1 = (++it)->u.operand;
967             int r2 = (++it)->u.operand;
968             dataLog("[%4d] del_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
969             break;
970         }
971         case op_put_by_index: {
972             int r0 = (++it)->u.operand;
973             unsigned n0 = (++it)->u.operand;
974             int r1 = (++it)->u.operand;
975             dataLog("[%4d] put_by_index\t %s, %u, %s\n", location, registerName(exec, r0).data(), n0, registerName(exec, r1).data());
976             break;
977         }
978         case op_jmp: {
979             int offset = (++it)->u.operand;
980             dataLog("[%4d] jmp\t\t %d(->%d)\n", location, offset, location + offset);
981             break;
982         }
983         case op_loop: {
984             int offset = (++it)->u.operand;
985             dataLog("[%4d] loop\t\t %d(->%d)\n", location, offset, location + offset);
986             break;
987         }
988         case op_jtrue: {
989             printConditionalJump(exec, begin, it, location, "jtrue");
990             break;
991         }
992         case op_loop_if_true: {
993             printConditionalJump(exec, begin, it, location, "loop_if_true");
994             break;
995         }
996         case op_loop_if_false: {
997             printConditionalJump(exec, begin, it, location, "loop_if_false");
998             break;
999         }
1000         case op_jfalse: {
1001             printConditionalJump(exec, begin, it, location, "jfalse");
1002             break;
1003         }
1004         case op_jeq_null: {
1005             printConditionalJump(exec, begin, it, location, "jeq_null");
1006             break;
1007         }
1008         case op_jneq_null: {
1009             printConditionalJump(exec, begin, it, location, "jneq_null");
1010             break;
1011         }
1012         case op_jneq_ptr: {
1013             int r0 = (++it)->u.operand;
1014             int r1 = (++it)->u.operand;
1015             int offset = (++it)->u.operand;
1016             dataLog("[%4d] jneq_ptr\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1017             break;
1018         }
1019         case op_jless: {
1020             int r0 = (++it)->u.operand;
1021             int r1 = (++it)->u.operand;
1022             int offset = (++it)->u.operand;
1023             dataLog("[%4d] jless\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1024             break;
1025         }
1026         case op_jlesseq: {
1027             int r0 = (++it)->u.operand;
1028             int r1 = (++it)->u.operand;
1029             int offset = (++it)->u.operand;
1030             dataLog("[%4d] jlesseq\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1031             break;
1032         }
1033         case op_jgreater: {
1034             int r0 = (++it)->u.operand;
1035             int r1 = (++it)->u.operand;
1036             int offset = (++it)->u.operand;
1037             dataLog("[%4d] jgreater\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1038             break;
1039         }
1040         case op_jgreatereq: {
1041             int r0 = (++it)->u.operand;
1042             int r1 = (++it)->u.operand;
1043             int offset = (++it)->u.operand;
1044             dataLog("[%4d] jgreatereq\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1045             break;
1046         }
1047         case op_jnless: {
1048             int r0 = (++it)->u.operand;
1049             int r1 = (++it)->u.operand;
1050             int offset = (++it)->u.operand;
1051             dataLog("[%4d] jnless\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1052             break;
1053         }
1054         case op_jnlesseq: {
1055             int r0 = (++it)->u.operand;
1056             int r1 = (++it)->u.operand;
1057             int offset = (++it)->u.operand;
1058             dataLog("[%4d] jnlesseq\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1059             break;
1060         }
1061         case op_jngreater: {
1062             int r0 = (++it)->u.operand;
1063             int r1 = (++it)->u.operand;
1064             int offset = (++it)->u.operand;
1065             dataLog("[%4d] jngreater\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1066             break;
1067         }
1068         case op_jngreatereq: {
1069             int r0 = (++it)->u.operand;
1070             int r1 = (++it)->u.operand;
1071             int offset = (++it)->u.operand;
1072             dataLog("[%4d] jngreatereq\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1073             break;
1074         }
1075         case op_loop_if_less: {
1076             int r0 = (++it)->u.operand;
1077             int r1 = (++it)->u.operand;
1078             int offset = (++it)->u.operand;
1079             dataLog("[%4d] loop_if_less\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1080             break;
1081         }
1082         case op_loop_if_lesseq: {
1083             int r0 = (++it)->u.operand;
1084             int r1 = (++it)->u.operand;
1085             int offset = (++it)->u.operand;
1086             dataLog("[%4d] loop_if_lesseq\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1087             break;
1088         }
1089         case op_loop_if_greater: {
1090             int r0 = (++it)->u.operand;
1091             int r1 = (++it)->u.operand;
1092             int offset = (++it)->u.operand;
1093             dataLog("[%4d] loop_if_greater\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1094             break;
1095         }
1096         case op_loop_if_greatereq: {
1097             int r0 = (++it)->u.operand;
1098             int r1 = (++it)->u.operand;
1099             int offset = (++it)->u.operand;
1100             dataLog("[%4d] loop_if_greatereq\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
1101             break;
1102         }
1103         case op_loop_hint: {
1104             dataLog("[%4d] loop_hint\n", location);
1105             break;
1106         }
1107         case op_switch_imm: {
1108             int tableIndex = (++it)->u.operand;
1109             int defaultTarget = (++it)->u.operand;
1110             int scrutineeRegister = (++it)->u.operand;
1111             dataLog("[%4d] switch_imm\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
1112             break;
1113         }
1114         case op_switch_char: {
1115             int tableIndex = (++it)->u.operand;
1116             int defaultTarget = (++it)->u.operand;
1117             int scrutineeRegister = (++it)->u.operand;
1118             dataLog("[%4d] switch_char\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
1119             break;
1120         }
1121         case op_switch_string: {
1122             int tableIndex = (++it)->u.operand;
1123             int defaultTarget = (++it)->u.operand;
1124             int scrutineeRegister = (++it)->u.operand;
1125             dataLog("[%4d] switch_string\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
1126             break;
1127         }
1128         case op_new_func: {
1129             int r0 = (++it)->u.operand;
1130             int f0 = (++it)->u.operand;
1131             int shouldCheck = (++it)->u.operand;
1132             dataLog("[%4d] new_func\t\t %s, f%d, %s\n", location, registerName(exec, r0).data(), f0, shouldCheck ? "<Checked>" : "<Unchecked>");
1133             break;
1134         }
1135         case op_new_func_exp: {
1136             int r0 = (++it)->u.operand;
1137             int f0 = (++it)->u.operand;
1138             dataLog("[%4d] new_func_exp\t %s, f%d\n", location, registerName(exec, r0).data(), f0);
1139             break;
1140         }
1141         case op_call: {
1142             printCallOp(exec, location, it, "call");
1143             break;
1144         }
1145         case op_call_eval: {
1146             printCallOp(exec, location, it, "call_eval");
1147             break;
1148         }
1149         case op_call_varargs: {
1150             int callee = (++it)->u.operand;
1151             int thisValue = (++it)->u.operand;
1152             int arguments = (++it)->u.operand;
1153             int firstFreeRegister = (++it)->u.operand;
1154             dataLog("[%4d] call_varargs\t %s, %s, %s, %d\n", location, registerName(exec, callee).data(), registerName(exec, thisValue).data(), registerName(exec, arguments).data(), firstFreeRegister);
1155             break;
1156         }
1157         case op_tear_off_activation: {
1158             int r0 = (++it)->u.operand;
1159             int r1 = (++it)->u.operand;
1160             dataLog("[%4d] tear_off_activation\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
1161             break;
1162         }
1163         case op_tear_off_arguments: {
1164             int r0 = (++it)->u.operand;
1165             dataLog("[%4d] tear_off_arguments %s\n", location, registerName(exec, r0).data());
1166             break;
1167         }
1168         case op_ret: {
1169             int r0 = (++it)->u.operand;
1170             dataLog("[%4d] ret\t\t %s\n", location, registerName(exec, r0).data());
1171             break;
1172         }
1173         case op_call_put_result: {
1174             int r0 = (++it)->u.operand;
1175             dataLog("[%4d] op_call_put_result\t\t %s\n", location, registerName(exec, r0).data());
1176             it++;
1177             break;
1178         }
1179         case op_ret_object_or_this: {
1180             int r0 = (++it)->u.operand;
1181             int r1 = (++it)->u.operand;
1182             dataLog("[%4d] constructor_ret\t\t %s %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
1183             break;
1184         }
1185         case op_construct: {
1186             printCallOp(exec, location, it, "construct");
1187             break;
1188         }
1189         case op_strcat: {
1190             int r0 = (++it)->u.operand;
1191             int r1 = (++it)->u.operand;
1192             int count = (++it)->u.operand;
1193             dataLog("[%4d] strcat\t\t %s, %s, %d\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), count);
1194             break;
1195         }
1196         case op_to_primitive: {
1197             int r0 = (++it)->u.operand;
1198             int r1 = (++it)->u.operand;
1199             dataLog("[%4d] to_primitive\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
1200             break;
1201         }
1202         case op_get_pnames: {
1203             int r0 = it[1].u.operand;
1204             int r1 = it[2].u.operand;
1205             int r2 = it[3].u.operand;
1206             int r3 = it[4].u.operand;
1207             int offset = it[5].u.operand;
1208             dataLog("[%4d] get_pnames\t %s, %s, %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), registerName(exec, r3).data(), offset, location + offset);
1209             it += OPCODE_LENGTH(op_get_pnames) - 1;
1210             break;
1211         }
1212         case op_next_pname: {
1213             int dest = it[1].u.operand;
1214             int base = it[2].u.operand;
1215             int i = it[3].u.operand;
1216             int size = it[4].u.operand;
1217             int iter = it[5].u.operand;
1218             int offset = it[6].u.operand;
1219             dataLog("[%4d] next_pname\t %s, %s, %s, %s, %s, %d(->%d)\n", location, registerName(exec, dest).data(), registerName(exec, base).data(), registerName(exec, i).data(), registerName(exec, size).data(), registerName(exec, iter).data(), offset, location + offset);
1220             it += OPCODE_LENGTH(op_next_pname) - 1;
1221             break;
1222         }
1223         case op_push_scope: {
1224             int r0 = (++it)->u.operand;
1225             dataLog("[%4d] push_scope\t %s\n", location, registerName(exec, r0).data());
1226             break;
1227         }
1228         case op_pop_scope: {
1229             dataLog("[%4d] pop_scope\n", location);
1230             break;
1231         }
1232         case op_push_new_scope: {
1233             int r0 = (++it)->u.operand;
1234             int id0 = (++it)->u.operand;
1235             int r1 = (++it)->u.operand;
1236             dataLog("[%4d] push_new_scope \t%s, %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data());
1237             break;
1238         }
1239         case op_jmp_scopes: {
1240             int scopeDelta = (++it)->u.operand;
1241             int offset = (++it)->u.operand;
1242             dataLog("[%4d] jmp_scopes\t^%d, %d(->%d)\n", location, scopeDelta, offset, location + offset);
1243             break;
1244         }
1245         case op_catch: {
1246             int r0 = (++it)->u.operand;
1247             dataLog("[%4d] catch\t\t %s\n", location, registerName(exec, r0).data());
1248             break;
1249         }
1250         case op_throw: {
1251             int r0 = (++it)->u.operand;
1252             dataLog("[%4d] throw\t\t %s\n", location, registerName(exec, r0).data());
1253             break;
1254         }
1255         case op_throw_reference_error: {
1256             int k0 = (++it)->u.operand;
1257             dataLog("[%4d] throw_reference_error\t %s\n", location, constantName(exec, k0, getConstant(k0)).data());
1258             break;
1259         }
1260         case op_jsr: {
1261             int retAddrDst = (++it)->u.operand;
1262             int offset = (++it)->u.operand;
1263             dataLog("[%4d] jsr\t\t %s, %d(->%d)\n", location, registerName(exec, retAddrDst).data(), offset, location + offset);
1264             break;
1265         }
1266         case op_sret: {
1267             int retAddrSrc = (++it)->u.operand;
1268             dataLog("[%4d] sret\t\t %s\n", location, registerName(exec, retAddrSrc).data());
1269             break;
1270         }
1271         case op_debug: {
1272             int debugHookID = (++it)->u.operand;
1273             int firstLine = (++it)->u.operand;
1274             int lastLine = (++it)->u.operand;
1275             dataLog("[%4d] debug\t\t %s, %d, %d\n", location, debugHookName(debugHookID), firstLine, lastLine);
1276             break;
1277         }
1278         case op_profile_will_call: {
1279             int function = (++it)->u.operand;
1280             dataLog("[%4d] profile_will_call %s\n", location, registerName(exec, function).data());
1281             break;
1282         }
1283         case op_profile_did_call: {
1284             int function = (++it)->u.operand;
1285             dataLog("[%4d] profile_did_call\t %s\n", location, registerName(exec, function).data());
1286             break;
1287         }
1288         case op_end: {
1289             int r0 = (++it)->u.operand;
1290             dataLog("[%4d] end\t\t %s\n", location, registerName(exec, r0).data());
1291             break;
1292         }
1293     }
1294 }
1295
1296 #if DUMP_CODE_BLOCK_STATISTICS
1297 static HashSet<CodeBlock*> liveCodeBlockSet;
1298 #endif
1299
1300 #define FOR_EACH_MEMBER_VECTOR(macro) \
1301     macro(instructions) \
1302     macro(globalResolveInfos) \
1303     macro(structureStubInfos) \
1304     macro(callLinkInfos) \
1305     macro(linkedCallerList) \
1306     macro(identifiers) \
1307     macro(functionExpressions) \
1308     macro(constantRegisters)
1309
1310 #define FOR_EACH_MEMBER_VECTOR_RARE_DATA(macro) \
1311     macro(regexps) \
1312     macro(functions) \
1313     macro(exceptionHandlers) \
1314     macro(immediateSwitchJumpTables) \
1315     macro(characterSwitchJumpTables) \
1316     macro(stringSwitchJumpTables) \
1317     macro(evalCodeCache) \
1318     macro(expressionInfo) \
1319     macro(lineInfo) \
1320     macro(callReturnIndexVector)
1321
1322 template<typename T>
1323 static size_t sizeInBytes(const Vector<T>& vector)
1324 {
1325     return vector.capacity() * sizeof(T);
1326 }
1327
1328 void CodeBlock::dumpStatistics()
1329 {
1330 #if DUMP_CODE_BLOCK_STATISTICS
1331     #define DEFINE_VARS(name) size_t name##IsNotEmpty = 0; size_t name##TotalSize = 0;
1332         FOR_EACH_MEMBER_VECTOR(DEFINE_VARS)
1333         FOR_EACH_MEMBER_VECTOR_RARE_DATA(DEFINE_VARS)
1334     #undef DEFINE_VARS
1335
1336     // Non-vector data members
1337     size_t evalCodeCacheIsNotEmpty = 0;
1338
1339     size_t symbolTableIsNotEmpty = 0;
1340     size_t symbolTableTotalSize = 0;
1341
1342     size_t hasRareData = 0;
1343
1344     size_t isFunctionCode = 0;
1345     size_t isGlobalCode = 0;
1346     size_t isEvalCode = 0;
1347
1348     HashSet<CodeBlock*>::const_iterator end = liveCodeBlockSet.end();
1349     for (HashSet<CodeBlock*>::const_iterator it = liveCodeBlockSet.begin(); it != end; ++it) {
1350         CodeBlock* codeBlock = *it;
1351
1352         #define GET_STATS(name) if (!codeBlock->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_##name); }
1353             FOR_EACH_MEMBER_VECTOR(GET_STATS)
1354         #undef GET_STATS
1355
1356         if (!codeBlock->m_symbolTable.isEmpty()) {
1357             symbolTableIsNotEmpty++;
1358             symbolTableTotalSize += (codeBlock->m_symbolTable.capacity() * (sizeof(SymbolTable::KeyType) + sizeof(SymbolTable::MappedType)));
1359         }
1360
1361         if (codeBlock->m_rareData) {
1362             hasRareData++;
1363             #define GET_STATS(name) if (!codeBlock->m_rareData->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_rareData->m_##name); }
1364                 FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_STATS)
1365             #undef GET_STATS
1366
1367             if (!codeBlock->m_rareData->m_evalCodeCache.isEmpty())
1368                 evalCodeCacheIsNotEmpty++;
1369         }
1370
1371         switch (codeBlock->codeType()) {
1372             case FunctionCode:
1373                 ++isFunctionCode;
1374                 break;
1375             case GlobalCode:
1376                 ++isGlobalCode;
1377                 break;
1378             case EvalCode:
1379                 ++isEvalCode;
1380                 break;
1381         }
1382     }
1383
1384     size_t totalSize = 0;
1385
1386     #define GET_TOTAL_SIZE(name) totalSize += name##TotalSize;
1387         FOR_EACH_MEMBER_VECTOR(GET_TOTAL_SIZE)
1388         FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_TOTAL_SIZE)
1389     #undef GET_TOTAL_SIZE
1390
1391     totalSize += symbolTableTotalSize;
1392     totalSize += (liveCodeBlockSet.size() * sizeof(CodeBlock));
1393
1394     dataLog("Number of live CodeBlocks: %d\n", liveCodeBlockSet.size());
1395     dataLog("Size of a single CodeBlock [sizeof(CodeBlock)]: %zu\n", sizeof(CodeBlock));
1396     dataLog("Size of all CodeBlocks: %zu\n", totalSize);
1397     dataLog("Average size of a CodeBlock: %zu\n", totalSize / liveCodeBlockSet.size());
1398
1399     dataLog("Number of FunctionCode CodeBlocks: %zu (%.3f%%)\n", isFunctionCode, static_cast<double>(isFunctionCode) * 100.0 / liveCodeBlockSet.size());
1400     dataLog("Number of GlobalCode CodeBlocks: %zu (%.3f%%)\n", isGlobalCode, static_cast<double>(isGlobalCode) * 100.0 / liveCodeBlockSet.size());
1401     dataLog("Number of EvalCode CodeBlocks: %zu (%.3f%%)\n", isEvalCode, static_cast<double>(isEvalCode) * 100.0 / liveCodeBlockSet.size());
1402
1403     dataLog("Number of CodeBlocks with rare data: %zu (%.3f%%)\n", hasRareData, static_cast<double>(hasRareData) * 100.0 / liveCodeBlockSet.size());
1404
1405     #define PRINT_STATS(name) dataLog("Number of CodeBlocks with " #name ": %zu\n", name##IsNotEmpty); dataLog("Size of all " #name ": %zu\n", name##TotalSize); 
1406         FOR_EACH_MEMBER_VECTOR(PRINT_STATS)
1407         FOR_EACH_MEMBER_VECTOR_RARE_DATA(PRINT_STATS)
1408     #undef PRINT_STATS
1409
1410     dataLog("Number of CodeBlocks with evalCodeCache: %zu\n", evalCodeCacheIsNotEmpty);
1411     dataLog("Number of CodeBlocks with symbolTable: %zu\n", symbolTableIsNotEmpty);
1412
1413     dataLog("Size of all symbolTables: %zu\n", symbolTableTotalSize);
1414
1415 #else
1416     dataLog("Dumping CodeBlock statistics is not enabled.\n");
1417 #endif
1418 }
1419
1420 CodeBlock::CodeBlock(CopyParsedBlockTag, CodeBlock& other, SymbolTable* symTab)
1421     : m_globalObject(other.m_globalObject)
1422     , m_heap(other.m_heap)
1423     , m_numCalleeRegisters(other.m_numCalleeRegisters)
1424     , m_numVars(other.m_numVars)
1425     , m_numCapturedVars(other.m_numCapturedVars)
1426     , m_isConstructor(other.m_isConstructor)
1427     , m_shouldDiscardBytecode(false)
1428     , m_ownerExecutable(*other.m_globalData, other.m_ownerExecutable.get(), other.m_ownerExecutable.get())
1429     , m_globalData(other.m_globalData)
1430     , m_instructions(other.m_instructions)
1431     , m_instructionCount(other.m_instructionCount)
1432     , m_thisRegister(other.m_thisRegister)
1433     , m_argumentsRegister(other.m_argumentsRegister)
1434     , m_activationRegister(other.m_activationRegister)
1435     , m_needsFullScopeChain(other.m_needsFullScopeChain)
1436     , m_usesEval(other.m_usesEval)
1437     , m_isNumericCompareFunction(other.m_isNumericCompareFunction)
1438     , m_isStrictMode(other.m_isStrictMode)
1439     , m_codeType(other.m_codeType)
1440     , m_source(other.m_source)
1441     , m_sourceOffset(other.m_sourceOffset)
1442 #if ENABLE(JIT)
1443     , m_globalResolveInfos(other.m_globalResolveInfos)
1444 #endif
1445 #if ENABLE(VALUE_PROFILER)
1446     , m_executionEntryCount(0)
1447 #endif
1448     , m_jumpTargets(other.m_jumpTargets)
1449     , m_loopTargets(other.m_loopTargets)
1450     , m_identifiers(other.m_identifiers)
1451     , m_constantRegisters(other.m_constantRegisters)
1452     , m_functionDecls(other.m_functionDecls)
1453     , m_functionExprs(other.m_functionExprs)
1454     , m_symbolTable(symTab)
1455     , m_speculativeSuccessCounter(0)
1456     , m_speculativeFailCounter(0)
1457     , m_optimizationDelayCounter(0)
1458     , m_reoptimizationRetryCounter(0)
1459 #if ENABLE(JIT)
1460     , m_canCompileWithDFGState(CompileWithDFGUnset)
1461 #endif
1462 {
1463     setNumParameters(other.numParameters());
1464     optimizeAfterWarmUp();
1465     jitAfterWarmUp();
1466     
1467     if (other.m_rareData) {
1468         createRareDataIfNecessary();
1469         
1470         m_rareData->m_exceptionHandlers = other.m_rareData->m_exceptionHandlers;
1471         m_rareData->m_regexps = other.m_rareData->m_regexps;
1472         m_rareData->m_constantBuffers = other.m_rareData->m_constantBuffers;
1473         m_rareData->m_immediateSwitchJumpTables = other.m_rareData->m_immediateSwitchJumpTables;
1474         m_rareData->m_characterSwitchJumpTables = other.m_rareData->m_characterSwitchJumpTables;
1475         m_rareData->m_stringSwitchJumpTables = other.m_rareData->m_stringSwitchJumpTables;
1476         m_rareData->m_expressionInfo = other.m_rareData->m_expressionInfo;
1477         m_rareData->m_lineInfo = other.m_rareData->m_lineInfo;
1478     }
1479 }
1480
1481 CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject *globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, SymbolTable* symTab, bool isConstructor, PassOwnPtr<CodeBlock> alternative)
1482     : m_globalObject(globalObject->globalData(), ownerExecutable, globalObject)
1483     , m_heap(&m_globalObject->globalData().heap)
1484     , m_numCalleeRegisters(0)
1485     , m_numVars(0)
1486     , m_isConstructor(isConstructor)
1487     , m_shouldDiscardBytecode(false)
1488     , m_numParameters(0)
1489     , m_ownerExecutable(globalObject->globalData(), ownerExecutable, ownerExecutable)
1490     , m_globalData(0)
1491     , m_instructions(adoptRef(new Instructions))
1492     , m_instructionCount(0)
1493     , m_argumentsRegister(-1)
1494     , m_needsFullScopeChain(ownerExecutable->needsActivation())
1495     , m_usesEval(ownerExecutable->usesEval())
1496     , m_isNumericCompareFunction(false)
1497     , m_isStrictMode(ownerExecutable->isStrictMode())
1498     , m_codeType(codeType)
1499     , m_source(sourceProvider)
1500     , m_sourceOffset(sourceOffset)
1501 #if ENABLE(VALUE_PROFILER)
1502     , m_executionEntryCount(0)
1503 #endif
1504     , m_symbolTable(symTab)
1505     , m_alternative(alternative)
1506     , m_speculativeSuccessCounter(0)
1507     , m_speculativeFailCounter(0)
1508     , m_optimizationDelayCounter(0)
1509     , m_reoptimizationRetryCounter(0)
1510 {
1511     ASSERT(m_source);
1512     
1513     optimizeAfterWarmUp();
1514     jitAfterWarmUp();
1515
1516 #if DUMP_CODE_BLOCK_STATISTICS
1517     liveCodeBlockSet.add(this);
1518 #endif
1519 }
1520
1521 CodeBlock::~CodeBlock()
1522 {
1523 #if ENABLE(DFG_JIT)
1524     // Remove myself from the set of DFG code blocks. Note that I may not be in this set
1525     // (because I'm not a DFG code block), in which case this is a no-op anyway.
1526     m_globalData->heap.m_dfgCodeBlocks.m_set.remove(this);
1527 #endif
1528     
1529 #if ENABLE(VERBOSE_VALUE_PROFILE)
1530     dumpValueProfiles();
1531 #endif
1532
1533 #if ENABLE(LLINT)    
1534     while (m_incomingLLIntCalls.begin() != m_incomingLLIntCalls.end())
1535         m_incomingLLIntCalls.begin()->remove();
1536 #endif // ENABLE(LLINT)
1537 #if ENABLE(JIT)
1538     // We may be destroyed before any CodeBlocks that refer to us are destroyed.
1539     // Consider that two CodeBlocks become unreachable at the same time. There
1540     // is no guarantee about the order in which the CodeBlocks are destroyed.
1541     // So, if we don't remove incoming calls, and get destroyed before the
1542     // CodeBlock(s) that have calls into us, then the CallLinkInfo vector's
1543     // destructor will try to remove nodes from our (no longer valid) linked list.
1544     while (m_incomingCalls.begin() != m_incomingCalls.end())
1545         m_incomingCalls.begin()->remove();
1546     
1547     // Note that our outgoing calls will be removed from other CodeBlocks'
1548     // m_incomingCalls linked lists through the execution of the ~CallLinkInfo
1549     // destructors.
1550
1551     for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i)
1552         m_structureStubInfos[i].deref();
1553 #endif // ENABLE(JIT)
1554
1555 #if DUMP_CODE_BLOCK_STATISTICS
1556     liveCodeBlockSet.remove(this);
1557 #endif
1558 }
1559
1560 void CodeBlock::setNumParameters(int newValue)
1561 {
1562     m_numParameters = newValue;
1563
1564 #if ENABLE(VALUE_PROFILER)
1565     m_argumentValueProfiles.resize(newValue);
1566 #endif
1567 }
1568
1569 void CodeBlock::addParameter()
1570 {
1571     m_numParameters++;
1572
1573 #if ENABLE(VALUE_PROFILER)
1574     m_argumentValueProfiles.append(ValueProfile());
1575 #endif
1576 }
1577
1578 void CodeBlock::visitStructures(SlotVisitor& visitor, Instruction* vPC) const
1579 {
1580     Interpreter* interpreter = m_globalData->interpreter;
1581
1582     if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id) && vPC[4].u.structure) {
1583         visitor.append(&vPC[4].u.structure);
1584         return;
1585     }
1586
1587     if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_self) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_self)) {
1588         visitor.append(&vPC[4].u.structure);
1589         return;
1590     }
1591     if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_proto) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_proto)) {
1592         visitor.append(&vPC[4].u.structure);
1593         visitor.append(&vPC[5].u.structure);
1594         return;
1595     }
1596     if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_chain) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_chain)) {
1597         visitor.append(&vPC[4].u.structure);
1598         visitor.append(&vPC[5].u.structureChain);
1599         return;
1600     }
1601     if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) {
1602         visitor.append(&vPC[4].u.structure);
1603         visitor.append(&vPC[5].u.structure);
1604         visitor.append(&vPC[6].u.structureChain);
1605         return;
1606     }
1607     if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id) && vPC[4].u.structure) {
1608         visitor.append(&vPC[4].u.structure);
1609         return;
1610     }
1611     if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) {
1612         visitor.append(&vPC[4].u.structure);
1613         return;
1614     }
1615     if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global) || vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) {
1616         if (vPC[3].u.structure)
1617             visitor.append(&vPC[3].u.structure);
1618         return;
1619     }
1620
1621     // These instructions don't ref their Structures.
1622     ASSERT(vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_get_array_length) || vPC[0].u.opcode == interpreter->getOpcode(op_get_string_length));
1623 }
1624
1625 void EvalCodeCache::visitAggregate(SlotVisitor& visitor)
1626 {
1627     EvalCacheMap::iterator end = m_cacheMap.end();
1628     for (EvalCacheMap::iterator ptr = m_cacheMap.begin(); ptr != end; ++ptr)
1629         visitor.append(&ptr->second);
1630 }
1631
1632 void CodeBlock::visitAggregate(SlotVisitor& visitor)
1633 {
1634     if (!!m_alternative)
1635         m_alternative->visitAggregate(visitor);
1636
1637     // There are three things that may use unconditional finalizers: lazy bytecode freeing,
1638     // inline cache clearing, and jettisoning. The probability of us wanting to do at
1639     // least one of those things is probably quite close to 1. So we add one no matter what
1640     // and when it runs, it figures out whether it has any work to do.
1641     visitor.addUnconditionalFinalizer(this);
1642     
1643     if (shouldImmediatelyAssumeLivenessDuringScan()) {
1644         // This code block is live, so scan all references strongly and return.
1645         stronglyVisitStrongReferences(visitor);
1646         stronglyVisitWeakReferences(visitor);
1647         return;
1648     }
1649     
1650 #if ENABLE(DFG_JIT)
1651     // We get here if we're live in the sense that our owner executable is live,
1652     // but we're not yet live for sure in another sense: we may yet decide that this
1653     // code block should be jettisoned based on its outgoing weak references being
1654     // stale. Set a flag to indicate that we're still assuming that we're dead, and
1655     // perform one round of determining if we're live. The GC may determine, based on
1656     // either us marking additional objects, or by other objects being marked for
1657     // other reasons, that this iteration should run again; it will notify us of this
1658     // decision by calling harvestWeakReferences().
1659     
1660     m_dfgData->livenessHasBeenProved = false;
1661     m_dfgData->allTransitionsHaveBeenMarked = false;
1662     
1663     performTracingFixpointIteration(visitor);
1664
1665     // GC doesn't have enough information yet for us to decide whether to keep our DFG
1666     // data, so we need to register a handler to run again at the end of GC, when more
1667     // information is available.
1668     if (!(m_dfgData->livenessHasBeenProved && m_dfgData->allTransitionsHaveBeenMarked))
1669         visitor.addWeakReferenceHarvester(this);
1670     
1671 #else // ENABLE(DFG_JIT)
1672     ASSERT_NOT_REACHED();
1673 #endif // ENABLE(DFG_JIT)
1674 }
1675
1676 void CodeBlock::performTracingFixpointIteration(SlotVisitor& visitor)
1677 {
1678     UNUSED_PARAM(visitor);
1679     
1680 #if ENABLE(DFG_JIT)
1681     // Evaluate our weak reference transitions, if there are still some to evaluate.
1682     if (!m_dfgData->allTransitionsHaveBeenMarked) {
1683         bool allAreMarkedSoFar = true;
1684         for (unsigned i = 0; i < m_dfgData->transitions.size(); ++i) {
1685             if ((!m_dfgData->transitions[i].m_codeOrigin
1686                  || Heap::isMarked(m_dfgData->transitions[i].m_codeOrigin.get()))
1687                 && Heap::isMarked(m_dfgData->transitions[i].m_from.get())) {
1688                 // If the following three things are live, then the target of the
1689                 // transition is also live:
1690                 // - This code block. We know it's live already because otherwise
1691                 //   we wouldn't be scanning ourselves.
1692                 // - The code origin of the transition. Transitions may arise from
1693                 //   code that was inlined. They are not relevant if the user's
1694                 //   object that is required for the inlinee to run is no longer
1695                 //   live.
1696                 // - The source of the transition. The transition checks if some
1697                 //   heap location holds the source, and if so, stores the target.
1698                 //   Hence the source must be live for the transition to be live.
1699                 visitor.append(&m_dfgData->transitions[i].m_to);
1700             } else
1701                 allAreMarkedSoFar = false;
1702         }
1703         
1704         if (allAreMarkedSoFar)
1705             m_dfgData->allTransitionsHaveBeenMarked = true;
1706     }
1707     
1708     // Check if we have any remaining work to do.
1709     if (m_dfgData->livenessHasBeenProved)
1710         return;
1711     
1712     // Now check all of our weak references. If all of them are live, then we
1713     // have proved liveness and so we scan our strong references. If at end of
1714     // GC we still have not proved liveness, then this code block is toast.
1715     bool allAreLiveSoFar = true;
1716     for (unsigned i = 0; i < m_dfgData->weakReferences.size(); ++i) {
1717         if (!Heap::isMarked(m_dfgData->weakReferences[i].get())) {
1718             allAreLiveSoFar = false;
1719             break;
1720         }
1721     }
1722     
1723     // If some weak references are dead, then this fixpoint iteration was
1724     // unsuccessful.
1725     if (!allAreLiveSoFar)
1726         return;
1727     
1728     // All weak references are live. Record this information so we don't
1729     // come back here again, and scan the strong references.
1730     m_dfgData->livenessHasBeenProved = true;
1731     stronglyVisitStrongReferences(visitor);
1732 #endif // ENABLE(DFG_JIT)
1733 }
1734
1735 void CodeBlock::visitWeakReferences(SlotVisitor& visitor)
1736 {
1737     performTracingFixpointIteration(visitor);
1738 }
1739
1740 void CodeBlock::finalizeUnconditionally()
1741 {
1742 #if ENABLE(JIT)
1743 #if ENABLE(JIT_VERBOSE_OSR)
1744     static const bool verboseUnlinking = true;
1745 #else
1746     static const bool verboseUnlinking = false;
1747 #endif
1748 #endif // ENABLE(JIT)
1749     
1750 #if ENABLE(LLINT)
1751     Interpreter* interpreter = m_globalData->interpreter;
1752     // interpreter->classicEnabled() returns true if the old C++ interpreter is enabled. If that's enabled
1753     // then we're not using LLInt.
1754     if (!interpreter->classicEnabled()) {
1755         for (size_t size = m_propertyAccessInstructions.size(), i = 0; i < size; ++i) {
1756             Instruction* curInstruction = &instructions()[m_propertyAccessInstructions[i]];
1757             switch (interpreter->getOpcodeID(curInstruction[0].u.opcode)) {
1758             case op_get_by_id:
1759             case op_put_by_id:
1760                 if (!curInstruction[4].u.structure || Heap::isMarked(curInstruction[4].u.structure.get()))
1761                     break;
1762                 if (verboseUnlinking)
1763                     dataLog("Clearing LLInt property access with structure %p.\n", curInstruction[4].u.structure.get());
1764                 curInstruction[4].u.structure.clear();
1765                 curInstruction[5].u.operand = 0;
1766                 break;
1767             case op_put_by_id_transition_direct:
1768             case op_put_by_id_transition_normal:
1769                 if (Heap::isMarked(curInstruction[4].u.structure.get())
1770                     && Heap::isMarked(curInstruction[6].u.structure.get())
1771                     && Heap::isMarked(curInstruction[7].u.structureChain.get()))
1772                     break;
1773                 if (verboseUnlinking) {
1774                     dataLog("Clearing LLInt put transition with structures %p -> %p, chain %p.\n",
1775                             curInstruction[4].u.structure.get(),
1776                             curInstruction[6].u.structure.get(),
1777                             curInstruction[7].u.structureChain.get());
1778                 }
1779                 curInstruction[4].u.structure.clear();
1780                 curInstruction[6].u.structure.clear();
1781                 curInstruction[7].u.structureChain.clear();
1782                 curInstruction[0].u.opcode = interpreter->getOpcode(op_put_by_id);
1783                 break;
1784             default:
1785                 ASSERT_NOT_REACHED();
1786             }
1787         }
1788         for (size_t size = m_globalResolveInstructions.size(), i = 0; i < size; ++i) {
1789             Instruction* curInstruction = &instructions()[m_globalResolveInstructions[i]];
1790             ASSERT(interpreter->getOpcodeID(curInstruction[0].u.opcode) == op_resolve_global
1791                    || interpreter->getOpcodeID(curInstruction[0].u.opcode) == op_resolve_global_dynamic);
1792             if (!curInstruction[3].u.structure || Heap::isMarked(curInstruction[3].u.structure.get()))
1793                 continue;
1794             if (verboseUnlinking)
1795                 dataLog("Clearing LLInt global resolve cache with structure %p.\n", curInstruction[3].u.structure.get());
1796             curInstruction[3].u.structure.clear();
1797             curInstruction[4].u.operand = 0;
1798         }
1799         for (unsigned i = 0; i < m_llintCallLinkInfos.size(); ++i) {
1800             if (m_llintCallLinkInfos[i].isLinked() && !Heap::isMarked(m_llintCallLinkInfos[i].callee.get())) {
1801                 if (verboseUnlinking)
1802                     dataLog("Clearing LLInt call from %p.\n", this);
1803                 m_llintCallLinkInfos[i].unlink();
1804             }
1805             if (!!m_llintCallLinkInfos[i].lastSeenCallee && !Heap::isMarked(m_llintCallLinkInfos[i].lastSeenCallee.get()))
1806                 m_llintCallLinkInfos[i].lastSeenCallee.clear();
1807         }
1808     }
1809 #endif // ENABLE(LLINT)
1810
1811 #if ENABLE(DFG_JIT)
1812     // Check if we're not live. If we are, then jettison.
1813     if (!(shouldImmediatelyAssumeLivenessDuringScan() || m_dfgData->livenessHasBeenProved)) {
1814         if (verboseUnlinking)
1815             dataLog("Code block %p has dead weak references, jettisoning during GC.\n", this);
1816
1817         // Make sure that the baseline JIT knows that it should re-warm-up before
1818         // optimizing.
1819         alternative()->optimizeAfterWarmUp();
1820         
1821         jettison();
1822         return;
1823     }
1824 #endif // ENABLE(DFG_JIT)
1825     
1826 #if ENABLE(JIT)
1827     // Handle inline caches.
1828     if (!!getJITCode()) {
1829         RepatchBuffer repatchBuffer(this);
1830         for (unsigned i = 0; i < numberOfCallLinkInfos(); ++i) {
1831             if (callLinkInfo(i).isLinked() && !Heap::isMarked(callLinkInfo(i).callee.get())) {
1832                 if (verboseUnlinking)
1833                     dataLog("Clearing call from %p to %p.\n", this, callLinkInfo(i).callee.get());
1834                 callLinkInfo(i).unlink(*m_globalData, repatchBuffer);
1835             }
1836             if (!!callLinkInfo(i).lastSeenCallee
1837                 && !Heap::isMarked(callLinkInfo(i).lastSeenCallee.get()))
1838                 callLinkInfo(i).lastSeenCallee.clear();
1839         }
1840         for (size_t size = m_globalResolveInfos.size(), i = 0; i < size; ++i) {
1841             if (m_globalResolveInfos[i].structure && !Heap::isMarked(m_globalResolveInfos[i].structure.get())) {
1842                 if (verboseUnlinking)
1843                     dataLog("Clearing resolve info in %p.\n", this);
1844                 m_globalResolveInfos[i].structure.clear();
1845             }
1846         }
1847
1848         for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i) {
1849             StructureStubInfo& stubInfo = m_structureStubInfos[i];
1850             
1851             AccessType accessType = static_cast<AccessType>(stubInfo.accessType);
1852             
1853             if (stubInfo.visitWeakReferences())
1854                 continue;
1855             
1856             if (verboseUnlinking)
1857                 dataLog("Clearing structure cache (kind %d) in %p.\n", stubInfo.accessType, this);
1858             
1859             if (isGetByIdAccess(accessType)) {
1860                 if (getJITCode().jitType() == JITCode::DFGJIT)
1861                     DFG::dfgResetGetByID(repatchBuffer, stubInfo);
1862                 else
1863                     JIT::resetPatchGetById(repatchBuffer, &stubInfo);
1864             } else {
1865                 ASSERT(isPutByIdAccess(accessType));
1866                 if (getJITCode().jitType() == JITCode::DFGJIT)
1867                     DFG::dfgResetPutByID(repatchBuffer, stubInfo);
1868                 else 
1869                     JIT::resetPatchPutById(repatchBuffer, &stubInfo);
1870             }
1871             
1872             stubInfo.reset();
1873         }
1874
1875         for (size_t size = m_methodCallLinkInfos.size(), i = 0; i < size; ++i) {
1876             if (!m_methodCallLinkInfos[i].cachedStructure)
1877                 continue;
1878             
1879             ASSERT(m_methodCallLinkInfos[i].seenOnce());
1880             ASSERT(!!m_methodCallLinkInfos[i].cachedPrototypeStructure);
1881
1882             if (!Heap::isMarked(m_methodCallLinkInfos[i].cachedStructure.get())
1883                 || !Heap::isMarked(m_methodCallLinkInfos[i].cachedPrototypeStructure.get())
1884                 || !Heap::isMarked(m_methodCallLinkInfos[i].cachedFunction.get())
1885                 || !Heap::isMarked(m_methodCallLinkInfos[i].cachedPrototype.get())) {
1886                 if (verboseUnlinking)
1887                     dataLog("Clearing method call in %p.\n", this);
1888                 m_methodCallLinkInfos[i].reset(repatchBuffer, getJITType());
1889
1890                 StructureStubInfo& stubInfo = getStubInfo(m_methodCallLinkInfos[i].bytecodeIndex);
1891
1892                 AccessType accessType = static_cast<AccessType>(stubInfo.accessType);
1893
1894                 if (accessType != access_unset) {
1895                     ASSERT(isGetByIdAccess(accessType));
1896                     if (getJITCode().jitType() == JITCode::DFGJIT)
1897                         DFG::dfgResetGetByID(repatchBuffer, stubInfo);
1898                     else
1899                         JIT::resetPatchGetById(repatchBuffer, &stubInfo);
1900                     stubInfo.reset();
1901                 }
1902             }
1903         }
1904     }
1905 #endif
1906
1907     // Handle the bytecode discarding chore.
1908     if (m_shouldDiscardBytecode) {
1909         discardBytecode();
1910         m_shouldDiscardBytecode = false;
1911     }
1912 }
1913
1914 void CodeBlock::stronglyVisitStrongReferences(SlotVisitor& visitor)
1915 {
1916     visitor.append(&m_globalObject);
1917     visitor.append(&m_ownerExecutable);
1918     if (m_rareData) {
1919         m_rareData->m_evalCodeCache.visitAggregate(visitor);
1920         size_t regExpCount = m_rareData->m_regexps.size();
1921         WriteBarrier<RegExp>* regexps = m_rareData->m_regexps.data();
1922         for (size_t i = 0; i < regExpCount; i++)
1923             visitor.append(regexps + i);
1924     }
1925     visitor.appendValues(m_constantRegisters.data(), m_constantRegisters.size());
1926     for (size_t i = 0; i < m_functionExprs.size(); ++i)
1927         visitor.append(&m_functionExprs[i]);
1928     for (size_t i = 0; i < m_functionDecls.size(); ++i)
1929         visitor.append(&m_functionDecls[i]);
1930 #if ENABLE(CLASSIC_INTERPRETER)
1931     if (m_globalData->interpreter->classicEnabled()) {
1932         for (size_t size = m_propertyAccessInstructions.size(), i = 0; i < size; ++i)
1933             visitStructures(visitor, &instructions()[m_propertyAccessInstructions[i]]);
1934         for (size_t size = m_globalResolveInstructions.size(), i = 0; i < size; ++i)
1935             visitStructures(visitor, &instructions()[m_globalResolveInstructions[i]]);
1936     }
1937 #endif
1938
1939 #if ENABLE(DFG_JIT)
1940     if (hasCodeOrigins()) {
1941         // Make sure that executables that we have inlined don't die.
1942         // FIXME: If they would have otherwise died, we should probably trigger recompilation.
1943         for (size_t i = 0; i < inlineCallFrames().size(); ++i) {
1944             InlineCallFrame& inlineCallFrame = inlineCallFrames()[i];
1945             visitor.append(&inlineCallFrame.executable);
1946             visitor.append(&inlineCallFrame.callee);
1947         }
1948     }
1949 #endif
1950
1951 #if ENABLE(VALUE_PROFILER)
1952     for (unsigned profileIndex = 0; profileIndex < numberOfArgumentValueProfiles(); ++profileIndex)
1953         valueProfileForArgument(profileIndex)->computeUpdatedPrediction();
1954     for (unsigned profileIndex = 0; profileIndex < numberOfValueProfiles(); ++profileIndex)
1955         valueProfile(profileIndex)->computeUpdatedPrediction();
1956 #endif
1957 }
1958
1959 void CodeBlock::stronglyVisitWeakReferences(SlotVisitor& visitor)
1960 {
1961     UNUSED_PARAM(visitor);
1962
1963 #if ENABLE(DFG_JIT)
1964     if (!m_dfgData)
1965         return;
1966
1967     for (unsigned i = 0; i < m_dfgData->transitions.size(); ++i) {
1968         if (!!m_dfgData->transitions[i].m_codeOrigin)
1969             visitor.append(&m_dfgData->transitions[i].m_codeOrigin); // Almost certainly not necessary, since the code origin should also be a weak reference. Better to be safe, though.
1970         visitor.append(&m_dfgData->transitions[i].m_from);
1971         visitor.append(&m_dfgData->transitions[i].m_to);
1972     }
1973     
1974     for (unsigned i = 0; i < m_dfgData->weakReferences.size(); ++i)
1975         visitor.append(&m_dfgData->weakReferences[i]);
1976 #endif    
1977 }
1978
1979 HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset)
1980 {
1981     ASSERT(bytecodeOffset < m_instructionCount);
1982
1983     if (!m_rareData)
1984         return 0;
1985     
1986     Vector<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers;
1987     for (size_t i = 0; i < exceptionHandlers.size(); ++i) {
1988         // Handlers are ordered innermost first, so the first handler we encounter
1989         // that contains the source address is the correct handler to use.
1990         if (exceptionHandlers[i].start <= bytecodeOffset && exceptionHandlers[i].end >= bytecodeOffset)
1991             return &exceptionHandlers[i];
1992     }
1993
1994     return 0;
1995 }
1996
1997 int CodeBlock::lineNumberForBytecodeOffset(unsigned bytecodeOffset)
1998 {
1999     ASSERT(bytecodeOffset < m_instructionCount);
2000
2001     if (!m_rareData)
2002         return m_ownerExecutable->source().firstLine();
2003
2004     Vector<LineInfo>& lineInfo = m_rareData->m_lineInfo;
2005
2006     int low = 0;
2007     int high = lineInfo.size();
2008     while (low < high) {
2009         int mid = low + (high - low) / 2;
2010         if (lineInfo[mid].instructionOffset <= bytecodeOffset)
2011             low = mid + 1;
2012         else
2013             high = mid;
2014     }
2015
2016     if (!low)
2017         return m_ownerExecutable->source().firstLine();
2018     return lineInfo[low - 1].lineNumber;
2019 }
2020
2021 void CodeBlock::expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset)
2022 {
2023     ASSERT(bytecodeOffset < m_instructionCount);
2024
2025     if (!m_rareData) {
2026         startOffset = 0;
2027         endOffset = 0;
2028         divot = 0;
2029         return;
2030     }
2031
2032     Vector<ExpressionRangeInfo>& expressionInfo = m_rareData->m_expressionInfo;
2033
2034     int low = 0;
2035     int high = expressionInfo.size();
2036     while (low < high) {
2037         int mid = low + (high - low) / 2;
2038         if (expressionInfo[mid].instructionOffset <= bytecodeOffset)
2039             low = mid + 1;
2040         else
2041             high = mid;
2042     }
2043
2044     ASSERT(low);
2045     if (!low) {
2046         startOffset = 0;
2047         endOffset = 0;
2048         divot = 0;
2049         return;
2050     }
2051
2052     startOffset = expressionInfo[low - 1].startOffset;
2053     endOffset = expressionInfo[low - 1].endOffset;
2054     divot = expressionInfo[low - 1].divotPoint + m_sourceOffset;
2055     return;
2056 }
2057
2058 #if ENABLE(CLASSIC_INTERPRETER)
2059 bool CodeBlock::hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset)
2060 {
2061     if (m_globalResolveInstructions.isEmpty())
2062         return false;
2063
2064     int low = 0;
2065     int high = m_globalResolveInstructions.size();
2066     while (low < high) {
2067         int mid = low + (high - low) / 2;
2068         if (m_globalResolveInstructions[mid] <= bytecodeOffset)
2069             low = mid + 1;
2070         else
2071             high = mid;
2072     }
2073
2074     if (!low || m_globalResolveInstructions[low - 1] != bytecodeOffset)
2075         return false;
2076     return true;
2077 }
2078 #endif
2079 #if ENABLE(JIT)
2080 bool CodeBlock::hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset)
2081 {
2082     if (m_globalResolveInfos.isEmpty())
2083         return false;
2084
2085     int low = 0;
2086     int high = m_globalResolveInfos.size();
2087     while (low < high) {
2088         int mid = low + (high - low) / 2;
2089         if (m_globalResolveInfos[mid].bytecodeOffset <= bytecodeOffset)
2090             low = mid + 1;
2091         else
2092             high = mid;
2093     }
2094
2095     if (!low || m_globalResolveInfos[low - 1].bytecodeOffset != bytecodeOffset)
2096         return false;
2097     return true;
2098 }
2099 #endif
2100
2101 void CodeBlock::shrinkToFit()
2102 {
2103     instructions().shrinkToFit();
2104
2105 #if ENABLE(CLASSIC_INTERPRETER)
2106     m_propertyAccessInstructions.shrinkToFit();
2107     m_globalResolveInstructions.shrinkToFit();
2108 #endif
2109 #if ENABLE(JIT)
2110     m_structureStubInfos.shrinkToFit();
2111     m_globalResolveInfos.shrinkToFit();
2112     m_callLinkInfos.shrinkToFit();
2113 #endif
2114
2115     m_identifiers.shrinkToFit();
2116     m_functionDecls.shrinkToFit();
2117     m_functionExprs.shrinkToFit();
2118     m_constantRegisters.shrinkToFit();
2119
2120     if (m_rareData) {
2121         m_rareData->m_exceptionHandlers.shrinkToFit();
2122         m_rareData->m_regexps.shrinkToFit();
2123         m_rareData->m_immediateSwitchJumpTables.shrinkToFit();
2124         m_rareData->m_characterSwitchJumpTables.shrinkToFit();
2125         m_rareData->m_stringSwitchJumpTables.shrinkToFit();
2126         m_rareData->m_expressionInfo.shrinkToFit();
2127         m_rareData->m_lineInfo.shrinkToFit();
2128     }
2129 }
2130
2131 void CodeBlock::createActivation(CallFrame* callFrame)
2132 {
2133     ASSERT(codeType() == FunctionCode);
2134     ASSERT(needsFullScopeChain());
2135     ASSERT(!callFrame->uncheckedR(activationRegister()).jsValue());
2136     JSActivation* activation = JSActivation::create(callFrame->globalData(), callFrame, static_cast<FunctionExecutable*>(ownerExecutable()));
2137     callFrame->uncheckedR(activationRegister()) = JSValue(activation);
2138     callFrame->setScopeChain(callFrame->scopeChain()->push(activation));
2139 }
2140
2141 unsigned CodeBlock::addOrFindConstant(JSValue v)
2142 {
2143     unsigned numberOfConstants = numberOfConstantRegisters();
2144     for (unsigned i = 0; i < numberOfConstants; ++i) {
2145         if (getConstant(FirstConstantRegisterIndex + i) == v)
2146             return i;
2147     }
2148     return addConstant(v);
2149 }
2150
2151 #if ENABLE(JIT)
2152 void CodeBlock::unlinkCalls()
2153 {
2154     if (!!m_alternative)
2155         m_alternative->unlinkCalls();
2156 #if ENABLE(LLINT)
2157     for (size_t i = 0; i < m_llintCallLinkInfos.size(); ++i) {
2158         if (m_llintCallLinkInfos[i].isLinked())
2159             m_llintCallLinkInfos[i].unlink();
2160     }
2161 #endif
2162     if (!(m_callLinkInfos.size() || m_methodCallLinkInfos.size()))
2163         return;
2164     if (!m_globalData->canUseJIT())
2165         return;
2166     RepatchBuffer repatchBuffer(this);
2167     for (size_t i = 0; i < m_callLinkInfos.size(); i++) {
2168         if (!m_callLinkInfos[i].isLinked())
2169             continue;
2170         m_callLinkInfos[i].unlink(*m_globalData, repatchBuffer);
2171     }
2172 }
2173
2174 void CodeBlock::unlinkIncomingCalls()
2175 {
2176 #if ENABLE(LLINT)
2177     while (m_incomingLLIntCalls.begin() != m_incomingLLIntCalls.end())
2178         m_incomingLLIntCalls.begin()->unlink();
2179 #endif
2180     if (m_incomingCalls.isEmpty())
2181         return;
2182     RepatchBuffer repatchBuffer(this);
2183     while (m_incomingCalls.begin() != m_incomingCalls.end())
2184         m_incomingCalls.begin()->unlink(*m_globalData, repatchBuffer);
2185 }
2186
2187 unsigned CodeBlock::bytecodeOffset(ExecState* exec, ReturnAddressPtr returnAddress)
2188 {
2189 #if ENABLE(LLINT)
2190     if (returnAddress.value() >= bitwise_cast<void*>(&llint_begin)
2191         && returnAddress.value() <= bitwise_cast<void*>(&llint_end)) {
2192         ASSERT(exec->codeBlock());
2193         ASSERT(exec->codeBlock() == this);
2194         ASSERT(JITCode::isBaselineCode(getJITType()));
2195         Instruction* instruction = exec->currentVPC();
2196         ASSERT(instruction);
2197         
2198         // The LLInt stores the PC after the call instruction rather than the PC of
2199         // the call instruction. This requires some correcting. We rely on the fact
2200         // that the preceding instruction must be one of the call instructions, so
2201         // either it's a call_varargs or it's a call, construct, or eval.
2202         ASSERT(OPCODE_LENGTH(op_call_varargs) <= OPCODE_LENGTH(op_call));
2203         ASSERT(OPCODE_LENGTH(op_call) == OPCODE_LENGTH(op_construct));
2204         ASSERT(OPCODE_LENGTH(op_call) == OPCODE_LENGTH(op_call_eval));
2205         if (instruction[-OPCODE_LENGTH(op_call_varargs)].u.pointer == bitwise_cast<void*>(llint_op_call_varargs)) {
2206             // We know that the preceding instruction must be op_call_varargs because there is no way that
2207             // the pointer to the call_varargs could be an operand to the call.
2208             instruction -= OPCODE_LENGTH(op_call_varargs);
2209             ASSERT(instruction[-OPCODE_LENGTH(op_call)].u.pointer != bitwise_cast<void*>(llint_op_call)
2210                    && instruction[-OPCODE_LENGTH(op_call)].u.pointer != bitwise_cast<void*>(llint_op_construct)
2211                    && instruction[-OPCODE_LENGTH(op_call)].u.pointer != bitwise_cast<void*>(llint_op_call_eval));
2212         } else {
2213             // Must be that the last instruction was some op_call.
2214             ASSERT(instruction[-OPCODE_LENGTH(op_call)].u.pointer == bitwise_cast<void*>(llint_op_call)
2215                    || instruction[-OPCODE_LENGTH(op_call)].u.pointer == bitwise_cast<void*>(llint_op_construct)
2216                    || instruction[-OPCODE_LENGTH(op_call)].u.pointer == bitwise_cast<void*>(llint_op_call_eval));
2217             instruction -= OPCODE_LENGTH(op_call);
2218         }
2219         
2220         return bytecodeOffset(instruction);
2221     }
2222 #else
2223     UNUSED_PARAM(exec);
2224 #endif
2225     if (!m_rareData)
2226         return 1;
2227     Vector<CallReturnOffsetToBytecodeOffset>& callIndices = m_rareData->m_callReturnIndexVector;
2228     if (!callIndices.size())
2229         return 1;
2230     return binarySearch<CallReturnOffsetToBytecodeOffset, unsigned, getCallReturnOffset>(callIndices.begin(), callIndices.size(), getJITCode().offsetOf(returnAddress.value()))->bytecodeOffset;
2231 }
2232 #endif
2233
2234 void CodeBlock::clearEvalCache()
2235 {
2236     if (!!m_alternative)
2237         m_alternative->clearEvalCache();
2238     if (!m_rareData)
2239         return;
2240     m_rareData->m_evalCodeCache.clear();
2241 }
2242
2243 template<typename T>
2244 inline void replaceExistingEntries(Vector<T>& target, Vector<T>& source)
2245 {
2246     ASSERT(target.size() <= source.size());
2247     for (size_t i = 0; i < target.size(); ++i)
2248         target[i] = source[i];
2249 }
2250
2251 void CodeBlock::copyPostParseDataFrom(CodeBlock* alternative)
2252 {
2253     if (!alternative)
2254         return;
2255     
2256     replaceExistingEntries(m_constantRegisters, alternative->m_constantRegisters);
2257     replaceExistingEntries(m_functionDecls, alternative->m_functionDecls);
2258     replaceExistingEntries(m_functionExprs, alternative->m_functionExprs);
2259     if (!!m_rareData && !!alternative->m_rareData)
2260         replaceExistingEntries(m_rareData->m_constantBuffers, alternative->m_rareData->m_constantBuffers);
2261 }
2262
2263 void CodeBlock::copyPostParseDataFromAlternative()
2264 {
2265     copyPostParseDataFrom(m_alternative.get());
2266 }
2267
2268 #if ENABLE(JIT)
2269 CodeBlock* ProgramCodeBlock::replacement()
2270 {
2271     return &static_cast<ProgramExecutable*>(ownerExecutable())->generatedBytecode();
2272 }
2273
2274 CodeBlock* EvalCodeBlock::replacement()
2275 {
2276     return &static_cast<EvalExecutable*>(ownerExecutable())->generatedBytecode();
2277 }
2278
2279 CodeBlock* FunctionCodeBlock::replacement()
2280 {
2281     return &static_cast<FunctionExecutable*>(ownerExecutable())->generatedBytecodeFor(m_isConstructor ? CodeForConstruct : CodeForCall);
2282 }
2283
2284 JSObject* ProgramCodeBlock::compileOptimized(ExecState* exec, ScopeChainNode* scopeChainNode)
2285 {
2286     if (replacement()->getJITType() == JITCode::nextTierJIT(getJITType()))
2287         return 0;
2288     JSObject* error = static_cast<ProgramExecutable*>(ownerExecutable())->compileOptimized(exec, scopeChainNode);
2289     return error;
2290 }
2291
2292 JSObject* EvalCodeBlock::compileOptimized(ExecState* exec, ScopeChainNode* scopeChainNode)
2293 {
2294     if (replacement()->getJITType() == JITCode::nextTierJIT(getJITType()))
2295         return 0;
2296     JSObject* error = static_cast<EvalExecutable*>(ownerExecutable())->compileOptimized(exec, scopeChainNode);
2297     return error;
2298 }
2299
2300 JSObject* FunctionCodeBlock::compileOptimized(ExecState* exec, ScopeChainNode* scopeChainNode)
2301 {
2302     if (replacement()->getJITType() == JITCode::nextTierJIT(getJITType()))
2303         return 0;
2304     JSObject* error = static_cast<FunctionExecutable*>(ownerExecutable())->compileOptimizedFor(exec, scopeChainNode, m_isConstructor ? CodeForConstruct : CodeForCall);
2305     return error;
2306 }
2307
2308 bool ProgramCodeBlock::canCompileWithDFGInternal()
2309 {
2310     return DFG::canCompileProgram(this);
2311 }
2312
2313 bool EvalCodeBlock::canCompileWithDFGInternal()
2314 {
2315     return DFG::canCompileEval(this);
2316 }
2317
2318 bool FunctionCodeBlock::canCompileWithDFGInternal()
2319 {
2320     if (m_isConstructor)
2321         return DFG::canCompileFunctionForConstruct(this);
2322     return DFG::canCompileFunctionForCall(this);
2323 }
2324
2325 void ProgramCodeBlock::jettison()
2326 {
2327     ASSERT(JITCode::isOptimizingJIT(getJITType()));
2328     ASSERT(this == replacement());
2329     static_cast<ProgramExecutable*>(ownerExecutable())->jettisonOptimizedCode(*globalData());
2330 }
2331
2332 void EvalCodeBlock::jettison()
2333 {
2334     ASSERT(JITCode::isOptimizingJIT(getJITType()));
2335     ASSERT(this == replacement());
2336     static_cast<EvalExecutable*>(ownerExecutable())->jettisonOptimizedCode(*globalData());
2337 }
2338
2339 void FunctionCodeBlock::jettison()
2340 {
2341     ASSERT(JITCode::isOptimizingJIT(getJITType()));
2342     ASSERT(this == replacement());
2343     static_cast<FunctionExecutable*>(ownerExecutable())->jettisonOptimizedCodeFor(*globalData(), m_isConstructor ? CodeForConstruct : CodeForCall);
2344 }
2345
2346 void ProgramCodeBlock::jitCompileImpl(JSGlobalData& globalData)
2347 {
2348     ASSERT(getJITType() == JITCode::InterpreterThunk);
2349     ASSERT(this == replacement());
2350     return static_cast<ProgramExecutable*>(ownerExecutable())->jitCompile(globalData);
2351 }
2352
2353 void EvalCodeBlock::jitCompileImpl(JSGlobalData& globalData)
2354 {
2355     ASSERT(getJITType() == JITCode::InterpreterThunk);
2356     ASSERT(this == replacement());
2357     return static_cast<EvalExecutable*>(ownerExecutable())->jitCompile(globalData);
2358 }
2359
2360 void FunctionCodeBlock::jitCompileImpl(JSGlobalData& globalData)
2361 {
2362     ASSERT(getJITType() == JITCode::InterpreterThunk);
2363     ASSERT(this == replacement());
2364     return static_cast<FunctionExecutable*>(ownerExecutable())->jitCompileFor(globalData, m_isConstructor ? CodeForConstruct : CodeForCall);
2365 }
2366 #endif
2367
2368 #if ENABLE(VALUE_PROFILER)
2369 bool CodeBlock::shouldOptimizeNow()
2370 {
2371 #if ENABLE(JIT_VERBOSE_OSR)
2372     dataLog("Considering optimizing %p...\n", this);
2373 #endif
2374
2375 #if ENABLE(VERBOSE_VALUE_PROFILE)
2376     dumpValueProfiles();
2377 #endif
2378
2379     if (m_optimizationDelayCounter >= Options::maximumOptimizationDelay)
2380         return true;
2381     
2382     unsigned numberOfLiveNonArgumentValueProfiles = 0;
2383     unsigned numberOfSamplesInProfiles = 0; // If this divided by ValueProfile::numberOfBuckets equals numberOfValueProfiles() then value profiles are full.
2384     for (unsigned i = 0; i < totalNumberOfValueProfiles(); ++i) {
2385         ValueProfile* profile = getFromAllValueProfiles(i);
2386         unsigned numSamples = profile->totalNumberOfSamples();
2387         if (numSamples > ValueProfile::numberOfBuckets)
2388             numSamples = ValueProfile::numberOfBuckets; // We don't want profiles that are extremely hot to be given more weight.
2389         numberOfSamplesInProfiles += numSamples;
2390         if (profile->m_bytecodeOffset < 0) {
2391             profile->computeUpdatedPrediction();
2392             continue;
2393         }
2394         if (profile->numberOfSamples() || profile->m_prediction != PredictNone)
2395             numberOfLiveNonArgumentValueProfiles++;
2396         profile->computeUpdatedPrediction();
2397     }
2398
2399 #if ENABLE(JIT_VERBOSE_OSR)
2400     dataLog("Profile hotness: %lf, %lf\n", (double)numberOfLiveNonArgumentValueProfiles / numberOfValueProfiles(), (double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / numberOfValueProfiles());
2401 #endif
2402
2403     if ((!numberOfValueProfiles() || (double)numberOfLiveNonArgumentValueProfiles / numberOfValueProfiles() >= Options::desiredProfileLivenessRate)
2404         && (!totalNumberOfValueProfiles() || (double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / totalNumberOfValueProfiles() >= Options::desiredProfileFullnessRate)
2405         && static_cast<unsigned>(m_optimizationDelayCounter) + 1 >= Options::minimumOptimizationDelay)
2406         return true;
2407     
2408     ASSERT(m_optimizationDelayCounter < std::numeric_limits<uint8_t>::max());
2409     m_optimizationDelayCounter++;
2410     optimizeAfterWarmUp();
2411     return false;
2412 }
2413 #endif
2414
2415 #if ENABLE(DFG_JIT)
2416 void CodeBlock::tallyFrequentExitSites()
2417 {
2418     ASSERT(getJITType() == JITCode::DFGJIT);
2419     ASSERT(alternative()->getJITType() == JITCode::BaselineJIT);
2420     ASSERT(!!m_dfgData);
2421     
2422     CodeBlock* profiledBlock = alternative();
2423     
2424     for (unsigned i = 0; i < m_dfgData->osrExit.size(); ++i) {
2425         DFG::OSRExit& exit = m_dfgData->osrExit[i];
2426         
2427         if (!exit.considerAddingAsFrequentExitSite(this, profiledBlock))
2428             continue;
2429         
2430 #if DFG_ENABLE(DEBUG_VERBOSE)
2431         dataLog("OSR exit #%u (bc#%u, @%u, %s) for code block %p occurred frequently; counting as frequent exit site.\n", i, exit.m_codeOrigin.bytecodeIndex, exit.m_nodeIndex, DFG::exitKindToString(exit.m_kind), this);
2432 #endif
2433     }
2434 }
2435 #endif // ENABLE(DFG_JIT)
2436
2437 #if ENABLE(VERBOSE_VALUE_PROFILE)
2438 void CodeBlock::dumpValueProfiles()
2439 {
2440     dataLog("ValueProfile for %p:\n", this);
2441     for (unsigned i = 0; i < totalNumberOfValueProfiles(); ++i) {
2442         ValueProfile* profile = getFromAllValueProfiles(i);
2443         if (profile->m_bytecodeOffset < 0) {
2444             ASSERT(profile->m_bytecodeOffset == -1);
2445             dataLog("   arg = %u: ", i);
2446         } else
2447             dataLog("   bc = %d: ", profile->m_bytecodeOffset);
2448         if (!profile->numberOfSamples() && profile->m_prediction == PredictNone) {
2449             dataLog("<empty>\n");
2450             continue;
2451         }
2452         profile->dump(WTF::dataFile());
2453         dataLog("\n");
2454     }
2455     dataLog("RareCaseProfile for %p:\n", this);
2456     for (unsigned i = 0; i < numberOfRareCaseProfiles(); ++i) {
2457         RareCaseProfile* profile = rareCaseProfile(i);
2458         dataLog("   bc = %d: %u\n", profile->m_bytecodeOffset, profile->m_counter);
2459     }
2460     dataLog("SpecialFastCaseProfile for %p:\n", this);
2461     for (unsigned i = 0; i < numberOfSpecialFastCaseProfiles(); ++i) {
2462         RareCaseProfile* profile = specialFastCaseProfile(i);
2463         dataLog("   bc = %d: %u\n", profile->m_bytecodeOffset, profile->m_counter);
2464     }
2465 }
2466 #endif
2467
2468 #ifndef NDEBUG
2469 bool CodeBlock::usesOpcode(OpcodeID opcodeID)
2470 {
2471     Interpreter* interpreter = globalData()->interpreter;
2472     Instruction* instructionsBegin = instructions().begin();
2473     unsigned instructionCount = instructions().size();
2474     
2475     for (unsigned bytecodeOffset = 0; bytecodeOffset < instructionCount; ) {
2476         switch (interpreter->getOpcodeID(instructionsBegin[bytecodeOffset].u.opcode)) {
2477 #define DEFINE_OP(curOpcode, length)        \
2478         case curOpcode:                     \
2479             if (curOpcode == opcodeID)      \
2480                 return true;                \
2481             bytecodeOffset += length;       \
2482             break;
2483             FOR_EACH_OPCODE_ID(DEFINE_OP)
2484 #undef DEFINE_OP
2485         default:
2486             ASSERT_NOT_REACHED();
2487             break;
2488         }
2489     }
2490     
2491     return false;
2492 }
2493 #endif
2494
2495 } // namespace JSC