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