Chromium Code Reviews| Index: src/compiler.cc |
| diff --git a/src/compiler.cc b/src/compiler.cc |
| index 7b0faf0b92d3155dbbb7e649d6c1566f65cc5738..45903983542d896dcb531711da7da0ab14371c69 100644 |
| --- a/src/compiler.cc |
| +++ b/src/compiler.cc |
| @@ -66,6 +66,19 @@ PARSE_INFO_GETTER(Handle<SharedFunctionInfo>, shared_info) |
| #undef PARSE_INFO_GETTER |
| #undef PARSE_INFO_GETTER_WITH_DEFAULT |
| +// A wrapper around a CompilationInfo that detaches the Handles from |
| +// the underlying DeferredHandleScope and stores them in info_ on |
| +// destruction. |
| +class CompilationHandleScope BASE_EMBEDDED { |
| + public: |
| + explicit CompilationHandleScope(CompilationInfo* info) |
| + : deferred_(info->isolate()), info_(info) {} |
| + ~CompilationHandleScope() { info_->set_deferred_handles(deferred_.Detach()); } |
| + |
| + private: |
| + DeferredHandleScope deferred_; |
| + CompilationInfo* info_; |
| +}; |
| // Exactly like a CompilationInfo, except being allocated via {new} and it also |
| // creates and enters a Zone on construction and deallocates it on destruction. |
| @@ -1002,8 +1015,7 @@ static bool GetOptimizedCodeLater(CompilationInfo* info) { |
| return true; |
| } |
| - |
| -MaybeHandle<Code> Compiler::GetUnoptimizedCode(Handle<JSFunction> function) { |
| +static MaybeHandle<Code> GetUnoptimizedCode(Handle<JSFunction> function) { |
|
Benedikt Meurer
2016/03/04 09:54:07
Nit: Place into anonymous instead of adding static
Michael Starzinger
2016/03/04 10:00:04
Done. I also covered two more functions since they
|
| DCHECK(!function->GetIsolate()->has_pending_exception()); |
| DCHECK(!function->is_compiled()); |
| if (function->shared()->is_compiled()) { |
| @@ -1018,8 +1030,7 @@ MaybeHandle<Code> Compiler::GetUnoptimizedCode(Handle<JSFunction> function) { |
| return result; |
| } |
| - |
| -MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) { |
| +static MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { |
| Isolate* isolate = function->GetIsolate(); |
| DCHECK(!isolate->has_pending_exception()); |
| DCHECK(!function->is_compiled()); |
| @@ -1070,7 +1081,7 @@ MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) { |
| bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { |
| if (function->is_compiled()) return true; |
| - MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function); |
| + MaybeHandle<Code> maybe_code = GetLazyCode(function); |
| Handle<Code> code; |
| if (!maybe_code.ToHandle(&code)) { |
| if (flag == CLEAR_EXCEPTION) { |
| @@ -1078,11 +1089,41 @@ bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { |
| } |
| return false; |
| } |
| + DCHECK(code->IsJavaScriptCode()); |
| function->ReplaceCode(*code); |
| DCHECK(function->is_compiled()); |
| return true; |
| } |
| +bool Compiler::CompileOptimized(Handle<JSFunction> function, |
| + ConcurrencyMode mode) { |
| + Handle<Code> code; |
| + if (Compiler::GetOptimizedCode(function, mode).ToHandle(&code)) { |
| + // Optimization succeeded, return optimized code. |
| + function->ReplaceCode(*code); |
| + } else { |
| + // Optimization failed, get unoptimized code. |
| + Isolate* isolate = function->GetIsolate(); |
| + if (isolate->has_pending_exception()) { // Possible stack overflow. |
| + return false; |
| + } |
| + code = Handle<Code>(function->shared()->code(), isolate); |
| + if (code->kind() != Code::FUNCTION && |
| + code->kind() != Code::OPTIMIZED_FUNCTION) { |
| + if (!GetUnoptimizedCode(function).ToHandle(&code)) { |
| + return false; |
| + } |
| + } |
| + function->ReplaceCode(*code); |
| + } |
| + |
| + DCHECK(function->code()->kind() == Code::FUNCTION || |
| + function->code()->kind() == Code::OPTIMIZED_FUNCTION || |
| + (function->code()->is_interpreter_entry_trampoline() && |
| + function->shared()->HasBytecodeArray()) || |
| + function->IsInOptimizationQueue()); |
| + return true; |
| +} |
| // TODO(turbofan): In the future, unoptimized code with deopt support could |
| // be generated lazily once deopt is triggered. |