2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
31 #include "CodeBlock.h"
35 #include "Interpreter.h"
36 #include "JSFunction.h"
37 #include "JSStaticScopeObject.h"
39 #include "BytecodeGenerator.h"
41 #include <wtf/StringExtras.h>
43 #define DUMP_CODE_BLOCK_STATISTICS 0
47 #if !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING)
49 static UString
escapeQuotes(const UString
& str
)
53 while ((pos
= result
.find('\"', pos
)) >= 0) {
54 result
= makeString(result
.substr(0, pos
), "\"\\\"\"", result
.substr(pos
+ 1));
60 static UString
valueToSourceString(ExecState
* exec
, JSValue val
)
66 return makeString("\"", escapeQuotes(val
.toString(exec
)), "\"");
68 return val
.toString(exec
);
71 static CString
constantName(ExecState
* exec
, int k
, JSValue value
)
73 return makeString(valueToSourceString(exec
, value
), "(@k", UString::from(k
- FirstConstantRegisterIndex
), ")").UTF8String();
76 static CString
idName(int id0
, const Identifier
& ident
)
78 return makeString(ident
.ustring(), "(@id", UString::from(id0
), ")").UTF8String();
81 CString
CodeBlock::registerName(ExecState
* exec
, int r
) const
83 if (r
== missingThisObjectMarker())
86 if (isConstantRegisterIndex(r
))
87 return constantName(exec
, r
, getConstant(r
));
89 return makeString("r", UString::from(r
)).UTF8String();
92 static UString
regexpToSourceString(RegExp
* regExp
)
94 char postfix
[5] = { '/', 0, 0, 0, 0 };
97 postfix
[index
++] = 'g';
98 if (regExp
->ignoreCase())
99 postfix
[index
++] = 'i';
100 if (regExp
->multiline())
101 postfix
[index
] = 'm';
103 return makeString("/", regExp
->pattern(), postfix
);
106 static CString
regexpName(int re
, RegExp
* regexp
)
108 return makeString(regexpToSourceString(regexp
), "(@re", UString::from(re
), ")").UTF8String();
111 static UString
pointerToSourceString(void* p
)
113 char buffer
[2 + 2 * sizeof(void*) + 1]; // 0x [two characters per byte] \0
114 snprintf(buffer
, sizeof(buffer
), "%p", p
);
118 NEVER_INLINE
static const char* debugHookName(int debugHookID
)
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";
135 ASSERT_NOT_REACHED();
139 void CodeBlock::printUnaryOp(ExecState
* exec
, int location
, Vector
<Instruction
>::const_iterator
& it
, const char* op
) const
141 int r0
= (++it
)->u
.operand
;
142 int r1
= (++it
)->u
.operand
;
144 printf("[%4d] %s\t\t %s, %s\n", location
, op
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str());
147 void CodeBlock::printBinaryOp(ExecState
* exec
, int location
, Vector
<Instruction
>::const_iterator
& it
, const char* op
) const
149 int r0
= (++it
)->u
.operand
;
150 int r1
= (++it
)->u
.operand
;
151 int r2
= (++it
)->u
.operand
;
152 printf("[%4d] %s\t\t %s, %s, %s\n", location
, op
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), registerName(exec
, r2
).c_str());
155 void CodeBlock::printConditionalJump(ExecState
* exec
, const Vector
<Instruction
>::const_iterator
&, Vector
<Instruction
>::const_iterator
& it
, int location
, const char* op
) const
157 int r0
= (++it
)->u
.operand
;
158 int offset
= (++it
)->u
.operand
;
159 printf("[%4d] %s\t\t %s, %d(->%d)\n", location
, op
, registerName(exec
, r0
).c_str(), offset
, location
+ offset
);
162 void CodeBlock::printGetByIdOp(ExecState
* exec
, int location
, Vector
<Instruction
>::const_iterator
& it
, const char* op
) const
164 int r0
= (++it
)->u
.operand
;
165 int r1
= (++it
)->u
.operand
;
166 int id0
= (++it
)->u
.operand
;
167 printf("[%4d] %s\t %s, %s, %s\n", location
, op
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str());
171 void CodeBlock::printPutByIdOp(ExecState
* exec
, int location
, Vector
<Instruction
>::const_iterator
& it
, const char* op
) const
173 int r0
= (++it
)->u
.operand
;
174 int id0
= (++it
)->u
.operand
;
175 int r1
= (++it
)->u
.operand
;
176 printf("[%4d] %s\t %s, %s, %s\n", location
, op
, registerName(exec
, r0
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str(), registerName(exec
, r1
).c_str());
181 static bool isGlobalResolve(OpcodeID opcodeID
)
183 return opcodeID
== op_resolve_global
;
186 static bool isPropertyAccess(OpcodeID 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
:
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
:
208 static unsigned instructionOffsetForNth(ExecState
* exec
, const Vector
<Instruction
>& instructions
, int nth
, bool (*predicate
)(OpcodeID
))
211 while (i
< instructions
.size()) {
212 OpcodeID currentOpcode
= exec
->interpreter()->getOpcodeID(instructions
[i
].u
.opcode
);
213 if (predicate(currentOpcode
)) {
217 i
+= opcodeLengths
[currentOpcode
];
220 ASSERT_NOT_REACHED();
224 static void printGlobalResolveInfo(const GlobalResolveInfo
& resolveInfo
, unsigned instructionOffset
)
226 printf(" [%4d] %s: %s\n", instructionOffset
, "resolve_global", pointerToSourceString(resolveInfo
.structure
).UTF8String().c_str());
229 static void printStructureStubInfo(const StructureStubInfo
& stubInfo
, unsigned instructionOffset
)
231 switch (stubInfo
.accessType
) {
232 case access_get_by_id_self
:
233 printf(" [%4d] %s: %s\n", instructionOffset
, "get_by_id_self", pointerToSourceString(stubInfo
.u
.getByIdSelf
.baseObjectStructure
).UTF8String().c_str());
235 case access_get_by_id_proto
:
236 printf(" [%4d] %s: %s, %s\n", instructionOffset
, "get_by_id_proto", pointerToSourceString(stubInfo
.u
.getByIdProto
.baseObjectStructure
).UTF8String().c_str(), pointerToSourceString(stubInfo
.u
.getByIdProto
.prototypeStructure
).UTF8String().c_str());
238 case access_get_by_id_chain
:
239 printf(" [%4d] %s: %s, %s\n", instructionOffset
, "get_by_id_chain", pointerToSourceString(stubInfo
.u
.getByIdChain
.baseObjectStructure
).UTF8String().c_str(), pointerToSourceString(stubInfo
.u
.getByIdChain
.chain
).UTF8String().c_str());
241 case access_get_by_id_self_list
:
242 printf(" [%4d] %s: %s (%d)\n", instructionOffset
, "op_get_by_id_self_list", pointerToSourceString(stubInfo
.u
.getByIdSelfList
.structureList
).UTF8String().c_str(), stubInfo
.u
.getByIdSelfList
.listSize
);
244 case access_get_by_id_proto_list
:
245 printf(" [%4d] %s: %s (%d)\n", instructionOffset
, "op_get_by_id_proto_list", pointerToSourceString(stubInfo
.u
.getByIdProtoList
.structureList
).UTF8String().c_str(), stubInfo
.u
.getByIdProtoList
.listSize
);
247 case access_put_by_id_transition
:
248 printf(" [%4d] %s: %s, %s, %s\n", instructionOffset
, "put_by_id_transition", pointerToSourceString(stubInfo
.u
.putByIdTransition
.previousStructure
).UTF8String().c_str(), pointerToSourceString(stubInfo
.u
.putByIdTransition
.structure
).UTF8String().c_str(), pointerToSourceString(stubInfo
.u
.putByIdTransition
.chain
).UTF8String().c_str());
250 case access_put_by_id_replace
:
251 printf(" [%4d] %s: %s\n", instructionOffset
, "put_by_id_replace", pointerToSourceString(stubInfo
.u
.putByIdReplace
.baseObjectStructure
).UTF8String().c_str());
253 case access_get_by_id
:
254 printf(" [%4d] %s\n", instructionOffset
, "get_by_id");
256 case access_put_by_id
:
257 printf(" [%4d] %s\n", instructionOffset
, "put_by_id");
259 case access_get_by_id_generic
:
260 printf(" [%4d] %s\n", instructionOffset
, "op_get_by_id_generic");
262 case access_put_by_id_generic
:
263 printf(" [%4d] %s\n", instructionOffset
, "op_put_by_id_generic");
265 case access_get_array_length
:
266 printf(" [%4d] %s\n", instructionOffset
, "op_get_array_length");
268 case access_get_string_length
:
269 printf(" [%4d] %s\n", instructionOffset
, "op_get_string_length");
272 ASSERT_NOT_REACHED();
277 void CodeBlock::printStructure(const char* name
, const Instruction
* vPC
, int operand
) const
279 unsigned instructionOffset
= vPC
- m_instructions
.begin();
280 printf(" [%4d] %s: %s\n", instructionOffset
, name
, pointerToSourceString(vPC
[operand
].u
.structure
).UTF8String().c_str());
283 void CodeBlock::printStructures(const Instruction
* vPC
) const
285 Interpreter
* interpreter
= m_globalData
->interpreter
;
286 unsigned instructionOffset
= vPC
- m_instructions
.begin();
288 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id
)) {
289 printStructure("get_by_id", vPC
, 4);
292 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_self
)) {
293 printStructure("get_by_id_self", vPC
, 4);
296 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_proto
)) {
297 printf(" [%4d] %s: %s, %s\n", instructionOffset
, "get_by_id_proto", pointerToSourceString(vPC
[4].u
.structure
).UTF8String().c_str(), pointerToSourceString(vPC
[5].u
.structure
).UTF8String().c_str());
300 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_put_by_id_transition
)) {
301 printf(" [%4d] %s: %s, %s, %s\n", instructionOffset
, "put_by_id_transition", pointerToSourceString(vPC
[4].u
.structure
).UTF8String().c_str(), pointerToSourceString(vPC
[5].u
.structure
).UTF8String().c_str(), pointerToSourceString(vPC
[6].u
.structureChain
).UTF8String().c_str());
304 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_chain
)) {
305 printf(" [%4d] %s: %s, %s\n", instructionOffset
, "get_by_id_chain", pointerToSourceString(vPC
[4].u
.structure
).UTF8String().c_str(), pointerToSourceString(vPC
[5].u
.structureChain
).UTF8String().c_str());
308 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_put_by_id
)) {
309 printStructure("put_by_id", vPC
, 4);
312 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_put_by_id_replace
)) {
313 printStructure("put_by_id_replace", vPC
, 4);
316 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_resolve_global
)) {
317 printStructure("resolve_global", vPC
, 4);
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
));
325 void CodeBlock::dump(ExecState
* exec
) const
327 if (m_instructions
.isEmpty()) {
328 printf("No instructions available.\n");
332 size_t instructionCount
= 0;
334 for (size_t i
= 0; i
< m_instructions
.size(); i
+= opcodeLengths
[exec
->interpreter()->getOpcodeID(m_instructions
[i
].u
.opcode
)])
337 printf("%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
);
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
);
347 if (!m_identifiers
.isEmpty()) {
348 printf("\nIdentifiers:\n");
351 printf(" id%u = %s\n", static_cast<unsigned>(i
), m_identifiers
[i
].ascii());
353 } while (i
!= m_identifiers
.size());
356 if (!m_constantRegisters
.isEmpty()) {
357 printf("\nConstants:\n");
358 unsigned registerIndex
= m_numVars
;
361 printf(" k%u = %s\n", registerIndex
, valueToSourceString(exec
, m_constantRegisters
[i
].jsValue()).ascii());
364 } while (i
< m_constantRegisters
.size());
367 if (m_rareData
&& !m_rareData
->m_regexps
.isEmpty()) {
368 printf("\nm_regexps:\n");
371 printf(" re%u = %s\n", static_cast<unsigned>(i
), regexpToSourceString(m_rareData
->m_regexps
[i
].get()).ascii());
373 } while (i
< m_rareData
->m_regexps
.size());
377 if (!m_globalResolveInfos
.isEmpty() || !m_structureStubInfos
.isEmpty())
378 printf("\nStructures:\n");
380 if (!m_globalResolveInfos
.isEmpty()) {
383 printGlobalResolveInfo(m_globalResolveInfos
[i
], instructionOffsetForNth(exec
, m_instructions
, i
+ 1, isGlobalResolve
));
385 } while (i
< m_globalResolveInfos
.size());
387 if (!m_structureStubInfos
.isEmpty()) {
390 printStructureStubInfo(m_structureStubInfos
[i
], instructionOffsetForNth(exec
, m_instructions
, i
+ 1, isPropertyAccess
));
392 } while (i
< m_structureStubInfos
.size());
395 if (!m_globalResolveInstructions
.isEmpty() || !m_propertyAccessInstructions
.isEmpty())
396 printf("\nStructures:\n");
398 if (!m_globalResolveInstructions
.isEmpty()) {
401 printStructures(&m_instructions
[m_globalResolveInstructions
[i
]]);
403 } while (i
< m_globalResolveInstructions
.size());
405 if (!m_propertyAccessInstructions
.isEmpty()) {
408 printStructures(&m_instructions
[m_propertyAccessInstructions
[i
]]);
410 } while (i
< m_propertyAccessInstructions
.size());
414 if (m_rareData
&& !m_rareData
->m_exceptionHandlers
.isEmpty()) {
415 printf("\nException Handlers:\n");
418 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
);
420 } while (i
< m_rareData
->m_exceptionHandlers
.size());
423 if (m_rareData
&& !m_rareData
->m_immediateSwitchJumpTables
.isEmpty()) {
424 printf("Immediate Switch Jump Tables:\n");
427 printf(" %1d = {\n", i
);
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
) {
433 printf("\t\t%4d => %04d\n", entry
+ m_rareData
->m_immediateSwitchJumpTables
[i
].min
, *iter
);
437 } while (i
< m_rareData
->m_immediateSwitchJumpTables
.size());
440 if (m_rareData
&& !m_rareData
->m_characterSwitchJumpTables
.isEmpty()) {
441 printf("\nCharacter Switch Jump Tables:\n");
444 printf(" %1d = {\n", i
);
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
) {
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("\t\t\"%s\" => %04d\n", UString(&ch
, 1).ascii(), *iter
);
456 } while (i
< m_rareData
->m_characterSwitchJumpTables
.size());
459 if (m_rareData
&& !m_rareData
->m_stringSwitchJumpTables
.isEmpty()) {
460 printf("\nString Switch Jump Tables:\n");
463 printf(" %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("\t\t\"%s\" => %04d\n", UString(iter
->first
).ascii(), iter
->second
.branchOffset
);
469 } while (i
< m_rareData
->m_stringSwitchJumpTables
.size());
475 void CodeBlock::dump(ExecState
* exec
, const Vector
<Instruction
>::const_iterator
& begin
, Vector
<Instruction
>::const_iterator
& it
) const
477 int location
= it
- begin
;
478 switch (exec
->interpreter()->getOpcodeID(it
->u
.opcode
)) {
480 printf("[%4d] enter\n", location
);
483 case op_enter_with_activation
: {
484 int r0
= (++it
)->u
.operand
;
485 printf("[%4d] enter_with_activation %s\n", location
, registerName(exec
, r0
).c_str());
488 case op_create_arguments
: {
489 printf("[%4d] create_arguments\n", location
);
492 case op_init_arguments
: {
493 printf("[%4d] init_arguments\n", location
);
496 case op_convert_this
: {
497 int r0
= (++it
)->u
.operand
;
498 printf("[%4d] convert_this %s\n", location
, registerName(exec
, r0
).c_str());
501 case op_new_object
: {
502 int r0
= (++it
)->u
.operand
;
503 printf("[%4d] new_object\t %s\n", location
, registerName(exec
, r0
).c_str());
507 int dst
= (++it
)->u
.operand
;
508 int argv
= (++it
)->u
.operand
;
509 int argc
= (++it
)->u
.operand
;
510 printf("[%4d] new_array\t %s, %s, %d\n", location
, registerName(exec
, dst
).c_str(), registerName(exec
, argv
).c_str(), argc
);
513 case op_new_regexp
: {
514 int r0
= (++it
)->u
.operand
;
515 int re0
= (++it
)->u
.operand
;
516 printf("[%4d] new_regexp\t %s, %s\n", location
, registerName(exec
, r0
).c_str(), regexpName(re0
, regexp(re0
)).c_str());
520 int r0
= (++it
)->u
.operand
;
521 int r1
= (++it
)->u
.operand
;
522 printf("[%4d] mov\t\t %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str());
526 printUnaryOp(exec
, location
, it
, "not");
530 printBinaryOp(exec
, location
, it
, "eq");
534 printUnaryOp(exec
, location
, it
, "eq_null");
538 printBinaryOp(exec
, location
, it
, "neq");
542 printUnaryOp(exec
, location
, it
, "neq_null");
546 printBinaryOp(exec
, location
, it
, "stricteq");
550 printBinaryOp(exec
, location
, it
, "nstricteq");
554 printBinaryOp(exec
, location
, it
, "less");
558 printBinaryOp(exec
, location
, it
, "lesseq");
562 int r0
= (++it
)->u
.operand
;
563 printf("[%4d] pre_inc\t\t %s\n", location
, registerName(exec
, r0
).c_str());
567 int r0
= (++it
)->u
.operand
;
568 printf("[%4d] pre_dec\t\t %s\n", location
, registerName(exec
, r0
).c_str());
572 printUnaryOp(exec
, location
, it
, "post_inc");
576 printUnaryOp(exec
, location
, it
, "post_dec");
579 case op_to_jsnumber
: {
580 printUnaryOp(exec
, location
, it
, "to_jsnumber");
584 printUnaryOp(exec
, location
, it
, "negate");
588 printBinaryOp(exec
, location
, it
, "add");
593 printBinaryOp(exec
, location
, it
, "mul");
598 printBinaryOp(exec
, location
, it
, "div");
603 printBinaryOp(exec
, location
, it
, "mod");
607 printBinaryOp(exec
, location
, it
, "sub");
612 printBinaryOp(exec
, location
, it
, "lshift");
616 printBinaryOp(exec
, location
, it
, "rshift");
620 printBinaryOp(exec
, location
, it
, "urshift");
624 printBinaryOp(exec
, location
, it
, "bitand");
629 printBinaryOp(exec
, location
, it
, "bitxor");
634 printBinaryOp(exec
, location
, it
, "bitor");
639 printUnaryOp(exec
, location
, it
, "bitnot");
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("[%4d] instanceof\t\t %s, %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), registerName(exec
, r2
).c_str(), registerName(exec
, r3
).c_str());
651 printUnaryOp(exec
, location
, it
, "typeof");
654 case op_is_undefined
: {
655 printUnaryOp(exec
, location
, it
, "is_undefined");
658 case op_is_boolean
: {
659 printUnaryOp(exec
, location
, it
, "is_boolean");
663 printUnaryOp(exec
, location
, it
, "is_number");
667 printUnaryOp(exec
, location
, it
, "is_string");
671 printUnaryOp(exec
, location
, it
, "is_object");
674 case op_is_function
: {
675 printUnaryOp(exec
, location
, it
, "is_function");
679 printBinaryOp(exec
, location
, it
, "in");
683 int r0
= (++it
)->u
.operand
;
684 int id0
= (++it
)->u
.operand
;
685 printf("[%4d] resolve\t\t %s, %s\n", location
, registerName(exec
, r0
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str());
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("[%4d] resolve_skip\t %s, %s, %d\n", location
, registerName(exec
, r0
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str(), skipLevels
);
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("[%4d] resolve_global\t %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), valueToSourceString(exec
, scope
).ascii(), idName(id0
, m_identifiers
[id0
]).c_str());
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("[%4d] get_scoped_var\t %s, %d, %d\n", location
, registerName(exec
, r0
).c_str(), index
, skipLevels
);
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("[%4d] put_scoped_var\t %d, %d, %s\n", location
, index
, skipLevels
, registerName(exec
, r0
).c_str());
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("[%4d] get_global_var\t %s, %s, %d\n", location
, registerName(exec
, r0
).c_str(), valueToSourceString(exec
, scope
).ascii(), index
);
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("[%4d] put_global_var\t %s, %d, %s\n", location
, valueToSourceString(exec
, scope
).ascii(), index
, registerName(exec
, r0
).c_str());
731 case op_resolve_base
: {
732 int r0
= (++it
)->u
.operand
;
733 int id0
= (++it
)->u
.operand
;
734 printf("[%4d] resolve_base\t %s, %s\n", location
, registerName(exec
, r0
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str());
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("[%4d] resolve_with_base %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str());
745 printGetByIdOp(exec
, location
, it
, "get_by_id");
748 case op_get_by_id_self
: {
749 printGetByIdOp(exec
, location
, it
, "get_by_id_self");
752 case op_get_by_id_self_list
: {
753 printGetByIdOp(exec
, location
, it
, "get_by_id_self_list");
756 case op_get_by_id_proto
: {
757 printGetByIdOp(exec
, location
, it
, "get_by_id_proto");
760 case op_get_by_id_proto_list
: {
761 printGetByIdOp(exec
, location
, it
, "op_get_by_id_proto_list");
764 case op_get_by_id_chain
: {
765 printGetByIdOp(exec
, location
, it
, "get_by_id_chain");
768 case op_get_by_id_generic
: {
769 printGetByIdOp(exec
, location
, it
, "get_by_id_generic");
772 case op_get_array_length
: {
773 printGetByIdOp(exec
, location
, it
, "get_array_length");
776 case op_get_string_length
: {
777 printGetByIdOp(exec
, location
, it
, "get_string_length");
781 printPutByIdOp(exec
, location
, it
, "put_by_id");
784 case op_put_by_id_replace
: {
785 printPutByIdOp(exec
, location
, it
, "put_by_id_replace");
788 case op_put_by_id_transition
: {
789 printPutByIdOp(exec
, location
, it
, "put_by_id_transition");
792 case op_put_by_id_generic
: {
793 printPutByIdOp(exec
, location
, it
, "put_by_id_generic");
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("[%4d] put_getter\t %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str(), registerName(exec
, r1
).c_str());
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("[%4d] put_setter\t %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str(), registerName(exec
, r1
).c_str());
810 case op_method_check
: {
811 printf("[%4d] method_check\n", location
);
815 int r0
= (++it
)->u
.operand
;
816 int r1
= (++it
)->u
.operand
;
817 int id0
= (++it
)->u
.operand
;
818 printf("[%4d] del_by_id\t %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str());
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("[%4d] get_by_val\t %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), registerName(exec
, r2
).c_str());
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("[%4d] get_by_pname\t %s, %s, %s, %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), registerName(exec
, r2
).c_str(), registerName(exec
, r3
).c_str(), registerName(exec
, r4
).c_str(), registerName(exec
, r5
).c_str());
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("[%4d] put_by_val\t %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), registerName(exec
, r2
).c_str());
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("[%4d] del_by_val\t %s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), registerName(exec
, r2
).c_str());
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("[%4d] put_by_index\t %s, %u, %s\n", location
, registerName(exec
, r0
).c_str(), n0
, registerName(exec
, r1
).c_str());
860 int offset
= (++it
)->u
.operand
;
861 printf("[%4d] jmp\t\t %d(->%d)\n", location
, offset
, location
+ offset
);
865 int offset
= (++it
)->u
.operand
;
866 printf("[%4d] loop\t\t %d(->%d)\n", location
, offset
, location
+ offset
);
870 printConditionalJump(exec
, begin
, it
, location
, "jtrue");
873 case op_loop_if_true
: {
874 printConditionalJump(exec
, begin
, it
, location
, "loop_if_true");
877 case op_loop_if_false
: {
878 printConditionalJump(exec
, begin
, it
, location
, "loop_if_false");
882 printConditionalJump(exec
, begin
, it
, location
, "jfalse");
886 printConditionalJump(exec
, begin
, it
, location
, "jeq_null");
890 printConditionalJump(exec
, begin
, it
, location
, "jneq_null");
894 int r0
= (++it
)->u
.operand
;
895 int r1
= (++it
)->u
.operand
;
896 int offset
= (++it
)->u
.operand
;
897 printf("[%4d] jneq_ptr\t\t %s, %s, %d(->%d)\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), offset
, location
+ offset
);
901 int r0
= (++it
)->u
.operand
;
902 int r1
= (++it
)->u
.operand
;
903 int offset
= (++it
)->u
.operand
;
904 printf("[%4d] jnless\t\t %s, %s, %d(->%d)\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), offset
, location
+ offset
);
908 int r0
= (++it
)->u
.operand
;
909 int r1
= (++it
)->u
.operand
;
910 int offset
= (++it
)->u
.operand
;
911 printf("[%4d] jnlesseq\t\t %s, %s, %d(->%d)\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), offset
, location
+ offset
);
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("[%4d] loop_if_less\t %s, %s, %d(->%d)\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), offset
, location
+ offset
);
922 int r0
= (++it
)->u
.operand
;
923 int r1
= (++it
)->u
.operand
;
924 int offset
= (++it
)->u
.operand
;
925 printf("[%4d] jless\t\t %s, %s, %d(->%d)\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), offset
, location
+ offset
);
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("[%4d] loop_if_lesseq\t %s, %s, %d(->%d)\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), offset
, location
+ offset
);
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("[%4d] switch_imm\t %d, %d(->%d), %s\n", location
, tableIndex
, defaultTarget
, location
+ defaultTarget
, registerName(exec
, scrutineeRegister
).c_str());
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("[%4d] switch_char\t %d, %d(->%d), %s\n", location
, tableIndex
, defaultTarget
, location
+ defaultTarget
, registerName(exec
, scrutineeRegister
).c_str());
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("[%4d] switch_string\t %d, %d(->%d), %s\n", location
, tableIndex
, defaultTarget
, location
+ defaultTarget
, registerName(exec
, scrutineeRegister
).c_str());
957 int r0
= (++it
)->u
.operand
;
958 int f0
= (++it
)->u
.operand
;
959 printf("[%4d] new_func\t\t %s, f%d\n", location
, registerName(exec
, r0
).c_str(), f0
);
962 case op_new_func_exp
: {
963 int r0
= (++it
)->u
.operand
;
964 int f0
= (++it
)->u
.operand
;
965 printf("[%4d] new_func_exp\t %s, f%d\n", location
, registerName(exec
, r0
).c_str(), f0
);
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("[%4d] call\t\t %s, %s, %d, %d\n", location
, registerName(exec
, dst
).c_str(), registerName(exec
, func
).c_str(), argCount
, registerOffset
);
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("[%4d] call_eval\t %s, %s, %d, %d\n", location
, registerName(exec
, dst
).c_str(), registerName(exec
, func
).c_str(), argCount
, registerOffset
);
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("[%4d] call_varargs\t %s, %s, %s, %d\n", location
, registerName(exec
, dst
).c_str(), registerName(exec
, func
).c_str(), registerName(exec
, argCount
).c_str(), registerOffset
);
992 case op_load_varargs
: {
993 printUnaryOp(exec
, location
, it
, "load_varargs");
996 case op_tear_off_activation
: {
997 int r0
= (++it
)->u
.operand
;
998 printf("[%4d] tear_off_activation\t %s\n", location
, registerName(exec
, r0
).c_str());
1001 case op_tear_off_arguments
: {
1002 printf("[%4d] tear_off_arguments\n", location
);
1006 int r0
= (++it
)->u
.operand
;
1007 printf("[%4d] ret\t\t %s\n", location
, registerName(exec
, r0
).c_str());
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("[%4d] construct\t %s, %s, %d, %d, %s, %s\n", location
, registerName(exec
, dst
).c_str(), registerName(exec
, func
).c_str(), argCount
, registerOffset
, registerName(exec
, proto
).c_str(), registerName(exec
, thisRegister
).c_str());
1020 case op_construct_verify
: {
1021 int r0
= (++it
)->u
.operand
;
1022 int r1
= (++it
)->u
.operand
;
1023 printf("[%4d] construct_verify\t %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str());
1027 int r0
= (++it
)->u
.operand
;
1028 int r1
= (++it
)->u
.operand
;
1029 int count
= (++it
)->u
.operand
;
1030 printf("[%4d] strcat\t\t %s, %s, %d\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), count
);
1033 case op_to_primitive
: {
1034 int r0
= (++it
)->u
.operand
;
1035 int r1
= (++it
)->u
.operand
;
1036 printf("[%4d] to_primitive\t %s, %s\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str());
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("[%4d] get_pnames\t %s, %s, %s, %s, %d(->%d)\n", location
, registerName(exec
, r0
).c_str(), registerName(exec
, r1
).c_str(), registerName(exec
, r2
).c_str(), registerName(exec
, r3
).c_str(), offset
, location
+ offset
);
1046 it
+= OPCODE_LENGTH(op_get_pnames
) - 1;
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("[%4d] next_pname\t %s, %s, %d(->%d)\n", location
, registerName(exec
, dest
).c_str(), registerName(exec
, iter
).c_str(), offset
, location
+ offset
);
1054 it
+= OPCODE_LENGTH(op_next_pname
) - 1;
1057 case op_push_scope
: {
1058 int r0
= (++it
)->u
.operand
;
1059 printf("[%4d] push_scope\t %s\n", location
, registerName(exec
, r0
).c_str());
1062 case op_pop_scope
: {
1063 printf("[%4d] pop_scope\n", location
);
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("[%4d] push_new_scope \t%s, %s, %s\n", location
, registerName(exec
, r0
).c_str(), idName(id0
, m_identifiers
[id0
]).c_str(), registerName(exec
, r1
).c_str());
1073 case op_jmp_scopes
: {
1074 int scopeDelta
= (++it
)->u
.operand
;
1075 int offset
= (++it
)->u
.operand
;
1076 printf("[%4d] jmp_scopes\t^%d, %d(->%d)\n", location
, scopeDelta
, offset
, location
+ offset
);
1080 int r0
= (++it
)->u
.operand
;
1081 printf("[%4d] catch\t\t %s\n", location
, registerName(exec
, r0
).c_str());
1085 int r0
= (++it
)->u
.operand
;
1086 printf("[%4d] throw\t\t %s\n", location
, registerName(exec
, r0
).c_str());
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("[%4d] new_error\t %s, %d, %s\n", location
, registerName(exec
, r0
).c_str(), errorType
, constantName(exec
, k0
, getConstant(k0
)).c_str());
1097 int retAddrDst
= (++it
)->u
.operand
;
1098 int offset
= (++it
)->u
.operand
;
1099 printf("[%4d] jsr\t\t %s, %d(->%d)\n", location
, registerName(exec
, retAddrDst
).c_str(), offset
, location
+ offset
);
1103 int retAddrSrc
= (++it
)->u
.operand
;
1104 printf("[%4d] sret\t\t %s\n", location
, registerName(exec
, retAddrSrc
).c_str());
1108 int debugHookID
= (++it
)->u
.operand
;
1109 int firstLine
= (++it
)->u
.operand
;
1110 int lastLine
= (++it
)->u
.operand
;
1111 printf("[%4d] debug\t\t %s, %d, %d\n", location
, debugHookName(debugHookID
), firstLine
, lastLine
);
1114 case op_profile_will_call
: {
1115 int function
= (++it
)->u
.operand
;
1116 printf("[%4d] profile_will_call %s\n", location
, registerName(exec
, function
).c_str());
1119 case op_profile_did_call
: {
1120 int function
= (++it
)->u
.operand
;
1121 printf("[%4d] profile_did_call\t %s\n", location
, registerName(exec
, function
).c_str());
1125 int r0
= (++it
)->u
.operand
;
1126 printf("[%4d] end\t\t %s\n", location
, registerName(exec
, r0
).c_str());
1132 #endif // !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING)
1134 #if DUMP_CODE_BLOCK_STATISTICS
1135 static HashSet
<CodeBlock
*> liveCodeBlockSet
;
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)
1148 #define FOR_EACH_MEMBER_VECTOR_RARE_DATA(macro) \
1151 macro(exceptionHandlers) \
1152 macro(immediateSwitchJumpTables) \
1153 macro(characterSwitchJumpTables) \
1154 macro(stringSwitchJumpTables) \
1155 macro(functionRegisterInfos)
1157 #define FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(macro) \
1158 macro(expressionInfo) \
1160 macro(getByIdExceptionInfo) \
1163 template<typename T
>
1164 static size_t sizeInBytes(const Vector
<T
>& vector
)
1166 return vector
.capacity() * sizeof(T
);
1169 void CodeBlock::dumpStatistics()
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
)
1178 // Non-vector data members
1179 size_t evalCodeCacheIsNotEmpty
= 0;
1181 size_t symbolTableIsNotEmpty
= 0;
1182 size_t symbolTableTotalSize
= 0;
1184 size_t hasExceptionInfo
= 0;
1185 size_t hasRareData
= 0;
1187 size_t isFunctionCode
= 0;
1188 size_t isGlobalCode
= 0;
1189 size_t isEvalCode
= 0;
1191 HashSet
<CodeBlock
*>::const_iterator end
= liveCodeBlockSet
.end();
1192 for (HashSet
<CodeBlock
*>::const_iterator it
= liveCodeBlockSet
.begin(); it
!= end
; ++it
) {
1193 CodeBlock
* codeBlock
= *it
;
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
)
1199 if (!codeBlock
->m_symbolTable
.isEmpty()) {
1200 symbolTableIsNotEmpty
++;
1201 symbolTableTotalSize
+= (codeBlock
->m_symbolTable
.capacity() * (sizeof(SymbolTable::KeyType
) + sizeof(SymbolTable::MappedType
)));
1204 if (codeBlock
->m_exceptionInfo
) {
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
)
1211 if (codeBlock
->m_rareData
) {
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
)
1217 if (!codeBlock
->m_rareData
->m_evalCodeCache
.isEmpty())
1218 evalCodeCacheIsNotEmpty
++;
1221 switch (codeBlock
->codeType()) {
1234 size_t totalSize
= 0;
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
1242 totalSize
+= symbolTableTotalSize
;
1243 totalSize
+= (liveCodeBlockSet
.size() * sizeof(CodeBlock
));
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());
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());
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());
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
)
1263 printf("Number of CodeBlocks with evalCodeCache: %zu\n", evalCodeCacheIsNotEmpty
);
1264 printf("Number of CodeBlocks with symbolTable: %zu\n", symbolTableIsNotEmpty
);
1266 printf("Size of all symbolTables: %zu\n", symbolTableTotalSize
);
1269 printf("Dumping CodeBlock statistics is not enabled.\n");
1273 CodeBlock::CodeBlock(ScriptExecutable
* ownerExecutable
, CodeType codeType
, PassRefPtr
<SourceProvider
> sourceProvider
, unsigned sourceOffset
, SymbolTable
* symTab
)
1274 : m_numCalleeRegisters(0)
1276 , m_numParameters(0)
1277 , m_ownerExecutable(ownerExecutable
)
1280 , m_instructionCount(0)
1282 , m_needsFullScopeChain(ownerExecutable
->needsActivation())
1283 , m_usesEval(ownerExecutable
->usesEval())
1284 , m_isNumericCompareFunction(false)
1285 , m_codeType(codeType
)
1286 , m_source(sourceProvider
)
1287 , m_sourceOffset(sourceOffset
)
1288 , m_symbolTable(symTab
)
1289 , m_exceptionInfo(new ExceptionInfo
)
1293 #if DUMP_CODE_BLOCK_STATISTICS
1294 liveCodeBlockSet
.add(this);
1298 CodeBlock::~CodeBlock()
1301 for (size_t size
= m_globalResolveInstructions
.size(), i
= 0; i
< size
; ++i
)
1302 derefStructures(&m_instructions
[m_globalResolveInstructions
[i
]]);
1304 for (size_t size
= m_propertyAccessInstructions
.size(), i
= 0; i
< size
; ++i
)
1305 derefStructures(&m_instructions
[m_propertyAccessInstructions
[i
]]);
1307 for (size_t size
= m_globalResolveInfos
.size(), i
= 0; i
< size
; ++i
) {
1308 if (m_globalResolveInfos
[i
].structure
)
1309 m_globalResolveInfos
[i
].structure
->deref();
1312 for (size_t size
= m_structureStubInfos
.size(), i
= 0; i
< size
; ++i
)
1313 m_structureStubInfos
[i
].deref();
1315 for (size_t size
= m_callLinkInfos
.size(), i
= 0; i
< size
; ++i
) {
1316 CallLinkInfo
* callLinkInfo
= &m_callLinkInfos
[i
];
1317 if (callLinkInfo
->isLinked())
1318 callLinkInfo
->callee
->removeCaller(callLinkInfo
);
1321 for (size_t size
= m_methodCallLinkInfos
.size(), i
= 0; i
< size
; ++i
) {
1322 if (Structure
* structure
= m_methodCallLinkInfos
[i
].cachedStructure
) {
1324 // Both members must be filled at the same time
1325 ASSERT(!!m_methodCallLinkInfos
[i
].cachedPrototypeStructure
);
1326 m_methodCallLinkInfos
[i
].cachedPrototypeStructure
->deref();
1330 #if ENABLE(JIT_OPTIMIZE_CALL)
1334 #endif // !ENABLE(JIT)
1336 #if DUMP_CODE_BLOCK_STATISTICS
1337 liveCodeBlockSet
.remove(this);
1341 #if ENABLE(JIT_OPTIMIZE_CALL)
1342 void CodeBlock::unlinkCallers()
1344 size_t size
= m_linkedCallerList
.size();
1345 for (size_t i
= 0; i
< size
; ++i
) {
1346 CallLinkInfo
* currentCaller
= m_linkedCallerList
[i
];
1347 JIT::unlinkCall(currentCaller
);
1348 currentCaller
->setUnlinked();
1350 m_linkedCallerList
.clear();
1354 void CodeBlock::derefStructures(Instruction
* vPC
) const
1356 Interpreter
* interpreter
= m_globalData
->interpreter
;
1358 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_self
)) {
1359 vPC
[4].u
.structure
->deref();
1362 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_proto
)) {
1363 vPC
[4].u
.structure
->deref();
1364 vPC
[5].u
.structure
->deref();
1367 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_chain
)) {
1368 vPC
[4].u
.structure
->deref();
1369 vPC
[5].u
.structureChain
->deref();
1372 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_put_by_id_transition
)) {
1373 vPC
[4].u
.structure
->deref();
1374 vPC
[5].u
.structure
->deref();
1375 vPC
[6].u
.structureChain
->deref();
1378 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_put_by_id_replace
)) {
1379 vPC
[4].u
.structure
->deref();
1382 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_resolve_global
)) {
1383 if(vPC
[4].u
.structure
)
1384 vPC
[4].u
.structure
->deref();
1387 if ((vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_proto_list
))
1388 || (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_self_list
))) {
1389 PolymorphicAccessStructureList
* polymorphicStructures
= vPC
[4].u
.polymorphicStructures
;
1390 polymorphicStructures
->derefStructures(vPC
[5].u
.operand
);
1391 delete polymorphicStructures
;
1395 // These instructions don't ref their Structures.
1396 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
));
1399 void CodeBlock::refStructures(Instruction
* vPC
) const
1401 Interpreter
* interpreter
= m_globalData
->interpreter
;
1403 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_self
)) {
1404 vPC
[4].u
.structure
->ref();
1407 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_proto
)) {
1408 vPC
[4].u
.structure
->ref();
1409 vPC
[5].u
.structure
->ref();
1412 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_get_by_id_chain
)) {
1413 vPC
[4].u
.structure
->ref();
1414 vPC
[5].u
.structureChain
->ref();
1417 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_put_by_id_transition
)) {
1418 vPC
[4].u
.structure
->ref();
1419 vPC
[5].u
.structure
->ref();
1420 vPC
[6].u
.structureChain
->ref();
1423 if (vPC
[0].u
.opcode
== interpreter
->getOpcode(op_put_by_id_replace
)) {
1424 vPC
[4].u
.structure
->ref();
1428 // These instructions don't ref their Structures.
1429 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
));
1432 void CodeBlock::markAggregate(MarkStack
& markStack
)
1434 for (size_t i
= 0; i
< m_constantRegisters
.size(); ++i
)
1435 markStack
.append(m_constantRegisters
[i
].jsValue());
1436 for (size_t i
= 0; i
< m_functionExprs
.size(); ++i
)
1437 m_functionExprs
[i
]->markAggregate(markStack
);
1438 for (size_t i
= 0; i
< m_functionDecls
.size(); ++i
)
1439 m_functionDecls
[i
]->markAggregate(markStack
);
1442 void CodeBlock::reparseForExceptionInfoIfNecessary(CallFrame
* callFrame
)
1444 if (m_exceptionInfo
)
1447 ScopeChainNode
* scopeChain
= callFrame
->scopeChain();
1448 if (m_needsFullScopeChain
) {
1449 ScopeChain
sc(scopeChain
);
1450 int scopeDelta
= sc
.localDepth();
1451 if (m_codeType
== EvalCode
)
1452 scopeDelta
-= static_cast<EvalCodeBlock
*>(this)->baseScopeDepth();
1453 else if (m_codeType
== FunctionCode
)
1454 scopeDelta
++; // Compilation of function code assumes activation is not on the scope chain yet.
1455 ASSERT(scopeDelta
>= 0);
1456 while (scopeDelta
--)
1457 scopeChain
= scopeChain
->next
;
1460 m_exceptionInfo
.set(m_ownerExecutable
->reparseExceptionInfo(m_globalData
, scopeChain
, this));
1463 HandlerInfo
* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset
)
1465 ASSERT(bytecodeOffset
< m_instructionCount
);
1470 Vector
<HandlerInfo
>& exceptionHandlers
= m_rareData
->m_exceptionHandlers
;
1471 for (size_t i
= 0; i
< exceptionHandlers
.size(); ++i
) {
1472 // Handlers are ordered innermost first, so the first handler we encounter
1473 // that contains the source address is the correct handler to use.
1474 if (exceptionHandlers
[i
].start
<= bytecodeOffset
&& exceptionHandlers
[i
].end
>= bytecodeOffset
)
1475 return &exceptionHandlers
[i
];
1481 int CodeBlock::lineNumberForBytecodeOffset(CallFrame
* callFrame
, unsigned bytecodeOffset
)
1483 ASSERT(bytecodeOffset
< m_instructionCount
);
1485 reparseForExceptionInfoIfNecessary(callFrame
);
1486 ASSERT(m_exceptionInfo
);
1488 if (!m_exceptionInfo
->m_lineInfo
.size())
1489 return m_ownerExecutable
->source().firstLine(); // Empty function
1492 int high
= m_exceptionInfo
->m_lineInfo
.size();
1493 while (low
< high
) {
1494 int mid
= low
+ (high
- low
) / 2;
1495 if (m_exceptionInfo
->m_lineInfo
[mid
].instructionOffset
<= bytecodeOffset
)
1502 return m_ownerExecutable
->source().firstLine();
1503 return m_exceptionInfo
->m_lineInfo
[low
- 1].lineNumber
;
1506 int CodeBlock::expressionRangeForBytecodeOffset(CallFrame
* callFrame
, unsigned bytecodeOffset
, int& divot
, int& startOffset
, int& endOffset
)
1508 ASSERT(bytecodeOffset
< m_instructionCount
);
1510 reparseForExceptionInfoIfNecessary(callFrame
);
1511 ASSERT(m_exceptionInfo
);
1513 if (!m_exceptionInfo
->m_expressionInfo
.size()) {
1514 // We didn't think anything could throw. Apparently we were wrong.
1518 return lineNumberForBytecodeOffset(callFrame
, bytecodeOffset
);
1522 int high
= m_exceptionInfo
->m_expressionInfo
.size();
1523 while (low
< high
) {
1524 int mid
= low
+ (high
- low
) / 2;
1525 if (m_exceptionInfo
->m_expressionInfo
[mid
].instructionOffset
<= bytecodeOffset
)
1536 return lineNumberForBytecodeOffset(callFrame
, bytecodeOffset
);
1539 startOffset
= m_exceptionInfo
->m_expressionInfo
[low
- 1].startOffset
;
1540 endOffset
= m_exceptionInfo
->m_expressionInfo
[low
- 1].endOffset
;
1541 divot
= m_exceptionInfo
->m_expressionInfo
[low
- 1].divotPoint
+ m_sourceOffset
;
1542 return lineNumberForBytecodeOffset(callFrame
, bytecodeOffset
);
1545 bool CodeBlock::getByIdExceptionInfoForBytecodeOffset(CallFrame
* callFrame
, unsigned bytecodeOffset
, OpcodeID
& opcodeID
)
1547 ASSERT(bytecodeOffset
< m_instructionCount
);
1549 reparseForExceptionInfoIfNecessary(callFrame
);
1550 ASSERT(m_exceptionInfo
);
1552 if (!m_exceptionInfo
->m_getByIdExceptionInfo
.size())
1556 int high
= m_exceptionInfo
->m_getByIdExceptionInfo
.size();
1557 while (low
< high
) {
1558 int mid
= low
+ (high
- low
) / 2;
1559 if (m_exceptionInfo
->m_getByIdExceptionInfo
[mid
].bytecodeOffset
<= bytecodeOffset
)
1565 if (!low
|| m_exceptionInfo
->m_getByIdExceptionInfo
[low
- 1].bytecodeOffset
!= bytecodeOffset
)
1568 opcodeID
= m_exceptionInfo
->m_getByIdExceptionInfo
[low
- 1].isOpConstruct
? op_construct
: op_instanceof
;
1573 bool CodeBlock::functionRegisterForBytecodeOffset(unsigned bytecodeOffset
, int& functionRegisterIndex
)
1575 ASSERT(bytecodeOffset
< m_instructionCount
);
1577 if (!m_rareData
|| !m_rareData
->m_functionRegisterInfos
.size())
1581 int high
= m_rareData
->m_functionRegisterInfos
.size();
1582 while (low
< high
) {
1583 int mid
= low
+ (high
- low
) / 2;
1584 if (m_rareData
->m_functionRegisterInfos
[mid
].bytecodeOffset
<= bytecodeOffset
)
1590 if (!low
|| m_rareData
->m_functionRegisterInfos
[low
- 1].bytecodeOffset
!= bytecodeOffset
)
1593 functionRegisterIndex
= m_rareData
->m_functionRegisterInfos
[low
- 1].functionRegisterIndex
;
1599 bool CodeBlock::hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset
)
1601 if (m_globalResolveInstructions
.isEmpty())
1605 int high
= m_globalResolveInstructions
.size();
1606 while (low
< high
) {
1607 int mid
= low
+ (high
- low
) / 2;
1608 if (m_globalResolveInstructions
[mid
] <= bytecodeOffset
)
1614 if (!low
|| m_globalResolveInstructions
[low
- 1] != bytecodeOffset
)
1619 bool CodeBlock::hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset
)
1621 if (m_globalResolveInfos
.isEmpty())
1625 int high
= m_globalResolveInfos
.size();
1626 while (low
< high
) {
1627 int mid
= low
+ (high
- low
) / 2;
1628 if (m_globalResolveInfos
[mid
].bytecodeOffset
<= bytecodeOffset
)
1634 if (!low
|| m_globalResolveInfos
[low
- 1].bytecodeOffset
!= bytecodeOffset
)
1640 void CodeBlock::shrinkToFit()
1642 m_instructions
.shrinkToFit();
1645 m_propertyAccessInstructions
.shrinkToFit();
1646 m_globalResolveInstructions
.shrinkToFit();
1648 m_structureStubInfos
.shrinkToFit();
1649 m_globalResolveInfos
.shrinkToFit();
1650 m_callLinkInfos
.shrinkToFit();
1651 m_linkedCallerList
.shrinkToFit();
1654 m_identifiers
.shrinkToFit();
1655 m_functionDecls
.shrinkToFit();
1656 m_functionExprs
.shrinkToFit();
1657 m_constantRegisters
.shrinkToFit();
1659 if (m_exceptionInfo
) {
1660 m_exceptionInfo
->m_expressionInfo
.shrinkToFit();
1661 m_exceptionInfo
->m_lineInfo
.shrinkToFit();
1662 m_exceptionInfo
->m_getByIdExceptionInfo
.shrinkToFit();
1666 m_rareData
->m_exceptionHandlers
.shrinkToFit();
1667 m_rareData
->m_regexps
.shrinkToFit();
1668 m_rareData
->m_immediateSwitchJumpTables
.shrinkToFit();
1669 m_rareData
->m_characterSwitchJumpTables
.shrinkToFit();
1670 m_rareData
->m_stringSwitchJumpTables
.shrinkToFit();
1672 m_rareData
->m_functionRegisterInfos
.shrinkToFit();