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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "src/compiler/pipeline.h" | 7 #include "src/compiler/pipeline.h" |
8 #include "src/execution.h" | 8 #include "src/execution.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/interpreter/bytecode-array-builder.h" | 10 #include "src/interpreter/bytecode-array-builder.h" |
(...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2552 | 2552 |
2553 BytecodeGraphTester tester(isolate, zone, script.start()); | 2553 BytecodeGraphTester tester(isolate, zone, script.start()); |
2554 auto callable = tester.GetCallable<>(); | 2554 auto callable = tester.GetCallable<>(); |
2555 Handle<Object> return_value = callable().ToHandleChecked(); | 2555 Handle<Object> return_value = callable().ToHandleChecked(); |
2556 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2556 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2557 } | 2557 } |
2558 } | 2558 } |
2559 | 2559 |
2560 | 2560 |
2561 TEST(JumpWithConstantsAndWideConstants) { | 2561 TEST(JumpWithConstantsAndWideConstants) { |
2562 HandleAndZoneScope scope; | |
2563 auto isolate = scope.main_isolate(); | |
2564 const int kStep = 19; | 2562 const int kStep = 19; |
2565 int start = 7; | 2563 int start = 7; |
2566 for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) { | 2564 for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) { |
2567 std::stringstream filler_os; | 2565 std::stringstream filler_os; |
2568 // Generate a string that consumes constant pool entries and | 2566 // Generate a string that consumes constant pool entries and |
2569 // spread out branch distances in script below. | 2567 // spread out branch distances in script below. |
2570 for (int i = 0; i < constants; i++) { | 2568 for (int i = 0; i < constants; i++) { |
2571 filler_os << "var x_ = 'x_" << i << "';\n"; | 2569 filler_os << "var x_ = 'x_" << i << "';\n"; |
2572 } | 2570 } |
2573 std::string filler(filler_os.str()); | 2571 std::string filler(filler_os.str()); |
2574 | 2572 |
2575 std::stringstream script_os; | 2573 std::stringstream script_os; |
2576 script_os << "function " << kFunctionName << "(a) {\n"; | 2574 script_os << "function " << kFunctionName << "(a) {\n"; |
2577 script_os << " " << filler; | 2575 script_os << " " << filler; |
2578 script_os << " for (var i = a; i < 2; i++) {\n"; | 2576 script_os << " for (var i = a; i < 2; i++) {\n"; |
2579 script_os << " " << filler; | 2577 script_os << " " << filler; |
2580 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; | 2578 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; |
2581 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n"; | 2579 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n"; |
2582 script_os << " else { " << filler << " }\n"; | 2580 script_os << " else { " << filler << " }\n"; |
2583 script_os << " }\n"; | 2581 script_os << " }\n"; |
2584 script_os << " return i;\n"; | 2582 script_os << " return i;\n"; |
2585 script_os << "}\n"; | 2583 script_os << "}\n"; |
2586 script_os << kFunctionName << "(0);\n"; | 2584 script_os << kFunctionName << "(0);\n"; |
2587 std::string script(script_os.str()); | 2585 std::string script(script_os.str()); |
| 2586 |
| 2587 HandleAndZoneScope scope; |
| 2588 auto isolate = scope.main_isolate(); |
2588 auto factory = isolate->factory(); | 2589 auto factory = isolate->factory(); |
2589 auto zone = scope.main_zone(); | 2590 auto zone = scope.main_zone(); |
2590 for (int a = 0; a < 3; a++) { | 2591 for (int a = 0; a < 3; a++) { |
2591 BytecodeGraphTester tester(isolate, zone, script.c_str()); | 2592 BytecodeGraphTester tester(isolate, zone, script.c_str()); |
2592 auto callable = tester.GetCallable<Handle<Object>>(); | 2593 auto callable = tester.GetCallable<Handle<Object>>(); |
2593 Handle<Object> return_val = | 2594 Handle<Object> return_val = |
2594 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); | 2595 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); |
2595 static const int results[] = {11, 12, 2}; | 2596 static const int results[] = {11, 12, 2}; |
2596 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); | 2597 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
2597 } | 2598 } |
(...skipping 29 matching lines...) Expand all Loading... |
2627 Handle<Object> return_value = callable().ToHandleChecked(); | 2628 Handle<Object> return_value = callable().ToHandleChecked(); |
2628 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2629 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2629 } | 2630 } |
2630 | 2631 |
2631 FLAG_harmony_do_expressions = old_flag; | 2632 FLAG_harmony_do_expressions = old_flag; |
2632 } | 2633 } |
2633 | 2634 |
2634 } // namespace compiler | 2635 } // namespace compiler |
2635 } // namespace internal | 2636 } // namespace internal |
2636 } // namespace v8 | 2637 } // namespace v8 |
OLD | NEW |