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" |
| 29 | #include "thread_pool.h" |
| 30 | |
| 31 | namespace art { |
| 32 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | class ArtMethod; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 34 | class CompilerCallbacks; |
| 35 | struct RuntimeArgumentMap; |
| 36 | |
| 37 | namespace jit { |
| 38 | |
| 39 | class JitCodeCache; |
| 40 | class JitInstrumentationCache; |
| 41 | class JitOptions; |
| 42 | |
| 43 | class Jit { |
| 44 | public: |
| 45 | static constexpr bool kStressMode = kIsDebugBuild; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 46 | static constexpr size_t kDefaultCompileThreshold = kStressMode ? 2 : 1000; |
| 47 | static constexpr size_t kDefaultWarmupThreshold = kDefaultCompileThreshold / 2; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 48 | |
| 49 | virtual ~Jit(); |
| 50 | static Jit* Create(JitOptions* options, std::string* error_msg); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 51 | bool CompileMethod(ArtMethod* method, Thread* self) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 52 | SHARED_REQUIRES(Locks::mutator_lock_); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 53 | void CreateInstrumentationCache(size_t compile_threshold, size_t warmup_threshold); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 54 | void CreateThreadPool(); |
| 55 | CompilerCallbacks* GetCompilerCallbacks() { |
| 56 | return compiler_callbacks_; |
| 57 | } |
| 58 | const JitCodeCache* GetCodeCache() const { |
| 59 | return code_cache_.get(); |
| 60 | } |
| 61 | JitCodeCache* GetCodeCache() { |
| 62 | return code_cache_.get(); |
| 63 | } |
| 64 | void DeleteThreadPool(); |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 65 | // Dump interesting info: #methods compiled, code vs data size, compile / verify cumulative |
| 66 | // loggers. |
| 67 | void DumpInfo(std::ostream& os); |
| 68 | // Add a timing logger to cumulative_timings_. |
| 69 | void AddTimingLogger(const TimingLogger& logger); |
Mathieu Chartier | a50f9cf | 2015-09-25 11:34:45 -0700 | [diff] [blame] | 70 | JitInstrumentationCache* GetInstrumentationCache() const { |
| 71 | return instrumentation_cache_.get(); |
| 72 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 73 | |
| 74 | private: |
| 75 | Jit(); |
| 76 | bool LoadCompiler(std::string* error_msg); |
| 77 | |
| 78 | // JIT compiler |
| 79 | void* jit_library_handle_; |
| 80 | void* jit_compiler_handle_; |
| 81 | void* (*jit_load_)(CompilerCallbacks**); |
| 82 | void (*jit_unload_)(void*); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 83 | bool (*jit_compile_method_)(void*, ArtMethod*, Thread*); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 84 | |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 85 | // Performance monitoring. |
| 86 | bool dump_info_on_shutdown_; |
| 87 | CumulativeLogger cumulative_timings_; |
| 88 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 89 | std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_; |
| 90 | std::unique_ptr<jit::JitCodeCache> code_cache_; |
| 91 | CompilerCallbacks* compiler_callbacks_; // Owned by the jit compiler. |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 92 | |
| 93 | DISALLOW_COPY_AND_ASSIGN(Jit); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | class JitOptions { |
| 97 | public: |
| 98 | static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options); |
| 99 | size_t GetCompileThreshold() const { |
| 100 | return compile_threshold_; |
| 101 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 102 | size_t GetWarmupThreshold() const { |
| 103 | return warmup_threshold_; |
| 104 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 105 | size_t GetCodeCacheCapacity() const { |
| 106 | return code_cache_capacity_; |
| 107 | } |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 108 | bool DumpJitInfoOnShutdown() const { |
| 109 | return dump_info_on_shutdown_; |
| 110 | } |
Mathieu Chartier | 455f67c | 2015-03-17 13:48:29 -0700 | [diff] [blame] | 111 | bool UseJIT() const { |
| 112 | return use_jit_; |
| 113 | } |
| 114 | void SetUseJIT(bool b) { |
| 115 | use_jit_ = b; |
| 116 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 117 | |
| 118 | private: |
Mathieu Chartier | 455f67c | 2015-03-17 13:48:29 -0700 | [diff] [blame] | 119 | bool use_jit_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 120 | size_t code_cache_capacity_; |
| 121 | size_t compile_threshold_; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 122 | size_t warmup_threshold_; |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 123 | bool dump_info_on_shutdown_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 124 | |
Mathieu Chartier | 455f67c | 2015-03-17 13:48:29 -0700 | [diff] [blame] | 125 | JitOptions() : use_jit_(false), code_cache_capacity_(0), compile_threshold_(0), |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 126 | dump_info_on_shutdown_(false) { } |
| 127 | |
| 128 | DISALLOW_COPY_AND_ASSIGN(JitOptions); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | } // namespace jit |
| 132 | } // namespace art |
| 133 | |
| 134 | #endif // ART_RUNTIME_JIT_JIT_H_ |