diff --git a/BUILD.bazel b/BUILD.bazel index edbaf359e3..075b6d9f34 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1243,8 +1243,6 @@ filegroup( "src/execution/protectors-inl.h", "src/execution/protectors.cc", "src/execution/protectors.h", - "src/execution/runtime-profiler.cc", - "src/execution/runtime-profiler.h", "src/execution/shared-mutex-guard-if-off-thread.h", "src/execution/simulator-base.cc", "src/execution/simulator-base.h", @@ -1255,6 +1253,8 @@ filegroup( "src/execution/thread-id.h", "src/execution/thread-local-top.cc", "src/execution/thread-local-top.h", + "src/execution/tiering-manager.cc", + "src/execution/tiering-manager.h", "src/execution/v8threads.cc", "src/execution/v8threads.h", "src/execution/vm-state-inl.h", diff --git a/BUILD.gn b/BUILD.gn index 26556963dc..af842a1794 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2921,13 +2921,13 @@ v8_header_set("v8_internal_headers") { "src/execution/pointer-authentication.h", "src/execution/protectors-inl.h", "src/execution/protectors.h", - "src/execution/runtime-profiler.h", "src/execution/shared-mutex-guard-if-off-thread.h", "src/execution/simulator-base.h", "src/execution/simulator.h", "src/execution/stack-guard.h", "src/execution/thread-id.h", "src/execution/thread-local-top.h", + "src/execution/tiering-manager.h", "src/execution/v8threads.h", "src/execution/vm-state-inl.h", "src/execution/vm-state.h", @@ -4142,11 +4142,11 @@ v8_source_set("v8_base_without_compiler") { "src/execution/messages.cc", "src/execution/microtask-queue.cc", "src/execution/protectors.cc", - "src/execution/runtime-profiler.cc", "src/execution/simulator-base.cc", "src/execution/stack-guard.cc", "src/execution/thread-id.cc", "src/execution/thread-local-top.cc", + "src/execution/tiering-manager.cc", "src/execution/v8threads.cc", "src/extensions/cputracemark-extension.cc", "src/extensions/externalize-string-extension.cc", diff --git a/src/api/api.cc b/src/api/api.cc index 230493db4b..e6797c92a5 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -57,7 +57,6 @@ #include "src/execution/isolate-inl.h" #include "src/execution/messages.h" #include "src/execution/microtask-queue.h" -#include "src/execution/runtime-profiler.h" #include "src/execution/simulator.h" #include "src/execution/v8threads.h" #include "src/execution/vm-state-inl.h" diff --git a/src/codegen/compiler.cc b/src/codegen/compiler.cc index dc8aa24ded..768a906a5e 100644 --- a/src/codegen/compiler.cc +++ b/src/codegen/compiler.cc @@ -34,7 +34,6 @@ #include "src/execution/isolate-inl.h" #include "src/execution/isolate.h" #include "src/execution/local-isolate.h" -#include "src/execution/runtime-profiler.h" #include "src/execution/vm-state-inl.h" #include "src/handles/handles.h" #include "src/handles/maybe-handles.h" diff --git a/src/execution/isolate.cc b/src/execution/isolate.cc index 4f3e15f4b5..d514cfaa1e 100644 --- a/src/execution/isolate.cc +++ b/src/execution/isolate.cc @@ -53,8 +53,8 @@ #include "src/execution/messages.h" #include "src/execution/microtask-queue.h" #include "src/execution/protectors-inl.h" -#include "src/execution/runtime-profiler.h" #include "src/execution/simulator.h" +#include "src/execution/tiering-manager.h" #include "src/execution/v8threads.h" #include "src/execution/vm-state-inl.h" #include "src/handles/global-handles-inl.h" @@ -3387,9 +3387,9 @@ void Isolate::Deinit() { builtins_.TearDown(); bootstrapper_->TearDown(); - if (runtime_profiler_ != nullptr) { - delete runtime_profiler_; - runtime_profiler_ = nullptr; + if (tiering_manager_ != nullptr) { + delete tiering_manager_; + tiering_manager_ = nullptr; } delete heap_profiler_; @@ -4035,9 +4035,9 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data, optimizing_compile_dispatcher_ = new OptimizingCompileDispatcher(this); } - // Initialize runtime profiler before deserialization, because collections may - // occur, clearing/updating ICs. - runtime_profiler_ = new RuntimeProfiler(this); + // Initialize before deserialization since collections may occur, + // clearing/updating ICs (and thus affecting tiering decisions). + tiering_manager_ = new TieringManager(this); // If we are deserializing, read the state into the now-empty heap. { diff --git a/src/execution/isolate.h b/src/execution/isolate.h index 019112f06c..420e317e73 100644 --- a/src/execution/isolate.h +++ b/src/execution/isolate.h @@ -121,7 +121,7 @@ class PersistentHandlesList; class ReadOnlyArtifacts; class RegExpStack; class RootVisitor; -class RuntimeProfiler; +class TieringManager; class SetupIsolateDelegate; class Simulator; class SnapshotData; @@ -1095,7 +1095,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { const std::shared_ptr& metrics_recorder() { return metrics_recorder_; } - RuntimeProfiler* runtime_profiler() { return runtime_profiler_; } + TieringManager* tiering_manager() { return tiering_manager_; } CompilationCache* compilation_cache() { return compilation_cache_; } Logger* logger() { // Call InitializeLoggingAndCounters() if logging is needed before @@ -2071,7 +2071,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { StringStream* incomplete_message_ = nullptr; Address isolate_addresses_[kIsolateAddressCount + 1] = {}; Bootstrapper* bootstrapper_ = nullptr; - RuntimeProfiler* runtime_profiler_ = nullptr; + TieringManager* tiering_manager_ = nullptr; CompilationCache* compilation_cache_ = nullptr; std::shared_ptr async_counters_; base::RecursiveMutex break_access_; diff --git a/src/execution/stack-guard.cc b/src/execution/stack-guard.cc index 9a7c8cb6eb..ddd6b7f153 100644 --- a/src/execution/stack-guard.cc +++ b/src/execution/stack-guard.cc @@ -8,7 +8,6 @@ #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" #include "src/execution/interrupts-scope.h" #include "src/execution/isolate.h" -#include "src/execution/runtime-profiler.h" #include "src/execution/simulator.h" #include "src/logging/counters.h" #include "src/objects/backing-store.h" diff --git a/src/execution/runtime-profiler.cc b/src/execution/tiering-manager.cc similarity index 85% rename from src/execution/runtime-profiler.cc rename to src/execution/tiering-manager.cc index be562525b4..10c2cb58a3 100644 --- a/src/execution/runtime-profiler.cc +++ b/src/execution/tiering-manager.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/execution/runtime-profiler.h" +#include "src/execution/tiering-manager.h" #include "src/base/platform/platform.h" #include "src/codegen/assembler.h" @@ -22,7 +22,6 @@ namespace internal { // Maximum size in bytes of generate code for a function to allow OSR. static const int kOSRBytecodeSizeAllowanceBase = 119; - static const int kOSRBytecodeSizeAllowancePerTick = 44; #define OPTIMIZATION_REASON_LIST(V) \ @@ -85,18 +84,15 @@ void TraceRecompile(JSFunction function, OptimizationReason reason, } // namespace -RuntimeProfiler::RuntimeProfiler(Isolate* isolate) - : isolate_(isolate), any_ic_changed_(false) {} - -void RuntimeProfiler::Optimize(JSFunction function, OptimizationReason reason, - CodeKind code_kind) { +void TieringManager::Optimize(JSFunction function, OptimizationReason reason, + CodeKind code_kind) { DCHECK_NE(reason, OptimizationReason::kDoNotOptimize); TraceRecompile(function, reason, code_kind, isolate_); function.MarkForOptimization(ConcurrencyMode::kConcurrent); } -void RuntimeProfiler::AttemptOnStackReplacement(UnoptimizedFrame* frame, - int loop_nesting_levels) { +void TieringManager::AttemptOnStackReplacement(UnoptimizedFrame* frame, + int loop_nesting_levels) { JSFunction function = frame->function(); SharedFunctionInfo shared = function.shared(); if (!FLAG_use_osr || !shared.IsUserJavaScript()) { @@ -122,9 +118,9 @@ void RuntimeProfiler::AttemptOnStackReplacement(UnoptimizedFrame* frame, {level + loop_nesting_levels, AbstractCode::kMaxLoopNestingMarker})); } -void RuntimeProfiler::MaybeOptimizeFrame(JSFunction function, - JavaScriptFrame* frame, - CodeKind code_kind) { +void TieringManager::MaybeOptimizeFrame(JSFunction function, + JavaScriptFrame* frame, + CodeKind code_kind) { if (function.IsInOptimizationQueue()) { TraceInOptimizationQueue(function); return; @@ -158,7 +154,7 @@ void RuntimeProfiler::MaybeOptimizeFrame(JSFunction function, } } -bool RuntimeProfiler::MaybeOSR(JSFunction function, UnoptimizedFrame* frame) { +bool TieringManager::MaybeOSR(JSFunction function, UnoptimizedFrame* frame) { int ticks = function.feedback_vector().profiler_ticks(); if (function.IsMarkedForOptimization() || function.IsMarkedForConcurrentOptimization() || @@ -182,9 +178,9 @@ bool ShouldOptimizeAsSmallFunction(int bytecode_size, bool any_ic_changed) { } // namespace -OptimizationReason RuntimeProfiler::ShouldOptimize(JSFunction function, - BytecodeArray bytecode, - JavaScriptFrame* frame) { +OptimizationReason TieringManager::ShouldOptimize(JSFunction function, + BytecodeArray bytecode, + JavaScriptFrame* frame) { if (function.ActiveTierIsTurbofan()) { return OptimizationReason::kDoNotOptimize; } @@ -238,21 +234,22 @@ OptimizationReason RuntimeProfiler::ShouldOptimize(JSFunction function, return OptimizationReason::kDoNotOptimize; } -RuntimeProfiler::MarkCandidatesForOptimizationScope:: - MarkCandidatesForOptimizationScope(RuntimeProfiler* profiler) +TieringManager::OnInterruptTickScope::OnInterruptTickScope( + TieringManager* profiler) : handle_scope_(profiler->isolate_), profiler_(profiler) { TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.MarkCandidatesForOptimization"); } -RuntimeProfiler::MarkCandidatesForOptimizationScope:: - ~MarkCandidatesForOptimizationScope() { +TieringManager::OnInterruptTickScope::~OnInterruptTickScope() { profiler_->any_ic_changed_ = false; } -void RuntimeProfiler::MarkCandidatesForOptimization(JavaScriptFrame* frame) { +void TieringManager::OnInterruptTick(JavaScriptFrame* frame) { + isolate_->counters()->runtime_profiler_ticks()->Increment(); + if (!isolate_->use_optimizer()) return; - MarkCandidatesForOptimizationScope scope(this); + OnInterruptTickScope scope(this); JSFunction function = frame->function(); CodeKind code_kind = function.GetActiveTier().value(); @@ -268,16 +265,16 @@ void RuntimeProfiler::MarkCandidatesForOptimization(JavaScriptFrame* frame) { MaybeOptimizeFrame(function, frame, code_kind); } -void RuntimeProfiler::MarkCandidatesForOptimizationFromBytecode() { +void TieringManager::OnInterruptTickFromBytecode() { JavaScriptFrameIterator it(isolate_); DCHECK(it.frame()->is_unoptimized()); - MarkCandidatesForOptimization(it.frame()); + OnInterruptTick(it.frame()); } -void RuntimeProfiler::MarkCandidatesForOptimizationFromCode() { +void TieringManager::OnInterruptTickFromCode() { JavaScriptFrameIterator it(isolate_); DCHECK(it.frame()->is_optimized()); - MarkCandidatesForOptimization(it.frame()); + OnInterruptTick(it.frame()); } } // namespace internal diff --git a/src/execution/runtime-profiler.h b/src/execution/tiering-manager.h similarity index 66% rename from src/execution/runtime-profiler.h rename to src/execution/tiering-manager.h index 0f3c94ea50..23aa686229 100644 --- a/src/execution/runtime-profiler.h +++ b/src/execution/tiering-manager.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef V8_EXECUTION_RUNTIME_PROFILER_H_ -#define V8_EXECUTION_RUNTIME_PROFILER_H_ +#ifndef V8_EXECUTION_TIERING_MANAGER_H_ +#define V8_EXECUTION_TIERING_MANAGER_H_ #include "src/common/assert-scope.h" #include "src/handles/handles.h" @@ -20,14 +20,12 @@ class JSFunction; enum class CodeKind; enum class OptimizationReason : uint8_t; -class RuntimeProfiler { +class TieringManager { public: - explicit RuntimeProfiler(Isolate* isolate); + explicit TieringManager(Isolate* isolate) : isolate_(isolate) {} - // Called from the interpreter when the bytecode interrupt has been exhausted. - void MarkCandidatesForOptimizationFromBytecode(); - // Likewise, from generated code. - void MarkCandidatesForOptimizationFromCode(); + void OnInterruptTickFromBytecode(); + void OnInterruptTickFromCode(); void NotifyICChanged() { any_ic_changed_ = true; } @@ -35,8 +33,8 @@ class RuntimeProfiler { int nesting_levels = 1); private: - // Helper function called from MarkCandidatesForOptimization* - void MarkCandidatesForOptimization(JavaScriptFrame* frame); + // Helper function called from OnInterruptTick* + void OnInterruptTick(JavaScriptFrame* frame); // Make the decision whether to optimize the given function, and mark it for // optimization if the decision was 'yes'. @@ -53,22 +51,22 @@ class RuntimeProfiler { CodeKind code_kind); void Baseline(JSFunction function, OptimizationReason reason); - class V8_NODISCARD MarkCandidatesForOptimizationScope final { + class V8_NODISCARD OnInterruptTickScope final { public: - explicit MarkCandidatesForOptimizationScope(RuntimeProfiler* profiler); - ~MarkCandidatesForOptimizationScope(); + explicit OnInterruptTickScope(TieringManager* profiler); + ~OnInterruptTickScope(); private: HandleScope handle_scope_; - RuntimeProfiler* const profiler_; + TieringManager* const profiler_; DisallowGarbageCollection no_gc; }; - Isolate* isolate_; - bool any_ic_changed_; + Isolate* const isolate_; + bool any_ic_changed_ = false; }; } // namespace internal } // namespace v8 -#endif // V8_EXECUTION_RUNTIME_PROFILER_H_ +#endif // V8_EXECUTION_TIERING_MANAGER_H_ diff --git a/src/heap/heap.cc b/src/heap/heap.cc index 8f1ad2d265..994c8e39d8 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -30,7 +30,6 @@ #include "src/execution/embedder-state.h" #include "src/execution/isolate-utils-inl.h" #include "src/execution/microtask-queue.h" -#include "src/execution/runtime-profiler.h" #include "src/execution/v8threads.h" #include "src/execution/vm-state-inl.h" #include "src/handles/global-handles-inl.h" diff --git a/src/ic/ic.cc b/src/ic/ic.cc index 1fcf31c996..d46ed22782 100644 --- a/src/ic/ic.cc +++ b/src/ic/ic.cc @@ -17,7 +17,7 @@ #include "src/execution/frames-inl.h" #include "src/execution/isolate-inl.h" #include "src/execution/protectors-inl.h" -#include "src/execution/runtime-profiler.h" +#include "src/execution/tiering-manager.h" #include "src/handles/handles-inl.h" #include "src/ic/call-optimization.h" #include "src/ic/handler-configuration-inl.h" @@ -345,7 +345,7 @@ void IC::OnFeedbackChanged(Isolate* isolate, FeedbackVector vector, } #endif - isolate->runtime_profiler()->NotifyICChanged(); + isolate->tiering_manager()->NotifyICChanged(); } namespace { diff --git a/src/init/v8.cc b/src/init/v8.cc index 746bdbbfda..edac725e8e 100644 --- a/src/init/v8.cc +++ b/src/init/v8.cc @@ -17,7 +17,6 @@ #include "src/deoptimizer/deoptimizer.h" #include "src/execution/frames.h" #include "src/execution/isolate.h" -#include "src/execution/runtime-profiler.h" #include "src/execution/simulator.h" #include "src/init/bootstrapper.h" #include "src/libsampler/sampler.h" diff --git a/src/logging/log.cc b/src/logging/log.cc index ec6beb95e8..bcbae67ec3 100644 --- a/src/logging/log.cc +++ b/src/logging/log.cc @@ -21,7 +21,6 @@ #include "src/deoptimizer/deoptimizer.h" #include "src/diagnostics/perf-jit.h" #include "src/execution/isolate.h" -#include "src/execution/runtime-profiler.h" #include "src/execution/v8threads.h" #include "src/execution/vm-state-inl.h" #include "src/handles/global-handles.h" diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index 8df0c9a073..1fc2d640fa 100644 --- a/src/runtime/runtime-internal.cc +++ b/src/runtime/runtime-internal.cc @@ -17,7 +17,7 @@ #include "src/execution/frames-inl.h" #include "src/execution/isolate-inl.h" #include "src/execution/messages.h" -#include "src/execution/runtime-profiler.h" +#include "src/execution/tiering-manager.h" #include "src/handles/maybe-handles.h" #include "src/init/bootstrapper.h" #include "src/logging/counters.h" @@ -372,8 +372,7 @@ void BytecodeBudgetInterruptFromBytecode(Isolate* isolate, } if (should_mark_for_optimization) { SealHandleScope shs(isolate); - isolate->counters()->runtime_profiler_ticks()->Increment(); - isolate->runtime_profiler()->MarkCandidatesForOptimizationFromBytecode(); + isolate->tiering_manager()->OnInterruptTickFromBytecode(); } } } // namespace @@ -427,8 +426,7 @@ RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterruptFromCode) { FeedbackVector::SetInterruptBudget(*feedback_cell); SealHandleScope shs(isolate); - isolate->counters()->runtime_profiler_ticks()->Increment(); - isolate->runtime_profiler()->MarkCandidatesForOptimizationFromCode(); + isolate->tiering_manager()->OnInterruptTickFromCode(); return ReadOnlyRoots(isolate).undefined_value(); } diff --git a/src/runtime/runtime-test.cc b/src/runtime/runtime-test.cc index 72770b289d..659f52e1e2 100644 --- a/src/runtime/runtime-test.cc +++ b/src/runtime/runtime-test.cc @@ -20,7 +20,7 @@ #include "src/execution/frames-inl.h" #include "src/execution/isolate-inl.h" #include "src/execution/protectors-inl.h" -#include "src/execution/runtime-profiler.h" +#include "src/execution/tiering-manager.h" #include "src/heap/heap-inl.h" // For ToBoolean. TODO(jkummerow): Drop. #include "src/heap/heap-write-barrier-inl.h" #include "src/ic/stub-cache.h" @@ -514,7 +514,7 @@ RUNTIME_FUNCTION(Runtime_OptimizeOsr) { // Make the profiler arm all back edges in unoptimized code. if (it.frame()->is_unoptimized()) { - isolate->runtime_profiler()->AttemptOnStackReplacement( + isolate->tiering_manager()->AttemptOnStackReplacement( UnoptimizedFrame::cast(it.frame()), AbstractCode::kMaxLoopNestingMarker); }