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 | |
Vladimir Marko | bdbee06 | 2022-11-16 12:44:15 +0000 | [diff] [blame] | 20 | #include "base/macros.h" |
David Sehr | 7f01971 | 2016-10-26 16:09:13 -0700 | [diff] [blame] | 21 | #include "base/mutex.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 22 | #include "base/os.h" |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 23 | #include "compilation_kind.h" |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 24 | #include "dex/invoke_type.h" |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 25 | |
Vladimir Marko | bdbee06 | 2022-11-16 12:44:15 +0000 | [diff] [blame] | 26 | namespace art HIDDEN { |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 27 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 28 | namespace dex { |
| 29 | struct CodeItem; |
| 30 | } // namespace dex |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 31 | namespace jit { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 32 | class JitCodeCache; |
| 33 | class JitLogger; |
Nicolas Geoffray | 7f7539b | 2019-06-06 16:20:54 +0100 | [diff] [blame] | 34 | class JitMemoryRegion; |
Andreas Gampe | deae7db | 2017-05-30 09:56:41 -0700 | [diff] [blame] | 35 | } // namespace jit |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 36 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 37 | class ClassLoader; |
| 38 | class DexCache; |
Andreas Gampe | deae7db | 2017-05-30 09:56:41 -0700 | [diff] [blame] | 39 | } // namespace mirror |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 40 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 41 | class ArtMethod; |
Vladimir Marko | d5a4319 | 2022-09-30 16:18:02 +0200 | [diff] [blame] | 42 | class CompiledCodeStorage; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 43 | class CompiledMethod; |
Vladimir Marko | 038924b | 2019-02-19 15:09:35 +0000 | [diff] [blame] | 44 | class CompilerOptions; |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 45 | class DexFile; |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 46 | template<class T> class Handle; |
David Sehr | 7f01971 | 2016-10-26 16:09:13 -0700 | [diff] [blame] | 47 | class Thread; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 48 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 49 | class Compiler { |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 50 | public: |
| 51 | enum Kind { |
| 52 | kQuick, |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 53 | kOptimizing |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Vladimir Marko | bdbee06 | 2022-11-16 12:44:15 +0000 | [diff] [blame] | 56 | EXPORT static Compiler* Create(const CompilerOptions& compiler_options, |
| 57 | CompiledCodeStorage* storage, |
| 58 | Kind kind); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 59 | |
Vladimir Marko | df73984 | 2016-03-23 16:59:07 +0000 | [diff] [blame] | 60 | 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] | 61 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 62 | virtual CompiledMethod* Compile(const dex::CodeItem* code_item, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 63 | uint32_t access_flags, |
| 64 | InvokeType invoke_type, |
| 65 | uint16_t class_def_idx, |
| 66 | uint32_t method_idx, |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 67 | Handle<mirror::ClassLoader> class_loader, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 68 | const DexFile& dex_file, |
| 69 | Handle<mirror::DexCache> dex_cache) const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 70 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 71 | virtual CompiledMethod* JniCompile(uint32_t access_flags, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 72 | uint32_t method_idx, |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 73 | const DexFile& dex_file, |
| 74 | Handle<mirror::DexCache> dex_cache) const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 75 | |
Nicolas Geoffray | d28b969 | 2015-11-04 14:36:55 +0000 | [diff] [blame] | 76 | virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED, |
| 77 | jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED, |
Nicolas Geoffray | 7f7539b | 2019-06-06 16:20:54 +0100 | [diff] [blame] | 78 | jit::JitMemoryRegion* region ATTRIBUTE_UNUSED, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 79 | ArtMethod* method ATTRIBUTE_UNUSED, |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 80 | CompilationKind compilation_kind ATTRIBUTE_UNUSED, |
Nicolas Geoffray | 01db5f7 | 2017-07-19 15:05:49 +0100 | [diff] [blame] | 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 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 95 | // Returns whether the method to compile is such a pathological case that |
| 96 | // it's not worth compiling. |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 97 | static bool IsPathologicalCase(const dex::CodeItem& code_item, |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 98 | uint32_t method_idx, |
| 99 | const DexFile& dex_file); |
| 100 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 101 | protected: |
Vladimir Marko | 038924b | 2019-02-19 15:09:35 +0000 | [diff] [blame] | 102 | Compiler(const CompilerOptions& compiler_options, |
Vladimir Marko | d5a4319 | 2022-09-30 16:18:02 +0200 | [diff] [blame] | 103 | CompiledCodeStorage* storage, |
Vladimir Marko | 038924b | 2019-02-19 15:09:35 +0000 | [diff] [blame] | 104 | uint64_t warning) : |
| 105 | compiler_options_(compiler_options), |
| 106 | storage_(storage), |
| 107 | maximum_compilation_time_before_warning_(warning) { |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Vladimir Marko | 038924b | 2019-02-19 15:09:35 +0000 | [diff] [blame] | 110 | const CompilerOptions& GetCompilerOptions() const { |
| 111 | return compiler_options_; |
| 112 | } |
| 113 | |
Vladimir Marko | d5a4319 | 2022-09-30 16:18:02 +0200 | [diff] [blame] | 114 | CompiledCodeStorage* GetCompiledCodeStorage() const { |
Vladimir Marko | 038924b | 2019-02-19 15:09:35 +0000 | [diff] [blame] | 115 | return storage_; |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 118 | private: |
Vladimir Marko | 038924b | 2019-02-19 15:09:35 +0000 | [diff] [blame] | 119 | const CompilerOptions& compiler_options_; |
Vladimir Marko | d5a4319 | 2022-09-30 16:18:02 +0200 | [diff] [blame] | 120 | CompiledCodeStorage* const storage_; |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 121 | const uint64_t maximum_compilation_time_before_warning_; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 122 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 123 | DISALLOW_COPY_AND_ASSIGN(Compiler); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace art |
| 127 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 128 | #endif // ART_COMPILER_COMPILER_H_ |