compiler_driver.h revision 6915898b28cea6c9836ca1be6814d87e89cc6d76
1afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project/*
2afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * Copyright (C) 2011 The Android Open Source Project
3afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project *
4afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * you may not use this file except in compliance with the License.
6afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * You may obtain a copy of the License at
7afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project *
8afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project *
10afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * See the License for the specific language governing permissions and
14afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project * limitations under the License.
15afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project */
16afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
17afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#ifndef ART_COMPILER_DRIVER_COMPILER_DRIVER_H_
18afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#define ART_COMPILER_DRIVER_COMPILER_DRIVER_H_
19afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
201789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski#include <set>
218d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski#include <string>
22afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include <unordered_set>
23afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include <vector>
24afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
25afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "arch/instruction_set.h"
26afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "base/arena_allocator.h"
278d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski#include "base/bit_utils.h"
288d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski#include "base/mutex.h"
29afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "base/timing_logger.h"
30afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "class_reference.h"
31afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "compiler.h"
32afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "dex_file.h"
33afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "driver/compiled_method_storage.h"
3439b467482d1bf256a111c757e9b7621c6f523271Jason Monk#include "jit/offline_profiling_info.h"
35afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "invoke_type.h"
36afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "method_reference.h"
37afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "mirror/class.h"  // For mirror::Class::Status.
38afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project#include "os.h"
3939b467482d1bf256a111c757e9b7621c6f523271Jason Monk#include "runtime.h"
4039b467482d1bf256a111c757e9b7621c6f523271Jason Monk#include "safe_map.h"
4139b467482d1bf256a111c757e9b7621c6f523271Jason Monk#include "thread_pool.h"
4239b467482d1bf256a111c757e9b7621c6f523271Jason Monk#include "utils/array_ref.h"
4339b467482d1bf256a111c757e9b7621c6f523271Jason Monk#include "utils/dex_cache_arrays_layout.h"
4439b467482d1bf256a111c757e9b7621c6f523271Jason Monk
4539b467482d1bf256a111c757e9b7621c6f523271Jason Monknamespace art {
4639b467482d1bf256a111c757e9b7621c6f523271Jason Monk
47afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projectnamespace mirror {
48afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projectclass DexCache;
49afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project}  // namespace mirror
50afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
511789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinskinamespace verifier {
528d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinskiclass MethodVerifier;
53b8eb474b924254839248d9227b2e04cb5f4e891fChristian Mehlmauer}  // namespace verifier
548d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
55afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projectclass CompiledClass;
56afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projectclass CompiledMethod;
57afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projectclass CompilerOptions;
581789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinskiclass DexCompilationUnit;
591789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinskiclass DexFileToMethodInlinerMap;
608d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinskistruct InlineIGetIPutData;
618d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinskiclass InstructionSetFeatures;
628d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinskiclass ParallelCompilationManager;
63afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projectclass ScopedObjectAccess;
64afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projecttemplate <class Allocator> class SrcMap;
658d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinskiclass SrcMapElem;
668d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinskiusing SwapSrcMap = SrcMap<SwapAllocator<SrcMapElem>>;
671789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinskitemplate<class T> class Handle;
688d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinskiclass TimingLogger;
698d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinskiclass VerificationResults;
70afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projectclass VerifiedMethod;
71afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
72afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Projectenum EntryPointCallingConvention {
738d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  // ABI of invocations to a method's interpreter entry point.
741789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  kInterpreterAbi,
758d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  // ABI of calls to a method's native code, only used for native methods.
761789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  kJniAbi,
77afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // ABI of calls to a method's quick code entry point.
788d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  kQuickAbi
79afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project};
80afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
811789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinskiclass CompilerDriver {
821789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski public:
838d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  // Create a compiler targeting the requested "instruction_set".
841789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  // "image" should be true if image specific optimizations should be
851789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  // enabled.  "image_classes" lets the compiler know what classes it
86afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // can assume will be in the image, with null implying all available
87afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // classes.
881789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  CompilerDriver(const CompilerOptions* compiler_options,
898d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski                 VerificationResults* verification_results,
90afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 DexFileToMethodInlinerMap* method_inliner_map,
91afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 Compiler::Kind compiler_kind,
928d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski                 InstructionSet instruction_set,
93afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 const InstructionSetFeatures* instruction_set_features,
94afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 bool boot_image, std::unordered_set<std::string>* image_classes,
951789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski                 std::unordered_set<std::string>* compiled_classes,
96afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 std::unordered_set<std::string>* compiled_methods,
97afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 size_t thread_count,
98afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 bool dump_stats,
998d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski                 bool dump_passes,
100afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 CumulativeLogger* timer,
1011789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski                 int swap_fd,
102afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                 const ProfileCompilationInfo* profile_compilation_info);
1038d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
1048d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  ~CompilerDriver();
105afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
1068d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  // Set dex files that will be stored in the oat file after being compiled.
1071789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files) {
1088d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski    dex_files_for_oat_file_ = &dex_files;
109afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  }
1108d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
1118d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  // Get dex file that will be stored in the oat file after being compiled.
1128d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  ArrayRef<const DexFile* const> GetDexFilesForOatFile() const {
1131789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski    return (dex_files_for_oat_file_ != nullptr)
1141789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski        ? ArrayRef<const DexFile* const>(*dex_files_for_oat_file_)
1151789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski        : ArrayRef<const DexFile* const>();
1168d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  }
117afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
118afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  void CompileAll(jobject class_loader,
1198d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski                  const std::vector<const DexFile*>& dex_files,
1201789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski                  TimingLogger* timings)
1211789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski      REQUIRES(!Locks::mutator_lock_, !compiled_classes_lock_);
1221789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski
1231789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  // Compile a single Method.
1248d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  void CompileOne(Thread* self, ArtMethod* method, TimingLogger* timings)
1258d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski      SHARED_REQUIRES(Locks::mutator_lock_)
1268d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski      REQUIRES(!compiled_methods_lock_, !compiled_classes_lock_);
1278d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
1288d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  VerificationResults* GetVerificationResults() const {
1298d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski    DCHECK(Runtime::Current()->IsAotCompiler());
1301789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski    return verification_results_;
1311789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  }
1321789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski
1331789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  DexFileToMethodInlinerMap* GetMethodInlinerMap() const {
1341789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski    return method_inliner_map_;
1351789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  }
1361789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski
1371789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  InstructionSet GetInstructionSet() const {
1381789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski    return instruction_set_;
139afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  }
1408d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
141afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  const InstructionSetFeatures* GetInstructionSetFeatures() const {
1421789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski    return instruction_set_features_;
1431789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  }
1448d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
1451789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  const CompilerOptions& GetCompilerOptions() const {
1461789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski    return *compiler_options_;
1471789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski  }
148afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
1498d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  Compiler* GetCompiler() const {
1508d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski    return compiler_.get();
151afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  }
1528d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
153afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Are we compiling and creating an image file?
154afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  bool IsBootImage() const {
1558d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski    return boot_image_;
156afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  }
1578d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
158afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  const std::unordered_set<std::string>* GetImageClasses() const {
159afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project    return image_classes_.get();
1608d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  }
161afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
162afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Generate the trampolines that are invoked by unresolved direct methods.
163afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  const std::vector<uint8_t>* CreateJniDlsymLookup() const;
164afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  const std::vector<uint8_t>* CreateQuickGenericJniTrampoline() const;
1658d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  const std::vector<uint8_t>* CreateQuickImtConflictTrampoline() const;
166afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  const std::vector<uint8_t>* CreateQuickResolutionTrampoline() const;
167afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  const std::vector<uint8_t>* CreateQuickToInterpreterBridge() const;
168afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
169afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  CompiledClass* GetCompiledClass(ClassReference ref) const
170afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      REQUIRES(!compiled_classes_lock_);
171afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
172afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  CompiledMethod* GetCompiledMethod(MethodReference ref) const
173afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      REQUIRES(!compiled_methods_lock_);
174afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  size_t GetNonRelativeLinkerPatchCount() const
175afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      REQUIRES(!compiled_methods_lock_);
176afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
177afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Add a compiled method.
178afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  void AddCompiledMethod(const MethodReference& method_ref,
179afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                         CompiledMethod* const compiled_method,
180afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                         size_t non_relative_linker_patch_count)
1818d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski      REQUIRES(!compiled_methods_lock_);
182afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Remove and delete a compiled method.
183afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  void RemoveCompiledMethod(const MethodReference& method_ref) REQUIRES(!compiled_methods_lock_);
184afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
185afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  void AddRequiresConstructorBarrier(Thread* self, const DexFile* dex_file,
186afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                     uint16_t class_def_index)
187afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      REQUIRES(!freezing_constructor_lock_);
188afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  bool RequiresConstructorBarrier(Thread* self, const DexFile* dex_file,
189afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                  uint16_t class_def_index) const
190afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      REQUIRES(!freezing_constructor_lock_);
1911789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski
192afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Callbacks from compiler to see what runtime checks must be generated.
1938d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
194afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  bool CanAssumeTypeIsPresentInDexCache(const DexFile& dex_file, uint32_t type_idx);
1958d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
1968d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  bool CanAssumeStringIsPresentInDexCache(const DexFile& dex_file, uint32_t string_idx)
1978d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski      REQUIRES(!Locks::mutator_lock_);
1981789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski
199afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Are runtime access checks necessary in the compiled code?
2008762093e0094e09493fa6cbac8e8fbf265f18165Michael Chan  bool CanAccessTypeWithoutChecks(uint32_t referrer_idx, const DexFile& dex_file,
201afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                  uint32_t type_idx, bool* type_known_final = nullptr,
202afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                  bool* type_known_abstract = nullptr,
203afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                  bool* equals_referrers_class = nullptr)
2041789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski      REQUIRES(!Locks::mutator_lock_);
205afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
206afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Are runtime access and instantiable checks necessary in the code?
207afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // out_is_finalizable is set to whether the type is finalizable.
208afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  bool CanAccessInstantiableTypeWithoutChecks(uint32_t referrer_idx,
209afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                              const DexFile& dex_file,
210afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                              uint32_t type_idx,
211afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                              bool* out_is_finalizable)
212afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      REQUIRES(!Locks::mutator_lock_);
213afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
214afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  bool CanEmbedTypeInCode(const DexFile& dex_file, uint32_t type_idx,
215afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                          bool* is_type_initialized, bool* use_direct_type_ptr,
2168d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski                          uintptr_t* direct_type_ptr, bool* out_is_finalizable);
2178d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
2188d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  // Query methods for the java.lang.ref.Reference class.
2198d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  bool CanEmbedReferenceTypeInCode(ClassReference* ref,
220afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project                                   bool* use_direct_type_ptr, uintptr_t* direct_type_ptr);
221afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  uint32_t GetReferenceSlowFlagOffset() const;
2228d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  uint32_t GetReferenceDisableFlagOffset() const;
223afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
224afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Get the DexCache for the
225afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  mirror::DexCache* GetDexCache(const DexCompilationUnit* mUnit)
226afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project    SHARED_REQUIRES(Locks::mutator_lock_);
227afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
228afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  mirror::ClassLoader* GetClassLoader(const ScopedObjectAccess& soa,
2298d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski                                      const DexCompilationUnit* mUnit)
230afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project    SHARED_REQUIRES(Locks::mutator_lock_);
231afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project
2328d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  // Resolve compiling method's class. Returns null on failure.
2338d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  mirror::Class* ResolveCompilingMethodsClass(
2348d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski      const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
235afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit)
236afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      SHARED_REQUIRES(Locks::mutator_lock_);
2378d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
2388d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  mirror::Class* ResolveClass(
2398d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski      const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
2401789f7d236bca1583fd3f7eafcf81bbae915e229Adam Lesinski      Handle<mirror::ClassLoader> class_loader, uint16_t type_index,
2418d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski      const DexCompilationUnit* mUnit)
242afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      SHARED_REQUIRES(Locks::mutator_lock_);
2438d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
244afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Resolve a field. Returns null on failure, including incompatible class change.
245afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // NOTE: Unlike ClassLinker's ResolveField(), this method enforces is_static.
2468d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski  ArtField* ResolveField(
2478d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski      const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
248afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit,
249afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      uint32_t field_idx, bool is_static)
250afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      SHARED_REQUIRES(Locks::mutator_lock_);
2518d7be7b738cce9facdd8832aa845ceb79c19ffc6Adam Lesinski
252afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  // Resolve a field with a given dex file.
253afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project  ArtField* ResolveFieldWithDexFile(
254afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
255afc4ab2ffbb8327ddce9907961295a32cbf49d0fThe Android Open Source Project      Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file,
256      uint32_t field_idx, bool is_static)
257      SHARED_REQUIRES(Locks::mutator_lock_);
258
259  // Get declaration location of a resolved field.
260  void GetResolvedFieldDexFileLocation(
261      ArtField* resolved_field, const DexFile** declaring_dex_file,
262      uint16_t* declaring_class_idx, uint16_t* declaring_field_idx)
263      SHARED_REQUIRES(Locks::mutator_lock_);
264
265  bool IsFieldVolatile(ArtField* field) SHARED_REQUIRES(Locks::mutator_lock_);
266  MemberOffset GetFieldOffset(ArtField* field) SHARED_REQUIRES(Locks::mutator_lock_);
267
268  // Find a dex cache for a dex file.
269  inline mirror::DexCache* FindDexCache(const DexFile* dex_file)
270      SHARED_REQUIRES(Locks::mutator_lock_);
271
272  // Can we fast-path an IGET/IPUT access to an instance field? If yes, compute the field offset.
273  std::pair<bool, bool> IsFastInstanceField(
274      mirror::DexCache* dex_cache, mirror::Class* referrer_class,
275      ArtField* resolved_field, uint16_t field_idx)
276      SHARED_REQUIRES(Locks::mutator_lock_);
277
278  // Can we fast-path an SGET/SPUT access to a static field? If yes, compute the type index
279  // of the declaring class in the referrer's dex file.
280  std::pair<bool, bool> IsFastStaticField(
281      mirror::DexCache* dex_cache, mirror::Class* referrer_class,
282      ArtField* resolved_field, uint16_t field_idx, uint32_t* storage_index)
283      SHARED_REQUIRES(Locks::mutator_lock_);
284
285  // Return whether the declaring class of `resolved_method` is
286  // available to `referrer_class`. If this is true, compute the type
287  // index of the declaring class in the referrer's dex file and
288  // return it through the out argument `storage_index`; otherwise
289  // return DexFile::kDexNoIndex through `storage_index`.
290  bool IsClassOfStaticMethodAvailableToReferrer(mirror::DexCache* dex_cache,
291                                                mirror::Class* referrer_class,
292                                                ArtMethod* resolved_method,
293                                                uint16_t method_idx,
294                                                uint32_t* storage_index)
295      SHARED_REQUIRES(Locks::mutator_lock_);
296
297  // Is static field's in referrer's class?
298  bool IsStaticFieldInReferrerClass(mirror::Class* referrer_class, ArtField* resolved_field)
299      SHARED_REQUIRES(Locks::mutator_lock_);
300
301  // Is static field's class initialized?
302  bool IsStaticFieldsClassInitialized(mirror::Class* referrer_class,
303                                      ArtField* resolved_field)
304      SHARED_REQUIRES(Locks::mutator_lock_);
305
306  // Resolve a method. Returns null on failure, including incompatible class change.
307  ArtMethod* ResolveMethod(
308      ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
309      Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit,
310      uint32_t method_idx, InvokeType invoke_type, bool check_incompatible_class_change = true)
311      SHARED_REQUIRES(Locks::mutator_lock_);
312
313  // Get declaration location of a resolved field.
314  void GetResolvedMethodDexFileLocation(
315      ArtMethod* resolved_method, const DexFile** declaring_dex_file,
316      uint16_t* declaring_class_idx, uint16_t* declaring_method_idx)
317      SHARED_REQUIRES(Locks::mutator_lock_);
318
319  // Get the index in the vtable of the method.
320  uint16_t GetResolvedMethodVTableIndex(
321      ArtMethod* resolved_method, InvokeType type)
322      SHARED_REQUIRES(Locks::mutator_lock_);
323
324  // Can we fast-path an INVOKE? If no, returns 0. If yes, returns a non-zero opaque flags value
325  // for ProcessedInvoke() and computes the necessary lowering info.
326  int IsFastInvoke(
327      ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
328      Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit,
329      mirror::Class* referrer_class, ArtMethod* resolved_method, InvokeType* invoke_type,
330      MethodReference* target_method, const MethodReference* devirt_target,
331      uintptr_t* direct_code, uintptr_t* direct_method)
332      SHARED_REQUIRES(Locks::mutator_lock_);
333
334  // Is method's class initialized for an invoke?
335  // For static invokes to determine whether we need to consider potential call to <clinit>().
336  // For non-static invokes, assuming a non-null reference, the class is always initialized.
337  bool IsMethodsClassInitialized(mirror::Class* referrer_class, ArtMethod* resolved_method)
338      SHARED_REQUIRES(Locks::mutator_lock_);
339
340  // Get the layout of dex cache arrays for a dex file. Returns invalid layout if the
341  // dex cache arrays don't have a fixed layout.
342  DexCacheArraysLayout GetDexCacheArraysLayout(const DexFile* dex_file);
343
344  void ProcessedInstanceField(bool resolved);
345  void ProcessedStaticField(bool resolved, bool local);
346  void ProcessedInvoke(InvokeType invoke_type, int flags);
347
348  void ComputeFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit,
349                        const ScopedObjectAccess& soa, bool is_static,
350                        ArtField** resolved_field,
351                        mirror::Class** referrer_class,
352                        mirror::DexCache** dex_cache)
353      SHARED_REQUIRES(Locks::mutator_lock_);
354
355  // Can we fast path instance field access? Computes field's offset and volatility.
356  bool ComputeInstanceFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit, bool is_put,
357                                MemberOffset* field_offset, bool* is_volatile)
358      REQUIRES(!Locks::mutator_lock_);
359
360  ArtField* ComputeInstanceFieldInfo(uint32_t field_idx,
361                                             const DexCompilationUnit* mUnit,
362                                             bool is_put,
363                                             const ScopedObjectAccess& soa)
364      SHARED_REQUIRES(Locks::mutator_lock_);
365
366
367  // Can we fastpath static field access? Computes field's offset, volatility and whether the
368  // field is within the referrer (which can avoid checking class initialization).
369  bool ComputeStaticFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit, bool is_put,
370                              MemberOffset* field_offset, uint32_t* storage_index,
371                              bool* is_referrers_class, bool* is_volatile, bool* is_initialized,
372                              Primitive::Type* type)
373      REQUIRES(!Locks::mutator_lock_);
374
375  // Can we fastpath a interface, super class or virtual method call? Computes method's vtable
376  // index.
377  bool ComputeInvokeInfo(const DexCompilationUnit* mUnit, const uint32_t dex_pc,
378                         bool update_stats, bool enable_devirtualization,
379                         InvokeType* type, MethodReference* target_method, int* vtable_idx,
380                         uintptr_t* direct_code, uintptr_t* direct_method)
381      REQUIRES(!Locks::mutator_lock_);
382
383  const VerifiedMethod* GetVerifiedMethod(const DexFile* dex_file, uint32_t method_idx) const;
384  bool IsSafeCast(const DexCompilationUnit* mUnit, uint32_t dex_pc);
385
386  bool GetSupportBootImageFixup() const {
387    return support_boot_image_fixup_;
388  }
389
390  void SetSupportBootImageFixup(bool support_boot_image_fixup) {
391    support_boot_image_fixup_ = support_boot_image_fixup;
392  }
393
394  void SetCompilerContext(void* compiler_context) {
395    compiler_context_ = compiler_context;
396  }
397
398  void* GetCompilerContext() const {
399    return compiler_context_;
400  }
401
402  size_t GetThreadCount() const {
403    return parallel_thread_count_;
404  }
405
406  bool GetDumpStats() const {
407    return dump_stats_;
408  }
409
410  bool GetDumpPasses() const {
411    return dump_passes_;
412  }
413
414  CumulativeLogger* GetTimingsLogger() const {
415    return timings_logger_;
416  }
417
418  void SetDedupeEnabled(bool dedupe_enabled) {
419    compiled_method_storage_.SetDedupeEnabled(dedupe_enabled);
420  }
421  bool DedupeEnabled() const {
422    return compiled_method_storage_.DedupeEnabled();
423  }
424
425  // Checks if class specified by type_idx is one of the image_classes_
426  bool IsImageClass(const char* descriptor) const;
427
428  // Checks whether the provided class should be compiled, i.e., is in classes_to_compile_.
429  bool IsClassToCompile(const char* descriptor) const;
430
431  // Checks whether the provided method should be compiled, i.e., is in method_to_compile_.
432  bool IsMethodToCompile(const MethodReference& method_ref) const;
433
434  // Checks whether profile guided compilation is enabled and if the method should be compiled
435  // according to the profile file.
436  bool ShouldCompileBasedOnProfile(const MethodReference& method_ref) const;
437
438  void RecordClassStatus(ClassReference ref, mirror::Class::Status status)
439      REQUIRES(!compiled_classes_lock_);
440
441  // Checks if the specified method has been verified without failures. Returns
442  // false if the method is not in the verification results (GetVerificationResults).
443  bool IsMethodVerifiedWithoutFailures(uint32_t method_idx,
444                                       uint16_t class_def_idx,
445                                       const DexFile& dex_file) const;
446
447  // Get memory usage during compilation.
448  std::string GetMemoryUsageString(bool extended) const;
449
450  bool IsStringTypeIndex(uint16_t type_index, const DexFile* dex_file);
451  bool IsStringInit(uint32_t method_index, const DexFile* dex_file, int32_t* offset);
452
453  void SetHadHardVerifierFailure() {
454    had_hard_verifier_failure_ = true;
455  }
456
457  Compiler::Kind GetCompilerKind() {
458    return compiler_kind_;
459  }
460
461  CompiledMethodStorage* GetCompiledMethodStorage() {
462    return &compiled_method_storage_;
463  }
464
465  // Can we assume that the klass is loaded?
466  bool CanAssumeClassIsLoaded(mirror::Class* klass)
467      SHARED_REQUIRES(Locks::mutator_lock_);
468
469  bool MayInline(const DexFile* inlined_from, const DexFile* inlined_into) const {
470    if (!kIsTargetBuild) {
471      return MayInlineInternal(inlined_from, inlined_into);
472    }
473    return true;
474  }
475
476 private:
477  // Return whether the declaring class of `resolved_member` is
478  // available to `referrer_class` for read or write access using two
479  // Boolean values returned as a pair. If is true at least for read
480  // access, compute the type index of the declaring class in the
481  // referrer's dex file and return it through the out argument
482  // `storage_index`; otherwise return DexFile::kDexNoIndex through
483  // `storage_index`.
484  template <typename ArtMember>
485  std::pair<bool, bool> IsClassOfStaticMemberAvailableToReferrer(mirror::DexCache* dex_cache,
486                                                                 mirror::Class* referrer_class,
487                                                                 ArtMember* resolved_member,
488                                                                 uint16_t member_idx,
489                                                                 uint32_t* storage_index)
490      SHARED_REQUIRES(Locks::mutator_lock_);
491
492  // Can `referrer_class` access the resolved `member`?
493  // Dispatch call to mirror::Class::CanAccessResolvedField or
494  // mirror::Class::CanAccessResolvedMember depending on the value of
495  // ArtMember.
496  template <typename ArtMember>
497  static bool CanAccessResolvedMember(mirror::Class* referrer_class,
498                                      mirror::Class* access_to,
499                                      ArtMember* member,
500                                      mirror::DexCache* dex_cache,
501                                      uint32_t field_idx)
502      SHARED_REQUIRES(Locks::mutator_lock_);
503
504  // Can we assume that the klass is initialized?
505  bool CanAssumeClassIsInitialized(mirror::Class* klass)
506      SHARED_REQUIRES(Locks::mutator_lock_);
507  bool CanReferrerAssumeClassIsInitialized(mirror::Class* referrer_class, mirror::Class* klass)
508      SHARED_REQUIRES(Locks::mutator_lock_);
509
510  // These flags are internal to CompilerDriver for collecting INVOKE resolution statistics.
511  // The only external contract is that unresolved method has flags 0 and resolved non-0.
512  enum {
513    kBitMethodResolved = 0,
514    kBitVirtualMadeDirect,
515    kBitPreciseTypeDevirtualization,
516    kBitDirectCallToBoot,
517    kBitDirectMethodToBoot
518  };
519  static constexpr int kFlagMethodResolved              = 1 << kBitMethodResolved;
520  static constexpr int kFlagVirtualMadeDirect           = 1 << kBitVirtualMadeDirect;
521  static constexpr int kFlagPreciseTypeDevirtualization = 1 << kBitPreciseTypeDevirtualization;
522  static constexpr int kFlagDirectCallToBoot            = 1 << kBitDirectCallToBoot;
523  static constexpr int kFlagDirectMethodToBoot          = 1 << kBitDirectMethodToBoot;
524  static constexpr int kFlagsMethodResolvedVirtualMadeDirect =
525      kFlagMethodResolved | kFlagVirtualMadeDirect;
526  static constexpr int kFlagsMethodResolvedPreciseTypeDevirtualization =
527      kFlagsMethodResolvedVirtualMadeDirect | kFlagPreciseTypeDevirtualization;
528
529 public:  // TODO make private or eliminate.
530  // Compute constant code and method pointers when possible.
531  void GetCodeAndMethodForDirectCall(/*out*/InvokeType* type,
532                                     InvokeType sharp_type,
533                                     bool no_guarantee_of_dex_cache_entry,
534                                     const mirror::Class* referrer_class,
535                                     ArtMethod* method,
536                                     /*out*/int* stats_flags,
537                                     MethodReference* target_method,
538                                     uintptr_t* direct_code, uintptr_t* direct_method)
539      SHARED_REQUIRES(Locks::mutator_lock_);
540
541 private:
542  void PreCompile(jobject class_loader,
543                  const std::vector<const DexFile*>& dex_files,
544                  TimingLogger* timings)
545      REQUIRES(!Locks::mutator_lock_, !compiled_classes_lock_);
546
547  void LoadImageClasses(TimingLogger* timings) REQUIRES(!Locks::mutator_lock_);
548
549  // Attempt to resolve all type, methods, fields, and strings
550  // referenced from code in the dex file following PathClassLoader
551  // ordering semantics.
552  void Resolve(jobject class_loader,
553               const std::vector<const DexFile*>& dex_files,
554               TimingLogger* timings)
555      REQUIRES(!Locks::mutator_lock_);
556  void ResolveDexFile(jobject class_loader,
557                      const DexFile& dex_file,
558                      const std::vector<const DexFile*>& dex_files,
559                      ThreadPool* thread_pool,
560                      size_t thread_count,
561                      TimingLogger* timings)
562      REQUIRES(!Locks::mutator_lock_);
563
564  void Verify(jobject class_loader,
565              const std::vector<const DexFile*>& dex_files,
566              TimingLogger* timings);
567  void VerifyDexFile(jobject class_loader,
568                     const DexFile& dex_file,
569                     const std::vector<const DexFile*>& dex_files,
570                     ThreadPool* thread_pool,
571                     size_t thread_count,
572                     TimingLogger* timings)
573      REQUIRES(!Locks::mutator_lock_);
574
575  void SetVerified(jobject class_loader,
576                   const std::vector<const DexFile*>& dex_files,
577                   TimingLogger* timings);
578  void SetVerifiedDexFile(jobject class_loader,
579                          const DexFile& dex_file,
580                          const std::vector<const DexFile*>& dex_files,
581                          ThreadPool* thread_pool,
582                          size_t thread_count,
583                          TimingLogger* timings)
584      REQUIRES(!Locks::mutator_lock_);
585
586  void InitializeClasses(jobject class_loader,
587                         const std::vector<const DexFile*>& dex_files,
588                         TimingLogger* timings)
589      REQUIRES(!Locks::mutator_lock_, !compiled_classes_lock_);
590  void InitializeClasses(jobject class_loader,
591                         const DexFile& dex_file,
592                         const std::vector<const DexFile*>& dex_files,
593                         TimingLogger* timings)
594      REQUIRES(!Locks::mutator_lock_, !compiled_classes_lock_);
595
596  void UpdateImageClasses(TimingLogger* timings) REQUIRES(!Locks::mutator_lock_);
597  static void FindClinitImageClassesCallback(mirror::Object* object, void* arg)
598      SHARED_REQUIRES(Locks::mutator_lock_);
599
600  void Compile(jobject class_loader,
601               const std::vector<const DexFile*>& dex_files,
602               TimingLogger* timings);
603  void CompileDexFile(jobject class_loader,
604                      const DexFile& dex_file,
605                      const std::vector<const DexFile*>& dex_files,
606                      ThreadPool* thread_pool,
607                      size_t thread_count,
608                      TimingLogger* timings)
609      REQUIRES(!Locks::mutator_lock_);
610
611  bool MayInlineInternal(const DexFile* inlined_from, const DexFile* inlined_into) const;
612
613  void InitializeThreadPools();
614  void FreeThreadPools();
615  void CheckThreadPools();
616
617  const CompilerOptions* const compiler_options_;
618  VerificationResults* const verification_results_;
619  DexFileToMethodInlinerMap* const method_inliner_map_;
620
621  std::unique_ptr<Compiler> compiler_;
622  Compiler::Kind compiler_kind_;
623
624  const InstructionSet instruction_set_;
625  const InstructionSetFeatures* const instruction_set_features_;
626
627  // All class references that require
628  mutable ReaderWriterMutex freezing_constructor_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
629  std::set<ClassReference> freezing_constructor_classes_ GUARDED_BY(freezing_constructor_lock_);
630
631  typedef SafeMap<const ClassReference, CompiledClass*> ClassTable;
632  // All class references that this compiler has compiled.
633  mutable Mutex compiled_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
634  ClassTable compiled_classes_ GUARDED_BY(compiled_classes_lock_);
635
636  typedef SafeMap<const MethodReference, CompiledMethod*, MethodReferenceComparator> MethodTable;
637
638 public:
639  // Lock is public so that non-members can have lock annotations.
640  mutable Mutex compiled_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
641
642 private:
643  // All method references that this compiler has compiled.
644  MethodTable compiled_methods_ GUARDED_BY(compiled_methods_lock_);
645  // Number of non-relative patches in all compiled methods. These patches need space
646  // in the .oat_patches ELF section if requested in the compiler options.
647  size_t non_relative_linker_patch_count_ GUARDED_BY(compiled_methods_lock_);
648
649  const bool boot_image_;
650
651  // If image_ is true, specifies the classes that will be included in the image.
652  // Note if image_classes_ is null, all classes are included in the image.
653  std::unique_ptr<std::unordered_set<std::string>> image_classes_;
654
655  // Specifies the classes that will be compiled. Note that if classes_to_compile_ is null,
656  // all classes are eligible for compilation (duplication filters etc. will still apply).
657  // This option may be restricted to the boot image, depending on a flag in the implementation.
658  std::unique_ptr<std::unordered_set<std::string>> classes_to_compile_;
659
660  // Specifies the methods that will be compiled. Note that if methods_to_compile_ is null,
661  // all methods are eligible for compilation (compilation filters etc. will still apply).
662  // This option may be restricted to the boot image, depending on a flag in the implementation.
663  std::unique_ptr<std::unordered_set<std::string>> methods_to_compile_;
664
665  bool had_hard_verifier_failure_;
666
667  // A thread pool that can (potentially) run tasks in parallel.
668  std::unique_ptr<ThreadPool> parallel_thread_pool_;
669  size_t parallel_thread_count_;
670
671  // A thread pool that guarantees running single-threaded on the main thread.
672  std::unique_ptr<ThreadPool> single_thread_pool_;
673
674  class AOTCompilationStats;
675  std::unique_ptr<AOTCompilationStats> stats_;
676
677  bool dump_stats_;
678  const bool dump_passes_;
679
680  CumulativeLogger* const timings_logger_;
681
682  typedef void (*CompilerCallbackFn)(CompilerDriver& driver);
683  typedef MutexLock* (*CompilerMutexLockFn)(CompilerDriver& driver);
684
685  void* compiler_context_;
686
687  bool support_boot_image_fixup_;
688
689  // List of dex files that will be stored in the oat file.
690  const std::vector<const DexFile*>* dex_files_for_oat_file_;
691
692  CompiledMethodStorage compiled_method_storage_;
693
694  // Info for profile guided compilation.
695  const ProfileCompilationInfo* const profile_compilation_info_;
696
697  size_t max_arena_alloc_;
698  friend class CompileClassVisitor;
699  DISALLOW_COPY_AND_ASSIGN(CompilerDriver);
700};
701
702}  // namespace art
703
704#endif  // ART_COMPILER_DRIVER_COMPILER_DRIVER_H_
705