1 /* 2 * Copyright 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_JIT_JIT_OPTIONS_H_ 18 #define ART_RUNTIME_JIT_JIT_OPTIONS_H_ 19 20 #include "base/macros.h" 21 #include "base/runtime_debug.h" 22 #include "profile_saver_options.h" 23 24 namespace art HIDDEN { 25 26 struct RuntimeArgumentMap; 27 28 namespace jit { 29 30 // At what priority to schedule jit threads. 9 is the lowest foreground priority on device. 31 // See android/os/Process.java. 32 static constexpr int kJitPoolThreadPthreadDefaultPriority = 9; 33 // At what priority to schedule jit zygote threads compiling profiles in the background. 34 // 19 is the lowest background priority on device. 35 // See android/os/Process.java. 36 static constexpr int kJitZygotePoolThreadPthreadDefaultPriority = 19; 37 38 class JitOptions { 39 public: 40 DECLARE_RUNTIME_DEBUG_FLAG(kSlowMode); 41 42 static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options); 43 GetOptimizeThreshold()44 uint16_t GetOptimizeThreshold() const { 45 return optimize_threshold_; 46 } 47 GetWarmupThreshold()48 uint16_t GetWarmupThreshold() const { 49 return warmup_threshold_; 50 } 51 GetPriorityThreadWeight()52 uint16_t GetPriorityThreadWeight() const { 53 return priority_thread_weight_; 54 } 55 GetInvokeTransitionWeight()56 uint16_t GetInvokeTransitionWeight() const { 57 return invoke_transition_weight_; 58 } 59 GetCodeCacheInitialCapacity()60 size_t GetCodeCacheInitialCapacity() const { 61 return code_cache_initial_capacity_; 62 } 63 GetCodeCacheMaxCapacity()64 size_t GetCodeCacheMaxCapacity() const { 65 return code_cache_max_capacity_; 66 } 67 DumpJitInfoOnShutdown()68 bool DumpJitInfoOnShutdown() const { 69 return dump_info_on_shutdown_; 70 } 71 GetProfileSaverOptions()72 const ProfileSaverOptions& GetProfileSaverOptions() const { 73 return profile_saver_options_; 74 } 75 GetSaveProfilingInfo()76 bool GetSaveProfilingInfo() const { 77 return profile_saver_options_.IsEnabled(); 78 } 79 GetThreadPoolPthreadPriority()80 int GetThreadPoolPthreadPriority() const { 81 return thread_pool_pthread_priority_; 82 } 83 GetZygoteThreadPoolPthreadPriority()84 int GetZygoteThreadPoolPthreadPriority() const { 85 return zygote_thread_pool_pthread_priority_; 86 } 87 UseJitCompilation()88 bool UseJitCompilation() const { 89 return use_jit_compilation_; 90 } 91 UseProfiledJitCompilation()92 bool UseProfiledJitCompilation() const { 93 return use_profiled_jit_compilation_; 94 } 95 SetUseJitCompilation(bool b)96 void SetUseJitCompilation(bool b) { 97 use_jit_compilation_ = b; 98 } 99 SetSaveProfilingInfo(bool save_profiling_info)100 void SetSaveProfilingInfo(bool save_profiling_info) { 101 profile_saver_options_.SetEnabled(save_profiling_info); 102 } 103 SetWaitForJitNotificationsToSaveProfile(bool value)104 void SetWaitForJitNotificationsToSaveProfile(bool value) { 105 profile_saver_options_.SetWaitForJitNotificationsToSave(value); 106 } 107 SetJitAtFirstUse()108 void SetJitAtFirstUse() { 109 use_jit_compilation_ = true; 110 optimize_threshold_ = 0; 111 } 112 SetUseBaselineCompiler()113 void SetUseBaselineCompiler() { 114 use_baseline_compiler_ = true; 115 } 116 UseBaselineCompiler()117 bool UseBaselineCompiler() const { 118 return use_baseline_compiler_; 119 } 120 121 private: 122 // We add the sample in batches of size kJitSamplesBatchSize. 123 // This method rounds the threshold so that it is multiple of the batch size. 124 static uint32_t RoundUpThreshold(uint32_t threshold); 125 126 bool use_jit_compilation_; 127 bool use_profiled_jit_compilation_; 128 bool use_baseline_compiler_; 129 size_t code_cache_initial_capacity_; 130 size_t code_cache_max_capacity_; 131 uint32_t optimize_threshold_; 132 uint32_t warmup_threshold_; 133 uint16_t priority_thread_weight_; 134 uint16_t invoke_transition_weight_; 135 bool dump_info_on_shutdown_; 136 int thread_pool_pthread_priority_; 137 int zygote_thread_pool_pthread_priority_; 138 ProfileSaverOptions profile_saver_options_; 139 JitOptions()140 JitOptions() 141 : use_jit_compilation_(false), 142 use_profiled_jit_compilation_(false), 143 use_baseline_compiler_(false), 144 code_cache_initial_capacity_(0), 145 code_cache_max_capacity_(0), 146 optimize_threshold_(0), 147 warmup_threshold_(0), 148 priority_thread_weight_(0), 149 invoke_transition_weight_(0), 150 dump_info_on_shutdown_(false), 151 thread_pool_pthread_priority_(kJitPoolThreadPthreadDefaultPriority), 152 zygote_thread_pool_pthread_priority_(kJitZygotePoolThreadPthreadDefaultPriority) {} 153 154 DISALLOW_COPY_AND_ASSIGN(JitOptions); 155 }; 156 157 } // namespace jit 158 } // namespace art 159 160 #endif // ART_RUNTIME_JIT_JIT_OPTIONS_H_ 161