| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 | 8 |
| 9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 515 } |
| 516 | 516 |
| 517 Timer t(this, &time_taken_to_create_graph_); | 517 Timer t(this, &time_taken_to_create_graph_); |
| 518 compiler::Pipeline pipeline(info()); | 518 compiler::Pipeline pipeline(info()); |
| 519 pipeline.GenerateCode(); | 519 pipeline.GenerateCode(); |
| 520 if (!info()->code().is_null()) { | 520 if (!info()->code().is_null()) { |
| 521 return SetLastStatus(SUCCEEDED); | 521 return SetLastStatus(SUCCEEDED); |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 | 524 |
| 525 // Do not use Crankshaft if the code is intended to be serialized. |
| 526 if (!isolate()->use_crankshaft()) return SetLastStatus(FAILED); |
| 527 |
| 525 if (FLAG_trace_opt) { | 528 if (FLAG_trace_opt) { |
| 526 OFStream os(stdout); | 529 OFStream os(stdout); |
| 527 os << "[compiling method " << Brief(*info()->closure()) | 530 os << "[compiling method " << Brief(*info()->closure()) |
| 528 << " using Crankshaft"; | 531 << " using Crankshaft"; |
| 529 if (info()->is_osr()) os << " OSR"; | 532 if (info()->is_osr()) os << " OSR"; |
| 530 os << "]" << std::endl; | 533 os << "]" << std::endl; |
| 531 } | 534 } |
| 532 | 535 |
| 533 if (FLAG_trace_hydrogen) { | 536 if (FLAG_trace_hydrogen) { |
| 534 isolate()->GetHTracer()->TraceCompilation(info()); | 537 isolate()->GetHTracer()->TraceCompilation(info()); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 // deopt from turbofan code. | 943 // deopt from turbofan code. |
| 941 if (FLAG_turbo_asm && function->shared()->asm_function() && | 944 if (FLAG_turbo_asm && function->shared()->asm_function() && |
| 942 (FLAG_turbo_deoptimization || !isolate->debug()->is_active()) && | 945 (FLAG_turbo_deoptimization || !isolate->debug()->is_active()) && |
| 943 !FLAG_turbo_osr) { | 946 !FLAG_turbo_osr) { |
| 944 CompilationInfoWithZone info(function); | 947 CompilationInfoWithZone info(function); |
| 945 | 948 |
| 946 VMState<COMPILER> state(isolate); | 949 VMState<COMPILER> state(isolate); |
| 947 PostponeInterruptsScope postpone(isolate); | 950 PostponeInterruptsScope postpone(isolate); |
| 948 | 951 |
| 949 info.SetOptimizing(BailoutId::None(), handle(function->shared()->code())); | 952 info.SetOptimizing(BailoutId::None(), handle(function->shared()->code())); |
| 950 info.MarkAsContextSpecializing(); | |
| 951 | 953 |
| 952 if (GetOptimizedCodeNow(&info)) { | 954 if (GetOptimizedCodeNow(&info)) { |
| 953 DCHECK(function->shared()->is_compiled()); | 955 DCHECK(function->shared()->is_compiled()); |
| 954 return info.code(); | 956 return info.code(); |
| 955 } | 957 } |
| 956 // We have failed compilation. If there was an exception clear it so that | 958 // We have failed compilation. If there was an exception clear it so that |
| 957 // we can compile unoptimized code. | 959 // we can compile unoptimized code. |
| 958 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); | 960 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); |
| 959 } | 961 } |
| 960 | 962 |
| 961 if (function->shared()->is_compiled()) { | 963 if (function->shared()->is_compiled()) { |
| 962 return Handle<Code>(function->shared()->code()); | 964 return Handle<Code>(function->shared()->code()); |
| 963 } | 965 } |
| 964 | 966 |
| 965 CompilationInfoWithZone info(function); | 967 CompilationInfoWithZone info(function); |
| 966 Handle<Code> result; | 968 Handle<Code> result; |
| 967 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCodeCommon(&info), | 969 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCodeCommon(&info), |
| 968 Code); | 970 Code); |
| 969 | 971 |
| 970 if (FLAG_always_opt && isolate->use_crankshaft()) { | 972 if (FLAG_always_opt) { |
| 971 Handle<Code> opt_code; | 973 Handle<Code> opt_code; |
| 972 if (Compiler::GetOptimizedCode( | 974 if (Compiler::GetOptimizedCode( |
| 973 function, result, | 975 function, result, |
| 974 Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) { | 976 Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) { |
| 975 result = opt_code; | 977 result = opt_code; |
| 976 } | 978 } |
| 977 } | 979 } |
| 978 | 980 |
| 979 return result; | 981 return result; |
| 980 } | 982 } |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 Handle<Code> cached_code; | 1480 Handle<Code> cached_code; |
| 1479 if (GetCodeFromOptimizedCodeMap( | 1481 if (GetCodeFromOptimizedCodeMap( |
| 1480 function, osr_ast_id).ToHandle(&cached_code)) { | 1482 function, osr_ast_id).ToHandle(&cached_code)) { |
| 1481 return cached_code; | 1483 return cached_code; |
| 1482 } | 1484 } |
| 1483 | 1485 |
| 1484 SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(function)); | 1486 SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(function)); |
| 1485 Isolate* isolate = info->isolate(); | 1487 Isolate* isolate = info->isolate(); |
| 1486 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1488 DCHECK(AllowCompilation::IsAllowed(isolate)); |
| 1487 VMState<COMPILER> state(isolate); | 1489 VMState<COMPILER> state(isolate); |
| 1488 DCHECK(isolate->use_crankshaft()); | |
| 1489 DCHECK(!isolate->has_pending_exception()); | 1490 DCHECK(!isolate->has_pending_exception()); |
| 1490 PostponeInterruptsScope postpone(isolate); | 1491 PostponeInterruptsScope postpone(isolate); |
| 1491 | 1492 |
| 1492 Handle<SharedFunctionInfo> shared = info->shared_info(); | 1493 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 1493 if (shared->code()->kind() != Code::FUNCTION || | 1494 if (shared->code()->kind() != Code::FUNCTION || |
| 1494 ScopeInfo::Empty(isolate) == shared->scope_info()) { | 1495 ScopeInfo::Empty(isolate) == shared->scope_info()) { |
| 1495 // The function was never compiled. Compile it unoptimized first. | 1496 // The function was never compiled. Compile it unoptimized first. |
| 1496 // TODO(titzer): reuse the AST and scope info from this compile. | 1497 // TODO(titzer): reuse the AST and scope info from this compile. |
| 1497 CompilationInfoWithZone nested(function); | 1498 CompilationInfoWithZone nested(function); |
| 1498 nested.EnableDeoptimizationSupport(); | 1499 nested.EnableDeoptimizationSupport(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 } | 1610 } |
| 1610 | 1611 |
| 1611 | 1612 |
| 1612 #if DEBUG | 1613 #if DEBUG |
| 1613 void CompilationInfo::PrintAstForTesting() { | 1614 void CompilationInfo::PrintAstForTesting() { |
| 1614 PrintF("--- Source from AST ---\n%s\n", | 1615 PrintF("--- Source from AST ---\n%s\n", |
| 1615 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1616 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
| 1616 } | 1617 } |
| 1617 #endif | 1618 #endif |
| 1618 } } // namespace v8::internal | 1619 } } // namespace v8::internal |
| OLD | NEW |