blob: dbd8977d9132a08d3e270bbe1c1c7b0e0052d166 [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;
46 static constexpr size_t kDefaultCompileThreshold = kStressMode ? 1 : 1000;
47
48 virtual ~Jit();
49 static Jit* Create(JitOptions* options, std::string* error_msg);
Mathieu Chartiere401d142015-04-22 13:56:20 -070050 bool CompileMethod(ArtMethod* method, Thread* self)
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080051 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
52 void CreateInstrumentationCache(size_t compile_threshold);
53 void CreateThreadPool();
54 CompilerCallbacks* GetCompilerCallbacks() {
55 return compiler_callbacks_;
56 }
57 const JitCodeCache* GetCodeCache() const {
58 return code_cache_.get();
59 }
60 JitCodeCache* GetCodeCache() {
61 return code_cache_.get();
62 }
63 void DeleteThreadPool();
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070064 // Dump interesting info: #methods compiled, code vs data size, compile / verify cumulative
65 // loggers.
66 void DumpInfo(std::ostream& os);
67 // Add a timing logger to cumulative_timings_.
68 void AddTimingLogger(const TimingLogger& logger);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080069
70 private:
71 Jit();
72 bool LoadCompiler(std::string* error_msg);
73
74 // JIT compiler
75 void* jit_library_handle_;
76 void* jit_compiler_handle_;
77 void* (*jit_load_)(CompilerCallbacks**);
78 void (*jit_unload_)(void*);
Mathieu Chartiere401d142015-04-22 13:56:20 -070079 bool (*jit_compile_method_)(void*, ArtMethod*, Thread*);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080080
Mathieu Chartiera4885cb2015-03-09 15:38:54 -070081 // Performance monitoring.
82 bool dump_info_on_shutdown_;
83 CumulativeLogger cumulative_timings_;
84
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080085 std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_;
86 std::unique_ptr<jit::JitCodeCache> code_cache_;
87 CompilerCallbacks* compiler_callbacks_; // Owned by the jit compiler.
Mathieu Chartier3130cdf2015-05-03 15:20:23 -070088
89 DISALLOW_COPY_AND_ASSIGN(Jit);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080090};
91
92class JitOptions {
93 public:
94 static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options);
95 size_t GetCompileThreshold() const {
96 return compile_threshold_;
97 }
98 size_t GetCodeCacheCapacity() const {
99 return code_cache_capacity_;
100 }
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700101 bool DumpJitInfoOnShutdown() const {
102 return dump_info_on_shutdown_;
103 }
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700104 bool UseJIT() const {
105 return use_jit_;
106 }
107 void SetUseJIT(bool b) {
108 use_jit_ = b;
109 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800110
111 private:
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700112 bool use_jit_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800113 size_t code_cache_capacity_;
114 size_t compile_threshold_;
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700115 bool dump_info_on_shutdown_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800116
Mathieu Chartier455f67c2015-03-17 13:48:29 -0700117 JitOptions() : use_jit_(false), code_cache_capacity_(0), compile_threshold_(0),
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700118 dump_info_on_shutdown_(false) { }
119
120 DISALLOW_COPY_AND_ASSIGN(JitOptions);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800121};
122
123} // namespace jit
124} // namespace art
125
126#endif // ART_RUNTIME_JIT_JIT_H_