blob: 643bc23da397670f3dea42270cc2f4357433e2b2 [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 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*);
Mathieu Chartiere401d142015-04-22 13:56:20 -070080 bool (*jit_compile_method_)(void*, ArtMethod*, Thread*);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080081
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 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +010099 size_t GetWarmupThreshold() const {
100 return warmup_threshold_;
101 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800102 size_t GetCodeCacheCapacity() const {
103 return code_cache_capacity_;
104 }
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700105 bool DumpJitInfoOnShutdown() const {
106 return dump_info_on_shutdown_;
107 }
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700108 bool UseJIT() const {
109 return use_jit_;
110 }
111 void SetUseJIT(bool b) {
112 use_jit_ = b;
113 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800114
115 private:
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700116 bool use_jit_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800117 size_t code_cache_capacity_;
118 size_t compile_threshold_;
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100119 size_t warmup_threshold_;
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700120 bool dump_info_on_shutdown_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800121
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700122 JitOptions() : use_jit_(false), code_cache_capacity_(0), compile_threshold_(0),
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700123 dump_info_on_shutdown_(false) { }
124
125 DISALLOW_COPY_AND_ASSIGN(JitOptions);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800126};
127
128} // namespace jit
129} // namespace art
130
131#endif // ART_RUNTIME_JIT_JIT_H_