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

source code of qtscript/src/3rdparty/javascriptcore/JavaScriptCore/bytecode/CodeBlock.cpp