Use MaybeHandles in Compiler to indicate failure instead of a null Handle.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/246603003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20890 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b4fa81db
......@@ -529,7 +529,7 @@ BUILTIN(ArrayPop) {
}
Handle<Object> element;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element, maybe_element);
RETURN_IF_EMPTY_HANDLE(
RETURN_FAILURE_ON_EXCEPTION(
isolate,
accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate)));
return *element;
......
......@@ -637,13 +637,14 @@ static bool CompileUnoptimizedCode(CompilationInfo* info) {
}
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);
......@@ -652,7 +653,7 @@ static Handle<Code> GetUnoptimizedCodeCommon(CompilationInfo* 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()) {
......@@ -660,39 +661,43 @@ Handle<Code> Compiler::GetUnoptimizedCode(Handle<JSFunction> function) {
}
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();
}
......@@ -713,7 +718,7 @@ bool Compiler::EnsureCompiled(Handle<JSFunction> function,
// 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);
......@@ -729,14 +734,15 @@ Handle<Code> Compiler::GetCodeForDebugging(Handle<JSFunction> function) {
} 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;
}
......@@ -1048,8 +1054,9 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
}
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;
......@@ -1069,7 +1076,7 @@ static Handle<Code> GetCodeFromOptimizedCodeMap(Handle<JSFunction> function,
return Handle<Code>(shared->GetCodeFromOptimizedCodeMap(index));
}
}
return Handle<Code>::null();
return MaybeHandle<Code>();
}
......@@ -1156,12 +1163,15 @@ static bool GetOptimizedCodeLater(CompilationInfo* info) {
}
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();
......@@ -1194,7 +1204,7 @@ Handle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function,
}
if (isolate->has_pending_exception()) isolate->clear_pending_exception();
return Handle<Code>::null();
return MaybeHandle<Code>();
}
......
......@@ -615,11 +615,14 @@ class OptimizedCompileJob: public ZoneObject {
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);
......@@ -655,7 +658,7 @@ class Compiler : public AllStatic {
// 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,
......
......@@ -2106,7 +2106,8 @@ void Debug::PrepareForBreakPoints() {
bool prev_force_debugger_active =
isolate_->debugger()->force_debugger_active();
isolate_->debugger()->set_force_debugger_active(true);
Handle<Code> code = Compiler::GetCodeForDebugging(function);
Handle<Code> code = Compiler::GetCodeForDebugging(
function).ToHandleChecked();
function->ReplaceCode(*code);
isolate_->debugger()->set_force_debugger_active(
prev_force_debugger_active);
......@@ -2222,10 +2223,10 @@ Object* Debug::FindSharedFunctionInfoInScript(Handle<Script> script,
// will compile all inner functions that cannot be compiled without a
// context, because Compiler::BuildFunctionInfo checks whether the
// debugger is active.
Handle<Code> result = target_function.is_null()
MaybeHandle<Code> maybe_result = target_function.is_null()
? Compiler::GetUnoptimizedCode(target)
: Compiler::GetUnoptimizedCode(target_function);
if (result.is_null()) return isolate_->heap()->undefined_value();
if (maybe_result.is_null()) return isolate_->heap()->undefined_value();
}
} // End while loop.
......
......@@ -125,20 +125,6 @@ typedef ZoneList<Handle<Object> > ZoneObjectList;
} \
} while (false)
// TODO(yangguo): Remove after we completely changed to MaybeHandles.
#define RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, value) \
do { \
if ((call).is_null()) { \
ASSERT((isolate)->has_pending_exception()); \
return (value); \
} \
} while (false)
// TODO(yangguo): Remove after we completely changed to MaybeHandles.
#define RETURN_IF_EMPTY_HANDLE(isolate, call) \
RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, isolate->heap()->exception())
// Macros for MaybeHandle.
#define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \
......
......@@ -8428,8 +8428,9 @@ RUNTIME_FUNCTION(RuntimeHidden_CompileUnoptimized) {
// 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.
......@@ -8470,8 +8471,13 @@ RUNTIME_FUNCTION(RuntimeHidden_CompileOptimized) {
} 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 ||
......@@ -8792,15 +8798,16 @@ RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) {
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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment