blob: f2ec3a9fa3b0d54287b477f3de762e0ccebd41ea [file] [log] [blame]
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +00001/*
2 * Copyright (C) 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
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000017#ifndef ART_COMPILER_COMPILER_H_
18#define ART_COMPILER_COMPILER_H_
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000019
David Sehr7f019712016-10-26 16:09:13 -070020#include "base/mutex.h"
David Sehrc431b9d2018-03-02 12:01:51 -080021#include "base/os.h"
David Sehr9e734c72018-01-04 17:56:19 -080022#include "dex/dex_file.h"
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000023
24namespace art {
25
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000026namespace jit {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080027class JitCodeCache;
28class JitLogger;
Andreas Gampedeae7db2017-05-30 09:56:41 -070029} // namespace jit
David Sehr9323e6e2016-09-13 08:58:35 -070030namespace mirror {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080031class ClassLoader;
32class DexCache;
Andreas Gampedeae7db2017-05-30 09:56:41 -070033} // namespace mirror
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000034
Mathieu Chartiere401d142015-04-22 13:56:20 -070035class ArtMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000036class CompilerDriver;
37class CompiledMethod;
David Sehr9323e6e2016-09-13 08:58:35 -070038template<class T> class Handle;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000039class OatWriter;
David Sehr7f019712016-10-26 16:09:13 -070040class Thread;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000041
Nicolas Geoffray66ff8a82018-02-28 13:27:55 +000042enum class CopyOption {
43 kNever,
44 kAlways,
45 kOnlyIfCompressed
46};
47
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000048class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000049 public:
50 enum Kind {
51 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080052 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000053 };
54
Ian Rogers72d32622014-05-06 16:20:11 -070055 static Compiler* Create(CompilerDriver* driver, Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000056
David Brazdilee690a32014-12-01 17:04:16 +000057 virtual void Init() = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000058
Ian Rogers72d32622014-05-06 16:20:11 -070059 virtual void UnInit() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000060
Vladimir Markodf739842016-03-23 16:59:07 +000061 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
Andreas Gampe53c913b2014-08-12 23:19:23 -070062
Ian Rogers72d32622014-05-06 16:20:11 -070063 virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000064 uint32_t access_flags,
65 InvokeType invoke_type,
66 uint16_t class_def_idx,
67 uint32_t method_idx,
Vladimir Marko8d6768d2017-03-14 10:13:21 +000068 Handle<mirror::ClassLoader> class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070069 const DexFile& dex_file,
70 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000071
Ian Rogers72d32622014-05-06 16:20:11 -070072 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000073 uint32_t method_idx,
Vladimir Marko92f7f3c2017-10-31 11:38:30 +000074 const DexFile& dex_file,
75 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000076
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000077 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED,
78 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +000079 ArtMethod* method ATTRIBUTE_UNUSED,
Nicolas Geoffray01db5f72017-07-19 15:05:49 +010080 bool osr ATTRIBUTE_UNUSED,
81 jit::JitLogger* jit_logger ATTRIBUTE_UNUSED)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070082 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000083 return false;
84 }
85
Mathieu Chartiere401d142015-04-22 13:56:20 -070086 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070087 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000088
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000089 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
90 return maximum_compilation_time_before_warning_;
91 }
92
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000093 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000094
Mark Mendellae9fd932014-02-10 16:14:35 -080095 /*
96 * @brief Generate and return Dwarf CFI initialization, if supported by the
97 * backend.
98 * @param driver CompilerDriver for this compile.
99 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
100 * information.
101 * @note This is used for backtrace information in generated code.
102 */
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100103 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(
104 const CompilerDriver& driver ATTRIBUTE_UNUSED) const {
Mark Mendellae9fd932014-02-10 16:14:35 -0800105 return nullptr;
106 }
107
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000108 // Returns whether the method to compile is such a pathological case that
109 // it's not worth compiling.
110 static bool IsPathologicalCase(const DexFile::CodeItem& code_item,
111 uint32_t method_idx,
112 const DexFile& dex_file);
113
Ian Rogers72d32622014-05-06 16:20:11 -0700114 protected:
Roland Levillain3887c462015-08-12 18:15:42 +0100115 Compiler(CompilerDriver* driver, uint64_t warning) :
Ian Rogers72d32622014-05-06 16:20:11 -0700116 driver_(driver), maximum_compilation_time_before_warning_(warning) {
117 }
118
119 CompilerDriver* GetCompilerDriver() const {
120 return driver_;
121 }
122
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000123 private:
Ian Rogers72d32622014-05-06 16:20:11 -0700124 CompilerDriver* const driver_;
Ian Rogers3d504072014-03-01 09:16:49 -0800125 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000126
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000127 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000128};
129
130} // namespace art
131
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000132#endif // ART_COMPILER_COMPILER_H_