Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 1 | /* |
| 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 Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 17 | #ifndef ART_COMPILER_COMPILER_H_ |
| 18 | #define ART_COMPILER_COMPILER_H_ |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 19 | |
David Sehr | 7f01971 | 2016-10-26 16:09:13 -0700 | [diff] [blame] | 20 | #include "base/mutex.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 21 | #include "base/os.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 22 | #include "dex/dex_file.h" |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 26 | namespace jit { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 27 | class JitCodeCache; |
| 28 | class JitLogger; |
Andreas Gampe | deae7db | 2017-05-30 09:56:41 -0700 | [diff] [blame] | 29 | } // namespace jit |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 30 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 31 | class ClassLoader; |
| 32 | class DexCache; |
Andreas Gampe | deae7db | 2017-05-30 09:56:41 -0700 | [diff] [blame] | 33 | } // namespace mirror |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 34 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 35 | class ArtMethod; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 36 | class CompilerDriver; |
| 37 | class CompiledMethod; |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 38 | template<class T> class Handle; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 39 | class OatWriter; |
David Sehr | 7f01971 | 2016-10-26 16:09:13 -0700 | [diff] [blame] | 40 | class Thread; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 41 | |
Nicolas Geoffray | 66ff8a8 | 2018-02-28 13:27:55 +0000 | [diff] [blame] | 42 | enum class CopyOption { |
| 43 | kNever, |
| 44 | kAlways, |
| 45 | kOnlyIfCompressed |
| 46 | }; |
| 47 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 48 | class Compiler { |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 49 | public: |
| 50 | enum Kind { |
| 51 | kQuick, |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 52 | kOptimizing |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 55 | static Compiler* Create(CompilerDriver* driver, Kind kind); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 56 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 57 | virtual void Init() = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 58 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 59 | virtual void UnInit() const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 60 | |
Vladimir Marko | df73984 | 2016-03-23 16:59:07 +0000 | [diff] [blame] | 61 | virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0; |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 62 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 63 | virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 64 | uint32_t access_flags, |
| 65 | InvokeType invoke_type, |
| 66 | uint16_t class_def_idx, |
| 67 | uint32_t method_idx, |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 68 | Handle<mirror::ClassLoader> class_loader, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 69 | const DexFile& dex_file, |
| 70 | Handle<mirror::DexCache> dex_cache) const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 71 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 72 | virtual CompiledMethod* JniCompile(uint32_t access_flags, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 73 | uint32_t method_idx, |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 74 | const DexFile& dex_file, |
| 75 | Handle<mirror::DexCache> dex_cache) const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 76 | |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 77 | virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED, |
| 78 | jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 79 | ArtMethod* method ATTRIBUTE_UNUSED, |
Nicolas Geoffray | 01db5f7 | 2017-07-19 15:05:49 +0100 | [diff] [blame] | 80 | bool osr ATTRIBUTE_UNUSED, |
| 81 | jit::JitLogger* jit_logger ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 82 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 83 | return false; |
| 84 | } |
| 85 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 86 | virtual uintptr_t GetEntryPointOf(ArtMethod* method) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 87 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 88 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 89 | uint64_t GetMaximumCompilationTimeBeforeWarning() const { |
| 90 | return maximum_compilation_time_before_warning_; |
| 91 | } |
| 92 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 93 | virtual ~Compiler() {} |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 94 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 95 | /* |
| 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 Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 103 | virtual std::vector<uint8_t>* GetCallFrameInformationInitialization( |
| 104 | const CompilerDriver& driver ATTRIBUTE_UNUSED) const { |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 105 | return nullptr; |
| 106 | } |
| 107 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 108 | // 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 Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 114 | protected: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 115 | Compiler(CompilerDriver* driver, uint64_t warning) : |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 116 | driver_(driver), maximum_compilation_time_before_warning_(warning) { |
| 117 | } |
| 118 | |
| 119 | CompilerDriver* GetCompilerDriver() const { |
| 120 | return driver_; |
| 121 | } |
| 122 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 123 | private: |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 124 | CompilerDriver* const driver_; |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 125 | const uint64_t maximum_compilation_time_before_warning_; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 126 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 127 | DISALLOW_COPY_AND_ASSIGN(Compiler); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | } // namespace art |
| 131 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 132 | #endif // ART_COMPILER_COMPILER_H_ |