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