jit.h revision a4885cbaafd35fe9c60eb6cd95e41e2c86f54f66
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 22#include "instrumentation.h" 23 24#include "atomic.h" 25#include "base/macros.h" 26#include "base/mutex.h" 27#include "base/timing_logger.h" 28#include "gc_root.h" 29#include "jni.h" 30#include "object_callbacks.h" 31#include "thread_pool.h" 32 33namespace art { 34 35class CompilerCallbacks; 36struct RuntimeArgumentMap; 37 38namespace jit { 39 40class JitCodeCache; 41class JitInstrumentationCache; 42class JitOptions; 43 44class Jit { 45 public: 46 static constexpr bool kStressMode = kIsDebugBuild; 47 static constexpr size_t kDefaultCompileThreshold = kStressMode ? 1 : 1000; 48 49 virtual ~Jit(); 50 static Jit* Create(JitOptions* options, std::string* error_msg); 51 bool CompileMethod(mirror::ArtMethod* method, Thread* self) 52 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 53 void CreateInstrumentationCache(size_t compile_threshold); 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(); 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); 70 71 private: 72 Jit(); 73 bool LoadCompiler(std::string* error_msg); 74 75 // JIT compiler 76 void* jit_library_handle_; 77 void* jit_compiler_handle_; 78 void* (*jit_load_)(CompilerCallbacks**); 79 void (*jit_unload_)(void*); 80 bool (*jit_compile_method_)(void*, mirror::ArtMethod*, Thread*); 81 82 // Performance monitoring. 83 bool dump_info_on_shutdown_; 84 CumulativeLogger cumulative_timings_; 85 86 std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_; 87 std::unique_ptr<jit::JitCodeCache> code_cache_; 88 CompilerCallbacks* compiler_callbacks_; // Owned by the jit compiler. 89}; 90 91class JitOptions { 92 public: 93 static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options); 94 size_t GetCompileThreshold() const { 95 return compile_threshold_; 96 } 97 size_t GetCodeCacheCapacity() const { 98 return code_cache_capacity_; 99 } 100 bool DumpJitInfoOnShutdown() const { 101 return dump_info_on_shutdown_; 102 } 103 104 private: 105 size_t code_cache_capacity_; 106 size_t compile_threshold_; 107 bool dump_info_on_shutdown_; 108 109 JitOptions() : code_cache_capacity_(0), compile_threshold_(0), dump_info_on_shutdown_(false) { 110 } 111}; 112 113} // namespace jit 114} // namespace art 115 116#endif // ART_RUNTIME_JIT_JIT_H_ 117