compiler_driver.h revision 9c86a0279aaf953377aa9e2277592e68bf814989
127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom/* 227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * Copyright (C) 2011 The Android Open Source Project 327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * 427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License"); 527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * you may not use this file except in compliance with the License. 627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * You may obtain a copy of the License at 727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * 827ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * http://www.apache.org/licenses/LICENSE-2.0 927ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * 1027ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * Unless required by applicable law or agreed to in writing, software 1127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS, 1227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * See the License for the specific language governing permissions and 1427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom * limitations under the License. 1527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom */ 1627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 1727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom#ifndef ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ 1827ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom#define ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ 19943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris 20c7dd295a4e0cc1d15c0c96088e55a85389bade74Ian Rogers#include <set> 21c7dd295a4e0cc1d15c0c96088e55a85389bade74Ian Rogers#include <string> 22700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers#include <vector> 23c7dd295a4e0cc1d15c0c96088e55a85389bade74Ian Rogers 24e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes#include "base/mutex.h" 25d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe#include "base/timing_logger.h" 26d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe#include "class_reference.h" 27d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe#include "compiled_class.h" 28d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe#include "compiled_method.h" 29d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe#include "compiler_backend.h" 30e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes#include "dex_file.h" 31277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe#include "instruction_set.h" 32277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe#include "invoke_type.h" 33277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe#include "method_reference.h" 346c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes#include "os.h" 35277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe#include "runtime.h" 36277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe#include "safe_map.h" 37c7dd295a4e0cc1d15c0c96088e55a85389bade74Ian Rogers#include "thread_pool.h" 386c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes#include "utils/arena_allocator.h" 396c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes#include "utils/dedupe_set.h" 406c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes 416c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughesnamespace art { 426c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes 436c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughesnamespace verifier { 44997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogersclass MethodVerifier; 45997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers} // namespace verifier 46997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers 476c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughesclass AOTCompilationStats; 486c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughesclass DexCompilationUnit; 49d6b6865cf787be8e4548e018762e72c7d1a40e52Ian Rogersclass DexFileToMethodInlinerMap; 50d6b6865cf787be8e4548e018762e72c7d1a40e52Ian Rogersclass InlineIGetIPutData; 51d6b6865cf787be8e4548e018762e72c7d1a40e52Ian Rogersclass OatWriter; 52d6b6865cf787be8e4548e018762e72c7d1a40e52Ian Rogersclass ParallelCompilationManager; 5327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstromclass TimingLogger; 5427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstromclass VerificationResults; 55943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferrisclass VerifiedMethod; 56943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris 57943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferrisenum EntryPointCallingConvention { 58943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris // ABI of invocations to a method's interpreter entry point. 59943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris kInterpreterAbi, 60943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris // ABI of calls to a method's native code, only used for native methods. 61943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris kJniAbi, 62943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris // ABI of calls to a method's portable code entry point. 63943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris kPortableAbi, 64943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris // ABI of calls to a method's quick code entry point. 65ecd3a6fc6e29d7dc4cb825c5282a8054ac52b8cfElliott Hughes kQuickAbi 66ecd3a6fc6e29d7dc4cb825c5282a8054ac52b8cfElliott Hughes}; 6796970cdab3e28511322ce37fa578f6eff8931d72Elliott Hughes 6896970cdab3e28511322ce37fa578f6eff8931d72Elliott Hughesenum DexToDexCompilationLevel { 69bad0267eaab9d6a522d05469ff90501deefdb88bMathieu Chartier kDontDexToDexCompile, // Only meaning wrt image time interpretation. 703eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi kRequired, // Dex-to-dex compilation required for correctness. 713eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi kOptimize // Perform required transformation and peep-hole optimizations. 723eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi}; 733eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 743eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi// Thread-local storage compiler worker threads 753eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchiclass CompilerTls { 763eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi public: 773eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi CompilerTls() : llvm_info_(NULL) {} 783eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi ~CompilerTls() {} 793eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 806e88ef6b604a7a945a466784580c42e6554c1289Mathieu Chartier void* GetLLVMInfo() { return llvm_info_; } 813eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 82c3ccc1039e0bbc0744f958cb8719cf96bce5b853Ian Rogers void SetLLVMInfo(void* llvm_info) { llvm_info_ = llvm_info; } 83d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 84d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe private: 85d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe void* llvm_info_; 866bd621aa31aa94ed42a2a35256d219630bf0b687Andreas Gampe}; 877104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe 88d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampeclass CompilerDriver { 89d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe public: 90d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe typedef std::set<std::string> DescriptorSet; 91d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 92d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe // Create a compiler targeting the requested "instruction_set". 93d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe // "image" should be true if image specific optimizations should be 94d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe // enabled. "image_classes" lets the compiler know what classes it 95d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe // can assume will be in the image, with NULL implying all available 96d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe // classes. 97d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe explicit CompilerDriver(VerificationResults* verification_results, 98d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe DexFileToMethodInlinerMap* method_inliner_map, 99d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe CompilerBackend::Kind compiler_backend_kind, 100d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe InstructionSet instruction_set, 101d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe InstructionSetFeatures instruction_set_features, 102d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe bool image, DescriptorSet* image_classes, 103d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe size_t thread_count, bool dump_stats, bool dump_passes, 104d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe CumulativeLogger* timer); 105d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 106d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe ~CompilerDriver(); 107d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 108d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe void CompileAll(jobject class_loader, const std::vector<const DexFile*>& dex_files, 109d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe TimingLogger& timings) 110d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe LOCKS_EXCLUDED(Locks::mutator_lock_); 111d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 112d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe // Compile a single Method. 113d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe void CompileOne(mirror::ArtMethod* method, TimingLogger& timings) 114d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 115d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 116d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe VerificationResults* GetVerificationResults() const { 117d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe return verification_results_; 118d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe } 119d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 120d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe DexFileToMethodInlinerMap* GetMethodInlinerMap() const { 121d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe return method_inliner_map_; 122d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe } 123d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 124d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe const InstructionSet& GetInstructionSet() const { 125d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe return instruction_set_; 126d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe } 127d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 128d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe const InstructionSetFeatures& GetInstructionSetFeatures() const { 129d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe return instruction_set_features_; 130d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe } 131d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 132d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe CompilerBackend* GetCompilerBackend() const { 133d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe return compiler_backend_.get(); 134d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe } 135d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe 136d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe // Are we compiling and creating an image file? 137d8f26dbebe72c1cbdfa85bdeeb003283c7435db3Andreas Gampe bool IsImage() const { 1388dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith return image_; 1398dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith } 140a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 1415c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko DescriptorSet* GetImageClasses() const { 142b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath return image_classes_.get(); 1435c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko } 1445c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko 145a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo CompilerTls* GetTls(); 146836572a07142627ff291d686a4e9e03a0988344bChristopher Ferris 147a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo // Generate the trampolines that are invoked by unresolved direct methods. 148a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo const std::vector<uint8_t>* CreateInterpreterToInterpreterBridge() const 149a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 150a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo const std::vector<uint8_t>* CreateInterpreterToCompiledCodeBridge() const 151a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 152a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo const std::vector<uint8_t>* CreateJniDlsymLookup() const 153a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 154a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo const std::vector<uint8_t>* CreatePortableImtConflictTrampoline() const 155a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 156b5505823ad3d0bab8fc9c15c266a3d8cd96ee59eVladimir Marko const std::vector<uint8_t>* CreatePortableResolutionTrampoline() const 157a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 158a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe const std::vector<uint8_t>* CreatePortableToInterpreterBridge() const 159a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 160a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo const std::vector<uint8_t>* CreateQuickImtConflictTrampoline() const 161a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 162a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo const std::vector<uint8_t>* CreateQuickResolutionTrampoline() const 163a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 164a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo const std::vector<uint8_t>* CreateQuickToInterpreterBridge() const 165a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 166a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 167836572a07142627ff291d686a4e9e03a0988344bChristopher Ferris CompiledClass* GetCompiledClass(ClassReference ref) const 168a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo LOCKS_EXCLUDED(compiled_classes_lock_); 169a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 170a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo CompiledMethod* GetCompiledMethod(MethodReference ref) const 171a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo LOCKS_EXCLUDED(compiled_methods_lock_); 172a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 173a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo void AddRequiresConstructorBarrier(Thread* self, const DexFile* dex_file, 174a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo uint16_t class_def_index); 175a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool RequiresConstructorBarrier(Thread* self, const DexFile* dex_file, uint16_t class_def_index); 176a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 177a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo // Callbacks from compiler to see what runtime checks must be generated. 178a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 179a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool CanAssumeTypeIsPresentInDexCache(const DexFile& dex_file, uint32_t type_idx); 180a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 181a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool CanAssumeStringIsPresentInDexCache(const DexFile& dex_file, uint32_t string_idx) 182a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo LOCKS_EXCLUDED(Locks::mutator_lock_); 183a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 184a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo // Are runtime access checks necessary in the compiled code? 185a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool CanAccessTypeWithoutChecks(uint32_t referrer_idx, const DexFile& dex_file, 186a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo uint32_t type_idx, bool* type_known_final = NULL, 187a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool* type_known_abstract = NULL, 188a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool* equals_referrers_class = NULL) 189a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo LOCKS_EXCLUDED(Locks::mutator_lock_); 190a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 191a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo // Are runtime access and instantiable checks necessary in the code? 192a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool CanAccessInstantiableTypeWithoutChecks(uint32_t referrer_idx, const DexFile& dex_file, 1932cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier uint32_t type_idx) 194a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo LOCKS_EXCLUDED(Locks::mutator_lock_); 195a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 196a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool CanEmbedTypeInCode(const DexFile& dex_file, uint32_t type_idx, 197a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool* is_type_initialized, bool* use_direct_type_ptr, 19813735955f39b3b304c37d2b2840663c131262c18Ian Rogers uintptr_t* direct_type_ptr); 199a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 2004fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi // Can we fast path instance field access in a verified accessor? 2014fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi // If yes, computes field's offset and volatility and whether the method is static or not. 2024fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi static bool ComputeSpecialAccessorInfo(uint32_t field_idx, bool is_put, 2034fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi verifier::MethodVerifier* verifier, 2044fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi InlineIGetIPutData* result) 2054fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 2064fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi 207a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo // Can we fast path instance field access? Computes field's offset and volatility. 208a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo bool ComputeInstanceFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit, bool is_put, 209a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo int* field_offset, bool* is_volatile) 210a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo LOCKS_EXCLUDED(Locks::mutator_lock_); 2114fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi 2124fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi // Can we fastpath static field access? Computes field's offset, volatility and whether the 2134fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi // field is within the referrer (which can avoid checking class initialization). 2144fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi bool ComputeStaticFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit, bool is_put, 2154fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi int* field_offset, int* storage_index, 2164fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi bool* is_referrers_class, bool* is_volatile, bool* is_initialized) 2174fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi LOCKS_EXCLUDED(Locks::mutator_lock_); 2184fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi 21927ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom // Can we fastpath a interface, super class or virtual method call? Computes method's vtable 220ecd3a6fc6e29d7dc4cb825c5282a8054ac52b8cfElliott Hughes // index. 221b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath bool ComputeInvokeInfo(const DexCompilationUnit* mUnit, const uint32_t dex_pc, 222b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath bool update_stats, bool enable_devirtualization, 223b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath InvokeType* type, MethodReference* target_method, int* vtable_idx, 2241d8199d8215a6ee7b1904edc47372d83fcdee5a3Kenny Root uintptr_t* direct_code, uintptr_t* direct_method) 225b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath LOCKS_EXCLUDED(Locks::mutator_lock_); 226b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath 227b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath const VerifiedMethod* GetVerifiedMethod(const DexFile* dex_file, uint32_t method_idx) const; 228b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath bool IsSafeCast(const DexCompilationUnit* mUnit, uint32_t dex_pc); 229b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath 230b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath // Record patch information for later fix up. 231b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath void AddCodePatch(const DexFile* dex_file, 232b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath uint16_t referrer_class_def_idx, 233b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath uint32_t referrer_method_idx, 234b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath InvokeType referrer_invoke_type, 235b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath uint32_t target_method_idx, 236b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath InvokeType target_invoke_type, 237943af7dab1454517c5bd11a31ab99f260afb22d1Christopher Ferris size_t literal_offset) 238a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo LOCKS_EXCLUDED(compiled_methods_lock_); 239b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath void AddRelativeCodePatch(const DexFile* dex_file, 2404fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi uint16_t referrer_class_def_idx, 24127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom uint32_t referrer_method_idx, 24227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom InvokeType referrer_invoke_type, 24338c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier uint32_t target_method_idx, 24438c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier InvokeType target_invoke_type, 24538c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier size_t literal_offset, 24638c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier int32_t pc_relative_offset) 24738c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier LOCKS_EXCLUDED(compiled_methods_lock_); 24838c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier void AddMethodPatch(const DexFile* dex_file, 24938c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier uint16_t referrer_class_def_idx, 25038c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier uint32_t referrer_method_idx, 25138c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier InvokeType referrer_invoke_type, 25238c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier uint32_t target_method_idx, 25338c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier InvokeType target_invoke_type, 25438c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier size_t literal_offset) 25538c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier LOCKS_EXCLUDED(compiled_methods_lock_); 25638c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier void AddClassPatch(const DexFile* dex_file, 25738c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier uint16_t referrer_class_def_idx, 25838c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier uint32_t referrer_method_idx, 25913735955f39b3b304c37d2b2840663c131262c18Ian Rogers uint32_t target_method_idx, 2605c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko size_t literal_offset) 2616a3c1fcb4ba42ad4d5d142c17a3712a6ddd3866fIan Rogers LOCKS_EXCLUDED(compiled_methods_lock_); 2626a3c1fcb4ba42ad4d5d142c17a3712a6ddd3866fIan Rogers 2636a3c1fcb4ba42ad4d5d142c17a3712a6ddd3866fIan Rogers bool GetSupportBootImageFixup() const { 2649004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom return support_boot_image_fixup_; 265a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo } 2669004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom 267ecd3a6fc6e29d7dc4cb825c5282a8054ac52b8cfElliott Hughes void SetSupportBootImageFixup(bool support_boot_image_fixup) { 2686c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes support_boot_image_fixup_ = support_boot_image_fixup; 269997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers } 2705c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko 2715c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko ArenaPool& GetArenaPool() { 2725c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko return arena_pool_; 2735c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko } 2745c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko 275b5505823ad3d0bab8fc9c15c266a3d8cd96ee59eVladimir Marko bool WriteElf(const std::string& android_root, 2765c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko bool is_host, 2775c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko const std::vector<const DexFile*>& dex_files, 2785c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko OatWriter& oat_writer, 279997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers File* file); 280997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers 2816c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes // TODO: move to a common home for llvm helpers once quick/portable are merged 282997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers static void InstructionSetToLLVMTarget(InstructionSet instruction_set, 283997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers std::string& target_triple, 2846c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes std::string& target_cpu, 285997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers std::string& target_attr); 286997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers 287997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers void SetCompilerContext(void* compiler_context) { 288997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers compiler_context_ = compiler_context; 289997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers } 290997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers 291997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers void* GetCompilerContext() const { 292997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers return compiler_context_; 293997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers } 294997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers 295997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers size_t GetThreadCount() const { 296997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers return thread_count_; 297997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers } 298997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers 299997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers class CallPatchInformation; 300997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers class TypePatchInformation; 301997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers 3025c42c29b89286e5efa4a4613132b09051ce5945bVladimir Marko bool GetDumpPasses() const { 303997f0f9e69ce7aee73cebd64be8dc40af9164257Ian Rogers return dump_passes_; 3046c9c06dbb0b16714079afaedbebd3d548aa832b2Elliott Hughes } 3058dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith 306aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom CumulativeLogger& GetTimingsLogger() const { 307aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom return *timings_logger_; 308aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom } 30984d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi 31084d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi class PatchInformation { 31184d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi public: 31284d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi const DexFile& GetDexFile() const { 31384d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi return *dex_file_; 314a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo } 31584d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi uint16_t GetReferrerClassDefIdx() const { 316a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo return referrer_class_def_idx_; 31784d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi } 318a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo uint32_t GetReferrerMethodIdx() const { 31984d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi return referrer_method_idx_; 32084d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi } 32184d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi size_t GetLiteralOffset() const { 32284d49ccd79088eb9a9f423c0a96e3905468cfe7dQiming Shi return literal_offset_; 3238dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith } 3248dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith 3258dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith virtual bool IsCall() const { 3268dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith return false; 327c3ccc1039e0bbc0744f958cb8719cf96bce5b853Ian Rogers } 3288dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith virtual bool IsType() const { 3298dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith return false; 330a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo } 3317104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe virtual const CallPatchInformation* AsCall() const { 3327104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe LOG(FATAL) << "Unreachable"; 3337889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier return nullptr; 33471a3ebabb2a6b4921071d115aa176d8222aeb803Andreas Gampe } 3357889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier virtual const TypePatchInformation* AsType() const { 3367889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier LOG(FATAL) << "Unreachable"; 3377889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier return nullptr; 3387889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier } 3397889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier 3407889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier protected: 3417889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier PatchInformation(const DexFile* dex_file, 3427889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier uint16_t referrer_class_def_idx, 3437889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier uint32_t referrer_method_idx, 3447889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier size_t literal_offset) 3457889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier : dex_file_(dex_file), 3467889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier referrer_class_def_idx_(referrer_class_def_idx), 3477889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier referrer_method_idx_(referrer_method_idx), 3487889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier literal_offset_(literal_offset) { 3497889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier CHECK(dex_file_ != NULL); 3507889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier } 3517889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier virtual ~PatchInformation() {} 3527889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier 3537889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier const DexFile* const dex_file_; 3547889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier const uint16_t referrer_class_def_idx_; 3557889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier const uint32_t referrer_method_idx_; 3567889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier const size_t literal_offset_; 3577889a77e464b820745c9507ccd484f68e7b1c650Mathieu Chartier 35838c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier friend class CompilerDriver; 35938c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier }; 36038c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier 36138c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier class CallPatchInformation : public PatchInformation { 36238c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier public: 36338c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier InvokeType GetReferrerInvokeType() const { 36438c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier return referrer_invoke_type_; 36538c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier } 3667104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe uint32_t GetTargetMethodIdx() const { 3677104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe return target_method_idx_; 3687104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe } 3697104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe InvokeType GetTargetInvokeType() const { 3709de65ff3a9c49b91d80be292020f012f3d0a24efAndreas Gampe return target_invoke_type_; 3717104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe } 3727104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe 3737104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe const CallPatchInformation* AsCall() const { 3747104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe return this; 3757104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe } 3767104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe bool IsCall() const { 3777104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe return true; 3787104cbf9c594563c6daae592b8f38f49a423d12eAndreas Gampe } 3798dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith virtual bool IsRelative() const { 3808dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith return false; 3818dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith } 3828dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith virtual int RelativeOffset() const { 3838dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith return 0; 3848dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith } 3858dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith 3868dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith protected: 3878dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith CallPatchInformation(const DexFile* dex_file, 3888dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith uint16_t referrer_class_def_idx, 3898dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith uint32_t referrer_method_idx, 3908dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith InvokeType referrer_invoke_type, 3918dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith uint32_t target_method_idx, 3928dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith InvokeType target_invoke_type, 3938dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith size_t literal_offset) 3948dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith : PatchInformation(dex_file, referrer_class_def_idx, 39538c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier referrer_method_idx, literal_offset), 39638c8221b8f8bd0411006c44d3126f78eb6a8e9abMathieu Chartier referrer_invoke_type_(referrer_invoke_type), 3978dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith target_method_idx_(target_method_idx), 398c355a2a78d6ebdfdb645221275affb9136b4c667Mathieu Chartier target_invoke_type_(target_invoke_type) { 3998dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith } 4008dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith 4018dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith private: 4028dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith const InvokeType referrer_invoke_type_; 4038dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith const uint32_t target_method_idx_; 4048dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith const InvokeType target_invoke_type_; 4058dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith 4068dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith friend class CompilerDriver; 407aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom DISALLOW_COPY_AND_ASSIGN(CallPatchInformation); 408aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom }; 4098dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith 4108dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith class RelativeCallPatchInformation : public CallPatchInformation { 411a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo public: 412aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom bool IsRelative() const { 4138dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith return true; 4148dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith } 4158dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith int RelativeOffset() const { 416c3ccc1039e0bbc0744f958cb8719cf96bce5b853Ian Rogers return offset_; 417a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo } 418ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 419ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers private: 420ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers RelativeCallPatchInformation(const DexFile* dex_file, 4214fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi uint16_t referrer_class_def_idx, 422a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo uint32_t referrer_method_idx, 423aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom InvokeType referrer_invoke_type, 4248dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith uint32_t target_method_idx, 4258dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith InvokeType target_invoke_type, 42627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom size_t literal_offset, 427a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe int32_t pc_relative_offset) 428aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom : CallPatchInformation(dex_file, referrer_class_def_idx, 429a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe referrer_method_idx, referrer_invoke_type, 430a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe target_method_idx, target_invoke_type, literal_offset), 431a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe offset_(pc_relative_offset) { 4324fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi } 4334fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi 4344fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi const int offset_; 435a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 4368d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers friend class CompilerDriver; 43727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom DISALLOW_COPY_AND_ASSIGN(RelativeCallPatchInformation); 43813735955f39b3b304c37d2b2840663c131262c18Ian Rogers }; 43901d4b5072c064d927260486c891a09fe689289c0Mathieu Chartier 44027ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom class TypePatchInformation : public PatchInformation { 44127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom public: 44249e1fabc85480f01077f3cc10e8ba6ada6e4befaDavid Srbecky uint32_t GetTargetTypeIdx() const { 44349e1fabc85480f01077f3cc10e8ba6ada6e4befaDavid Srbecky return target_type_idx_; 44449e1fabc85480f01077f3cc10e8ba6ada6e4befaDavid Srbecky } 44549e1fabc85480f01077f3cc10e8ba6ada6e4befaDavid Srbecky 44649e1fabc85480f01077f3cc10e8ba6ada6e4befaDavid Srbecky bool IsType() const { 44749e1fabc85480f01077f3cc10e8ba6ada6e4befaDavid Srbecky return true; 44849e1fabc85480f01077f3cc10e8ba6ada6e4befaDavid Srbecky } 44949e1fabc85480f01077f3cc10e8ba6ada6e4befaDavid Srbecky const TypePatchInformation* AsType() const { 4502cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier return this; 4512cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier } 4528d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers 45327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom private: 45427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom TypePatchInformation(const DexFile* dex_file, 455b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath uint16_t referrer_class_def_idx, 456b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath uint32_t referrer_method_idx, 457b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath uint32_t target_type_idx, 4584fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi size_t literal_offset) 4594fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi : PatchInformation(dex_file, referrer_class_def_idx, 4604fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi referrer_method_idx, literal_offset), 461a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo target_type_idx_(target_type_idx) { 462b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath } 463b5505823ad3d0bab8fc9c15c266a3d8cd96ee59eVladimir Marko 4644fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi const uint32_t target_type_idx_; 4654fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi 4664fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi friend class CompilerDriver; 467b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath DISALLOW_COPY_AND_ASSIGN(TypePatchInformation); 468b89c3da592de1a2741a08cc3c8ed2908e8bdd15aNarayan Kamath }; 4694fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi 4704fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi const std::vector<const CallPatchInformation*>& GetCodeToPatch() const { 4719004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom return code_to_patch_; 472a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo } 4739004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom const std::vector<const CallPatchInformation*>& GetMethodsToPatch() const { 474f8adc60455b90c95a6a3c8f87830e4e88b2644e1Ian Rogers return methods_to_patch_; 47527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom } 47627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom const std::vector<const TypePatchInformation*>& GetClassesToPatch() const { 477f8adc60455b90c95a6a3c8f87830e4e88b2644e1Ian Rogers return classes_to_patch_; 478ecd3a6fc6e29d7dc4cb825c5282a8054ac52b8cfElliott Hughes } 479a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 480a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo // Checks if class specified by type_idx is one of the image_classes_ 4812cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier bool IsImageClass(const char* descriptor) const; 4822cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier 4834fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi void RecordClassStatus(ClassReference ref, mirror::Class::Status status) 48413735955f39b3b304c37d2b2840663c131262c18Ian Rogers LOCKS_EXCLUDED(compiled_classes_lock_); 485ecd3a6fc6e29d7dc4cb825c5282a8054ac52b8cfElliott Hughes 48627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom std::vector<uint8_t>* DeduplicateCode(const std::vector<uint8_t>& code); 48727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom std::vector<uint8_t>* DeduplicateMappingTable(const std::vector<uint8_t>& code); 48827ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom std::vector<uint8_t>* DeduplicateVMapTable(const std::vector<uint8_t>& code); 48927ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom std::vector<uint8_t>* DeduplicateGCMap(const std::vector<uint8_t>& code); 49027ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 491aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom private: 492aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom // Compute constant code and method pointers when possible 493a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe void GetCodeAndMethodForDirectCall(InvokeType* type, InvokeType sharp_type, 494aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom bool no_guarantee_of_dex_cache_entry, 495c7cb1901b776129044a4ad3886fd6450e83df681Mathieu Chartier mirror::Class* referrer_class, 496a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe mirror::ArtMethod* method, 4974fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi bool update_stats, 498aa94cf3e77035bf204a21d0341d8f8513a19885cBrian Carlstrom MethodReference* target_method, 499a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe uintptr_t* direct_code, uintptr_t* direct_method) 5004fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 5014fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi 5024fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi void PreCompile(jobject class_loader, const std::vector<const DexFile*>& dex_files, 503a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo ThreadPool& thread_pool, TimingLogger& timings) 5044fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi LOCKS_EXCLUDED(Locks::mutator_lock_); 50527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 5060d6adac2550113da33d42e88f0d87a57b25c5a60Brian Carlstrom void LoadImageClasses(TimingLogger& timings); 507a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 50827ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom // Attempt to resolve all type, methods, fields, and strings 50927ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom // referenced from code in the dex file following PathClassLoader 51027ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom // ordering semantics. 5114fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi void Resolve(jobject class_loader, const std::vector<const DexFile*>& dex_files, 51227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom ThreadPool& thread_pool, TimingLogger& timings) 51327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom LOCKS_EXCLUDED(Locks::mutator_lock_); 514a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo void ResolveDexFile(jobject class_loader, const DexFile& dex_file, 515a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo ThreadPool& thread_pool, TimingLogger& timings) 516a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo LOCKS_EXCLUDED(Locks::mutator_lock_); 517a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 518a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo void Verify(jobject class_loader, const std::vector<const DexFile*>& dex_files, 51927ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom ThreadPool& thread_pool, TimingLogger& timings); 5203eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi void VerifyDexFile(jobject class_loader, const DexFile& dex_file, 5213eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi ThreadPool& thread_pool, TimingLogger& timings) 5223eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi LOCKS_EXCLUDED(Locks::mutator_lock_); 5233eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 5246e88ef6b604a7a945a466784580c42e6554c1289Mathieu Chartier void InitializeClasses(jobject class_loader, const std::vector<const DexFile*>& dex_files, 5256e88ef6b604a7a945a466784580c42e6554c1289Mathieu Chartier ThreadPool& thread_pool, TimingLogger& timings) 5263eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi LOCKS_EXCLUDED(Locks::mutator_lock_); 5273eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi void InitializeClasses(jobject class_loader, const DexFile& dex_file, 5283eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi ThreadPool& thread_pool, TimingLogger& timings) 5296e88ef6b604a7a945a466784580c42e6554c1289Mathieu Chartier LOCKS_EXCLUDED(Locks::mutator_lock_, compiled_classes_lock_); 5303eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 5313eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi void UpdateImageClasses(TimingLogger& timings) 5323eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi LOCKS_EXCLUDED(Locks::mutator_lock_); 5333eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi static void FindClinitImageClassesCallback(mirror::Object* object, void* arg) 53427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 53527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 53613735955f39b3b304c37d2b2840663c131262c18Ian Rogers void Compile(jobject class_loader, const std::vector<const DexFile*>& dex_files, 537a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo ThreadPool& thread_pool, TimingLogger& timings); 5381c23e1edb7361bbaec6e57fca86d8d3797960ad2Mathieu Chartier void CompileDexFile(jobject class_loader, const DexFile& dex_file, 539a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo ThreadPool& thread_pool, TimingLogger& timings) 5409004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom LOCKS_EXCLUDED(Locks::mutator_lock_); 5414fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi void CompileMethod(const DexFile::CodeItem* code_item, uint32_t access_flags, 5424fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi InvokeType invoke_type, uint16_t class_def_idx, uint32_t method_idx, 5439004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom jobject class_loader, const DexFile& dex_file, 5449004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom DexToDexCompilationLevel dex_to_dex_compilation_level) 5454fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi LOCKS_EXCLUDED(compiled_methods_lock_); 5464fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi 5479004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom static void CompileClass(const ParallelCompilationManager* context, size_t class_def_index) 5483eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi LOCKS_EXCLUDED(Locks::mutator_lock_); 5493eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 5503eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi std::vector<const CallPatchInformation*> code_to_patch_; 5516e88ef6b604a7a945a466784580c42e6554c1289Mathieu Chartier std::vector<const CallPatchInformation*> methods_to_patch_; 5526e88ef6b604a7a945a466784580c42e6554c1289Mathieu Chartier std::vector<const TypePatchInformation*> classes_to_patch_; 5539004cb6591781d1e6c5ec6d7bc6dc99d9ecee124Brian Carlstrom 554c8ccf68b805c92674545f63e0341ba47e8d9701cAndreas Gampe VerificationResults* verification_results_; 55527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom DexFileToMethodInlinerMap* method_inliner_map_; 55613735955f39b3b304c37d2b2840663c131262c18Ian Rogers 557fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi UniquePtr<CompilerBackend> compiler_backend_; 558cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier 559cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier const InstructionSet instruction_set_; 56013735955f39b3b304c37d2b2840663c131262c18Ian Rogers const InstructionSetFeatures instruction_set_features_; 561fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 562fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi // All class references that require 56313735955f39b3b304c37d2b2840663c131262c18Ian Rogers mutable ReaderWriterMutex freezing_constructor_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 564fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi std::set<ClassReference> freezing_constructor_classes_ GUARDED_BY(freezing_constructor_lock_); 56513735955f39b3b304c37d2b2840663c131262c18Ian Rogers 56613735955f39b3b304c37d2b2840663c131262c18Ian Rogers typedef SafeMap<const ClassReference, CompiledClass*> ClassTable; 56713735955f39b3b304c37d2b2840663c131262c18Ian Rogers // All class references that this compiler has compiled. 568fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi mutable Mutex compiled_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 569fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi ClassTable compiled_classes_ GUARDED_BY(compiled_classes_lock_); 570a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 571fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi typedef SafeMap<const MethodReference, CompiledMethod*, MethodReferenceComparator> MethodTable; 57213735955f39b3b304c37d2b2840663c131262c18Ian Rogers // All method references that this compiler has compiled. 57313735955f39b3b304c37d2b2840663c131262c18Ian Rogers mutable Mutex compiled_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 57413735955f39b3b304c37d2b2840663c131262c18Ian Rogers MethodTable compiled_methods_ GUARDED_BY(compiled_methods_lock_); 575fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 57613735955f39b3b304c37d2b2840663c131262c18Ian Rogers const bool image_; 577fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 578fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi // If image_ is true, specifies the classes that will be included in 579fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi // the image. Note if image_classes_ is NULL, all classes are 580fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi // included in the image. 581fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi UniquePtr<DescriptorSet> image_classes_; 582fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 583fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi size_t thread_count_; 584fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi uint64_t start_ns_; 585fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 586fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi UniquePtr<AOTCompilationStats> stats_; 5878dba5aaaffc0bc2b2580bf02f0d9095c00d26a17Stuart Monteith 588fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi bool dump_stats_; 589fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi const bool dump_passes_; 590fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 591fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi CumulativeLogger* const timings_logger_; 592fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 593fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi typedef void (*CompilerCallbackFn)(CompilerDriver& driver); 594fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi typedef MutexLock* (*CompilerMutexLockFn)(CompilerDriver& driver); 595fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 596fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi void* compiler_library_; 597fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 598fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi typedef void (*DexToDexCompilerFn)(CompilerDriver& driver, 599fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi const DexFile::CodeItem* code_item, 600fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi uint32_t access_flags, InvokeType invoke_type, 601a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe uint32_t class_dex_idx, uint32_t method_idx, 602a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe jobject class_loader, const DexFile& dex_file, 603a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe DexToDexCompilationLevel dex_to_dex_compilation_level); 604fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi DexToDexCompilerFn dex_to_dex_compiler_; 605fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 606fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi void* compiler_context_; 607fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 608fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi pthread_key_t tls_key_; 609fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 61013735955f39b3b304c37d2b2840663c131262c18Ian Rogers // Arena pool used by the compiler. 611fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi ArenaPool arena_pool_; 612fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi 613a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe typedef void (*CompilerEnableAutoElfLoadingFn)(CompilerDriver& driver); 614a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe CompilerEnableAutoElfLoadingFn compiler_enable_auto_elf_loading_; 615a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe 616a6dfdae1cffc78f9791348b2e1dc8f4c6c3f7128Andreas Gampe typedef const void* (*CompilerGetMethodCodeAddrFn) 617fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi (const CompilerDriver& driver, const CompiledMethod* cm, const mirror::ArtMethod* method); 618fd7e7f1253927c8d7f17e7cbc259daaf51868bd3Hiroshi Yamauchi CompilerGetMethodCodeAddrFn compiler_get_method_code_addr_; 619a62a588a9202f69e53fbeb3045ea8ea5ec2587f8Jim_Guo 620cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier bool support_boot_image_fixup_; 621d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien 622c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers // DeDuplication data structures, these own the corresponding byte arrays. 623c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers class DedupeHashFunc { 624c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers public: 625c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers size_t operator()(const std::vector<uint8_t>& array) const { 626c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers // For small arrays compute a hash using every byte. 627c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers static const size_t kSmallArrayThreshold = 16; 628c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers size_t hash = 0x811c9dc5; 629c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers if (array.size() <= kSmallArrayThreshold) { 630c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers for (uint8_t b : array) { 631c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers hash = (hash * 16777619) ^ b; 632c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers } 633c5f17732d8144491c642776b6b48c85dfadf4b52Ian Rogers } else { 634d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien // For larger arrays use the 2 bytes at 6 bytes (the location of a push registers 6354fb5df8453367aa3f160ac230c03a7a98a28e562Hiroshi Yamauchi // instruction field for quick generated code on ARM) and then select a number of other 6361c849e5badc85b6753dee0c0487729b2c0529f51Ian Rogers // values at random. 637d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien static const size_t kRandomHashCount = 16; 638d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien for (size_t i = 0; i < 2; ++i) { 639d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien uint8_t b = array[i + 6]; 640d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien hash = (hash * 16777619) ^ b; 6411c849e5badc85b6753dee0c0487729b2c0529f51Ian Rogers } 642d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien for (size_t i = 2; i < kRandomHashCount; ++i) { 643d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien size_t r = i * 1103515245 + 12345; 644d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien uint8_t b = array[r % array.size()]; 645a060ed959efb8d57419edc3c5c1fa48372cc6588Shih-wei Liao hash = (hash * 16777619) ^ b; 646a060ed959efb8d57419edc3c5c1fa48372cc6588Shih-wei Liao } 647d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien } 648d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien hash += hash << 13; 649d88fa26892ad5ddebb7ab3407cdc574c54ed8258Logan Chien hash ^= hash >> 7; 6503eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi hash += hash << 3; 6513eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi hash ^= hash >> 17; 6523eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi hash += hash << 5; 6533eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi return hash; 6543eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi } 6553eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi }; 6563eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi DedupeSet<std::vector<uint8_t>, size_t, DedupeHashFunc, 4> dedupe_code_; 6573eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi DedupeSet<std::vector<uint8_t>, size_t, DedupeHashFunc, 4> dedupe_mapping_table_; 6583eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi DedupeSet<std::vector<uint8_t>, size_t, DedupeHashFunc, 4> dedupe_vmap_table_; 6593eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi DedupeSet<std::vector<uint8_t>, size_t, DedupeHashFunc, 4> dedupe_gc_map_; 6603eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 6613eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi DISALLOW_COPY_AND_ASSIGN(CompilerDriver); 6623eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi}; 6633eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 6643eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi} // namespace art 6653eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi 6663eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi#endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_H_ 6673eed93dd5be03e5539827bebf0f414251a12e15eHiroshi Yamauchi