Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ |
| 18 | #define ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 19 | |
Andreas Gampe | f39208f | 2017-10-19 15:06:59 -0700 | [diff] [blame] | 20 | #include <atomic> |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 21 | #include <set> |
| 22 | #include <string> |
Logan Chien | df57614 | 2012-03-20 17:36:32 +0800 | [diff] [blame] | 23 | #include <vector> |
Elliott Hughes | e5448b5 | 2012-01-18 16:44:06 -0800 | [diff] [blame] | 24 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 25 | #include "android-base/strings.h" |
| 26 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 27 | #include "arch/instruction_set.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 28 | #include "base/array_ref.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 29 | #include "base/bit_utils.h" |
Vladimir Marko | 54159c6 | 2018-06-20 14:30:08 +0100 | [diff] [blame] | 30 | #include "base/hash_set.h" |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 31 | #include "base/mutex.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 32 | #include "base/os.h" |
| 33 | #include "base/quasi_atomic.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 34 | #include "base/safe_map.h" |
Nicolas Geoffray | ea3fa0b | 2014-02-10 11:59:41 +0000 | [diff] [blame] | 35 | #include "base/timing_logger.h" |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 36 | #include "class_status.h" |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 37 | #include "compiler.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 38 | #include "dex/class_reference.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 39 | #include "dex/dex_file_types.h" |
Mathieu Chartier | a79efdb | 2018-01-18 16:31:01 -0800 | [diff] [blame] | 40 | #include "dex/dex_to_dex_compiler.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 41 | #include "dex/method_reference.h" |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 42 | #include "driver/compiled_method_storage.h" |
Mathieu Chartier | 0e4627e | 2012-10-23 16:13:36 -0700 | [diff] [blame] | 43 | #include "thread_pool.h" |
Mathieu Chartier | 93764b8 | 2017-07-17 14:51:53 -0700 | [diff] [blame] | 44 | #include "utils/atomic_dex_ref_map.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 45 | #include "utils/dex_cache_arrays_layout.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 46 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 47 | namespace art { |
| 48 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame^] | 49 | namespace dex { |
| 50 | struct CodeItem; |
| 51 | } // namespace dex |
| 52 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 53 | namespace mirror { |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 54 | class Class; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 55 | class DexCache; |
| 56 | } // namespace mirror |
| 57 | |
Vladimir Marko | 2bc4780 | 2014-02-10 09:43:07 +0000 | [diff] [blame] | 58 | namespace verifier { |
| 59 | class MethodVerifier; |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 60 | class VerifierDepsTest; |
Vladimir Marko | 2bc4780 | 2014-02-10 09:43:07 +0000 | [diff] [blame] | 61 | } // namespace verifier |
| 62 | |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 63 | class ArtField; |
Vladimir Marko | 492a7fa | 2016-06-01 18:38:43 +0100 | [diff] [blame] | 64 | class BitVector; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 65 | class CompiledMethod; |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 66 | class CompilerOptions; |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 67 | class DexCompilationUnit; |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame^] | 68 | class DexFile; |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 69 | template<class T> class Handle; |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 70 | struct InlineIGetIPutData; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 71 | class InstructionSetFeatures; |
Andreas Gampe | d482e73 | 2017-04-24 17:59:09 -0700 | [diff] [blame] | 72 | class InternTable; |
Andreas Gampe | 04c6ab9 | 2017-06-08 21:49:14 -0700 | [diff] [blame] | 73 | enum InvokeType : uint32_t; |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 74 | class MemberOffset; |
| 75 | template<class MirrorType> class ObjPtr; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 76 | class ParallelCompilationManager; |
Andreas Gampe | 3913e48 | 2018-01-22 18:58:01 -0800 | [diff] [blame] | 77 | class ProfileCompilationInfo; |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 78 | class ScopedObjectAccess; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 79 | template <class Allocator> class SrcMap; |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 80 | class TimingLogger; |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 81 | class VdexFile; |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 82 | class VerificationResults; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 83 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 84 | enum EntryPointCallingConvention { |
| 85 | // ABI of invocations to a method's interpreter entry point. |
| 86 | kInterpreterAbi, |
| 87 | // ABI of calls to a method's native code, only used for native methods. |
| 88 | kJniAbi, |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 89 | // ABI of calls to a method's quick code entry point. |
| 90 | kQuickAbi |
| 91 | }; |
| 92 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 93 | class CompilerDriver { |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 94 | public: |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 95 | // Create a compiler targeting the requested "instruction_set". |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 96 | // "image" should be true if image specific optimizations should be |
| 97 | // enabled. "image_classes" lets the compiler know what classes it |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 98 | // can assume will be in the image, with null implying all available |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 99 | // classes. |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 100 | CompilerDriver(const CompilerOptions* compiler_options, |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 101 | Compiler::Kind compiler_kind, |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 102 | size_t thread_count, |
Vladimir Marko | 1a2a5cd | 2018-11-07 15:39:48 +0000 | [diff] [blame] | 103 | int swap_fd); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 104 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 105 | ~CompilerDriver(); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 106 | |
Nicolas Geoffray | c4204a3 | 2017-09-18 14:03:45 +0100 | [diff] [blame] | 107 | // Set dex files classpath. |
Nicolas Geoffray | 486dda0 | 2017-09-11 14:15:52 +0100 | [diff] [blame] | 108 | void SetClasspathDexFiles(const std::vector<const DexFile*>& dex_files); |
Vladimir Marko | d1eaf0d | 2015-10-29 12:18:29 +0000 | [diff] [blame] | 109 | |
Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 110 | // Initialize and destroy thread pools. This is exposed because we do not want |
| 111 | // to do this twice, for PreCompile() and CompileAll(). |
| 112 | void InitializeThreadPools(); |
| 113 | void FreeThreadPools(); |
| 114 | |
| 115 | void PreCompile(jobject class_loader, |
| 116 | const std::vector<const DexFile*>& dex_files, |
| 117 | TimingLogger* timings, |
| 118 | /*inout*/ HashSet<std::string>* image_classes, |
| 119 | /*out*/ VerificationResults* verification_results) |
| 120 | REQUIRES(!Locks::mutator_lock_); |
Vladimir Marko | d1eaf0d | 2015-10-29 12:18:29 +0000 | [diff] [blame] | 121 | void CompileAll(jobject class_loader, |
| 122 | const std::vector<const DexFile*>& dex_files, |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 123 | TimingLogger* timings) |
Mathieu Chartier | a79efdb | 2018-01-18 16:31:01 -0800 | [diff] [blame] | 124 | REQUIRES(!Locks::mutator_lock_); |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 125 | |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 126 | // Compile a single Method. (For testing only.) |
| 127 | void CompileOne(Thread* self, |
| 128 | jobject class_loader, |
| 129 | const DexFile& dex_file, |
| 130 | uint16_t class_def_idx, |
| 131 | uint32_t method_idx, |
| 132 | uint32_t access_flags, |
| 133 | InvokeType invoke_type, |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame^] | 134 | const dex::CodeItem* code_item, |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 135 | Handle<mirror::DexCache> dex_cache, |
| 136 | Handle<mirror::ClassLoader> h_class_loader) |
| 137 | REQUIRES(!Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 138 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 139 | const CompilerOptions& GetCompilerOptions() const { |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 140 | return *compiler_options_; |
| 141 | } |
| 142 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 143 | Compiler* GetCompiler() const { |
| 144 | return compiler_.get(); |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 147 | // Generate the trampolines that are invoked by unresolved direct methods. |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 148 | std::unique_ptr<const std::vector<uint8_t>> CreateJniDlsymLookup() const; |
| 149 | std::unique_ptr<const std::vector<uint8_t>> CreateQuickGenericJniTrampoline() const; |
| 150 | std::unique_ptr<const std::vector<uint8_t>> CreateQuickImtConflictTrampoline() const; |
| 151 | std::unique_ptr<const std::vector<uint8_t>> CreateQuickResolutionTrampoline() const; |
| 152 | std::unique_ptr<const std::vector<uint8_t>> CreateQuickToInterpreterBridge() const; |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 153 | |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 154 | ClassStatus GetClassStatus(const ClassReference& ref) const; |
| 155 | bool GetCompiledClass(const ClassReference& ref, ClassStatus* status) const; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 156 | |
Mathieu Chartier | acab8d4 | 2016-11-23 13:45:58 -0800 | [diff] [blame] | 157 | CompiledMethod* GetCompiledMethod(MethodReference ref) const; |
Andreas Gampe | 5eb0d38 | 2015-07-23 01:19:26 -0700 | [diff] [blame] | 158 | // Add a compiled method. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 159 | void AddCompiledMethod(const MethodReference& method_ref, CompiledMethod* const compiled_method); |
Mathieu Chartier | 279e3a3 | 2018-01-24 18:17:55 -0800 | [diff] [blame] | 160 | CompiledMethod* RemoveCompiledMethod(const MethodReference& method_ref); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 161 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 162 | // Resolve compiling method's class. Returns null on failure. |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 163 | ObjPtr<mirror::Class> ResolveCompilingMethodsClass(const ScopedObjectAccess& soa, |
| 164 | Handle<mirror::DexCache> dex_cache, |
| 165 | Handle<mirror::ClassLoader> class_loader, |
| 166 | const DexCompilationUnit* mUnit) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 167 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 168 | |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 169 | ObjPtr<mirror::Class> ResolveClass(const ScopedObjectAccess& soa, |
| 170 | Handle<mirror::DexCache> dex_cache, |
| 171 | Handle<mirror::ClassLoader> class_loader, |
| 172 | dex::TypeIndex type_index, |
| 173 | const DexCompilationUnit* mUnit) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 174 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 175 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 176 | // Resolve a field. Returns null on failure, including incompatible class change. |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 177 | // NOTE: Unlike ClassLinker's ResolveField(), this method enforces is_static. |
Vladimir Marko | e11dd50 | 2017-12-08 14:09:45 +0000 | [diff] [blame] | 178 | ArtField* ResolveField(const ScopedObjectAccess& soa, |
| 179 | Handle<mirror::DexCache> dex_cache, |
| 180 | Handle<mirror::ClassLoader> class_loader, |
| 181 | uint32_t field_idx, |
| 182 | bool is_static) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 183 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 184 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 185 | // Can we fast-path an IGET/IPUT access to an instance field? If yes, compute the field offset. |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 186 | std::pair<bool, bool> IsFastInstanceField(ObjPtr<mirror::DexCache> dex_cache, |
| 187 | ObjPtr<mirror::Class> referrer_class, |
| 188 | ArtField* resolved_field, |
| 189 | uint16_t field_idx) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 190 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 191 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 192 | void ProcessedInstanceField(bool resolved); |
| 193 | void ProcessedStaticField(bool resolved, bool local); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 194 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 195 | // Can we fast path instance field access? Computes field's offset and volatility. |
Ian Rogers | 9b297bf | 2013-09-06 11:11:25 -0700 | [diff] [blame] | 196 | bool ComputeInstanceFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit, bool is_put, |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 197 | MemberOffset* field_offset, bool* is_volatile) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 198 | REQUIRES(!Locks::mutator_lock_); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 199 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 200 | ArtField* ComputeInstanceFieldInfo(uint32_t field_idx, |
Vladimir Marko | e11dd50 | 2017-12-08 14:09:45 +0000 | [diff] [blame] | 201 | const DexCompilationUnit* mUnit, |
| 202 | bool is_put, |
| 203 | const ScopedObjectAccess& soa) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 204 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 205 | |
| 206 | |
Vladimir Marko | 2730db0 | 2014-01-27 11:15:17 +0000 | [diff] [blame] | 207 | bool IsSafeCast(const DexCompilationUnit* mUnit, uint32_t dex_pc); |
Ian Rogers | fae370a | 2013-06-05 08:33:27 -0700 | [diff] [blame] | 208 | |
Logan Chien | 08e1ba3 | 2012-05-08 15:08:51 +0800 | [diff] [blame] | 209 | size_t GetThreadCount() const { |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 210 | return parallel_thread_count_; |
Logan Chien | 08e1ba3 | 2012-05-08 15:08:51 +0800 | [diff] [blame] | 211 | } |
| 212 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 213 | void SetDedupeEnabled(bool dedupe_enabled) { |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 214 | compiled_method_storage_.SetDedupeEnabled(dedupe_enabled); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 215 | } |
Nicolas Geoffray | 571d234 | 2016-10-12 13:03:15 +0000 | [diff] [blame] | 216 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 217 | bool DedupeEnabled() const { |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 218 | return compiled_method_storage_.DedupeEnabled(); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 221 | // Checks whether profile guided compilation is enabled and if the method should be compiled |
| 222 | // according to the profile file. |
| 223 | bool ShouldCompileBasedOnProfile(const MethodReference& method_ref) const; |
| 224 | |
Mathieu Chartier | a807780 | 2016-03-16 19:08:31 -0700 | [diff] [blame] | 225 | // Checks whether profile guided verification is enabled and if the method should be verified |
| 226 | // according to the profile file. |
| 227 | bool ShouldVerifyClassBasedOnProfile(const DexFile& dex_file, uint16_t class_idx) const; |
| 228 | |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 229 | void RecordClassStatus(const ClassReference& ref, ClassStatus status); |
Ian Rogers | 3d1548d | 2012-09-24 14:08:03 -0700 | [diff] [blame] | 230 | |
Mathieu Chartier | ab972ef | 2014-12-03 17:38:22 -0800 | [diff] [blame] | 231 | // Get memory usage during compilation. |
Andreas Gampe | 8d295f8 | 2015-01-20 14:50:21 -0800 | [diff] [blame] | 232 | std::string GetMemoryUsageString(bool extended) const; |
Mathieu Chartier | ab972ef | 2014-12-03 17:38:22 -0800 | [diff] [blame] | 233 | |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 234 | void SetHadHardVerifierFailure() { |
| 235 | had_hard_verifier_failure_ = true; |
| 236 | } |
Andreas Gampe | f39208f | 2017-10-19 15:06:59 -0700 | [diff] [blame] | 237 | void AddSoftVerifierFailure() { |
| 238 | number_of_soft_verifier_failures_++; |
| 239 | } |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 240 | |
Andreas Gampe | 5eb0d38 | 2015-07-23 01:19:26 -0700 | [diff] [blame] | 241 | Compiler::Kind GetCompilerKind() { |
| 242 | return compiler_kind_; |
| 243 | } |
| 244 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 245 | CompiledMethodStorage* GetCompiledMethodStorage() { |
| 246 | return &compiled_method_storage_; |
| 247 | } |
| 248 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 249 | // Is `boot_image_filename` the name of a core image (small boot |
| 250 | // image used for ART testing only)? |
| 251 | static bool IsCoreImageFilename(const std::string& boot_image_filename) { |
Vladimir Marko | be0c7cf | 2018-03-19 13:40:56 +0000 | [diff] [blame] | 252 | // Look for "core.art" or "core-*.art". |
| 253 | if (android::base::EndsWith(boot_image_filename, "core.art")) { |
| 254 | return true; |
| 255 | } |
| 256 | if (!android::base::EndsWith(boot_image_filename, ".art")) { |
| 257 | return false; |
| 258 | } |
Andreas Gampe | db20a4b | 2018-04-11 15:44:19 -0700 | [diff] [blame] | 259 | size_t slash_pos = boot_image_filename.rfind('/'); |
| 260 | if (slash_pos == std::string::npos) { |
| 261 | return android::base::StartsWith(boot_image_filename, "core-"); |
Vladimir Marko | be0c7cf | 2018-03-19 13:40:56 +0000 | [diff] [blame] | 262 | } |
Andreas Gampe | db20a4b | 2018-04-11 15:44:19 -0700 | [diff] [blame] | 263 | return boot_image_filename.compare(slash_pos + 1, 5u, "core-") == 0; |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Mathieu Chartier | a79efdb | 2018-01-18 16:31:01 -0800 | [diff] [blame] | 266 | optimizer::DexToDexCompiler& GetDexToDexCompiler() { |
| 267 | return dex_to_dex_compiler_; |
| 268 | } |
| 269 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 270 | private: |
Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 271 | void LoadImageClasses(TimingLogger* timings, /*inout*/ HashSet<std::string>* image_classes) |
Mathieu Chartier | 1a088d4 | 2017-07-18 11:43:57 -0700 | [diff] [blame] | 272 | REQUIRES(!Locks::mutator_lock_); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 273 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 274 | // Attempt to resolve all type, methods, fields, and strings |
| 275 | // referenced from code in the dex file following PathClassLoader |
| 276 | // ordering semantics. |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 277 | void Resolve(jobject class_loader, |
| 278 | const std::vector<const DexFile*>& dex_files, |
| 279 | TimingLogger* timings) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 280 | REQUIRES(!Locks::mutator_lock_); |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 281 | void ResolveDexFile(jobject class_loader, |
| 282 | const DexFile& dex_file, |
Andreas Gampe | de7b436 | 2014-07-28 18:38:57 -0700 | [diff] [blame] | 283 | const std::vector<const DexFile*>& dex_files, |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 284 | ThreadPool* thread_pool, |
| 285 | size_t thread_count, |
| 286 | TimingLogger* timings) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 287 | REQUIRES(!Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 288 | |
Nicolas Geoffray | 7498105 | 2017-01-16 17:54:09 +0000 | [diff] [blame] | 289 | // Do fast verification through VerifierDeps if possible. Return whether |
| 290 | // verification was successful. |
Nicolas Geoffray | 7498105 | 2017-01-16 17:54:09 +0000 | [diff] [blame] | 291 | bool FastVerify(jobject class_loader, |
| 292 | const std::vector<const DexFile*>& dex_files, |
Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 293 | TimingLogger* timings, |
| 294 | /*out*/ VerificationResults* verification_results); |
Nicolas Geoffray | 7498105 | 2017-01-16 17:54:09 +0000 | [diff] [blame] | 295 | |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 296 | void Verify(jobject class_loader, |
| 297 | const std::vector<const DexFile*>& dex_files, |
Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 298 | TimingLogger* timings, |
| 299 | /*out*/ VerificationResults* verification_results); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 300 | |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 301 | void VerifyDexFile(jobject class_loader, |
| 302 | const DexFile& dex_file, |
Andreas Gampe | de7b436 | 2014-07-28 18:38:57 -0700 | [diff] [blame] | 303 | const std::vector<const DexFile*>& dex_files, |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 304 | ThreadPool* thread_pool, |
| 305 | size_t thread_count, |
| 306 | TimingLogger* timings) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 307 | REQUIRES(!Locks::mutator_lock_); |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 308 | |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 309 | void SetVerified(jobject class_loader, |
| 310 | const std::vector<const DexFile*>& dex_files, |
| 311 | TimingLogger* timings); |
| 312 | void SetVerifiedDexFile(jobject class_loader, |
| 313 | const DexFile& dex_file, |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 314 | const std::vector<const DexFile*>& dex_files, |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 315 | ThreadPool* thread_pool, |
| 316 | size_t thread_count, |
| 317 | TimingLogger* timings) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 318 | REQUIRES(!Locks::mutator_lock_); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 319 | |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 320 | void InitializeClasses(jobject class_loader, |
Andreas Gampe | de7b436 | 2014-07-28 18:38:57 -0700 | [diff] [blame] | 321 | const std::vector<const DexFile*>& dex_files, |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 322 | TimingLogger* timings) |
Mathieu Chartier | 1a088d4 | 2017-07-18 11:43:57 -0700 | [diff] [blame] | 323 | REQUIRES(!Locks::mutator_lock_); |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 324 | void InitializeClasses(jobject class_loader, |
| 325 | const DexFile& dex_file, |
| 326 | const std::vector<const DexFile*>& dex_files, |
| 327 | TimingLogger* timings) |
Mathieu Chartier | 1a088d4 | 2017-07-18 11:43:57 -0700 | [diff] [blame] | 328 | REQUIRES(!Locks::mutator_lock_); |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 329 | |
Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 330 | void UpdateImageClasses(TimingLogger* timings, /*inout*/ HashSet<std::string>* image_classes) |
| 331 | REQUIRES(!Locks::mutator_lock_); |
Brian Carlstrom | 9639160 | 2013-06-13 19:49:50 -0700 | [diff] [blame] | 332 | |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 333 | void Compile(jobject class_loader, |
| 334 | const std::vector<const DexFile*>& dex_files, |
Mathieu Chartier | a79efdb | 2018-01-18 16:31:01 -0800 | [diff] [blame] | 335 | TimingLogger* timings); |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 336 | |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 337 | void CheckThreadPools(); |
| 338 | |
Andreas Gampe | 4776987 | 2018-11-07 13:36:36 -0800 | [diff] [blame] | 339 | // Resolve const string literals that are loaded from dex code. If only_startup_strings is |
| 340 | // specified, only methods that are marked startup in the profile are resolved. |
| 341 | void ResolveConstStrings(const std::vector<const DexFile*>& dex_files, |
| 342 | bool only_startup_strings, |
| 343 | /*inout*/ TimingLogger* timings); |
| 344 | |
Brian Carlstrom | ae7083d | 2014-02-24 21:56:02 -0800 | [diff] [blame] | 345 | const CompilerOptions* const compiler_options_; |
Vladimir Marko | 2b5eaa2 | 2013-12-13 13:59:30 +0000 | [diff] [blame] | 346 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 347 | std::unique_ptr<Compiler> compiler_; |
Jeff Hao | 48699fb | 2015-04-06 14:21:37 -0700 | [diff] [blame] | 348 | Compiler::Kind compiler_kind_; |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 349 | |
Nicolas Geoffray | c4204a3 | 2017-09-18 14:03:45 +0100 | [diff] [blame] | 350 | // All class references that this compiler has compiled. Indexed by class defs. |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 351 | using ClassStateTable = AtomicDexRefMap<ClassReference, ClassStatus>; |
Mathieu Chartier | 1a088d4 | 2017-07-18 11:43:57 -0700 | [diff] [blame] | 352 | ClassStateTable compiled_classes_; |
Nicolas Geoffray | c4204a3 | 2017-09-18 14:03:45 +0100 | [diff] [blame] | 353 | // All class references that are in the classpath. Indexed by class defs. |
Nicolas Geoffray | 486dda0 | 2017-09-11 14:15:52 +0100 | [diff] [blame] | 354 | ClassStateTable classpath_classes_; |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 355 | |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 356 | typedef AtomicDexRefMap<MethodReference, CompiledMethod*> MethodTable; |
Andreas Gampe | 5eb0d38 | 2015-07-23 01:19:26 -0700 | [diff] [blame] | 357 | |
Andreas Gampe | 5eb0d38 | 2015-07-23 01:19:26 -0700 | [diff] [blame] | 358 | // All method references that this compiler has compiled. |
Mathieu Chartier | acab8d4 | 2016-11-23 13:45:58 -0800 | [diff] [blame] | 359 | MethodTable compiled_methods_; |
| 360 | |
Andreas Gampe | f39208f | 2017-10-19 15:06:59 -0700 | [diff] [blame] | 361 | std::atomic<uint32_t> number_of_soft_verifier_failures_; |
Andreas Gampe | bd600e3 | 2018-04-12 14:25:39 -0700 | [diff] [blame] | 362 | |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 363 | bool had_hard_verifier_failure_; |
| 364 | |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 365 | // A thread pool that can (potentially) run tasks in parallel. |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 366 | size_t parallel_thread_count_; |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 367 | std::unique_ptr<ThreadPool> parallel_thread_pool_; |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 368 | |
| 369 | // A thread pool that guarantees running single-threaded on the main thread. |
| 370 | std::unique_ptr<ThreadPool> single_thread_pool_; |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 371 | |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 372 | class AOTCompilationStats; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 373 | std::unique_ptr<AOTCompilationStats> stats_; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 374 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 375 | CompiledMethodStorage compiled_method_storage_; |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 376 | |
Calin Juravle | 6915898 | 2016-03-16 11:53:41 +0000 | [diff] [blame] | 377 | size_t max_arena_alloc_; |
Vladimir Marko | 492a7fa | 2016-06-01 18:38:43 +0100 | [diff] [blame] | 378 | |
Mathieu Chartier | a79efdb | 2018-01-18 16:31:01 -0800 | [diff] [blame] | 379 | // Compiler for dex to dex (quickening). |
Mathieu Chartier | a79efdb | 2018-01-18 16:31:01 -0800 | [diff] [blame] | 380 | optimizer::DexToDexCompiler dex_to_dex_compiler_; |
Vladimir Marko | 492a7fa | 2016-06-01 18:38:43 +0100 | [diff] [blame] | 381 | |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 382 | friend class CommonCompilerTest; |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 383 | friend class CompileClassVisitor; |
Nicolas Geoffray | 01b70e8 | 2016-11-17 10:58:36 +0000 | [diff] [blame] | 384 | friend class DexToDexDecompilerTest; |
Mathieu Chartier | 41dba67 | 2018-12-21 15:06:17 -0800 | [diff] [blame] | 385 | friend class InitializeClassVisitor; |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 386 | friend class verifier::VerifierDepsTest; |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 387 | DISALLOW_COPY_AND_ASSIGN(CompilerDriver); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 388 | }; |
| 389 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 390 | } // namespace art |
| 391 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 392 | #endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ |