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

Side by Side Diff: test/cctest/test-code-stub-assembler.cc

Issue 2570213002: [stubs] Enable machine graph verification for CodeStubAssembler and friends by default in debug mode (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « test/cctest/test-accessor-assembler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base/utils/random-number-generator.h" 5 #include "src/base/utils/random-number-generator.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 #include "src/code-stub-assembler.h" 7 #include "src/code-stub-assembler.h"
8 #include "src/compiler/node.h" 8 #include "src/compiler/node.h"
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 #include "test/cctest/compiler/code-assembler-tester.h" 10 #include "test/cctest/compiler/code-assembler-tester.h"
11 #include "test/cctest/compiler/function-tester.h" 11 #include "test/cctest/compiler/function-tester.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 using compiler::CodeAssemblerTester; 16 using compiler::CodeAssemblerTester;
17 using compiler::FunctionTester; 17 using compiler::FunctionTester;
18 using compiler::Node; 18 using compiler::Node;
19 using compiler::CodeAssemblerLabel;
20 using compiler::CodeAssemblerVariable;
21 using compiler::CodeAssemblerVariableList;
19 22
20 TEST(FixedArrayAccessSmiIndex) { 23 TEST(FixedArrayAccessSmiIndex) {
21 Isolate* isolate(CcTest::InitIsolateOnce()); 24 Isolate* isolate(CcTest::InitIsolateOnce());
22 CodeAssemblerTester data(isolate); 25 CodeAssemblerTester data(isolate);
23 CodeStubAssembler m(data.state()); 26 CodeStubAssembler m(data.state());
24 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); 27 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5);
25 array->set(4, Smi::FromInt(733)); 28 array->set(4, Smi::FromInt(733));
26 m.Return(m.LoadFixedArrayElement(m.HeapConstant(array), 29 m.Return(m.LoadFixedArrayElement(m.HeapConstant(array),
27 m.SmiTag(m.Int32Constant(4)), 0, 30 m.SmiTag(m.Int32Constant(4)), 0,
28 CodeStubAssembler::SMI_PARAMETERS)); 31 CodeStubAssembler::SMI_PARAMETERS));
29 Handle<Code> code = data.GenerateCode(); 32 Handle<Code> code = data.GenerateCode();
30 FunctionTester ft(code); 33 FunctionTester ft(code);
31 MaybeHandle<Object> result = ft.Call(); 34 MaybeHandle<Object> result = ft.Call();
32 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value()); 35 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value());
33 } 36 }
34 37
35 TEST(LoadHeapNumberValue) { 38 TEST(LoadHeapNumberValue) {
36 Isolate* isolate(CcTest::InitIsolateOnce()); 39 Isolate* isolate(CcTest::InitIsolateOnce());
37 CodeAssemblerTester data(isolate); 40 CodeAssemblerTester data(isolate);
38 CodeStubAssembler m(data.state()); 41 CodeStubAssembler m(data.state());
39 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(1234); 42 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(1234);
40 m.Return(m.SmiTag( 43 m.Return(m.SmiFromWord32(
41 m.ChangeFloat64ToUint32(m.LoadHeapNumberValue(m.HeapConstant(number))))); 44 m.ChangeFloat64ToUint32(m.LoadHeapNumberValue(m.HeapConstant(number)))));
42 Handle<Code> code = data.GenerateCode(); 45 Handle<Code> code = data.GenerateCode();
43 FunctionTester ft(code); 46 FunctionTester ft(code);
44 MaybeHandle<Object> result = ft.Call(); 47 MaybeHandle<Object> result = ft.Call();
45 CHECK_EQ(1234, Handle<Smi>::cast(result.ToHandleChecked())->value()); 48 CHECK_EQ(1234, Handle<Smi>::cast(result.ToHandleChecked())->value());
46 } 49 }
47 50
48 TEST(LoadInstanceType) { 51 TEST(LoadInstanceType) {
49 Isolate* isolate(CcTest::InitIsolateOnce()); 52 Isolate* isolate(CcTest::InitIsolateOnce());
50 CodeAssemblerTester data(isolate); 53 CodeAssemblerTester data(isolate);
51 CodeStubAssembler m(data.state()); 54 CodeStubAssembler m(data.state());
52 Handle<HeapObject> undefined = isolate->factory()->undefined_value(); 55 Handle<HeapObject> undefined = isolate->factory()->undefined_value();
53 m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined)))); 56 m.Return(m.SmiFromWord32(m.LoadInstanceType(m.HeapConstant(undefined))));
54 Handle<Code> code = data.GenerateCode(); 57 Handle<Code> code = data.GenerateCode();
55 FunctionTester ft(code); 58 FunctionTester ft(code);
56 MaybeHandle<Object> result = ft.Call(); 59 MaybeHandle<Object> result = ft.Call();
57 CHECK_EQ(InstanceType::ODDBALL_TYPE, 60 CHECK_EQ(InstanceType::ODDBALL_TYPE,
58 Handle<Smi>::cast(result.ToHandleChecked())->value()); 61 Handle<Smi>::cast(result.ToHandleChecked())->value());
59 } 62 }
60 63
61 TEST(DecodeWordFromWord32) { 64 TEST(DecodeWordFromWord32) {
62 Isolate* isolate(CcTest::InitIsolateOnce()); 65 Isolate* isolate(CcTest::InitIsolateOnce());
63 CodeAssemblerTester data(isolate); 66 CodeAssemblerTester data(isolate);
(...skipping 27 matching lines...) Expand all
91 handle(Smi::FromInt(34), isolate)); 94 handle(Smi::FromInt(34), isolate));
92 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value()); 95 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
93 } 96 }
94 97
95 TEST(ComputeIntegerHash) { 98 TEST(ComputeIntegerHash) {
96 Isolate* isolate(CcTest::InitIsolateOnce()); 99 Isolate* isolate(CcTest::InitIsolateOnce());
97 const int kNumParams = 2; 100 const int kNumParams = 2;
98 CodeAssemblerTester data(isolate, kNumParams); 101 CodeAssemblerTester data(isolate, kNumParams);
99 CodeStubAssembler m(data.state()); 102 CodeStubAssembler m(data.state());
100 m.Return(m.SmiFromWord32(m.ComputeIntegerHash( 103 m.Return(m.SmiFromWord32(m.ComputeIntegerHash(
101 m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1))))); 104 m.SmiUntag(m.Parameter(0)), m.SmiToWord32(m.Parameter(1)))));
102 105
103 Handle<Code> code = data.GenerateCode(); 106 Handle<Code> code = data.GenerateCode();
104 FunctionTester ft(code, kNumParams); 107 FunctionTester ft(code, kNumParams);
105 108
106 Handle<Smi> hash_seed = isolate->factory()->hash_seed(); 109 Handle<Smi> hash_seed = isolate->factory()->hash_seed();
107 110
108 base::RandomNumberGenerator rand_gen(FLAG_random_seed); 111 base::RandomNumberGenerator rand_gen(FLAG_random_seed);
109 112
110 for (int i = 0; i < 1024; i++) { 113 for (int i = 0; i < 1024; i++) {
111 int k = rand_gen.NextInt(Smi::kMaxValue); 114 int k = rand_gen.NextInt(Smi::kMaxValue);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 for (int i = 0; i < 4; ++i) { 214 for (int i = 0; i < 4; ++i) {
212 Handle<String> test = handle(String::cast(test_cases->get(i))); 215 Handle<String> test = handle(String::cast(test_cases->get(i)));
213 Handle<Object> result = ft.Call(test).ToHandleChecked(); 216 Handle<Object> result = ft.Call(test).ToHandleChecked();
214 CHECK(result->IsString()); 217 CHECK(result->IsString());
215 CHECK(Handle<String>::cast(result)->IsFlat()); 218 CHECK(Handle<String>::cast(result)->IsFlat());
216 CHECK(String::Equals(Handle<String>::cast(result), expected)); 219 CHECK(String::Equals(Handle<String>::cast(result), expected));
217 } 220 }
218 } 221 }
219 222
220 TEST(TryToName) { 223 TEST(TryToName) {
221 typedef CodeStubAssembler::Label Label; 224 typedef CodeAssemblerLabel Label;
222 typedef CodeStubAssembler::Variable Variable; 225 typedef CodeAssemblerVariable Variable;
223 Isolate* isolate(CcTest::InitIsolateOnce()); 226 Isolate* isolate(CcTest::InitIsolateOnce());
224 227
225 const int kNumParams = 3; 228 const int kNumParams = 3;
226 CodeAssemblerTester data(isolate, kNumParams); 229 CodeAssemblerTester data(isolate, kNumParams);
227 CodeStubAssembler m(data.state()); 230 CodeStubAssembler m(data.state());
228 231
229 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; 232 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
230 { 233 {
231 Node* key = m.Parameter(0); 234 Node* key = m.Parameter(0);
232 Node* expected_result = m.Parameter(1); 235 Node* expected_result = m.Parameter(1);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 379
377 TEST(NameDictionaryEntryToIndex) { TestEntryToIndex<NameDictionary>(); } 380 TEST(NameDictionaryEntryToIndex) { TestEntryToIndex<NameDictionary>(); }
378 TEST(GlobalDictionaryEntryToIndex) { TestEntryToIndex<GlobalDictionary>(); } 381 TEST(GlobalDictionaryEntryToIndex) { TestEntryToIndex<GlobalDictionary>(); }
379 382
380 } // namespace 383 } // namespace
381 384
382 namespace { 385 namespace {
383 386
384 template <typename Dictionary> 387 template <typename Dictionary>
385 void TestNameDictionaryLookup() { 388 void TestNameDictionaryLookup() {
386 typedef CodeStubAssembler::Label Label; 389 typedef CodeAssemblerLabel Label;
387 typedef CodeStubAssembler::Variable Variable; 390 typedef CodeAssemblerVariable Variable;
388 Isolate* isolate(CcTest::InitIsolateOnce()); 391 Isolate* isolate(CcTest::InitIsolateOnce());
389 392
390 const int kNumParams = 4; 393 const int kNumParams = 4;
391 CodeAssemblerTester data(isolate, kNumParams); 394 CodeAssemblerTester data(isolate, kNumParams);
392 CodeStubAssembler m(data.state()); 395 CodeStubAssembler m(data.state());
393 396
394 enum Result { kFound, kNotFound }; 397 enum Result { kFound, kNotFound };
395 { 398 {
396 Node* dictionary = m.Parameter(0); 399 Node* dictionary = m.Parameter(0);
397 Node* unique_name = m.Parameter(1); 400 Node* unique_name = m.Parameter(1);
398 Node* expected_result = m.Parameter(2); 401 Node* expected_result = m.Parameter(2);
399 Node* expected_arg = m.Parameter(3); 402 Node* expected_arg = m.Parameter(3);
400 403
401 Label passed(&m), failed(&m); 404 Label passed(&m), failed(&m);
402 Label if_found(&m), if_not_found(&m); 405 Label if_found(&m), if_not_found(&m);
403 Variable var_name_index(&m, MachineType::PointerRepresentation()); 406 Variable var_name_index(&m, MachineType::PointerRepresentation());
404 407
405 m.NameDictionaryLookup<Dictionary>(dictionary, unique_name, &if_found, 408 m.NameDictionaryLookup<Dictionary>(dictionary, unique_name, &if_found,
406 &var_name_index, &if_not_found); 409 &var_name_index, &if_not_found);
407 m.Bind(&if_found); 410 m.Bind(&if_found);
408 m.GotoUnless( 411 m.GotoUnless(
409 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kFound))), 412 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kFound))),
410 &failed); 413 &failed);
411 m.Branch(m.Word32Equal(m.SmiToWord32(expected_arg), var_name_index.value()), 414 m.Branch(m.WordEqual(m.SmiUntag(expected_arg), var_name_index.value()),
412 &passed, &failed); 415 &passed, &failed);
413 416
414 m.Bind(&if_not_found); 417 m.Bind(&if_not_found);
415 m.Branch( 418 m.Branch(
416 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))), 419 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
417 &passed, &failed); 420 &passed, &failed);
418 421
419 m.Bind(&passed); 422 m.Bind(&passed);
420 m.Return(m.BooleanConstant(true)); 423 m.Return(m.BooleanConstant(true));
421 424
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } // namespace 486 } // namespace
484 487
485 TEST(NameDictionaryLookup) { TestNameDictionaryLookup<NameDictionary>(); } 488 TEST(NameDictionaryLookup) { TestNameDictionaryLookup<NameDictionary>(); }
486 489
487 TEST(GlobalDictionaryLookup) { TestNameDictionaryLookup<GlobalDictionary>(); } 490 TEST(GlobalDictionaryLookup) { TestNameDictionaryLookup<GlobalDictionary>(); }
488 491
489 namespace { 492 namespace {
490 493
491 template <typename Dictionary> 494 template <typename Dictionary>
492 void TestNumberDictionaryLookup() { 495 void TestNumberDictionaryLookup() {
493 typedef CodeStubAssembler::Label Label; 496 typedef CodeAssemblerLabel Label;
494 typedef CodeStubAssembler::Variable Variable; 497 typedef CodeAssemblerVariable Variable;
495 Isolate* isolate(CcTest::InitIsolateOnce()); 498 Isolate* isolate(CcTest::InitIsolateOnce());
496 499
497 const int kNumParams = 4; 500 const int kNumParams = 4;
498 CodeAssemblerTester data(isolate, kNumParams); 501 CodeAssemblerTester data(isolate, kNumParams);
499 CodeStubAssembler m(data.state()); 502 CodeStubAssembler m(data.state());
500 503
501 enum Result { kFound, kNotFound }; 504 enum Result { kFound, kNotFound };
502 { 505 {
503 Node* dictionary = m.Parameter(0); 506 Node* dictionary = m.Parameter(0);
504 Node* key = m.SmiToWord32(m.Parameter(1)); 507 Node* key = m.SmiUntag(m.Parameter(1));
505 Node* expected_result = m.Parameter(2); 508 Node* expected_result = m.Parameter(2);
506 Node* expected_arg = m.Parameter(3); 509 Node* expected_arg = m.Parameter(3);
507 510
508 Label passed(&m), failed(&m); 511 Label passed(&m), failed(&m);
509 Label if_found(&m), if_not_found(&m); 512 Label if_found(&m), if_not_found(&m);
510 Variable var_entry(&m, MachineType::PointerRepresentation()); 513 Variable var_entry(&m, MachineType::PointerRepresentation());
511 514
512 m.NumberDictionaryLookup<Dictionary>(dictionary, key, &if_found, &var_entry, 515 m.NumberDictionaryLookup<Dictionary>(dictionary, key, &if_found, &var_entry,
513 &if_not_found); 516 &if_not_found);
514 m.Bind(&if_found); 517 m.Bind(&if_found);
515 m.GotoUnless( 518 m.GotoUnless(
516 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kFound))), 519 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kFound))),
517 &failed); 520 &failed);
518 m.Branch(m.Word32Equal(m.SmiToWord32(expected_arg), var_entry.value()), 521 m.Branch(m.WordEqual(m.SmiUntag(expected_arg), var_entry.value()), &passed,
519 &passed, &failed); 522 &failed);
520 523
521 m.Bind(&if_not_found); 524 m.Bind(&if_not_found);
522 m.Branch( 525 m.Branch(
523 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))), 526 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
524 &passed, &failed); 527 &passed, &failed);
525 528
526 m.Bind(&passed); 529 m.Bind(&passed);
527 m.Return(m.BooleanConstant(true)); 530 m.Return(m.BooleanConstant(true));
528 531
529 m.Bind(&failed); 532 m.Bind(&failed);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 JSObject::DefineAccessor(object, names[i], getter, setter, NONE).Check(); 625 JSObject::DefineAccessor(object, names[i], getter, setter, NONE).Check();
623 } else { 626 } else {
624 JSObject::AddProperty(object, names[i], value, NONE); 627 JSObject::AddProperty(object, names[i], value, NONE);
625 } 628 }
626 } 629 }
627 } 630 }
628 631
629 } // namespace 632 } // namespace
630 633
631 TEST(TryHasOwnProperty) { 634 TEST(TryHasOwnProperty) {
632 typedef CodeStubAssembler::Label Label; 635 typedef CodeAssemblerLabel Label;
633 Isolate* isolate(CcTest::InitIsolateOnce()); 636 Isolate* isolate(CcTest::InitIsolateOnce());
634 637
635 const int kNumParams = 4; 638 const int kNumParams = 4;
636 CodeAssemblerTester data(isolate, kNumParams); 639 CodeAssemblerTester data(isolate, kNumParams);
637 CodeStubAssembler m(data.state()); 640 CodeStubAssembler m(data.state());
638 641
639 enum Result { kFound, kNotFound, kBailout }; 642 enum Result { kFound, kNotFound, kBailout };
640 { 643 {
641 Node* object = m.Parameter(0); 644 Node* object = m.Parameter(0);
642 Node* unique_name = m.Parameter(1); 645 Node* unique_name = m.Parameter(1);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 } 810 }
808 811
809 { 812 {
810 Handle<JSObject> object = isolate->global_proxy(); 813 Handle<JSObject> object = isolate->global_proxy();
811 CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type()); 814 CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type());
812 ft.CheckTrue(object, names[0], expect_bailout); 815 ft.CheckTrue(object, names[0], expect_bailout);
813 } 816 }
814 } 817 }
815 818
816 TEST(TryGetOwnProperty) { 819 TEST(TryGetOwnProperty) {
817 typedef CodeStubAssembler::Label Label; 820 typedef CodeAssemblerLabel Label;
818 typedef CodeStubAssembler::Variable Variable; 821 typedef CodeAssemblerVariable Variable;
819 Isolate* isolate(CcTest::InitIsolateOnce()); 822 Isolate* isolate(CcTest::InitIsolateOnce());
820 Factory* factory = isolate->factory(); 823 Factory* factory = isolate->factory();
821 824
822 const int kNumParams = 2; 825 const int kNumParams = 2;
823 CodeAssemblerTester data(isolate, kNumParams); 826 CodeAssemblerTester data(isolate, kNumParams);
824 CodeStubAssembler m(data.state()); 827 CodeStubAssembler m(data.state());
825 828
826 Handle<Symbol> not_found_symbol = factory->NewSymbol(); 829 Handle<Symbol> not_found_symbol = factory->NewSymbol();
827 Handle<Symbol> bailout_symbol = factory->NewSymbol(); 830 Handle<Symbol> bailout_symbol = factory->NewSymbol();
828 { 831 {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 namespace { 1029 namespace {
1027 1030
1028 void AddElement(Handle<JSObject> object, uint32_t index, Handle<Object> value, 1031 void AddElement(Handle<JSObject> object, uint32_t index, Handle<Object> value,
1029 PropertyAttributes attributes = NONE) { 1032 PropertyAttributes attributes = NONE) {
1030 JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked(); 1033 JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked();
1031 } 1034 }
1032 1035
1033 } // namespace 1036 } // namespace
1034 1037
1035 TEST(TryLookupElement) { 1038 TEST(TryLookupElement) {
1036 typedef CodeStubAssembler::Label Label; 1039 typedef CodeAssemblerLabel Label;
1037 Isolate* isolate(CcTest::InitIsolateOnce()); 1040 Isolate* isolate(CcTest::InitIsolateOnce());
1038 1041
1039 const int kNumParams = 3; 1042 const int kNumParams = 3;
1040 CodeAssemblerTester data(isolate, kNumParams); 1043 CodeAssemblerTester data(isolate, kNumParams);
1041 CodeStubAssembler m(data.state()); 1044 CodeStubAssembler m(data.state());
1042 1045
1043 enum Result { kFound, kNotFound, kBailout }; 1046 enum Result { kFound, kNotFound, kBailout };
1044 { 1047 {
1045 Node* object = m.Parameter(0); 1048 Node* object = m.Parameter(0);
1046 Node* index = m.SmiToWord32(m.Parameter(1)); 1049 Node* index = m.SmiUntag(m.Parameter(1));
1047 Node* expected_result = m.Parameter(2); 1050 Node* expected_result = m.Parameter(2);
1048 1051
1049 Label passed(&m), failed(&m); 1052 Label passed(&m), failed(&m);
1050 Label if_found(&m), if_not_found(&m), if_bailout(&m); 1053 Label if_found(&m), if_not_found(&m), if_bailout(&m);
1051 1054
1052 Node* map = m.LoadMap(object); 1055 Node* map = m.LoadMap(object);
1053 Node* instance_type = m.LoadMapInstanceType(map); 1056 Node* instance_type = m.LoadMapInstanceType(map);
1054 1057
1055 m.TryLookupElement(object, map, instance_type, index, &if_found, 1058 m.TryLookupElement(object, map, instance_type, index, &if_found,
1056 &if_not_found, &if_bailout); 1059 &if_not_found, &if_bailout);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 ft.CheckTrue(object, smi0, expect_bailout); 1215 ft.CheckTrue(object, smi0, expect_bailout);
1213 } 1216 }
1214 1217
1215 { 1218 {
1216 Handle<JSObject> object = isolate->global_proxy(); 1219 Handle<JSObject> object = isolate->global_proxy();
1217 CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type()); 1220 CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type());
1218 ft.CheckTrue(object, smi0, expect_bailout); 1221 ft.CheckTrue(object, smi0, expect_bailout);
1219 } 1222 }
1220 } 1223 }
1221 1224
1222 TEST(DeferredCodePhiHints) {
Igor Sheludko 2016/12/14 15:45:37 I moved this whole red block to test-code-assemble
1223 typedef compiler::Node Node;
1224 typedef CodeStubAssembler::Label Label;
1225 typedef CodeStubAssembler::Variable Variable;
1226 Isolate* isolate(CcTest::InitIsolateOnce());
1227 CodeAssemblerTester data(isolate);
1228 CodeStubAssembler m(data.state());
1229 Label block1(&m, Label::kDeferred);
1230 m.Goto(&block1);
1231 m.Bind(&block1);
1232 {
1233 Variable var_object(&m, MachineRepresentation::kTagged);
1234 Label loop(&m, &var_object);
1235 var_object.Bind(m.IntPtrConstant(0));
1236 m.Goto(&loop);
1237 m.Bind(&loop);
1238 {
1239 Node* map = m.LoadMap(var_object.value());
1240 var_object.Bind(map);
1241 m.Goto(&loop);
1242 }
1243 }
1244 CHECK(!data.GenerateCode().is_null());
1245 }
1246
1247 TEST(TestOutOfScopeVariable) {
1248 typedef CodeStubAssembler::Label Label;
1249 typedef CodeStubAssembler::Variable Variable;
1250 Isolate* isolate(CcTest::InitIsolateOnce());
1251 CodeAssemblerTester data(isolate);
1252 CodeStubAssembler m(data.state());
1253 Label block1(&m);
1254 Label block2(&m);
1255 Label block3(&m);
1256 Label block4(&m);
1257 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block1, &block4);
1258 m.Bind(&block4);
1259 {
1260 Variable var_object(&m, MachineRepresentation::kTagged);
1261 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block2,
1262 &block3);
1263
1264 m.Bind(&block2);
1265 var_object.Bind(m.IntPtrConstant(55));
1266 m.Goto(&block1);
1267
1268 m.Bind(&block3);
1269 var_object.Bind(m.IntPtrConstant(66));
1270 m.Goto(&block1);
1271 }
1272 m.Bind(&block1);
1273 CHECK(!data.GenerateCode().is_null());
1274 }
1275
1276 TEST(GotoIfException) {
1277 typedef CodeStubAssembler::Label Label;
1278 typedef CodeStubAssembler::Variable Variable;
1279 Isolate* isolate(CcTest::InitIsolateOnce());
1280
1281 const int kNumParams = 1;
1282 CodeAssemblerTester data(isolate, kNumParams);
1283 CodeStubAssembler m(data.state());
1284
1285 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
1286 Node* to_string_tag =
1287 m.HeapConstant(isolate->factory()->to_string_tag_symbol());
1288 Variable exception(&m, MachineRepresentation::kTagged);
1289
1290 Label exception_handler(&m);
1291 Callable to_string = CodeFactory::ToString(isolate);
1292 Node* string = m.CallStub(to_string, context, to_string_tag);
1293 m.GotoIfException(string, &exception_handler, &exception);
1294 m.Return(string);
1295
1296 m.Bind(&exception_handler);
1297 m.Return(exception.value());
1298
1299 Handle<Code> code = data.GenerateCode();
1300 CHECK(!code.is_null());
1301
1302 FunctionTester ft(code, kNumParams);
1303 Handle<Object> result = ft.Call().ToHandleChecked();
1304
1305 // Should be a TypeError.
1306 CHECK(result->IsJSObject());
1307
1308 Handle<Object> constructor =
1309 Object::GetPropertyOrElement(result,
1310 isolate->factory()->constructor_string())
1311 .ToHandleChecked();
1312 CHECK(constructor->SameValue(*isolate->type_error_function()));
1313 }
1314
1315 TEST(GotoIfExceptionMultiple) {
1316 typedef CodeStubAssembler::Label Label;
1317 typedef CodeStubAssembler::Variable Variable;
1318 Isolate* isolate(CcTest::InitIsolateOnce());
1319
1320 const int kNumParams = 4; // receiver, first, second, third
1321 CodeAssemblerTester data(isolate, kNumParams);
1322 CodeStubAssembler m(data.state());
1323
1324 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
1325 Node* first_value = m.Parameter(0);
1326 Node* second_value = m.Parameter(1);
1327 Node* third_value = m.Parameter(2);
1328
1329 Label exception_handler1(&m);
1330 Label exception_handler2(&m);
1331 Label exception_handler3(&m);
1332 Variable return_value(&m, MachineRepresentation::kWord32);
1333 Variable error(&m, MachineRepresentation::kTagged);
1334
1335 return_value.Bind(m.Int32Constant(0));
1336
1337 // try { return ToString(param1) } catch (e) { ... }
1338 Callable to_string = CodeFactory::ToString(isolate);
1339 Node* string = m.CallStub(to_string, context, first_value);
1340 m.GotoIfException(string, &exception_handler1, &error);
1341 m.Return(string);
1342
1343 // try { ToString(param2); return 7 } catch (e) { ... }
1344 m.Bind(&exception_handler1);
1345 return_value.Bind(m.Int32Constant(7));
1346 error.Bind(m.UndefinedConstant());
1347 string = m.CallStub(to_string, context, second_value);
1348 m.GotoIfException(string, &exception_handler2, &error);
1349 m.Return(m.SmiFromWord32(return_value.value()));
1350
1351 // try { ToString(param3); return 7 & ~2; } catch (e) { return e; }
1352 m.Bind(&exception_handler2);
1353 // Return returnValue & ~2
1354 error.Bind(m.UndefinedConstant());
1355 string = m.CallStub(to_string, context, third_value);
1356 m.GotoIfException(string, &exception_handler3, &error);
1357 m.Return(m.SmiFromWord32(
1358 m.Word32And(return_value.value(),
1359 m.Word32Xor(m.Int32Constant(2), m.Int32Constant(-1)))));
1360
1361 m.Bind(&exception_handler3);
1362 m.Return(error.value());
1363
1364 Handle<Code> code = data.GenerateCode();
1365 CHECK(!code.is_null());
1366
1367 FunctionTester ft(code, kNumParams);
1368
1369 Handle<Object> result;
1370 // First handler does not throw, returns result of first value.
1371 result = ft.Call(isolate->factory()->undefined_value(),
1372 isolate->factory()->to_string_tag_symbol())
1373 .ToHandleChecked();
1374 CHECK(String::cast(*result)->IsOneByteEqualTo(OneByteVector("undefined")));
1375
1376 // First handler returns a number.
1377 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1378 isolate->factory()->undefined_value())
1379 .ToHandleChecked();
1380 CHECK_EQ(7, Smi::cast(*result)->value());
1381
1382 // First handler throws, second handler returns a number.
1383 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1384 isolate->factory()->to_primitive_symbol())
1385 .ToHandleChecked();
1386 CHECK_EQ(7 & ~2, Smi::cast(*result)->value());
1387
1388 // First handler throws, second handler throws, third handler returns thrown
1389 // value.
1390 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1391 isolate->factory()->to_primitive_symbol(),
1392 isolate->factory()->unscopables_symbol())
1393 .ToHandleChecked();
1394
1395 // Should be a TypeError.
1396 CHECK(result->IsJSObject());
1397
1398 Handle<Object> constructor =
1399 Object::GetPropertyOrElement(result,
1400 isolate->factory()->constructor_string())
1401 .ToHandleChecked();
1402 CHECK(constructor->SameValue(*isolate->type_error_function()));
1403 }
1404
1405 TEST(AllocateJSObjectFromMap) { 1225 TEST(AllocateJSObjectFromMap) {
1406 Isolate* isolate(CcTest::InitIsolateOnce()); 1226 Isolate* isolate(CcTest::InitIsolateOnce());
1407 Factory* factory = isolate->factory(); 1227 Factory* factory = isolate->factory();
1408 1228
1409 const int kNumParams = 3; 1229 const int kNumParams = 3;
1410 CodeAssemblerTester data(isolate, kNumParams); 1230 CodeAssemblerTester data(isolate, kNumParams);
1411 CodeStubAssembler m(data.state()); 1231 CodeStubAssembler m(data.state());
1412 1232
1413 { 1233 {
1414 Node* map = m.Parameter(0); 1234 Node* map = m.Parameter(0);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]); 1518 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
1699 } 1519 }
1700 1520
1701 TEST(Arguments) { 1521 TEST(Arguments) {
1702 Isolate* isolate(CcTest::InitIsolateOnce()); 1522 Isolate* isolate(CcTest::InitIsolateOnce());
1703 1523
1704 const int kNumParams = 4; 1524 const int kNumParams = 4;
1705 CodeAssemblerTester data(isolate, kNumParams); 1525 CodeAssemblerTester data(isolate, kNumParams);
1706 CodeStubAssembler m(data.state()); 1526 CodeStubAssembler m(data.state());
1707 1527
1708 CodeStubArguments arguments(&m, m.IntPtrConstant(3)); 1528 CodeStubArguments arguments(&m, m.Int32Constant(3));
1709 1529
1710 CSA_ASSERT( 1530 CSA_ASSERT(
1711 &m, m.WordEqual(arguments.AtIndex(0), m.SmiConstant(Smi::FromInt(12)))); 1531 &m, m.WordEqual(arguments.AtIndex(0), m.SmiConstant(Smi::FromInt(12))));
1712 CSA_ASSERT( 1532 CSA_ASSERT(
1713 &m, m.WordEqual(arguments.AtIndex(1), m.SmiConstant(Smi::FromInt(13)))); 1533 &m, m.WordEqual(arguments.AtIndex(1), m.SmiConstant(Smi::FromInt(13))));
1714 CSA_ASSERT( 1534 CSA_ASSERT(
1715 &m, m.WordEqual(arguments.AtIndex(2), m.SmiConstant(Smi::FromInt(14)))); 1535 &m, m.WordEqual(arguments.AtIndex(2), m.SmiConstant(Smi::FromInt(14))));
1716 1536
1717 m.Return(arguments.GetReceiver()); 1537 m.Return(arguments.GetReceiver());
1718 1538
1719 Handle<Code> code = data.GenerateCode(); 1539 Handle<Code> code = data.GenerateCode();
1720 CHECK(!code.is_null()); 1540 CHECK(!code.is_null());
1721 1541
1722 FunctionTester ft(code, kNumParams); 1542 FunctionTester ft(code, kNumParams);
1723 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(), 1543 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1724 Handle<Smi>(Smi::FromInt(12), isolate), 1544 Handle<Smi>(Smi::FromInt(12), isolate),
1725 Handle<Smi>(Smi::FromInt(13), isolate), 1545 Handle<Smi>(Smi::FromInt(13), isolate),
1726 Handle<Smi>(Smi::FromInt(14), isolate)) 1546 Handle<Smi>(Smi::FromInt(14), isolate))
1727 .ToHandleChecked(); 1547 .ToHandleChecked();
1728 CHECK_EQ(*isolate->factory()->undefined_value(), *result); 1548 CHECK_EQ(*isolate->factory()->undefined_value(), *result);
1729 } 1549 }
1730 1550
1731 TEST(ArgumentsForEach) { 1551 TEST(ArgumentsForEach) {
1732 Isolate* isolate(CcTest::InitIsolateOnce()); 1552 Isolate* isolate(CcTest::InitIsolateOnce());
1733 1553
1734 const int kNumParams = 4; 1554 const int kNumParams = 4;
1735 CodeAssemblerTester data(isolate, kNumParams); 1555 CodeAssemblerTester data(isolate, kNumParams);
1736 CodeStubAssembler m(data.state()); 1556 CodeStubAssembler m(data.state());
1737 1557
1738 CodeStubArguments arguments(&m, m.IntPtrConstant(3)); 1558 CodeStubArguments arguments(&m, m.Int32Constant(3));
1739 1559
1740 CodeStubAssembler::Variable sum(&m, MachineType::PointerRepresentation()); 1560 CodeAssemblerVariable sum(&m, MachineRepresentation::kTagged);
1741 CodeStubAssembler::VariableList list({&sum}, m.zone()); 1561 CodeAssemblerVariableList list({&sum}, m.zone());
1742 1562
1743 sum.Bind(m.IntPtrConstant(0)); 1563 sum.Bind(m.SmiConstant(0));
1744 1564
1745 arguments.ForEach( 1565 arguments.ForEach(
1746 list, [&m, &sum](Node* arg) { sum.Bind(m.IntPtrAdd(sum.value(), arg)); }); 1566 list, [&m, &sum](Node* arg) { sum.Bind(m.SmiAdd(sum.value(), arg)); });
1747 1567
1748 m.Return(sum.value()); 1568 m.Return(sum.value());
1749 1569
1750 Handle<Code> code = data.GenerateCode(); 1570 Handle<Code> code = data.GenerateCode();
1751 CHECK(!code.is_null()); 1571 CHECK(!code.is_null());
1752 1572
1753 FunctionTester ft(code, kNumParams); 1573 FunctionTester ft(code, kNumParams);
1754 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(), 1574 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1755 Handle<Smi>(Smi::FromInt(12), isolate), 1575 Handle<Smi>(Smi::FromInt(12), isolate),
1756 Handle<Smi>(Smi::FromInt(13), isolate), 1576 Handle<Smi>(Smi::FromInt(13), isolate),
1757 Handle<Smi>(Smi::FromInt(14), isolate)) 1577 Handle<Smi>(Smi::FromInt(14), isolate))
1758 .ToHandleChecked(); 1578 .ToHandleChecked();
1759 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result); 1579 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result);
1760 } 1580 }
1761 1581
1762 TEST(IsDebugActive) { 1582 TEST(IsDebugActive) {
1763 Isolate* isolate(CcTest::InitIsolateOnce()); 1583 Isolate* isolate(CcTest::InitIsolateOnce());
1764 1584
1765 const int kNumParams = 1; 1585 const int kNumParams = 1;
1766 CodeAssemblerTester data(isolate, kNumParams); 1586 CodeAssemblerTester data(isolate, kNumParams);
1767 CodeStubAssembler m(data.state()); 1587 CodeStubAssembler m(data.state());
1768 1588
1769 CodeStubAssembler::Label if_active(&m), if_not_active(&m); 1589 CodeAssemblerLabel if_active(&m), if_not_active(&m);
1770 1590
1771 m.Branch(m.IsDebugActive(), &if_active, &if_not_active); 1591 m.Branch(m.IsDebugActive(), &if_active, &if_not_active);
1772 m.Bind(&if_active); 1592 m.Bind(&if_active);
1773 m.Return(m.TrueConstant()); 1593 m.Return(m.TrueConstant());
1774 m.Bind(&if_not_active); 1594 m.Bind(&if_not_active);
1775 m.Return(m.FalseConstant()); 1595 m.Return(m.FalseConstant());
1776 1596
1777 Handle<Code> code = data.GenerateCode(); 1597 Handle<Code> code = data.GenerateCode();
1778 CHECK(!code.is_null()); 1598 CHECK(!code.is_null());
1779 1599
(...skipping 18 matching lines...) Expand all
1798 1618
1799 class AppendJSArrayCodeStubAssembler : public CodeStubAssembler { 1619 class AppendJSArrayCodeStubAssembler : public CodeStubAssembler {
1800 public: 1620 public:
1801 AppendJSArrayCodeStubAssembler(compiler::CodeAssemblerState* state, 1621 AppendJSArrayCodeStubAssembler(compiler::CodeAssemblerState* state,
1802 ElementsKind kind) 1622 ElementsKind kind)
1803 : CodeStubAssembler(state), kind_(kind) {} 1623 : CodeStubAssembler(state), kind_(kind) {}
1804 1624
1805 void TestAppendJSArrayImpl(Isolate* isolate, CodeAssemblerTester* tester, 1625 void TestAppendJSArrayImpl(Isolate* isolate, CodeAssemblerTester* tester,
1806 Object* o1, Object* o2, Object* o3, Object* o4, 1626 Object* o1, Object* o2, Object* o3, Object* o4,
1807 int initial_size, int result_size) { 1627 int initial_size, int result_size) {
1808 typedef CodeStubAssembler::Variable Variable; 1628 typedef CodeAssemblerVariable Variable;
1809 typedef CodeStubAssembler::Label Label; 1629 typedef CodeAssemblerLabel Label;
1810 Handle<JSArray> array = isolate->factory()->NewJSArray( 1630 Handle<JSArray> array = isolate->factory()->NewJSArray(
1811 kind_, 2, initial_size, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); 1631 kind_, 2, initial_size, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
1812 JSObject::SetElement(isolate, array, 0, 1632 JSObject::SetElement(isolate, array, 0,
1813 Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY) 1633 Handle<Smi>(Smi::FromInt(1), isolate), SLOPPY)
1814 .Check(); 1634 .Check();
1815 JSObject::SetElement(isolate, array, 1, 1635 JSObject::SetElement(isolate, array, 1,
1816 Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY) 1636 Handle<Smi>(Smi::FromInt(2), isolate), SLOPPY)
1817 .Check(); 1637 .Check();
1818 CodeStubArguments args(this, IntPtrConstant(kNumParams)); 1638 CodeStubArguments args(this, Int32Constant(kNumParams));
1819 Variable arg_index(this, MachineType::PointerRepresentation()); 1639 Variable arg_index(this, MachineType::PointerRepresentation());
1820 Label bailout(this); 1640 Label bailout(this);
1821 arg_index.Bind(IntPtrConstant(0)); 1641 arg_index.Bind(IntPtrConstant(0));
1822 Node* length = BuildAppendJSArray( 1642 Node* length = BuildAppendJSArray(
1823 kind_, HeapConstant(Handle<HeapObject>(isolate->context(), isolate)), 1643 kind_, HeapConstant(Handle<HeapObject>(isolate->context(), isolate)),
1824 HeapConstant(array), args, arg_index, &bailout); 1644 HeapConstant(array), args, arg_index, &bailout);
1825 Return(length); 1645 Return(length);
1826 1646
1827 Bind(&bailout); 1647 Bind(&bailout);
1828 Return(SmiTag(IntPtrAdd(arg_index.value(), IntPtrConstant(2)))); 1648 Return(SmiTag(IntPtrAdd(arg_index.value(), IntPtrConstant(2))));
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 CHECK_EQ(Smi::FromInt(1), promise_info->value()); 1918 CHECK_EQ(Smi::FromInt(1), promise_info->value());
2099 CHECK(promise_info->tasks()->IsFixedArray()); 1919 CHECK(promise_info->tasks()->IsFixedArray());
2100 CHECK(promise_info->deferred()->IsFixedArray()); 1920 CHECK(promise_info->deferred()->IsFixedArray());
2101 CHECK(promise_info->context()->IsContext()); 1921 CHECK(promise_info->context()->IsContext());
2102 CHECK(promise_info->debug_id()->IsUndefined(isolate)); 1922 CHECK(promise_info->debug_id()->IsUndefined(isolate));
2103 CHECK(promise_info->debug_name()->IsUndefined(isolate)); 1923 CHECK(promise_info->debug_name()->IsUndefined(isolate));
2104 } 1924 }
2105 1925
2106 } // namespace internal 1926 } // namespace internal
2107 } // namespace v8 1927 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-accessor-assembler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698