Commit b02dd5b3 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[sparkplug] Allow sparkplug compilation to gracefully OOM

This also makes OOMing on --always-sparkplug not crash

Bug: v8:11420
Change-Id: Ibaa5eb8a268a7d47ec30210f5cf5af51e514f039
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2786846
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73679}
parent d51e27b6
......@@ -287,7 +287,7 @@ void BaselineCompiler::GenerateCode() {
}
}
Handle<Code> BaselineCompiler::Build(Isolate* isolate) {
MaybeHandle<Code> BaselineCompiler::Build(Isolate* isolate) {
CodeDesc desc;
__ GetCode(isolate, &desc);
// Allocate the bytecode offset table.
......@@ -295,7 +295,7 @@ Handle<Code> BaselineCompiler::Build(Isolate* isolate) {
bytecode_offset_table_builder_.ToBytecodeOffsetTable(isolate);
return Factory::CodeBuilder(isolate, desc, CodeKind::BASELINE)
.set_bytecode_offset_table(bytecode_offset_table)
.Build();
.TryBuild();
}
interpreter::Register BaselineCompiler::RegisterOperand(int operand_index) {
......
......@@ -54,7 +54,7 @@ class BaselineCompiler {
Handle<BytecodeArray> bytecode);
void GenerateCode();
Handle<Code> Build(Isolate* isolate);
MaybeHandle<Code> Build(Isolate* isolate);
private:
void Prologue();
......
......@@ -19,17 +19,17 @@
namespace v8 {
namespace internal {
Handle<Code> GenerateBaselineCode(Isolate* isolate,
Handle<SharedFunctionInfo> shared) {
MaybeHandle<Code> GenerateBaselineCode(Isolate* isolate,
Handle<SharedFunctionInfo> shared) {
RuntimeCallTimerScope runtimeTimer(isolate,
RuntimeCallCounterId::kCompileBaseline);
baseline::BaselineCompiler compiler(
isolate, shared, handle(shared->GetBytecodeArray(isolate), isolate));
compiler.GenerateCode();
Handle<Code> code = compiler.Build(isolate);
if (FLAG_print_code) {
code->Print();
MaybeHandle<Code> code = compiler.Build(isolate);
if (FLAG_print_code && !code.is_null()) {
code.ToHandleChecked()->Print();
}
return code;
}
......
......@@ -14,8 +14,8 @@ class Code;
class SharedFunctionInfo;
class MacroAssembler;
Handle<Code> GenerateBaselineCode(Isolate* isolate,
Handle<SharedFunctionInfo> shared);
MaybeHandle<Code> GenerateBaselineCode(Isolate* isolate,
Handle<SharedFunctionInfo> shared);
void EmitReturnBaseline(MacroAssembler* masm);
......
......@@ -687,7 +687,11 @@ bool CompileSharedWithBaseline(Isolate* isolate,
base::TimeDelta time_taken;
{
ScopedTimer timer(&time_taken);
code = GenerateBaselineCode(isolate, shared);
if (!GenerateBaselineCode(isolate, shared).ToHandle(&code)) {
// TODO(leszeks): This can only fail because of an OOM. Do we want to
// report these somehow, or silently ignore them?
return false;
}
Handle<HeapObject> function_data =
handle(HeapObject::cast(shared->function_data(kAcquireLoad)), isolate);
......@@ -1402,21 +1406,17 @@ void FinalizeUnoptimizedScriptCompilation(
}
}
bool CompileAllWithBaseline(Isolate* isolate,
void CompileAllWithBaseline(Isolate* isolate,
const FinalizeUnoptimizedCompilationDataList&
finalize_unoptimized_compilation_data_list,
Compiler::ClearExceptionFlag flag) {
finalize_unoptimized_compilation_data_list) {
for (const auto& finalize_data : finalize_unoptimized_compilation_data_list) {
Handle<SharedFunctionInfo> shared_info = finalize_data.function_handle();
IsCompiledScope is_compiled_scope(*shared_info, isolate);
if (!is_compiled_scope.is_compiled()) continue;
if (!CanCompileWithBaseline(isolate, shared_info)) continue;
if (!CompileSharedWithBaseline(isolate, shared_info, flag,
&is_compiled_scope)) {
return false;
}
CompileSharedWithBaseline(isolate, shared_info, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope);
}
return true;
}
// Create shared function info for top level and shared function infos array for
......@@ -1488,13 +1488,8 @@ MaybeHandle<SharedFunctionInfo> CompileToplevel(
isolate, script, parse_info->flags(), parse_info->state(),
finalize_unoptimized_compilation_data_list);
if (FLAG_always_sparkplug &&
!CompileAllWithBaseline(isolate,
finalize_unoptimized_compilation_data_list,
Compiler::ClearExceptionFlag::KEEP_EXCEPTION)) {
FailWithPendingException(isolate, script, parse_info,
Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
return MaybeHandle<SharedFunctionInfo>();
if (FLAG_always_sparkplug) {
CompileAllWithBaseline(isolate, finalize_unoptimized_compilation_data_list);
}
return shared_info;
......@@ -1954,10 +1949,8 @@ bool Compiler::Compile(Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
FinalizeUnoptimizedCompilation(isolate, script, flags, &compile_state,
finalize_unoptimized_compilation_data_list);
if (FLAG_always_sparkplug &&
!CompileAllWithBaseline(
isolate, finalize_unoptimized_compilation_data_list, flag)) {
return FailWithPendingException(isolate, script, &parse_info, flag);
if (FLAG_always_sparkplug) {
CompileAllWithBaseline(isolate, finalize_unoptimized_compilation_data_list);
}
DCHECK(!isolate->has_pending_exception());
......
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