compiler_driver.h revision 45724f9a0cc38dbb3071beb3eeab96499868b49c
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 */ 16 17#ifndef ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ 18#define ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ 19 20#include <set> 21#include <string> 22#include <unordered_set> 23#include <vector> 24 25#include "arch/instruction_set.h" 26#include "base/arena_allocator.h" 27#include "base/bit_utils.h" 28#include "base/mutex.h" 29#include "base/timing_logger.h" 30#include "class_reference.h" 31#include "compiler.h" 32#include "dex_file.h" 33#include "driver/compiled_method_storage.h" 34#include "jit/offline_profiling_info.h" 35#include "invoke_type.h" 36#include "method_reference.h" 37#include "mirror/class.h" // For mirror::Class::Status. 38#include "os.h" 39#include "runtime.h" 40#include "safe_map.h" 41#include "thread_pool.h" 42#include "utils/array_ref.h" 43#include "utils/dex_cache_arrays_layout.h" 44 45namespace art { 46 47namespace mirror { 48class DexCache; 49} // namespace mirror 50 51namespace verifier { 52class MethodVerifier; 53} // namespace verifier 54 55class CompiledClass; 56class CompiledMethod; 57class CompilerOptions; 58class DexCompilationUnit; 59class DexFileToMethodInlinerMap; 60struct InlineIGetIPutData; 61class InstructionSetFeatures; 62class ParallelCompilationManager; 63class ScopedObjectAccess; 64template <class Allocator> class SrcMap; 65class SrcMapElem; 66using SwapSrcMap = SrcMap<SwapAllocator<SrcMapElem>>; 67template<class T> class Handle; 68class TimingLogger; 69class VerificationResults; 70class VerifiedMethod; 71 72enum EntryPointCallingConvention { 73 // ABI of invocations to a method's interpreter entry point. 74 kInterpreterAbi, 75 // ABI of calls to a method's native code, only used for native methods. 76 kJniAbi, 77 // ABI of calls to a method's quick code entry point. 78 kQuickAbi 79}; 80 81class CompilerDriver { 82 public: 83 // Create a compiler targeting the requested "instruction_set". 84 // "image" should be true if image specific optimizations should be 85 // enabled. "image_classes" lets the compiler know what classes it 86 // can assume will be in the image, with null implying all available 87 // classes. 88 CompilerDriver(const CompilerOptions* compiler_options, 89 VerificationResults* verification_results, 90 DexFileToMethodInlinerMap* method_inliner_map, 91 Compiler::Kind compiler_kind, 92 InstructionSet instruction_set, 93 const InstructionSetFeatures* instruction_set_features, 94 bool boot_image, std::unordered_set<std::string>* image_classes, 95 std::unordered_set<std::string>* compiled_classes, 96 std::unordered_set<std::string>* compiled_methods, 97 size_t thread_count, bool dump_stats, bool dump_passes, 98 CumulativeLogger* timer, int swap_fd, 99 const std::unordered_map<const DexFile*, const char*>* dex_to_oat_map, 100 const ProfileCompilationInfo* profile_compilation_info); 101 102 ~CompilerDriver(); 103 104 // Set dex files that will be stored in the oat file after being compiled. 105 void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files) { 106 dex_files_for_oat_file_ = &dex_files; 107 } 108 109 // Get dex file that will be stored in the oat file after being compiled. 110 ArrayRef<const DexFile* const> GetDexFilesForOatFile() const { 111 return (dex_files_for_oat_file_ != nullptr) 112 ? ArrayRef<const DexFile* const>(*dex_files_for_oat_file_) 113 : ArrayRef<const DexFile* const>(); 114 } 115 116 // Are the given dex files compiled into the same oat file? Should only be called after 117 // GetDexFilesForOatFile, as the conservative answer (when we don't have a map) is true. 118 bool AreInSameOatFile(const DexFile* d1, const DexFile* d2) { 119 if (dex_file_oat_filename_map_ == nullptr) { 120 // TODO: Check for this wrt/ apps and boot image calls. 121 return true; 122 } 123 auto it1 = dex_file_oat_filename_map_->find(d1); 124 DCHECK(it1 != dex_file_oat_filename_map_->end()); 125 auto it2 = dex_file_oat_filename_map_->find(d2); 126 DCHECK(it2 != dex_file_oat_filename_map_->end()); 127 return it1->second == it2->second; 128 } 129 130 void CompileAll(jobject class_loader, 131 const std::vector<const DexFile*>& dex_files, 132 TimingLogger* timings) 133 REQUIRES(!Locks::mutator_lock_, !compiled_classes_lock_); 134 135 // Compile a single Method. 136 void CompileOne(Thread* self, ArtMethod* method, TimingLogger* timings) 137 SHARED_REQUIRES(Locks::mutator_lock_) 138 REQUIRES(!compiled_methods_lock_, !compiled_classes_lock_); 139 140 VerificationResults* GetVerificationResults() const { 141 return verification_results_; 142 } 143 144 DexFileToMethodInlinerMap* GetMethodInlinerMap() const { 145 return method_inliner_map_; 146 } 147 148 InstructionSet GetInstructionSet() const { 149 return instruction_set_; 150 } 151 152 const InstructionSetFeatures* GetInstructionSetFeatures() const { 153 return instruction_set_features_; 154 } 155 156 const CompilerOptions& GetCompilerOptions() const { 157 return *compiler_options_; 158 } 159 160 Compiler* GetCompiler() const { 161 return compiler_.get(); 162 } 163 164 // Are we compiling and creating an image file? 165 bool IsBootImage() const { 166 return boot_image_; 167 } 168 169 const std::unordered_set<std::string>* GetImageClasses() const { 170 return image_classes_.get(); 171 } 172 173 // Generate the trampolines that are invoked by unresolved direct methods. 174 const std::vector<uint8_t>* CreateJniDlsymLookup() const; 175 const std::vector<uint8_t>* CreateQuickGenericJniTrampoline() const; 176 const std::vector<uint8_t>* CreateQuickImtConflictTrampoline() const; 177 const std::vector<uint8_t>* CreateQuickResolutionTrampoline() const; 178 const std::vector<uint8_t>* CreateQuickToInterpreterBridge() const; 179 180 CompiledClass* GetCompiledClass(ClassReference ref) const 181 REQUIRES(!compiled_classes_lock_); 182 183 CompiledMethod* GetCompiledMethod(MethodReference ref) const 184 REQUIRES(!compiled_methods_lock_); 185 size_t GetNonRelativeLinkerPatchCount() const 186 REQUIRES(!compiled_methods_lock_); 187 188 // Add a compiled method. 189 void AddCompiledMethod(const MethodReference& method_ref, 190 CompiledMethod* const compiled_method, 191 size_t non_relative_linker_patch_count) 192 REQUIRES(!compiled_methods_lock_); 193 // Remove and delete a compiled method. 194 void RemoveCompiledMethod(const MethodReference& method_ref) REQUIRES(!compiled_methods_lock_); 195 196 void AddRequiresConstructorBarrier(Thread* self, const DexFile* dex_file, 197 uint16_t class_def_index) 198 REQUIRES(!freezing_constructor_lock_); 199 bool RequiresConstructorBarrier(Thread* self, const DexFile* dex_file, 200 uint16_t class_def_index) const 201 REQUIRES(!freezing_constructor_lock_); 202 203 // Callbacks from compiler to see what runtime checks must be generated. 204 205 bool CanAssumeTypeIsPresentInDexCache(const DexFile& dex_file, uint32_t type_idx); 206 207 bool CanAssumeStringIsPresentInDexCache(const DexFile& dex_file, uint32_t string_idx) 208 REQUIRES(!Locks::mutator_lock_); 209 210 // Are runtime access checks necessary in the compiled code? 211 bool CanAccessTypeWithoutChecks(uint32_t referrer_idx, const DexFile& dex_file, 212 uint32_t type_idx, bool* type_known_final = nullptr, 213 bool* type_known_abstract = nullptr, 214 bool* equals_referrers_class = nullptr) 215 REQUIRES(!Locks::mutator_lock_); 216 217 // Are runtime access and instantiable checks necessary in the code? 218 // out_is_finalizable is set to whether the type is finalizable. 219 bool CanAccessInstantiableTypeWithoutChecks(uint32_t referrer_idx, 220 const DexFile& dex_file, 221 uint32_t type_idx, 222 bool* out_is_finalizable) 223 REQUIRES(!Locks::mutator_lock_); 224 225 bool CanEmbedTypeInCode(const DexFile& dex_file, uint32_t type_idx, 226 bool* is_type_initialized, bool* use_direct_type_ptr, 227 uintptr_t* direct_type_ptr, bool* out_is_finalizable); 228 229 // Query methods for the java.lang.ref.Reference class. 230 bool CanEmbedReferenceTypeInCode(ClassReference* ref, 231 bool* use_direct_type_ptr, uintptr_t* direct_type_ptr); 232 uint32_t GetReferenceSlowFlagOffset() const; 233 uint32_t GetReferenceDisableFlagOffset() const; 234 235 // Get the DexCache for the 236 mirror::DexCache* GetDexCache(const DexCompilationUnit* mUnit) 237 SHARED_REQUIRES(Locks::mutator_lock_); 238 239 mirror::ClassLoader* GetClassLoader(const ScopedObjectAccess& soa, 240 const DexCompilationUnit* mUnit) 241 SHARED_REQUIRES(Locks::mutator_lock_); 242 243 // Resolve compiling method's class. Returns null on failure. 244 mirror::Class* ResolveCompilingMethodsClass( 245 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 246 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit) 247 SHARED_REQUIRES(Locks::mutator_lock_); 248 249 mirror::Class* ResolveClass( 250 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 251 Handle<mirror::ClassLoader> class_loader, uint16_t type_index, 252 const DexCompilationUnit* mUnit) 253 SHARED_REQUIRES(Locks::mutator_lock_); 254 255 // Resolve a field. Returns null on failure, including incompatible class change. 256 // NOTE: Unlike ClassLinker's ResolveField(), this method enforces is_static. 257 ArtField* ResolveField( 258 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 259 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit, 260 uint32_t field_idx, bool is_static) 261 SHARED_REQUIRES(Locks::mutator_lock_); 262 263 // Resolve a field with a given dex file. 264 ArtField* ResolveFieldWithDexFile( 265 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 266 Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file, 267 uint32_t field_idx, bool is_static) 268 SHARED_REQUIRES(Locks::mutator_lock_); 269 270 // Get declaration location of a resolved field. 271 void GetResolvedFieldDexFileLocation( 272 ArtField* resolved_field, const DexFile** declaring_dex_file, 273 uint16_t* declaring_class_idx, uint16_t* declaring_field_idx) 274 SHARED_REQUIRES(Locks::mutator_lock_); 275 276 bool IsFieldVolatile(ArtField* field) SHARED_REQUIRES(Locks::mutator_lock_); 277 MemberOffset GetFieldOffset(ArtField* field) SHARED_REQUIRES(Locks::mutator_lock_); 278 279 // Find a dex cache for a dex file. 280 inline mirror::DexCache* FindDexCache(const DexFile* dex_file) 281 SHARED_REQUIRES(Locks::mutator_lock_); 282 283 // Can we fast-path an IGET/IPUT access to an instance field? If yes, compute the field offset. 284 std::pair<bool, bool> IsFastInstanceField( 285 mirror::DexCache* dex_cache, mirror::Class* referrer_class, 286 ArtField* resolved_field, uint16_t field_idx) 287 SHARED_REQUIRES(Locks::mutator_lock_); 288 289 // Can we fast-path an SGET/SPUT access to a static field? If yes, compute the type index 290 // of the declaring class in the referrer's dex file. 291 std::pair<bool, bool> IsFastStaticField( 292 mirror::DexCache* dex_cache, mirror::Class* referrer_class, 293 ArtField* resolved_field, uint16_t field_idx, uint32_t* storage_index) 294 SHARED_REQUIRES(Locks::mutator_lock_); 295 296 // Return whether the declaring class of `resolved_method` is 297 // available to `referrer_class`. If this is true, compute the type 298 // index of the declaring class in the referrer's dex file and 299 // return it through the out argument `storage_index`; otherwise 300 // return DexFile::kDexNoIndex through `storage_index`. 301 bool IsClassOfStaticMethodAvailableToReferrer(mirror::DexCache* dex_cache, 302 mirror::Class* referrer_class, 303 ArtMethod* resolved_method, 304 uint16_t method_idx, 305 uint32_t* storage_index) 306 SHARED_REQUIRES(Locks::mutator_lock_); 307 308 // Is static field's in referrer's class? 309 bool IsStaticFieldInReferrerClass(mirror::Class* referrer_class, ArtField* resolved_field) 310 SHARED_REQUIRES(Locks::mutator_lock_); 311 312 // Is static field's class initialized? 313 bool IsStaticFieldsClassInitialized(mirror::Class* referrer_class, 314 ArtField* resolved_field) 315 SHARED_REQUIRES(Locks::mutator_lock_); 316 317 // Resolve a method. Returns null on failure, including incompatible class change. 318 ArtMethod* ResolveMethod( 319 ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 320 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit, 321 uint32_t method_idx, InvokeType invoke_type, bool check_incompatible_class_change = true) 322 SHARED_REQUIRES(Locks::mutator_lock_); 323 324 // Get declaration location of a resolved field. 325 void GetResolvedMethodDexFileLocation( 326 ArtMethod* resolved_method, const DexFile** declaring_dex_file, 327 uint16_t* declaring_class_idx, uint16_t* declaring_method_idx) 328 SHARED_REQUIRES(Locks::mutator_lock_); 329 330 // Get the index in the vtable of the method. 331 uint16_t GetResolvedMethodVTableIndex( 332 ArtMethod* resolved_method, InvokeType type) 333 SHARED_REQUIRES(Locks::mutator_lock_); 334 335 // Can we fast-path an INVOKE? If no, returns 0. If yes, returns a non-zero opaque flags value 336 // for ProcessedInvoke() and computes the necessary lowering info. 337 int IsFastInvoke( 338 ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 339 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit, 340 mirror::Class* referrer_class, ArtMethod* resolved_method, InvokeType* invoke_type, 341 MethodReference* target_method, const MethodReference* devirt_target, 342 uintptr_t* direct_code, uintptr_t* direct_method) 343 SHARED_REQUIRES(Locks::mutator_lock_); 344 345 // Is method's class initialized for an invoke? 346 // For static invokes to determine whether we need to consider potential call to <clinit>(). 347 // For non-static invokes, assuming a non-null reference, the class is always initialized. 348 bool IsMethodsClassInitialized(mirror::Class* referrer_class, ArtMethod* resolved_method) 349 SHARED_REQUIRES(Locks::mutator_lock_); 350 351 // Get the layout of dex cache arrays for a dex file. Returns invalid layout if the 352 // dex cache arrays don't have a fixed layout. 353 DexCacheArraysLayout GetDexCacheArraysLayout(const DexFile* dex_file); 354 355 void ProcessedInstanceField(bool resolved); 356 void ProcessedStaticField(bool resolved, bool local); 357 void ProcessedInvoke(InvokeType invoke_type, int flags); 358 359 void ComputeFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit, 360 const ScopedObjectAccess& soa, bool is_static, 361 ArtField** resolved_field, 362 mirror::Class** referrer_class, 363 mirror::DexCache** dex_cache) 364 SHARED_REQUIRES(Locks::mutator_lock_); 365 366 // Can we fast path instance field access? Computes field's offset and volatility. 367 bool ComputeInstanceFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit, bool is_put, 368 MemberOffset* field_offset, bool* is_volatile) 369 REQUIRES(!Locks::mutator_lock_); 370 371 ArtField* ComputeInstanceFieldInfo(uint32_t field_idx, 372 const DexCompilationUnit* mUnit, 373 bool is_put, 374 const ScopedObjectAccess& soa) 375 SHARED_REQUIRES(Locks::mutator_lock_); 376 377 378 // Can we fastpath static field access? Computes field's offset, volatility and whether the 379 // field is within the referrer (which can avoid checking class initialization). 380 bool ComputeStaticFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit, bool is_put, 381 MemberOffset* field_offset, uint32_t* storage_index, 382 bool* is_referrers_class, bool* is_volatile, bool* is_initialized, 383 Primitive::Type* type) 384 REQUIRES(!Locks::mutator_lock_); 385 386 // Can we fastpath a interface, super class or virtual method call? Computes method's vtable 387 // index. 388 bool ComputeInvokeInfo(const DexCompilationUnit* mUnit, const uint32_t dex_pc, 389 bool update_stats, bool enable_devirtualization, 390 InvokeType* type, MethodReference* target_method, int* vtable_idx, 391 uintptr_t* direct_code, uintptr_t* direct_method) 392 REQUIRES(!Locks::mutator_lock_); 393 394 const VerifiedMethod* GetVerifiedMethod(const DexFile* dex_file, uint32_t method_idx) const; 395 bool IsSafeCast(const DexCompilationUnit* mUnit, uint32_t dex_pc); 396 397 bool GetSupportBootImageFixup() const { 398 return support_boot_image_fixup_; 399 } 400 401 void SetSupportBootImageFixup(bool support_boot_image_fixup) { 402 support_boot_image_fixup_ = support_boot_image_fixup; 403 } 404 405 void SetCompilerContext(void* compiler_context) { 406 compiler_context_ = compiler_context; 407 } 408 409 void* GetCompilerContext() const { 410 return compiler_context_; 411 } 412 413 size_t GetThreadCount() const { 414 return parallel_thread_count_; 415 } 416 417 bool GetDumpStats() const { 418 return dump_stats_; 419 } 420 421 bool GetDumpPasses() const { 422 return dump_passes_; 423 } 424 425 CumulativeLogger* GetTimingsLogger() const { 426 return timings_logger_; 427 } 428 429 void SetDedupeEnabled(bool dedupe_enabled) { 430 compiled_method_storage_.SetDedupeEnabled(dedupe_enabled); 431 } 432 bool DedupeEnabled() const { 433 return compiled_method_storage_.DedupeEnabled(); 434 } 435 436 // Checks if class specified by type_idx is one of the image_classes_ 437 bool IsImageClass(const char* descriptor) const; 438 439 // Checks whether the provided class should be compiled, i.e., is in classes_to_compile_. 440 bool IsClassToCompile(const char* descriptor) const; 441 442 // Checks whether the provided method should be compiled, i.e., is in method_to_compile_. 443 bool IsMethodToCompile(const MethodReference& method_ref) const; 444 445 // Checks whether profile guided compilation is enabled and if the method should be compiled 446 // according to the profile file. 447 bool ShouldCompileBasedOnProfile(const MethodReference& method_ref) const; 448 449 void RecordClassStatus(ClassReference ref, mirror::Class::Status status) 450 REQUIRES(!compiled_classes_lock_); 451 452 // Checks if the specified method has been verified without failures. Returns 453 // false if the method is not in the verification results (GetVerificationResults). 454 bool IsMethodVerifiedWithoutFailures(uint32_t method_idx, 455 uint16_t class_def_idx, 456 const DexFile& dex_file) const; 457 458 // Get memory usage during compilation. 459 std::string GetMemoryUsageString(bool extended) const; 460 461 bool IsStringTypeIndex(uint16_t type_index, const DexFile* dex_file); 462 bool IsStringInit(uint32_t method_index, const DexFile* dex_file, int32_t* offset); 463 464 void SetHadHardVerifierFailure() { 465 had_hard_verifier_failure_ = true; 466 } 467 468 Compiler::Kind GetCompilerKind() { 469 return compiler_kind_; 470 } 471 472 CompiledMethodStorage* GetCompiledMethodStorage() { 473 return &compiled_method_storage_; 474 } 475 476 // Can we assume that the klass is loaded? 477 bool CanAssumeClassIsLoaded(mirror::Class* klass) 478 SHARED_REQUIRES(Locks::mutator_lock_); 479 480 bool MayInline(const DexFile* inlined_from, const DexFile* inlined_into) const { 481 if (!kIsTargetBuild) { 482 return MayInlineInternal(inlined_from, inlined_into); 483 } 484 return true; 485 } 486 487 private: 488 // Return whether the declaring class of `resolved_member` is 489 // available to `referrer_class` for read or write access using two 490 // Boolean values returned as a pair. If is true at least for read 491 // access, compute the type index of the declaring class in the 492 // referrer's dex file and return it through the out argument 493 // `storage_index`; otherwise return DexFile::kDexNoIndex through 494 // `storage_index`. 495 template <typename ArtMember> 496 std::pair<bool, bool> IsClassOfStaticMemberAvailableToReferrer(mirror::DexCache* dex_cache, 497 mirror::Class* referrer_class, 498 ArtMember* resolved_member, 499 uint16_t member_idx, 500 uint32_t* storage_index) 501 SHARED_REQUIRES(Locks::mutator_lock_); 502 503 // Can `referrer_class` access the resolved `member`? 504 // Dispatch call to mirror::Class::CanAccessResolvedField or 505 // mirror::Class::CanAccessResolvedMember depending on the value of 506 // ArtMember. 507 template <typename ArtMember> 508 static bool CanAccessResolvedMember(mirror::Class* referrer_class, 509 mirror::Class* access_to, 510 ArtMember* member, 511 mirror::DexCache* dex_cache, 512 uint32_t field_idx) 513 SHARED_REQUIRES(Locks::mutator_lock_); 514 515 // Can we assume that the klass is initialized? 516 bool CanAssumeClassIsInitialized(mirror::Class* klass) 517 SHARED_REQUIRES(Locks::mutator_lock_); 518 bool CanReferrerAssumeClassIsInitialized(mirror::Class* referrer_class, mirror::Class* klass) 519 SHARED_REQUIRES(Locks::mutator_lock_); 520 521 // These flags are internal to CompilerDriver for collecting INVOKE resolution statistics. 522 // The only external contract is that unresolved method has flags 0 and resolved non-0. 523 enum { 524 kBitMethodResolved = 0, 525 kBitVirtualMadeDirect, 526 kBitPreciseTypeDevirtualization, 527 kBitDirectCallToBoot, 528 kBitDirectMethodToBoot 529 }; 530 static constexpr int kFlagMethodResolved = 1 << kBitMethodResolved; 531 static constexpr int kFlagVirtualMadeDirect = 1 << kBitVirtualMadeDirect; 532 static constexpr int kFlagPreciseTypeDevirtualization = 1 << kBitPreciseTypeDevirtualization; 533 static constexpr int kFlagDirectCallToBoot = 1 << kBitDirectCallToBoot; 534 static constexpr int kFlagDirectMethodToBoot = 1 << kBitDirectMethodToBoot; 535 static constexpr int kFlagsMethodResolvedVirtualMadeDirect = 536 kFlagMethodResolved | kFlagVirtualMadeDirect; 537 static constexpr int kFlagsMethodResolvedPreciseTypeDevirtualization = 538 kFlagsMethodResolvedVirtualMadeDirect | kFlagPreciseTypeDevirtualization; 539 540 public: // TODO make private or eliminate. 541 // Compute constant code and method pointers when possible. 542 void GetCodeAndMethodForDirectCall(/*out*/InvokeType* type, 543 InvokeType sharp_type, 544 bool no_guarantee_of_dex_cache_entry, 545 const mirror::Class* referrer_class, 546 ArtMethod* method, 547 /*out*/int* stats_flags, 548 MethodReference* target_method, 549 uintptr_t* direct_code, uintptr_t* direct_method) 550 SHARED_REQUIRES(Locks::mutator_lock_); 551 552 private: 553 void PreCompile(jobject class_loader, 554 const std::vector<const DexFile*>& dex_files, 555 TimingLogger* timings) 556 REQUIRES(!Locks::mutator_lock_, !compiled_classes_lock_); 557 558 void LoadImageClasses(TimingLogger* timings) REQUIRES(!Locks::mutator_lock_); 559 560 // Attempt to resolve all type, methods, fields, and strings 561 // referenced from code in the dex file following PathClassLoader 562 // ordering semantics. 563 void Resolve(jobject class_loader, 564 const std::vector<const DexFile*>& dex_files, 565 TimingLogger* timings) 566 REQUIRES(!Locks::mutator_lock_); 567 void ResolveDexFile(jobject class_loader, 568 const DexFile& dex_file, 569 const std::vector<const DexFile*>& dex_files, 570 ThreadPool* thread_pool, 571 size_t thread_count, 572 TimingLogger* timings) 573 REQUIRES(!Locks::mutator_lock_); 574 575 void Verify(jobject class_loader, 576 const std::vector<const DexFile*>& dex_files, 577 TimingLogger* timings); 578 void VerifyDexFile(jobject class_loader, 579 const DexFile& dex_file, 580 const std::vector<const DexFile*>& dex_files, 581 ThreadPool* thread_pool, 582 size_t thread_count, 583 TimingLogger* timings) 584 REQUIRES(!Locks::mutator_lock_); 585 586 void SetVerified(jobject class_loader, 587 const std::vector<const DexFile*>& dex_files, 588 TimingLogger* timings); 589 void SetVerifiedDexFile(jobject class_loader, 590 const DexFile& dex_file, 591 const std::vector<const DexFile*>& dex_files, 592 ThreadPool* thread_pool, 593 size_t thread_count, 594 TimingLogger* timings) 595 REQUIRES(!Locks::mutator_lock_); 596 597 void InitializeClasses(jobject class_loader, 598 const std::vector<const DexFile*>& dex_files, 599 TimingLogger* timings) 600 REQUIRES(!Locks::mutator_lock_, !compiled_classes_lock_); 601 void InitializeClasses(jobject class_loader, 602 const DexFile& dex_file, 603 const std::vector<const DexFile*>& dex_files, 604 TimingLogger* timings) 605 REQUIRES(!Locks::mutator_lock_, !compiled_classes_lock_); 606 607 void UpdateImageClasses(TimingLogger* timings) REQUIRES(!Locks::mutator_lock_); 608 static void FindClinitImageClassesCallback(mirror::Object* object, void* arg) 609 SHARED_REQUIRES(Locks::mutator_lock_); 610 611 void Compile(jobject class_loader, 612 const std::vector<const DexFile*>& dex_files, 613 TimingLogger* timings); 614 void CompileDexFile(jobject class_loader, 615 const DexFile& dex_file, 616 const std::vector<const DexFile*>& dex_files, 617 ThreadPool* thread_pool, 618 size_t thread_count, 619 TimingLogger* timings) 620 REQUIRES(!Locks::mutator_lock_); 621 622 bool MayInlineInternal(const DexFile* inlined_from, const DexFile* inlined_into) const; 623 624 void InitializeThreadPools(); 625 void FreeThreadPools(); 626 void CheckThreadPools(); 627 628 const CompilerOptions* const compiler_options_; 629 VerificationResults* const verification_results_; 630 DexFileToMethodInlinerMap* const method_inliner_map_; 631 632 std::unique_ptr<Compiler> compiler_; 633 Compiler::Kind compiler_kind_; 634 635 const InstructionSet instruction_set_; 636 const InstructionSetFeatures* const instruction_set_features_; 637 638 // All class references that require 639 mutable ReaderWriterMutex freezing_constructor_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 640 std::set<ClassReference> freezing_constructor_classes_ GUARDED_BY(freezing_constructor_lock_); 641 642 typedef SafeMap<const ClassReference, CompiledClass*> ClassTable; 643 // All class references that this compiler has compiled. 644 mutable Mutex compiled_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 645 ClassTable compiled_classes_ GUARDED_BY(compiled_classes_lock_); 646 647 typedef SafeMap<const MethodReference, CompiledMethod*, MethodReferenceComparator> MethodTable; 648 649 public: 650 // Lock is public so that non-members can have lock annotations. 651 mutable Mutex compiled_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 652 653 private: 654 // All method references that this compiler has compiled. 655 MethodTable compiled_methods_ GUARDED_BY(compiled_methods_lock_); 656 // Number of non-relative patches in all compiled methods. These patches need space 657 // in the .oat_patches ELF section if requested in the compiler options. 658 size_t non_relative_linker_patch_count_ GUARDED_BY(compiled_methods_lock_); 659 660 const bool boot_image_; 661 662 // If image_ is true, specifies the classes that will be included in the image. 663 // Note if image_classes_ is null, all classes are included in the image. 664 std::unique_ptr<std::unordered_set<std::string>> image_classes_; 665 666 // Specifies the classes that will be compiled. Note that if classes_to_compile_ is null, 667 // all classes are eligible for compilation (duplication filters etc. will still apply). 668 // This option may be restricted to the boot image, depending on a flag in the implementation. 669 std::unique_ptr<std::unordered_set<std::string>> classes_to_compile_; 670 671 // Specifies the methods that will be compiled. Note that if methods_to_compile_ is null, 672 // all methods are eligible for compilation (compilation filters etc. will still apply). 673 // This option may be restricted to the boot image, depending on a flag in the implementation. 674 std::unique_ptr<std::unordered_set<std::string>> methods_to_compile_; 675 676 bool had_hard_verifier_failure_; 677 678 // A thread pool that can (potentially) run tasks in parallel. 679 std::unique_ptr<ThreadPool> parallel_thread_pool_; 680 size_t parallel_thread_count_; 681 682 // A thread pool that guarantees running single-threaded on the main thread. 683 std::unique_ptr<ThreadPool> single_thread_pool_; 684 685 class AOTCompilationStats; 686 std::unique_ptr<AOTCompilationStats> stats_; 687 688 bool dump_stats_; 689 const bool dump_passes_; 690 691 CumulativeLogger* const timings_logger_; 692 693 typedef void (*CompilerCallbackFn)(CompilerDriver& driver); 694 typedef MutexLock* (*CompilerMutexLockFn)(CompilerDriver& driver); 695 696 void* compiler_context_; 697 698 bool support_boot_image_fixup_; 699 700 // List of dex files that will be stored in the oat file. 701 const std::vector<const DexFile*>* dex_files_for_oat_file_; 702 703 // Map from dex files to the oat file (name) they will be compiled into. 704 const std::unordered_map<const DexFile*, const char*>* dex_file_oat_filename_map_; 705 706 CompiledMethodStorage compiled_method_storage_; 707 708 // Info for profile guided compilation. 709 const ProfileCompilationInfo* const profile_compilation_info_; 710 711 friend class CompileClassVisitor; 712 DISALLOW_COPY_AND_ASSIGN(CompilerDriver); 713}; 714 715} // namespace art 716 717#endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ 718