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