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/base/utils/random-number-generator.h" |
7 #include "src/compiler/pipeline.h" | 8 #include "src/compiler/pipeline.h" |
8 #include "src/execution.h" | 9 #include "src/execution.h" |
9 #include "src/handles.h" | 10 #include "src/handles.h" |
10 #include "src/interpreter/bytecode-array-builder.h" | 11 #include "src/interpreter/bytecode-array-builder.h" |
11 #include "src/interpreter/interpreter.h" | 12 #include "src/interpreter/interpreter.h" |
12 #include "src/parsing/parser.h" | 13 #include "src/parsing/parser.h" |
13 #include "test/cctest/cctest.h" | 14 #include "test/cctest/cctest.h" |
14 | 15 |
15 namespace v8 { | 16 namespace v8 { |
16 namespace internal { | 17 namespace internal { |
(...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2021 snippets[i].code_snippet, kFunctionName); | 2022 snippets[i].code_snippet, kFunctionName); |
2022 | 2023 |
2023 BytecodeGraphTester tester(isolate, zone, script.start()); | 2024 BytecodeGraphTester tester(isolate, zone, script.start()); |
2024 auto callable = tester.GetCallable<>(); | 2025 auto callable = tester.GetCallable<>(); |
2025 Handle<Object> return_value = callable().ToHandleChecked(); | 2026 Handle<Object> return_value = callable().ToHandleChecked(); |
2026 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2027 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2027 } | 2028 } |
2028 } | 2029 } |
2029 | 2030 |
2030 | 2031 |
| 2032 TEST(JumpWithConstantsAndWideConstants) { |
| 2033 HandleAndZoneScope scope; |
| 2034 auto isolate = scope.main_isolate(); |
| 2035 const int kStep = 19; |
| 2036 int start = isolate->random_number_generator()->NextInt(kStep); |
| 2037 for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) { |
| 2038 std::stringstream os; |
| 2039 // Generate a string that consumes constant pool entries and |
| 2040 // spread out branch distances in script below. |
| 2041 for (int i = 0; i < constants; i++) { |
| 2042 os << "var x_ = 'x_" << i << "';\n"; |
| 2043 } |
| 2044 std::string filler(os.str()); |
| 2045 os.str(""); |
| 2046 os << "function " << kFunctionName << "(a) {\n"; |
| 2047 os << " " << filler; |
| 2048 os << " for (var i = a; i < 2; i++) {\n"; |
| 2049 os << " " << filler; |
| 2050 os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; |
| 2051 os << " else if (i == a) { " << filler << "i = 12; break; }\n"; |
| 2052 os << " else { " << filler << " }\n"; |
| 2053 os << " }\n"; |
| 2054 os << " return i;\n"; |
| 2055 os << "}\n"; |
| 2056 os << kFunctionName << "(0);\n"; |
| 2057 std::string script(os.str()); |
| 2058 auto factory = isolate->factory(); |
| 2059 auto zone = scope.main_zone(); |
| 2060 for (int a = 0; a < 3; a++) { |
| 2061 BytecodeGraphTester tester(isolate, zone, script.c_str()); |
| 2062 auto callable = tester.GetCallable<Handle<Object>>(); |
| 2063 Handle<Object> return_val = |
| 2064 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); |
| 2065 static const int results[] = {11, 12, 2}; |
| 2066 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
| 2067 } |
| 2068 } |
| 2069 } |
| 2070 |
2031 } // namespace compiler | 2071 } // namespace compiler |
2032 } // namespace internal | 2072 } // namespace internal |
2033 } // namespace v8 | 2073 } // namespace v8 |
OLD | NEW |