Commit 0db5e7b8 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[TurboFan] Return MaybeHandle from TurboFan compiler

TurboFan returned null handles if compilation did not succeed. This CL
changes that to a MaybeHandle to make it explicit that client code needs
to handle the error.

Bug: v8:7856
Change-Id: I6087e6263faa1150b9788213dd22c398b4a2fc2d
Reviewed-on: https://chromium-review.googlesource.com/1104688
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53824}
parent 6394fd35
......@@ -178,19 +178,22 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) {
bool should_optimize_jumps =
rasm->isolate()->serializer_enabled() && FLAG_turbo_rewrite_far_jumps;
Handle<Code> code = Pipeline::GenerateCodeForCodeStub(
rasm->isolate(), rasm->call_descriptor(), rasm->graph(), schedule,
state->kind_, state->name_, state->stub_key_, state->builtin_index_,
should_optimize_jumps ? &jump_opt : nullptr, rasm->poisoning_level());
Handle<Code> code =
Pipeline::GenerateCodeForCodeStub(
rasm->isolate(), rasm->call_descriptor(), rasm->graph(), schedule,
state->kind_, state->name_, state->stub_key_, state->builtin_index_,
should_optimize_jumps ? &jump_opt : nullptr, rasm->poisoning_level())
.ToHandleChecked();
if (jump_opt.is_optimizable()) {
jump_opt.set_optimizing();
// Regenerate machine code
code = Pipeline::GenerateCodeForCodeStub(
rasm->isolate(), rasm->call_descriptor(), rasm->graph(), schedule,
state->kind_, state->name_, state->stub_key_, state->builtin_index_,
&jump_opt, rasm->poisoning_level());
rasm->isolate(), rasm->call_descriptor(), rasm->graph(),
schedule, state->kind_, state->name_, state->stub_key_,
state->builtin_index_, &jump_opt, rasm->poisoning_level())
.ToHandleChecked();
}
state->code_generated_ = true;
......
......@@ -356,10 +356,10 @@ Handle<ByteArray> CodeGenerator::GetSourcePositionTable() {
return source_position_table_builder_.ToSourcePositionTable(isolate());
}
Handle<Code> CodeGenerator::FinalizeCode() {
MaybeHandle<Code> CodeGenerator::FinalizeCode() {
if (result_ != kSuccess) {
tasm()->AbortedCodeGeneration();
return Handle<Code>();
return MaybeHandle<Code>();
}
// Allocate the source position table.
......@@ -381,10 +381,11 @@ Handle<Code> CodeGenerator::FinalizeCode() {
source_positions, deopt_data, kMovable, info()->stub_key(), true,
frame()->GetTotalFrameSlotCount(), safepoints()->GetCodeOffset(),
handler_table_offset_);
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
tasm()->AbortedCodeGeneration();
return Handle<Code>();
return MaybeHandle<Code>();
}
isolate()->counters()->total_compiled_code_size()->Increment(
code->raw_instruction_size());
......
......@@ -88,9 +88,9 @@ class CodeGenerator final : public GapResolver::Assembler {
// Generate native code. After calling AssembleCode, call FinalizeCode to
// produce the actual code object. If an error occurs during either phase,
// FinalizeCode returns a null handle.
// FinalizeCode returns an empty MaybeHandle.
void AssembleCode(); // Does not need to run on main thread.
Handle<Code> FinalizeCode();
MaybeHandle<Code> FinalizeCode();
Handle<ByteArray> GetSourcePositionTable();
......
......@@ -222,8 +222,8 @@ class PipelineData {
bool verify_graph() const { return verify_graph_; }
void set_verify_graph(bool value) { verify_graph_ = value; }
Handle<Code> code() { return code_; }
void set_code(Handle<Code> code) {
MaybeHandle<Code> code() { return code_; }
void set_code(MaybeHandle<Code> code) {
DCHECK(code_.is_null());
code_ = code;
}
......@@ -404,7 +404,7 @@ class PipelineData {
bool verify_graph_ = false;
int start_source_position_ = kNoSourcePosition;
base::Optional<OsrHelper> osr_helper_;
Handle<Code> code_ = Handle<Code>::null();
MaybeHandle<Code> code_;
CodeGenerator* code_generator_ = nullptr;
// All objects in the following group of fields are allocated in graph_zone_.
......@@ -485,11 +485,11 @@ class PipelineImpl final {
void AssembleCode(Linkage* linkage);
// Step D. Run the code finalization pass.
Handle<Code> FinalizeCode();
MaybeHandle<Code> FinalizeCode();
void VerifyGeneratedCodeIsIdempotent();
void RunPrintAndVerify(const char* phase, bool untyped = false);
Handle<Code> GenerateCode(CallDescriptor* call_descriptor);
MaybeHandle<Code> GenerateCode(CallDescriptor* call_descriptor);
void AllocateRegisters(const RegisterConfiguration* config,
CallDescriptor* call_descriptor, bool run_verifier);
......@@ -910,8 +910,9 @@ PipelineCompilationJob::Status PipelineCompilationJob::ExecuteJobImpl() {
PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl(
Isolate* isolate) {
Handle<Code> code = pipeline_.FinalizeCode();
if (code.is_null()) {
MaybeHandle<Code> maybe_code = pipeline_.FinalizeCode();
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
if (compilation_info()->bailout_reason() == BailoutReason::kNoReason) {
return AbortOptimization(BailoutReason::kCodeGenerationFailed);
}
......@@ -2081,7 +2082,7 @@ bool PipelineImpl::OptimizeGraph(Linkage* linkage) {
return SelectInstructions(linkage);
}
Handle<Code> Pipeline::GenerateCodeForCodeStub(
MaybeHandle<Code> Pipeline::GenerateCodeForCodeStub(
Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
Schedule* schedule, Code::Kind kind, const char* debug_name,
uint32_t stub_key, int32_t builtin_index, JumpOptimizationInfo* jump_opt,
......@@ -2134,8 +2135,8 @@ Handle<Code> Pipeline::GenerateCodeForCodeStub(
}
// static
Handle<Code> Pipeline::GenerateCodeForTesting(OptimizedCompilationInfo* info,
Isolate* isolate) {
MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate) {
ZoneStats zone_stats(isolate->allocator());
std::unique_ptr<PipelineStatistics> pipeline_statistics(
CreatePipelineStatistics(Handle<Script>::null(), info, isolate,
......@@ -2146,23 +2147,23 @@ Handle<Code> Pipeline::GenerateCodeForTesting(OptimizedCompilationInfo* info,
Linkage linkage(Linkage::ComputeIncoming(data.instruction_zone(), info));
Deoptimizer::EnsureCodeForMaxDeoptimizationEntries(isolate);
if (!pipeline.CreateGraph()) return Handle<Code>::null();
if (!pipeline.OptimizeGraph(&linkage)) return Handle<Code>::null();
if (!pipeline.CreateGraph()) return MaybeHandle<Code>();
if (!pipeline.OptimizeGraph(&linkage)) return MaybeHandle<Code>();
pipeline.AssembleCode(&linkage);
return pipeline.FinalizeCode();
}
// static
Handle<Code> Pipeline::GenerateCodeForTesting(OptimizedCompilationInfo* info,
Isolate* isolate, Graph* graph,
Schedule* schedule) {
MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate, Graph* graph,
Schedule* schedule) {
auto call_descriptor = Linkage::ComputeIncoming(info->zone(), info);
return GenerateCodeForTesting(info, isolate, call_descriptor, graph,
schedule);
}
// static
Handle<Code> Pipeline::GenerateCodeForTesting(
MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate,
CallDescriptor* call_descriptor, Graph* graph, Schedule* schedule,
SourcePositionTable* source_positions) {
......@@ -2437,12 +2438,15 @@ std::ostream& operator<<(std::ostream& out, const BlockStartsAsJSON& s) {
return out;
}
Handle<Code> PipelineImpl::FinalizeCode() {
MaybeHandle<Code> PipelineImpl::FinalizeCode() {
PipelineData* data = this->data_;
Run<FinalizeCodePhase>();
Handle<Code> code = data->code();
if (code.is_null()) return code;
MaybeHandle<Code> maybe_code = data->code();
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
}
if (data->profiler_data()) {
#ifdef ENABLE_DISASSEMBLER
......@@ -2486,11 +2490,11 @@ Handle<Code> PipelineImpl::FinalizeCode() {
return code;
}
Handle<Code> PipelineImpl::GenerateCode(CallDescriptor* call_descriptor) {
MaybeHandle<Code> PipelineImpl::GenerateCode(CallDescriptor* call_descriptor) {
Linkage linkage(call_descriptor);
// Perform instruction selection and register allocation.
if (!SelectInstructions(&linkage)) return Handle<Code>();
if (!SelectInstructions(&linkage)) return MaybeHandle<Code>();
// Generate the final machine code.
AssembleCode(&linkage);
......
......@@ -56,7 +56,7 @@ class Pipeline : public AllStatic {
// Run the pipeline on a machine graph and generate code. The {schedule} must
// be valid, hence the given {graph} does not need to be schedulable.
static Handle<Code> GenerateCodeForCodeStub(
static MaybeHandle<Code> GenerateCodeForCodeStub(
Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
Schedule* schedule, Code::Kind kind, const char* debug_name,
uint32_t stub_key, int32_t builtin_index, JumpOptimizationInfo* jump_opt,
......@@ -64,14 +64,14 @@ class Pipeline : public AllStatic {
// Run the entire pipeline and generate a handle to a code object suitable for
// testing.
static Handle<Code> GenerateCodeForTesting(OptimizedCompilationInfo* info,
Isolate* isolate);
static MaybeHandle<Code> GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate);
// Run the pipeline on a machine graph and generate code. If {schedule} is
// {nullptr}, then compute a new schedule for code generation.
static Handle<Code> GenerateCodeForTesting(OptimizedCompilationInfo* info,
Isolate* isolate, Graph* graph,
Schedule* schedule = nullptr);
static MaybeHandle<Code> GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate, Graph* graph,
Schedule* schedule = nullptr);
// Run just the register allocator phases.
V8_EXPORT_PRIVATE static bool AllocateRegistersForTesting(
......@@ -80,7 +80,7 @@ class Pipeline : public AllStatic {
// Run the pipeline on a machine graph and generate code. If {schedule} is
// {nullptr}, then compute a new schedule for code generation.
V8_EXPORT_PRIVATE static Handle<Code> GenerateCodeForTesting(
V8_EXPORT_PRIVATE static MaybeHandle<Code> GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate,
CallDescriptor* call_descriptor, Graph* graph,
Schedule* schedule = nullptr,
......
......@@ -4711,9 +4711,9 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
};
} // namespace
Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::WasmModule* module,
Address call_target, uint32_t index,
wasm::UseTrapHandler use_trap_handler) {
MaybeHandle<Code> CompileJSToWasmWrapper(
Isolate* isolate, wasm::WasmModule* module, Address call_target,
uint32_t index, wasm::UseTrapHandler use_trap_handler) {
const wasm::WasmFunction* func = &module->functions[index];
//----------------------------------------------------------------------------
......@@ -4761,10 +4761,14 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::WasmModule* module,
CallDescriptor* incoming = Linkage::GetJSCallDescriptor(
&zone, false, params + 1, CallDescriptor::kNoFlags);
Handle<Code> code =
MaybeHandle<Code> maybe_code =
Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph);
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
}
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code && !code.is_null()) {
if (FLAG_print_opt_code) {
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
OFStream os(tracing_scope.file());
code->Disassemble(func_name.start(), os);
......@@ -4779,10 +4783,10 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::WasmModule* module,
return code;
}
Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
wasm::FunctionSig* sig, uint32_t index,
wasm::ModuleOrigin origin,
wasm::UseTrapHandler use_trap_handler) {
MaybeHandle<Code> CompileWasmToJSWrapper(
Isolate* isolate, Handle<JSReceiver> target, wasm::FunctionSig* sig,
uint32_t index, wasm::ModuleOrigin origin,
wasm::UseTrapHandler use_trap_handler) {
//----------------------------------------------------------------------------
// Create the Graph
//----------------------------------------------------------------------------
......@@ -4832,10 +4836,14 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
incoming = GetI32WasmCallDescriptor(&zone, incoming);
}
Handle<Code> code = Pipeline::GenerateCodeForTesting(
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForTesting(
&info, isolate, incoming, &graph, nullptr, source_position_table);
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
}
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code && !code.is_null()) {
if (FLAG_print_opt_code) {
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
OFStream os(tracing_scope.file());
code->Disassemble(func_name.start(), os);
......@@ -4850,8 +4858,9 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
return code;
}
Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
wasm::FunctionSig* sig) {
MaybeHandle<Code> CompileWasmInterpreterEntry(Isolate* isolate,
uint32_t func_index,
wasm::FunctionSig* sig) {
//----------------------------------------------------------------------------
// Create the Graph
//----------------------------------------------------------------------------
......@@ -4872,49 +4881,49 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
builder.set_effect_ptr(&effect);
builder.BuildWasmInterpreterEntry(func_index);
Handle<Code> code = Handle<Code>::null();
{
// Schedule and compile to machine code.
CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig);
if (machine.Is32()) {
incoming = GetI32WasmCallDescriptor(&zone, incoming);
}
// Schedule and compile to machine code.
CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig);
if (machine.Is32()) {
incoming = GetI32WasmCallDescriptor(&zone, incoming);
}
#ifdef DEBUG
EmbeddedVector<char, 32> func_name;
func_name.Truncate(
SNPrintF(func_name, "wasm-interpreter-entry#%d", func_index));
EmbeddedVector<char, 32> func_name;
func_name.Truncate(
SNPrintF(func_name, "wasm-interpreter-entry#%d", func_index));
#else
Vector<const char> func_name = CStrVector("wasm-interpreter-entry");
Vector<const char> func_name = CStrVector("wasm-interpreter-entry");
#endif
OptimizedCompilationInfo info(func_name, &zone,
Code::WASM_INTERPRETER_ENTRY);
OptimizedCompilationInfo info(func_name, &zone, Code::WASM_INTERPRETER_ENTRY);
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
StdoutStream{} << "-- Wasm interpreter entry graph -- " << std::endl
<< AsRPO(graph);
}
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
StdoutStream{} << "-- Wasm interpreter entry graph -- " << std::endl
<< AsRPO(graph);
}
code = Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph,
nullptr);
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForTesting(
&info, isolate, incoming, &graph, nullptr);
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
}
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code && !code.is_null()) {
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
OFStream os(tracing_scope.file());
code->Disassemble(func_name.start(), os);
}
if (FLAG_print_opt_code) {
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
OFStream os(tracing_scope.file());
code->Disassemble(func_name.start(), os);
}
#endif
if (must_record_function_compilation(isolate)) {
RecordFunctionCompilation(CodeEventListener::STUB_TAG, isolate, code,
"%.*s", func_name.length(), func_name.start());
}
if (must_record_function_compilation(isolate)) {
RecordFunctionCompilation(CodeEventListener::STUB_TAG, isolate, code,
"%.*s", func_name.length(), func_name.start());
}
return code;
return maybe_code;
}
Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
Zone zone(isolate->allocator(), ZONE_NAME);
Graph graph(&zone);
CommonOperatorBuilder common(&zone);
......@@ -4960,10 +4969,14 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
StdoutStream{} << "-- C Wasm entry graph -- " << std::endl << AsRPO(graph);
}
Handle<Code> code =
MaybeHandle<Code> maybe_code =
Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph);
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
}
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code && !code.is_null()) {
if (FLAG_print_opt_code) {
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
OFStream os(tracing_scope.file());
code->Disassemble(debug_name, os);
......
......@@ -107,21 +107,20 @@ class TurbofanWasmCompilationUnit {
};
// Wraps a JS function, producing a code object that can be called from wasm.
Handle<Code> CompileWasmToJSWrapper(Isolate*, Handle<JSReceiver> target,
wasm::FunctionSig*, uint32_t index,
wasm::ModuleOrigin, wasm::UseTrapHandler);
MaybeHandle<Code> CompileWasmToJSWrapper(Isolate*, Handle<JSReceiver> target,
wasm::FunctionSig*, uint32_t index,
wasm::ModuleOrigin,
wasm::UseTrapHandler);
// Wraps a given wasm code object, producing a code object.
V8_EXPORT_PRIVATE Handle<Code> CompileJSToWasmWrapper(Isolate*,
wasm::WasmModule*,
Address call_target,
uint32_t index,
wasm::UseTrapHandler);
V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper(
Isolate*, wasm::WasmModule*, Address call_target, uint32_t index,
wasm::UseTrapHandler);
// Compiles a stub that redirects a call to a wasm function to the wasm
// interpreter. It's ABI compatible with the compiled wasm function.
Handle<Code> CompileWasmInterpreterEntry(Isolate*, uint32_t func_index,
wasm::FunctionSig*);
MaybeHandle<Code> CompileWasmInterpreterEntry(Isolate*, uint32_t func_index,
wasm::FunctionSig*);
// Helper function to get the offset into a fixed array for a given {index}.
// TODO(titzer): access-builder.h is not accessible outside compiler. Move?
......@@ -138,7 +137,7 @@ enum CWasmEntryParameters {
// Compiles a stub with JS linkage, taking parameters as described by
// {CWasmEntryParameters}. It loads the wasm parameters from the argument
// buffer and calls the wasm function given as first parameter.
Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig);
MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig);
// Values from the instance object are cached between WASM-level function calls.
// This struct allows the SSA environment handling this cache to be defined
......
......@@ -216,8 +216,10 @@ class JSToWasmWrapperCache {
}
}
Handle<Code> code = compiler::CompileJSToWasmWrapper(
isolate, module, call_target, index, use_trap_handler);
Handle<Code> code =
compiler::CompileJSToWasmWrapper(isolate, module, call_target, index,
use_trap_handler)
.ToHandleChecked();
if (!is_import) {
uint32_t new_cache_idx = sig_map_.FindOrInsert(func->sig);
DCHECK_EQ(code_cache_.size(), new_cache_idx);
......@@ -2163,9 +2165,11 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
} else {
// The imported function is a callable.
Handle<JSReceiver> js_receiver(JSReceiver::cast(*value), isolate_);
Handle<Code> wrapper_code = compiler::CompileWasmToJSWrapper(
isolate_, js_receiver, expected_sig, func_index, module_->origin,
use_trap_handler());
Handle<Code> wrapper_code =
compiler::CompileWasmToJSWrapper(
isolate_, js_receiver, expected_sig, func_index,
module_->origin, use_trap_handler())
.ToHandleChecked();
RecordStats(*wrapper_code, counters());
WasmCode* wasm_code = native_module->AddCodeCopy(
......
......@@ -676,10 +676,10 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
DCHECK_GT(module->functions.size(), func_index);
if (!interpreted_functions->get(func_index)->IsUndefined(isolate)) continue;
Handle<Code> new_code = compiler::CompileWasmInterpreterEntry(
MaybeHandle<Code> new_code = compiler::CompileWasmInterpreterEntry(
isolate, func_index, module->functions[func_index].sig);
const wasm::WasmCode* wasm_new_code =
native_module->AddInterpreterEntry(new_code, func_index);
const wasm::WasmCode* wasm_new_code = native_module->AddInterpreterEntry(
new_code.ToHandleChecked(), func_index);
const wasm::WasmCode* old_code =
native_module->code(static_cast<uint32_t>(func_index));
Handle<Foreign> foreign_holder = isolate->factory()->NewForeign(
......@@ -770,7 +770,8 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry(
debug_info->set_c_wasm_entries(*entries);
}
DCHECK(entries->get(index)->IsUndefined(isolate));
Handle<Code> new_entry_code = compiler::CompileCWasmEntry(isolate, sig);
Handle<Code> new_entry_code =
compiler::CompileCWasmEntry(isolate, sig).ToHandleChecked();
Handle<WasmExportedFunctionData> function_data =
Handle<WasmExportedFunctionData>::cast(isolate->factory()->NewStruct(
WASM_EXPORTED_FUNCTION_DATA_TYPE, TENURED));
......
......@@ -150,8 +150,8 @@ Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
CHECK(info.shared_info()->HasBytecodeArray());
JSFunction::EnsureFeedbackVector(function);
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, isolate);
CHECK(!code.is_null());
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, isolate).ToHandleChecked();
info.dependencies()->Commit(code);
info.context()->native_context()->AddOptimizedCode(*code);
function->set_code(*code);
......@@ -165,8 +165,8 @@ Handle<JSFunction> FunctionTester::CompileGraph(Graph* graph) {
Zone zone(isolate->allocator(), ZONE_NAME);
OptimizedCompilationInfo info(&zone, isolate, shared, function);
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, isolate, graph);
CHECK(!code.is_null());
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, isolate, graph).ToHandleChecked();
function->set_code(*code);
return function;
}
......
......@@ -1106,7 +1106,7 @@ class CodeGeneratorTester {
generator_->FinishCode();
generator_->safepoints()->Emit(generator_->tasm(),
frame_.GetTotalFrameSlotCount());
return generator_->FinalizeCode();
return generator_->FinalizeCode().ToHandleChecked();
}
Handle<Code> FinalizeForExecuting() {
......
......@@ -163,8 +163,10 @@ void TestReturnMultipleValues(MachineType type) {
OptimizedCompilationInfo info(ArrayVector("testing"), handles.main_zone(),
Code::WASM_FUNCTION);
Handle<Code> code = Pipeline::GenerateCodeForTesting(
&info, handles.main_isolate(), desc, m.graph(), m.Export());
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, handles.main_isolate(), desc,
m.graph(), m.Export())
.ToHandleChecked();
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_code) {
StdoutStream os;
......@@ -256,8 +258,10 @@ void ReturnLastValue(MachineType type) {
OptimizedCompilationInfo info(ArrayVector("testing"), handles.main_zone(),
Code::WASM_FUNCTION);
Handle<Code> code = Pipeline::GenerateCodeForTesting(
&info, handles.main_isolate(), desc, m.graph(), m.Export());
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, handles.main_isolate(), desc,
m.graph(), m.Export())
.ToHandleChecked();
std::unique_ptr<wasm::NativeModule> module = AllocateNativeModule(
handles.main_isolate(), code->raw_instruction_size());
......@@ -316,8 +320,10 @@ void ReturnSumOfReturns(MachineType type) {
OptimizedCompilationInfo info(ArrayVector("testing"), handles.main_zone(),
Code::WASM_FUNCTION);
Handle<Code> code = Pipeline::GenerateCodeForTesting(
&info, handles.main_isolate(), desc, m.graph(), m.Export());
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, handles.main_isolate(), desc,
m.graph(), m.Export())
.ToHandleChecked();
std::unique_ptr<wasm::NativeModule> module = AllocateNativeModule(
handles.main_isolate(), code->raw_instruction_size());
......
......@@ -128,7 +128,8 @@ class BytecodeGraphTester {
compilation_info.ReopenHandlesInNewHandleScope();
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&compilation_info, isolate_);
Pipeline::GenerateCodeForTesting(&compilation_info, isolate_)
.ToHandleChecked();
function->set_code(*code);
return function;
......
......@@ -258,8 +258,8 @@ Handle<Code> CompileGraph(const char* name, CallDescriptor* call_descriptor,
OptimizedCompilationInfo info(ArrayVector("testing"), graph->zone(),
Code::STUB);
Handle<Code> code = Pipeline::GenerateCodeForTesting(
&info, isolate, call_descriptor, graph, schedule);
CHECK(!code.is_null());
&info, isolate, call_descriptor, graph, schedule)
.ToHandleChecked();
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code) {
StdoutStream os;
......
......@@ -42,7 +42,7 @@ TestingModuleBuilder::TestingModuleBuilder(
if (maybe_import) {
// Manually compile a wasm to JS wrapper and insert it into the instance.
CodeSpaceMemoryModificationScope modification_scope(isolate_->heap());
Handle<Code> code = compiler::CompileWasmToJSWrapper(
MaybeHandle<Code> code = compiler::CompileWasmToJSWrapper(
isolate_, maybe_import->js_function, maybe_import->sig,
maybe_import_index, test_module_->origin,
trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler
......@@ -51,7 +51,8 @@ TestingModuleBuilder::TestingModuleBuilder(
native_module_->SetNumFunctionsForTesting(maybe_import_index + 1);
}
auto wasm_to_js_wrapper = native_module_->AddCodeCopy(
code, wasm::WasmCode::kWasmToJsWrapper, maybe_import_index);
code.ToHandleChecked(), wasm::WasmCode::kWasmToJsWrapper,
maybe_import_index);
ImportedFunctionEntry(instance_object_, maybe_import_index)
.set_wasm_to_js(*maybe_import->js_function, wasm_to_js_wrapper);
......@@ -119,9 +120,10 @@ Handle<JSFunction> TestingModuleBuilder::WrapCode(uint32_t index) {
// Wrap the code so it can be called as a JS function.
Link();
wasm::WasmCode* code = native_module_->code(index);
Handle<Code> ret_code = compiler::CompileJSToWasmWrapper(
MaybeHandle<Code> maybe_ret_code = compiler::CompileJSToWasmWrapper(
isolate_, test_module_ptr_, code->instruction_start(), index,
trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler : kNoTrapHandler);
Handle<Code> ret_code = maybe_ret_code.ToHandleChecked();
Handle<JSFunction> ret = WasmExportedFunction::New(
isolate_, instance_object(), MaybeHandle<String>(),
static_cast<int>(index),
......@@ -339,7 +341,8 @@ void WasmFunctionWrapper::Init(CallDescriptor* call_descriptor,
}
Handle<Code> WasmFunctionWrapper::GetWrapperCode() {
if (code_.is_null()) {
Handle<Code> code;
if (!code_.ToHandle(&code)) {
Isolate* isolate = CcTest::InitIsolateOnce();
auto call_descriptor =
......@@ -364,18 +367,18 @@ Handle<Code> WasmFunctionWrapper::GetWrapperCode() {
Code::C_WASM_ENTRY);
code_ = compiler::Pipeline::GenerateCodeForTesting(
&info, isolate, call_descriptor, graph(), nullptr);
CHECK(!code_.is_null());
code = code_.ToHandleChecked();
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code) {
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
OFStream os(tracing_scope.file());
code_->Disassemble("wasm wrapper", os);
code->Disassemble("wasm wrapper", os);
}
#endif
}
return code_;
return code;
}
void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
......
......@@ -299,7 +299,7 @@ class WasmFunctionWrapper : private compiler::GraphAndBuilders {
private:
Node* inner_code_node_;
Node* context_address_;
Handle<Code> code_;
MaybeHandle<Code> code_;
Signature<MachineType>* signature_;
};
......
......@@ -256,8 +256,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
OptimizedCompilationInfo info(ArrayVector("testing"), &zone,
Code::WASM_FUNCTION);
Handle<Code> code = Pipeline::GenerateCodeForTesting(
&info, i_isolate, desc, callee.graph(), callee.Export());
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, i_isolate, desc, callee.graph(),
callee.Export())
.ToHandleChecked();
std::unique_ptr<wasm::NativeModule> module =
AllocateNativeModule(i_isolate, code->raw_instruction_size());
......@@ -300,8 +302,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Call the wrapper.
OptimizedCompilationInfo wrapper_info(ArrayVector("wrapper"), &zone,
Code::STUB);
Handle<Code> wrapper_code = Pipeline::GenerateCodeForTesting(
&wrapper_info, i_isolate, wrapper_desc, caller.graph(), caller.Export());
Handle<Code> wrapper_code =
Pipeline::GenerateCodeForTesting(&wrapper_info, i_isolate, wrapper_desc,
caller.graph(), caller.Export())
.ToHandleChecked();
auto fn = GeneratedCode<int32_t>::FromCode(*wrapper_code);
int result = fn.Call();
......
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