Commit 5cdac4b8 authored by Jakob Gruber's avatar Jakob Gruber Committed by V8 LUCI CQ

[tiering] Centralize interrupt budget decisions

.. by moving them all to TieringManager.

Bug: v8:7700
Change-Id: I03eb2d1607b06ece84a1ca98ebc723788dbc0cde
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3500220
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79325}
parent 9923a6c2
......@@ -121,6 +121,25 @@ void TieringManager::AttemptOnStackReplacement(UnoptimizedFrame* frame,
{level + loop_nesting_levels, AbstractCode::kMaxLoopNestingMarker}));
}
// static
int TieringManager::InterruptBudgetFor(Isolate* isolate, JSFunction function) {
if (function.has_feedback_vector()) {
return FLAG_interrupt_budget; // For Turbofan.
}
DCHECK(!function.has_feedback_vector());
DCHECK(function.shared().is_compiled());
return function.shared().GetBytecodeArray(isolate).length() *
FLAG_interrupt_budget_factor_for_feedback_allocation;
}
// static
int TieringManager::InitialInterruptBudget() {
return V8_LIKELY(FLAG_lazy_feedback_allocation)
? FLAG_interrupt_budget_for_feedback_allocation
: FLAG_interrupt_budget;
}
void TieringManager::MaybeOptimizeFrame(JSFunction function,
JavaScriptFrame* frame,
CodeKind code_kind) {
......@@ -261,7 +280,7 @@ void TieringManager::OnInterruptTick(Handle<JSFunction> function) {
// Ensure that the feedback vector has been allocated, and reset the
// interrupt budget in preparation for the next tick.
if (had_feedback_vector) {
function->SetInterruptBudget();
function->SetInterruptBudget(isolate_);
} else {
JSFunction::CreateAndAttachFeedbackVector(isolate_, function,
&is_compiled_scope);
......
......@@ -31,6 +31,11 @@ class TieringManager {
void AttemptOnStackReplacement(UnoptimizedFrame* frame,
int nesting_levels = 1);
// For use when a JSFunction is available.
static int InterruptBudgetFor(Isolate* isolate, JSFunction function);
// For use when no JSFunction is available.
static int InitialInterruptBudget();
private:
// Make the decision whether to optimize the given function, and mark it for
// optimization if the decision was 'yes'.
......
......@@ -5,6 +5,7 @@
#ifndef V8_OBJECTS_FEEDBACK_CELL_INL_H_
#define V8_OBJECTS_FEEDBACK_CELL_INL_H_
#include "src/execution/tiering-manager.h"
#include "src/heap/heap-write-barrier-inl.h"
#include "src/objects/feedback-cell.h"
#include "src/objects/feedback-vector-inl.h"
......@@ -48,11 +49,7 @@ void FeedbackCell::reset_feedback_vector(
}
void FeedbackCell::SetInitialInterruptBudget() {
if (FLAG_lazy_feedback_allocation) {
set_interrupt_budget(FLAG_interrupt_budget_for_feedback_allocation);
} else {
set_interrupt_budget(FLAG_interrupt_budget);
}
set_interrupt_budget(TieringManager::InitialInterruptBudget());
}
......
......@@ -407,13 +407,6 @@ void FeedbackVector::SetOptimizedCode(Handle<FeedbackVector> vector,
vector->set_flags(state);
}
// static
void FeedbackVector::SetInterruptBudget(FeedbackCell feedback_cell, int value) {
DCHECK(feedback_cell.value().IsFeedbackVector());
// Set the interrupt budget as required for tiering up to next level.
feedback_cell.set_interrupt_budget(value);
}
void FeedbackVector::ClearOptimizedCode() {
DCHECK(has_optimized_code());
DCHECK(maybe_has_optimized_code());
......
......@@ -252,9 +252,6 @@ class FeedbackVector
// Clears the optimization marker in the feedback vector.
void ClearOptimizationMarker();
// This function expects that the feedback cell contains a feedback vector.
static void SetInterruptBudget(FeedbackCell feedback_cell, int value);
// Conversion from a slot to an integer index to the underlying array.
static int GetIndex(FeedbackSlot slot) { return slot.ToInt(); }
......
......@@ -69,18 +69,6 @@ bool JSFunction::IsMarkedForConcurrentOptimization() {
OptimizationMarker::kCompileTurbofan_Concurrent;
}
void JSFunction::SetInterruptBudget() {
if (has_feedback_vector()) {
int budget = FLAG_interrupt_budget; // For Turbofan.
FeedbackVector::SetInterruptBudget(raw_feedback_cell(), budget);
} else {
DCHECK(shared().is_compiled());
raw_feedback_cell().set_interrupt_budget(
shared().GetBytecodeArray(GetIsolate()).length() *
FLAG_interrupt_budget_factor_for_feedback_allocation);
}
}
bool JSFunction::IsInOptimizationQueue() {
if (!has_feedback_vector()) return false;
return feedback_vector().optimization_marker() ==
......
......@@ -6,6 +6,7 @@
#include "src/codegen/compiler.h"
#include "src/diagnostics/code-tracer.h"
#include "src/execution/tiering-manager.h"
#include "src/heap/heap-inl.h"
#include "src/ic/ic.h"
#include "src/init/bootstrapper.h"
......@@ -214,6 +215,11 @@ void JSFunction::MarkForOptimization(Isolate* isolate, CodeKind target_kind,
SetOptimizationMarker(OptimizationMarkerFor(target_kind, mode));
}
void JSFunction::SetInterruptBudget(Isolate* isolate) {
raw_feedback_cell().set_interrupt_budget(
TieringManager::InterruptBudgetFor(isolate, *this));
}
// static
MaybeHandle<String> JSBoundFunction::GetName(Isolate* isolate,
Handle<JSBoundFunction> function) {
......@@ -310,7 +316,7 @@ void JSFunction::EnsureClosureFeedbackCellArray(
// cases.
if (reset_budget_for_feedback_allocation ||
!has_closure_feedback_cell_array) {
function->SetInterruptBudget();
function->SetInterruptBudget(isolate);
}
if (has_closure_feedback_cell_array) {
......@@ -329,7 +335,7 @@ void JSFunction::EnsureClosureFeedbackCellArray(
Handle<FeedbackCell> feedback_cell =
isolate->factory()->NewOneClosureCell(feedback_cell_array);
function->set_raw_feedback_cell(*feedback_cell, kReleaseStore);
function->SetInterruptBudget();
function->SetInterruptBudget(isolate);
} else {
function->raw_feedback_cell().set_value(*feedback_cell_array,
kReleaseStore);
......@@ -375,7 +381,7 @@ void JSFunction::CreateAndAttachFeedbackVector(
DCHECK(function->raw_feedback_cell() !=
isolate->heap()->many_closures_cell());
function->raw_feedback_cell().set_value(*feedback_vector, kReleaseStore);
function->SetInterruptBudget();
function->SetInterruptBudget(isolate);
}
// static
......
......@@ -179,7 +179,7 @@ class JSFunction : public TorqueGeneratedJSFunction<
// Sets the interrupt budget based on whether the function has a feedback
// vector and any optimized code.
inline void SetInterruptBudget();
void SetInterruptBudget(Isolate* isolate);
// If slack tracking is active, it computes instance size of the initial map
// with minimum permissible object slack. If it is not active, it simply
......
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