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