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