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 | |
| 20 | #include <unordered_map> |
| 21 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 22 | #include "atomic.h" |
| 23 | #include "base/macros.h" |
| 24 | #include "base/mutex.h" |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 25 | #include "base/timing_logger.h" |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 26 | #include "gc_root.h" |
| 27 | #include "jni.h" |
| 28 | #include "object_callbacks.h" |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 29 | #include "offline_profiling_info.h" |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 30 | #include "thread_pool.h" |
| 31 | |
| 32 | namespace art { |
| 33 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 34 | class ArtMethod; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 35 | class CompilerCallbacks; |
| 36 | struct RuntimeArgumentMap; |
| 37 | |
| 38 | namespace jit { |
| 39 | |
| 40 | class JitCodeCache; |
| 41 | class JitInstrumentationCache; |
| 42 | class JitOptions; |
| 43 | |
| 44 | class Jit { |
| 45 | public: |
| 46 | static constexpr bool kStressMode = kIsDebugBuild; |
Nicolas Geoffray | 4e915fb | 2015-10-28 17:39:47 +0000 | [diff] [blame] | 47 | static constexpr size_t kDefaultCompileThreshold = kStressMode ? 2 : 500; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 48 | static constexpr size_t kDefaultWarmupThreshold = kDefaultCompileThreshold / 2; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 49 | |
| 50 | virtual ~Jit(); |
| 51 | static Jit* Create(JitOptions* options, std::string* error_msg); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 52 | bool CompileMethod(ArtMethod* method, Thread* self) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 53 | SHARED_REQUIRES(Locks::mutator_lock_); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 54 | void CreateInstrumentationCache(size_t compile_threshold, size_t warmup_threshold); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 55 | void CreateThreadPool(); |
| 56 | CompilerCallbacks* GetCompilerCallbacks() { |
| 57 | return compiler_callbacks_; |
| 58 | } |
| 59 | const JitCodeCache* GetCodeCache() const { |
| 60 | return code_cache_.get(); |
| 61 | } |
| 62 | JitCodeCache* GetCodeCache() { |
| 63 | return code_cache_.get(); |
| 64 | } |
| 65 | void DeleteThreadPool(); |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 66 | // Dump interesting info: #methods compiled, code vs data size, compile / verify cumulative |
| 67 | // loggers. |
| 68 | void DumpInfo(std::ostream& os); |
| 69 | // Add a timing logger to cumulative_timings_. |
| 70 | void AddTimingLogger(const TimingLogger& logger); |
Mathieu Chartier | a50f9cf | 2015-09-25 11:34:45 -0700 | [diff] [blame] | 71 | JitInstrumentationCache* GetInstrumentationCache() const { |
| 72 | return instrumentation_cache_.get(); |
| 73 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 74 | |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 75 | void StartProfileSaver(const std::string& filename, const std::vector<std::string>& code_paths); |
| 76 | void StopProfileSaver(); |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 77 | |
Nicolas Geoffray | aee2156 | 2015-12-15 16:39:44 +0000 | [diff] [blame] | 78 | void DumpForSigQuit(std::ostream& os) { |
| 79 | DumpInfo(os); |
| 80 | } |
| 81 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 82 | private: |
| 83 | Jit(); |
| 84 | bool LoadCompiler(std::string* error_msg); |
| 85 | |
| 86 | // JIT compiler |
| 87 | void* jit_library_handle_; |
| 88 | void* jit_compiler_handle_; |
Nicolas Geoffray | a25dce9 | 2016-01-12 16:41:10 +0000 | [diff] [blame] | 89 | void* (*jit_load_)(CompilerCallbacks**, bool*); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 90 | void (*jit_unload_)(void*); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 91 | bool (*jit_compile_method_)(void*, ArtMethod*, Thread*); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 92 | |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 93 | // Performance monitoring. |
| 94 | bool dump_info_on_shutdown_; |
| 95 | CumulativeLogger cumulative_timings_; |
| 96 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 97 | std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_; |
| 98 | std::unique_ptr<jit::JitCodeCache> code_cache_; |
| 99 | CompilerCallbacks* compiler_callbacks_; // Owned by the jit compiler. |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 100 | |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 101 | bool save_profiling_info_; |
Nicolas Geoffray | a25dce9 | 2016-01-12 16:41:10 +0000 | [diff] [blame] | 102 | bool generate_debug_info_; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 103 | |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(Jit); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | class JitOptions { |
| 108 | public: |
| 109 | static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options); |
| 110 | size_t GetCompileThreshold() const { |
| 111 | return compile_threshold_; |
| 112 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 113 | size_t GetWarmupThreshold() const { |
| 114 | return warmup_threshold_; |
| 115 | } |
Nicolas Geoffray | 0a3be16 | 2015-11-18 11:15:22 +0000 | [diff] [blame] | 116 | size_t GetCodeCacheInitialCapacity() const { |
| 117 | return code_cache_initial_capacity_; |
| 118 | } |
| 119 | size_t GetCodeCacheMaxCapacity() const { |
| 120 | return code_cache_max_capacity_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 121 | } |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 122 | bool DumpJitInfoOnShutdown() const { |
| 123 | return dump_info_on_shutdown_; |
| 124 | } |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 125 | bool GetSaveProfilingInfo() const { |
| 126 | return save_profiling_info_; |
| 127 | } |
Mathieu Chartier | 455f67c | 2015-03-17 13:48:29 -0700 | [diff] [blame] | 128 | bool UseJIT() const { |
| 129 | return use_jit_; |
| 130 | } |
| 131 | void SetUseJIT(bool b) { |
| 132 | use_jit_ = b; |
| 133 | } |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 134 | void SetSaveProfilingInfo(bool b) { |
| 135 | save_profiling_info_ = b; |
| 136 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 137 | |
| 138 | private: |
Mathieu Chartier | 455f67c | 2015-03-17 13:48:29 -0700 | [diff] [blame] | 139 | bool use_jit_; |
Nicolas Geoffray | 0a3be16 | 2015-11-18 11:15:22 +0000 | [diff] [blame] | 140 | size_t code_cache_initial_capacity_; |
| 141 | size_t code_cache_max_capacity_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 142 | size_t compile_threshold_; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 143 | size_t warmup_threshold_; |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 144 | bool dump_info_on_shutdown_; |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 145 | bool save_profiling_info_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 146 | |
Nicolas Geoffray | 0a3be16 | 2015-11-18 11:15:22 +0000 | [diff] [blame] | 147 | JitOptions() |
| 148 | : use_jit_(false), |
| 149 | code_cache_initial_capacity_(0), |
| 150 | code_cache_max_capacity_(0), |
| 151 | compile_threshold_(0), |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 152 | dump_info_on_shutdown_(false), |
| 153 | save_profiling_info_(false) { } |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 154 | |
| 155 | DISALLOW_COPY_AND_ASSIGN(JitOptions); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | } // namespace jit |
| 159 | } // namespace art |
| 160 | |
| 161 | #endif // ART_RUNTIME_JIT_JIT_H_ |