blob: c698cfc180f4d8c26d15b14682b5d7fded5e5509 [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
36namespace jit {
37
38class JitCodeCache;
39class JitInstrumentationCache;
40class JitOptions;
41
42class Jit {
43 public:
44 static constexpr bool kStressMode = kIsDebugBuild;
45 static constexpr size_t kDefaultCompileThreshold = kStressMode ? 1 : 1000;
46
47 virtual ~Jit();
48 static Jit* Create(JitOptions* options, std::string* error_msg);
49 bool CompileMethod(mirror::ArtMethod* method, Thread* self)
50 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
51 void CreateInstrumentationCache(size_t compile_threshold);
52 void CreateThreadPool();
53 CompilerCallbacks* GetCompilerCallbacks() {
54 return compiler_callbacks_;
55 }
56 const JitCodeCache* GetCodeCache() const {
57 return code_cache_.get();
58 }
59 JitCodeCache* GetCodeCache() {
60 return code_cache_.get();
61 }
62 void DeleteThreadPool();
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070063 // Dump interesting info: #methods compiled, code vs data size, compile / verify cumulative
64 // loggers.
65 void DumpInfo(std::ostream& os);
66 // Add a timing logger to cumulative_timings_.
67 void AddTimingLogger(const TimingLogger& logger);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080068
69 private:
70 Jit();
71 bool LoadCompiler(std::string* error_msg);
72
73 // JIT compiler
74 void* jit_library_handle_;
75 void* jit_compiler_handle_;
76 void* (*jit_load_)(CompilerCallbacks**);
77 void (*jit_unload_)(void*);
78 bool (*jit_compile_method_)(void*, mirror::ArtMethod*, Thread*);
79
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070080 // Performance monitoring.
81 bool dump_info_on_shutdown_;
82 CumulativeLogger cumulative_timings_;
83
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080084 std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_;
85 std::unique_ptr<jit::JitCodeCache> code_cache_;
86 CompilerCallbacks* compiler_callbacks_; // Owned by the jit compiler.
Mathieu Chartier3130cdf2015-05-03 15:20:23 -070087
88 DISALLOW_COPY_AND_ASSIGN(Jit);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080089};
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 }
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700100 bool DumpJitInfoOnShutdown() const {
101 return dump_info_on_shutdown_;
102 }
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700103 bool UseJIT() const {
104 return use_jit_;
105 }
106 void SetUseJIT(bool b) {
107 use_jit_ = b;
108 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800109
110 private:
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700111 bool use_jit_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800112 size_t code_cache_capacity_;
113 size_t compile_threshold_;
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700114 bool dump_info_on_shutdown_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800115
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700116 JitOptions() : use_jit_(false), code_cache_capacity_(0), compile_threshold_(0),
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700117 dump_info_on_shutdown_(false) { }
118
119 DISALLOW_COPY_AND_ASSIGN(JitOptions);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800120};
121
122} // namespace jit
123} // namespace art
124
125#endif // ART_RUNTIME_JIT_JIT_H_