This repository was archived by the owner on Jan 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathInterpreter.cpp
More file actions
3787 lines (3425 loc) · 131 KB
/
Copy pathInterpreter.cpp
File metadata and controls
3787 lines (3425 loc) · 131 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
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "avmplus.h"
#include "Interpreter.h"
#ifdef VMCFG_NANOJIT
# include "exec-osr.h"
#endif
#ifdef AVMPLUS_MAC
#ifndef __GNUC__
// inline_max_total_size() defaults to 10000.
// This module includes so many inline functions that we
// exceed this limit and we start getting compile warnings,
// so bump up the limit for this file.
#pragma inline_max_total_size(26576)
#endif
#endif
// The macro VMCFG_WORDCODE is true if the representation of ABC code is as an array of words and
// not an array of bytes.
namespace avmplus
{
// an auto-ptr for managing MethodFrame calls.
class EnterMethodEnv
{
public:
inline explicit EnterMethodEnv(AvmCore* core, MethodEnv* env, MethodFrame& frame) : m_core(core), m_frame(frame)
{
m_frame.enter(m_core, env);
}
inline ~EnterMethodEnv()
{
m_frame.exit(m_core);
}
void setCurrent()
{
m_core->currentMethodFrame = &m_frame;
}
private:
AvmCore* m_core;
MethodFrame& m_frame;
};
#ifdef _DEBUG
REALLY_INLINE Atom CHECK_INT_ATOM(Atom a)
{
AvmAssert(atomKind(a) == kIntptrType && atomIsValidIntptrValue(atomGetIntptr(a)));
return a;
}
REALLY_INLINE Atom MAKE_INTEGER(intptr_t i)
{
AvmAssert(atomIsValidIntptrValue(i));
return (intptr_t(i) << 3) | kIntptrType;
}
#else
#define CHECK_INT_ATOM(a) (a)
#define MAKE_INTEGER(v) ((intptr_t(v) << 3) | kIntptrType)
#endif
#define IS_INTEGER(v) (((v) & 7) == kIntptrType)
#define IS_DOUBLE(v) (((v) & 7) == kDoubleType)
#define IS_BOOLEAN(v) (((v) & 7) == kBooleanType)
#define IS_STRING(v) (((v) & 7) == kStringType)
#ifdef VMCFG_FLOAT
#define IS_FLOAT(v) ((((v) & 7) == kSpecialBibopType) && ((v)!=AtomConstants::undefinedAtom) && bibopKind(v)==kBibopFloatType)
#define IS_FLOAT4(v) ((((v) & 7) == kSpecialBibopType) && ((v)!=AtomConstants::undefinedAtom) && bibopKind(v)==kBibopFloat4Type)
#endif // VMCFG_FLOAT
// note that the argument to SIGN_EXTEND is expected to be upshifted 3 bits (not a "raw" intptr),
// but it doesn't expect or require the tag bits to be set properly.
#ifdef AVMPLUS_64BIT
// since 64-bit int atoms expect exactly 54 bits of precision, we want to shift bit 54+3 up into the sign bit and back down
# define SIGN_EXTEND(v) ((intptr_t(v) << (atomSignExtendShift-AtomConstants::kAtomTypeSize)) >> (atomSignExtendShift-AtomConstants::kAtomTypeSize))
#else
# define SIGN_EXTEND(v) (intptr_t(v))
#endif
// CLAMP_32 is equivalent to running an int atom thru AvmCore::integer (ie, truncate to int32_t using the right rules),
// but, like SIGN_EXTEND, it expects the argument to be upshifted 3 bit.
#ifdef AVMPLUS_64BIT
# define CLAMP_32(v) ((intptr_t(v) << (32-AtomConstants::kAtomTypeSize)) >> (32-AtomConstants::kAtomTypeSize))
#else
# define CLAMP_32(v) (intptr_t(v))
#endif
#define INT32_VALUE(v) int32_t(atomGetIntptr(v))
#define UINT32_VALUE(v) uint32_t(atomGetIntptr(v))
#define DOUBLE_VALUE(v) (*(double*)((v) ^ kDoubleType))
#ifdef VMCFG_FLOAT
#define FLOAT_VALUE(v) (*(float*)((v) ^ kSpecialBibopType))
#endif
#define IS_BOTH_KIND(a,b,k) (((( (a) ^ (k) ) | ( (b) ^ (k) )) & 7) == 0) // less control flow but more registers -- which is better?
#define IS_BOTH_INTEGER(a,b) IS_BOTH_KIND(a,b,kIntptrType)
#define IS_BOTH_DOUBLE(a,b) IS_BOTH_KIND(a,b,kDoubleType)
#ifdef VMCFG_FLOAT
#define IS_BOTH_BIBOP(a,b,k) IS_BOTH_KIND(a,b,kSpecialBibopType) && \
((a)!=AtomConstants::undefinedAtom) && ((b)!=AtomConstants::undefinedAtom) \
&& bibopKind(a)==k && bibopKind(b)==k
#define IS_BOTH_FLOAT(a,b) IS_BOTH_BIBOP(a,b,kBibopFloatType)
#define IS_BOTH_FLOAT4(a,b) IS_BOTH_BIBOP(a,b,kBibopFloat4Type)
#endif // VMCFG_FLOAT
#ifdef VMCFG_WORDCODE
# define WORD_CODE_ONLY(x) x
# define ABC_CODE_ONLY(x)
#else
# define WORD_CODE_ONLY(x)
# define ABC_CODE_ONLY(x) x
#endif
#ifdef VMCFG_WORDCODE_PEEPHOLE
# define PEEPHOLE_ONLY(x) x
#else
# define PEEPHOLE_ONLY(x)
#endif
#ifdef DEBUGGER
# define DEBUGGER_ONLY(x) x
# define NONDEBUGGER_ONLY(x)
#else
# define DEBUGGER_ONLY(x)
# define NONDEBUGGER_ONLY(x) x
#endif
#ifdef DEBUG
# define DEBUG_ONLY(x) x
#else
# define DEBUG_ONLY(x)
#endif
#ifdef VMCFG_WORDCODE
typedef uintptr_t bytecode_t;
#else
typedef uint8_t bytecode_t;
#endif
#ifndef VMCFG_WORDCODE
inline intptr_t readS24(const uint8_t* pc) {
return AvmCore::readS24(pc);
}
inline uintptr_t readU30(const uint8_t*& pc) {
return AvmCore::readU32(pc);
}
#endif
// Direct threading in the interpreter.
//
// If you have gcc, direct threading should work out of the box and
// should provide a nice speedup with many platforms and compiler versions.
//
// If you are using Microsoft Visual C/C++ then you may turn on direct
// threading, and you must select one of the two threading implementations
// below. MSVC_X86_ASM_THREADING should "just work" but is likely
// to be slower than switch dispatch, unless you're using a compiler
// version with little or no optimization. MSVC_X86_REWRITE_THREADING
// usually improves the performance over switch dispatch, but requires
// a fair amount of manual work if core/Interpreter.cpp has been modified
// since core/FastInterpreter.asm was generated. The specific work
// needed to regenerate core/FastInterpreter.cpp is described in a comment
// at the head of utils/x86rewrite.as, which you will need to run.
#ifdef VMCFG_DIRECT_THREADED
# ifndef VMCFG_WORDCODE
# error "Need word code enabled for this"
# endif
# if defined __GNUC__
# define GNUC_THREADING
# define DIRECT_DISPATCH
# elif defined AVMPLUS_WIN32
// Pick one of the two following options
//# define MSVC_X86_ASM_THREADING
# define MSVC_X86_REWRITE_THREADING
# ifdef MSVC_X86_ASM_THREADING
# define DIRECT_DISPATCH
# endif
# ifdef MSVC_X86_REWRITE_THREADING
# define SWITCH_DISPATCH
# endif
# else
# error "Threaded code not supported for this platform/compiler"
# endif
#else
# define SWITCH_DISPATCH
#endif // compiler/platform vipers' nest
static Atom* initMultiname(MethodEnv* env, Multiname &name, Atom* sp);
static Atom* initMultinameNoXMLList(MethodEnv* env, Multiname &name, Atom* sp);
static Traits* getTraits(const Multiname* name, PoolObject* pool, Toplevel* toplevel, AvmCore* core);
#ifdef AVMPLUS_VERBOSE
// display contents of current stack frame only
static void showState(MethodInfo* info, const bytecode_t *code_start, const bytecode_t *pc,
Atom* framep, Atom *spp, int scopeDepth, Atom *scopebasep, int max_scope);
#endif
/**
* on a backwards branch, check if the interrupt flag is enabled.
* used by interpreter only. A copy of this is inline-generated
* by CodegenLIR at loop headers.
*/
REALLY_INLINE void branchCheck(AvmCore* core, MethodEnv *env, bool interruptable)
{
#ifdef DEBUGGER
core->sampleCheck();
#endif
if (core->interruptCheck(interruptable))
core->handleInterruptMethodEnv(env);
}
#ifdef _MSC_VER
# ifdef MSVC_X86_ASM_THREADING
# pragma warning(disable:4740) // "inline assembler suppresses global optimization"
# endif
#endif // _MSC_VER
#ifdef VMCFG_DIRECT_THREADED
void** interpGetOpcodeLabels() {
// *** NOTE ON THREAD SAFETY ***
//
// If we ever enable direct threading for a platform where the thread jump targets
// cannot be constants in a vector but must be written into a vector the first time
// interpGetOpcodeLabels() is called, then the following call must be within a
// critical section (or some startup code must make an initial call to make sure
// the vector is initialized in a thread safe way). At this time, Visual C++
// requires this, but we're not using direct threading with Visual C++, so there
// is no critical section here.
//
// The startup code to make the initial call can simply call this function and
// assign the result to a dummy static global variable; that trick is not portable
// but it can be used for many platforms (and is used elsewhere).
#if defined MSVC_X86_ASM_THREADING || defined MSVC_X86_REWRITE_THREADING
#error "interpGetOpcodeLabels needs a critical section or eager initialization for this compiler / platform combination"
#endif
return (void**)interpBoxed(NULL, 0, NULL);
}
#endif // VMCFG_DIRECT_THREADED
#ifdef VMCFG_NANOJIT
# define OSR(offset) \
if (OSR::countEdge(env, info, ms) && \
OSR::execute(env, framep, ms, pc + (offset), &a1l)) { \
methodFrame.setCurrent(); \
a1 = a1l; \
goto return_value_from_interpreter; \
}
#else
# define OSR(i1)
#endif
/* [Pepper Linux x86 only]
*
* GCC 4.4.3 generates wrong optimization code for the following 2 functions:
*
* |interpBoxed()|
* |initMultiname()|
*
* The problem only happens on Pepper linux x86 build, and it consistently crashes
* when running testID=18467 in ATS10AS3, refer to bug# 3831468. Bug# 3831882 is
* also related to this issue.
*
* We found that GCC 4.4.2/4.4.3/4.4.4 all have this problem, while GCC 4.4.5 and
* later do not have this issue.
*
* We should remove this __attribute__ once we upgrade GCC compiler to GCC 4.4.5 and
* later.
*/
#if defined(PEPPER_PLUGIN) && defined(AVMPLUS_UNIX) && !defined(PEPPER_MAC) && \
!defined(OS_CHROMEOS) && defined(VMCFG_32BIT) && !defined(DEBUG)
Atom __attribute__((optimize("O1"))) interpBoxed(register MethodEnv* env, register int _argc, register Atom* _atomv)
#else
Atom interpBoxed(register MethodEnv* env, register int _argc, register Atom* _atomv)
#endif
{
#ifdef VMCFG_DIRECT_THREADED
// If env is NULL return the jump table. Optionally initialize it here on those
// platforms where compile-time initialization is not possible or practical.
if (env == NULL) {
# if defined GNUC_THREADING
# define III(idx, lbl) &&lbl,
# define XXX(idx) &&L_illegal_op,
static void* opcode_labels[] = {
# elif defined MSVC_X86_ASM_THREADING || defined MSVC_X86_REWRITE_THREADING
static void* opcode_labels[WOP_LAST+1];
if (opcode_labels[0] == 0) {
# define XXX(idx) III(idx, L_illegal_op)
# ifdef MSVC_X86_ASM_THREADING
# define III(idx, lbl) __asm { \
__asm mov eax, offset opcode_labels \
__asm mov ebx, offset lbl \
__asm mov [eax+4*idx], ebx \
}
# else
extern bool LLLLABEL(int);
# define III(a,b) extern void LLLLABEL ## _ ## a ## _ ## b(); LLLLABEL ## _ ## a ## _ ## b();
# endif
# endif // threading discipline
# define IIM(a,b) III(a,b)
# if defined VMCFG_WORDCODE_PEEPHOLE
# define IIP(a,b) III(a,b)
# else
# define IIP(a,b) XXX(a)
# endif
# if defined DEBUGGER || !defined VMCFG_WORDCODE
# define IID(a,b) III(a,b)
# else
# define IID(a,b) XXX(a)
# endif
XXX(0x00)
XXX(0x01) /* OP_bkpt */
III(0x02, L_nop)
III(0x03, L_throw)
III(0x04, L_getsuper)
III(0x05, L_setsuper)
III(0x06, L_dxns)
III(0x07, L_dxnslate)
III(0x08, L_kill)
XXX(0x09) /* OP_label */
#ifdef VMCFG_FLOAT
III(0x0A, L_lf32x4)
III(0x0B, L_sf32x4)
#else
XXX(0x0A)
XXX(0x0B)
#endif
III(0x0C, L_ifnlt)
III(0x0D, L_ifnle)
III(0x0E, L_ifngt)
III(0x0F, L_ifnge)
III(0x10, L_jump)
III(0x11, L_iftrue)
III(0x12, L_iffalse)
III(0x13, L_ifeq)
III(0x14, L_ifne)
III(0x15, L_iflt)
III(0x16, L_ifle)
III(0x17, L_ifgt)
III(0x18, L_ifge)
III(0x19, L_ifstricteq)
III(0x1A, L_ifstrictne)
III(0x1B, L_lookupswitch)
III(0x1C, L_pushwith)
III(0x1D, L_popscope)
III(0x1E, L_nextname)
III(0x1F, L_hasnext)
III(0x20, L_pushnull)
III(0x21, L_pushundefined)
#ifdef VMCFG_FLOAT
III(0x22, L_pushfloat)
#else
XXX(0x22)
#endif
III(0x23, L_nextvalue)
XXX(0x24) /* OP_pushbyte */
XXX(0x25) /* OP_pushshort */
III(0x26, L_pushtrue)
III(0x27, L_pushfalse)
III(0x28, L_pushnan)
III(0x29, L_pop)
III(0x2A, L_dup)
III(0x2B, L_swap)
III(0x2C, L_pushstring)
XXX(0x2D) /* OP_pushint */
XXX(0x2E) /* OP_pushuint */
III(0x2F, L_pushdouble)
III(0x30, L_pushscope)
III(0x31, L_pushnamespace)
III(0x32, L_hasnext2)
XXX(0x33)
XXX(0x34)
IIM(0x35, L_li8)
IIM(0x36, L_li16)
IIM(0x37, L_li32)
IIM(0x38, L_lf32)
IIM(0x39, L_lf64)
IIM(0x3A, L_si8)
IIM(0x3B, L_si16)
IIM(0x3C, L_si32)
IIM(0x3D, L_sf32)
IIM(0x3E, L_sf64)
XXX(0x3F)
III(0x40, L_newfunction)
III(0x41, L_call)
III(0x42, L_construct)
III(0x43, L_callmethod)
III(0x44, L_callstatic)
III(0x45, L_callsuper)
III(0x46, L_callproperty)
III(0x47, L_returnvoid)
III(0x48, L_returnvalue)
III(0x49, L_constructsuper)
III(0x4A, L_constructprop)
XXX(0x4B) /* OP_callsuperid */
III(0x4C, L_callproplex)
XXX(0x4D) /* OP_callinterface */
III(0x4E, L_callsupervoid)
III(0x4F, L_callpropvoid)
IIM(0x50, L_sxi1)
IIM(0x51, L_sxi8)
IIM(0x52, L_sxi16)
III(0x53, L_applytype)
#ifdef VMCFG_FLOAT
III(0x54, L_pushfloat4)
#else
XXX(0x54)
#endif
III(0x55, L_newobject)
III(0x56, L_newarray)
III(0x57, L_newactivation)
III(0x58, L_newclass)
III(0x59, L_getdescendants)
III(0x5A, L_newcatch)
XXX(0x5B)
XXX(0x5C)
III(0x5D, L_findpropstrict)
III(0x5E, L_findproperty)
III(0x5F, L_finddef)
III(0x60, L_getlex)
III(0x61, L_setproperty)
III(0x62, L_getlocal)
III(0x63, L_setlocal)
III(0x64, L_getglobalscope)
III(0x65, L_getscopeobject)
III(0x66, L_getproperty)
III(0x67, L_getouterscope)
III(0x68, L_initproperty)
XXX(0x69)
III(0x6A, L_deleteproperty)
XXX(0x6B)
III(0x6C, L_getslot)
III(0x6D, L_setslot)
III(0x6E, L_getglobalslot)
III(0x6F, L_setglobalslot)
III(0x70, L_convert_s)
III(0x71, L_esc_xelem)
III(0x72, L_esc_xattr)
III(0x73, L_convert_i)
III(0x74, L_convert_u)
III(0x75, L_convert_d)
III(0x76, L_convert_b)
III(0x77, L_convert_o)
III(0x78, L_checkfilter)
#ifdef VMCFG_FLOAT
III(0x79, L_convert_f)
III(0x7A, L_unplus)
III(0x7B, L_convert_f4)
#else
XXX(0x79)
XXX(0x7A)
XXX(0x7B)
#endif
XXX(0x7C)
XXX(0x7D)
XXX(0x7E)
XXX(0x7F)
III(0x80, L_coerce)
III(0x81, L_convert_b) // coerce_b -> convert_b, they are the same
XXX(0x82) /* OP_coerce_a */
III(0x83, L_convert_i) // coerce_i -> convert_i, they are the same
III(0x84, L_convert_d) // coerce_d -> convert_d, they are the same
III(0x85, L_coerce_s)
III(0x86, L_astype)
III(0x87, L_astypelate)
III(0x88, L_convert_u) // coerce_u -> convert_u, they are the same
III(0x89, L_coerce_o)
XXX(0x8A)
XXX(0x8B)
XXX(0x8C)
XXX(0x8D)
XXX(0x8E)
XXX(0x8F)
III(0x90, L_negate)
III(0x91, L_increment)
III(0x92, L_inclocal)
III(0x93, L_decrement)
III(0x94, L_declocal)
III(0x95, L_typeof)
III(0x96, L_not)
III(0x97, L_bitnot)
XXX(0x98)
XXX(0x99)
XXX(0x9A)
XXX(0x9B)
XXX(0x9C)
XXX(0x9D)
XXX(0x9E)
XXX(0x9F)
III(0xA0, L_add)
III(0xA1, L_subtract)
III(0xA2, L_multiply)
III(0xA3, L_divide)
III(0xA4, L_modulo)
III(0xA5, L_lshift)
III(0xA6, L_rshift)
III(0xA7, L_urshift)
III(0xA8, L_bitand)
III(0xA9, L_bitor)
III(0xAA, L_bitxor)
III(0xAB, L_equals)
III(0xAC, L_strictequals)
III(0xAD, L_lessthan)
III(0xAE, L_lessequals)
III(0xAF, L_greaterthan)
III(0xB0, L_greaterequals)
III(0xB1, L_instanceof)
III(0xB2, L_istype)
III(0xB3, L_istypelate)
III(0xB4, L_in)
XXX(0xB5)
XXX(0xB6)
XXX(0xB7)
XXX(0xB8)
XXX(0xB9)
XXX(0xBA)
XXX(0xBB)
XXX(0xBC)
XXX(0xBD)
XXX(0xBE)
XXX(0xBF)
III(0xC0, L_increment_i)
III(0xC1, L_decrement_i)
III(0xC2, L_inclocal_i)
III(0xC3, L_declocal_i)
III(0xC4, L_negate_i)
III(0xC5, L_add_i)
III(0xC6, L_subtract_i)
III(0xC7, L_multiply_i)
XXX(0xC8)
XXX(0xC9)
XXX(0xCA)
XXX(0xCB)
XXX(0xCC)
XXX(0xCD)
XXX(0xCE)
XXX(0xCF)
III(0xD0, L_getlocal0)
III(0xD1, L_getlocal1)
III(0xD2, L_getlocal2)
III(0xD3, L_getlocal3)
III(0xD4, L_setlocal0)
III(0xD5, L_setlocal1)
III(0xD6, L_setlocal2)
III(0xD7, L_setlocal3)
XXX(0xD8)
XXX(0xD9)
XXX(0xDA)
XXX(0xDB)
XXX(0xDC)
XXX(0xDD)
XXX(0xDE)
XXX(0xDF)
XXX(0xE0)
XXX(0xE1)
XXX(0xE2)
XXX(0xE3)
XXX(0xE4)
XXX(0xE5)
XXX(0xE6)
XXX(0xE7)
XXX(0xE8)
XXX(0xE9)
XXX(0xEA)
XXX(0xEB)
XXX(0xEC)
XXX(0xED)
XXX(0xEE)
IID(0xEF, L_debug)
IID(0xF0, L_debugline)
IID(0xF1, L_debugfile)
XXX(0xF2) /* OP_bkptline */
XXX(0xF3) /* OP_timestamp */
XXX(0xF4)
XXX(0xF5)
XXX(0xF6)
XXX(0xF7)
XXX(0xF8)
XXX(0xF9)
XXX(0xFA)
XXX(0xFB)
XXX(0xFC)
XXX(0xFD)
XXX(0xFE)
XXX(0xFF) /* OP_ext */
XXX(0x100)
III(0x101, L_pushbits)
III(0x102, L_push_doublebits)
IIP(0x103, L_get2locals)
IIP(0x104, L_get3locals)
IIP(0x105, L_get4locals)
IIP(0x106, L_get5locals)
IIP(0x107, L_storelocal)
IIP(0x108, L_add_ll)
IIP(0x109, L_add_set_lll)
IIP(0x10A, L_subtract_ll)
IIP(0x10B, L_multiply_ll)
IIP(0x10C, L_divide_ll)
IIP(0x10D, L_modulo_ll)
IIP(0x10E, L_bitand_ll)
IIP(0x10F, L_bitor_ll)
IIP(0x110, L_bitxor_ll)
IIP(0x111, L_add_lb)
IIP(0x112, L_subtract_lb)
IIP(0x113, L_multiply_lb)
IIP(0x114, L_divide_lb)
IIP(0x115, L_bitand_lb)
IIP(0x116, L_bitor_lb)
IIP(0x117, L_bitxor_lb)
IIP(0x118, L_iflt_ll)
IIP(0x119, L_ifnlt_ll)
IIP(0x11A, L_ifle_ll)
IIP(0x11B, L_ifnle_ll)
IIP(0x11C, L_ifgt_ll)
IIP(0x11D, L_ifngt_ll)
IIP(0x11E, L_ifge_ll)
IIP(0x11F, L_ifnge_ll)
IIP(0x120, L_ifeq_ll)
IIP(0x121, L_ifne_ll)
IIP(0x122, L_ifstricteq_ll)
IIP(0x123, L_ifstrictne_ll)
IIP(0x124, L_iflt_lb)
IIP(0x125, L_ifnlt_lb)
IIP(0x126, L_ifle_lb)
IIP(0x127, L_ifnle_lb)
IIP(0x128, L_ifgt_lb)
IIP(0x129, L_ifngt_lb)
IIP(0x12A, L_ifge_lb)
IIP(0x12B, L_ifnge_lb)
IIP(0x12C, L_ifeq_lb)
IIP(0x12D, L_ifne_lb)
IIP(0x12E, L_ifstricteq_lb)
IIP(0x12F, L_ifstrictne_lb)
IIP(0x130, L_swap_pop)
III(0x131, L_findpropglobal)
III(0x132, L_findpropglobalstrict)
#if defined DEBUGGER && defined VMCFG_WORDCODE
IID(0x133, L_debugenter)
IID(0x134, L_debugexit)
#else
XXX(0x133)
XXX(0x134)
#endif
III(0x135, L_lix8)
III(0x136, L_lix16)
#ifdef VMCFG_FLOAT
III(0x137, L_float4)
#else
XXX(0x137)
#endif
# if defined GNUC_THREADING
};
AvmAssert(opcode_labels[0x18] == &&L_ifge);
AvmAssert(opcode_labels[0x97] == &&L_bitnot);
AvmAssert(opcode_labels[257] == &&L_pushbits);
# ifdef VMCFG_WORDCODE_PEEPHOLE
AvmAssert(opcode_labels[48 + 256] == &&L_swap_pop);
# endif
# elif defined MSVC_X86_ASM_THREADING || defined MSVC_X86_REWRITE_THREADING
} // conditional run-time initialization of jump table
# endif // threading discipline
return (Atom)opcode_labels;
} // env == 0?
#endif // !VMCFG_DIRECT_THREADED
// These are local variables that are allocated to alloca'd memory;
// if alloca() is the real alloca() then that makes no difference, but
// when alloca() is redirected to the heap it makes stack frames smaller,
// which matters on systems with short stacks.
//
// Storage that is conditionally initialized or rarely used may be moved
// into this structure, to balance the benefit (smaller stack frames)
// with the costs (more expensive access, slightly larger code).
//
// Be careful: if a member has a destructor then an auto_ptr like mechanism is
// required to invoke the destructor. The ExceptionFrame gets such a mechanism
// when the TRY_UNLESS_HEAPMEM macro is used to initialize it.
struct InterpreterAuxiliaryFrame
{
MethodFrame methodFrame;
ExceptionFrame ef;
Multiname multiname2;
};
#ifdef DEBUGGER
struct InterpreterAuxiliaryFrameWithCSN : public InterpreterAuxiliaryFrame
{
inline InterpreterAuxiliaryFrameWithCSN() : cs(CallStackNode::kEmpty) {}
CallStackNode cs;
};
#endif
// OPTIMIZEME - opportunity to compute some information only when needed.
//
// Some of these, notably cpool_double and envDomain, are cached because
// programs that use them tend to be quite a bit slower if they're not cached. (In the
// ABC interpreter we should also cache cpool_int and cpool_uint.) But
// the caching slows down function-heavy programs that don't use them. It may
// be fruitful to have a bit in the info that tells the interpreter whether to
// set these up or not.
register AvmCore* const core = env->core();
register Toplevel* const toplevel = env->toplevel();
register MethodInfo* const info = env->method;
register PoolObject* const pool = info->pool();
#ifdef DEBUGGER
const size_t kAuxFrameSize = core->debugger() ? sizeof(InterpreterAuxiliaryFrameWithCSN) : sizeof(InterpreterAuxiliaryFrame);
#else
const size_t kAuxFrameSize = sizeof(InterpreterAuxiliaryFrame);
#endif
#ifdef AVMPLUS_VERBOSE
if (pool->isVerbose(VB_interp, info))
core->console << "interp " << info << '\n';
#endif
// always do a stack check; this not only checks true stack overflows
// but also the stack limit is used to gain control for host interrupts.
// so this stack check doubles as an interrupt check.
// see also: AvmCore::handleStackOverflow().
core->stackCheck(env);
register GCList<GCDouble> const & cpool_double = pool->cpool_double;
register const bool interruptable = !info->isNonInterruptible();
register const DomainEnv* envDomain = env->domainEnv();
// I do *not* like making pc 'volatile'; a smart compiler may handle it well
// and only spill to memory across a call, but a dumb compiler may not ever
#ifdef VMCFG_STACK_METRICS
core->recordStackPointer();
#endif
// keep the value in a register at all.
MethodSignaturep volatile ms = env->method->getMethodSignature();
#if !defined VMCFG_WORDCODE || defined AVMPLUS_VERBOSE
#ifdef VMCFG_WORDCODE
register const bytecode_t* volatile codeStart = info->word_code_start();
#else
register const bytecode_t* volatile codeStart = ms->abc_code_start();
#endif
#endif
#ifdef VMCFG_WORDCODE
register const bytecode_t* /* NOT VOLATILE */ pc = info->word_code_start();
#else
register const bytecode_t* /* NOT VOLATILE */ pc = ms->abc_code_start();
#endif
intptr_t volatile expc=0;
MMgc::GC::AllocaAutoPtr _framep;
#ifdef AVMPLUS_64BIT
// Allocation is guaranteed on an 8-byte boundary, but we need 16 for _setjmpex.
// So allocate 8 bytes extra, then round up to a 16-byte boundary.
register Atom* const framep =
(Atom*)avmStackAlloc(core, _framep,
sizeof(Atom)*(ms->frame_size())
+ 8
+ kAuxFrameSize);
register InterpreterAuxiliaryFrame* const aux_memory = (InterpreterAuxiliaryFrame*)(((uintptr_t)(framep + ms->frame_size()) + 15) & ~15);
#else
register Atom* const framep =
(Atom*)avmStackAlloc(core, _framep,
sizeof(Atom)*(ms->frame_size())
+ kAuxFrameSize);
union {
Atom* fa;
InterpreterAuxiliaryFrame* fi;
};
fa = framep + ms->frame_size();
register InterpreterAuxiliaryFrame* const aux_memory = (InterpreterAuxiliaryFrame*)fi;
#endif
// It's essential that the MethodFrame is cleaned up upon normal exit,
// to keep core->currentMethodFrame in order. A throw past the frame
// will not perform cleanup. A manual call just before returning
// is *not* adequate, as we need to be able to call
// aux_memory->methodFrame->exit() *after* our TRY/CATCH code has
// completed (otherwise, it may attempt to "restore" currentStack
// to a bogus value). Using a real dtor here ensures we are called
// after any endTry().
EnterMethodEnv methodFrame(core, env, aux_memory->methodFrame);
register Atom* const scopeBase = framep + ms->local_count();
register Atom* volatile withBase = NULL;
NONDEBUGGER_ONLY( register ) int volatile scopeDepth = 0;
register ScopeChain* const scope = env->scope();
// Compute base of operand stack.
register Atom* /* NOT VOLATILE */ sp = scopeBase + ms->max_scope() - 1;
// We used to assume that scope 0 (the global scope) must be a ScriptObject*,
// but this is not the case: it can legitimately be a String* or a primitive.
// (Note that no scope can be null or undefined, however.)
Atom /* NOT VOLATILE */ globalScopeAtom = (scope->getSize() > 0) ?
scope->getScope(0) :
nullObjectAtom;
// OPTIMIZEME - opportunities for streamlining the function entry code.
//
// * With unbox/box optimization introduced and alloca removed so
// that the parameter are as on the heap, we could overlap the
// outgoing parameter area with the incoming locals. This avoids
// copying, and will be a win if we don't have to work hard to
// figure out when it's applicable.
//
// * A minor point is that rest / arguments could possibly be
// created by a special opcode so that those flags don't have to be
// checked here. Unlikely to be a time sink.
//
// Edwin has suggested that the interp() function should simply take
// a boxed argument array always and that the call code should always
// pass a boxed argument array. We'd end up with two entry points,
// one for boxed entry and one for unboxed entry. For interpreted
// code the boxed entry would jump straight into this function, and
// the unboxed entry would go through reboxing. For compiled code it
// would be the other way around, probably.
{
// Copy instance and args to local frame
const int param_count = ms->param_count();
for (int i=0, n = _argc < param_count ? _argc : param_count; i <= n; i++)
framep[i] = _atomv[i];
// Store original value of argc for createRest and createArguments.
// argc may be changed by the optional parameter check below.
int arguments_argc = _argc;
// Set optional param values. these not aliased to arguments[] since arguments[]
// only present with traditional prototype functions (no optional args)
if (info->hasOptional())
{
if (_argc < param_count)
{
// initialize default values
for (int i=_argc+1, o=_argc + ms->optional_count() - param_count, n=param_count; i <= n; i++, o++)
framep[i] = ms->getDefaultValue(o);
_argc = param_count;
}
}
// Set remaining locals to undefined. Don't have to init scope or stack because
// our conservative GC scan knows how to ignore garbage.
for (Atom *p = framep + 1 + param_count; p < scopeBase; p++)
*p = undefinedAtom;
// Capture arguments or rest array.
if (info->needRest())
{
framep[param_count+1] = env->createRest(_atomv, arguments_argc)->atom();
}
else if (info->needArguments())
{
// create arguments using atomv[1..argc].
// Even tho E3 says create an Object, E4 says create an Array so thats what we will do.
framep[param_count+1] = env->createArguments(_atomv, arguments_argc)->atom();
}
#ifdef DEBUGGER
// in debugger builds, ensure that non-active scope entries are nulled out
// (really only need to do so if there's a debugger active, but not really worth checking for)
for (int i = 0; i < ms->max_scope(); ++i)
scopeBase[i] = nullObjectAtom;
#endif
}
#ifdef DEBUGGER
CallStackNode* volatile callStackNode = NULL;
#ifndef VMCFG_WORDCODE
if (core->debugger())
{
callStackNode = new ((char*)aux_memory + offsetof(InterpreterAuxiliaryFrameWithCSN, cs)) CallStackNode(env, (FramePtr)framep, /*frameTraits*/0, &expc);
env->debugEnterInner();
}
#endif
#endif
// NEXT dispatches the next instruction.
//
// U30ARG picks up a variable-length unsigned integer argument from the instruction
// stream and advances the PC.
//
// U8ARG picks up a fixed-length unsigned byte argument from the instruction stream
// and advances the PC.
//
// S24ARG picks up a fixed-length signed integer argument from the instruction stream
// and advances the PC.
//
// SAVE_EXPC and variants saves the address of the current opcode in the local 'expc'.
// Used in the case of exceptions.
#ifdef AVMPLUS_VERBOSE
# define VERBOSE if (pool->isVerbose(VB_interp, info)) showState(info, codeStart, pc-1, framep, sp, scopeDepth, scopeBase, ms->max_scope())
#else
# define VERBOSE
#endif
#ifdef VMCFG_WORDCODE
# if defined VMCFG_DIRECT_THREADED
# if defined GNUC_THREADING
# define INSTR(op) L_##op: VERBOSE;
# define NEXT goto *(*pc++)
# elif defined MSVC_X86_REWRITE_THREADING
# define INSTR(op) case WOP_##op: L_ ## op: VERBOSE;
# define NEXT continue
# elif defined MSVC_X86_ASM_THREADING
# define INSTR(op) L_ ## op: VERBOSE;
# define NEXT __asm { \
__asm mov ebx, pc \
__asm mov eax, [ebx] \
__asm add ebx, 4 \
__asm mov pc, ebx \
__asm jmp eax \
}
# endif // threading discipline
# else // VMCFG_DIRECT_THREADED
# define INSTR(op) case WOP_##op: VERBOSE;
# define NEXT continue
# endif
# define U30ARG (*pc++)
# define U8ARG (*pc++)
# define S24ARG (intptr_t)(*pc++)
# ifdef DEBUGGER
// expc is visible outside this function, so make sure it's correct.
// It's probably possible to adjust it on demand outside the function too,
// because code that accesses it will have access to "info" and can
// perform the adjustment.
# define SAVE_EXPC expc = pc-1-info->word_code_start()
# define SAVE_EXPC_TARGET(off) expc = pc + (off) - info->word_code_start()
# else
// Adjusted on demand in the CATCH clause. Reduces size of interpreter function
// by 2.5KB of object code (x86 / gcc4.0 / -O3).
# define SAVE_EXPC expc = (intptr_t)pc
# define SAVE_EXPC_TARGET(off) expc = (intptr_t)(pc + (off) + 1)
# endif
#else // !VMCFG_WORDCODE
# define INSTR(op) case OP_##op: VERBOSE;
# define NEXT continue
# define U30ARG (tmp_pc=pc, tmp_u30 = uint32_t(readU30(tmp_pc)), pc = tmp_pc, tmp_u30)
# define U8ARG (*pc++)
# define S24ARG (pc+=3, readS24(pc-3))
# define SAVE_EXPC expc = pc-1-codeStart
# define SAVE_EXPC_TARGET(off) expc = pc + (off) - codeStart
#endif // VMCFG_WORDCODE
// The following variables are here for the following purposes:
//
// - parameter passing between shared bytecode bodies
//
// - reducing the size of the stack frame on compilers that allocate
// individual frame slots to individual block-scoped variables.
// Visual C++ is particularly bad.
//
// Please do not initialize these variables.
//
// Please do not remove the 'register' qualifier. The variables are so
// qualified so that their addresses can't be taken.
//
// Please do not try to put any of these in a union together.
register Atom a1, a2, a3;
register Atom* a2p;
register intptr_t i1, i2;
register uintptr_t u1, u2;
register uintptr_t u1t, u2t, u3t; // private to the generic arithmetic macros
register double d1, d2;
register bool b1;
register uint8_t ub2;
register ScriptObject *o1;
register const Multiname* multiname;
register MethodEnv* f;
register Traits* t1;
uint16_t uh2l; // not register - its address /can/ be taken
int32_t i32l; // ditto
float f2l; // ditto
double d2l; // ditto
#ifdef VMCFG_FLOAT
float4_t f4l; // ditto
#endif
Atom a1l; // ditto
#ifndef VMCFG_WORDCODE
register uint32_t tmp_u30;
const bytecode_t* tmp_pc;