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 | |
| 20 | #include "dex_file.h" |
| 21 | #include "os.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 25 | namespace jit { |
| 26 | class JitCodeCache; |
| 27 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame^] | 28 | namespace mirror { |
| 29 | class DexCache; |
| 30 | } |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 31 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 32 | class ArtMethod; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 33 | class CompilerDriver; |
| 34 | class CompiledMethod; |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame^] | 35 | template<class T> class Handle; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 36 | class OatWriter; |
| 37 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 38 | class Compiler { |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 39 | public: |
| 40 | enum Kind { |
| 41 | kQuick, |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 42 | kOptimizing |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 45 | enum JniOptimizationFlags { |
Igor Murashkin | 367f3dd | 2016-09-01 17:00:24 -0700 | [diff] [blame] | 46 | kNone = 0x0, |
| 47 | kFastNative = 0x1, |
| 48 | kCriticalNative = 0x2, |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 51 | static Compiler* Create(CompilerDriver* driver, Kind kind); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 52 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 53 | virtual void Init() = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 54 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 55 | virtual void UnInit() const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 56 | |
Vladimir Marko | df73984 | 2016-03-23 16:59:07 +0000 | [diff] [blame] | 57 | 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] | 58 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 59 | virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 60 | uint32_t access_flags, |
| 61 | InvokeType invoke_type, |
| 62 | uint16_t class_def_idx, |
| 63 | uint32_t method_idx, |
| 64 | jobject class_loader, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 65 | const DexFile& dex_file, |
| 66 | Handle<mirror::DexCache> dex_cache) const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 67 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 68 | virtual CompiledMethod* JniCompile(uint32_t access_flags, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 69 | uint32_t method_idx, |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 70 | const DexFile& dex_file, |
| 71 | JniOptimizationFlags optimization_flags) const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 72 | |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 73 | virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED, |
| 74 | jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 75 | ArtMethod* method ATTRIBUTE_UNUSED, |
| 76 | bool osr ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 77 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 78 | return false; |
| 79 | } |
| 80 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 81 | virtual uintptr_t GetEntryPointOf(ArtMethod* method) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 82 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 83 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 84 | uint64_t GetMaximumCompilationTimeBeforeWarning() const { |
| 85 | return maximum_compilation_time_before_warning_; |
| 86 | } |
| 87 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 88 | virtual ~Compiler() {} |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 89 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 90 | /* |
| 91 | * @brief Generate and return Dwarf CFI initialization, if supported by the |
| 92 | * backend. |
| 93 | * @param driver CompilerDriver for this compile. |
| 94 | * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF |
| 95 | * information. |
| 96 | * @note This is used for backtrace information in generated code. |
| 97 | */ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 98 | virtual std::vector<uint8_t>* GetCallFrameInformationInitialization( |
| 99 | const CompilerDriver& driver ATTRIBUTE_UNUSED) const { |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 100 | return nullptr; |
| 101 | } |
| 102 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 103 | // Returns whether the method to compile is such a pathological case that |
| 104 | // it's not worth compiling. |
| 105 | static bool IsPathologicalCase(const DexFile::CodeItem& code_item, |
| 106 | uint32_t method_idx, |
| 107 | const DexFile& dex_file); |
| 108 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 109 | protected: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 110 | Compiler(CompilerDriver* driver, uint64_t warning) : |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 111 | driver_(driver), maximum_compilation_time_before_warning_(warning) { |
| 112 | } |
| 113 | |
| 114 | CompilerDriver* GetCompilerDriver() const { |
| 115 | return driver_; |
| 116 | } |
| 117 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 118 | private: |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 119 | CompilerDriver* const driver_; |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 120 | const uint64_t maximum_compilation_time_before_warning_; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 121 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 122 | DISALLOW_COPY_AND_ASSIGN(Compiler); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // namespace art |
| 126 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 127 | #endif // ART_COMPILER_COMPILER_H_ |