Chromium Code Reviews| 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 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
| 6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "src/compiler/pipeline.h" | 10 #include "src/compiler/pipeline.h" |
| 11 #include "src/execution.h" | 11 #include "src/execution.h" |
| 12 #include "src/handles.h" | 12 #include "src/handles.h" |
| 13 #include "src/interpreter/bytecode-array-builder.h" | 13 #include "src/interpreter/bytecode-array-builder.h" |
| 14 #include "src/interpreter/interpreter.h" | 14 #include "src/interpreter/interpreter.h" |
| 15 #include "src/parser.h" | 15 #include "src/parser.h" |
| 16 #include "test/cctest/cctest.h" | 16 #include "test/cctest/cctest.h" |
| 17 | 17 |
| 18 | |
|
rmcilroy
2015/11/09 15:23:00
nit - remove extra newline
mythria
2015/11/10 09:55:35
Done.
| |
| 18 namespace v8 { | 19 namespace v8 { |
| 19 namespace internal { | 20 namespace internal { |
| 20 namespace compiler { | 21 namespace compiler { |
| 21 | 22 |
| 22 | 23 |
| 23 static const char kFunctionName[] = "f"; | 24 static const char kFunctionName[] = "f"; |
| 24 | 25 |
| 25 | 26 |
| 26 static MaybeHandle<Object> CallFunction(Isolate* isolate, | 27 static MaybeHandle<Object> CallFunction(Isolate* isolate, |
| 27 Handle<JSFunction> function) { | 28 Handle<JSFunction> function) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 // Ensure handler table is generated. | 75 // Ensure handler table is generated. |
| 75 isolate->interpreter()->Initialize(); | 76 isolate->interpreter()->Initialize(); |
| 76 } | 77 } |
| 77 virtual ~BytecodeGraphTester() {} | 78 virtual ~BytecodeGraphTester() {} |
| 78 | 79 |
| 79 template <class... A> | 80 template <class... A> |
| 80 BytecodeGraphCallable<A...> GetCallable() { | 81 BytecodeGraphCallable<A...> GetCallable() { |
| 81 return BytecodeGraphCallable<A...>(isolate_, GetFunction()); | 82 return BytecodeGraphCallable<A...>(isolate_, GetFunction()); |
| 82 } | 83 } |
| 83 | 84 |
| 85 static Handle<Object> NewObject(const char* script) { | |
| 86 return v8::Utils::OpenHandle(*CompileRun(script)); | |
| 87 } | |
| 88 | |
| 84 private: | 89 private: |
| 85 Isolate* isolate_; | 90 Isolate* isolate_; |
| 86 Zone* zone_; | 91 Zone* zone_; |
| 87 const char* script_; | 92 const char* script_; |
| 88 | 93 |
| 89 Handle<JSFunction> GetFunction() { | 94 Handle<JSFunction> GetFunction() { |
| 90 CompileRun(script_); | 95 CompileRun(script_); |
| 91 Local<Function> api_function = Local<Function>::Cast( | 96 Local<Function> api_function = Local<Function>::Cast( |
| 92 CcTest::global() | 97 CcTest::global() |
| 93 ->Get(CcTest::isolate()->GetCurrentContext(), v8_str(kFunctionName)) | 98 ->Get(CcTest::isolate()->GetCurrentContext(), v8_str(kFunctionName)) |
| 94 .ToLocalChecked()); | 99 .ToLocalChecked()); |
| 95 Handle<JSFunction> function = | 100 Handle<JSFunction> function = |
| 96 Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function)); | 101 Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function)); |
| 97 CHECK(function->shared()->HasBytecodeArray()); | 102 CHECK(function->shared()->HasBytecodeArray()); |
| 98 | 103 |
| 99 ParseInfo parse_info(zone_, function); | 104 ParseInfo parse_info(zone_, function); |
| 100 | 105 |
| 101 CompilationInfo compilation_info(&parse_info); | 106 CompilationInfo compilation_info(&parse_info); |
| 102 compilation_info.SetOptimizing(BailoutId::None(), Handle<Code>()); | 107 compilation_info.SetOptimizing(BailoutId::None(), Handle<Code>()); |
| 103 Parser parser(&parse_info); | 108 // TODO(mythria): Remove this step once parse_info is not needed. |
| 104 CHECK(parser.Parse(&parse_info)); | 109 CHECK(Compiler::ParseAndAnalyze(&parse_info)); |
| 105 compiler::Pipeline pipeline(&compilation_info); | 110 compiler::Pipeline pipeline(&compilation_info); |
| 106 Handle<Code> code = pipeline.GenerateCode(); | 111 Handle<Code> code = pipeline.GenerateCode(); |
| 107 function->ReplaceCode(*code); | 112 function->ReplaceCode(*code); |
| 108 | 113 |
| 109 return function; | 114 return function; |
| 110 } | 115 } |
| 111 | 116 |
| 112 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphTester); | 117 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphTester); |
| 113 }; | 118 }; |
| 114 | 119 |
| 115 | 120 |
| 121 #define SPACE() | |
| 122 | |
| 123 #define REPEAT_2(SEP, ...) __VA_ARGS__ SEP() __VA_ARGS__ | |
| 124 #define REPEAT_4(SEP, ...) \ | |
| 125 REPEAT_2(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) | |
| 126 #define REPEAT_8(SEP, ...) \ | |
| 127 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_4(SEP, __VA_ARGS__) | |
| 128 #define REPEAT_16(SEP, ...) \ | |
| 129 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) | |
| 130 #define REPEAT_32(SEP, ...) \ | |
| 131 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__) | |
| 132 #define REPEAT_64(SEP, ...) \ | |
| 133 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) | |
| 134 #define REPEAT_128(SEP, ...) \ | |
| 135 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__) | |
| 136 #define REPEAT_256(SEP, ...) \ | |
| 137 REPEAT_128(SEP, __VA_ARGS__) SEP() REPEAT_128(SEP, __VA_ARGS__) | |
| 138 | |
| 139 #define REPEAT_127(SEP, ...) \ | |
| 140 REPEAT_64(SEP, __VA_ARGS__) \ | |
| 141 SEP() \ | |
| 142 REPEAT_32(SEP, __VA_ARGS__) \ | |
| 143 SEP() \ | |
| 144 REPEAT_16(SEP, __VA_ARGS__) \ | |
| 145 SEP() \ | |
| 146 REPEAT_8(SEP, __VA_ARGS__) \ | |
| 147 SEP() \ | |
| 148 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() __VA_ARGS__ | |
|
rmcilroy
2015/11/09 15:23:00
These are all unused in this test now, right? If s
mythria
2015/11/10 09:55:35
I use them for testing LoadICS in wide mode in tes
rmcilroy
2015/11/10 11:23:19
You're right, missed this.
| |
| 149 | |
| 150 | |
| 116 template <int N> | 151 template <int N> |
| 117 struct ExpectedSnippet { | 152 struct ExpectedSnippet { |
| 118 const char* code_snippet; | 153 const char* code_snippet; |
| 119 Handle<Object> return_value_and_parameters[N + 1]; | 154 Handle<Object> return_value_and_parameters[N + 1]; |
| 120 | 155 |
| 121 inline Handle<Object> return_value() const { | 156 inline Handle<Object> return_value() const { |
| 122 return return_value_and_parameters[0]; | 157 return return_value_and_parameters[0]; |
| 123 } | 158 } |
| 124 | 159 |
| 125 inline Handle<Object> parameter(int i) const { | 160 inline Handle<Object> parameter(int i) const { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 | 282 |
| 248 BytecodeGraphTester tester(isolate, zone, script.start()); | 283 BytecodeGraphTester tester(isolate, zone, script.start()); |
| 249 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); | 284 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); |
| 250 Handle<Object> return_value = | 285 Handle<Object> return_value = |
| 251 callable(snippets[i].parameter(0), snippets[i].parameter(1)) | 286 callable(snippets[i].parameter(0), snippets[i].parameter(1)) |
| 252 .ToHandleChecked(); | 287 .ToHandleChecked(); |
| 253 CHECK(return_value->SameValue(*snippets[i].return_value())); | 288 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 254 } | 289 } |
| 255 } | 290 } |
| 256 | 291 |
| 292 | |
| 293 TEST(BytecodeGraphBuilderNamedLoad) { | |
| 294 HandleAndZoneScope scope; | |
| 295 Isolate* isolate = scope.main_isolate(); | |
| 296 Zone* zone = scope.main_zone(); | |
| 297 Factory* factory = isolate->factory(); | |
| 298 | |
| 299 ExpectedSnippet<1> snippets[] = { | |
| 300 {"return p1.val;", | |
| 301 {factory->NewNumberFromInt(10), | |
| 302 BytecodeGraphTester::NewObject("({ val : 10})")}}, | |
| 303 {"return p1[\"name\"];", | |
| 304 {factory->NewStringFromStaticChars("abc"), | |
| 305 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, | |
| 306 {"'use strict'; return p1.val;", | |
| 307 {factory->NewNumberFromInt(10), | |
| 308 BytecodeGraphTester::NewObject("({ val : 10 })")}}, | |
| 309 {"'use strict'; return p1[\"val\"];", | |
| 310 {factory->NewNumberFromInt(10), | |
| 311 BytecodeGraphTester::NewObject("({ val : 10, name : 'abc'})")}}, | |
| 312 {"var b;\n" REPEAT_127(SPACE, " b = p1.name; ") " return p1.name;\n", | |
| 313 {factory->NewStringFromStaticChars("abc"), | |
| 314 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, | |
| 315 {" 'use strict'; var b;\n" REPEAT_127( | |
| 316 SPACE, " b = p1.name; ") " return p1.name;\n", | |
| 317 {factory->NewStringFromStaticChars("abc"), | |
| 318 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, | |
| 319 }; | |
| 320 | |
| 321 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); | |
| 322 for (size_t i = 0; i < num_snippets; i++) { | |
| 323 ScopedVector<char> script(2048); | |
| 324 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, | |
| 325 snippets[i].code_snippet, kFunctionName); | |
| 326 | |
| 327 BytecodeGraphTester tester(isolate, zone, script.start()); | |
| 328 auto callable = tester.GetCallable<Handle<Object>>(); | |
| 329 Handle<Object> return_value = | |
| 330 callable(snippets[i].parameter(0)).ToHandleChecked(); | |
| 331 CHECK(return_value->SameValue(*snippets[i].return_value())); | |
| 332 } | |
| 333 } | |
| 334 | |
| 257 } // namespace compiler | 335 } // namespace compiler |
| 258 } // namespace internal | 336 } // namespace internal |
| 259 } // namespace v8 | 337 } // namespace v8 |
| OLD | NEW |