blob: f5ad8b837ce3381922ba0a50340c6b6be845763e [file] [log] [blame]
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001/*
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"
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070027#include "base/timing_logger.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080028#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();
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070065 // 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 Chartiere5f13e52015-02-24 09:37:21 -080070
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
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070082 // Performance monitoring.
83 bool dump_info_on_shutdown_;
84 CumulativeLogger cumulative_timings_;
85
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080086 std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_;
87 std::unique_ptr<jit::JitCodeCache> code_cache_;
88 CompilerCallbacks* compiler_callbacks_; // Owned by the jit compiler.
Mathieu Chartier3130cdf2015-05-03 15:20:23 -070089
90 DISALLOW_COPY_AND_ASSIGN(Jit);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080091};
92
93class JitOptions {
94 public:
95 static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options);
96 size_t GetCompileThreshold() const {
97 return compile_threshold_;
98 }
99 size_t GetCodeCacheCapacity() const {
100 return code_cache_capacity_;
101 }
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700102 bool DumpJitInfoOnShutdown() const {
103 return dump_info_on_shutdown_;
104 }
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700105 bool UseJIT() const {
106 return use_jit_;
107 }
108 void SetUseJIT(bool b) {
109 use_jit_ = b;
110 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800111
112 private:
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700113 bool use_jit_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800114 size_t code_cache_capacity_;
115 size_t compile_threshold_;
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700116 bool dump_info_on_shutdown_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800117
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700118 JitOptions() : use_jit_(false), code_cache_capacity_(0), compile_threshold_(0),
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700119 dump_info_on_shutdown_(false) { }
120
121 DISALLOW_COPY_AND_ASSIGN(JitOptions);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800122};
123
124} // namespace jit
125} // namespace art
126
127#endif // ART_RUNTIME_JIT_JIT_H_