diff options
author | 2015-05-06 14:12:42 +0100 | |
---|---|---|
committer | 2015-08-19 12:23:37 +0100 | |
commit | 9b688a095afbae21112df5d495487ac5231b12d0 (patch) | |
tree | e5e881d4d124803e66f1e90c1e0a0e4c90d22e13 /compiler/optimizing/builder.cc | |
parent | 009c34cba875885d9540696f33255a9b355d6e15 (diff) |
Optimizing: Better invoke-static/-direct dispatch.
Add framework for different types of loading ArtMethod*
and code pointer retrieval. Implement invoke-static and
invoke-direct calls the same way as Quick. Document the
dispatch kinds in HInvokeStaticOrDirect's new enumerations
MethodLoadKind and CodePtrLocation.
PC-relative loads from dex cache arrays are used only for
x86-64 and arm64. The implementation for other architectures
will be done in separate CLs.
Change-Id: I468ca4d422dbd14748e1ba6b45289f0d31734d94
Diffstat (limited to 'compiler/optimizing/builder.cc')
-rw-r--r-- | compiler/optimizing/builder.cc | 89 |
1 files changed, 80 insertions, 9 deletions
diff --git a/compiler/optimizing/builder.cc b/compiler/optimizing/builder.cc index 88414980b8..cae3da357b 100644 --- a/compiler/optimizing/builder.cc +++ b/compiler/optimizing/builder.cc @@ -31,6 +31,7 @@ #include "primitive.h" #include "scoped_thread_state_change.h" #include "thread.h" +#include "utils/dex_cache_arrays_layout-inl.h" namespace art { @@ -786,6 +787,77 @@ void HGraphBuilder::PotentiallySimplifyFakeString(uint16_t original_dex_register } } +HInvokeStaticOrDirect::DispatchInfo HGraphBuilder::ComputeDispatchInfo( + bool is_string_init, + int32_t string_init_offset, + MethodReference target_method, + uintptr_t direct_method, + uintptr_t direct_code) { + HInvokeStaticOrDirect::MethodLoadKind method_load_kind; + HInvokeStaticOrDirect::CodePtrLocation code_ptr_location; + uint64_t method_load_data = 0u; + uint64_t direct_code_ptr = 0u; + + if (is_string_init) { + // TODO: Use direct_method and direct_code for the appropriate StringFactory method. + method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kStringInit; + code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; + method_load_data = string_init_offset; + } else if (target_method.dex_file == outer_compilation_unit_->GetDexFile() && + target_method.dex_method_index == outer_compilation_unit_->GetDexMethodIndex()) { + method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kRecursive; + code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallSelf; + } else { + if (direct_method != 0u) { // Should we use a direct pointer to the method? + if (direct_method != static_cast<uintptr_t>(-1)) { // Is the method pointer known now? + method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress; + method_load_data = direct_method; + } else { // The direct pointer will be known at link time. + method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup; + } + } else { // Use dex cache. + DCHECK(target_method.dex_file == dex_compilation_unit_->GetDexFile()); + DexCacheArraysLayout layout = + compiler_driver_->GetDexCacheArraysLayout(target_method.dex_file); + if (layout.Valid()) { // Can we use PC-relative access to the dex cache arrays? + method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative; + method_load_data = layout.MethodOffset(target_method.dex_method_index); + } else { // We must go through the ArtMethod's pointer to resolved methods. + method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; + } + } + if (direct_code != 0u) { // Should we use a direct pointer to the code? + if (direct_code != static_cast<uintptr_t>(-1)) { // Is the code pointer known now? + code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallDirect; + direct_code_ptr = direct_code; + } else if (compiler_driver_->IsImage() || + target_method.dex_file == dex_compilation_unit_->GetDexFile()) { + // Use PC-relative calls for invokes within a multi-dex oat file. + // TODO: Recognize when the target dex file is within the current oat file for + // app compilation. At the moment we recognize only the boot image as multi-dex. + // NOTE: This will require changing the ARM backend which currently falls + // through from kCallPCRelative to kDirectCodeFixup for different dex files. + code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative; + } else { // The direct pointer will be known at link time. + // NOTE: This is used for app->boot calls when compiling an app against + // a relocatable but not yet relocated image. + code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup; + } + } else { // We must use the code pointer from the ArtMethod. + code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; + } + } + + if (graph_->IsDebuggable()) { + // For debuggable apps always use the code pointer from ArtMethod + // so that we don't circumvent instrumentation stubs if installed. + code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; + } + + return HInvokeStaticOrDirect::DispatchInfo { + method_load_kind, code_ptr_location, method_load_data, direct_code_ptr }; +} + bool HGraphBuilder::BuildInvoke(const Instruction& instruction, uint32_t dex_pc, uint32_t method_idx, @@ -879,12 +951,6 @@ bool HGraphBuilder::BuildInvoke(const Instruction& instruction, arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); } else { DCHECK(optimized_invoke_type == kDirect || optimized_invoke_type == kStatic); - // Sharpening to kDirect only works if we compile PIC. - DCHECK((optimized_invoke_type == invoke_type) || (optimized_invoke_type != kDirect) - || compiler_driver_->GetCompilerOptions().GetCompilePic()); - bool is_recursive = - (target_method.dex_method_index == outer_compilation_unit_->GetDexMethodIndex()) - && (target_method.dex_file == outer_compilation_unit_->GetDexFile()); if (optimized_invoke_type == kStatic && !is_string_init) { ScopedObjectAccess soa(Thread::Current()); @@ -958,13 +1024,18 @@ bool HGraphBuilder::BuildInvoke(const Instruction& instruction, } } + HInvokeStaticOrDirect::DispatchInfo dispatch_info = ComputeDispatchInfo(is_string_init, + string_init_offset, + target_method, + direct_method, + direct_code); invoke = new (arena_) HInvokeStaticOrDirect(arena_, number_of_arguments, return_type, dex_pc, - target_method.dex_method_index, - is_recursive, - string_init_offset, + method_idx, + target_method, + dispatch_info, invoke_type, optimized_invoke_type, clinit_check_requirement); |