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_RUNTIME_PROFILER_H_ 6 #define V8_EXECUTION_RUNTIME_PROFILER_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 InterpretedFrame; 18 class JavaScriptFrame; 19 class JSFunction; 20 enum class CodeKind; 21 enum class OptimizationReason : uint8_t; 22 23 class RuntimeProfiler { 24 public: 25 explicit RuntimeProfiler(Isolate* isolate); 26 27 // Called from the interpreter when the bytecode interrupt has been exhausted. 28 void MarkCandidatesForOptimizationFromBytecode(); 29 // Likewise, from generated code. 30 void MarkCandidatesForOptimizationFromCode(); 31 NotifyICChanged()32 void NotifyICChanged() { any_ic_changed_ = true; } 33 34 void AttemptOnStackReplacement(InterpretedFrame* frame, 35 int nesting_levels = 1); 36 37 private: 38 // Make the decision whether to optimize the given function, and mark it for 39 // optimization if the decision was 'yes'. 40 void MaybeOptimizeFrame(JSFunction function, JavaScriptFrame* frame, 41 CodeKind code_kind); 42 43 // Potentially attempts OSR from and returns whether no other 44 // optimization attempts should be made. 45 bool MaybeOSR(JSFunction function, InterpretedFrame* frame); 46 OptimizationReason ShouldOptimize(JSFunction function, 47 BytecodeArray bytecode_array); 48 void Optimize(JSFunction function, OptimizationReason reason, 49 CodeKind code_kind); 50 void Baseline(JSFunction function, OptimizationReason reason); 51 52 class MarkCandidatesForOptimizationScope final { 53 public: 54 explicit MarkCandidatesForOptimizationScope(RuntimeProfiler* profiler); 55 ~MarkCandidatesForOptimizationScope(); 56 57 private: 58 HandleScope handle_scope_; 59 RuntimeProfiler* const profiler_; 60 DisallowHeapAllocation no_gc; 61 }; 62 63 Isolate* isolate_; 64 bool any_ic_changed_; 65 }; 66 67 } // namespace internal 68 } // namespace v8 69 70 #endif // V8_EXECUTION_RUNTIME_PROFILER_H_ 71