| OLD | NEW |
| 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/execution.h" | 7 #include "src/execution.h" |
| 8 #include "src/handles.h" | 8 #include "src/handles.h" |
| 9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
| 10 #include "src/interpreter/bytecode-array-iterator.h" | 10 #include "src/interpreter/bytecode-array-iterator.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 131 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 132 auto callable = tester.GetCallable<>(); | 132 auto callable = tester.GetCallable<>(); |
| 133 Handle<Object> return_val = callable().ToHandleChecked(); | 133 Handle<Object> return_val = callable().ToHandleChecked(); |
| 134 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(i)); | 134 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(i)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Large Smis. | 137 // Large Smis. |
| 138 { | 138 { |
| 139 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 139 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 140 0, 0); | 140 0, 0); |
| 141 |
| 141 builder.LoadLiteral(Smi::FromInt(0x12345678)).Return(); | 142 builder.LoadLiteral(Smi::FromInt(0x12345678)).Return(); |
| 142 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 143 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 143 | 144 |
| 144 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 145 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 145 auto callable = tester.GetCallable<>(); | 146 auto callable = tester.GetCallable<>(); |
| 146 Handle<Object> return_val = callable().ToHandleChecked(); | 147 Handle<Object> return_val = callable().ToHandleChecked(); |
| 147 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x12345678)); | 148 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x12345678)); |
| 148 } | 149 } |
| 149 | 150 |
| 150 // Heap numbers. | 151 // Heap numbers. |
| 151 { | 152 { |
| 152 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 153 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 153 0, 0); | 154 0, 0); |
| 155 |
| 154 builder.LoadLiteral(factory->NewHeapNumber(-2.1e19)).Return(); | 156 builder.LoadLiteral(factory->NewHeapNumber(-2.1e19)).Return(); |
| 155 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 157 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 156 | 158 |
| 157 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 159 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 158 auto callable = tester.GetCallable<>(); | 160 auto callable = tester.GetCallable<>(); |
| 159 Handle<Object> return_val = callable().ToHandleChecked(); | 161 Handle<Object> return_val = callable().ToHandleChecked(); |
| 160 CHECK_EQ(i::HeapNumber::cast(*return_val)->value(), -2.1e19); | 162 CHECK_EQ(i::HeapNumber::cast(*return_val)->value(), -2.1e19); |
| 161 } | 163 } |
| 162 | 164 |
| 163 // Strings. | 165 // Strings. |
| 164 { | 166 { |
| 165 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 167 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 166 0, 0); | 168 0, 0); |
| 169 |
| 167 Handle<i::String> string = factory->NewStringFromAsciiChecked("String"); | 170 Handle<i::String> string = factory->NewStringFromAsciiChecked("String"); |
| 168 builder.LoadLiteral(string).Return(); | 171 builder.LoadLiteral(string).Return(); |
| 169 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 172 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 170 | 173 |
| 171 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 174 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 172 auto callable = tester.GetCallable<>(); | 175 auto callable = tester.GetCallable<>(); |
| 173 Handle<Object> return_val = callable().ToHandleChecked(); | 176 Handle<Object> return_val = callable().ToHandleChecked(); |
| 174 CHECK(i::String::cast(*return_val)->Equals(*string)); | 177 CHECK(i::String::cast(*return_val)->Equals(*string)); |
| 175 } | 178 } |
| 176 } | 179 } |
| 177 | 180 |
| 178 | 181 |
| 179 TEST(InterpreterLoadStoreRegisters) { | 182 TEST(InterpreterLoadStoreRegisters) { |
| 180 HandleAndZoneScope handles; | 183 HandleAndZoneScope handles; |
| 181 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); | 184 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); |
| 182 for (int i = 0; i <= kMaxInt8; i++) { | 185 for (int i = 0; i <= kMaxInt8; i++) { |
| 183 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 186 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 184 0, i + 1); | 187 0, i + 1); |
| 188 |
| 185 Register reg(i); | 189 Register reg(i); |
| 186 builder.LoadTrue() | 190 builder.LoadTrue() |
| 187 .StoreAccumulatorInRegister(reg) | 191 .StoreAccumulatorInRegister(reg) |
| 188 .LoadFalse() | 192 .LoadFalse() |
| 189 .LoadAccumulatorWithRegister(reg) | 193 .LoadAccumulatorWithRegister(reg) |
| 190 .Return(); | 194 .Return(); |
| 191 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 195 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 192 | 196 |
| 193 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 197 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 194 auto callable = tester.GetCallable<>(); | 198 auto callable = tester.GetCallable<>(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 TEST(InterpreterBinaryOpsSmi) { | 294 TEST(InterpreterBinaryOpsSmi) { |
| 291 int lhs_inputs[] = {3266, 1024, 0, -17, -18000}; | 295 int lhs_inputs[] = {3266, 1024, 0, -17, -18000}; |
| 292 int rhs_inputs[] = {3266, 5, 4, 3, 2, 1, -1, -2}; | 296 int rhs_inputs[] = {3266, 5, 4, 3, 2, 1, -1, -2}; |
| 293 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { | 297 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
| 294 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { | 298 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
| 295 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { | 299 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { |
| 296 HandleAndZoneScope handles; | 300 HandleAndZoneScope handles; |
| 297 i::Factory* factory = handles.main_isolate()->factory(); | 301 i::Factory* factory = handles.main_isolate()->factory(); |
| 298 BytecodeArrayBuilder builder(handles.main_isolate(), | 302 BytecodeArrayBuilder builder(handles.main_isolate(), |
| 299 handles.main_zone(), 1, 0, 1); | 303 handles.main_zone(), 1, 0, 1); |
| 304 |
| 300 Register reg(0); | 305 Register reg(0); |
| 301 int lhs = lhs_inputs[l]; | 306 int lhs = lhs_inputs[l]; |
| 302 int rhs = rhs_inputs[r]; | 307 int rhs = rhs_inputs[r]; |
| 303 builder.LoadLiteral(Smi::FromInt(lhs)) | 308 builder.LoadLiteral(Smi::FromInt(lhs)) |
| 304 .StoreAccumulatorInRegister(reg) | 309 .StoreAccumulatorInRegister(reg) |
| 305 .LoadLiteral(Smi::FromInt(rhs)) | 310 .LoadLiteral(Smi::FromInt(rhs)) |
| 306 .BinaryOperation(kArithmeticOperators[o], reg) | 311 .BinaryOperation(kArithmeticOperators[o], reg) |
| 307 .Return(); | 312 .Return(); |
| 308 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 313 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 309 | 314 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 factory->NewStringFromStaticChars("1.112.5")}, | 385 factory->NewStringFromStaticChars("1.112.5")}, |
| 381 {factory->NewStringFromStaticChars("-1.11"), factory->NewHeapNumber(2.56), | 386 {factory->NewStringFromStaticChars("-1.11"), factory->NewHeapNumber(2.56), |
| 382 factory->NewStringFromStaticChars("-1.112.56")}, | 387 factory->NewStringFromStaticChars("-1.112.56")}, |
| 383 {factory->NewStringFromStaticChars(""), factory->NewHeapNumber(2.5), | 388 {factory->NewStringFromStaticChars(""), factory->NewHeapNumber(2.5), |
| 384 factory->NewStringFromStaticChars("2.5")}, | 389 factory->NewStringFromStaticChars("2.5")}, |
| 385 }; | 390 }; |
| 386 | 391 |
| 387 for (size_t i = 0; i < arraysize(test_cases); i++) { | 392 for (size_t i = 0; i < arraysize(test_cases); i++) { |
| 388 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 393 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 389 0, 1); | 394 0, 1); |
| 395 |
| 390 Register reg(0); | 396 Register reg(0); |
| 391 builder.LoadLiteral(test_cases[i].lhs) | 397 builder.LoadLiteral(test_cases[i].lhs) |
| 392 .StoreAccumulatorInRegister(reg) | 398 .StoreAccumulatorInRegister(reg) |
| 393 .LoadLiteral(test_cases[i].rhs) | 399 .LoadLiteral(test_cases[i].rhs) |
| 394 .BinaryOperation(Token::Value::ADD, reg) | 400 .BinaryOperation(Token::Value::ADD, reg) |
| 395 .Return(); | 401 .Return(); |
| 396 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 402 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 397 | 403 |
| 398 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 404 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 399 auto callable = tester.GetCallable<>(); | 405 auto callable = tester.GetCallable<>(); |
| 400 Handle<Object> return_value = callable().ToHandleChecked(); | 406 Handle<Object> return_value = callable().ToHandleChecked(); |
| 401 CHECK(return_value->SameValue(*test_cases[i].expected_value)); | 407 CHECK(return_value->SameValue(*test_cases[i].expected_value)); |
| 402 } | 408 } |
| 403 } | 409 } |
| 404 | 410 |
| 405 | 411 |
| 406 TEST(InterpreterParameter1) { | 412 TEST(InterpreterParameter1) { |
| 407 HandleAndZoneScope handles; | 413 HandleAndZoneScope handles; |
| 408 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 414 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 409 0, 0); | 415 0, 0); |
| 416 |
| 410 builder.LoadAccumulatorWithRegister(builder.Parameter(0)).Return(); | 417 builder.LoadAccumulatorWithRegister(builder.Parameter(0)).Return(); |
| 411 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 418 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 412 | 419 |
| 413 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 420 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 414 auto callable = tester.GetCallable<Handle<Object>>(); | 421 auto callable = tester.GetCallable<Handle<Object>>(); |
| 415 | 422 |
| 416 // Check for heap objects. | 423 // Check for heap objects. |
| 417 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); | 424 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); |
| 418 Handle<Object> return_val = callable(true_value).ToHandleChecked(); | 425 Handle<Object> return_val = callable(true_value).ToHandleChecked(); |
| 419 CHECK(return_val.is_identical_to(true_value)); | 426 CHECK(return_val.is_identical_to(true_value)); |
| 420 | 427 |
| 421 // Check for Smis. | 428 // Check for Smis. |
| 422 return_val = callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) | 429 return_val = callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) |
| 423 .ToHandleChecked(); | 430 .ToHandleChecked(); |
| 424 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); | 431 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
| 425 } | 432 } |
| 426 | 433 |
| 427 | 434 |
| 428 TEST(InterpreterParameter8) { | 435 TEST(InterpreterParameter8) { |
| 429 HandleAndZoneScope handles; | 436 HandleAndZoneScope handles; |
| 430 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 8, | 437 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 8, |
| 431 0, 0); | 438 0, 0); |
| 439 |
| 432 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) | 440 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) |
| 433 .BinaryOperation(Token::Value::ADD, builder.Parameter(1)) | 441 .BinaryOperation(Token::Value::ADD, builder.Parameter(1)) |
| 434 .BinaryOperation(Token::Value::ADD, builder.Parameter(2)) | 442 .BinaryOperation(Token::Value::ADD, builder.Parameter(2)) |
| 435 .BinaryOperation(Token::Value::ADD, builder.Parameter(3)) | 443 .BinaryOperation(Token::Value::ADD, builder.Parameter(3)) |
| 436 .BinaryOperation(Token::Value::ADD, builder.Parameter(4)) | 444 .BinaryOperation(Token::Value::ADD, builder.Parameter(4)) |
| 437 .BinaryOperation(Token::Value::ADD, builder.Parameter(5)) | 445 .BinaryOperation(Token::Value::ADD, builder.Parameter(5)) |
| 438 .BinaryOperation(Token::Value::ADD, builder.Parameter(6)) | 446 .BinaryOperation(Token::Value::ADD, builder.Parameter(6)) |
| 439 .BinaryOperation(Token::Value::ADD, builder.Parameter(7)) | 447 .BinaryOperation(Token::Value::ADD, builder.Parameter(7)) |
| 440 .Return(); | 448 .Return(); |
| 441 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 449 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 457 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) | 465 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) |
| 458 .ToHandleChecked(); | 466 .ToHandleChecked(); |
| 459 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); | 467 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); |
| 460 } | 468 } |
| 461 | 469 |
| 462 | 470 |
| 463 TEST(InterpreterParameter1Assign) { | 471 TEST(InterpreterParameter1Assign) { |
| 464 HandleAndZoneScope handles; | 472 HandleAndZoneScope handles; |
| 465 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 473 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 466 0, 0); | 474 0, 0); |
| 475 |
| 467 builder.LoadLiteral(Smi::FromInt(5)) | 476 builder.LoadLiteral(Smi::FromInt(5)) |
| 468 .StoreAccumulatorInRegister(builder.Parameter(0)) | 477 .StoreAccumulatorInRegister(builder.Parameter(0)) |
| 469 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 478 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
| 470 .Return(); | 479 .Return(); |
| 471 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 480 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 472 | 481 |
| 473 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 482 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 474 auto callable = tester.GetCallable<Handle<Object>>(); | 483 auto callable = tester.GetCallable<Handle<Object>>(); |
| 475 | 484 |
| 476 Handle<Object> return_val = | 485 Handle<Object> return_val = |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 594 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
| 586 | 595 |
| 587 Handle<i::TypeFeedbackVector> vector = | 596 Handle<i::TypeFeedbackVector> vector = |
| 588 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 597 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 589 | 598 |
| 590 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 599 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
| 591 name = factory->string_table()->LookupString(isolate, name); | 600 name = factory->string_table()->LookupString(isolate, name); |
| 592 | 601 |
| 593 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 602 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 594 0, 0); | 603 0, 0); |
| 604 |
| 595 builder.LoadNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot)) | 605 builder.LoadNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot)) |
| 596 .Return(); | 606 .Return(); |
| 597 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 607 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 598 | 608 |
| 599 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 609 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
| 600 auto callable = tester.GetCallable<Handle<Object>>(); | 610 auto callable = tester.GetCallable<Handle<Object>>(); |
| 601 | 611 |
| 602 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 612 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
| 603 // Test IC miss. | 613 // Test IC miss. |
| 604 Handle<Object> return_val = callable(object).ToHandleChecked(); | 614 Handle<Object> return_val = callable(object).ToHandleChecked(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); | 648 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); |
| 639 | 649 |
| 640 Handle<i::TypeFeedbackVector> vector = | 650 Handle<i::TypeFeedbackVector> vector = |
| 641 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 651 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 642 | 652 |
| 643 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); | 653 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); |
| 644 key = factory->string_table()->LookupString(isolate, key); | 654 key = factory->string_table()->LookupString(isolate, key); |
| 645 | 655 |
| 646 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 656 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 647 0, 1); | 657 0, 1); |
| 658 |
| 648 builder.LoadLiteral(key) | 659 builder.LoadLiteral(key) |
| 649 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot)) | 660 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot)) |
| 650 .Return(); | 661 .Return(); |
| 651 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 662 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 652 | 663 |
| 653 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 664 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
| 654 auto callable = tester.GetCallable<Handle<Object>>(); | 665 auto callable = tester.GetCallable<Handle<Object>>(); |
| 655 | 666 |
| 656 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); | 667 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); |
| 657 // Test IC miss. | 668 // Test IC miss. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 680 i::FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); | 691 i::FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); |
| 681 | 692 |
| 682 Handle<i::TypeFeedbackVector> vector = | 693 Handle<i::TypeFeedbackVector> vector = |
| 683 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 694 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 684 | 695 |
| 685 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 696 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
| 686 name = factory->string_table()->LookupString(isolate, name); | 697 name = factory->string_table()->LookupString(isolate, name); |
| 687 | 698 |
| 688 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 699 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 689 0, 0); | 700 0, 0); |
| 701 |
| 690 builder.LoadLiteral(Smi::FromInt(999)) | 702 builder.LoadLiteral(Smi::FromInt(999)) |
| 691 .StoreNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot), | 703 .StoreNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot), |
| 692 i::STRICT) | 704 i::STRICT) |
| 693 .Return(); | 705 .Return(); |
| 694 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 706 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 695 | 707 |
| 696 InterpreterTester tester(isolate, bytecode_array, vector); | 708 InterpreterTester tester(isolate, bytecode_array, vector); |
| 697 auto callable = tester.GetCallable<Handle<Object>>(); | 709 auto callable = tester.GetCallable<Handle<Object>>(); |
| 698 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 710 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
| 699 // Test IC miss. | 711 // Test IC miss. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedStoreICSlot(); | 751 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedStoreICSlot(); |
| 740 | 752 |
| 741 Handle<i::TypeFeedbackVector> vector = | 753 Handle<i::TypeFeedbackVector> vector = |
| 742 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 754 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 743 | 755 |
| 744 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 756 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
| 745 name = factory->string_table()->LookupString(isolate, name); | 757 name = factory->string_table()->LookupString(isolate, name); |
| 746 | 758 |
| 747 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 759 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 748 0, 1); | 760 0, 1); |
| 761 |
| 749 builder.LoadLiteral(name) | 762 builder.LoadLiteral(name) |
| 750 .StoreAccumulatorInRegister(Register(0)) | 763 .StoreAccumulatorInRegister(Register(0)) |
| 751 .LoadLiteral(Smi::FromInt(999)) | 764 .LoadLiteral(Smi::FromInt(999)) |
| 752 .StoreKeyedProperty(builder.Parameter(0), Register(0), | 765 .StoreKeyedProperty(builder.Parameter(0), Register(0), |
| 753 vector->GetIndex(slot), i::SLOPPY) | 766 vector->GetIndex(slot), i::SLOPPY) |
| 754 .Return(); | 767 .Return(); |
| 755 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 768 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 756 | 769 |
| 757 InterpreterTester tester(isolate, bytecode_array, vector); | 770 InterpreterTester tester(isolate, bytecode_array, vector); |
| 758 auto callable = tester.GetCallable<Handle<Object>>(); | 771 auto callable = tester.GetCallable<Handle<Object>>(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 789 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 802 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 790 int slot_index = vector->GetIndex(slot); | 803 int slot_index = vector->GetIndex(slot); |
| 791 | 804 |
| 792 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); | 805 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); |
| 793 name = factory->string_table()->LookupString(isolate, name); | 806 name = factory->string_table()->LookupString(isolate, name); |
| 794 | 807 |
| 795 // Check with no args. | 808 // Check with no args. |
| 796 { | 809 { |
| 797 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 810 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 798 0, 1); | 811 0, 1); |
| 812 |
| 799 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 813 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
| 800 .StoreAccumulatorInRegister(Register(0)) | 814 .StoreAccumulatorInRegister(Register(0)) |
| 801 .Call(Register(0), builder.Parameter(0), 1, 0, tail_call_mode) | 815 .Call(Register(0), builder.Parameter(0), 1, 0, tail_call_mode) |
| 802 .Return(); | 816 .Return(); |
| 803 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 817 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 804 | 818 |
| 805 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 819 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
| 806 auto callable = tester.GetCallable<Handle<Object>>(); | 820 auto callable = tester.GetCallable<Handle<Object>>(); |
| 807 | 821 |
| 808 Handle<Object> object = InterpreterTester::NewObject( | 822 Handle<Object> object = InterpreterTester::NewObject( |
| 809 "new (function Obj() { this.func = function() { return 0x265; }})()"); | 823 "new (function Obj() { this.func = function() { return 0x265; }})()"); |
| 810 Handle<Object> return_val = callable(object).ToHandleChecked(); | 824 Handle<Object> return_val = callable(object).ToHandleChecked(); |
| 811 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); | 825 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); |
| 812 } | 826 } |
| 813 | 827 |
| 814 // Check that receiver is passed properly. | 828 // Check that receiver is passed properly. |
| 815 { | 829 { |
| 816 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 830 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 817 0, 1); | 831 0, 1); |
| 832 |
| 818 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 833 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
| 819 .StoreAccumulatorInRegister(Register(0)) | 834 .StoreAccumulatorInRegister(Register(0)) |
| 820 .Call(Register(0), builder.Parameter(0), 1, 0, tail_call_mode) | 835 .Call(Register(0), builder.Parameter(0), 1, 0, tail_call_mode) |
| 821 .Return(); | 836 .Return(); |
| 822 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 837 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 823 | 838 |
| 824 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 839 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
| 825 auto callable = tester.GetCallable<Handle<Object>>(); | 840 auto callable = tester.GetCallable<Handle<Object>>(); |
| 826 | 841 |
| 827 Handle<Object> object = InterpreterTester::NewObject( | 842 Handle<Object> object = InterpreterTester::NewObject( |
| 828 "new (function Obj() {" | 843 "new (function Obj() {" |
| 829 " this.val = 1234;" | 844 " this.val = 1234;" |
| 830 " this.func = function() { return this.val; };" | 845 " this.func = function() { return this.val; };" |
| 831 "})()"); | 846 "})()"); |
| 832 Handle<Object> return_val = callable(object).ToHandleChecked(); | 847 Handle<Object> return_val = callable(object).ToHandleChecked(); |
| 833 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); | 848 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); |
| 834 } | 849 } |
| 835 | 850 |
| 836 // Check with two parameters (+ receiver). | 851 // Check with two parameters (+ receiver). |
| 837 { | 852 { |
| 838 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 853 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 839 0, 4); | 854 0, 4); |
| 855 |
| 840 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 856 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
| 841 .StoreAccumulatorInRegister(Register(0)) | 857 .StoreAccumulatorInRegister(Register(0)) |
| 842 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 858 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
| 843 .StoreAccumulatorInRegister(Register(1)) | 859 .StoreAccumulatorInRegister(Register(1)) |
| 844 .LoadLiteral(Smi::FromInt(51)) | 860 .LoadLiteral(Smi::FromInt(51)) |
| 845 .StoreAccumulatorInRegister(Register(2)) | 861 .StoreAccumulatorInRegister(Register(2)) |
| 846 .LoadLiteral(Smi::FromInt(11)) | 862 .LoadLiteral(Smi::FromInt(11)) |
| 847 .StoreAccumulatorInRegister(Register(3)) | 863 .StoreAccumulatorInRegister(Register(3)) |
| 848 .Call(Register(0), Register(1), 3, 0, tail_call_mode) | 864 .Call(Register(0), Register(1), 3, 0, tail_call_mode) |
| 849 .Return(); | 865 .Return(); |
| 850 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 866 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 851 | 867 |
| 852 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 868 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
| 853 auto callable = tester.GetCallable<Handle<Object>>(); | 869 auto callable = tester.GetCallable<Handle<Object>>(); |
| 854 | 870 |
| 855 Handle<Object> object = InterpreterTester::NewObject( | 871 Handle<Object> object = InterpreterTester::NewObject( |
| 856 "new (function Obj() { " | 872 "new (function Obj() { " |
| 857 " this.func = function(a, b) { return a - b; }" | 873 " this.func = function(a, b) { return a - b; }" |
| 858 "})()"); | 874 "})()"); |
| 859 Handle<Object> return_val = callable(object).ToHandleChecked(); | 875 Handle<Object> return_val = callable(object).ToHandleChecked(); |
| 860 CHECK(return_val->SameValue(Smi::FromInt(40))); | 876 CHECK(return_val->SameValue(Smi::FromInt(40))); |
| 861 } | 877 } |
| 862 | 878 |
| 863 // Check with 10 parameters (+ receiver). | 879 // Check with 10 parameters (+ receiver). |
| 864 { | 880 { |
| 865 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 881 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 866 0, 12); | 882 0, 12); |
| 883 |
| 867 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 884 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
| 868 .StoreAccumulatorInRegister(Register(0)) | 885 .StoreAccumulatorInRegister(Register(0)) |
| 869 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 886 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
| 870 .StoreAccumulatorInRegister(Register(1)) | 887 .StoreAccumulatorInRegister(Register(1)) |
| 871 .LoadLiteral(factory->NewStringFromAsciiChecked("a")) | 888 .LoadLiteral(factory->NewStringFromAsciiChecked("a")) |
| 872 .StoreAccumulatorInRegister(Register(2)) | 889 .StoreAccumulatorInRegister(Register(2)) |
| 873 .LoadLiteral(factory->NewStringFromAsciiChecked("b")) | 890 .LoadLiteral(factory->NewStringFromAsciiChecked("b")) |
| 874 .StoreAccumulatorInRegister(Register(3)) | 891 .StoreAccumulatorInRegister(Register(3)) |
| 875 .LoadLiteral(factory->NewStringFromAsciiChecked("c")) | 892 .LoadLiteral(factory->NewStringFromAsciiChecked("c")) |
| 876 .StoreAccumulatorInRegister(Register(4)) | 893 .StoreAccumulatorInRegister(Register(4)) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 .BinaryOperation(Token::Value::ADD, reg) | 948 .BinaryOperation(Token::Value::ADD, reg) |
| 932 .StoreAccumulatorInRegister(reg) | 949 .StoreAccumulatorInRegister(reg) |
| 933 .LoadAccumulatorWithRegister(scratch); | 950 .LoadAccumulatorWithRegister(scratch); |
| 934 } | 951 } |
| 935 | 952 |
| 936 | 953 |
| 937 TEST(InterpreterJumps) { | 954 TEST(InterpreterJumps) { |
| 938 HandleAndZoneScope handles; | 955 HandleAndZoneScope handles; |
| 939 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 956 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, |
| 940 0, 2); | 957 0, 2); |
| 958 |
| 941 Register reg(0), scratch(1); | 959 Register reg(0), scratch(1); |
| 942 BytecodeLabel label[3]; | 960 BytecodeLabel label[3]; |
| 943 | 961 |
| 944 builder.LoadLiteral(Smi::FromInt(0)) | 962 builder.LoadLiteral(Smi::FromInt(0)) |
| 945 .StoreAccumulatorInRegister(reg) | 963 .StoreAccumulatorInRegister(reg) |
| 946 .Jump(&label[1]); | 964 .Jump(&label[1]); |
| 947 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]); | 965 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]); |
| 948 IncrementRegister(builder, reg, 1, scratch).Jump(&label[2]); | 966 IncrementRegister(builder, reg, 1, scratch).Jump(&label[2]); |
| 949 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]); | 967 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]); |
| 950 IncrementRegister(builder, reg, 2, scratch).Jump(&label[0]); | 968 IncrementRegister(builder, reg, 2, scratch).Jump(&label[0]); |
| 951 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]); | 969 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]); |
| 952 IncrementRegister(builder, reg, 4, scratch) | 970 IncrementRegister(builder, reg, 4, scratch) |
| 953 .LoadAccumulatorWithRegister(reg) | 971 .LoadAccumulatorWithRegister(reg) |
| 954 .Return(); | 972 .Return(); |
| 955 | 973 |
| 956 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 974 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 957 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 975 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 958 auto callable = tester.GetCallable<>(); | 976 auto callable = tester.GetCallable<>(); |
| 959 Handle<Object> return_value = callable().ToHandleChecked(); | 977 Handle<Object> return_value = callable().ToHandleChecked(); |
| 960 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 978 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
| 961 } | 979 } |
| 962 | 980 |
| 963 | 981 |
| 964 TEST(InterpreterConditionalJumps) { | 982 TEST(InterpreterConditionalJumps) { |
| 965 HandleAndZoneScope handles; | 983 HandleAndZoneScope handles; |
| 966 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 984 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, |
| 967 0, 2); | 985 0, 2); |
| 986 |
| 968 Register reg(0), scratch(1); | 987 Register reg(0), scratch(1); |
| 969 BytecodeLabel label[2]; | 988 BytecodeLabel label[2]; |
| 970 BytecodeLabel done, done1; | 989 BytecodeLabel done, done1; |
| 971 | 990 |
| 972 builder.LoadLiteral(Smi::FromInt(0)) | 991 builder.LoadLiteral(Smi::FromInt(0)) |
| 973 .StoreAccumulatorInRegister(reg) | 992 .StoreAccumulatorInRegister(reg) |
| 974 .LoadFalse() | 993 .LoadFalse() |
| 975 .JumpIfFalse(&label[0]); | 994 .JumpIfFalse(&label[0]); |
| 976 IncrementRegister(builder, reg, 1024, scratch) | 995 IncrementRegister(builder, reg, 1024, scratch) |
| 977 .Bind(&label[0]) | 996 .Bind(&label[0]) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 991 auto callable = tester.GetCallable<>(); | 1010 auto callable = tester.GetCallable<>(); |
| 992 Handle<Object> return_value = callable().ToHandleChecked(); | 1011 Handle<Object> return_value = callable().ToHandleChecked(); |
| 993 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 1012 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
| 994 } | 1013 } |
| 995 | 1014 |
| 996 TEST(InterpreterConditionalJumps2) { | 1015 TEST(InterpreterConditionalJumps2) { |
| 997 // TODO(oth): Add tests for all conditional jumps near and far. | 1016 // TODO(oth): Add tests for all conditional jumps near and far. |
| 998 HandleAndZoneScope handles; | 1017 HandleAndZoneScope handles; |
| 999 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1018 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, |
| 1000 0, 2); | 1019 0, 2); |
| 1020 |
| 1001 Register reg(0), scratch(1); | 1021 Register reg(0), scratch(1); |
| 1002 BytecodeLabel label[2]; | 1022 BytecodeLabel label[2]; |
| 1003 BytecodeLabel done, done1; | 1023 BytecodeLabel done, done1; |
| 1004 | 1024 |
| 1005 builder.LoadLiteral(Smi::FromInt(0)) | 1025 builder.LoadLiteral(Smi::FromInt(0)) |
| 1006 .StoreAccumulatorInRegister(reg) | 1026 .StoreAccumulatorInRegister(reg) |
| 1007 .LoadFalse() | 1027 .LoadFalse() |
| 1008 .JumpIfFalse(&label[0]); | 1028 .JumpIfFalse(&label[0]); |
| 1009 IncrementRegister(builder, reg, 1024, scratch) | 1029 IncrementRegister(builder, reg, 1024, scratch) |
| 1010 .Bind(&label[0]) | 1030 .Bind(&label[0]) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1023 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1043 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1024 auto callable = tester.GetCallable<>(); | 1044 auto callable = tester.GetCallable<>(); |
| 1025 Handle<Object> return_value = callable().ToHandleChecked(); | 1045 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1026 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 1046 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
| 1027 } | 1047 } |
| 1028 | 1048 |
| 1029 TEST(InterpreterJumpConstantWith16BitOperand) { | 1049 TEST(InterpreterJumpConstantWith16BitOperand) { |
| 1030 HandleAndZoneScope handles; | 1050 HandleAndZoneScope handles; |
| 1031 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1051 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 1032 0, 257); | 1052 0, 257); |
| 1053 |
| 1033 Register reg(0), scratch(256); | 1054 Register reg(0), scratch(256); |
| 1034 BytecodeLabel done; | 1055 BytecodeLabel done; |
| 1035 | 1056 |
| 1036 builder.LoadLiteral(Smi::FromInt(0)); | 1057 builder.LoadLiteral(Smi::FromInt(0)); |
| 1037 builder.StoreAccumulatorInRegister(reg); | 1058 builder.StoreAccumulatorInRegister(reg); |
| 1038 // Consume all 8-bit operands | 1059 // Consume all 8-bit operands |
| 1039 for (int i = 1; i <= 256; i++) { | 1060 for (int i = 1; i <= 256; i++) { |
| 1040 builder.LoadLiteral(handles.main_isolate()->factory()->NewNumber(i)); | 1061 builder.LoadLiteral(handles.main_isolate()->factory()->NewNumber(i)); |
| 1041 builder.BinaryOperation(Token::Value::ADD, reg); | 1062 builder.BinaryOperation(Token::Value::ADD, reg); |
| 1042 builder.StoreAccumulatorInRegister(reg); | 1063 builder.StoreAccumulatorInRegister(reg); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 v8::internal::kMaxInt / 4, | 1181 v8::internal::kMaxInt / 4, |
| 1161 v8::internal::kMaxInt / 2}; | 1182 v8::internal::kMaxInt / 2}; |
| 1162 | 1183 |
| 1163 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1184 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
| 1164 Token::Value comparison = kComparisonTypes[c]; | 1185 Token::Value comparison = kComparisonTypes[c]; |
| 1165 for (size_t i = 0; i < arraysize(inputs); i++) { | 1186 for (size_t i = 0; i < arraysize(inputs); i++) { |
| 1166 for (size_t j = 0; j < arraysize(inputs); j++) { | 1187 for (size_t j = 0; j < arraysize(inputs); j++) { |
| 1167 HandleAndZoneScope handles; | 1188 HandleAndZoneScope handles; |
| 1168 BytecodeArrayBuilder builder(handles.main_isolate(), | 1189 BytecodeArrayBuilder builder(handles.main_isolate(), |
| 1169 handles.main_zone(), 0, 0, 1); | 1190 handles.main_zone(), 0, 0, 1); |
| 1191 |
| 1170 Register r0(0); | 1192 Register r0(0); |
| 1171 builder.LoadLiteral(Smi::FromInt(inputs[i])) | 1193 builder.LoadLiteral(Smi::FromInt(inputs[i])) |
| 1172 .StoreAccumulatorInRegister(r0) | 1194 .StoreAccumulatorInRegister(r0) |
| 1173 .LoadLiteral(Smi::FromInt(inputs[j])) | 1195 .LoadLiteral(Smi::FromInt(inputs[j])) |
| 1174 .CompareOperation(comparison, r0) | 1196 .CompareOperation(comparison, r0) |
| 1175 .Return(); | 1197 .Return(); |
| 1176 | 1198 |
| 1177 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1199 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1178 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1200 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1179 auto callable = tester.GetCallable<>(); | 1201 auto callable = tester.GetCallable<>(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1196 1e99, | 1218 1e99, |
| 1197 -1e-99}; | 1219 -1e-99}; |
| 1198 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1220 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
| 1199 Token::Value comparison = kComparisonTypes[c]; | 1221 Token::Value comparison = kComparisonTypes[c]; |
| 1200 for (size_t i = 0; i < arraysize(inputs); i++) { | 1222 for (size_t i = 0; i < arraysize(inputs); i++) { |
| 1201 for (size_t j = 0; j < arraysize(inputs); j++) { | 1223 for (size_t j = 0; j < arraysize(inputs); j++) { |
| 1202 HandleAndZoneScope handles; | 1224 HandleAndZoneScope handles; |
| 1203 i::Factory* factory = handles.main_isolate()->factory(); | 1225 i::Factory* factory = handles.main_isolate()->factory(); |
| 1204 BytecodeArrayBuilder builder(handles.main_isolate(), | 1226 BytecodeArrayBuilder builder(handles.main_isolate(), |
| 1205 handles.main_zone(), 0, 0, 1); | 1227 handles.main_zone(), 0, 0, 1); |
| 1228 |
| 1206 Register r0(0); | 1229 Register r0(0); |
| 1207 builder.LoadLiteral(factory->NewHeapNumber(inputs[i])) | 1230 builder.LoadLiteral(factory->NewHeapNumber(inputs[i])) |
| 1208 .StoreAccumulatorInRegister(r0) | 1231 .StoreAccumulatorInRegister(r0) |
| 1209 .LoadLiteral(factory->NewHeapNumber(inputs[j])) | 1232 .LoadLiteral(factory->NewHeapNumber(inputs[j])) |
| 1210 .CompareOperation(comparison, r0) | 1233 .CompareOperation(comparison, r0) |
| 1211 .Return(); | 1234 .Return(); |
| 1212 | 1235 |
| 1213 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1236 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1214 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1237 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1215 auto callable = tester.GetCallable<>(); | 1238 auto callable = tester.GetCallable<>(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1229 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1252 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
| 1230 Token::Value comparison = kComparisonTypes[c]; | 1253 Token::Value comparison = kComparisonTypes[c]; |
| 1231 for (size_t i = 0; i < arraysize(inputs); i++) { | 1254 for (size_t i = 0; i < arraysize(inputs); i++) { |
| 1232 for (size_t j = 0; j < arraysize(inputs); j++) { | 1255 for (size_t j = 0; j < arraysize(inputs); j++) { |
| 1233 const char* lhs = inputs[i].c_str(); | 1256 const char* lhs = inputs[i].c_str(); |
| 1234 const char* rhs = inputs[j].c_str(); | 1257 const char* rhs = inputs[j].c_str(); |
| 1235 HandleAndZoneScope handles; | 1258 HandleAndZoneScope handles; |
| 1236 i::Factory* factory = handles.main_isolate()->factory(); | 1259 i::Factory* factory = handles.main_isolate()->factory(); |
| 1237 BytecodeArrayBuilder builder(handles.main_isolate(), | 1260 BytecodeArrayBuilder builder(handles.main_isolate(), |
| 1238 handles.main_zone(), 0, 0, 1); | 1261 handles.main_zone(), 0, 0, 1); |
| 1262 |
| 1239 Register r0(0); | 1263 Register r0(0); |
| 1240 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs)) | 1264 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs)) |
| 1241 .StoreAccumulatorInRegister(r0) | 1265 .StoreAccumulatorInRegister(r0) |
| 1242 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs)) | 1266 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs)) |
| 1243 .CompareOperation(comparison, r0) | 1267 .CompareOperation(comparison, r0) |
| 1244 .Return(); | 1268 .Return(); |
| 1245 | 1269 |
| 1246 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1270 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1247 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1271 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1248 auto callable = tester.GetCallable<>(); | 1272 auto callable = tester.GetCallable<>(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1273 const char* lhs_cstr = inputs[i]; | 1297 const char* lhs_cstr = inputs[i]; |
| 1274 const char* rhs_cstr = inputs[j]; | 1298 const char* rhs_cstr = inputs[j]; |
| 1275 double lhs = StringToDouble(&unicode_cache, lhs_cstr, | 1299 double lhs = StringToDouble(&unicode_cache, lhs_cstr, |
| 1276 i::ConversionFlags::NO_FLAGS); | 1300 i::ConversionFlags::NO_FLAGS); |
| 1277 double rhs = StringToDouble(&unicode_cache, rhs_cstr, | 1301 double rhs = StringToDouble(&unicode_cache, rhs_cstr, |
| 1278 i::ConversionFlags::NO_FLAGS); | 1302 i::ConversionFlags::NO_FLAGS); |
| 1279 HandleAndZoneScope handles; | 1303 HandleAndZoneScope handles; |
| 1280 i::Factory* factory = handles.main_isolate()->factory(); | 1304 i::Factory* factory = handles.main_isolate()->factory(); |
| 1281 BytecodeArrayBuilder builder(handles.main_isolate(), | 1305 BytecodeArrayBuilder builder(handles.main_isolate(), |
| 1282 handles.main_zone(), 0, 0, 1); | 1306 handles.main_zone(), 0, 0, 1); |
| 1307 |
| 1283 Register r0(0); | 1308 Register r0(0); |
| 1284 if (pass == 0) { | 1309 if (pass == 0) { |
| 1285 // Comparison with HeapNumber on the lhs and String on the rhs | 1310 // Comparison with HeapNumber on the lhs and String on the rhs |
| 1286 builder.LoadLiteral(factory->NewNumber(lhs)) | 1311 builder.LoadLiteral(factory->NewNumber(lhs)) |
| 1287 .StoreAccumulatorInRegister(r0) | 1312 .StoreAccumulatorInRegister(r0) |
| 1288 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs_cstr)) | 1313 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs_cstr)) |
| 1289 .CompareOperation(comparison, r0) | 1314 .CompareOperation(comparison, r0) |
| 1290 .Return(); | 1315 .Return(); |
| 1291 } else { | 1316 } else { |
| 1292 // Comparison with HeapNumber on the rhs and String on the lhs | 1317 // Comparison with HeapNumber on the rhs and String on the lhs |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 i::Factory* factory = handles.main_isolate()->factory(); | 1411 i::Factory* factory = handles.main_isolate()->factory(); |
| 1387 Handle<i::String> name = factory->NewStringFromAsciiChecked("cons"); | 1412 Handle<i::String> name = factory->NewStringFromAsciiChecked("cons"); |
| 1388 Handle<i::JSFunction> func = factory->NewFunction(name); | 1413 Handle<i::JSFunction> func = factory->NewFunction(name); |
| 1389 Handle<i::JSObject> instance = factory->NewJSObject(func); | 1414 Handle<i::JSObject> instance = factory->NewJSObject(func); |
| 1390 Handle<i::Object> other = factory->NewNumber(3.3333); | 1415 Handle<i::Object> other = factory->NewNumber(3.3333); |
| 1391 Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; | 1416 Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; |
| 1392 for (size_t i = 0; i < arraysize(cases); i++) { | 1417 for (size_t i = 0; i < arraysize(cases); i++) { |
| 1393 bool expected_value = (i == 0); | 1418 bool expected_value = (i == 0); |
| 1394 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1419 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, |
| 1395 0, 1); | 1420 0, 1); |
| 1421 |
| 1396 Register r0(0); | 1422 Register r0(0); |
| 1397 builder.LoadLiteral(cases[i]); | 1423 builder.LoadLiteral(cases[i]); |
| 1398 builder.StoreAccumulatorInRegister(r0) | 1424 builder.StoreAccumulatorInRegister(r0) |
| 1399 .LoadLiteral(func) | 1425 .LoadLiteral(func) |
| 1400 .CompareOperation(Token::Value::INSTANCEOF, r0) | 1426 .CompareOperation(Token::Value::INSTANCEOF, r0) |
| 1401 .Return(); | 1427 .Return(); |
| 1402 | 1428 |
| 1403 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1429 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1404 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1430 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1405 auto callable = tester.GetCallable<>(); | 1431 auto callable = tester.GetCallable<>(); |
| 1406 Handle<Object> return_value = callable().ToHandleChecked(); | 1432 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1407 CHECK(return_value->IsBoolean()); | 1433 CHECK(return_value->IsBoolean()); |
| 1408 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1434 CHECK_EQ(return_value->BooleanValue(), expected_value); |
| 1409 } | 1435 } |
| 1410 } | 1436 } |
| 1411 | 1437 |
| 1412 | 1438 |
| 1413 TEST(InterpreterTestIn) { | 1439 TEST(InterpreterTestIn) { |
| 1414 HandleAndZoneScope handles; | 1440 HandleAndZoneScope handles; |
| 1415 i::Factory* factory = handles.main_isolate()->factory(); | 1441 i::Factory* factory = handles.main_isolate()->factory(); |
| 1416 // Allocate an array | 1442 // Allocate an array |
| 1417 Handle<i::JSArray> array = | 1443 Handle<i::JSArray> array = |
| 1418 factory->NewJSArray(0, i::ElementsKind::FAST_SMI_ELEMENTS); | 1444 factory->NewJSArray(0, i::ElementsKind::FAST_SMI_ELEMENTS); |
| 1419 // Check for these properties on the array object | 1445 // Check for these properties on the array object |
| 1420 const char* properties[] = {"length", "fuzzle", "x", "0"}; | 1446 const char* properties[] = {"length", "fuzzle", "x", "0"}; |
| 1421 for (size_t i = 0; i < arraysize(properties); i++) { | 1447 for (size_t i = 0; i < arraysize(properties); i++) { |
| 1422 bool expected_value = (i == 0); | 1448 bool expected_value = (i == 0); |
| 1423 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1449 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, |
| 1424 0, 1); | 1450 0, 1); |
| 1451 |
| 1425 Register r0(0); | 1452 Register r0(0); |
| 1426 builder.LoadLiteral(factory->NewStringFromAsciiChecked(properties[i])) | 1453 builder.LoadLiteral(factory->NewStringFromAsciiChecked(properties[i])) |
| 1427 .StoreAccumulatorInRegister(r0) | 1454 .StoreAccumulatorInRegister(r0) |
| 1428 .LoadLiteral(Handle<Object>::cast(array)) | 1455 .LoadLiteral(Handle<Object>::cast(array)) |
| 1429 .CompareOperation(Token::Value::IN, r0) | 1456 .CompareOperation(Token::Value::IN, r0) |
| 1430 .Return(); | 1457 .Return(); |
| 1431 | 1458 |
| 1432 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1459 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1433 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1460 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1434 auto callable = tester.GetCallable<>(); | 1461 auto callable = tester.GetCallable<>(); |
| 1435 Handle<Object> return_value = callable().ToHandleChecked(); | 1462 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1436 CHECK(return_value->IsBoolean()); | 1463 CHECK(return_value->IsBoolean()); |
| 1437 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1464 CHECK_EQ(return_value->BooleanValue(), expected_value); |
| 1438 } | 1465 } |
| 1439 } | 1466 } |
| 1440 | 1467 |
| 1441 | 1468 |
| 1442 TEST(InterpreterUnaryNot) { | 1469 TEST(InterpreterUnaryNot) { |
| 1443 HandleAndZoneScope handles; | 1470 HandleAndZoneScope handles; |
| 1444 for (size_t i = 1; i < 10; i++) { | 1471 for (size_t i = 1; i < 10; i++) { |
| 1445 bool expected_value = ((i & 1) == 1); | 1472 bool expected_value = ((i & 1) == 1); |
| 1446 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1473 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, |
| 1447 0, 0); | 1474 0, 0); |
| 1475 |
| 1448 Register r0(0); | 1476 Register r0(0); |
| 1449 builder.LoadFalse(); | 1477 builder.LoadFalse(); |
| 1450 for (size_t j = 0; j < i; j++) { | 1478 for (size_t j = 0; j < i; j++) { |
| 1451 builder.LogicalNot(); | 1479 builder.LogicalNot(); |
| 1452 } | 1480 } |
| 1453 builder.Return(); | 1481 builder.Return(); |
| 1454 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1482 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1455 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1483 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1456 auto callable = tester.GetCallable<>(); | 1484 auto callable = tester.GetCallable<>(); |
| 1457 Handle<Object> return_value = callable().ToHandleChecked(); | 1485 Handle<Object> return_value = callable().ToHandleChecked(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 std::make_pair( | 1527 std::make_pair( |
| 1500 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")), | 1528 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")), |
| 1501 false), | 1529 false), |
| 1502 std::make_pair( | 1530 std::make_pair( |
| 1503 Handle<Object>::cast(factory->NewStringFromStaticChars("")), true), | 1531 Handle<Object>::cast(factory->NewStringFromStaticChars("")), true), |
| 1504 }; | 1532 }; |
| 1505 | 1533 |
| 1506 for (size_t i = 0; i < arraysize(object_type_tuples); i++) { | 1534 for (size_t i = 0; i < arraysize(object_type_tuples); i++) { |
| 1507 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1535 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, |
| 1508 0, 0); | 1536 0, 0); |
| 1537 |
| 1509 Register r0(0); | 1538 Register r0(0); |
| 1510 LoadAny(&builder, factory, object_type_tuples[i].first); | 1539 LoadAny(&builder, factory, object_type_tuples[i].first); |
| 1511 builder.LogicalNot(); | 1540 builder.LogicalNot(); |
| 1512 builder.Return(); | 1541 builder.Return(); |
| 1513 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1542 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1514 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1543 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1515 auto callable = tester.GetCallable<>(); | 1544 auto callable = tester.GetCallable<>(); |
| 1516 Handle<Object> return_value = callable().ToHandleChecked(); | 1545 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1517 CHECK(return_value->IsBoolean()); | 1546 CHECK(return_value->IsBoolean()); |
| 1518 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second); | 1547 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1545 CHECK_EQ(strcmp(&actual[0], typeof_vals[i].second), 0); | 1574 CHECK_EQ(strcmp(&actual[0], typeof_vals[i].second), 0); |
| 1546 } | 1575 } |
| 1547 } | 1576 } |
| 1548 | 1577 |
| 1549 | 1578 |
| 1550 TEST(InterpreterCallRuntime) { | 1579 TEST(InterpreterCallRuntime) { |
| 1551 HandleAndZoneScope handles; | 1580 HandleAndZoneScope handles; |
| 1552 | 1581 |
| 1553 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1582 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 1554 0, 2); | 1583 0, 2); |
| 1584 |
| 1555 builder.LoadLiteral(Smi::FromInt(15)) | 1585 builder.LoadLiteral(Smi::FromInt(15)) |
| 1556 .StoreAccumulatorInRegister(Register(0)) | 1586 .StoreAccumulatorInRegister(Register(0)) |
| 1557 .LoadLiteral(Smi::FromInt(40)) | 1587 .LoadLiteral(Smi::FromInt(40)) |
| 1558 .StoreAccumulatorInRegister(Register(1)) | 1588 .StoreAccumulatorInRegister(Register(1)) |
| 1559 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1589 .CallRuntime(Runtime::kAdd, Register(0), 2) |
| 1560 .Return(); | 1590 .Return(); |
| 1561 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1591 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1562 | 1592 |
| 1563 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1593 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1564 auto callable = tester.GetCallable<>(); | 1594 auto callable = tester.GetCallable<>(); |
| 1565 | 1595 |
| 1566 Handle<Object> return_val = callable().ToHandleChecked(); | 1596 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1567 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1597 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
| 1568 } | 1598 } |
| 1569 | 1599 |
| 1570 TEST(InterpreterInvokeIntrinsic) { | 1600 TEST(InterpreterInvokeIntrinsic) { |
| 1571 HandleAndZoneScope handles; | 1601 HandleAndZoneScope handles; |
| 1572 | 1602 |
| 1573 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1603 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, |
| 1574 0, 2); | 1604 0, 2); |
| 1605 |
| 1575 builder.LoadLiteral(Smi::FromInt(15)) | 1606 builder.LoadLiteral(Smi::FromInt(15)) |
| 1576 .StoreAccumulatorInRegister(Register(0)) | 1607 .StoreAccumulatorInRegister(Register(0)) |
| 1577 .CallRuntime(Runtime::kInlineIsArray, Register(0), 1) | 1608 .CallRuntime(Runtime::kInlineIsArray, Register(0), 1) |
| 1578 .Return(); | 1609 .Return(); |
| 1579 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1610 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1580 | 1611 |
| 1581 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1612 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1582 auto callable = tester.GetCallable<>(); | 1613 auto callable = tester.GetCallable<>(); |
| 1583 | 1614 |
| 1584 Handle<Object> return_val = callable().ToHandleChecked(); | 1615 Handle<Object> return_val = callable().ToHandleChecked(); |
| (...skipping 2576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4161 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4192 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 4162 CHECK(return_value->SameValue(*tests[i].second)); | 4193 CHECK(return_value->SameValue(*tests[i].second)); |
| 4163 } | 4194 } |
| 4164 | 4195 |
| 4165 FLAG_ignition_generators = old_flag; | 4196 FLAG_ignition_generators = old_flag; |
| 4166 } | 4197 } |
| 4167 | 4198 |
| 4168 } // namespace interpreter | 4199 } // namespace interpreter |
| 4169 } // namespace internal | 4200 } // namespace internal |
| 4170 } // namespace v8 | 4201 } // namespace v8 |
| OLD | NEW |