diff options
| author | 2014-01-23 23:57:53 +0000 | |
|---|---|---|
| committer | 2014-01-23 23:57:54 +0000 | |
| commit | 8c95011dad0ea0e3a88775de70256ace93488baf (patch) | |
| tree | d6ec71e2b86c74fd9bdc8c438d380d9d0f95c410 /compiler/driver/compiler_driver.cc | |
| parent | 2eea3f3c8ca18cd464fcb479acd6e2a2eea4f6c8 (diff) | |
| parent | be1ca55db3362f5b100c4c65da5342fd299520bb (diff) | |
Merge "Use direct class pointers at allocation sites in the compiled code."
Diffstat (limited to 'compiler/driver/compiler_driver.cc')
| -rw-r--r-- | compiler/driver/compiler_driver.cc | 89 |
1 files changed, 75 insertions, 14 deletions
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index f713151dc5..f390b4143f 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -439,6 +439,10 @@ CompilerDriver::~CompilerDriver() { MutexLock mu(self, compiled_methods_lock_); STLDeleteElements(&methods_to_patch_); } + { + MutexLock mu(self, compiled_methods_lock_); + STLDeleteElements(&classes_to_patch_); + } CHECK_PTHREAD_CALL(pthread_key_delete, (tls_key_), "delete tls key"); typedef void (*UninitCompilerContextFn)(CompilerDriver&); UninitCompilerContextFn uninit_compiler_context; @@ -906,6 +910,51 @@ bool CompilerDriver::CanAccessInstantiableTypeWithoutChecks(uint32_t referrer_id return result; } +bool CompilerDriver::CanEmbedTypeInCode(const DexFile& dex_file, uint32_t type_idx, + bool* is_type_initialized, bool* use_direct_type_ptr, + uintptr_t* direct_type_ptr) { + ScopedObjectAccess soa(Thread::Current()); + mirror::DexCache* dex_cache = Runtime::Current()->GetClassLinker()->FindDexCache(dex_file); + mirror::Class* resolved_class = dex_cache->GetResolvedType(type_idx); + if (resolved_class == nullptr) { + return false; + } + const bool compiling_boot = Runtime::Current()->GetHeap()->IsCompilingBoot(); + if (compiling_boot) { + // boot -> boot class pointers. + // True if the class is in the image at boot compiling time. + const bool is_image_class = IsImage() && IsImageClass( + dex_file.StringDataByIdx(dex_file.GetTypeId(type_idx).descriptor_idx_)); + // True if pc relative load works. + const bool support_boot_image_fixup = GetSupportBootImageFixup(); + if (is_image_class && support_boot_image_fixup) { + *is_type_initialized = resolved_class->IsInitialized(); + *use_direct_type_ptr = false; + *direct_type_ptr = 0; + return true; + } else { + return false; + } + } else { + // True if the class is in the image at app compiling time. + const bool class_in_image = + Runtime::Current()->GetHeap()->FindSpaceFromObject(resolved_class, false)->IsImageSpace(); + if (class_in_image) { + // boot -> app class pointers. + *is_type_initialized = resolved_class->IsInitialized(); + *use_direct_type_ptr = true; + *direct_type_ptr = reinterpret_cast<uintptr_t>(resolved_class); + return true; + } else { + // app -> app class pointers. + // Give up because app does not have an image and class + // isn't created at compile time. TODO: implement this + // if/when each app gets an image. + return false; + } + } +} + static mirror::Class* ComputeCompilingMethodsClass(ScopedObjectAccess& soa, SirtRef<mirror::DexCache>& dex_cache, const DexCompilationUnit* mUnit) @@ -1291,13 +1340,13 @@ void CompilerDriver::AddCodePatch(const DexFile* dex_file, InvokeType target_invoke_type, size_t literal_offset) { MutexLock mu(Thread::Current(), compiled_methods_lock_); - code_to_patch_.push_back(new PatchInformation(dex_file, - referrer_class_def_idx, - referrer_method_idx, - referrer_invoke_type, - target_method_idx, - target_invoke_type, - literal_offset)); + code_to_patch_.push_back(new CallPatchInformation(dex_file, + referrer_class_def_idx, + referrer_method_idx, + referrer_invoke_type, + target_method_idx, + target_invoke_type, + literal_offset)); } void CompilerDriver::AddMethodPatch(const DexFile* dex_file, uint16_t referrer_class_def_idx, @@ -1307,13 +1356,25 @@ void CompilerDriver::AddMethodPatch(const DexFile* dex_file, InvokeType target_invoke_type, size_t literal_offset) { MutexLock mu(Thread::Current(), compiled_methods_lock_); - methods_to_patch_.push_back(new PatchInformation(dex_file, - referrer_class_def_idx, - referrer_method_idx, - referrer_invoke_type, - target_method_idx, - target_invoke_type, - literal_offset)); + methods_to_patch_.push_back(new CallPatchInformation(dex_file, + referrer_class_def_idx, + referrer_method_idx, + referrer_invoke_type, + target_method_idx, + target_invoke_type, + literal_offset)); +} +void CompilerDriver::AddClassPatch(const DexFile* dex_file, + uint16_t referrer_class_def_idx, + uint32_t referrer_method_idx, + uint32_t target_type_idx, + size_t literal_offset) { + MutexLock mu(Thread::Current(), compiled_methods_lock_); + classes_to_patch_.push_back(new TypePatchInformation(dex_file, + referrer_class_def_idx, + referrer_method_idx, + target_type_idx, + literal_offset)); } class ParallelCompilationManager { |