• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_EXECUTION_TIERING_MANAGER_H_
6 #define V8_EXECUTION_TIERING_MANAGER_H_
7 
8 #include "src/common/assert-scope.h"
9 #include "src/handles/handles.h"
10 #include "src/utils/allocation.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class BytecodeArray;
16 class Isolate;
17 class UnoptimizedFrame;
18 class JavaScriptFrame;
19 class JSFunction;
20 class OptimizationDecision;
21 enum class CodeKind : uint8_t;
22 enum class OptimizationReason : uint8_t;
23 
24 void TraceManualRecompile(JSFunction function, CodeKind code_kind,
25                           ConcurrencyMode concurrency_mode);
26 
27 class TieringManager {
28  public:
TieringManager(Isolate * isolate)29   explicit TieringManager(Isolate* isolate) : isolate_(isolate) {}
30 
31   void OnInterruptTick(Handle<JSFunction> function);
32 
NotifyICChanged()33   void NotifyICChanged() { any_ic_changed_ = true; }
34 
35   // After this request, the next JumpLoop will perform OSR.
36   void RequestOsrAtNextOpportunity(JSFunction function);
37 
38   // For use when a JSFunction is available.
39   static int InterruptBudgetFor(Isolate* isolate, JSFunction function);
40   // For use when no JSFunction is available.
41   static int InitialInterruptBudget();
42 
43  private:
44   // Make the decision whether to optimize the given function, and mark it for
45   // optimization if the decision was 'yes'.
46   // This function is also responsible for bumping the OSR urgency.
47   void MaybeOptimizeFrame(JSFunction function, UnoptimizedFrame* frame,
48                           CodeKind code_kind);
49 
50   OptimizationDecision ShouldOptimize(JSFunction function, CodeKind code_kind,
51                                       JavaScriptFrame* frame);
52   void Optimize(JSFunction function, CodeKind code_kind,
53                 OptimizationDecision decision);
54   void Baseline(JSFunction function, OptimizationReason reason);
55 
56   class V8_NODISCARD OnInterruptTickScope final {
57    public:
58     explicit OnInterruptTickScope(TieringManager* profiler);
59     ~OnInterruptTickScope();
60 
61    private:
62     TieringManager* const profiler_;
63     DisallowGarbageCollection no_gc;
64   };
65 
66   Isolate* const isolate_;
67   bool any_ic_changed_ = false;
68 };
69 
70 }  // namespace internal
71 }  // namespace v8
72 
73 #endif  // V8_EXECUTION_TIERING_MANAGER_H_
74