blob: 8f924538662b7d5b8e95127098df0efc9557549d [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
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080022#include "atomic.h"
23#include "base/macros.h"
24#include "base/mutex.h"
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070025#include "base/timing_logger.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080026#include "gc_root.h"
27#include "jni.h"
28#include "object_callbacks.h"
29#include "thread_pool.h"
30
31namespace art {
32
33class CompilerCallbacks;
34struct RuntimeArgumentMap;
35
Vladimir Marko80afd022015-05-19 18:08:00 +010036namespace mirror {
37class ArtMethod;
38} // namespace mirror
39
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080040namespace jit {
41
42class JitCodeCache;
43class JitInstrumentationCache;
44class JitOptions;
45
46class Jit {
47 public:
48 static constexpr bool kStressMode = kIsDebugBuild;
49 static constexpr size_t kDefaultCompileThreshold = kStressMode ? 1 : 1000;
50
51 virtual ~Jit();
52 static Jit* Create(JitOptions* options, std::string* error_msg);
53 bool CompileMethod(mirror::ArtMethod* method, Thread* self)
54 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
55 void CreateInstrumentationCache(size_t compile_threshold);
56 void CreateThreadPool();
57 CompilerCallbacks* GetCompilerCallbacks() {
58 return compiler_callbacks_;
59 }
60 const JitCodeCache* GetCodeCache() const {
61 return code_cache_.get();
62 }
63 JitCodeCache* GetCodeCache() {
64 return code_cache_.get();
65 }
66 void DeleteThreadPool();
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070067 // Dump interesting info: #methods compiled, code vs data size, compile / verify cumulative
68 // loggers.
69 void DumpInfo(std::ostream& os);
70 // Add a timing logger to cumulative_timings_.
71 void AddTimingLogger(const TimingLogger& logger);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080072
73 private:
74 Jit();
75 bool LoadCompiler(std::string* error_msg);
76
77 // JIT compiler
78 void* jit_library_handle_;
79 void* jit_compiler_handle_;
80 void* (*jit_load_)(CompilerCallbacks**);
81 void (*jit_unload_)(void*);
82 bool (*jit_compile_method_)(void*, mirror::ArtMethod*, Thread*);
83
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070084 // Performance monitoring.
85 bool dump_info_on_shutdown_;
86 CumulativeLogger cumulative_timings_;
87
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080088 std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_;
89 std::unique_ptr<jit::JitCodeCache> code_cache_;
90 CompilerCallbacks* compiler_callbacks_; // Owned by the jit compiler.
Mathieu Chartier3130cdf2015-05-03 15:20:23 -070091
92 DISALLOW_COPY_AND_ASSIGN(Jit);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080093};
94
95class JitOptions {
96 public:
97 static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options);
98 size_t GetCompileThreshold() const {
99 return compile_threshold_;
100 }
101 size_t GetCodeCacheCapacity() const {
102 return code_cache_capacity_;
103 }
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700104 bool DumpJitInfoOnShutdown() const {
105 return dump_info_on_shutdown_;
106 }
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700107 bool UseJIT() const {
108 return use_jit_;
109 }
110 void SetUseJIT(bool b) {
111 use_jit_ = b;
112 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800113
114 private:
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700115 bool use_jit_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800116 size_t code_cache_capacity_;
117 size_t compile_threshold_;
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700118 bool dump_info_on_shutdown_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800119
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700120 JitOptions() : use_jit_(false), code_cache_capacity_(0), compile_threshold_(0),
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700121 dump_info_on_shutdown_(false) { }
122
123 DISALLOW_COPY_AND_ASSIGN(JitOptions);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800124};
125
126} // namespace jit
127} // namespace art
128
129#endif // ART_RUNTIME_JIT_JIT_H_