-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathCodeBlock.cpp
More file actions
3580 lines (3244 loc) · 134 KB
/
CodeBlock.cpp
File metadata and controls
3580 lines (3244 loc) · 134 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2008 Cameron Zwarich <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "CodeBlock.h"
#include "BytecodeGenerator.h"
#include "BytecodeUseDef.h"
#include "CallLinkStatus.h"
#include "DFGCapabilities.h"
#include "DFGCommon.h"
#include "DFGDriver.h"
#include "DFGNode.h"
#include "DFGWorklist.h"
#include "Debugger.h"
#include "Interpreter.h"
#include "JIT.h"
#include "JITStubs.h"
#include "JSActivation.h"
#include "JSCJSValue.h"
#include "JSFunction.h"
#include "JSNameScope.h"
#include "LLIntEntrypoint.h"
#include "LowLevelInterpreter.h"
#include "Operations.h"
#include "PolymorphicPutByIdList.h"
#include "ReduceWhitespace.h"
#include "Repatch.h"
#include "RepatchBuffer.h"
#include "SlotVisitorInlines.h"
#include <wtf/BagToHashMap.h>
#include <wtf/CommaPrinter.h>
#include <wtf/StringExtras.h>
#include <wtf/StringPrintStream.h>
#if ENABLE(DFG_JIT)
#include "DFGOperations.h"
#endif
#if ENABLE(FTL_JIT)
#include "FTLJITCode.h"
#endif
namespace JSC {
CString CodeBlock::inferredName() const
{
switch (codeType()) {
case GlobalCode:
return "<global>";
case EvalCode:
return "<eval>";
case FunctionCode:
return jsCast<FunctionExecutable*>(ownerExecutable())->inferredName().utf8();
default:
CRASH();
return CString("", 0);
}
}
bool CodeBlock::hasHash() const
{
return !!m_hash;
}
bool CodeBlock::isSafeToComputeHash() const
{
return !isCompilationThread();
}
CodeBlockHash CodeBlock::hash() const
{
if (!m_hash) {
RELEASE_ASSERT(isSafeToComputeHash());
m_hash = CodeBlockHash(ownerExecutable()->source(), specializationKind());
}
return m_hash;
}
CString CodeBlock::sourceCodeForTools() const
{
if (codeType() != FunctionCode)
return ownerExecutable()->source().toUTF8();
SourceProvider* provider = source();
FunctionExecutable* executable = jsCast<FunctionExecutable*>(ownerExecutable());
UnlinkedFunctionExecutable* unlinked = executable->unlinkedExecutable();
unsigned unlinkedStartOffset = unlinked->startOffset();
unsigned linkedStartOffset = executable->source().startOffset();
int delta = linkedStartOffset - unlinkedStartOffset;
unsigned rangeStart = delta + unlinked->unlinkedFunctionNameStart();
unsigned rangeEnd = delta + unlinked->startOffset() + unlinked->sourceLength();
return toCString(
"function ",
provider->source().impl()->utf8ForRange(rangeStart, rangeEnd - rangeStart));
}
CString CodeBlock::sourceCodeOnOneLine() const
{
return reduceWhitespace(sourceCodeForTools());
}
void CodeBlock::dumpAssumingJITType(PrintStream& out, JITCode::JITType jitType) const
{
if (hasHash() || isSafeToComputeHash())
out.print(inferredName(), "#", hash(), ":[", RawPointer(this), "->", RawPointer(ownerExecutable()), ", ", jitType, codeType());
else
out.print(inferredName(), "#<no-hash>:[", RawPointer(this), "->", RawPointer(ownerExecutable()), ", ", jitType, codeType());
if (codeType() == FunctionCode)
out.print(specializationKind());
out.print(", ", instructionCount());
if (this->jitType() == JITCode::BaselineJIT && m_shouldAlwaysBeInlined)
out.print(" (SABI)");
if (ownerExecutable()->neverInline())
out.print(" (NeverInline)");
if (ownerExecutable()->isStrictMode())
out.print(" (StrictMode)");
out.print("]");
}
void CodeBlock::dump(PrintStream& out) const
{
dumpAssumingJITType(out, jitType());
}
static CString constantName(int k, JSValue value)
{
return toCString(value, "(@k", k - FirstConstantRegisterIndex, ")");
}
static CString idName(int id0, const Identifier& ident)
{
return toCString(ident.impl(), "(@id", id0, ")");
}
CString CodeBlock::registerName(int r) const
{
if (r == missingThisObjectMarker())
return "<null>";
if (isConstantRegisterIndex(r))
return constantName(r, getConstant(r));
if (operandIsArgument(r)) {
if (!VirtualRegister(r).toArgument())
return "this";
return toCString("arg", VirtualRegister(r).toArgument());
}
return toCString("loc", VirtualRegister(r).toLocal());
}
static CString regexpToSourceString(RegExp* regExp)
{
char postfix[5] = { '/', 0, 0, 0, 0 };
int index = 1;
if (regExp->global())
postfix[index++] = 'g';
if (regExp->ignoreCase())
postfix[index++] = 'i';
if (regExp->multiline())
postfix[index] = 'm';
return toCString("/", regExp->pattern().impl(), postfix);
}
static CString regexpName(int re, RegExp* regexp)
{
return toCString(regexpToSourceString(regexp), "(@re", re, ")");
}
NEVER_INLINE static const char* debugHookName(int debugHookID)
{
switch (static_cast<DebugHookID>(debugHookID)) {
case DidEnterCallFrame:
return "didEnterCallFrame";
case WillLeaveCallFrame:
return "willLeaveCallFrame";
case WillExecuteStatement:
return "willExecuteStatement";
case WillExecuteProgram:
return "willExecuteProgram";
case DidExecuteProgram:
return "didExecuteProgram";
case DidReachBreakpoint:
return "didReachBreakpoint";
}
RELEASE_ASSERT_NOT_REACHED();
return "";
}
void CodeBlock::printUnaryOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
{
int r0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, op);
out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
}
void CodeBlock::printBinaryOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
{
int r0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
int r2 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, op);
out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
}
void CodeBlock::printConditionalJump(PrintStream& out, ExecState* exec, const Instruction*, const Instruction*& it, int location, const char* op)
{
int r0 = (++it)->u.operand;
int offset = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, op);
out.printf("%s, %d(->%d)", registerName(r0).data(), offset, location + offset);
}
void CodeBlock::printGetByIdOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it)
{
const char* op;
switch (exec->interpreter()->getOpcodeID(it->u.opcode)) {
case op_get_by_id:
op = "get_by_id";
break;
case op_get_by_id_out_of_line:
op = "get_by_id_out_of_line";
break;
case op_get_by_id_self:
op = "get_by_id_self";
break;
case op_get_by_id_proto:
op = "get_by_id_proto";
break;
case op_get_by_id_chain:
op = "get_by_id_chain";
break;
case op_get_by_id_getter_self:
op = "get_by_id_getter_self";
break;
case op_get_by_id_getter_proto:
op = "get_by_id_getter_proto";
break;
case op_get_by_id_getter_chain:
op = "get_by_id_getter_chain";
break;
case op_get_by_id_custom_self:
op = "get_by_id_custom_self";
break;
case op_get_by_id_custom_proto:
op = "get_by_id_custom_proto";
break;
case op_get_by_id_custom_chain:
op = "get_by_id_custom_chain";
break;
case op_get_by_id_generic:
op = "get_by_id_generic";
break;
case op_get_array_length:
op = "array_length";
break;
case op_get_string_length:
op = "string_length";
break;
default:
RELEASE_ASSERT_NOT_REACHED();
op = 0;
}
int r0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
int id0 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, op);
out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), idName(id0, identifier(id0)).data());
it += 4; // Increment up to the value profiler.
}
#if ENABLE(JIT) || ENABLE(LLINT) // unused in some configurations
static void dumpStructure(PrintStream& out, const char* name, ExecState* exec, Structure* structure, const Identifier& ident)
{
if (!structure)
return;
out.printf("%s = %p", name, structure);
PropertyOffset offset = structure->getConcurrently(exec->vm(), ident.impl());
if (offset != invalidOffset)
out.printf(" (offset = %d)", offset);
}
#endif
#if ENABLE(JIT) // unused when not ENABLE(JIT), leading to silly warnings
static void dumpChain(PrintStream& out, ExecState* exec, StructureChain* chain, const Identifier& ident)
{
out.printf("chain = %p: [", chain);
bool first = true;
for (WriteBarrier<Structure>* currentStructure = chain->head();
*currentStructure;
++currentStructure) {
if (first)
first = false;
else
out.printf(", ");
dumpStructure(out, "struct", exec, currentStructure->get(), ident);
}
out.printf("]");
}
#endif
void CodeBlock::printGetByIdCacheStatus(PrintStream& out, ExecState* exec, int location, const StubInfoMap& map)
{
Instruction* instruction = instructions().begin() + location;
const Identifier& ident = identifier(instruction[3].u.operand);
UNUSED_PARAM(ident); // tell the compiler to shut up in certain platform configurations.
#if ENABLE(LLINT)
if (exec->interpreter()->getOpcodeID(instruction[0].u.opcode) == op_get_array_length)
out.printf(" llint(array_length)");
else if (Structure* structure = instruction[4].u.structure.get()) {
out.printf(" llint(");
dumpStructure(out, "struct", exec, structure, ident);
out.printf(")");
}
#endif
#if ENABLE(JIT)
if (StructureStubInfo* stubPtr = map.get(CodeOrigin(location))) {
StructureStubInfo& stubInfo = *stubPtr;
if (stubInfo.seen) {
out.printf(" jit(");
Structure* baseStructure = 0;
Structure* prototypeStructure = 0;
StructureChain* chain = 0;
PolymorphicAccessStructureList* structureList = 0;
int listSize = 0;
switch (stubInfo.accessType) {
case access_get_by_id_self:
out.printf("self");
baseStructure = stubInfo.u.getByIdSelf.baseObjectStructure.get();
break;
case access_get_by_id_proto:
out.printf("proto");
baseStructure = stubInfo.u.getByIdProto.baseObjectStructure.get();
prototypeStructure = stubInfo.u.getByIdProto.prototypeStructure.get();
break;
case access_get_by_id_chain:
out.printf("chain");
baseStructure = stubInfo.u.getByIdChain.baseObjectStructure.get();
chain = stubInfo.u.getByIdChain.chain.get();
break;
case access_get_by_id_self_list:
out.printf("self_list");
structureList = stubInfo.u.getByIdSelfList.structureList;
listSize = stubInfo.u.getByIdSelfList.listSize;
break;
case access_get_by_id_proto_list:
out.printf("proto_list");
structureList = stubInfo.u.getByIdProtoList.structureList;
listSize = stubInfo.u.getByIdProtoList.listSize;
break;
case access_unset:
out.printf("unset");
break;
case access_get_by_id_generic:
out.printf("generic");
break;
case access_get_array_length:
out.printf("array_length");
break;
case access_get_string_length:
out.printf("string_length");
break;
default:
RELEASE_ASSERT_NOT_REACHED();
break;
}
if (baseStructure) {
out.printf(", ");
dumpStructure(out, "struct", exec, baseStructure, ident);
}
if (prototypeStructure) {
out.printf(", ");
dumpStructure(out, "prototypeStruct", exec, baseStructure, ident);
}
if (chain) {
out.printf(", ");
dumpChain(out, exec, chain, ident);
}
if (structureList) {
out.printf(", list = %p: [", structureList);
for (int i = 0; i < listSize; ++i) {
if (i)
out.printf(", ");
out.printf("(");
dumpStructure(out, "base", exec, structureList->list[i].base.get(), ident);
if (structureList->list[i].isChain) {
if (structureList->list[i].u.chain.get()) {
out.printf(", ");
dumpChain(out, exec, structureList->list[i].u.chain.get(), ident);
}
} else {
if (structureList->list[i].u.proto.get()) {
out.printf(", ");
dumpStructure(out, "proto", exec, structureList->list[i].u.proto.get(), ident);
}
}
out.printf(")");
}
out.printf("]");
}
out.printf(")");
}
}
#else
UNUSED_PARAM(map);
#endif
}
void CodeBlock::printCallOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op, CacheDumpMode cacheDumpMode, bool& hasPrintedProfiling)
{
int dst = (++it)->u.operand;
int func = (++it)->u.operand;
int argCount = (++it)->u.operand;
int registerOffset = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, op);
out.printf("%s, %s, %d, %d", registerName(dst).data(), registerName(func).data(), argCount, registerOffset);
if (cacheDumpMode == DumpCaches) {
#if ENABLE(LLINT)
LLIntCallLinkInfo* callLinkInfo = it[1].u.callLinkInfo;
if (callLinkInfo->lastSeenCallee) {
out.printf(
" llint(%p, exec %p)",
callLinkInfo->lastSeenCallee.get(),
callLinkInfo->lastSeenCallee->executable());
}
#endif
#if ENABLE(JIT)
if (numberOfCallLinkInfos()) {
JSFunction* target = getCallLinkInfo(location).lastSeenCallee.get();
if (target)
out.printf(" jit(%p, exec %p)", target, target->executable());
}
#endif
out.print(" status(", CallLinkStatus::computeFor(this, location), ")");
}
++it;
dumpArrayProfiling(out, it, hasPrintedProfiling);
dumpValueProfiling(out, it, hasPrintedProfiling);
}
void CodeBlock::printPutByIdOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
{
int r0 = (++it)->u.operand;
int id0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, op);
out.printf("%s, %s, %s", registerName(r0).data(), idName(id0, identifier(id0)).data(), registerName(r1).data());
it += 5;
}
void CodeBlock::dumpBytecode(PrintStream& out)
{
// We only use the ExecState* for things that don't actually lead to JS execution,
// like converting a JSString to a String. Hence the globalExec is appropriate.
ExecState* exec = m_globalObject->globalExec();
size_t instructionCount = 0;
for (size_t i = 0; i < instructions().size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(instructions()[i].u.opcode)])
++instructionCount;
out.print(*this);
out.printf(
": %lu m_instructions; %lu bytes; %d parameter(s); %d callee register(s); %d variable(s)",
static_cast<unsigned long>(instructions().size()),
static_cast<unsigned long>(instructions().size() * sizeof(Instruction)),
m_numParameters, m_numCalleeRegisters, m_numVars);
if (symbolTable() && symbolTable()->captureCount()) {
out.printf(
"; %d captured var(s) (from r%d to r%d, inclusive)",
symbolTable()->captureCount(), symbolTable()->captureStart(), symbolTable()->captureEnd() + 1);
}
if (usesArguments()) {
out.printf(
"; uses arguments, in r%d, r%d",
argumentsRegister().offset(),
unmodifiedArgumentsRegister(argumentsRegister()).offset());
}
if (needsFullScopeChain() && codeType() == FunctionCode)
out.printf("; activation in r%d", activationRegister().offset());
out.printf("\n");
StubInfoMap stubInfos;
#if ENABLE(JIT)
{
ConcurrentJITLocker locker(m_lock);
getStubInfoMap(locker, stubInfos);
}
#endif
const Instruction* begin = instructions().begin();
const Instruction* end = instructions().end();
for (const Instruction* it = begin; it != end; ++it)
dumpBytecode(out, exec, begin, it, stubInfos);
if (numberOfIdentifiers()) {
out.printf("\nIdentifiers:\n");
size_t i = 0;
do {
out.printf(" id%u = %s\n", static_cast<unsigned>(i), identifier(i).string().utf8().data());
++i;
} while (i != numberOfIdentifiers());
}
if (!m_constantRegisters.isEmpty()) {
out.printf("\nConstants:\n");
size_t i = 0;
do {
out.printf(" k%u = %s\n", static_cast<unsigned>(i), toCString(m_constantRegisters[i].get()).data());
++i;
} while (i < m_constantRegisters.size());
}
if (size_t count = m_unlinkedCode->numberOfRegExps()) {
out.printf("\nm_regexps:\n");
size_t i = 0;
do {
out.printf(" re%u = %s\n", static_cast<unsigned>(i), regexpToSourceString(m_unlinkedCode->regexp(i)).data());
++i;
} while (i < count);
}
if (m_rareData && !m_rareData->m_exceptionHandlers.isEmpty()) {
out.printf("\nException Handlers:\n");
unsigned i = 0;
do {
out.printf("\t %d: { start: [%4d] end: [%4d] target: [%4d] depth: [%4d] }\n", i + 1, m_rareData->m_exceptionHandlers[i].start, m_rareData->m_exceptionHandlers[i].end, m_rareData->m_exceptionHandlers[i].target, m_rareData->m_exceptionHandlers[i].scopeDepth);
++i;
} while (i < m_rareData->m_exceptionHandlers.size());
}
if (m_rareData && !m_rareData->m_switchJumpTables.isEmpty()) {
out.printf("Switch Jump Tables:\n");
unsigned i = 0;
do {
out.printf(" %1d = {\n", i);
int entry = 0;
Vector<int32_t>::const_iterator end = m_rareData->m_switchJumpTables[i].branchOffsets.end();
for (Vector<int32_t>::const_iterator iter = m_rareData->m_switchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) {
if (!*iter)
continue;
out.printf("\t\t%4d => %04d\n", entry + m_rareData->m_switchJumpTables[i].min, *iter);
}
out.printf(" }\n");
++i;
} while (i < m_rareData->m_switchJumpTables.size());
}
if (m_rareData && !m_rareData->m_stringSwitchJumpTables.isEmpty()) {
out.printf("\nString Switch Jump Tables:\n");
unsigned i = 0;
do {
out.printf(" %1d = {\n", i);
StringJumpTable::StringOffsetTable::const_iterator end = m_rareData->m_stringSwitchJumpTables[i].offsetTable.end();
for (StringJumpTable::StringOffsetTable::const_iterator iter = m_rareData->m_stringSwitchJumpTables[i].offsetTable.begin(); iter != end; ++iter)
out.printf("\t\t\"%s\" => %04d\n", String(iter->key).utf8().data(), iter->value.branchOffset);
out.printf(" }\n");
++i;
} while (i < m_rareData->m_stringSwitchJumpTables.size());
}
out.printf("\n");
}
void CodeBlock::beginDumpProfiling(PrintStream& out, bool& hasPrintedProfiling)
{
if (hasPrintedProfiling) {
out.print("; ");
return;
}
out.print(" ");
hasPrintedProfiling = true;
}
void CodeBlock::dumpValueProfiling(PrintStream& out, const Instruction*& it, bool& hasPrintedProfiling)
{
ConcurrentJITLocker locker(m_lock);
++it;
#if ENABLE(VALUE_PROFILER)
CString description = it->u.profile->briefDescription(locker);
if (!description.length())
return;
beginDumpProfiling(out, hasPrintedProfiling);
out.print(description);
#else
UNUSED_PARAM(out);
UNUSED_PARAM(hasPrintedProfiling);
#endif
}
void CodeBlock::dumpArrayProfiling(PrintStream& out, const Instruction*& it, bool& hasPrintedProfiling)
{
ConcurrentJITLocker locker(m_lock);
++it;
#if ENABLE(VALUE_PROFILER)
if (!it->u.arrayProfile)
return;
CString description = it->u.arrayProfile->briefDescription(locker, this);
if (!description.length())
return;
beginDumpProfiling(out, hasPrintedProfiling);
out.print(description);
#else
UNUSED_PARAM(out);
UNUSED_PARAM(hasPrintedProfiling);
#endif
}
#if ENABLE(VALUE_PROFILER)
void CodeBlock::dumpRareCaseProfile(PrintStream& out, const char* name, RareCaseProfile* profile, bool& hasPrintedProfiling)
{
if (!profile || !profile->m_counter)
return;
beginDumpProfiling(out, hasPrintedProfiling);
out.print(name, profile->m_counter);
}
#endif
void CodeBlock::dumpBytecode(PrintStream& out, ExecState* exec, const Instruction* begin, const Instruction*& it, const StubInfoMap& map)
{
int location = it - begin;
bool hasPrintedProfiling = false;
switch (exec->interpreter()->getOpcodeID(it->u.opcode)) {
case op_enter: {
printLocationAndOp(out, exec, location, it, "enter");
break;
}
case op_touch_entry: {
printLocationAndOp(out, exec, location, it, "touch_entry");
break;
}
case op_create_activation: {
int r0 = (++it)->u.operand;
printLocationOpAndRegisterOperand(out, exec, location, it, "create_activation", r0);
break;
}
case op_create_arguments: {
int r0 = (++it)->u.operand;
printLocationOpAndRegisterOperand(out, exec, location, it, "create_arguments", r0);
break;
}
case op_init_lazy_reg: {
int r0 = (++it)->u.operand;
printLocationOpAndRegisterOperand(out, exec, location, it, "init_lazy_reg", r0);
break;
}
case op_get_callee: {
int r0 = (++it)->u.operand;
printLocationOpAndRegisterOperand(out, exec, location, it, "get_callee", r0);
++it;
break;
}
case op_create_this: {
int r0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
unsigned inferredInlineCapacity = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "create_this");
out.printf("%s, %s, %u", registerName(r0).data(), registerName(r1).data(), inferredInlineCapacity);
break;
}
case op_to_this: {
int r0 = (++it)->u.operand;
printLocationOpAndRegisterOperand(out, exec, location, it, "to_this", r0);
++it; // Skip value profile.
break;
}
case op_new_object: {
int r0 = (++it)->u.operand;
unsigned inferredInlineCapacity = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "new_object");
out.printf("%s, %u", registerName(r0).data(), inferredInlineCapacity);
++it; // Skip object allocation profile.
break;
}
case op_new_array: {
int dst = (++it)->u.operand;
int argv = (++it)->u.operand;
int argc = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "new_array");
out.printf("%s, %s, %d", registerName(dst).data(), registerName(argv).data(), argc);
++it; // Skip array allocation profile.
break;
}
case op_new_array_with_size: {
int dst = (++it)->u.operand;
int length = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "new_array_with_size");
out.printf("%s, %s", registerName(dst).data(), registerName(length).data());
++it; // Skip array allocation profile.
break;
}
case op_new_array_buffer: {
int dst = (++it)->u.operand;
int argv = (++it)->u.operand;
int argc = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "new_array_buffer");
out.printf("%s, %d, %d", registerName(dst).data(), argv, argc);
++it; // Skip array allocation profile.
break;
}
case op_new_regexp: {
int r0 = (++it)->u.operand;
int re0 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "new_regexp");
out.printf("%s, ", registerName(r0).data());
if (r0 >=0 && r0 < (int)m_unlinkedCode->numberOfRegExps())
out.printf("%s", regexpName(re0, regexp(re0)).data());
else
out.printf("bad_regexp(%d)", re0);
break;
}
case op_mov: {
int r0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "mov");
out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
break;
}
case op_captured_mov: {
int r0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "captured_mov");
out.printf("%s, %s", registerName(r0).data(), registerName(r1).data());
++it;
break;
}
case op_not: {
printUnaryOp(out, exec, location, it, "not");
break;
}
case op_eq: {
printBinaryOp(out, exec, location, it, "eq");
break;
}
case op_eq_null: {
printUnaryOp(out, exec, location, it, "eq_null");
break;
}
case op_neq: {
printBinaryOp(out, exec, location, it, "neq");
break;
}
case op_neq_null: {
printUnaryOp(out, exec, location, it, "neq_null");
break;
}
case op_stricteq: {
printBinaryOp(out, exec, location, it, "stricteq");
break;
}
case op_nstricteq: {
printBinaryOp(out, exec, location, it, "nstricteq");
break;
}
case op_less: {
printBinaryOp(out, exec, location, it, "less");
break;
}
case op_lesseq: {
printBinaryOp(out, exec, location, it, "lesseq");
break;
}
case op_greater: {
printBinaryOp(out, exec, location, it, "greater");
break;
}
case op_greatereq: {
printBinaryOp(out, exec, location, it, "greatereq");
break;
}
case op_inc: {
int r0 = (++it)->u.operand;
printLocationOpAndRegisterOperand(out, exec, location, it, "inc", r0);
break;
}
case op_dec: {
int r0 = (++it)->u.operand;
printLocationOpAndRegisterOperand(out, exec, location, it, "dec", r0);
break;
}
case op_to_number: {
printUnaryOp(out, exec, location, it, "to_number");
break;
}
case op_negate: {
printUnaryOp(out, exec, location, it, "negate");
break;
}
case op_add: {
printBinaryOp(out, exec, location, it, "add");
++it;
break;
}
case op_mul: {
printBinaryOp(out, exec, location, it, "mul");
++it;
break;
}
case op_div: {
printBinaryOp(out, exec, location, it, "div");
++it;
break;
}
case op_mod: {
printBinaryOp(out, exec, location, it, "mod");
break;
}
case op_sub: {
printBinaryOp(out, exec, location, it, "sub");
++it;
break;
}
case op_lshift: {
printBinaryOp(out, exec, location, it, "lshift");
break;
}
case op_rshift: {
printBinaryOp(out, exec, location, it, "rshift");
break;
}
case op_urshift: {
printBinaryOp(out, exec, location, it, "urshift");
break;
}
case op_bitand: {
printBinaryOp(out, exec, location, it, "bitand");
++it;
break;
}
case op_bitxor: {
printBinaryOp(out, exec, location, it, "bitxor");
++it;
break;
}
case op_bitor: {
printBinaryOp(out, exec, location, it, "bitor");
++it;
break;
}
case op_check_has_instance: {
int r0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
int r2 = (++it)->u.operand;
int offset = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "check_has_instance");
out.printf("%s, %s, %s, %d(->%d)", registerName(r0).data(), registerName(r1).data(), registerName(r2).data(), offset, location + offset);
break;
}
case op_instanceof: {
int r0 = (++it)->u.operand;
int r1 = (++it)->u.operand;
int r2 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "instanceof");
out.printf("%s, %s, %s", registerName(r0).data(), registerName(r1).data(), registerName(r2).data());
break;
}
case op_unsigned: {
printUnaryOp(out, exec, location, it, "unsigned");
break;
}
case op_typeof: {
printUnaryOp(out, exec, location, it, "typeof");
break;
}
case op_is_undefined: {
printUnaryOp(out, exec, location, it, "is_undefined");
break;
}
case op_is_boolean: {
printUnaryOp(out, exec, location, it, "is_boolean");
break;
}
case op_is_number: {
printUnaryOp(out, exec, location, it, "is_number");
break;
}
case op_is_string: {
printUnaryOp(out, exec, location, it, "is_string");
break;
}
case op_is_object: {
printUnaryOp(out, exec, location, it, "is_object");
break;
}
case op_is_function: {
printUnaryOp(out, exec, location, it, "is_function");
break;
}
case op_in: {
printBinaryOp(out, exec, location, it, "in");
break;
}
case op_init_global_const_nop: {
printLocationAndOp(out, exec, location, it, "init_global_const_nop");
it++;
it++;
it++;
it++;
break;
}
case op_init_global_const: {
WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer;
int r0 = (++it)->u.operand;
printLocationAndOp(out, exec, location, it, "init_global_const");
out.printf("g%d(%p), %s", m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(r0).data());
it++;
it++;
break;
}
case op_get_by_id:
case op_get_by_id_out_of_line:
case op_get_by_id_self:
case op_get_by_id_proto:
case op_get_by_id_chain:
case op_get_by_id_getter_self:
case op_get_by_id_getter_proto:
case op_get_by_id_getter_chain:
case op_get_by_id_custom_self:
case op_get_by_id_custom_proto:
case op_get_by_id_custom_chain:
case op_get_by_id_generic:
case op_get_array_length:
case op_get_string_length: {
printGetByIdOp(out, exec, location, it);
printGetByIdCacheStatus(out, exec, location, map);
dumpValueProfiling(out, it, hasPrintedProfiling);
break;
}
case op_get_arguments_length: {
printUnaryOp(out, exec, location, it, "get_arguments_length");
it++;
break;
}
case op_put_by_id: {
printPutByIdOp(out, exec, location, it, "put_by_id");
break;
}
case op_put_by_id_out_of_line: {
printPutByIdOp(out, exec, location, it, "put_by_id_out_of_line");
break;
}
case op_put_by_id_replace: {
printPutByIdOp(out, exec, location, it, "put_by_id_replace");
break;
}
case op_put_by_id_transition: {
printPutByIdOp(out, exec, location, it, "put_by_id_transition");
break;
}
case op_put_by_id_transition_direct: {
printPutByIdOp(out, exec, location, it, "put_by_id_transition_direct");
break;