OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 Handle<Code> code(info()->shared_info()->code()); | 270 Handle<Code> code(info()->shared_info()->code()); |
271 ASSERT(code->kind() == Code::FUNCTION); | 271 ASSERT(code->kind() == Code::FUNCTION); |
272 | 272 |
273 // We should never arrive here if optimization has been disabled on the | 273 // We should never arrive here if optimization has been disabled on the |
274 // shared function info. | 274 // shared function info. |
275 ASSERT(!info()->shared_info()->optimization_disabled()); | 275 ASSERT(!info()->shared_info()->optimization_disabled()); |
276 | 276 |
277 // Fall back to using the full code generator if it's not possible | 277 // Fall back to using the full code generator if it's not possible |
278 // to use the Hydrogen-based optimizing compiler. We already have | 278 // to use the Hydrogen-based optimizing compiler. We already have |
279 // generated code for this from the shared function object. | 279 // generated code for this from the shared function object. |
280 if (AlwaysFullCompiler(info()->isolate())) { | 280 if (AlwaysFullCompiler(isolate())) { |
281 info()->SetCode(code); | 281 info()->SetCode(code); |
282 return SetLastStatus(BAILED_OUT); | 282 return SetLastStatus(BAILED_OUT); |
283 } | 283 } |
284 | 284 |
285 // Limit the number of times we re-compile a functions with | 285 // Limit the number of times we re-compile a functions with |
286 // the optimizing compiler. | 286 // the optimizing compiler. |
287 const int kMaxOptCount = | 287 const int kMaxOptCount = |
288 FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; | 288 FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; |
289 if (info()->opt_count() > kMaxOptCount) { | 289 if (info()->opt_count() > kMaxOptCount) { |
290 info()->set_bailout_reason("optimized too many times"); | 290 info()->set_bailout_reason("optimized too many times"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 return SetLastStatus(BAILED_OUT); | 323 return SetLastStatus(BAILED_OUT); |
324 } | 324 } |
325 } | 325 } |
326 | 326 |
327 // Recompile the unoptimized version of the code if the current version | 327 // Recompile the unoptimized version of the code if the current version |
328 // doesn't have deoptimization support. Alternatively, we may decide to | 328 // doesn't have deoptimization support. Alternatively, we may decide to |
329 // run the full code generator to get a baseline for the compile-time | 329 // run the full code generator to get a baseline for the compile-time |
330 // performance of the hydrogen-based compiler. | 330 // performance of the hydrogen-based compiler. |
331 bool should_recompile = !info()->shared_info()->has_deoptimization_support(); | 331 bool should_recompile = !info()->shared_info()->has_deoptimization_support(); |
332 if (should_recompile || FLAG_hydrogen_stats) { | 332 if (should_recompile || FLAG_hydrogen_stats) { |
333 HPhase phase(HPhase::kFullCodeGen); | 333 HPhase phase(HPhase::kFullCodeGen, isolate()); |
334 CompilationInfoWithZone unoptimized(info()->shared_info()); | 334 CompilationInfoWithZone unoptimized(info()->shared_info()); |
335 // Note that we use the same AST that we will use for generating the | 335 // Note that we use the same AST that we will use for generating the |
336 // optimized code. | 336 // optimized code. |
337 unoptimized.SetFunction(info()->function()); | 337 unoptimized.SetFunction(info()->function()); |
338 unoptimized.SetScope(info()->scope()); | 338 unoptimized.SetScope(info()->scope()); |
339 unoptimized.SetContext(info()->context()); | 339 unoptimized.SetContext(info()->context()); |
340 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); | 340 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
341 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); | 341 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); |
342 if (should_recompile) { | 342 if (should_recompile) { |
343 if (!succeeded) return SetLastStatus(FAILED); | 343 if (!succeeded) return SetLastStatus(FAILED); |
344 Handle<SharedFunctionInfo> shared = info()->shared_info(); | 344 Handle<SharedFunctionInfo> shared = info()->shared_info(); |
345 shared->EnableDeoptimizationSupport(*unoptimized.code()); | 345 shared->EnableDeoptimizationSupport(*unoptimized.code()); |
346 // The existing unoptimized code was replaced with the new one. | 346 // The existing unoptimized code was replaced with the new one. |
347 Compiler::RecordFunctionCompilation( | 347 Compiler::RecordFunctionCompilation( |
348 Logger::LAZY_COMPILE_TAG, &unoptimized, shared); | 348 Logger::LAZY_COMPILE_TAG, &unoptimized, shared); |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 // Check that the unoptimized, shared code is ready for | 352 // Check that the unoptimized, shared code is ready for |
353 // optimizations. When using the always_opt flag we disregard the | 353 // optimizations. When using the always_opt flag we disregard the |
354 // optimizable marker in the code object and optimize anyway. This | 354 // optimizable marker in the code object and optimize anyway. This |
355 // is safe as long as the unoptimized code has deoptimization | 355 // is safe as long as the unoptimized code has deoptimization |
356 // support. | 356 // support. |
357 ASSERT(FLAG_always_opt || code->optimizable()); | 357 ASSERT(FLAG_always_opt || code->optimizable()); |
358 ASSERT(info()->shared_info()->has_deoptimization_support()); | 358 ASSERT(info()->shared_info()->has_deoptimization_support()); |
359 | 359 |
360 if (FLAG_trace_hydrogen) { | 360 if (FLAG_trace_hydrogen) { |
361 PrintF("-----------------------------------------------------------\n"); | 361 PrintF("-----------------------------------------------------------\n"); |
362 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); | 362 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); |
363 HTracer::Instance()->TraceCompilation(info()); | 363 isolate()->GetHTracer()->TraceCompilation(info()); |
364 } | 364 } |
365 Handle<Context> native_context( | 365 Handle<Context> native_context( |
366 info()->closure()->context()->native_context()); | 366 info()->closure()->context()->native_context()); |
367 oracle_ = new(info()->zone()) TypeFeedbackOracle( | 367 oracle_ = new(info()->zone()) TypeFeedbackOracle( |
368 code, native_context, info()->isolate(), info()->zone()); | 368 code, native_context, isolate(), info()->zone()); |
369 graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info(), oracle_); | 369 graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info(), oracle_); |
370 | 370 |
371 Timer t(this, &time_taken_to_create_graph_); | 371 Timer t(this, &time_taken_to_create_graph_); |
372 graph_ = graph_builder_->CreateGraph(); | 372 graph_ = graph_builder_->CreateGraph(); |
373 | 373 |
374 if (info()->isolate()->has_pending_exception()) { | 374 if (isolate()->has_pending_exception()) { |
375 info()->SetCode(Handle<Code>::null()); | 375 info()->SetCode(Handle<Code>::null()); |
376 return SetLastStatus(FAILED); | 376 return SetLastStatus(FAILED); |
377 } | 377 } |
378 | 378 |
379 // The function being compiled may have bailed out due to an inline | 379 // The function being compiled may have bailed out due to an inline |
380 // candidate bailing out. In such a case, we don't disable | 380 // candidate bailing out. In such a case, we don't disable |
381 // optimization on the shared_info. | 381 // optimization on the shared_info. |
382 ASSERT(!graph_builder_->inline_bailout() || graph_ == NULL); | 382 ASSERT(!graph_builder_->inline_bailout() || graph_ == NULL); |
383 if (graph_ == NULL) { | 383 if (graph_ == NULL) { |
384 if (graph_builder_->inline_bailout()) { | 384 if (graph_builder_->inline_bailout()) { |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 } | 1120 } |
1121 } | 1121 } |
1122 | 1122 |
1123 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 1123 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
1124 Handle<Script>(info->script()), | 1124 Handle<Script>(info->script()), |
1125 Handle<Code>(info->code()), | 1125 Handle<Code>(info->code()), |
1126 info)); | 1126 info)); |
1127 } | 1127 } |
1128 | 1128 |
1129 } } // namespace v8::internal | 1129 } } // namespace v8::internal |
OLD | NEW |