blob: b80015feca71268291e32cd93c088107aa3e162c [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
22#include "instrumentation.h"
23
24#include "atomic.h"
25#include "base/macros.h"
26#include "base/mutex.h"
27#include "gc_root.h"
28#include "jni.h"
29#include "object_callbacks.h"
30#include "thread_pool.h"
31
32namespace art {
33
34class 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);
50 bool CompileMethod(mirror::ArtMethod* method, Thread* self)
51 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();
64
65 private:
66 Jit();
67 bool LoadCompiler(std::string* error_msg);
68
69 // JIT compiler
70 void* jit_library_handle_;
71 void* jit_compiler_handle_;
72 void* (*jit_load_)(CompilerCallbacks**);
73 void (*jit_unload_)(void*);
74 bool (*jit_compile_method_)(void*, mirror::ArtMethod*, Thread*);
75
76 std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_;
77 std::unique_ptr<jit::JitCodeCache> code_cache_;
78 CompilerCallbacks* compiler_callbacks_; // Owned by the jit compiler.
79};
80
81class JitOptions {
82 public:
83 static JitOptions* CreateFromRuntimeArguments(const RuntimeArgumentMap& options);
84 size_t GetCompileThreshold() const {
85 return compile_threshold_;
86 }
87 size_t GetCodeCacheCapacity() const {
88 return code_cache_capacity_;
89 }
90
91 private:
92 size_t code_cache_capacity_;
93 size_t compile_threshold_;
94
95 JitOptions() : code_cache_capacity_(0), compile_threshold_(0) {
96 }
97};
98
99} // namespace jit
100} // namespace art
101
102#endif // ART_RUNTIME_JIT_JIT_H_