| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 public: | 116 public: |
| 117 explicit TrivialDeoptCodegenTester(HandleAndZoneScope* scope) | 117 explicit TrivialDeoptCodegenTester(HandleAndZoneScope* scope) |
| 118 : DeoptCodegenTester(scope, | 118 : DeoptCodegenTester(scope, |
| 119 "function foo() { deopt(); return 42; }; foo") {} | 119 "function foo() { deopt(); return 42; }; foo") {} |
| 120 | 120 |
| 121 void GenerateCode() { | 121 void GenerateCode() { |
| 122 GenerateCodeFromSchedule(BuildGraphAndSchedule(graph)); | 122 GenerateCodeFromSchedule(BuildGraphAndSchedule(graph)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 Schedule* BuildGraphAndSchedule(Graph* graph) { | 125 Schedule* BuildGraphAndSchedule(Graph* graph) { |
| 126 Isolate* isolate = info.isolate(); | |
| 127 CommonOperatorBuilder common(zone()); | 126 CommonOperatorBuilder common(zone()); |
| 128 | 127 |
| 129 // Manually construct a schedule for the function below: | 128 // Manually construct a schedule for the function below: |
| 130 // function foo() { | 129 // function foo() { |
| 131 // deopt(); | 130 // deopt(); |
| 132 // } | 131 // } |
| 133 | 132 |
| 134 CSignature1<Object*, Object*> sig; | 133 CSignature1<Object*, Object*> sig; |
| 135 RawMachineAssembler m(graph, &sig); | 134 RawMachineAssembler m(graph, &sig); |
| 136 | 135 |
| 137 Handle<Object> undef_object = | |
| 138 Handle<Object>(isolate->heap()->undefined_value(), isolate); | |
| 139 PrintableUnique<Object> undef_constant = | |
| 140 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); | |
| 141 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); | |
| 142 | |
| 143 Handle<JSFunction> deopt_function = | 136 Handle<JSFunction> deopt_function = |
| 144 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); | 137 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); |
| 145 PrintableUnique<Object> deopt_fun_constant = | 138 PrintableUnique<Object> deopt_fun_constant = |
| 146 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); | 139 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); |
| 147 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); | 140 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); |
| 148 | 141 |
| 149 Handle<Context> context(deopt_function->context(), isolate); | 142 Handle<Context> context(deopt_function->context(), CcTest::i_isolate()); |
| 150 PrintableUnique<Object> context_constant = | 143 PrintableUnique<Object> context_constant = |
| 151 PrintableUnique<Object>::CreateUninitialized(zone(), context); | 144 PrintableUnique<Object>::CreateUninitialized(zone(), context); |
| 152 Node* context_node = m.NewNode(common.HeapConstant(context_constant)); | 145 Node* context_node = m.NewNode(common.HeapConstant(context_constant)); |
| 153 | 146 |
| 154 bailout_id = GetCallBailoutId(); | 147 bailout_id = GetCallBailoutId(); |
| 155 Node* parameters = m.NewNode(common.StateValues(1), undef_node); | 148 Node* parameters = m.NewNode(common.StateValues(1), m.UndefinedConstant()); |
| 156 Node* locals = m.NewNode(common.StateValues(0)); | 149 Node* locals = m.NewNode(common.StateValues(0)); |
| 157 Node* stack = m.NewNode(common.StateValues(0)); | 150 Node* stack = m.NewNode(common.StateValues(0)); |
| 158 | 151 |
| 159 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), | 152 Node* state_node = |
| 160 parameters, locals, stack, undef_node); | 153 m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), parameters, |
| 154 locals, stack, m.UndefinedConstant(), m.UndefinedConstant()); |
| 161 | 155 |
| 162 m.CallJS0(deopt_fun_node, undef_node, context_node, state_node); | 156 m.CallJS0(deopt_fun_node, m.UndefinedConstant(), context_node, state_node); |
| 163 | 157 |
| 164 m.Return(undef_node); | 158 m.Return(m.UndefinedConstant()); |
| 165 | 159 |
| 166 // Schedule the graph: | 160 // Schedule the graph: |
| 167 Schedule* schedule = m.Export(); | 161 Schedule* schedule = m.Export(); |
| 168 | 162 |
| 169 return schedule; | 163 return schedule; |
| 170 } | 164 } |
| 171 | 165 |
| 172 BailoutId GetCallBailoutId() { | 166 BailoutId GetCallBailoutId() { |
| 173 ZoneList<Statement*>* body = info.function()->body(); | 167 ZoneList<Statement*>* body = info.function()->body(); |
| 174 for (int i = 0; i < body->length(); i++) { | 168 for (int i = 0; i < body->length(); i++) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 explicit TrivialRuntimeDeoptCodegenTester(HandleAndZoneScope* scope) | 227 explicit TrivialRuntimeDeoptCodegenTester(HandleAndZoneScope* scope) |
| 234 : DeoptCodegenTester( | 228 : DeoptCodegenTester( |
| 235 scope, | 229 scope, |
| 236 "function foo() { %DeoptimizeFunction(foo); return 42; }; foo") {} | 230 "function foo() { %DeoptimizeFunction(foo); return 42; }; foo") {} |
| 237 | 231 |
| 238 void GenerateCode() { | 232 void GenerateCode() { |
| 239 GenerateCodeFromSchedule(BuildGraphAndSchedule(graph)); | 233 GenerateCodeFromSchedule(BuildGraphAndSchedule(graph)); |
| 240 } | 234 } |
| 241 | 235 |
| 242 Schedule* BuildGraphAndSchedule(Graph* graph) { | 236 Schedule* BuildGraphAndSchedule(Graph* graph) { |
| 243 Isolate* isolate = info.isolate(); | |
| 244 CommonOperatorBuilder common(zone()); | 237 CommonOperatorBuilder common(zone()); |
| 245 | 238 |
| 246 // Manually construct a schedule for the function below: | 239 // Manually construct a schedule for the function below: |
| 247 // function foo() { | 240 // function foo() { |
| 248 // %DeoptimizeFunction(foo); | 241 // %DeoptimizeFunction(foo); |
| 249 // } | 242 // } |
| 250 | 243 |
| 251 CSignature1<Object*, Object*> sig; | 244 CSignature1<Object*, Object*> sig; |
| 252 RawMachineAssembler m(graph, &sig); | 245 RawMachineAssembler m(graph, &sig); |
| 253 | 246 |
| 254 Handle<Object> undef_object = | |
| 255 Handle<Object>(isolate->heap()->undefined_value(), isolate); | |
| 256 PrintableUnique<Object> undef_constant = | |
| 257 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); | |
| 258 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); | |
| 259 | |
| 260 PrintableUnique<Object> this_fun_constant = | 247 PrintableUnique<Object> this_fun_constant = |
| 261 PrintableUnique<Object>::CreateUninitialized(zone(), function); | 248 PrintableUnique<Object>::CreateUninitialized(zone(), function); |
| 262 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); | 249 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); |
| 263 | 250 |
| 264 Handle<Context> context(function->context(), isolate); | 251 Handle<Context> context(function->context(), CcTest::i_isolate()); |
| 265 PrintableUnique<Object> context_constant = | 252 PrintableUnique<Object> context_constant = |
| 266 PrintableUnique<Object>::CreateUninitialized(zone(), context); | 253 PrintableUnique<Object>::CreateUninitialized(zone(), context); |
| 267 Node* context_node = m.NewNode(common.HeapConstant(context_constant)); | 254 Node* context_node = m.NewNode(common.HeapConstant(context_constant)); |
| 268 | 255 |
| 269 bailout_id = GetCallBailoutId(); | 256 bailout_id = GetCallBailoutId(); |
| 270 Node* parameters = m.NewNode(common.StateValues(1), undef_node); | 257 Node* parameters = m.NewNode(common.StateValues(1), m.UndefinedConstant()); |
| 271 Node* locals = m.NewNode(common.StateValues(0)); | 258 Node* locals = m.NewNode(common.StateValues(0)); |
| 272 Node* stack = m.NewNode(common.StateValues(0)); | 259 Node* stack = m.NewNode(common.StateValues(0)); |
| 273 | 260 |
| 274 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), | 261 Node* state_node = |
| 275 parameters, locals, stack, undef_node); | 262 m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), parameters, |
| 263 locals, stack, m.UndefinedConstant(), m.UndefinedConstant()); |
| 276 | 264 |
| 277 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, context_node, | 265 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, context_node, |
| 278 state_node); | 266 state_node); |
| 279 | 267 |
| 280 m.Return(undef_node); | 268 m.Return(m.UndefinedConstant()); |
| 281 | 269 |
| 282 // Schedule the graph: | 270 // Schedule the graph: |
| 283 Schedule* schedule = m.Export(); | 271 Schedule* schedule = m.Export(); |
| 284 | 272 |
| 285 return schedule; | 273 return schedule; |
| 286 } | 274 } |
| 287 | 275 |
| 288 BailoutId GetCallBailoutId() { | 276 BailoutId GetCallBailoutId() { |
| 289 ZoneList<Statement*>* body = info.function()->body(); | 277 ZoneList<Statement*>* body = info.function()->body(); |
| 290 for (int i = 0; i < body->length(); i++) { | 278 for (int i = 0; i < body->length(); i++) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 316 Handle<Object> result; | 304 Handle<Object> result; |
| 317 bool has_pending_exception = | 305 bool has_pending_exception = |
| 318 !Execution::Call(isolate, t.function, | 306 !Execution::Call(isolate, t.function, |
| 319 isolate->factory()->undefined_value(), 0, NULL, | 307 isolate->factory()->undefined_value(), 0, NULL, |
| 320 false).ToHandle(&result); | 308 false).ToHandle(&result); |
| 321 CHECK(!has_pending_exception); | 309 CHECK(!has_pending_exception); |
| 322 CHECK(result->SameValue(Smi::FromInt(42))); | 310 CHECK(result->SameValue(Smi::FromInt(42))); |
| 323 } | 311 } |
| 324 | 312 |
| 325 #endif | 313 #endif |
| OLD | NEW |