]> git.saurik.com Git - apple/javascriptcore.git/blame - bytecode/CodeBlock.cpp
JavaScriptCore-621.1.tar.gz
[apple/javascriptcore.git] / bytecode / CodeBlock.cpp
CommitLineData
9dae56ea
A
1/*
2 * Copyright (C) 2008, 2009 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 "JIT.h"
34#include "JSValue.h"
35#include "Interpreter.h"
f9bf01c6
A
36#include "JSFunction.h"
37#include "JSStaticScopeObject.h"
9dae56ea
A
38#include "Debugger.h"
39#include "BytecodeGenerator.h"
40#include <stdio.h>
41#include <wtf/StringExtras.h>
42
43#define DUMP_CODE_BLOCK_STATISTICS 0
44
45namespace JSC {
46
47#if !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING)
48
49static UString escapeQuotes(const UString& str)
50{
51 UString result = str;
4e4e5a6f
A
52 unsigned pos = 0;
53 while ((pos = result.find('\"', pos)) != UString::NotFound) {
f9bf01c6 54 result = makeString(result.substr(0, pos), "\"\\\"\"", result.substr(pos + 1));
9dae56ea
A
55 pos += 4;
56 }
57 return result;
58}
59
ba379fdc 60static UString valueToSourceString(ExecState* exec, JSValue val)
9dae56ea 61{
ba379fdc
A
62 if (!val)
63 return "0";
64
f9bf01c6
A
65 if (val.isString())
66 return makeString("\"", escapeQuotes(val.toString(exec)), "\"");
9dae56ea
A
67
68 return val.toString(exec);
69}
70
f9bf01c6 71static CString constantName(ExecState* exec, int k, JSValue value)
9dae56ea 72{
f9bf01c6 73 return makeString(valueToSourceString(exec, value), "(@k", UString::from(k - FirstConstantRegisterIndex), ")").UTF8String();
9dae56ea
A
74}
75
f9bf01c6 76static CString idName(int id0, const Identifier& ident)
9dae56ea 77{
f9bf01c6 78 return makeString(ident.ustring(), "(@id", UString::from(id0), ")").UTF8String();
9dae56ea
A
79}
80
f9bf01c6 81CString CodeBlock::registerName(ExecState* exec, int r) const
9dae56ea 82{
f9bf01c6
A
83 if (r == missingThisObjectMarker())
84 return "<null>";
85
86 if (isConstantRegisterIndex(r))
87 return constantName(exec, r, getConstant(r));
88
89 return makeString("r", UString::from(r)).UTF8String();
9dae56ea
A
90}
91
92static UString regexpToSourceString(RegExp* regExp)
93{
f9bf01c6
A
94 char postfix[5] = { '/', 0, 0, 0, 0 };
95 int index = 1;
9dae56ea 96 if (regExp->global())
f9bf01c6 97 postfix[index++] = 'g';
9dae56ea 98 if (regExp->ignoreCase())
f9bf01c6 99 postfix[index++] = 'i';
9dae56ea 100 if (regExp->multiline())
f9bf01c6 101 postfix[index] = 'm';
9dae56ea 102
f9bf01c6 103 return makeString("/", regExp->pattern(), postfix);
9dae56ea
A
104}
105
106static CString regexpName(int re, RegExp* regexp)
107{
f9bf01c6 108 return makeString(regexpToSourceString(regexp), "(@re", UString::from(re), ")").UTF8String();
9dae56ea
A
109}
110
111static UString pointerToSourceString(void* p)
112{
113 char buffer[2 + 2 * sizeof(void*) + 1]; // 0x [two characters per byte] \0
114 snprintf(buffer, sizeof(buffer), "%p", p);
115 return buffer;
116}
117
118NEVER_INLINE static const char* debugHookName(int debugHookID)
119{
120 switch (static_cast<DebugHookID>(debugHookID)) {
121 case DidEnterCallFrame:
122 return "didEnterCallFrame";
123 case WillLeaveCallFrame:
124 return "willLeaveCallFrame";
125 case WillExecuteStatement:
126 return "willExecuteStatement";
127 case WillExecuteProgram:
128 return "willExecuteProgram";
129 case DidExecuteProgram:
130 return "didExecuteProgram";
131 case DidReachBreakpoint:
132 return "didReachBreakpoint";
133 }
134
135 ASSERT_NOT_REACHED();
136 return "";
137}
138
f9bf01c6 139void CodeBlock::printUnaryOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
9dae56ea
A
140{
141 int r0 = (++it)->u.operand;
142 int r1 = (++it)->u.operand;
143
4e4e5a6f 144 printf("[%4d] %s\t\t %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data());
9dae56ea
A
145}
146
f9bf01c6 147void CodeBlock::printBinaryOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
9dae56ea
A
148{
149 int r0 = (++it)->u.operand;
150 int r1 = (++it)->u.operand;
151 int r2 = (++it)->u.operand;
4e4e5a6f 152 printf("[%4d] %s\t\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
9dae56ea
A
153}
154
f9bf01c6 155void CodeBlock::printConditionalJump(ExecState* exec, const Vector<Instruction>::const_iterator&, Vector<Instruction>::const_iterator& it, int location, const char* op) const
9dae56ea
A
156{
157 int r0 = (++it)->u.operand;
158 int offset = (++it)->u.operand;
4e4e5a6f 159 printf("[%4d] %s\t\t %s, %d(->%d)\n", location, op, registerName(exec, r0).data(), offset, location + offset);
9dae56ea
A
160}
161
f9bf01c6 162void CodeBlock::printGetByIdOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
9dae56ea
A
163{
164 int r0 = (++it)->u.operand;
165 int r1 = (++it)->u.operand;
166 int id0 = (++it)->u.operand;
4e4e5a6f 167 printf("[%4d] %s\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
9dae56ea
A
168 it += 4;
169}
170
f9bf01c6 171void CodeBlock::printPutByIdOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const
9dae56ea
A
172{
173 int r0 = (++it)->u.operand;
174 int id0 = (++it)->u.operand;
175 int r1 = (++it)->u.operand;
4e4e5a6f 176 printf("[%4d] %s\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data());
9dae56ea
A
177 it += 4;
178}
179
180#if ENABLE(JIT)
181static bool isGlobalResolve(OpcodeID opcodeID)
182{
4e4e5a6f 183 return opcodeID == op_resolve_global || opcodeID == op_resolve_global_dynamic;
9dae56ea
A
184}
185
186static bool isPropertyAccess(OpcodeID opcodeID)
187{
188 switch (opcodeID) {
189 case op_get_by_id_self:
190 case op_get_by_id_proto:
191 case op_get_by_id_chain:
192 case op_get_by_id_self_list:
193 case op_get_by_id_proto_list:
194 case op_put_by_id_transition:
195 case op_put_by_id_replace:
196 case op_get_by_id:
197 case op_put_by_id:
198 case op_get_by_id_generic:
199 case op_put_by_id_generic:
200 case op_get_array_length:
201 case op_get_string_length:
202 return true;
203 default:
204 return false;
205 }
206}
207
208static unsigned instructionOffsetForNth(ExecState* exec, const Vector<Instruction>& instructions, int nth, bool (*predicate)(OpcodeID))
209{
210 size_t i = 0;
211 while (i < instructions.size()) {
212 OpcodeID currentOpcode = exec->interpreter()->getOpcodeID(instructions[i].u.opcode);
213 if (predicate(currentOpcode)) {
214 if (!--nth)
215 return i;
216 }
217 i += opcodeLengths[currentOpcode];
218 }
219
220 ASSERT_NOT_REACHED();
221 return 0;
222}
223
224static void printGlobalResolveInfo(const GlobalResolveInfo& resolveInfo, unsigned instructionOffset)
225{
4e4e5a6f 226 printf(" [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure).UTF8String().data());
9dae56ea
A
227}
228
229static void printStructureStubInfo(const StructureStubInfo& stubInfo, unsigned instructionOffset)
230{
f9bf01c6
A
231 switch (stubInfo.accessType) {
232 case access_get_by_id_self:
4e4e5a6f 233 printf(" [%4d] %s: %s\n", instructionOffset, "get_by_id_self", pointerToSourceString(stubInfo.u.getByIdSelf.baseObjectStructure).UTF8String().data());
9dae56ea 234 return;
f9bf01c6 235 case access_get_by_id_proto:
4e4e5a6f 236 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(stubInfo.u.getByIdProto.baseObjectStructure).UTF8String().data(), pointerToSourceString(stubInfo.u.getByIdProto.prototypeStructure).UTF8String().data());
9dae56ea 237 return;
f9bf01c6 238 case access_get_by_id_chain:
4e4e5a6f 239 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(stubInfo.u.getByIdChain.baseObjectStructure).UTF8String().data(), pointerToSourceString(stubInfo.u.getByIdChain.chain).UTF8String().data());
9dae56ea 240 return;
f9bf01c6 241 case access_get_by_id_self_list:
4e4e5a6f 242 printf(" [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_self_list", pointerToSourceString(stubInfo.u.getByIdSelfList.structureList).UTF8String().data(), stubInfo.u.getByIdSelfList.listSize);
9dae56ea 243 return;
f9bf01c6 244 case access_get_by_id_proto_list:
4e4e5a6f 245 printf(" [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_proto_list", pointerToSourceString(stubInfo.u.getByIdProtoList.structureList).UTF8String().data(), stubInfo.u.getByIdProtoList.listSize);
9dae56ea 246 return;
f9bf01c6 247 case access_put_by_id_transition:
4e4e5a6f 248 printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(stubInfo.u.putByIdTransition.previousStructure).UTF8String().data(), pointerToSourceString(stubInfo.u.putByIdTransition.structure).UTF8String().data(), pointerToSourceString(stubInfo.u.putByIdTransition.chain).UTF8String().data());
9dae56ea 249 return;
f9bf01c6 250 case access_put_by_id_replace:
4e4e5a6f 251 printf(" [%4d] %s: %s\n", instructionOffset, "put_by_id_replace", pointerToSourceString(stubInfo.u.putByIdReplace.baseObjectStructure).UTF8String().data());
9dae56ea 252 return;
f9bf01c6 253 case access_get_by_id:
9dae56ea
A
254 printf(" [%4d] %s\n", instructionOffset, "get_by_id");
255 return;
f9bf01c6 256 case access_put_by_id:
9dae56ea
A
257 printf(" [%4d] %s\n", instructionOffset, "put_by_id");
258 return;
f9bf01c6 259 case access_get_by_id_generic:
9dae56ea
A
260 printf(" [%4d] %s\n", instructionOffset, "op_get_by_id_generic");
261 return;
f9bf01c6 262 case access_put_by_id_generic:
9dae56ea
A
263 printf(" [%4d] %s\n", instructionOffset, "op_put_by_id_generic");
264 return;
f9bf01c6 265 case access_get_array_length:
9dae56ea
A
266 printf(" [%4d] %s\n", instructionOffset, "op_get_array_length");
267 return;
f9bf01c6 268 case access_get_string_length:
9dae56ea
A
269 printf(" [%4d] %s\n", instructionOffset, "op_get_string_length");
270 return;
271 default:
272 ASSERT_NOT_REACHED();
273 }
274}
275#endif
276
277void CodeBlock::printStructure(const char* name, const Instruction* vPC, int operand) const
278{
279 unsigned instructionOffset = vPC - m_instructions.begin();
4e4e5a6f 280 printf(" [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure).UTF8String().data());
9dae56ea
A
281}
282
283void CodeBlock::printStructures(const Instruction* vPC) const
284{
285 Interpreter* interpreter = m_globalData->interpreter;
286 unsigned instructionOffset = vPC - m_instructions.begin();
287
288 if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id)) {
289 printStructure("get_by_id", vPC, 4);
290 return;
291 }
292 if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self)) {
293 printStructure("get_by_id_self", vPC, 4);
294 return;
295 }
296 if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto)) {
4e4e5a6f 297 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structure).UTF8String().data());
9dae56ea
A
298 return;
299 }
300 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) {
4e4e5a6f 301 printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structure).UTF8String().data(), pointerToSourceString(vPC[6].u.structureChain).UTF8String().data());
9dae56ea
A
302 return;
303 }
304 if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain)) {
4e4e5a6f 305 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structureChain).UTF8String().data());
9dae56ea
A
306 return;
307 }
308 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id)) {
309 printStructure("put_by_id", vPC, 4);
310 return;
311 }
312 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) {
313 printStructure("put_by_id_replace", vPC, 4);
314 return;
315 }
316 if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global)) {
317 printStructure("resolve_global", vPC, 4);
318 return;
319 }
4e4e5a6f
A
320 if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) {
321 printStructure("resolve_global_dynamic", vPC, 4);
322 return;
323 }
9dae56ea
A
324
325 // These m_instructions doesn't ref Structures.
326 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));
327}
328
329void CodeBlock::dump(ExecState* exec) const
330{
331 if (m_instructions.isEmpty()) {
332 printf("No instructions available.\n");
333 return;
334 }
335
336 size_t instructionCount = 0;
337
338 for (size_t i = 0; i < m_instructions.size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(m_instructions[i].u.opcode)])
339 ++instructionCount;
340
341 printf("%lu m_instructions; %lu bytes at %p; %d parameter(s); %d callee register(s)\n\n",
342 static_cast<unsigned long>(instructionCount),
343 static_cast<unsigned long>(m_instructions.size() * sizeof(Instruction)),
344 this, m_numParameters, m_numCalleeRegisters);
345
346 Vector<Instruction>::const_iterator begin = m_instructions.begin();
347 Vector<Instruction>::const_iterator end = m_instructions.end();
348 for (Vector<Instruction>::const_iterator it = begin; it != end; ++it)
349 dump(exec, begin, it);
350
351 if (!m_identifiers.isEmpty()) {
352 printf("\nIdentifiers:\n");
353 size_t i = 0;
354 do {
355 printf(" id%u = %s\n", static_cast<unsigned>(i), m_identifiers[i].ascii());
356 ++i;
357 } while (i != m_identifiers.size());
358 }
359
360 if (!m_constantRegisters.isEmpty()) {
361 printf("\nConstants:\n");
362 unsigned registerIndex = m_numVars;
363 size_t i = 0;
364 do {
f9bf01c6 365 printf(" k%u = %s\n", registerIndex, valueToSourceString(exec, m_constantRegisters[i].jsValue()).ascii());
9dae56ea
A
366 ++i;
367 ++registerIndex;
368 } while (i < m_constantRegisters.size());
369 }
370
9dae56ea
A
371 if (m_rareData && !m_rareData->m_regexps.isEmpty()) {
372 printf("\nm_regexps:\n");
373 size_t i = 0;
374 do {
375 printf(" re%u = %s\n", static_cast<unsigned>(i), regexpToSourceString(m_rareData->m_regexps[i].get()).ascii());
376 ++i;
377 } while (i < m_rareData->m_regexps.size());
378 }
379
380#if ENABLE(JIT)
381 if (!m_globalResolveInfos.isEmpty() || !m_structureStubInfos.isEmpty())
382 printf("\nStructures:\n");
383
384 if (!m_globalResolveInfos.isEmpty()) {
385 size_t i = 0;
386 do {
387 printGlobalResolveInfo(m_globalResolveInfos[i], instructionOffsetForNth(exec, m_instructions, i + 1, isGlobalResolve));
388 ++i;
389 } while (i < m_globalResolveInfos.size());
390 }
391 if (!m_structureStubInfos.isEmpty()) {
392 size_t i = 0;
393 do {
394 printStructureStubInfo(m_structureStubInfos[i], instructionOffsetForNth(exec, m_instructions, i + 1, isPropertyAccess));
395 ++i;
396 } while (i < m_structureStubInfos.size());
397 }
398#else
399 if (!m_globalResolveInstructions.isEmpty() || !m_propertyAccessInstructions.isEmpty())
400 printf("\nStructures:\n");
401
402 if (!m_globalResolveInstructions.isEmpty()) {
403 size_t i = 0;
404 do {
405 printStructures(&m_instructions[m_globalResolveInstructions[i]]);
406 ++i;
407 } while (i < m_globalResolveInstructions.size());
408 }
409 if (!m_propertyAccessInstructions.isEmpty()) {
410 size_t i = 0;
411 do {
412 printStructures(&m_instructions[m_propertyAccessInstructions[i]]);
413 ++i;
414 } while (i < m_propertyAccessInstructions.size());
415 }
416#endif
417
418 if (m_rareData && !m_rareData->m_exceptionHandlers.isEmpty()) {
419 printf("\nException Handlers:\n");
420 unsigned i = 0;
421 do {
422 printf("\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);
423 ++i;
424 } while (i < m_rareData->m_exceptionHandlers.size());
425 }
426
427 if (m_rareData && !m_rareData->m_immediateSwitchJumpTables.isEmpty()) {
428 printf("Immediate Switch Jump Tables:\n");
429 unsigned i = 0;
430 do {
431 printf(" %1d = {\n", i);
432 int entry = 0;
433 Vector<int32_t>::const_iterator end = m_rareData->m_immediateSwitchJumpTables[i].branchOffsets.end();
434 for (Vector<int32_t>::const_iterator iter = m_rareData->m_immediateSwitchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) {
435 if (!*iter)
436 continue;
437 printf("\t\t%4d => %04d\n", entry + m_rareData->m_immediateSwitchJumpTables[i].min, *iter);
438 }
439 printf(" }\n");
440 ++i;
441 } while (i < m_rareData->m_immediateSwitchJumpTables.size());
442 }
443
444 if (m_rareData && !m_rareData->m_characterSwitchJumpTables.isEmpty()) {
445 printf("\nCharacter Switch Jump Tables:\n");
446 unsigned i = 0;
447 do {
448 printf(" %1d = {\n", i);
449 int entry = 0;
450 Vector<int32_t>::const_iterator end = m_rareData->m_characterSwitchJumpTables[i].branchOffsets.end();
451 for (Vector<int32_t>::const_iterator iter = m_rareData->m_characterSwitchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) {
452 if (!*iter)
453 continue;
454 ASSERT(!((i + m_rareData->m_characterSwitchJumpTables[i].min) & ~0xFFFF));
455 UChar ch = static_cast<UChar>(entry + m_rareData->m_characterSwitchJumpTables[i].min);
456 printf("\t\t\"%s\" => %04d\n", UString(&ch, 1).ascii(), *iter);
457 }
458 printf(" }\n");
459 ++i;
460 } while (i < m_rareData->m_characterSwitchJumpTables.size());
461 }
462
463 if (m_rareData && !m_rareData->m_stringSwitchJumpTables.isEmpty()) {
464 printf("\nString Switch Jump Tables:\n");
465 unsigned i = 0;
466 do {
467 printf(" %1d = {\n", i);
468 StringJumpTable::StringOffsetTable::const_iterator end = m_rareData->m_stringSwitchJumpTables[i].offsetTable.end();
469 for (StringJumpTable::StringOffsetTable::const_iterator iter = m_rareData->m_stringSwitchJumpTables[i].offsetTable.begin(); iter != end; ++iter)
470 printf("\t\t\"%s\" => %04d\n", UString(iter->first).ascii(), iter->second.branchOffset);
471 printf(" }\n");
472 ++i;
473 } while (i < m_rareData->m_stringSwitchJumpTables.size());
474 }
475
476 printf("\n");
477}
478
479void CodeBlock::dump(ExecState* exec, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator& it) const
480{
481 int location = it - begin;
482 switch (exec->interpreter()->getOpcodeID(it->u.opcode)) {
483 case op_enter: {
484 printf("[%4d] enter\n", location);
485 break;
486 }
487 case op_enter_with_activation: {
488 int r0 = (++it)->u.operand;
4e4e5a6f 489 printf("[%4d] enter_with_activation %s\n", location, registerName(exec, r0).data());
9dae56ea
A
490 break;
491 }
492 case op_create_arguments: {
493 printf("[%4d] create_arguments\n", location);
494 break;
495 }
ba379fdc
A
496 case op_init_arguments: {
497 printf("[%4d] init_arguments\n", location);
9dae56ea
A
498 break;
499 }
ba379fdc 500 case op_convert_this: {
9dae56ea 501 int r0 = (++it)->u.operand;
4e4e5a6f 502 printf("[%4d] convert_this %s\n", location, registerName(exec, r0).data());
9dae56ea
A
503 break;
504 }
505 case op_new_object: {
506 int r0 = (++it)->u.operand;
4e4e5a6f 507 printf("[%4d] new_object\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
508 break;
509 }
510 case op_new_array: {
511 int dst = (++it)->u.operand;
512 int argv = (++it)->u.operand;
513 int argc = (++it)->u.operand;
4e4e5a6f 514 printf("[%4d] new_array\t %s, %s, %d\n", location, registerName(exec, dst).data(), registerName(exec, argv).data(), argc);
9dae56ea
A
515 break;
516 }
517 case op_new_regexp: {
518 int r0 = (++it)->u.operand;
519 int re0 = (++it)->u.operand;
4e4e5a6f 520 printf("[%4d] new_regexp\t %s, %s\n", location, registerName(exec, r0).data(), regexpName(re0, regexp(re0)).data());
9dae56ea
A
521 break;
522 }
523 case op_mov: {
524 int r0 = (++it)->u.operand;
525 int r1 = (++it)->u.operand;
4e4e5a6f 526 printf("[%4d] mov\t\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
9dae56ea
A
527 break;
528 }
529 case op_not: {
f9bf01c6 530 printUnaryOp(exec, location, it, "not");
9dae56ea
A
531 break;
532 }
533 case op_eq: {
f9bf01c6 534 printBinaryOp(exec, location, it, "eq");
9dae56ea
A
535 break;
536 }
537 case op_eq_null: {
f9bf01c6 538 printUnaryOp(exec, location, it, "eq_null");
9dae56ea
A
539 break;
540 }
541 case op_neq: {
f9bf01c6 542 printBinaryOp(exec, location, it, "neq");
9dae56ea
A
543 break;
544 }
545 case op_neq_null: {
f9bf01c6 546 printUnaryOp(exec, location, it, "neq_null");
9dae56ea
A
547 break;
548 }
549 case op_stricteq: {
f9bf01c6 550 printBinaryOp(exec, location, it, "stricteq");
9dae56ea
A
551 break;
552 }
553 case op_nstricteq: {
f9bf01c6 554 printBinaryOp(exec, location, it, "nstricteq");
9dae56ea
A
555 break;
556 }
557 case op_less: {
f9bf01c6 558 printBinaryOp(exec, location, it, "less");
9dae56ea
A
559 break;
560 }
561 case op_lesseq: {
f9bf01c6 562 printBinaryOp(exec, location, it, "lesseq");
9dae56ea
A
563 break;
564 }
565 case op_pre_inc: {
566 int r0 = (++it)->u.operand;
4e4e5a6f 567 printf("[%4d] pre_inc\t\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
568 break;
569 }
570 case op_pre_dec: {
571 int r0 = (++it)->u.operand;
4e4e5a6f 572 printf("[%4d] pre_dec\t\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
573 break;
574 }
575 case op_post_inc: {
f9bf01c6 576 printUnaryOp(exec, location, it, "post_inc");
9dae56ea
A
577 break;
578 }
579 case op_post_dec: {
f9bf01c6 580 printUnaryOp(exec, location, it, "post_dec");
9dae56ea
A
581 break;
582 }
583 case op_to_jsnumber: {
f9bf01c6 584 printUnaryOp(exec, location, it, "to_jsnumber");
9dae56ea
A
585 break;
586 }
587 case op_negate: {
f9bf01c6 588 printUnaryOp(exec, location, it, "negate");
9dae56ea
A
589 break;
590 }
591 case op_add: {
f9bf01c6 592 printBinaryOp(exec, location, it, "add");
9dae56ea
A
593 ++it;
594 break;
595 }
596 case op_mul: {
f9bf01c6 597 printBinaryOp(exec, location, it, "mul");
9dae56ea
A
598 ++it;
599 break;
600 }
601 case op_div: {
f9bf01c6 602 printBinaryOp(exec, location, it, "div");
ba379fdc 603 ++it;
9dae56ea
A
604 break;
605 }
606 case op_mod: {
f9bf01c6 607 printBinaryOp(exec, location, it, "mod");
9dae56ea
A
608 break;
609 }
610 case op_sub: {
f9bf01c6 611 printBinaryOp(exec, location, it, "sub");
9dae56ea
A
612 ++it;
613 break;
614 }
615 case op_lshift: {
f9bf01c6 616 printBinaryOp(exec, location, it, "lshift");
9dae56ea
A
617 break;
618 }
619 case op_rshift: {
f9bf01c6 620 printBinaryOp(exec, location, it, "rshift");
9dae56ea
A
621 break;
622 }
623 case op_urshift: {
f9bf01c6 624 printBinaryOp(exec, location, it, "urshift");
9dae56ea
A
625 break;
626 }
627 case op_bitand: {
f9bf01c6 628 printBinaryOp(exec, location, it, "bitand");
9dae56ea
A
629 ++it;
630 break;
631 }
632 case op_bitxor: {
f9bf01c6 633 printBinaryOp(exec, location, it, "bitxor");
9dae56ea
A
634 ++it;
635 break;
636 }
637 case op_bitor: {
f9bf01c6 638 printBinaryOp(exec, location, it, "bitor");
9dae56ea
A
639 ++it;
640 break;
641 }
642 case op_bitnot: {
f9bf01c6 643 printUnaryOp(exec, location, it, "bitnot");
9dae56ea
A
644 break;
645 }
646 case op_instanceof: {
647 int r0 = (++it)->u.operand;
648 int r1 = (++it)->u.operand;
649 int r2 = (++it)->u.operand;
650 int r3 = (++it)->u.operand;
4e4e5a6f 651 printf("[%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());
9dae56ea
A
652 break;
653 }
654 case op_typeof: {
f9bf01c6 655 printUnaryOp(exec, location, it, "typeof");
9dae56ea
A
656 break;
657 }
658 case op_is_undefined: {
f9bf01c6 659 printUnaryOp(exec, location, it, "is_undefined");
9dae56ea
A
660 break;
661 }
662 case op_is_boolean: {
f9bf01c6 663 printUnaryOp(exec, location, it, "is_boolean");
9dae56ea
A
664 break;
665 }
666 case op_is_number: {
f9bf01c6 667 printUnaryOp(exec, location, it, "is_number");
9dae56ea
A
668 break;
669 }
670 case op_is_string: {
f9bf01c6 671 printUnaryOp(exec, location, it, "is_string");
9dae56ea
A
672 break;
673 }
674 case op_is_object: {
f9bf01c6 675 printUnaryOp(exec, location, it, "is_object");
9dae56ea
A
676 break;
677 }
678 case op_is_function: {
f9bf01c6 679 printUnaryOp(exec, location, it, "is_function");
9dae56ea
A
680 break;
681 }
682 case op_in: {
f9bf01c6 683 printBinaryOp(exec, location, it, "in");
9dae56ea
A
684 break;
685 }
686 case op_resolve: {
687 int r0 = (++it)->u.operand;
688 int id0 = (++it)->u.operand;
4e4e5a6f 689 printf("[%4d] resolve\t\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data());
9dae56ea
A
690 break;
691 }
692 case op_resolve_skip: {
693 int r0 = (++it)->u.operand;
694 int id0 = (++it)->u.operand;
695 int skipLevels = (++it)->u.operand;
4e4e5a6f 696 printf("[%4d] resolve_skip\t %s, %s, %d\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), skipLevels);
9dae56ea
A
697 break;
698 }
699 case op_resolve_global: {
700 int r0 = (++it)->u.operand;
ba379fdc 701 JSValue scope = JSValue((++it)->u.jsCell);
9dae56ea 702 int id0 = (++it)->u.operand;
4e4e5a6f 703 printf("[%4d] resolve_global\t %s, %s, %s\n", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).ascii(), idName(id0, m_identifiers[id0]).data());
9dae56ea
A
704 it += 2;
705 break;
706 }
4e4e5a6f
A
707 case op_resolve_global_dynamic: {
708 int r0 = (++it)->u.operand;
709 JSValue scope = JSValue((++it)->u.jsCell);
710 int id0 = (++it)->u.operand;
711 int depth = it[2].u.operand;
712 printf("[%4d] resolve_global_dynamic\t %s, %s, %s, %d\n", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).ascii(), idName(id0, m_identifiers[id0]).data(), depth);
713 it += 3;
714 break;
715 }
9dae56ea
A
716 case op_get_scoped_var: {
717 int r0 = (++it)->u.operand;
718 int index = (++it)->u.operand;
719 int skipLevels = (++it)->u.operand;
4e4e5a6f 720 printf("[%4d] get_scoped_var\t %s, %d, %d\n", location, registerName(exec, r0).data(), index, skipLevels);
9dae56ea
A
721 break;
722 }
723 case op_put_scoped_var: {
724 int index = (++it)->u.operand;
725 int skipLevels = (++it)->u.operand;
726 int r0 = (++it)->u.operand;
4e4e5a6f 727 printf("[%4d] put_scoped_var\t %d, %d, %s\n", location, index, skipLevels, registerName(exec, r0).data());
9dae56ea
A
728 break;
729 }
730 case op_get_global_var: {
731 int r0 = (++it)->u.operand;
ba379fdc 732 JSValue scope = JSValue((++it)->u.jsCell);
9dae56ea 733 int index = (++it)->u.operand;
4e4e5a6f 734 printf("[%4d] get_global_var\t %s, %s, %d\n", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).ascii(), index);
9dae56ea
A
735 break;
736 }
737 case op_put_global_var: {
ba379fdc 738 JSValue scope = JSValue((++it)->u.jsCell);
9dae56ea
A
739 int index = (++it)->u.operand;
740 int r0 = (++it)->u.operand;
4e4e5a6f 741 printf("[%4d] put_global_var\t %s, %d, %s\n", location, valueToSourceString(exec, scope).ascii(), index, registerName(exec, r0).data());
9dae56ea
A
742 break;
743 }
744 case op_resolve_base: {
745 int r0 = (++it)->u.operand;
746 int id0 = (++it)->u.operand;
4e4e5a6f 747 printf("[%4d] resolve_base\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data());
9dae56ea
A
748 break;
749 }
750 case op_resolve_with_base: {
751 int r0 = (++it)->u.operand;
752 int r1 = (++it)->u.operand;
753 int id0 = (++it)->u.operand;
4e4e5a6f 754 printf("[%4d] resolve_with_base %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
9dae56ea
A
755 break;
756 }
9dae56ea 757 case op_get_by_id: {
f9bf01c6 758 printGetByIdOp(exec, location, it, "get_by_id");
9dae56ea
A
759 break;
760 }
761 case op_get_by_id_self: {
f9bf01c6 762 printGetByIdOp(exec, location, it, "get_by_id_self");
9dae56ea
A
763 break;
764 }
765 case op_get_by_id_self_list: {
f9bf01c6 766 printGetByIdOp(exec, location, it, "get_by_id_self_list");
9dae56ea
A
767 break;
768 }
769 case op_get_by_id_proto: {
f9bf01c6 770 printGetByIdOp(exec, location, it, "get_by_id_proto");
9dae56ea
A
771 break;
772 }
773 case op_get_by_id_proto_list: {
f9bf01c6 774 printGetByIdOp(exec, location, it, "op_get_by_id_proto_list");
9dae56ea
A
775 break;
776 }
777 case op_get_by_id_chain: {
f9bf01c6 778 printGetByIdOp(exec, location, it, "get_by_id_chain");
9dae56ea
A
779 break;
780 }
4e4e5a6f
A
781 case op_get_by_id_getter_self: {
782 printGetByIdOp(exec, location, it, "get_by_id_getter_self");
783 break;
784 }
785 case op_get_by_id_getter_self_list: {
786 printGetByIdOp(exec, location, it, "get_by_id_getter_self_list");
787 break;
788 }
789 case op_get_by_id_getter_proto: {
790 printGetByIdOp(exec, location, it, "get_by_id_getter_proto");
791 break;
792 }
793 case op_get_by_id_getter_proto_list: {
794 printGetByIdOp(exec, location, it, "get_by_id_getter_proto_list");
795 break;
796 }
797 case op_get_by_id_getter_chain: {
798 printGetByIdOp(exec, location, it, "get_by_id_getter_chain");
799 break;
800 }
801 case op_get_by_id_custom_self: {
802 printGetByIdOp(exec, location, it, "get_by_id_custom_self");
803 break;
804 }
805 case op_get_by_id_custom_self_list: {
806 printGetByIdOp(exec, location, it, "get_by_id_custom_self_list");
807 break;
808 }
809 case op_get_by_id_custom_proto: {
810 printGetByIdOp(exec, location, it, "get_by_id_custom_proto");
811 break;
812 }
813 case op_get_by_id_custom_proto_list: {
814 printGetByIdOp(exec, location, it, "get_by_id_custom_proto_list");
815 break;
816 }
817 case op_get_by_id_custom_chain: {
818 printGetByIdOp(exec, location, it, "get_by_id_custom_chain");
819 break;
820 }
9dae56ea 821 case op_get_by_id_generic: {
f9bf01c6 822 printGetByIdOp(exec, location, it, "get_by_id_generic");
9dae56ea
A
823 break;
824 }
825 case op_get_array_length: {
f9bf01c6 826 printGetByIdOp(exec, location, it, "get_array_length");
9dae56ea
A
827 break;
828 }
829 case op_get_string_length: {
f9bf01c6 830 printGetByIdOp(exec, location, it, "get_string_length");
9dae56ea
A
831 break;
832 }
833 case op_put_by_id: {
f9bf01c6 834 printPutByIdOp(exec, location, it, "put_by_id");
9dae56ea
A
835 break;
836 }
837 case op_put_by_id_replace: {
f9bf01c6 838 printPutByIdOp(exec, location, it, "put_by_id_replace");
9dae56ea
A
839 break;
840 }
841 case op_put_by_id_transition: {
f9bf01c6 842 printPutByIdOp(exec, location, it, "put_by_id_transition");
9dae56ea
A
843 break;
844 }
845 case op_put_by_id_generic: {
f9bf01c6 846 printPutByIdOp(exec, location, it, "put_by_id_generic");
9dae56ea
A
847 break;
848 }
849 case op_put_getter: {
850 int r0 = (++it)->u.operand;
851 int id0 = (++it)->u.operand;
852 int r1 = (++it)->u.operand;
4e4e5a6f 853 printf("[%4d] put_getter\t %s, %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data());
9dae56ea
A
854 break;
855 }
856 case op_put_setter: {
857 int r0 = (++it)->u.operand;
858 int id0 = (++it)->u.operand;
859 int r1 = (++it)->u.operand;
4e4e5a6f 860 printf("[%4d] put_setter\t %s, %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data());
9dae56ea
A
861 break;
862 }
ba379fdc 863 case op_method_check: {
f9bf01c6 864 printf("[%4d] method_check\n", location);
ba379fdc
A
865 break;
866 }
9dae56ea
A
867 case op_del_by_id: {
868 int r0 = (++it)->u.operand;
869 int r1 = (++it)->u.operand;
870 int id0 = (++it)->u.operand;
4e4e5a6f 871 printf("[%4d] del_by_id\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
9dae56ea
A
872 break;
873 }
874 case op_get_by_val: {
875 int r0 = (++it)->u.operand;
876 int r1 = (++it)->u.operand;
877 int r2 = (++it)->u.operand;
4e4e5a6f 878 printf("[%4d] get_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
f9bf01c6
A
879 break;
880 }
881 case op_get_by_pname: {
882 int r0 = (++it)->u.operand;
883 int r1 = (++it)->u.operand;
884 int r2 = (++it)->u.operand;
885 int r3 = (++it)->u.operand;
886 int r4 = (++it)->u.operand;
887 int r5 = (++it)->u.operand;
4e4e5a6f 888 printf("[%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());
9dae56ea
A
889 break;
890 }
891 case op_put_by_val: {
892 int r0 = (++it)->u.operand;
893 int r1 = (++it)->u.operand;
894 int r2 = (++it)->u.operand;
4e4e5a6f 895 printf("[%4d] put_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
9dae56ea
A
896 break;
897 }
898 case op_del_by_val: {
899 int r0 = (++it)->u.operand;
900 int r1 = (++it)->u.operand;
901 int r2 = (++it)->u.operand;
4e4e5a6f 902 printf("[%4d] del_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
9dae56ea
A
903 break;
904 }
905 case op_put_by_index: {
906 int r0 = (++it)->u.operand;
907 unsigned n0 = (++it)->u.operand;
908 int r1 = (++it)->u.operand;
4e4e5a6f 909 printf("[%4d] put_by_index\t %s, %u, %s\n", location, registerName(exec, r0).data(), n0, registerName(exec, r1).data());
9dae56ea
A
910 break;
911 }
912 case op_jmp: {
913 int offset = (++it)->u.operand;
f9bf01c6 914 printf("[%4d] jmp\t\t %d(->%d)\n", location, offset, location + offset);
9dae56ea
A
915 break;
916 }
917 case op_loop: {
918 int offset = (++it)->u.operand;
f9bf01c6 919 printf("[%4d] loop\t\t %d(->%d)\n", location, offset, location + offset);
9dae56ea
A
920 break;
921 }
922 case op_jtrue: {
f9bf01c6 923 printConditionalJump(exec, begin, it, location, "jtrue");
9dae56ea
A
924 break;
925 }
926 case op_loop_if_true: {
f9bf01c6
A
927 printConditionalJump(exec, begin, it, location, "loop_if_true");
928 break;
929 }
930 case op_loop_if_false: {
931 printConditionalJump(exec, begin, it, location, "loop_if_false");
9dae56ea
A
932 break;
933 }
934 case op_jfalse: {
f9bf01c6 935 printConditionalJump(exec, begin, it, location, "jfalse");
9dae56ea
A
936 break;
937 }
938 case op_jeq_null: {
f9bf01c6 939 printConditionalJump(exec, begin, it, location, "jeq_null");
9dae56ea
A
940 break;
941 }
942 case op_jneq_null: {
f9bf01c6 943 printConditionalJump(exec, begin, it, location, "jneq_null");
9dae56ea
A
944 break;
945 }
ba379fdc
A
946 case op_jneq_ptr: {
947 int r0 = (++it)->u.operand;
948 int r1 = (++it)->u.operand;
949 int offset = (++it)->u.operand;
4e4e5a6f 950 printf("[%4d] jneq_ptr\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
ba379fdc
A
951 break;
952 }
9dae56ea
A
953 case op_jnless: {
954 int r0 = (++it)->u.operand;
955 int r1 = (++it)->u.operand;
956 int offset = (++it)->u.operand;
4e4e5a6f 957 printf("[%4d] jnless\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
9dae56ea
A
958 break;
959 }
ba379fdc
A
960 case op_jnlesseq: {
961 int r0 = (++it)->u.operand;
962 int r1 = (++it)->u.operand;
963 int offset = (++it)->u.operand;
4e4e5a6f 964 printf("[%4d] jnlesseq\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
ba379fdc
A
965 break;
966 }
9dae56ea
A
967 case op_loop_if_less: {
968 int r0 = (++it)->u.operand;
969 int r1 = (++it)->u.operand;
970 int offset = (++it)->u.operand;
4e4e5a6f 971 printf("[%4d] loop_if_less\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
f9bf01c6
A
972 break;
973 }
974 case op_jless: {
975 int r0 = (++it)->u.operand;
976 int r1 = (++it)->u.operand;
977 int offset = (++it)->u.operand;
4e4e5a6f
A
978 printf("[%4d] jless\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
979 break;
980 }
981 case op_jlesseq: {
982 int r0 = (++it)->u.operand;
983 int r1 = (++it)->u.operand;
984 int offset = (++it)->u.operand;
985 printf("[%4d] jlesseq\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
9dae56ea
A
986 break;
987 }
988 case op_loop_if_lesseq: {
989 int r0 = (++it)->u.operand;
990 int r1 = (++it)->u.operand;
991 int offset = (++it)->u.operand;
4e4e5a6f 992 printf("[%4d] loop_if_lesseq\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
9dae56ea
A
993 break;
994 }
995 case op_switch_imm: {
996 int tableIndex = (++it)->u.operand;
997 int defaultTarget = (++it)->u.operand;
998 int scrutineeRegister = (++it)->u.operand;
4e4e5a6f 999 printf("[%4d] switch_imm\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
9dae56ea
A
1000 break;
1001 }
1002 case op_switch_char: {
1003 int tableIndex = (++it)->u.operand;
1004 int defaultTarget = (++it)->u.operand;
1005 int scrutineeRegister = (++it)->u.operand;
4e4e5a6f 1006 printf("[%4d] switch_char\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
9dae56ea
A
1007 break;
1008 }
1009 case op_switch_string: {
1010 int tableIndex = (++it)->u.operand;
1011 int defaultTarget = (++it)->u.operand;
1012 int scrutineeRegister = (++it)->u.operand;
4e4e5a6f 1013 printf("[%4d] switch_string\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
9dae56ea
A
1014 break;
1015 }
1016 case op_new_func: {
1017 int r0 = (++it)->u.operand;
1018 int f0 = (++it)->u.operand;
4e4e5a6f 1019 printf("[%4d] new_func\t\t %s, f%d\n", location, registerName(exec, r0).data(), f0);
9dae56ea
A
1020 break;
1021 }
1022 case op_new_func_exp: {
1023 int r0 = (++it)->u.operand;
1024 int f0 = (++it)->u.operand;
4e4e5a6f 1025 printf("[%4d] new_func_exp\t %s, f%d\n", location, registerName(exec, r0).data(), f0);
9dae56ea
A
1026 break;
1027 }
1028 case op_call: {
1029 int dst = (++it)->u.operand;
1030 int func = (++it)->u.operand;
1031 int argCount = (++it)->u.operand;
1032 int registerOffset = (++it)->u.operand;
4e4e5a6f 1033 printf("[%4d] call\t\t %s, %s, %d, %d\n", location, registerName(exec, dst).data(), registerName(exec, func).data(), argCount, registerOffset);
9dae56ea
A
1034 break;
1035 }
1036 case op_call_eval: {
1037 int dst = (++it)->u.operand;
1038 int func = (++it)->u.operand;
1039 int argCount = (++it)->u.operand;
1040 int registerOffset = (++it)->u.operand;
4e4e5a6f 1041 printf("[%4d] call_eval\t %s, %s, %d, %d\n", location, registerName(exec, dst).data(), registerName(exec, func).data(), argCount, registerOffset);
9dae56ea
A
1042 break;
1043 }
ba379fdc
A
1044 case op_call_varargs: {
1045 int dst = (++it)->u.operand;
1046 int func = (++it)->u.operand;
1047 int argCount = (++it)->u.operand;
1048 int registerOffset = (++it)->u.operand;
4e4e5a6f 1049 printf("[%4d] call_varargs\t %s, %s, %s, %d\n", location, registerName(exec, dst).data(), registerName(exec, func).data(), registerName(exec, argCount).data(), registerOffset);
ba379fdc
A
1050 break;
1051 }
1052 case op_load_varargs: {
f9bf01c6 1053 printUnaryOp(exec, location, it, "load_varargs");
ba379fdc
A
1054 break;
1055 }
9dae56ea
A
1056 case op_tear_off_activation: {
1057 int r0 = (++it)->u.operand;
4e4e5a6f 1058 printf("[%4d] tear_off_activation\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
1059 break;
1060 }
1061 case op_tear_off_arguments: {
1062 printf("[%4d] tear_off_arguments\n", location);
1063 break;
1064 }
1065 case op_ret: {
1066 int r0 = (++it)->u.operand;
4e4e5a6f 1067 printf("[%4d] ret\t\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
1068 break;
1069 }
1070 case op_construct: {
1071 int dst = (++it)->u.operand;
1072 int func = (++it)->u.operand;
1073 int argCount = (++it)->u.operand;
1074 int registerOffset = (++it)->u.operand;
1075 int proto = (++it)->u.operand;
1076 int thisRegister = (++it)->u.operand;
4e4e5a6f 1077 printf("[%4d] construct\t %s, %s, %d, %d, %s, %s\n", location, registerName(exec, dst).data(), registerName(exec, func).data(), argCount, registerOffset, registerName(exec, proto).data(), registerName(exec, thisRegister).data());
9dae56ea
A
1078 break;
1079 }
1080 case op_construct_verify: {
1081 int r0 = (++it)->u.operand;
1082 int r1 = (++it)->u.operand;
4e4e5a6f 1083 printf("[%4d] construct_verify\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
9dae56ea
A
1084 break;
1085 }
ba379fdc
A
1086 case op_strcat: {
1087 int r0 = (++it)->u.operand;
1088 int r1 = (++it)->u.operand;
1089 int count = (++it)->u.operand;
4e4e5a6f 1090 printf("[%4d] strcat\t\t %s, %s, %d\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), count);
ba379fdc
A
1091 break;
1092 }
1093 case op_to_primitive: {
1094 int r0 = (++it)->u.operand;
1095 int r1 = (++it)->u.operand;
4e4e5a6f 1096 printf("[%4d] to_primitive\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
ba379fdc
A
1097 break;
1098 }
9dae56ea 1099 case op_get_pnames: {
f9bf01c6
A
1100 int r0 = it[1].u.operand;
1101 int r1 = it[2].u.operand;
1102 int r2 = it[3].u.operand;
1103 int r3 = it[4].u.operand;
1104 int offset = it[5].u.operand;
4e4e5a6f 1105 printf("[%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);
f9bf01c6 1106 it += OPCODE_LENGTH(op_get_pnames) - 1;
9dae56ea
A
1107 break;
1108 }
1109 case op_next_pname: {
f9bf01c6
A
1110 int dest = it[1].u.operand;
1111 int iter = it[4].u.operand;
1112 int offset = it[5].u.operand;
4e4e5a6f 1113 printf("[%4d] next_pname\t %s, %s, %d(->%d)\n", location, registerName(exec, dest).data(), registerName(exec, iter).data(), offset, location + offset);
f9bf01c6 1114 it += OPCODE_LENGTH(op_next_pname) - 1;
9dae56ea
A
1115 break;
1116 }
1117 case op_push_scope: {
1118 int r0 = (++it)->u.operand;
4e4e5a6f 1119 printf("[%4d] push_scope\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
1120 break;
1121 }
1122 case op_pop_scope: {
1123 printf("[%4d] pop_scope\n", location);
1124 break;
1125 }
1126 case op_push_new_scope: {
1127 int r0 = (++it)->u.operand;
1128 int id0 = (++it)->u.operand;
1129 int r1 = (++it)->u.operand;
4e4e5a6f 1130 printf("[%4d] push_new_scope \t%s, %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data());
9dae56ea
A
1131 break;
1132 }
1133 case op_jmp_scopes: {
1134 int scopeDelta = (++it)->u.operand;
1135 int offset = (++it)->u.operand;
f9bf01c6 1136 printf("[%4d] jmp_scopes\t^%d, %d(->%d)\n", location, scopeDelta, offset, location + offset);
9dae56ea
A
1137 break;
1138 }
1139 case op_catch: {
1140 int r0 = (++it)->u.operand;
4e4e5a6f 1141 printf("[%4d] catch\t\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
1142 break;
1143 }
1144 case op_throw: {
1145 int r0 = (++it)->u.operand;
4e4e5a6f 1146 printf("[%4d] throw\t\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
1147 break;
1148 }
1149 case op_new_error: {
1150 int r0 = (++it)->u.operand;
1151 int errorType = (++it)->u.operand;
1152 int k0 = (++it)->u.operand;
4e4e5a6f 1153 printf("[%4d] new_error\t %s, %d, %s\n", location, registerName(exec, r0).data(), errorType, constantName(exec, k0, getConstant(k0)).data());
9dae56ea
A
1154 break;
1155 }
1156 case op_jsr: {
1157 int retAddrDst = (++it)->u.operand;
1158 int offset = (++it)->u.operand;
4e4e5a6f 1159 printf("[%4d] jsr\t\t %s, %d(->%d)\n", location, registerName(exec, retAddrDst).data(), offset, location + offset);
9dae56ea
A
1160 break;
1161 }
1162 case op_sret: {
1163 int retAddrSrc = (++it)->u.operand;
4e4e5a6f 1164 printf("[%4d] sret\t\t %s\n", location, registerName(exec, retAddrSrc).data());
9dae56ea
A
1165 break;
1166 }
1167 case op_debug: {
1168 int debugHookID = (++it)->u.operand;
1169 int firstLine = (++it)->u.operand;
1170 int lastLine = (++it)->u.operand;
1171 printf("[%4d] debug\t\t %s, %d, %d\n", location, debugHookName(debugHookID), firstLine, lastLine);
1172 break;
1173 }
1174 case op_profile_will_call: {
1175 int function = (++it)->u.operand;
4e4e5a6f 1176 printf("[%4d] profile_will_call %s\n", location, registerName(exec, function).data());
9dae56ea
A
1177 break;
1178 }
1179 case op_profile_did_call: {
1180 int function = (++it)->u.operand;
4e4e5a6f 1181 printf("[%4d] profile_did_call\t %s\n", location, registerName(exec, function).data());
9dae56ea
A
1182 break;
1183 }
1184 case op_end: {
1185 int r0 = (++it)->u.operand;
4e4e5a6f 1186 printf("[%4d] end\t\t %s\n", location, registerName(exec, r0).data());
9dae56ea
A
1187 break;
1188 }
1189 }
1190}
1191
1192#endif // !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING)
1193
1194#if DUMP_CODE_BLOCK_STATISTICS
1195static HashSet<CodeBlock*> liveCodeBlockSet;
1196#endif
1197
1198#define FOR_EACH_MEMBER_VECTOR(macro) \
1199 macro(instructions) \
1200 macro(globalResolveInfos) \
1201 macro(structureStubInfos) \
1202 macro(callLinkInfos) \
1203 macro(linkedCallerList) \
1204 macro(identifiers) \
1205 macro(functionExpressions) \
1206 macro(constantRegisters)
1207
1208#define FOR_EACH_MEMBER_VECTOR_RARE_DATA(macro) \
1209 macro(regexps) \
1210 macro(functions) \
9dae56ea
A
1211 macro(exceptionHandlers) \
1212 macro(immediateSwitchJumpTables) \
1213 macro(characterSwitchJumpTables) \
1214 macro(stringSwitchJumpTables) \
1215 macro(functionRegisterInfos)
1216
1217#define FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(macro) \
1218 macro(expressionInfo) \
1219 macro(lineInfo) \
1220 macro(getByIdExceptionInfo) \
1221 macro(pcVector)
1222
1223template<typename T>
1224static size_t sizeInBytes(const Vector<T>& vector)
1225{
1226 return vector.capacity() * sizeof(T);
1227}
1228
1229void CodeBlock::dumpStatistics()
1230{
1231#if DUMP_CODE_BLOCK_STATISTICS
1232 #define DEFINE_VARS(name) size_t name##IsNotEmpty = 0; size_t name##TotalSize = 0;
1233 FOR_EACH_MEMBER_VECTOR(DEFINE_VARS)
1234 FOR_EACH_MEMBER_VECTOR_RARE_DATA(DEFINE_VARS)
1235 FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(DEFINE_VARS)
1236 #undef DEFINE_VARS
1237
1238 // Non-vector data members
1239 size_t evalCodeCacheIsNotEmpty = 0;
1240
1241 size_t symbolTableIsNotEmpty = 0;
1242 size_t symbolTableTotalSize = 0;
1243
1244 size_t hasExceptionInfo = 0;
1245 size_t hasRareData = 0;
1246
1247 size_t isFunctionCode = 0;
1248 size_t isGlobalCode = 0;
1249 size_t isEvalCode = 0;
1250
1251 HashSet<CodeBlock*>::const_iterator end = liveCodeBlockSet.end();
1252 for (HashSet<CodeBlock*>::const_iterator it = liveCodeBlockSet.begin(); it != end; ++it) {
1253 CodeBlock* codeBlock = *it;
1254
1255 #define GET_STATS(name) if (!codeBlock->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_##name); }
1256 FOR_EACH_MEMBER_VECTOR(GET_STATS)
1257 #undef GET_STATS
1258
1259 if (!codeBlock->m_symbolTable.isEmpty()) {
1260 symbolTableIsNotEmpty++;
1261 symbolTableTotalSize += (codeBlock->m_symbolTable.capacity() * (sizeof(SymbolTable::KeyType) + sizeof(SymbolTable::MappedType)));
1262 }
1263
1264 if (codeBlock->m_exceptionInfo) {
1265 hasExceptionInfo++;
1266 #define GET_STATS(name) if (!codeBlock->m_exceptionInfo->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_exceptionInfo->m_##name); }
1267 FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(GET_STATS)
1268 #undef GET_STATS
1269 }
1270
1271 if (codeBlock->m_rareData) {
1272 hasRareData++;
1273 #define GET_STATS(name) if (!codeBlock->m_rareData->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_rareData->m_##name); }
1274 FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_STATS)
1275 #undef GET_STATS
1276
1277 if (!codeBlock->m_rareData->m_evalCodeCache.isEmpty())
1278 evalCodeCacheIsNotEmpty++;
1279 }
1280
1281 switch (codeBlock->codeType()) {
1282 case FunctionCode:
1283 ++isFunctionCode;
1284 break;
1285 case GlobalCode:
1286 ++isGlobalCode;
1287 break;
1288 case EvalCode:
1289 ++isEvalCode;
1290 break;
1291 }
1292 }
1293
1294 size_t totalSize = 0;
1295
1296 #define GET_TOTAL_SIZE(name) totalSize += name##TotalSize;
1297 FOR_EACH_MEMBER_VECTOR(GET_TOTAL_SIZE)
1298 FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_TOTAL_SIZE)
1299 FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(GET_TOTAL_SIZE)
1300 #undef GET_TOTAL_SIZE
1301
1302 totalSize += symbolTableTotalSize;
1303 totalSize += (liveCodeBlockSet.size() * sizeof(CodeBlock));
1304
1305 printf("Number of live CodeBlocks: %d\n", liveCodeBlockSet.size());
1306 printf("Size of a single CodeBlock [sizeof(CodeBlock)]: %zu\n", sizeof(CodeBlock));
1307 printf("Size of all CodeBlocks: %zu\n", totalSize);
1308 printf("Average size of a CodeBlock: %zu\n", totalSize / liveCodeBlockSet.size());
1309
1310 printf("Number of FunctionCode CodeBlocks: %zu (%.3f%%)\n", isFunctionCode, static_cast<double>(isFunctionCode) * 100.0 / liveCodeBlockSet.size());
1311 printf("Number of GlobalCode CodeBlocks: %zu (%.3f%%)\n", isGlobalCode, static_cast<double>(isGlobalCode) * 100.0 / liveCodeBlockSet.size());
1312 printf("Number of EvalCode CodeBlocks: %zu (%.3f%%)\n", isEvalCode, static_cast<double>(isEvalCode) * 100.0 / liveCodeBlockSet.size());
1313
1314 printf("Number of CodeBlocks with exception info: %zu (%.3f%%)\n", hasExceptionInfo, static_cast<double>(hasExceptionInfo) * 100.0 / liveCodeBlockSet.size());
1315 printf("Number of CodeBlocks with rare data: %zu (%.3f%%)\n", hasRareData, static_cast<double>(hasRareData) * 100.0 / liveCodeBlockSet.size());
1316
1317 #define PRINT_STATS(name) printf("Number of CodeBlocks with " #name ": %zu\n", name##IsNotEmpty); printf("Size of all " #name ": %zu\n", name##TotalSize);
1318 FOR_EACH_MEMBER_VECTOR(PRINT_STATS)
1319 FOR_EACH_MEMBER_VECTOR_RARE_DATA(PRINT_STATS)
1320 FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(PRINT_STATS)
1321 #undef PRINT_STATS
1322
1323 printf("Number of CodeBlocks with evalCodeCache: %zu\n", evalCodeCacheIsNotEmpty);
1324 printf("Number of CodeBlocks with symbolTable: %zu\n", symbolTableIsNotEmpty);
1325
1326 printf("Size of all symbolTables: %zu\n", symbolTableTotalSize);
1327
1328#else
1329 printf("Dumping CodeBlock statistics is not enabled.\n");
1330#endif
1331}
1332
f9bf01c6 1333CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, SymbolTable* symTab)
ba379fdc
A
1334 : m_numCalleeRegisters(0)
1335 , m_numVars(0)
1336 , m_numParameters(0)
f9bf01c6 1337 , m_ownerExecutable(ownerExecutable)
ba379fdc
A
1338 , m_globalData(0)
1339#ifndef NDEBUG
1340 , m_instructionCount(0)
1341#endif
f9bf01c6
A
1342 , m_needsFullScopeChain(ownerExecutable->needsActivation())
1343 , m_usesEval(ownerExecutable->usesEval())
4e4e5a6f 1344 , m_usesArguments(false)
9dae56ea
A
1345 , m_isNumericCompareFunction(false)
1346 , m_codeType(codeType)
1347 , m_source(sourceProvider)
1348 , m_sourceOffset(sourceOffset)
f9bf01c6 1349 , m_symbolTable(symTab)
9dae56ea
A
1350 , m_exceptionInfo(new ExceptionInfo)
1351{
1352 ASSERT(m_source);
1353
1354#if DUMP_CODE_BLOCK_STATISTICS
1355 liveCodeBlockSet.add(this);
1356#endif
1357}
1358
1359CodeBlock::~CodeBlock()
1360{
4e4e5a6f 1361#if ENABLE(INTERPRETER)
9dae56ea
A
1362 for (size_t size = m_globalResolveInstructions.size(), i = 0; i < size; ++i)
1363 derefStructures(&m_instructions[m_globalResolveInstructions[i]]);
1364
1365 for (size_t size = m_propertyAccessInstructions.size(), i = 0; i < size; ++i)
1366 derefStructures(&m_instructions[m_propertyAccessInstructions[i]]);
4e4e5a6f
A
1367#endif
1368#if ENABLE(JIT)
9dae56ea
A
1369 for (size_t size = m_globalResolveInfos.size(), i = 0; i < size; ++i) {
1370 if (m_globalResolveInfos[i].structure)
1371 m_globalResolveInfos[i].structure->deref();
1372 }
1373
1374 for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i)
1375 m_structureStubInfos[i].deref();
1376
1377 for (size_t size = m_callLinkInfos.size(), i = 0; i < size; ++i) {
1378 CallLinkInfo* callLinkInfo = &m_callLinkInfos[i];
1379 if (callLinkInfo->isLinked())
1380 callLinkInfo->callee->removeCaller(callLinkInfo);
1381 }
1382
ba379fdc
A
1383 for (size_t size = m_methodCallLinkInfos.size(), i = 0; i < size; ++i) {
1384 if (Structure* structure = m_methodCallLinkInfos[i].cachedStructure) {
1385 structure->deref();
1386 // Both members must be filled at the same time
f9bf01c6 1387 ASSERT(!!m_methodCallLinkInfos[i].cachedPrototypeStructure);
ba379fdc
A
1388 m_methodCallLinkInfos[i].cachedPrototypeStructure->deref();
1389 }
1390 }
1391
1392#if ENABLE(JIT_OPTIMIZE_CALL)
9dae56ea
A
1393 unlinkCallers();
1394#endif
1395
4e4e5a6f 1396#endif // ENABLE(JIT)
ba379fdc 1397
9dae56ea
A
1398#if DUMP_CODE_BLOCK_STATISTICS
1399 liveCodeBlockSet.remove(this);
1400#endif
1401}
1402
ba379fdc 1403#if ENABLE(JIT_OPTIMIZE_CALL)
9dae56ea
A
1404void CodeBlock::unlinkCallers()
1405{
1406 size_t size = m_linkedCallerList.size();
1407 for (size_t i = 0; i < size; ++i) {
1408 CallLinkInfo* currentCaller = m_linkedCallerList[i];
1409 JIT::unlinkCall(currentCaller);
1410 currentCaller->setUnlinked();
1411 }
1412 m_linkedCallerList.clear();
1413}
1414#endif
1415
1416void CodeBlock::derefStructures(Instruction* vPC) const
1417{
1418 Interpreter* interpreter = m_globalData->interpreter;
1419
4e4e5a6f 1420 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)) {
9dae56ea
A
1421 vPC[4].u.structure->deref();
1422 return;
1423 }
4e4e5a6f 1424 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)) {
9dae56ea
A
1425 vPC[4].u.structure->deref();
1426 vPC[5].u.structure->deref();
1427 return;
1428 }
4e4e5a6f 1429 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)) {
9dae56ea
A
1430 vPC[4].u.structure->deref();
1431 vPC[5].u.structureChain->deref();
1432 return;
1433 }
1434 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) {
1435 vPC[4].u.structure->deref();
1436 vPC[5].u.structure->deref();
1437 vPC[6].u.structureChain->deref();
1438 return;
1439 }
1440 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) {
1441 vPC[4].u.structure->deref();
1442 return;
1443 }
4e4e5a6f 1444 if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global) || vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) {
9dae56ea
A
1445 if(vPC[4].u.structure)
1446 vPC[4].u.structure->deref();
1447 return;
1448 }
1449 if ((vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto_list))
4e4e5a6f
A
1450 || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self_list))
1451 || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_proto_list))
1452 || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_self_list))
1453 || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_proto_list))
1454 || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_self_list))) {
9dae56ea
A
1455 PolymorphicAccessStructureList* polymorphicStructures = vPC[4].u.polymorphicStructures;
1456 polymorphicStructures->derefStructures(vPC[5].u.operand);
1457 delete polymorphicStructures;
1458 return;
1459 }
1460
1461 // These instructions don't ref their Structures.
1462 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));
1463}
1464
1465void CodeBlock::refStructures(Instruction* vPC) const
1466{
1467 Interpreter* interpreter = m_globalData->interpreter;
1468
4e4e5a6f 1469 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)) {
9dae56ea
A
1470 vPC[4].u.structure->ref();
1471 return;
1472 }
4e4e5a6f 1473 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)) {
9dae56ea
A
1474 vPC[4].u.structure->ref();
1475 vPC[5].u.structure->ref();
1476 return;
1477 }
4e4e5a6f 1478 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)) {
9dae56ea
A
1479 vPC[4].u.structure->ref();
1480 vPC[5].u.structureChain->ref();
1481 return;
1482 }
1483 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) {
1484 vPC[4].u.structure->ref();
1485 vPC[5].u.structure->ref();
1486 vPC[6].u.structureChain->ref();
1487 return;
1488 }
1489 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) {
1490 vPC[4].u.structure->ref();
1491 return;
1492 }
1493
1494 // These instructions don't ref their Structures.
1495 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));
1496}
1497
f9bf01c6 1498void CodeBlock::markAggregate(MarkStack& markStack)
9dae56ea
A
1499{
1500 for (size_t i = 0; i < m_constantRegisters.size(); ++i)
f9bf01c6
A
1501 markStack.append(m_constantRegisters[i].jsValue());
1502 for (size_t i = 0; i < m_functionExprs.size(); ++i)
1503 m_functionExprs[i]->markAggregate(markStack);
1504 for (size_t i = 0; i < m_functionDecls.size(); ++i)
1505 m_functionDecls[i]->markAggregate(markStack);
9dae56ea
A
1506}
1507
1508void CodeBlock::reparseForExceptionInfoIfNecessary(CallFrame* callFrame)
1509{
1510 if (m_exceptionInfo)
1511 return;
1512
1513 ScopeChainNode* scopeChain = callFrame->scopeChain();
1514 if (m_needsFullScopeChain) {
1515 ScopeChain sc(scopeChain);
1516 int scopeDelta = sc.localDepth();
1517 if (m_codeType == EvalCode)
1518 scopeDelta -= static_cast<EvalCodeBlock*>(this)->baseScopeDepth();
1519 else if (m_codeType == FunctionCode)
1520 scopeDelta++; // Compilation of function code assumes activation is not on the scope chain yet.
1521 ASSERT(scopeDelta >= 0);
1522 while (scopeDelta--)
1523 scopeChain = scopeChain->next;
1524 }
1525
f9bf01c6 1526 m_exceptionInfo.set(m_ownerExecutable->reparseExceptionInfo(m_globalData, scopeChain, this));
9dae56ea
A
1527}
1528
1529HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset)
1530{
1531 ASSERT(bytecodeOffset < m_instructionCount);
1532
1533 if (!m_rareData)
1534 return 0;
1535
1536 Vector<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers;
1537 for (size_t i = 0; i < exceptionHandlers.size(); ++i) {
1538 // Handlers are ordered innermost first, so the first handler we encounter
1539 // that contains the source address is the correct handler to use.
1540 if (exceptionHandlers[i].start <= bytecodeOffset && exceptionHandlers[i].end >= bytecodeOffset)
1541 return &exceptionHandlers[i];
1542 }
1543
1544 return 0;
1545}
1546
1547int CodeBlock::lineNumberForBytecodeOffset(CallFrame* callFrame, unsigned bytecodeOffset)
1548{
1549 ASSERT(bytecodeOffset < m_instructionCount);
1550
1551 reparseForExceptionInfoIfNecessary(callFrame);
1552 ASSERT(m_exceptionInfo);
1553
1554 if (!m_exceptionInfo->m_lineInfo.size())
f9bf01c6 1555 return m_ownerExecutable->source().firstLine(); // Empty function
9dae56ea
A
1556
1557 int low = 0;
1558 int high = m_exceptionInfo->m_lineInfo.size();
1559 while (low < high) {
1560 int mid = low + (high - low) / 2;
1561 if (m_exceptionInfo->m_lineInfo[mid].instructionOffset <= bytecodeOffset)
1562 low = mid + 1;
1563 else
1564 high = mid;
1565 }
1566
1567 if (!low)
f9bf01c6 1568 return m_ownerExecutable->source().firstLine();
9dae56ea
A
1569 return m_exceptionInfo->m_lineInfo[low - 1].lineNumber;
1570}
1571
1572int CodeBlock::expressionRangeForBytecodeOffset(CallFrame* callFrame, unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset)
1573{
1574 ASSERT(bytecodeOffset < m_instructionCount);
1575
1576 reparseForExceptionInfoIfNecessary(callFrame);
1577 ASSERT(m_exceptionInfo);
1578
1579 if (!m_exceptionInfo->m_expressionInfo.size()) {
1580 // We didn't think anything could throw. Apparently we were wrong.
1581 startOffset = 0;
1582 endOffset = 0;
1583 divot = 0;
1584 return lineNumberForBytecodeOffset(callFrame, bytecodeOffset);
1585 }
1586
1587 int low = 0;
1588 int high = m_exceptionInfo->m_expressionInfo.size();
1589 while (low < high) {
1590 int mid = low + (high - low) / 2;
1591 if (m_exceptionInfo->m_expressionInfo[mid].instructionOffset <= bytecodeOffset)
1592 low = mid + 1;
1593 else
1594 high = mid;
1595 }
1596
1597 ASSERT(low);
1598 if (!low) {
1599 startOffset = 0;
1600 endOffset = 0;
1601 divot = 0;
1602 return lineNumberForBytecodeOffset(callFrame, bytecodeOffset);
1603 }
1604
1605 startOffset = m_exceptionInfo->m_expressionInfo[low - 1].startOffset;
1606 endOffset = m_exceptionInfo->m_expressionInfo[low - 1].endOffset;
1607 divot = m_exceptionInfo->m_expressionInfo[low - 1].divotPoint + m_sourceOffset;
1608 return lineNumberForBytecodeOffset(callFrame, bytecodeOffset);
1609}
1610
1611bool CodeBlock::getByIdExceptionInfoForBytecodeOffset(CallFrame* callFrame, unsigned bytecodeOffset, OpcodeID& opcodeID)
1612{
1613 ASSERT(bytecodeOffset < m_instructionCount);
1614
1615 reparseForExceptionInfoIfNecessary(callFrame);
1616 ASSERT(m_exceptionInfo);
1617
1618 if (!m_exceptionInfo->m_getByIdExceptionInfo.size())
1619 return false;
1620
1621 int low = 0;
1622 int high = m_exceptionInfo->m_getByIdExceptionInfo.size();
1623 while (low < high) {
1624 int mid = low + (high - low) / 2;
1625 if (m_exceptionInfo->m_getByIdExceptionInfo[mid].bytecodeOffset <= bytecodeOffset)
1626 low = mid + 1;
1627 else
1628 high = mid;
1629 }
1630
1631 if (!low || m_exceptionInfo->m_getByIdExceptionInfo[low - 1].bytecodeOffset != bytecodeOffset)
1632 return false;
1633
1634 opcodeID = m_exceptionInfo->m_getByIdExceptionInfo[low - 1].isOpConstruct ? op_construct : op_instanceof;
1635 return true;
1636}
1637
1638#if ENABLE(JIT)
1639bool CodeBlock::functionRegisterForBytecodeOffset(unsigned bytecodeOffset, int& functionRegisterIndex)
1640{
1641 ASSERT(bytecodeOffset < m_instructionCount);
1642
1643 if (!m_rareData || !m_rareData->m_functionRegisterInfos.size())
1644 return false;
1645
1646 int low = 0;
1647 int high = m_rareData->m_functionRegisterInfos.size();
1648 while (low < high) {
1649 int mid = low + (high - low) / 2;
1650 if (m_rareData->m_functionRegisterInfos[mid].bytecodeOffset <= bytecodeOffset)
1651 low = mid + 1;
1652 else
1653 high = mid;
1654 }
1655
1656 if (!low || m_rareData->m_functionRegisterInfos[low - 1].bytecodeOffset != bytecodeOffset)
1657 return false;
1658
1659 functionRegisterIndex = m_rareData->m_functionRegisterInfos[low - 1].functionRegisterIndex;
1660 return true;
1661}
1662#endif
1663
4e4e5a6f 1664#if ENABLE(INTERPRETER)
9dae56ea
A
1665bool CodeBlock::hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset)
1666{
1667 if (m_globalResolveInstructions.isEmpty())
1668 return false;
1669
1670 int low = 0;
1671 int high = m_globalResolveInstructions.size();
1672 while (low < high) {
1673 int mid = low + (high - low) / 2;
1674 if (m_globalResolveInstructions[mid] <= bytecodeOffset)
1675 low = mid + 1;
1676 else
1677 high = mid;
1678 }
1679
1680 if (!low || m_globalResolveInstructions[low - 1] != bytecodeOffset)
1681 return false;
1682 return true;
1683}
4e4e5a6f
A
1684#endif
1685#if ENABLE(JIT)
9dae56ea
A
1686bool CodeBlock::hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset)
1687{
1688 if (m_globalResolveInfos.isEmpty())
1689 return false;
1690
1691 int low = 0;
1692 int high = m_globalResolveInfos.size();
1693 while (low < high) {
1694 int mid = low + (high - low) / 2;
1695 if (m_globalResolveInfos[mid].bytecodeOffset <= bytecodeOffset)
1696 low = mid + 1;
1697 else
1698 high = mid;
1699 }
1700
1701 if (!low || m_globalResolveInfos[low - 1].bytecodeOffset != bytecodeOffset)
1702 return false;
1703 return true;
1704}
1705#endif
1706
9dae56ea
A
1707void CodeBlock::shrinkToFit()
1708{
1709 m_instructions.shrinkToFit();
1710
4e4e5a6f 1711#if ENABLE(INTERPRETER)
9dae56ea
A
1712 m_propertyAccessInstructions.shrinkToFit();
1713 m_globalResolveInstructions.shrinkToFit();
4e4e5a6f
A
1714#endif
1715#if ENABLE(JIT)
9dae56ea
A
1716 m_structureStubInfos.shrinkToFit();
1717 m_globalResolveInfos.shrinkToFit();
1718 m_callLinkInfos.shrinkToFit();
1719 m_linkedCallerList.shrinkToFit();
1720#endif
1721
1722 m_identifiers.shrinkToFit();
f9bf01c6
A
1723 m_functionDecls.shrinkToFit();
1724 m_functionExprs.shrinkToFit();
9dae56ea
A
1725 m_constantRegisters.shrinkToFit();
1726
1727 if (m_exceptionInfo) {
1728 m_exceptionInfo->m_expressionInfo.shrinkToFit();
1729 m_exceptionInfo->m_lineInfo.shrinkToFit();
1730 m_exceptionInfo->m_getByIdExceptionInfo.shrinkToFit();
1731 }
1732
1733 if (m_rareData) {
1734 m_rareData->m_exceptionHandlers.shrinkToFit();
9dae56ea
A
1735 m_rareData->m_regexps.shrinkToFit();
1736 m_rareData->m_immediateSwitchJumpTables.shrinkToFit();
1737 m_rareData->m_characterSwitchJumpTables.shrinkToFit();
1738 m_rareData->m_stringSwitchJumpTables.shrinkToFit();
1739#if ENABLE(JIT)
1740 m_rareData->m_functionRegisterInfos.shrinkToFit();
1741#endif
1742 }
1743}
1744
1745} // namespace JSC