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