| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
| (...skipping 8439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8450 } | 8450 } |
| 8451 | 8451 |
| 8452 | 8452 |
| 8453 RUNTIME_FUNCTION(Runtime_CompileOptimized) { | 8453 RUNTIME_FUNCTION(Runtime_CompileOptimized) { |
| 8454 HandleScope scope(isolate); | 8454 HandleScope scope(isolate); |
| 8455 DCHECK(args.length() == 2); | 8455 DCHECK(args.length() == 2); |
| 8456 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 8456 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| 8457 CONVERT_BOOLEAN_ARG_CHECKED(concurrent, 1); | 8457 CONVERT_BOOLEAN_ARG_CHECKED(concurrent, 1); |
| 8458 | 8458 |
| 8459 Handle<Code> unoptimized(function->shared()->code()); | 8459 Handle<Code> unoptimized(function->shared()->code()); |
| 8460 if (!function->shared()->is_compiled()) { | 8460 if (!isolate->use_crankshaft() || |
| 8461 // If the function is not compiled, do not optimize. | 8461 function->shared()->optimization_disabled() || |
| 8462 // This can happen if the debugger is activated and | 8462 isolate->DebuggerHasBreakPoints()) { |
| 8463 // the function is returned to the not compiled state. | |
| 8464 // TODO(yangguo): reconsider this. | |
| 8465 function->ReplaceCode(function->shared()->code()); | |
| 8466 } else if (!isolate->use_crankshaft() || | |
| 8467 function->shared()->optimization_disabled() || | |
| 8468 isolate->DebuggerHasBreakPoints()) { | |
| 8469 // If the function is not optimizable or debugger is active continue | 8463 // If the function is not optimizable or debugger is active continue |
| 8470 // using the code from the full compiler. | 8464 // using the code from the full compiler. |
| 8471 if (FLAG_trace_opt) { | 8465 if (FLAG_trace_opt) { |
| 8472 PrintF("[failed to optimize "); | 8466 PrintF("[failed to optimize "); |
| 8473 function->PrintName(); | 8467 function->PrintName(); |
| 8474 PrintF(": is code optimizable: %s, is debugger enabled: %s]\n", | 8468 PrintF(": is code optimizable: %s, is debugger enabled: %s]\n", |
| 8475 function->shared()->optimization_disabled() ? "F" : "T", | 8469 function->shared()->optimization_disabled() ? "F" : "T", |
| 8476 isolate->DebuggerHasBreakPoints() ? "T" : "F"); | 8470 isolate->DebuggerHasBreakPoints() ? "T" : "F"); |
| 8477 } | 8471 } |
| 8478 function->ReplaceCode(*unoptimized); | 8472 function->ReplaceCode(*unoptimized); |
| 8473 return function->code(); |
| 8474 } |
| 8475 |
| 8476 Compiler::ConcurrencyMode mode = |
| 8477 concurrent ? Compiler::CONCURRENT : Compiler::NOT_CONCURRENT; |
| 8478 Handle<Code> code; |
| 8479 if (Compiler::GetOptimizedCode(function, unoptimized, mode).ToHandle(&code)) { |
| 8480 function->ReplaceCode(*code); |
| 8479 } else { | 8481 } else { |
| 8480 Compiler::ConcurrencyMode mode = concurrent ? Compiler::CONCURRENT | 8482 function->ReplaceCode(*unoptimized); |
| 8481 : Compiler::NOT_CONCURRENT; | |
| 8482 Handle<Code> code; | |
| 8483 if (Compiler::GetOptimizedCode( | |
| 8484 function, unoptimized, mode).ToHandle(&code)) { | |
| 8485 function->ReplaceCode(*code); | |
| 8486 } else { | |
| 8487 function->ReplaceCode(*unoptimized); | |
| 8488 } | |
| 8489 } | 8483 } |
| 8490 | 8484 |
| 8491 DCHECK(function->code()->kind() == Code::FUNCTION || | 8485 DCHECK(function->code()->kind() == Code::FUNCTION || |
| 8492 function->code()->kind() == Code::OPTIMIZED_FUNCTION || | 8486 function->code()->kind() == Code::OPTIMIZED_FUNCTION || |
| 8493 function->IsInOptimizationQueue()); | 8487 function->IsInOptimizationQueue()); |
| 8494 return function->code(); | 8488 return function->code(); |
| 8495 } | 8489 } |
| 8496 | 8490 |
| 8497 | 8491 |
| 8498 class ActivationsFinder : public ThreadVisitor { | 8492 class ActivationsFinder : public ThreadVisitor { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8634 return isolate->heap()->ToBoolean( | 8628 return isolate->heap()->ToBoolean( |
| 8635 isolate->concurrent_recompilation_enabled()); | 8629 isolate->concurrent_recompilation_enabled()); |
| 8636 } | 8630 } |
| 8637 | 8631 |
| 8638 | 8632 |
| 8639 RUNTIME_FUNCTION(Runtime_OptimizeFunctionOnNextCall) { | 8633 RUNTIME_FUNCTION(Runtime_OptimizeFunctionOnNextCall) { |
| 8640 HandleScope scope(isolate); | 8634 HandleScope scope(isolate); |
| 8641 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2); | 8635 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2); |
| 8642 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 8636 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| 8643 | 8637 |
| 8644 if (!function->IsOptimizable() && | 8638 if (function->IsOptimized()) return isolate->heap()->undefined_value(); |
| 8645 !function->IsMarkedForConcurrentOptimization() && | |
| 8646 !function->IsInOptimizationQueue()) { | |
| 8647 return isolate->heap()->undefined_value(); | |
| 8648 } | |
| 8649 | 8639 |
| 8650 function->MarkForOptimization(); | 8640 function->MarkForOptimization(); |
| 8651 | 8641 |
| 8652 Code* unoptimized = function->shared()->code(); | 8642 Code* unoptimized = function->shared()->code(); |
| 8653 if (args.length() == 2 && | 8643 if (args.length() == 2 && |
| 8654 unoptimized->kind() == Code::FUNCTION) { | 8644 unoptimized->kind() == Code::FUNCTION) { |
| 8655 CONVERT_ARG_HANDLE_CHECKED(String, type, 1); | 8645 CONVERT_ARG_HANDLE_CHECKED(String, type, 1); |
| 8656 if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("osr")) && FLAG_use_osr) { | 8646 if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("osr")) && FLAG_use_osr) { |
| 8657 // Start patching from the currently patched loop nesting level. | 8647 // Start patching from the currently patched loop nesting level. |
| 8658 DCHECK(BackEdgeTable::Verify(isolate, unoptimized)); | 8648 DCHECK(BackEdgeTable::Verify(isolate, unoptimized)); |
| (...skipping 6998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15657 } | 15647 } |
| 15658 return NULL; | 15648 return NULL; |
| 15659 } | 15649 } |
| 15660 | 15650 |
| 15661 | 15651 |
| 15662 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15652 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 15663 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15653 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 15664 } | 15654 } |
| 15665 | 15655 |
| 15666 } } // namespace v8::internal | 15656 } } // namespace v8::internal |
| OLD | NEW |