Commit 91c5b186 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[maglev] Log Maglev compilations

This allows us to inject maglev compilations into perf profiles.

Bug: v8:7700
Change-Id: Ic1f2671835ca231cd954124db325a5ab8480bee0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3579101
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79886}
parent cce601ba
......@@ -1128,6 +1128,25 @@ MaybeHandle<CodeT> CompileTurbofan(Isolate* isolate,
return {};
}
#ifdef V8_ENABLE_MAGLEV
// TODO(v8:7700): Record maglev compilations better.
void RecordMaglevFunctionCompilation(Isolate* isolate,
Handle<JSFunction> function) {
Handle<AbstractCode> abstract_code(
AbstractCode::cast(FromCodeT(function->code())), isolate);
Handle<SharedFunctionInfo> shared(function->shared(), isolate);
Handle<Script> script(Script::cast(shared->script()), isolate);
Handle<FeedbackVector> feedback_vector(function->feedback_vector(), isolate);
// Optimistic estimate.
double time_taken_ms = 0;
LogFunctionCompilation(isolate, CodeEventListener::FUNCTION_TAG, script,
shared, feedback_vector, abstract_code,
abstract_code->kind(), time_taken_ms);
}
#endif // V8_ENABLE_MAGLEV
MaybeHandle<CodeT> CompileMaglev(Isolate* isolate, Handle<JSFunction> function,
ConcurrencyMode mode,
BytecodeOffset osr_offset,
......@@ -1145,13 +1164,6 @@ MaybeHandle<CodeT> CompileMaglev(Isolate* isolate, Handle<JSFunction> function,
DCHECK(!isolate->has_pending_exception());
PostponeInterruptsScope postpone(isolate);
if (IsSynchronous(mode)) {
function->reset_tiering_state();
return Maglev::Compile(isolate, function);
}
DCHECK(IsConcurrent(mode));
// TODO(v8:7700): See everything in CompileTurbofan_Concurrent.
// - Tracing,
// - timers,
......@@ -1163,6 +1175,29 @@ MaybeHandle<CodeT> CompileMaglev(Isolate* isolate, Handle<JSFunction> function,
CompilationJob::Status status = job->PrepareJob(isolate);
CHECK_EQ(status, CompilationJob::SUCCEEDED); // TODO(v8:7700): Use status.
if (IsSynchronous(mode)) {
function->reset_tiering_state();
{
// Park the main thread Isolate here, to be in the same state as
// background threads.
ParkedScope parked_scope(isolate->main_thread_local_isolate());
if (job->ExecuteJob(isolate->counters()->runtime_call_stats(),
isolate->main_thread_local_isolate()) !=
CompilationJob::SUCCEEDED) {
return {};
}
}
if (job->FinalizeJob(isolate) != CompilationJob::SUCCEEDED) {
return {};
}
RecordMaglevFunctionCompilation(isolate, function);
return handle(function->code(), isolate);
}
DCHECK(IsConcurrent(mode));
// Enqueue it.
isolate->maglev_concurrent_dispatcher()->EnqueueJob(std::move(job));
......@@ -3457,6 +3492,16 @@ bool Compiler::FinalizeTurbofanCompilationJob(TurbofanCompilationJob* job,
return CompilationJob::FAILED;
}
// static
bool Compiler::FinalizeMaglevCompilationJob(maglev::MaglevCompilationJob* job,
Isolate* isolate) {
#ifdef V8_ENABLE_MAGLEV
VMState<COMPILER> state(isolate);
RecordMaglevFunctionCompilation(isolate, job->function());
#endif
return CompilationJob::SUCCEEDED;
}
// static
void Compiler::PostInstantiation(Handle<JSFunction> function) {
Isolate* isolate = function->GetIsolate();
......
......@@ -44,6 +44,10 @@ class WorkerThreadRuntimeCallStats;
struct ScriptDetails;
struct ScriptStreamingData;
namespace maglev {
class MaglevCompilationJob;
} // namespace maglev
// The V8 compiler API.
//
// This is the central hub for dispatching to the various compilers within V8.
......@@ -121,6 +125,10 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
static bool FinalizeTurbofanCompilationJob(TurbofanCompilationJob* job,
Isolate* isolate);
// Finalize and install Maglev code from a previously run job.
static bool FinalizeMaglevCompilationJob(maglev::MaglevCompilationJob* job,
Isolate* isolate);
// Give the compiler a chance to perform low-latency initialization tasks of
// the given {function} on its instantiation. Note that only the runtime will
// offer this chance, optimized closure instantiation will not call this.
......
......@@ -217,6 +217,7 @@ void PerfJitLogger::LogRecordedBuffer(
if (FLAG_perf_basic_prof_only_functions &&
(abstract_code->kind() != CodeKind::INTERPRETED_FUNCTION &&
abstract_code->kind() != CodeKind::TURBOFAN &&
abstract_code->kind() != CodeKind::MAGLEV &&
abstract_code->kind() != CodeKind::BASELINE)) {
return;
}
......
......@@ -4,6 +4,7 @@
#include "src/maglev/maglev-concurrent-dispatcher.h"
#include "src/codegen/compiler.h"
#include "src/compiler/compilation-dependencies.h"
#include "src/compiler/js-heap-broker.h"
#include "src/execution/isolate.h"
......@@ -115,6 +116,10 @@ CompilationJob::Status MaglevCompilationJob::FinalizeJobImpl(Isolate* isolate) {
return CompilationJob::SUCCEEDED;
}
Handle<JSFunction> MaglevCompilationJob::function() const {
return info_->function();
}
// The JobTask is posted to V8::GetCurrentPlatform(). It's responsible for
// processing the incoming queue on a worker thread.
class MaglevConcurrentDispatcher::JobTask final : public v8::JobTask {
......@@ -187,7 +192,9 @@ void MaglevConcurrentDispatcher::FinalizeFinishedJobs() {
CompilationJob::Status status = job->FinalizeJob(isolate_);
// TODO(v8:7700): Use the result and check if job succeed
// when all the bytecodes are implemented.
USE(status);
if (status == CompilationJob::SUCCEEDED) {
Compiler::FinalizeMaglevCompilationJob(job.get(), isolate_);
}
}
}
......
......@@ -54,6 +54,8 @@ class MaglevCompilationJob final : public OptimizedCompilationJob {
LocalIsolate* local_isolate) override;
Status FinalizeJobImpl(Isolate* isolate) override;
Handle<JSFunction> function() const;
private:
explicit MaglevCompilationJob(std::unique_ptr<MaglevCompilationInfo>&& info);
......
......@@ -24,6 +24,8 @@ const char* CodeKindToMarker(CodeKind kind) {
return "~";
case CodeKind::BASELINE:
return "^";
case CodeKind::MAGLEV:
return "+";
case CodeKind::TURBOFAN:
return "*";
default:
......
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