Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1413863010: [Interpreter] Add wide varients of bytecodes with feedback and constant pool indexes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_fixbuiltinstacklimit
Patch Set: Rebased Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const char* function_name) { 48 const char* function_name) {
49 CompileRun(script); 49 CompileRun(script);
50 Local<Function> function = 50 Local<Function> function =
51 Local<Function>::Cast(CcTest::global()->Get(v8_str(function_name))); 51 Local<Function>::Cast(CcTest::global()->Get(v8_str(function_name)));
52 i::Handle<i::JSFunction> js_function = 52 i::Handle<i::JSFunction> js_function =
53 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function)); 53 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function));
54 return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate()); 54 return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate());
55 } 55 }
56 56
57 Handle<BytecodeArray> MakeBytecodeForFunctionBody(const char* body) { 57 Handle<BytecodeArray> MakeBytecodeForFunctionBody(const char* body) {
58 ScopedVector<char> program(1024); 58 ScopedVector<char> program(3072);
59 SNPrintF(program, "function %s() { %s }\n%s();", kFunctionName, body, 59 SNPrintF(program, "function %s() { %s }\n%s();", kFunctionName, body,
60 kFunctionName); 60 kFunctionName);
61 return MakeBytecode(program.start(), kFunctionName); 61 return MakeBytecode(program.start(), kFunctionName);
62 } 62 }
63 63
64 Handle<BytecodeArray> MakeBytecodeForFunction(const char* function) { 64 Handle<BytecodeArray> MakeBytecodeForFunction(const char* function) {
65 ScopedVector<char> program(1024); 65 ScopedVector<char> program(3072);
66 SNPrintF(program, "%s\n%s();", function, kFunctionName); 66 SNPrintF(program, "%s\n%s();", function, kFunctionName);
67 return MakeBytecode(program.start(), kFunctionName); 67 return MakeBytecode(program.start(), kFunctionName);
68 } 68 }
69 69
70 Handle<BytecodeArray> MakeBytecodeForFunctionNoFilter(const char* function) { 70 Handle<BytecodeArray> MakeBytecodeForFunctionNoFilter(const char* function) {
71 const char* old_ignition_filter = i::FLAG_ignition_filter; 71 const char* old_ignition_filter = i::FLAG_ignition_filter;
72 i::FLAG_ignition_filter = "*"; 72 i::FLAG_ignition_filter = "*";
73 ScopedVector<char> program(1024); 73 ScopedVector<char> program(3072);
74 SNPrintF(program, "%s\n%s();", function, kFunctionName); 74 SNPrintF(program, "%s\n%s();", function, kFunctionName);
75 Handle<BytecodeArray> return_val = 75 Handle<BytecodeArray> return_val =
76 MakeBytecode(program.start(), kFunctionName); 76 MakeBytecode(program.start(), kFunctionName);
77 i::FLAG_ignition_filter = old_ignition_filter; 77 i::FLAG_ignition_filter = old_ignition_filter;
78 return return_val; 78 return return_val;
79 } 79 }
80 }; 80 };
81 81
82 82
83 // Helper macros for handcrafting bytecode sequences. 83 // Helper macros for handcrafting bytecode sequences.
84 #define B(x) static_cast<uint8_t>(Bytecode::k##x) 84 #define B(x) static_cast<uint8_t>(Bytecode::k##x)
85 #define U8(x) static_cast<uint8_t>((x) & 0xff) 85 #define U8(x) static_cast<uint8_t>((x) & 0xff)
86 #define R(x) static_cast<uint8_t>(-(x) & 0xff) 86 #define R(x) static_cast<uint8_t>(-(x) & 0xff)
87 #define A(x, n) R(helper.kLastParamIndex - (n) + 1 + (x)) 87 #define A(x, n) R(helper.kLastParamIndex - (n) + 1 + (x))
88 #define THIS(n) A(0, n) 88 #define THIS(n) A(0, n)
89 #if defined(V8_TARGET_LITTLE_ENDIAN) 89 #if defined(V8_TARGET_LITTLE_ENDIAN)
90 #define U16(x) static_cast<uint8_t>((x) & 0xff), \ 90 #define U16(x) static_cast<uint8_t>((x) & 0xff), \
91 static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff) 91 static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff)
92 #elif defined(V8_TARGET_BIG_ENDIAN) 92 #elif defined(V8_TARGET_BIG_ENDIAN)
93 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ 93 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \
94 static_cast<uint8_t>((x) & 0xff) 94 static_cast<uint8_t>((x) & 0xff)
95 #else 95 #else
96 #error Unknown byte ordering 96 #error Unknown byte ordering
97 #endif 97 #endif
98 98
99 #define COMMA() ,
100 #define SPACE()
101
102 #define REPEAT_2(SEP, ...) \
103 __VA_ARGS__ SEP() __VA_ARGS__
104 #define REPEAT_4(SEP, ...) \
105 REPEAT_2(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__)
106 #define REPEAT_8(SEP, ...) \
107 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_4(SEP, __VA_ARGS__)
108 #define REPEAT_16(SEP, ...) \
109 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__)
110 #define REPEAT_32(SEP, ...) \
111 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__)
112 #define REPEAT_64(SEP, ...) \
113 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__)
114 #define REPEAT_128(SEP, ...) \
115 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__)
116 #define REPEAT_256(SEP, ...) \
117 REPEAT_128(SEP, __VA_ARGS__) SEP() REPEAT_128(SEP, __VA_ARGS__)
118
119 #define REPEAT_127(SEP, ...) \
120 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) SEP() \
121 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) SEP() \
122 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() \
123 __VA_ARGS__
99 124
100 // Structure for containing expected bytecode snippets. 125 // Structure for containing expected bytecode snippets.
101 template<typename T> 126 template<typename T, int C = 6>
102 struct ExpectedSnippet { 127 struct ExpectedSnippet {
103 const char* code_snippet; 128 const char* code_snippet;
104 int frame_size; 129 int frame_size;
105 int parameter_count; 130 int parameter_count;
106 int bytecode_length; 131 int bytecode_length;
107 const uint8_t bytecode[512]; 132 const uint8_t bytecode[2048];
108 int constant_count; 133 int constant_count;
109 T constants[6]; 134 T constants[C];
110 }; 135 };
111 136
112 137
113 static void CheckConstant(int expected, Object* actual) { 138 static void CheckConstant(int expected, Object* actual) {
114 CHECK_EQ(expected, Smi::cast(actual)->value()); 139 CHECK_EQ(expected, Smi::cast(actual)->value());
115 } 140 }
116 141
117 142
118 static void CheckConstant(double expected, Object* actual) { 143 static void CheckConstant(double expected, Object* actual) {
119 CHECK_EQ(expected, HeapNumber::cast(actual)->value()); 144 CHECK_EQ(expected, HeapNumber::cast(actual)->value());
(...skipping 10 matching lines...) Expand all
130 static void CheckConstant(Handle<Object> expected, Object* actual) { 155 static void CheckConstant(Handle<Object> expected, Object* actual) {
131 CHECK(actual == *expected || expected->StrictEquals(actual)); 156 CHECK(actual == *expected || expected->StrictEquals(actual));
132 } 157 }
133 158
134 159
135 static void CheckConstant(InstanceType expected, Object* actual) { 160 static void CheckConstant(InstanceType expected, Object* actual) {
136 CHECK_EQ(expected, HeapObject::cast(actual)->map()->instance_type()); 161 CHECK_EQ(expected, HeapObject::cast(actual)->map()->instance_type());
137 } 162 }
138 163
139 164
140 template <typename T> 165 template <typename T, int C>
141 static void CheckBytecodeArrayEqual(const ExpectedSnippet<T>& expected, 166 static void CheckBytecodeArrayEqual(const ExpectedSnippet<T, C>& expected,
142 Handle<BytecodeArray> actual) { 167 Handle<BytecodeArray> actual) {
143 CHECK_EQ(expected.frame_size, actual->frame_size()); 168 CHECK_EQ(expected.frame_size, actual->frame_size());
144 CHECK_EQ(expected.parameter_count, actual->parameter_count()); 169 CHECK_EQ(expected.parameter_count, actual->parameter_count());
145 CHECK_EQ(expected.bytecode_length, actual->length()); 170 CHECK_EQ(expected.bytecode_length, actual->length());
146 if (expected.constant_count == 0) { 171 if (expected.constant_count == 0) {
147 CHECK_EQ(CcTest::heap()->empty_fixed_array(), actual->constant_pool()); 172 CHECK_EQ(CcTest::heap()->empty_fixed_array(), actual->constant_pool());
148 } else { 173 } else {
149 CHECK_EQ(expected.constant_count, actual->constant_pool()->length()); 174 CHECK_EQ(expected.constant_count, actual->constant_pool()->length());
150 for (int i = 0; i < expected.constant_count; i++) { 175 for (int i = 0; i < expected.constant_count; i++) {
151 CheckConstant(expected.constants[i], actual->constant_pool()->get(i)); 176 CheckConstant(expected.constants[i], actual->constant_pool()->get(i));
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 B(LdaSmi8), U8(4), // 443 B(LdaSmi8), U8(4), //
419 B(Star), R(2), // 444 B(Star), R(2), //
420 B(Ldar), R(0), // 445 B(Ldar), R(0), //
421 B(JumpIfToBooleanTrue), U8(8), // 446 B(JumpIfToBooleanTrue), U8(8), //
422 B(LdaSmi8), U8(5), // 447 B(LdaSmi8), U8(5), //
423 B(Star), R(2), // 448 B(Star), R(2), //
424 B(LdaSmi8), U8(3), // 449 B(LdaSmi8), U8(3), //
425 B(Return)}, 450 B(Return)},
426 0}, 451 0},
427 {"var x = 1; var a = 2, b = 3; return x || (" 452 {"var x = 1; var a = 2, b = 3; return x || ("
428 #define X "a = 1, b = 2, " 453 REPEAT_32(SPACE, "a = 1, b = 2, ")
429 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
430 #undef X
431 "3);", 454 "3);",
432 3 * kPointerSize, 455 3 * kPointerSize,
433 1, 456 1,
434 283, 457 275,
435 {B(LdaSmi8), U8(1), // 458 {B(LdaSmi8), U8(1), //
436 B(Star), R(0), // 459 B(Star), R(0), //
437 B(LdaSmi8), U8(2), // 460 B(LdaSmi8), U8(2), //
438 B(Star), R(1), // 461 B(Star), R(1), //
439 B(LdaSmi8), U8(3), // 462 B(LdaSmi8), U8(3), //
440 B(Star), R(2), // 463 B(Star), R(2), //
441 B(Ldar), R(0), // 464 B(Ldar), R(0), //
442 B(JumpIfToBooleanTrueConstant), U8(0), // 465 B(JumpIfToBooleanTrueConstant), U8(0), //
443 #define X B(LdaSmi8), U8(1), B(Star), R(1), B(LdaSmi8), U8(2), B(Star), R(2), 466 REPEAT_32(COMMA, //
444 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X 467 B(LdaSmi8), U8(1), //
445 #undef X 468 B(Star), R(1), //
469 B(LdaSmi8), U8(2), //
470 B(Star), R(2)), //
446 B(LdaSmi8), U8(3), // 471 B(LdaSmi8), U8(3), //
447 B(Return)}, 472 B(Return)},
448 1, 473 1,
449 {268, 0, 0, 0}}, 474 {260, 0, 0, 0}},
450 {"var x = 0; var a = 2, b = 3; return x && (" 475 {"var x = 0; var a = 2, b = 3; return x && ("
451 #define X "a = 1, b = 2, " 476 REPEAT_32(SPACE, "a = 1, b = 2, ")
452 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
453 #undef X
454 "3);", 477 "3);",
455 3 * kPointerSize, 478 3 * kPointerSize,
456 1, 479 1,
457 282, 480 274,
458 {B(LdaZero), // 481 {B(LdaZero), //
459 B(Star), R(0), // 482 B(Star), R(0), //
460 B(LdaSmi8), U8(2), // 483 B(LdaSmi8), U8(2), //
461 B(Star), R(1), // 484 B(Star), R(1), //
462 B(LdaSmi8), U8(3), // 485 B(LdaSmi8), U8(3), //
463 B(Star), R(2), // 486 B(Star), R(2), //
464 B(Ldar), R(0), // 487 B(Ldar), R(0), //
465 B(JumpIfToBooleanFalseConstant), U8(0), // 488 B(JumpIfToBooleanFalseConstant), U8(0), //
466 #define X B(LdaSmi8), U8(1), B(Star), R(1), B(LdaSmi8), U8(2), B(Star), R(2), 489 REPEAT_32(COMMA, //
467 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X 490 B(LdaSmi8), U8(1), //
468 #undef X 491 B(Star), R(1), //
469 B(LdaSmi8), U8(3), // 492 B(LdaSmi8), U8(2), //
470 B(Return)}, 493 B(Star), R(2)), //
494 B(LdaSmi8), U8(3), //
495 B(Return)}, //
471 1, 496 1,
472 {268, 0, 0, 0}}, 497 {260, 0, 0, 0}},
473 {"return 0 && 3;", 498 {"return 0 && 3;",
474 0 * kPointerSize, 499 0 * kPointerSize,
475 1, 500 1,
476 2, 501 2,
477 {B(LdaZero), // 502 {B(LdaZero), //
478 B(Return)}, 503 B(Return)},
479 0}, 504 0},
480 {"return 1 || 3;", 505 {"return 1 || 3;",
481 0 * kPointerSize, 506 0 * kPointerSize,
482 1, 507 1,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 640 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
616 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 641 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
617 } 642 }
618 } 643 }
619 644
620 645
621 TEST(HeapNumberConstants) { 646 TEST(HeapNumberConstants) {
622 InitializedHandleScope handle_scope; 647 InitializedHandleScope handle_scope;
623 BytecodeGeneratorHelper helper; 648 BytecodeGeneratorHelper helper;
624 649
625 ExpectedSnippet<double> snippets[] = { 650 int wide_idx = 0;
651
652 ExpectedSnippet<double, 257> snippets[] = {
626 {"return 1.2;", 653 {"return 1.2;",
627 0, 654 0,
628 1, 655 1,
629 3, 656 3,
630 { 657 {
631 B(LdaConstant), U8(0), // 658 B(LdaConstant), U8(0), //
632 B(Return) // 659 B(Return) //
633 }, 660 },
634 1, 661 1,
635 {1.2}}, 662 {1.2}},
(...skipping 13 matching lines...) Expand all
649 1 * kPointerSize, 676 1 * kPointerSize,
650 1, 677 1,
651 7, 678 7,
652 { 679 {
653 B(LdaConstant), U8(0), // 680 B(LdaConstant), U8(0), //
654 B(Star), R(0), // 681 B(Star), R(0), //
655 B(LdaConstant), U8(1), // 682 B(LdaConstant), U8(1), //
656 B(Return) // 683 B(Return) //
657 }, 684 },
658 2, 685 2,
659 {3.14, 3.14}}}; 686 {3.14, 3.14}},
687 {"var a;"
688 REPEAT_256(SPACE, " a = 1.414;")
689 " a = 3.14;",
690 1 * kPointerSize,
691 1,
692 1031,
693 {
694 REPEAT_256(COMMA, //
695 B(LdaConstant), U8(wide_idx++), //
696 B(Star), R(0)), //
697 B(LdaConstantWide), U16(wide_idx++), //
698 B(Star), R(0), //
699 B(LdaUndefined), //
700 B(Return), //
701 },
702 257,
703 {REPEAT_256(COMMA, 1.414),
704 3.14}}
705 };
660 for (size_t i = 0; i < arraysize(snippets); i++) { 706 for (size_t i = 0; i < arraysize(snippets); i++) {
661 Handle<BytecodeArray> bytecode_array = 707 Handle<BytecodeArray> bytecode_array =
662 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 708 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
663 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 709 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
664 } 710 }
665 } 711 }
666 712
667 713
668 TEST(StringConstants) { 714 TEST(StringConstants) {
669 InitializedHandleScope handle_scope; 715 InitializedHandleScope handle_scope;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 BytecodeGeneratorHelper helper; 764 BytecodeGeneratorHelper helper;
719 Zone zone; 765 Zone zone;
720 766
721 FeedbackVectorSpec feedback_spec(&zone); 767 FeedbackVectorSpec feedback_spec(&zone);
722 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); 768 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
723 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); 769 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot();
724 770
725 Handle<i::TypeFeedbackVector> vector = 771 Handle<i::TypeFeedbackVector> vector =
726 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 772 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
727 773
774 // These are a hack used by the LoadICXXXWide tests below.
775 int wide_idx_1 = vector->GetIndex(slot1) - 2;
776 int wide_idx_2 = vector->GetIndex(slot1) - 2;
777 int wide_idx_3 = vector->GetIndex(slot1) - 2;
778 int wide_idx_4 = vector->GetIndex(slot1) - 2;
779
728 ExpectedSnippet<const char*> snippets[] = { 780 ExpectedSnippet<const char*> snippets[] = {
729 {"function f(a) { return a.name; }\nf({name : \"test\"})", 781 {"function f(a) { return a.name; }\nf({name : \"test\"})",
730 0, 782 0,
731 2, 783 2,
732 5, 784 5,
733 { 785 {
734 B(LoadICSloppy), A(1, 2), U8(0), U8(vector->GetIndex(slot1)), // 786 B(LoadICSloppy), A(1, 2), U8(0), U8(vector->GetIndex(slot1)), //
735 B(Return), // 787 B(Return), //
736 }, 788 },
737 1, 789 1,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 "function f(a, b) { \"use strict\"; return a[b]; }\n" 846 "function f(a, b) { \"use strict\"; return a[b]; }\n"
795 "f({arg : \"test\"}, \"arg\")", 847 "f({arg : \"test\"}, \"arg\")",
796 0, 848 0,
797 3, 849 3,
798 6, 850 6,
799 { 851 {
800 B(Ldar), A(2, 3), // 852 B(Ldar), A(2, 3), //
801 B(KeyedLoadICStrict), A(1, 3), U8(vector->GetIndex(slot1)), // 853 B(KeyedLoadICStrict), A(1, 3), U8(vector->GetIndex(slot1)), //
802 B(Return), // 854 B(Return), //
803 }, 855 },
804 0, 856 0},
805 }}; 857 {
858 "function f(a) {\n"
859 " var b;\n"
860 REPEAT_127(SPACE, " b = a.name; ")
861 " return a.name; }\n"
862 "f({name : \"test\"})\n",
863 1 * kPointerSize,
864 2,
865 769,
866 {
867 REPEAT_127(COMMA, //
868 B(LoadICSloppy), A(1, 2), U8(0), U8((wide_idx_1 += 2)), //
869 B(Star), R(0)), //
870 B(LoadICSloppyWide), A(1, 2), U16(0), U16(wide_idx_1 += 2), //
871 B(Return), //
872 },
873 1,
874 {"name"}},
875 {
876 "function f(a) {\n"
877 " 'use strict'; var b;\n"
878 REPEAT_127(SPACE, " b = a.name; ")
879 " return a.name; }\n"
880 "f({name : \"test\"})\n",
881 1 * kPointerSize,
882 2,
883 769,
884 {
885 REPEAT_127(COMMA, //
886 B(LoadICStrict), A(1, 2), U8(0), U8((wide_idx_2 += 2)), //
887 B(Star), R(0)), //
888 B(LoadICStrictWide), A(1, 2), U16(0), U16(wide_idx_2 += 2), //
889 B(Return), //
890 },
891 1,
892 {"name"}},
893 {
894 "function f(a, b) {\n"
895 " var c;\n"
896 REPEAT_127(SPACE, " c = a[b]; ")
897 " return a[b]; }\n"
898 "f({name : \"test\"}, \"name\")\n",
899 1 * kPointerSize,
900 3,
901 896,
902 {
903 REPEAT_127(COMMA, //
904 B(Ldar), A(2, 3), //
905 B(KeyedLoadICSloppy), A(1, 3), U8((wide_idx_3 += 2)), //
906 B(Star), R(0)), //
907 B(Ldar), A(2, 3), //
908 B(KeyedLoadICSloppyWide), A(1, 3), U16(wide_idx_3 += 2), //
909 B(Return), //
910 }},
911 {
912 "function f(a, b) {\n"
913 " 'use strict'; var c;\n"
914 REPEAT_127(SPACE, " c = a[b]; ")
915 " return a[b]; }\n"
916 "f({name : \"test\"}, \"name\")\n",
917 1 * kPointerSize,
918 3,
919 896,
920 {
921 REPEAT_127(COMMA, //
922 B(Ldar), A(2, 3), //
923 B(KeyedLoadICStrict), A(1, 3), U8((wide_idx_4 += 2)), //
924 B(Star), R(0)), //
925 B(Ldar), A(2, 3), //
926 B(KeyedLoadICStrictWide), A(1, 3), U16(wide_idx_4 += 2), //
927 B(Return), //
928 }},
929 };
806 for (size_t i = 0; i < arraysize(snippets); i++) { 930 for (size_t i = 0; i < arraysize(snippets); i++) {
807 Handle<BytecodeArray> bytecode_array = 931 Handle<BytecodeArray> bytecode_array =
808 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 932 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
809 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 933 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
810 } 934 }
811 } 935 }
812 936
813 937
814 TEST(PropertyStores) { 938 TEST(PropertyStores) {
815 InitializedHandleScope handle_scope; 939 InitializedHandleScope handle_scope;
816 BytecodeGeneratorHelper helper; 940 BytecodeGeneratorHelper helper;
817 Zone zone; 941 Zone zone;
818 942
819 FeedbackVectorSpec feedback_spec(&zone); 943 FeedbackVectorSpec feedback_spec(&zone);
820 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot(); 944 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot();
821 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); 945 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
822 946
823 Handle<i::TypeFeedbackVector> vector = 947 Handle<i::TypeFeedbackVector> vector =
824 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 948 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
825 949
950 // These are a hack used by the StoreICXXXWide tests below.
951 int wide_idx_1 = vector->GetIndex(slot1) - 2;
952 int wide_idx_2 = vector->GetIndex(slot1) - 2;
953 int wide_idx_3 = vector->GetIndex(slot1) - 2;
954 int wide_idx_4 = vector->GetIndex(slot1) - 2;
955
826 ExpectedSnippet<const char*> snippets[] = { 956 ExpectedSnippet<const char*> snippets[] = {
827 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})", 957 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})",
828 0, 958 0,
829 2, 959 2,
830 8, 960 8,
831 { 961 {
832 B(LdaConstant), U8(1), // 962 B(LdaConstant), U8(1), //
833 B(StoreICSloppy), A(1, 2), U8(0), U8(vector->GetIndex(slot1)), // 963 B(StoreICSloppy), A(1, 2), U8(0), U8(vector->GetIndex(slot1)), //
834 B(LdaUndefined), // 964 B(LdaUndefined), //
835 B(Return), // 965 B(Return), //
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 3, 1039 3,
910 8, 1040 8,
911 { 1041 {
912 B(LdaConstant), U8(0), // 1042 B(LdaConstant), U8(0), //
913 B(KeyedStoreICStrict), A(1, 3), A(2, 3), // 1043 B(KeyedStoreICStrict), A(1, 3), A(2, 3), //
914 U8(vector->GetIndex(slot1)), // 1044 U8(vector->GetIndex(slot1)), //
915 B(LdaUndefined), // 1045 B(LdaUndefined), //
916 B(Return), // 1046 B(Return), //
917 }, 1047 },
918 1, 1048 1,
919 {"val"}}}; 1049 {"val"}},
1050 {"function f(a) {\n"
1051 REPEAT_127(SPACE, " a.name = 1; ")
1052 " a.name = 2; }\n"
1053 "f({name : \"test\"})\n",
1054 0,
1055 2,
1056 772,
1057 {
1058 REPEAT_127(COMMA, //
1059 B(LdaSmi8), U8(1), //
1060 B(StoreICSloppy), A(1, 2), U8(0), U8((wide_idx_1 += 2))), //
1061 B(LdaSmi8), U8(2), //
1062 B(StoreICSloppyWide), A(1, 2), U16(0), U16(wide_idx_1 += 2), //
1063 B(LdaUndefined), //
1064 B(Return), //
1065 },
1066 1,
1067 {"name"}},
1068 {"function f(a) {\n"
1069 "'use strict';\n"
1070 REPEAT_127(SPACE, " a.name = 1; ")
1071 " a.name = 2; }\n"
1072 "f({name : \"test\"})\n",
1073 0,
1074 2,
1075 772,
1076 {
1077 REPEAT_127(COMMA, //
1078 B(LdaSmi8), U8(1), //
1079 B(StoreICStrict), A(1, 2), U8(0), U8((wide_idx_2 += 2))), //
1080 B(LdaSmi8), U8(2), //
1081 B(StoreICStrictWide), A(1, 2), U16(0), U16(wide_idx_2 += 2), //
1082 B(LdaUndefined), //
1083 B(Return), //
1084 },
1085 1,
1086 {"name"}},
1087 {"function f(a, b) {\n"
1088 REPEAT_127(SPACE, " a[b] = 1; ")
1089 " a[b] = 2; }\n"
1090 "f({name : \"test\"})\n",
1091 0,
1092 3,
1093 771,
1094 {
1095 REPEAT_127(COMMA, //
1096 B(LdaSmi8), U8(1), //
1097 B(KeyedStoreICSloppy), A(1, 3), A(2, 3), //
1098 U8((wide_idx_3 += 2))), //
1099 B(LdaSmi8), U8(2), //
1100 B(KeyedStoreICSloppyWide), A(1, 3), A(2, 3), //
1101 U16(wide_idx_3 += 2), //
1102 B(LdaUndefined), //
1103 B(Return), //
1104 }},
1105 {"function f(a, b) {\n"
1106 "'use strict';\n"
1107 REPEAT_127(SPACE, " a[b] = 1; ")
1108 " a[b] = 2; }\n"
1109 "f({name : \"test\"})\n",
1110 0,
1111 3,
1112 771,
1113 {
1114 REPEAT_127(COMMA, //
1115 B(LdaSmi8), U8(1), //
1116 B(KeyedStoreICStrict), A(1, 3), A(2, 3), //
1117 U8((wide_idx_4 += 2))), //
1118 B(LdaSmi8), U8(2), //
1119 B(KeyedStoreICStrictWide), A(1, 3), A(2, 3), //
1120 U16(wide_idx_4 += 2), //
1121 B(LdaUndefined), //
1122 B(Return), //
1123 }}};
920 for (size_t i = 0; i < arraysize(snippets); i++) { 1124 for (size_t i = 0; i < arraysize(snippets); i++) {
921 Handle<BytecodeArray> bytecode_array = 1125 Handle<BytecodeArray> bytecode_array =
922 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 1126 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
923 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1127 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
924 } 1128 }
925 } 1129 }
926 1130
927 1131
928 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()" 1132 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()"
929 1133
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 InitializedHandleScope handle_scope; 1209 InitializedHandleScope handle_scope;
1006 BytecodeGeneratorHelper helper; 1210 BytecodeGeneratorHelper helper;
1007 Zone zone; 1211 Zone zone;
1008 1212
1009 FeedbackVectorSpec feedback_spec(&zone); 1213 FeedbackVectorSpec feedback_spec(&zone);
1010 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); 1214 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot();
1011 1215
1012 Handle<i::TypeFeedbackVector> vector = 1216 Handle<i::TypeFeedbackVector> vector =
1013 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 1217 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
1014 1218
1219 // These are a hack used by the LdaGlobalXXXWide tests below.
1220 int wide_idx_1 = vector->GetIndex(slot) - 2;
1221 int wide_idx_2 = vector->GetIndex(slot) - 2;
1222
1015 ExpectedSnippet<const char*> snippets[] = { 1223 ExpectedSnippet<const char*> snippets[] = {
1016 {"var a = 1;\nfunction f() { return a; }\nf()", 1224 {"var a = 1;\nfunction f() { return a; }\nf()",
1017 0, 1225 0,
1018 1, 1226 1,
1019 4, 1227 4,
1020 { 1228 {
1021 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // 1229 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
1022 B(Return) // 1230 B(Return) //
1023 }, 1231 },
1024 1, 1232 1,
(...skipping 21 matching lines...) Expand all
1046 {"a = 1;\nfunction f() { return a; }\nf()", 1254 {"a = 1;\nfunction f() { return a; }\nf()",
1047 0, 1255 0,
1048 1, 1256 1,
1049 4, 1257 4,
1050 { 1258 {
1051 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // 1259 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
1052 B(Return) // 1260 B(Return) //
1053 }, 1261 },
1054 1, 1262 1,
1055 {"a"}}, 1263 {"a"}},
1264 {"a = 1; function f(b) {\n"
1265 REPEAT_127(SPACE, "b.name; ")
1266 " return a; }\nf({name: 1});",
1267 0,
1268 2,
1269 514,
1270 {
1271 REPEAT_127(COMMA, //
1272 B(LoadICSloppy), A(1, 2), U8(0), U8(wide_idx_1 += 2)), //
1273 B(LdaGlobalSloppyWide), U16(1), U16(wide_idx_1 += 2), //
1274 B(Return), //
1275 },
1276 2,
1277 {"name", "a"}},
1278 {"a = 1; function f(b) {\n"
1279 " 'use strict';\n"
1280 REPEAT_127(SPACE, "b.name; ")
1281 " return a; }\nf({name: 1});",
1282 0,
1283 2,
1284 514,
1285 {
1286 REPEAT_127(COMMA, //
1287 B(LoadICStrict), A(1, 2), U8(0), U8(wide_idx_2 += 2)), //
1288 B(LdaGlobalStrictWide), U16(1), U16(wide_idx_2 += 2), //
1289 B(Return), //
1290 },
1291 2,
1292 {"name", "a"}},
1056 }; 1293 };
1057 1294
1058 for (size_t i = 0; i < arraysize(snippets); i++) { 1295 for (size_t i = 0; i < arraysize(snippets); i++) {
1059 Handle<BytecodeArray> bytecode_array = 1296 Handle<BytecodeArray> bytecode_array =
1060 helper.MakeBytecode(snippets[i].code_snippet, "f"); 1297 helper.MakeBytecode(snippets[i].code_snippet, "f");
1061 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1298 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1062 } 1299 }
1063 } 1300 }
1064 1301
1065 1302
1066 TEST(StoreGlobal) { 1303 TEST(StoreGlobal) {
1067 InitializedHandleScope handle_scope; 1304 InitializedHandleScope handle_scope;
1068 BytecodeGeneratorHelper helper; 1305 BytecodeGeneratorHelper helper;
1069 Zone zone; 1306 Zone zone;
1070 1307
1071 FeedbackVectorSpec feedback_spec(&zone); 1308 FeedbackVectorSpec feedback_spec(&zone);
1072 FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); 1309 FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot();
1073 1310
1074 Handle<i::TypeFeedbackVector> vector = 1311 Handle<i::TypeFeedbackVector> vector =
1075 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 1312 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
1076 1313
1314 // These are a hack used by the StaGlobalXXXWide tests below.
1315 int wide_idx_1 = vector->GetIndex(slot) - 2;
1316 int wide_idx_2 = vector->GetIndex(slot) - 2;
1317
1077 ExpectedSnippet<const char*> snippets[] = { 1318 ExpectedSnippet<const char*> snippets[] = {
1078 {"var a = 1;\nfunction f() { a = 2; }\nf()", 1319 {"var a = 1;\nfunction f() { a = 2; }\nf()",
1079 0, 1320 0,
1080 1, 1321 1,
1081 7, 1322 7,
1082 { 1323 {
1083 B(LdaSmi8), U8(2), // 1324 B(LdaSmi8), U8(2), //
1084 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // 1325 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
1085 B(LdaUndefined), // 1326 B(LdaUndefined), //
1086 B(Return) // 1327 B(Return) //
(...skipping 29 matching lines...) Expand all
1116 1, 1357 1,
1117 7, 1358 7,
1118 { 1359 {
1119 B(LdaSmi8), U8(2), // 1360 B(LdaSmi8), U8(2), //
1120 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // 1361 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
1121 B(LdaUndefined), // 1362 B(LdaUndefined), //
1122 B(Return) // 1363 B(Return) //
1123 }, 1364 },
1124 1, 1365 1,
1125 {"a"}}, 1366 {"a"}},
1367 {"a = 1; function f(b) {\n"
1368 REPEAT_127(SPACE, "b.name; ")
1369 " a = 2; }\nf({name: 1});",
1370 0,
1371 2,
1372 517,
1373 {
1374 REPEAT_127(COMMA, //
1375 B(LoadICSloppy), A(1, 2), U8(0), U8(wide_idx_1 += 2)), //
1376 B(LdaSmi8), U8(2), //
1377 B(StaGlobalSloppyWide), U16(1), U16(wide_idx_1 += 2), //
1378 B(LdaUndefined), //
1379 B(Return), //
1380 },
1381 2,
1382 {"name", "a"}},
1383 {"a = 1; function f(b) {\n"
1384 " 'use strict';\n"
1385 REPEAT_127(SPACE, "b.name; ")
1386 " a = 2; }\nf({name: 1});",
1387 0,
1388 2,
1389 517,
1390 {
1391 REPEAT_127(COMMA, //
1392 B(LoadICStrict), A(1, 2), U8(0), U8(wide_idx_2 += 2)), //
1393 B(LdaSmi8), U8(2), //
1394 B(StaGlobalStrictWide), U16(1), U16(wide_idx_2 += 2), //
1395 B(LdaUndefined), //
1396 B(Return), //
1397 },
1398 2,
1399 {"name", "a"}},
1126 }; 1400 };
1127 1401
1128 for (size_t i = 0; i < arraysize(snippets); i++) { 1402 for (size_t i = 0; i < arraysize(snippets); i++) {
1129 Handle<BytecodeArray> bytecode_array = 1403 Handle<BytecodeArray> bytecode_array =
1130 helper.MakeBytecode(snippets[i].code_snippet, "f"); 1404 helper.MakeBytecode(snippets[i].code_snippet, "f");
1131 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1405 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1132 } 1406 }
1133 } 1407 }
1134 1408
1135 1409
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 B(TestIn), A(1, 3), // 1601 B(TestIn), A(1, 3), //
1328 B(JumpIfFalse), U8(5), // 1602 B(JumpIfFalse), U8(5), //
1329 B(LdaConstant), U8(0), // 1603 B(LdaConstant), U8(0), //
1330 B(Return), // 1604 B(Return), //
1331 B(LdaUndefined), // 1605 B(LdaUndefined), //
1332 B(Return)}, // 1606 B(Return)}, //
1333 1, 1607 1,
1334 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused, 1608 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused,
1335 unused}}, 1609 unused}},
1336 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " 1610 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { "
1337 #define X "b = a; a = b; " 1611 REPEAT_32(SPACE, "b = a; a = b; ")
1338 X X X X X X X X X X X X X X X X X X X X X X X X
1339 #undef X
1340 " return 200; } else { return -200; } } f(0.001)", 1612 " return 200; } else { return -200; } } f(0.001)",
1341 2 * kPointerSize, 1613 2 * kPointerSize,
1342 2, 1614 2,
1343 214, 1615 278,
1344 { 1616 {
1345 #define X B(Ldar), R(0), B(Star), R(1), B(Ldar), R(1), B(Star), R(0)
1346 B(LdaZero), // 1617 B(LdaZero), //
1347 B(Star), R(0), // 1618 B(Star), R(0), //
1348 B(LdaZero), // 1619 B(LdaZero), //
1349 B(Star), R(1), // 1620 B(Star), R(1), //
1350 B(LdaConstant), U8(0), // 1621 B(LdaConstant), U8(0), //
1351 B(TestEqualStrict), R(0), // 1622 B(TestEqualStrict), R(0), //
1352 B(JumpIfFalseConstant), U8(2), // 1623 B(JumpIfFalseConstant), U8(2), //
1353 X, X, X, X, X, X, X, X, X, X, // 1624 REPEAT_32(COMMA, //
1354 X, X, X, X, X, X, X, X, X, X, // 1625 B(Ldar), R(0), //
1355 X, X, X, X, // 1626 B(Star), R(1), //
1627 B(Ldar), R(1), //
1628 B(Star), R(0)), //
1356 B(LdaConstant), U8(1), // 1629 B(LdaConstant), U8(1), //
1357 B(Return), // 1630 B(Return), //
1358 B(Jump), U8(5), // 1631 B(Jump), U8(5), //
1359 B(LdaConstant), U8(3), // 1632 B(LdaConstant), U8(3), //
1360 B(Return), // 1633 B(Return), //
1361 B(LdaUndefined), // 1634 B(LdaUndefined), //
1362 B(Return)}, // 1635 B(Return)}, //
1363 #undef X
1364 4, 1636 4,
1365 {helper.factory()->NewHeapNumber(0.01), 1637 {helper.factory()->NewHeapNumber(0.01),
1366 helper.factory()->NewNumberFromInt(200), 1638 helper.factory()->NewNumberFromInt(200),
1367 helper.factory()->NewNumberFromInt(199), 1639 helper.factory()->NewNumberFromInt(263),
1368 helper.factory()->NewNumberFromInt(-200), unused, unused}}, 1640 helper.factory()->NewNumberFromInt(-200), unused, unused}},
1369 {"function f(a, b) {\n" 1641 {"function f(a, b) {\n"
1370 " if (a == b) { return 1; }\n" 1642 " if (a == b) { return 1; }\n"
1371 " if (a === b) { return 1; }\n" 1643 " if (a === b) { return 1; }\n"
1372 " if (a < b) { return 1; }\n" 1644 " if (a < b) { return 1; }\n"
1373 " if (a > b) { return 1; }\n" 1645 " if (a > b) { return 1; }\n"
1374 " if (a <= b) { return 1; }\n" 1646 " if (a <= b) { return 1; }\n"
1375 " if (a >= b) { return 1; }\n" 1647 " if (a >= b) { return 1; }\n"
1376 " if (a in b) { return 1; }\n" 1648 " if (a in b) { return 1; }\n"
1377 " if (a instanceof b) { return 1; }\n" 1649 " if (a instanceof b) { return 1; }\n"
1378 " return 0;\n" 1650 " return 0;\n"
1379 "} f(1, 1);", 1651 "} f(1, 1);",
1380 0, 1652 0,
1381 3, 1653 3,
1382 74, 1654 74,
1383 { 1655 {
1384 #define IF_CONDITION_RETURN(condition) \ 1656 #define IF_CONDITION_RETURN(condition) \
1385 B(Ldar), A(2, 3), \ 1657 B(Ldar), A(2, 3), \
1386 B(condition), A(1, 3), \ 1658 B(condition), A(1, 3), \
1387 B(JumpIfFalse), U8(5), \ 1659 B(JumpIfFalse), U8(5), \
1388 B(LdaSmi8), U8(1), \ 1660 B(LdaSmi8), U8(1), \
1389 B(Return), 1661 B(Return),
1390 IF_CONDITION_RETURN(TestEqual) // 1662 IF_CONDITION_RETURN(TestEqual) //
1391 IF_CONDITION_RETURN(TestEqualStrict) // 1663 IF_CONDITION_RETURN(TestEqualStrict) //
1392 IF_CONDITION_RETURN(TestLessThan) // 1664 IF_CONDITION_RETURN(TestLessThan) //
1393 IF_CONDITION_RETURN(TestGreaterThan) // 1665 IF_CONDITION_RETURN(TestGreaterThan) //
1394 IF_CONDITION_RETURN(TestLessThanOrEqual) // 1666 IF_CONDITION_RETURN(TestLessThanOrEqual) //
1395 IF_CONDITION_RETURN(TestGreaterThanOrEqual) // 1667 IF_CONDITION_RETURN(TestGreaterThanOrEqual) //
(...skipping 2669 matching lines...) Expand 10 before | Expand all | Expand 10 after
4065 for (size_t i = 0; i < arraysize(snippets); i++) { 4337 for (size_t i = 0; i < arraysize(snippets); i++) {
4066 Handle<BytecodeArray> bytecode_array = 4338 Handle<BytecodeArray> bytecode_array =
4067 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 4339 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
4068 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 4340 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
4069 } 4341 }
4070 } 4342 }
4071 4343
4072 } // namespace interpreter 4344 } // namespace interpreter
4073 } // namespace internal 4345 } // namespace internal
4074 } // namespace v8 4346 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | test/unittests/compiler/interpreter-assembler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698