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