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 2088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 snippets[i].code_snippet, kFunctionName); | 2099 snippets[i].code_snippet, kFunctionName); |
2100 | 2100 |
2101 BytecodeGraphTester tester(isolate, zone, script.start()); | 2101 BytecodeGraphTester tester(isolate, zone, script.start()); |
2102 auto callable = tester.GetCallable<>(); | 2102 auto callable = tester.GetCallable<>(); |
2103 Handle<Object> return_value = callable().ToHandleChecked(); | 2103 Handle<Object> return_value = callable().ToHandleChecked(); |
2104 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2104 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2105 } | 2105 } |
2106 } | 2106 } |
2107 | 2107 |
2108 | 2108 |
| 2109 TEST(JumpWithConstantsAndWideConstants) { |
| 2110 HandleAndZoneScope scope; |
| 2111 auto isolate = scope.main_isolate(); |
| 2112 const int kStep = 19; |
| 2113 int start = 7; |
| 2114 for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) { |
| 2115 std::stringstream filler_os; |
| 2116 // Generate a string that consumes constant pool entries and |
| 2117 // spread out branch distances in script below. |
| 2118 for (int i = 0; i < constants; i++) { |
| 2119 filler_os << "var x_ = 'x_" << i << "';\n"; |
| 2120 } |
| 2121 std::string filler(filler_os.str()); |
| 2122 |
| 2123 std::stringstream script_os; |
| 2124 script_os << "function " << kFunctionName << "(a) {\n"; |
| 2125 script_os << " " << filler; |
| 2126 script_os << " for (var i = a; i < 2; i++) {\n"; |
| 2127 script_os << " " << filler; |
| 2128 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; |
| 2129 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n"; |
| 2130 script_os << " else { " << filler << " }\n"; |
| 2131 script_os << " }\n"; |
| 2132 script_os << " return i;\n"; |
| 2133 script_os << "}\n"; |
| 2134 script_os << kFunctionName << "(0);\n"; |
| 2135 std::string script(script_os.str()); |
| 2136 auto factory = isolate->factory(); |
| 2137 auto zone = scope.main_zone(); |
| 2138 for (int a = 0; a < 3; a++) { |
| 2139 BytecodeGraphTester tester(isolate, zone, script.c_str()); |
| 2140 auto callable = tester.GetCallable<Handle<Object>>(); |
| 2141 Handle<Object> return_val = |
| 2142 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); |
| 2143 static const int results[] = {11, 12, 2}; |
| 2144 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
| 2145 } |
| 2146 } |
| 2147 } |
| 2148 |
2109 } // namespace compiler | 2149 } // namespace compiler |
2110 } // namespace internal | 2150 } // namespace internal |
2111 } // namespace v8 | 2151 } // namespace v8 |
OLD | NEW |