blob: e73ba82278dcf792969f2d4c445d77e8a0d38f51 [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
Mathieu Chartiere401d142015-04-22 13:56:20 -070033class ArtMethod;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080034class CompilerCallbacks;
35struct RuntimeArgumentMap;
36
37namespace jit {
38
39class JitCodeCache;
40class JitInstrumentationCache;
41class JitOptions;
42
43class Jit {
44 public:
45 static constexpr bool kStressMode = kIsDebugBuild;
Nicolas Geoffray5550ca82015-08-21 18:38:30 +010046 static constexpr size_t kDefaultCompileThreshold = kStressMode ? 2 : 1000;
47 static constexpr size_t kDefaultWarmupThreshold = kDefaultCompileThreshold / 2;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080048
49 virtual ~Jit();
50 static Jit* Create(JitOptions* options, std::string* error_msg);
Mathieu Chartiere401d142015-04-22 13:56:20 -070051 bool CompileMethod(ArtMethod* method, Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070052 SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray5550ca82015-08-21 18:38:30 +010053 void CreateInstrumentationCache(size_t compile_threshold, size_t warmup_threshold);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080054 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 Chartiera50f9cf2015-09-25 11:34:45 -070070 JitInstrumentationCache* GetInstrumentationCache() const {
71 return instrumentation_cache_.get();
72 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080073
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 Chartiere401d142015-04-22 13:56:20 -070083 bool (*jit_compile_method_)(void*, ArtMethod*, Thread*);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080084
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070085 // Performance monitoring.
86 bool dump_info_on_shutdown_;
87 CumulativeLogger cumulative_timings_;
88
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080089 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 Chartier3130cdf2015-05-03 15:20:23 -070092
93 DISALLOW_COPY_AND_ASSIGN(Jit);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080094};
95
96class JitOptions {
97 public:
98 static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options);
99 size_t GetCompileThreshold() const {
100 return compile_threshold_;
101 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100102 size_t GetWarmupThreshold() const {
103 return warmup_threshold_;
104 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800105 size_t GetCodeCacheCapacity() const {
106 return code_cache_capacity_;
107 }
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700108 bool DumpJitInfoOnShutdown() const {
109 return dump_info_on_shutdown_;
110 }
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700111 bool UseJIT() const {
112 return use_jit_;
113 }
114 void SetUseJIT(bool b) {
115 use_jit_ = b;
116 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800117
118 private:
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700119 bool use_jit_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800120 size_t code_cache_capacity_;
121 size_t compile_threshold_;
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100122 size_t warmup_threshold_;
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700123 bool dump_info_on_shutdown_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800124
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700125 JitOptions() : use_jit_(false), code_cache_capacity_(0), compile_threshold_(0),
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700126 dump_info_on_shutdown_(false) { }
127
128 DISALLOW_COPY_AND_ASSIGN(JitOptions);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800129};
130
131} // namespace jit
132} // namespace art
133
134#endif // ART_RUNTIME_JIT_JIT_H_