}
-static Handle<Code> GetUnoptimizedCodeCommon(CompilationInfo* info) {
+MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon(
+ CompilationInfo* info) {
VMState<COMPILER> state(info->isolate());
PostponeInterruptsScope postpone(info->isolate());
- if (!Parser::Parse(info)) return Handle<Code>::null();
+ if (!Parser::Parse(info)) return MaybeHandle<Code>();
info->SetStrictMode(info->function()->strict_mode());
- if (!CompileUnoptimizedCode(info)) return Handle<Code>::null();
+ if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>();
Compiler::RecordFunctionCompilation(
Logger::LAZY_COMPILE_TAG, info, info->shared_info());
UpdateSharedFunctionInfo(info);
}
-Handle<Code> Compiler::GetUnoptimizedCode(Handle<JSFunction> function) {
+MaybeHandle<Code> Compiler::GetUnoptimizedCode(Handle<JSFunction> function) {
ASSERT(!function->GetIsolate()->has_pending_exception());
ASSERT(!function->is_compiled());
if (function->shared()->is_compiled()) {
}
CompilationInfoWithZone info(function);
- Handle<Code> result = GetUnoptimizedCodeCommon(&info);
- ASSERT_EQ(result.is_null(), info.isolate()->has_pending_exception());
+ Handle<Code> result;
+ ASSIGN_RETURN_ON_EXCEPTION(info.isolate(), result,
+ GetUnoptimizedCodeCommon(&info),
+ Code);
if (FLAG_always_opt &&
- !result.is_null() &&
info.isolate()->use_crankshaft() &&
!info.shared_info()->optimization_disabled() &&
!info.isolate()->DebuggerHasBreakPoints()) {
- Handle<Code> opt_code = Compiler::GetOptimizedCode(
- function, result, Compiler::NOT_CONCURRENT);
- if (!opt_code.is_null()) result = opt_code;
+ Handle<Code> opt_code;
+ if (Compiler::GetOptimizedCode(
+ function, result,
+ Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) {
+ result = opt_code;
+ }
}
return result;
}
-Handle<Code> Compiler::GetUnoptimizedCode(Handle<SharedFunctionInfo> shared) {
+MaybeHandle<Code> Compiler::GetUnoptimizedCode(
+ Handle<SharedFunctionInfo> shared) {
ASSERT(!shared->GetIsolate()->has_pending_exception());
ASSERT(!shared->is_compiled());
CompilationInfoWithZone info(shared);
- Handle<Code> result = GetUnoptimizedCodeCommon(&info);
- ASSERT_EQ(result.is_null(), info.isolate()->has_pending_exception());
- return result;
+ return GetUnoptimizedCodeCommon(&info);
}
bool Compiler::EnsureCompiled(Handle<JSFunction> function,
ClearExceptionFlag flag) {
if (function->is_compiled()) return true;
- Handle<Code> code = Compiler::GetUnoptimizedCode(function);
- if (code.is_null()) {
+ MaybeHandle<Code> maybe_code = Compiler::GetUnoptimizedCode(function);
+ Handle<Code> code;
+ if (!maybe_code.ToHandle(&code)) {
if (flag == CLEAR_EXCEPTION) {
function->GetIsolate()->clear_pending_exception();
}
// full code without debug break slots to full code with debug break slots
// depends on the generated code is otherwise exactly the same.
// If compilation fails, just keep the existing code.
-Handle<Code> Compiler::GetCodeForDebugging(Handle<JSFunction> function) {
+MaybeHandle<Code> Compiler::GetCodeForDebugging(Handle<JSFunction> function) {
CompilationInfoWithZone info(function);
Isolate* isolate = info.isolate();
VMState<COMPILER> state(isolate);
} else {
info.MarkNonOptimizable();
}
- Handle<Code> new_code = GetUnoptimizedCodeCommon(&info);
- if (new_code.is_null()) {
+ MaybeHandle<Code> maybe_new_code = GetUnoptimizedCodeCommon(&info);
+ Handle<Code> new_code;
+ if (!maybe_new_code.ToHandle(&new_code)) {
isolate->clear_pending_exception();
} else {
ASSERT_EQ(old_code->is_compiled_optimizable(),
new_code->is_compiled_optimizable());
}
- return new_code;
+ return maybe_new_code;
}
}
-static Handle<Code> GetCodeFromOptimizedCodeMap(Handle<JSFunction> function,
- BailoutId osr_ast_id) {
+MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap(
+ Handle<JSFunction> function,
+ BailoutId osr_ast_id) {
if (FLAG_cache_optimized_code) {
Handle<SharedFunctionInfo> shared(function->shared());
DisallowHeapAllocation no_gc;
return Handle<Code>(shared->GetCodeFromOptimizedCodeMap(index));
}
}
- return Handle<Code>::null();
+ return MaybeHandle<Code>();
}
}
-Handle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function,
- Handle<Code> current_code,
- ConcurrencyMode mode,
- BailoutId osr_ast_id) {
- Handle<Code> cached_code = GetCodeFromOptimizedCodeMap(function, osr_ast_id);
- if (!cached_code.is_null()) return cached_code;
+MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function,
+ Handle<Code> current_code,
+ ConcurrencyMode mode,
+ BailoutId osr_ast_id) {
+ Handle<Code> cached_code;
+ if (GetCodeFromOptimizedCodeMap(
+ function, osr_ast_id).ToHandle(&cached_code)) {
+ return cached_code;
+ }
SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(function));
Isolate* isolate = info->isolate();
}
if (isolate->has_pending_exception()) isolate->clear_pending_exception();
- return Handle<Code>::null();
+ return MaybeHandle<Code>();
}
class Compiler : public AllStatic {
public:
- static Handle<Code> GetUnoptimizedCode(Handle<JSFunction> function);
- static Handle<Code> GetUnoptimizedCode(Handle<SharedFunctionInfo> shared);
+ MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCode(
+ Handle<JSFunction> function);
+ MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCode(
+ Handle<SharedFunctionInfo> shared);
static bool EnsureCompiled(Handle<JSFunction> function,
ClearExceptionFlag flag);
- static Handle<Code> GetCodeForDebugging(Handle<JSFunction> function);
+ MUST_USE_RESULT static MaybeHandle<Code> GetCodeForDebugging(
+ Handle<JSFunction> function);
#ifdef ENABLE_DEBUGGER_SUPPORT
static void CompileForLiveEdit(Handle<Script> script);
// Generate and return optimized code or start a concurrent optimization job.
// In the latter case, return the InOptimizationQueue builtin. On failure,
// return the empty handle.
- static Handle<Code> GetOptimizedCode(
+ MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCode(
Handle<JSFunction> function,
Handle<Code> current_code,
ConcurrencyMode mode,
// Compile the target function.
ASSERT(function->shared()->allows_lazy_compilation());
- Handle<Code> code = Compiler::GetUnoptimizedCode(function);
- RETURN_IF_EMPTY_HANDLE(isolate, code);
+ Handle<Code> code;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, code,
+ Compiler::GetUnoptimizedCode(function));
function->ReplaceCode(*code);
// All done. Return the compiled code.
} else {
Compiler::ConcurrencyMode mode = concurrent ? Compiler::CONCURRENT
: Compiler::NOT_CONCURRENT;
- Handle<Code> code = Compiler::GetOptimizedCode(function, unoptimized, mode);
- function->ReplaceCode(code.is_null() ? *unoptimized : *code);
+ Handle<Code> code;
+ if (Compiler::GetOptimizedCode(
+ function, unoptimized, mode).ToHandle(&code)) {
+ function->ReplaceCode(*code);
+ } else {
+ function->ReplaceCode(*unoptimized);
+ }
}
ASSERT(function->code()->kind() == Code::FUNCTION ||
PrintF(" at AST id %d]\n", ast_id.ToInt());
}
result = Compiler::GetConcurrentlyOptimizedCode(job);
- } else if (result.is_null() &&
- IsSuitableForOnStackReplacement(isolate, function, caller_code)) {
+ } else if (IsSuitableForOnStackReplacement(isolate, function, caller_code)) {
if (FLAG_trace_osr) {
PrintF("[OSR - Compiling: ");
function->PrintName();
PrintF(" at AST id %d]\n", ast_id.ToInt());
}
- result = Compiler::GetOptimizedCode(function, caller_code, mode, ast_id);
- if (result.is_identical_to(isolate->builtins()->InOptimizationQueue())) {
+ MaybeHandle<Code> maybe_result = Compiler::GetOptimizedCode(
+ function, caller_code, mode, ast_id);
+ if (maybe_result.ToHandle(&result) &&
+ result.is_identical_to(isolate->builtins()->InOptimizationQueue())) {
// Optimization is queued. Return to check later.
return NULL;
}