OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "src/v8.h" | 5 #include "src/v8.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/compiler/code-generator.h" | 8 #include "src/compiler/code-generator.h" |
9 #include "src/compiler/common-operator.h" | 9 #include "src/compiler/common-operator.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 public: | 107 public: |
108 explicit TrivialDeoptCodegenTester(HandleAndZoneScope* scope) | 108 explicit TrivialDeoptCodegenTester(HandleAndZoneScope* scope) |
109 : DeoptCodegenTester(scope, | 109 : DeoptCodegenTester(scope, |
110 "function foo() { deopt(); return 42; }; foo") {} | 110 "function foo() { deopt(); return 42; }; foo") {} |
111 | 111 |
112 void GenerateCode() { | 112 void GenerateCode() { |
113 GenerateCodeFromSchedule(BuildGraphAndSchedule(graph)); | 113 GenerateCodeFromSchedule(BuildGraphAndSchedule(graph)); |
114 } | 114 } |
115 | 115 |
116 Schedule* BuildGraphAndSchedule(Graph* graph) { | 116 Schedule* BuildGraphAndSchedule(Graph* graph) { |
117 Isolate* isolate = info.isolate(); | |
118 CommonOperatorBuilder common(zone()); | 117 CommonOperatorBuilder common(zone()); |
119 | 118 |
120 // Manually construct a schedule for the function below: | 119 // Manually construct a schedule for the function below: |
121 // function foo() { | 120 // function foo() { |
122 // deopt(); | 121 // deopt(); |
123 // } | 122 // } |
124 | 123 |
125 MachineType parameter_reps[] = {kMachAnyTagged}; | 124 MachineType parameter_reps[] = {kMachAnyTagged}; |
126 MachineCallDescriptorBuilder descriptor_builder(kMachAnyTagged, 1, | 125 MachineCallDescriptorBuilder descriptor_builder(kMachAnyTagged, 1, |
127 parameter_reps); | 126 parameter_reps); |
128 | 127 |
129 RawMachineAssembler m(graph, &descriptor_builder); | 128 RawMachineAssembler m(graph, &descriptor_builder); |
130 | 129 |
131 Handle<Object> undef_object = | |
132 Handle<Object>(isolate->heap()->undefined_value(), isolate); | |
133 PrintableUnique<Object> undef_constant = | |
134 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); | |
135 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); | |
136 | |
137 Handle<JSFunction> deopt_function = | 130 Handle<JSFunction> deopt_function = |
138 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); | 131 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); |
139 PrintableUnique<Object> deopt_fun_constant = | 132 PrintableUnique<Object> deopt_fun_constant = |
140 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); | 133 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); |
141 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); | 134 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); |
142 | 135 |
143 | 136 |
144 bailout_id = GetCallBailoutId(); | 137 bailout_id = GetCallBailoutId(); |
145 Node* parameters = m.NewNode(common.StateValues(1), undef_node); | 138 Node* parameters = m.NewNode(common.StateValues(1), m.UndefinedConstant()); |
146 Node* locals = m.NewNode(common.StateValues(0)); | 139 Node* locals = m.NewNode(common.StateValues(0)); |
147 Node* stack = m.NewNode(common.StateValues(0)); | 140 Node* stack = m.NewNode(common.StateValues(0)); |
148 | 141 |
149 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), | 142 Node* state_node = |
150 parameters, locals, stack, undef_node); | 143 m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), parameters, |
| 144 locals, stack, m.UndefinedConstant(), m.UndefinedConstant()); |
151 | 145 |
152 m.CallJS0(deopt_fun_node, undef_node, state_node); | 146 m.CallJS0(deopt_fun_node, m.UndefinedConstant(), state_node); |
153 | 147 |
154 m.Return(undef_node); | 148 m.Return(m.UndefinedConstant()); |
155 | 149 |
156 // Schedule the graph: | 150 // Schedule the graph: |
157 Schedule* schedule = m.Export(); | 151 Schedule* schedule = m.Export(); |
158 | 152 |
159 return schedule; | 153 return schedule; |
160 } | 154 } |
161 | 155 |
162 BailoutId GetCallBailoutId() { | 156 BailoutId GetCallBailoutId() { |
163 ZoneList<Statement*>* body = info.function()->body(); | 157 ZoneList<Statement*>* body = info.function()->body(); |
164 for (int i = 0; i < body->length(); i++) { | 158 for (int i = 0; i < body->length(); i++) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 explicit TrivialRuntimeDeoptCodegenTester(HandleAndZoneScope* scope) | 217 explicit TrivialRuntimeDeoptCodegenTester(HandleAndZoneScope* scope) |
224 : DeoptCodegenTester( | 218 : DeoptCodegenTester( |
225 scope, | 219 scope, |
226 "function foo() { %DeoptimizeFunction(foo); return 42; }; foo") {} | 220 "function foo() { %DeoptimizeFunction(foo); return 42; }; foo") {} |
227 | 221 |
228 void GenerateCode() { | 222 void GenerateCode() { |
229 GenerateCodeFromSchedule(BuildGraphAndSchedule(graph)); | 223 GenerateCodeFromSchedule(BuildGraphAndSchedule(graph)); |
230 } | 224 } |
231 | 225 |
232 Schedule* BuildGraphAndSchedule(Graph* graph) { | 226 Schedule* BuildGraphAndSchedule(Graph* graph) { |
233 Isolate* isolate = info.isolate(); | |
234 CommonOperatorBuilder common(zone()); | 227 CommonOperatorBuilder common(zone()); |
235 | 228 |
236 // Manually construct a schedule for the function below: | 229 // Manually construct a schedule for the function below: |
237 // function foo() { | 230 // function foo() { |
238 // %DeoptimizeFunction(foo); | 231 // %DeoptimizeFunction(foo); |
239 // } | 232 // } |
240 | 233 |
241 MachineType parameter_reps[] = {kMachAnyTagged}; | 234 MachineType parameter_reps[] = {kMachAnyTagged}; |
242 MachineCallDescriptorBuilder descriptor_builder(kMachAnyTagged, 2, | 235 MachineCallDescriptorBuilder descriptor_builder(kMachAnyTagged, 2, |
243 parameter_reps); | 236 parameter_reps); |
244 | 237 |
245 RawMachineAssembler m(graph, &descriptor_builder); | 238 RawMachineAssembler m(graph, &descriptor_builder); |
246 | 239 |
247 Handle<Object> undef_object = | |
248 Handle<Object>(isolate->heap()->undefined_value(), isolate); | |
249 PrintableUnique<Object> undef_constant = | |
250 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); | |
251 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); | |
252 | |
253 PrintableUnique<Object> this_fun_constant = | 240 PrintableUnique<Object> this_fun_constant = |
254 PrintableUnique<Object>::CreateUninitialized(zone(), function); | 241 PrintableUnique<Object>::CreateUninitialized(zone(), function); |
255 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); | 242 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); |
256 | 243 |
257 bailout_id = GetCallBailoutId(); | 244 bailout_id = GetCallBailoutId(); |
258 Node* parameters = m.NewNode(common.StateValues(1), undef_node); | 245 Node* parameters = m.NewNode(common.StateValues(1), m.UndefinedConstant()); |
259 Node* locals = m.NewNode(common.StateValues(0)); | 246 Node* locals = m.NewNode(common.StateValues(0)); |
260 Node* stack = m.NewNode(common.StateValues(0)); | 247 Node* stack = m.NewNode(common.StateValues(0)); |
261 | 248 |
262 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), | 249 Node* state_node = |
263 parameters, locals, stack, undef_node); | 250 m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), parameters, |
| 251 locals, stack, m.UndefinedConstant(), m.UndefinedConstant()); |
264 | 252 |
265 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, state_node); | 253 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, state_node); |
266 | 254 |
267 m.Return(undef_node); | 255 m.Return(m.UndefinedConstant()); |
268 | 256 |
269 // Schedule the graph: | 257 // Schedule the graph: |
270 Schedule* schedule = m.Export(); | 258 Schedule* schedule = m.Export(); |
271 | 259 |
272 return schedule; | 260 return schedule; |
273 } | 261 } |
274 | 262 |
275 BailoutId GetCallBailoutId() { | 263 BailoutId GetCallBailoutId() { |
276 ZoneList<Statement*>* body = info.function()->body(); | 264 ZoneList<Statement*>* body = info.function()->body(); |
277 for (int i = 0; i < body->length(); i++) { | 265 for (int i = 0; i < body->length(); i++) { |
(...skipping 25 matching lines...) Expand all Loading... |
303 Handle<Object> result; | 291 Handle<Object> result; |
304 bool has_pending_exception = | 292 bool has_pending_exception = |
305 !Execution::Call(isolate, t.function, | 293 !Execution::Call(isolate, t.function, |
306 isolate->factory()->undefined_value(), 0, NULL, | 294 isolate->factory()->undefined_value(), 0, NULL, |
307 false).ToHandle(&result); | 295 false).ToHandle(&result); |
308 CHECK(!has_pending_exception); | 296 CHECK(!has_pending_exception); |
309 CHECK(result->SameValue(Smi::FromInt(42))); | 297 CHECK(result->SameValue(Smi::FromInt(42))); |
310 } | 298 } |
311 | 299 |
312 #endif | 300 #endif |
OLD | NEW |