Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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_H_ |
| 18 | #define ART_RUNTIME_JIT_JIT_H_ |
| 19 | |
Nicolas Geoffray | a4f8154 | 2016-03-08 16:57:48 +0000 | [diff] [blame] | 20 | #include "base/histogram-inl.h" |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 21 | #include "base/macros.h" |
| 22 | #include "base/mutex.h" |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 23 | #include "base/timing_logger.h" |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 24 | #include "jit/profile_saver_options.h" |
| 25 | #include "obj_ptr.h" |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 26 | #include "thread_pool.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 30 | class ArtMethod; |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 31 | class ClassLinker; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 32 | struct RuntimeArgumentMap; |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 33 | union JValue; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 34 | |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 35 | namespace mirror { |
| 36 | class Object; |
| 37 | class Class; |
| 38 | } // namespace mirror |
| 39 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 40 | namespace jit { |
| 41 | |
| 42 | class JitCodeCache; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 43 | class JitOptions; |
| 44 | |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 45 | static constexpr int16_t kJitCheckForOSR = -1; |
| 46 | static constexpr int16_t kJitHotnessDisabled = -2; |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 47 | // At what priority to schedule jit threads. 9 is the lowest foreground priority on device. |
| 48 | // See android/os/Process.java. |
| 49 | static constexpr int kJitPoolThreadPthreadDefaultPriority = 9; |
David Srbecky | db94f2b | 2018-11-09 12:58:28 +0000 | [diff] [blame^] | 50 | static constexpr uint32_t kJitSamplesBatchSize = 32; // Must be power of 2. |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 51 | |
| 52 | class JitOptions { |
| 53 | public: |
| 54 | static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options); |
| 55 | |
| 56 | uint16_t GetCompileThreshold() const { |
| 57 | return compile_threshold_; |
| 58 | } |
| 59 | |
| 60 | uint16_t GetWarmupThreshold() const { |
| 61 | return warmup_threshold_; |
| 62 | } |
| 63 | |
| 64 | uint16_t GetOsrThreshold() const { |
| 65 | return osr_threshold_; |
| 66 | } |
| 67 | |
| 68 | uint16_t GetPriorityThreadWeight() const { |
| 69 | return priority_thread_weight_; |
| 70 | } |
| 71 | |
| 72 | uint16_t GetInvokeTransitionWeight() const { |
| 73 | return invoke_transition_weight_; |
| 74 | } |
| 75 | |
| 76 | size_t GetCodeCacheInitialCapacity() const { |
| 77 | return code_cache_initial_capacity_; |
| 78 | } |
| 79 | |
| 80 | size_t GetCodeCacheMaxCapacity() const { |
| 81 | return code_cache_max_capacity_; |
| 82 | } |
| 83 | |
| 84 | bool DumpJitInfoOnShutdown() const { |
| 85 | return dump_info_on_shutdown_; |
| 86 | } |
| 87 | |
| 88 | const ProfileSaverOptions& GetProfileSaverOptions() const { |
| 89 | return profile_saver_options_; |
| 90 | } |
| 91 | |
| 92 | bool GetSaveProfilingInfo() const { |
| 93 | return profile_saver_options_.IsEnabled(); |
| 94 | } |
| 95 | |
| 96 | int GetThreadPoolPthreadPriority() const { |
| 97 | return thread_pool_pthread_priority_; |
| 98 | } |
| 99 | |
| 100 | bool UseJitCompilation() const { |
| 101 | return use_jit_compilation_; |
| 102 | } |
| 103 | |
| 104 | void SetUseJitCompilation(bool b) { |
| 105 | use_jit_compilation_ = b; |
| 106 | } |
| 107 | |
| 108 | void SetSaveProfilingInfo(bool save_profiling_info) { |
| 109 | profile_saver_options_.SetEnabled(save_profiling_info); |
| 110 | } |
| 111 | |
| 112 | void SetWaitForJitNotificationsToSaveProfile(bool value) { |
| 113 | profile_saver_options_.SetWaitForJitNotificationsToSave(value); |
| 114 | } |
| 115 | |
| 116 | void SetProfileAOTCode(bool value) { |
| 117 | profile_saver_options_.SetProfileAOTCode(value); |
| 118 | } |
| 119 | |
| 120 | void SetJitAtFirstUse() { |
| 121 | use_jit_compilation_ = true; |
| 122 | compile_threshold_ = 0; |
| 123 | } |
| 124 | |
| 125 | private: |
| 126 | bool use_jit_compilation_; |
| 127 | size_t code_cache_initial_capacity_; |
| 128 | size_t code_cache_max_capacity_; |
| 129 | uint16_t compile_threshold_; |
| 130 | uint16_t warmup_threshold_; |
| 131 | uint16_t osr_threshold_; |
| 132 | uint16_t priority_thread_weight_; |
| 133 | uint16_t invoke_transition_weight_; |
| 134 | bool dump_info_on_shutdown_; |
| 135 | int thread_pool_pthread_priority_; |
| 136 | ProfileSaverOptions profile_saver_options_; |
| 137 | |
| 138 | JitOptions() |
| 139 | : use_jit_compilation_(false), |
| 140 | code_cache_initial_capacity_(0), |
| 141 | code_cache_max_capacity_(0), |
| 142 | compile_threshold_(0), |
| 143 | warmup_threshold_(0), |
| 144 | osr_threshold_(0), |
| 145 | priority_thread_weight_(0), |
| 146 | invoke_transition_weight_(0), |
| 147 | dump_info_on_shutdown_(false), |
Nicolas Geoffray | c9de61c | 2018-11-27 17:34:31 +0000 | [diff] [blame] | 148 | thread_pool_pthread_priority_(kJitPoolThreadPthreadDefaultPriority) {} |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(JitOptions); |
| 151 | }; |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 152 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 153 | class Jit { |
| 154 | public: |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 155 | static constexpr size_t kDefaultPriorityThreadWeightRatio = 1000; |
Nicolas Geoffray | bd553eb | 2016-04-28 13:56:04 +0100 | [diff] [blame] | 156 | static constexpr size_t kDefaultInvokeTransitionWeightRatio = 500; |
buzbee | 42a09cb0 | 2017-02-01 09:08:31 -0800 | [diff] [blame] | 157 | // How frequently should the interpreter check to see if OSR compilation is ready. |
| 158 | static constexpr int16_t kJitRecheckOSRThreshold = 100; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 159 | |
| 160 | virtual ~Jit(); |
Orion Hodson | ad28f5e | 2018-10-17 09:08:17 +0100 | [diff] [blame] | 161 | |
| 162 | // Create JIT itself. |
| 163 | static Jit* Create(JitCodeCache* code_cache, JitOptions* options); |
| 164 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 165 | bool CompileMethod(ArtMethod* method, Thread* self, bool osr) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 166 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 167 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 168 | const JitCodeCache* GetCodeCache() const { |
Orion Hodson | ad28f5e | 2018-10-17 09:08:17 +0100 | [diff] [blame] | 169 | return code_cache_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 170 | } |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 171 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 172 | JitCodeCache* GetCodeCache() { |
Orion Hodson | ad28f5e | 2018-10-17 09:08:17 +0100 | [diff] [blame] | 173 | return code_cache_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 174 | } |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 175 | |
Orion Hodson | ad28f5e | 2018-10-17 09:08:17 +0100 | [diff] [blame] | 176 | void CreateThreadPool(); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 177 | void DeleteThreadPool(); |
Orion Hodson | ad28f5e | 2018-10-17 09:08:17 +0100 | [diff] [blame] | 178 | |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 179 | // Dump interesting info: #methods compiled, code vs data size, compile / verify cumulative |
| 180 | // loggers. |
Nicolas Geoffray | a4f8154 | 2016-03-08 16:57:48 +0000 | [diff] [blame] | 181 | void DumpInfo(std::ostream& os) REQUIRES(!lock_); |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 182 | // Add a timing logger to cumulative_timings_. |
| 183 | void AddTimingLogger(const TimingLogger& logger); |
Nicolas Geoffray | a4f8154 | 2016-03-08 16:57:48 +0000 | [diff] [blame] | 184 | |
| 185 | void AddMemoryUsage(ArtMethod* method, size_t bytes) |
| 186 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 187 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | a4f8154 | 2016-03-08 16:57:48 +0000 | [diff] [blame] | 188 | |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 189 | uint16_t OSRMethodThreshold() const { |
| 190 | return options_->GetOsrThreshold(); |
Mathieu Chartier | a50f9cf | 2015-09-25 11:34:45 -0700 | [diff] [blame] | 191 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 192 | |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 193 | uint16_t HotMethodThreshold() const { |
| 194 | return options_->GetCompileThreshold(); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 197 | uint16_t WarmMethodThreshold() const { |
| 198 | return options_->GetWarmupThreshold(); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | uint16_t PriorityThreadWeight() const { |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 202 | return options_->GetPriorityThreadWeight(); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 205 | // Returns false if we only need to save profile information and not compile methods. |
| 206 | bool UseJitCompilation() const { |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 207 | return options_->UseJitCompilation(); |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 208 | } |
| 209 | |
Calin Juravle | 138dbff | 2016-06-28 19:36:58 +0100 | [diff] [blame] | 210 | bool GetSaveProfilingInfo() const { |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 211 | return options_->GetSaveProfilingInfo(); |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 212 | } |
| 213 | |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 214 | // Wait until there is no more pending compilation tasks. |
| 215 | void WaitForCompilationToFinish(Thread* self); |
| 216 | |
| 217 | // Profiling methods. |
| 218 | void MethodEntered(Thread* thread, ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 219 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 220 | |
David Srbecky | db94f2b | 2018-11-09 12:58:28 +0000 | [diff] [blame^] | 221 | ALWAYS_INLINE void AddSamples(Thread* self, |
| 222 | ArtMethod* method, |
| 223 | uint16_t samples, |
| 224 | bool with_backedges) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 225 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 226 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 227 | void InvokeVirtualOrInterface(ObjPtr<mirror::Object> this_object, |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 228 | ArtMethod* caller, |
| 229 | uint32_t dex_pc, |
| 230 | ArtMethod* callee) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 231 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 232 | |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 233 | void NotifyInterpreterToCompiledCodeTransition(Thread* self, ArtMethod* caller) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 234 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 235 | AddSamples(self, caller, options_->GetInvokeTransitionWeight(), false); |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void NotifyCompiledCodeToInterpreterTransition(Thread* self, ArtMethod* callee) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 239 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 240 | AddSamples(self, callee, options_->GetInvokeTransitionWeight(), false); |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Calin Juravle | c90bc92 | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 243 | // Starts the profile saver if the config options allow profile recording. |
| 244 | // The profile will be stored in the specified `filename` and will contain |
| 245 | // information collected from the given `code_paths` (a set of dex locations). |
Calin Juravle | c90bc92 | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 246 | void StartProfileSaver(const std::string& filename, |
Calin Juravle | 77651c4 | 2017-03-03 18:04:02 -0800 | [diff] [blame] | 247 | const std::vector<std::string>& code_paths); |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 248 | void StopProfileSaver(); |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 249 | |
Calin Juravle | b8e6999 | 2016-03-09 15:37:48 +0000 | [diff] [blame] | 250 | void DumpForSigQuit(std::ostream& os) REQUIRES(!lock_); |
Nicolas Geoffray | aee2156 | 2015-12-15 16:39:44 +0000 | [diff] [blame] | 251 | |
Tamas Berghammer | 160e6df | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 252 | static void NewTypeLoadedIfUsingJit(mirror::Class* type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 253 | REQUIRES_SHARED(Locks::mutator_lock_); |
Tamas Berghammer | 160e6df | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 254 | |
Tamas Berghammer | fffbee4 | 2016-01-15 13:09:34 +0000 | [diff] [blame] | 255 | // If debug info generation is turned on then write the type information for types already loaded |
| 256 | // into the specified class linker to the jit debug interface, |
| 257 | void DumpTypeInfoForLoadedTypes(ClassLinker* linker); |
| 258 | |
Nicolas Geoffray | 3512244 | 2016-03-02 12:05:30 +0000 | [diff] [blame] | 259 | // Return whether we should try to JIT compiled code as soon as an ArtMethod is invoked. |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 260 | bool JitAtFirstUse(); |
| 261 | |
Nicolas Geoffray | 3512244 | 2016-03-02 12:05:30 +0000 | [diff] [blame] | 262 | // Return whether we can invoke JIT code for `method`. |
| 263 | bool CanInvokeCompiledCode(ArtMethod* method); |
| 264 | |
Calin Juravle | b2771b4 | 2016-04-07 17:09:25 +0100 | [diff] [blame] | 265 | // Return whether the runtime should use a priority thread weight when sampling. |
Vladimir Marko | a710d91 | 2017-09-12 14:56:07 +0100 | [diff] [blame] | 266 | static bool ShouldUsePriorityThreadWeight(Thread* self); |
Calin Juravle | b2771b4 | 2016-04-07 17:09:25 +0100 | [diff] [blame] | 267 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 268 | // If an OSR compiled version is available for `method`, |
| 269 | // and `dex_pc + dex_pc_offset` is an entry point of that compiled |
| 270 | // version, this method will jump to the compiled code, let it run, |
| 271 | // and return true afterwards. Return false otherwise. |
| 272 | static bool MaybeDoOnStackReplacement(Thread* thread, |
| 273 | ArtMethod* method, |
| 274 | uint32_t dex_pc, |
| 275 | int32_t dex_pc_offset, |
| 276 | JValue* result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 277 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 278 | |
Nicolas Geoffray | a7edd0d | 2018-11-07 03:18:16 +0000 | [diff] [blame] | 279 | // Load the compiler library. |
| 280 | static bool LoadCompilerLibrary(std::string* error_msg); |
Mathieu Chartier | 72918ea | 2016-03-24 11:07:06 -0700 | [diff] [blame] | 281 | |
Andreas Gampe | f149b3f | 2016-11-16 14:58:24 -0800 | [diff] [blame] | 282 | ThreadPool* GetThreadPool() const { |
| 283 | return thread_pool_.get(); |
| 284 | } |
| 285 | |
Nicolas Geoffray | 021c5f2 | 2016-12-16 11:22:05 +0000 | [diff] [blame] | 286 | // Stop the JIT by waiting for all current compilations and enqueued compilations to finish. |
| 287 | void Stop(); |
| 288 | |
| 289 | // Start JIT threads. |
| 290 | void Start(); |
| 291 | |
Nicolas Geoffray | c9de61c | 2018-11-27 17:34:31 +0000 | [diff] [blame] | 292 | // Transition to a zygote child state. |
| 293 | void PostForkChildAction(); |
| 294 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 295 | private: |
Orion Hodson | ad28f5e | 2018-10-17 09:08:17 +0100 | [diff] [blame] | 296 | Jit(JitCodeCache* code_cache, JitOptions* options); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 297 | |
David Srbecky | db94f2b | 2018-11-09 12:58:28 +0000 | [diff] [blame^] | 298 | // Compile the method if the number of samples passes a threshold. |
| 299 | // Returns false if we can not compile now - don't increment the counter and retry later. |
| 300 | bool MaybeCompileMethod(Thread* self, |
| 301 | ArtMethod* method, |
| 302 | uint32_t old_count, |
| 303 | uint32_t new_count, |
| 304 | bool with_backedges) |
| 305 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 306 | |
Orion Hodson | ad28f5e | 2018-10-17 09:08:17 +0100 | [diff] [blame] | 307 | static bool BindCompilerMethods(std::string* error_msg); |
Mathieu Chartier | c1bc415 | 2016-03-24 17:22:52 -0700 | [diff] [blame] | 308 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 309 | // JIT compiler |
Mathieu Chartier | 72918ea | 2016-03-24 11:07:06 -0700 | [diff] [blame] | 310 | static void* jit_library_handle_; |
| 311 | static void* jit_compiler_handle_; |
Nicolas Geoffray | c9de61c | 2018-11-27 17:34:31 +0000 | [diff] [blame] | 312 | static void* (*jit_load_)(void); |
Mathieu Chartier | 72918ea | 2016-03-24 11:07:06 -0700 | [diff] [blame] | 313 | static void (*jit_unload_)(void*); |
| 314 | static bool (*jit_compile_method_)(void*, ArtMethod*, Thread*, bool); |
| 315 | static void (*jit_types_loaded_)(void*, mirror::Class**, size_t count); |
Nicolas Geoffray | c9de61c | 2018-11-27 17:34:31 +0000 | [diff] [blame] | 316 | static void (*jit_update_options_)(void*); |
| 317 | static bool (*jit_generate_debug_info_)(void*); |
| 318 | template <typename T> static bool LoadSymbol(T*, const char* symbol, std::string* error_msg); |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 319 | |
Orion Hodson | ad28f5e | 2018-10-17 09:08:17 +0100 | [diff] [blame] | 320 | // JIT resources owned by runtime. |
| 321 | jit::JitCodeCache* const code_cache_; |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 322 | const JitOptions* const options_; |
| 323 | |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 324 | std::unique_ptr<ThreadPool> thread_pool_; |
| 325 | |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 326 | // Performance monitoring. |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 327 | CumulativeLogger cumulative_timings_; |
Nicolas Geoffray | a4f8154 | 2016-03-08 16:57:48 +0000 | [diff] [blame] | 328 | Histogram<uint64_t> memory_use_ GUARDED_BY(lock_); |
| 329 | Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 330 | |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 331 | DISALLOW_COPY_AND_ASSIGN(Jit); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 332 | }; |
| 333 | |
Andreas Gampe | f149b3f | 2016-11-16 14:58:24 -0800 | [diff] [blame] | 334 | // Helper class to stop the JIT for a given scope. This will wait for the JIT to quiesce. |
| 335 | class ScopedJitSuspend { |
| 336 | public: |
| 337 | ScopedJitSuspend(); |
| 338 | ~ScopedJitSuspend(); |
| 339 | |
| 340 | private: |
| 341 | bool was_on_; |
| 342 | }; |
| 343 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 344 | } // namespace jit |
| 345 | } // namespace art |
| 346 | |
| 347 | #endif // ART_RUNTIME_JIT_JIT_H_ |