Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "sharpening.h" |
| 18 | |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 19 | #include "base/casts.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 20 | #include "base/enums.h" |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 21 | #include "class_linker.h" |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 22 | #include "code_generator.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 23 | #include "driver/compiler_options.h" |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 24 | #include "driver/dex_compilation_unit.h" |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 25 | #include "utils/dex_cache_arrays_layout-inl.h" |
| 26 | #include "driver/compiler_driver.h" |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 27 | #include "gc/heap.h" |
| 28 | #include "gc/space/image_space.h" |
| 29 | #include "handle_scope-inl.h" |
| 30 | #include "mirror/dex_cache.h" |
| 31 | #include "mirror/string.h" |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 32 | #include "nodes.h" |
Vladimir Marko | d1eaf0d | 2015-10-29 12:18:29 +0000 | [diff] [blame] | 33 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 34 | #include "scoped_thread_state_change-inl.h" |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 35 | |
| 36 | namespace art { |
| 37 | |
| 38 | void HSharpening::Run() { |
| 39 | // We don't care about the order of the blocks here. |
| 40 | for (HBasicBlock* block : graph_->GetReversePostOrder()) { |
| 41 | for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { |
| 42 | HInstruction* instruction = it.Current(); |
| 43 | if (instruction->IsInvokeStaticOrDirect()) { |
| 44 | ProcessInvokeStaticOrDirect(instruction->AsInvokeStaticOrDirect()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 45 | } else if (instruction->IsLoadClass()) { |
| 46 | ProcessLoadClass(instruction->AsLoadClass()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 47 | } else if (instruction->IsLoadString()) { |
| 48 | ProcessLoadString(instruction->AsLoadString()); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 49 | } |
| 50 | // TODO: Move the sharpening of invoke-virtual/-interface/-super from HGraphBuilder |
| 51 | // here. Rewrite it to avoid the CompilerDriver's reliance on verifier data |
| 52 | // because we know the type better when inlining. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | void HSharpening::ProcessInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 58 | if (invoke->IsStringInit()) { |
| 59 | // Not using the dex cache arrays. But we could still try to use a better dispatch... |
| 60 | // TODO: Use direct_method and direct_code for the appropriate StringFactory method. |
| 61 | return; |
| 62 | } |
| 63 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 64 | HGraph* outer_graph = codegen_->GetGraph(); |
| 65 | ArtMethod* compiling_method = graph_->GetArtMethod(); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 66 | |
| 67 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind; |
| 68 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location; |
| 69 | uint64_t method_load_data = 0u; |
| 70 | uint64_t direct_code_ptr = 0u; |
| 71 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 72 | if (invoke->GetResolvedMethod() == outer_graph->GetArtMethod()) { |
| 73 | DCHECK(outer_graph->GetArtMethod() != nullptr); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 74 | method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kRecursive; |
| 75 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallSelf; |
| 76 | } else { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 77 | uintptr_t direct_code, direct_method; |
| 78 | { |
| 79 | ScopedObjectAccess soa(Thread::Current()); |
| 80 | compiler_driver_->GetCodeAndMethodForDirectCall( |
| 81 | (compiling_method == nullptr) ? nullptr : compiling_method->GetDeclaringClass(), |
| 82 | invoke->GetResolvedMethod(), |
| 83 | &direct_code, |
| 84 | &direct_method); |
| 85 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 86 | if (direct_method != 0u) { // Should we use a direct pointer to the method? |
Vladimir Marko | d1eaf0d | 2015-10-29 12:18:29 +0000 | [diff] [blame] | 87 | // Note: For JIT, kDirectAddressWithFixup doesn't make sense at all and while |
| 88 | // kDirectAddress would be fine for image methods, we don't support it at the moment. |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 89 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 90 | if (direct_method != static_cast<uintptr_t>(-1)) { // Is the method pointer known now? |
| 91 | method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress; |
| 92 | method_load_data = direct_method; |
| 93 | } else { // The direct pointer will be known at link time. |
| 94 | method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup; |
| 95 | } |
| 96 | } else { // Use dex cache. |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 97 | if (!Runtime::Current()->UseJitCompilation()) { |
| 98 | // Use PC-relative access to the dex cache arrays. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 99 | method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative; |
Vladimir Marko | d1eaf0d | 2015-10-29 12:18:29 +0000 | [diff] [blame] | 100 | DexCacheArraysLayout layout(GetInstructionSetPointerSize(codegen_->GetInstructionSet()), |
| 101 | &graph_->GetDexFile()); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 102 | method_load_data = layout.MethodOffset(invoke->GetDexMethodIndex()); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 103 | } else { // We must go through the ArtMethod's pointer to resolved methods. |
| 104 | method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 105 | } |
| 106 | } |
| 107 | if (direct_code != 0u) { // Should we use a direct pointer to the code? |
Vladimir Marko | d1eaf0d | 2015-10-29 12:18:29 +0000 | [diff] [blame] | 108 | // Note: For JIT, kCallPCRelative and kCallDirectWithFixup don't make sense at all and |
| 109 | // while kCallDirect would be fine for image methods, we don't support it at the moment. |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 110 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 111 | const DexFile* dex_file_of_callee = invoke->GetTargetMethod().dex_file; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 112 | if (direct_code != static_cast<uintptr_t>(-1)) { // Is the code pointer known now? |
| 113 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallDirect; |
| 114 | direct_code_ptr = direct_code; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 115 | } else if (ContainsElement(compiler_driver_->GetDexFilesForOatFile(), dex_file_of_callee)) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 116 | // Use PC-relative calls for invokes within a multi-dex oat file. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 117 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative; |
| 118 | } else { // The direct pointer will be known at link time. |
| 119 | // NOTE: This is used for app->boot calls when compiling an app against |
| 120 | // a relocatable but not yet relocated image. |
| 121 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup; |
| 122 | } |
| 123 | } else { // We must use the code pointer from the ArtMethod. |
| 124 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if (graph_->IsDebuggable()) { |
| 129 | // For debuggable apps always use the code pointer from ArtMethod |
| 130 | // so that we don't circumvent instrumentation stubs if installed. |
| 131 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 132 | } |
| 133 | |
| 134 | HInvokeStaticOrDirect::DispatchInfo desired_dispatch_info = { |
| 135 | method_load_kind, code_ptr_location, method_load_data, direct_code_ptr |
| 136 | }; |
| 137 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 138 | codegen_->GetSupportedInvokeStaticOrDirectDispatch(desired_dispatch_info, invoke); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 139 | invoke->SetDispatchInfo(dispatch_info); |
| 140 | } |
| 141 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 142 | void HSharpening::ProcessLoadClass(HLoadClass* load_class) { |
Mathieu Chartier | 4a4a601 | 2016-09-16 14:16:42 -0700 | [diff] [blame] | 143 | DCHECK(load_class->GetLoadKind() == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 144 | load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) |
| 145 | << load_class->GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 146 | DCHECK(!load_class->IsInDexCache()) << "HLoadClass should not be optimized before sharpening."; |
Mathieu Chartier | 4a4a601 | 2016-09-16 14:16:42 -0700 | [diff] [blame] | 147 | DCHECK(!load_class->IsInBootImage()) << "HLoadClass should not be optimized before sharpening."; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 148 | |
| 149 | const DexFile& dex_file = load_class->GetDexFile(); |
| 150 | uint32_t type_index = load_class->GetTypeIndex(); |
| 151 | |
| 152 | bool is_in_dex_cache = false; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 153 | bool is_in_boot_image = false; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 154 | HLoadClass::LoadKind desired_load_kind; |
| 155 | uint64_t address = 0u; // Class or dex cache element address. |
| 156 | { |
| 157 | ScopedObjectAccess soa(Thread::Current()); |
| 158 | StackHandleScope<1> hs(soa.Self()); |
| 159 | Runtime* runtime = Runtime::Current(); |
| 160 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 161 | Handle<mirror::DexCache> dex_cache = IsSameDexFile(dex_file, *compilation_unit_.GetDexFile()) |
| 162 | ? compilation_unit_.GetDexCache() |
| 163 | : hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file)); |
| 164 | mirror::Class* klass = dex_cache->GetResolvedType(type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 165 | if (codegen_->GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 166 | // Compiling boot image. Check if the class is a boot image class. |
| 167 | DCHECK(!runtime->UseJitCompilation()); |
| 168 | if (!compiler_driver_->GetSupportBootImageFixup()) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 169 | // MIPS64 or compiler_driver_test. Do not sharpen. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 170 | desired_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 171 | } else if ((klass != nullptr) && compiler_driver_->IsImageClass( |
| 172 | dex_file.StringDataByIdx(dex_file.GetTypeId(type_index).descriptor_idx_))) { |
| 173 | is_in_boot_image = true; |
| 174 | is_in_dex_cache = true; |
| 175 | desired_load_kind = codegen_->GetCompilerOptions().GetCompilePic() |
| 176 | ? HLoadClass::LoadKind::kBootImageLinkTimePcRelative |
| 177 | : HLoadClass::LoadKind::kBootImageLinkTimeAddress; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 178 | } else { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 179 | // Not a boot image class. We must go through the dex cache. |
| 180 | DCHECK(ContainsElement(compiler_driver_->GetDexFilesForOatFile(), &dex_file)); |
| 181 | desired_load_kind = HLoadClass::LoadKind::kDexCachePcRelative; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 182 | } |
| 183 | } else { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 184 | is_in_boot_image = (klass != nullptr) && runtime->GetHeap()->ObjectIsInBootImageSpace(klass); |
| 185 | if (runtime->UseJitCompilation()) { |
| 186 | // TODO: Make sure we don't set the "compile PIC" flag for JIT as that's bogus. |
| 187 | // DCHECK(!codegen_->GetCompilerOptions().GetCompilePic()); |
| 188 | is_in_dex_cache = (klass != nullptr); |
| 189 | if (is_in_boot_image) { |
| 190 | // TODO: Use direct pointers for all non-moving spaces, not just boot image. Bug: 29530787 |
| 191 | desired_load_kind = HLoadClass::LoadKind::kBootImageAddress; |
| 192 | address = reinterpret_cast64<uint64_t>(klass); |
| 193 | } else { |
| 194 | // Note: If the class is not in the dex cache or isn't initialized, the |
| 195 | // instruction needs environment and will not be inlined across dex files. |
| 196 | // Within a dex file, the slow-path helper loads the correct class and |
| 197 | // inlined frames are used correctly for OOM stack trace. |
| 198 | // TODO: Write a test for this. Bug: 29416588 |
| 199 | desired_load_kind = HLoadClass::LoadKind::kDexCacheAddress; |
| 200 | void* dex_cache_element_address = &dex_cache->GetResolvedTypes()[type_index]; |
| 201 | address = reinterpret_cast64<uint64_t>(dex_cache_element_address); |
| 202 | } |
| 203 | // AOT app compilation. Check if the class is in the boot image. |
| 204 | } else if (is_in_boot_image && !codegen_->GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 205 | desired_load_kind = HLoadClass::LoadKind::kBootImageAddress; |
| 206 | address = reinterpret_cast64<uint64_t>(klass); |
| 207 | } else { |
| 208 | // Not JIT and either the klass is not in boot image or we are compiling in PIC mode. |
| 209 | // Use PC-relative load from the dex cache if the dex file belongs |
| 210 | // to the oat file that we're currently compiling. |
| 211 | desired_load_kind = |
| 212 | ContainsElement(compiler_driver_->GetDexFilesForOatFile(), &load_class->GetDexFile()) |
| 213 | ? HLoadClass::LoadKind::kDexCachePcRelative |
| 214 | : HLoadClass::LoadKind::kDexCacheViaMethod; |
| 215 | } |
| 216 | } |
| 217 | } |
Mathieu Chartier | 4a4a601 | 2016-09-16 14:16:42 -0700 | [diff] [blame] | 218 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 219 | if (is_in_boot_image) { |
| 220 | load_class->MarkInBootImage(); |
| 221 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 222 | |
Mathieu Chartier | 4a4a601 | 2016-09-16 14:16:42 -0700 | [diff] [blame] | 223 | if (load_class->NeedsAccessCheck()) { |
| 224 | // We need to call the runtime anyway, so we simply get the class as that call's return value. |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | if (load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) { |
| 229 | // Loading from the ArtMethod* is the most efficient retrieval in code size. |
| 230 | // TODO: This may not actually be true for all architectures and |
| 231 | // locations of target classes. The additional register pressure |
| 232 | // for using the ArtMethod* should be considered. |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | if (is_in_dex_cache) { |
| 237 | load_class->MarkInDexCache(); |
| 238 | } |
| 239 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 240 | HLoadClass::LoadKind load_kind = codegen_->GetSupportedLoadClassKind(desired_load_kind); |
| 241 | switch (load_kind) { |
| 242 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 243 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 244 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 245 | load_class->SetLoadKindWithTypeReference(load_kind, dex_file, type_index); |
| 246 | break; |
| 247 | case HLoadClass::LoadKind::kBootImageAddress: |
| 248 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 249 | DCHECK_NE(address, 0u); |
| 250 | load_class->SetLoadKindWithAddress(load_kind, address); |
| 251 | break; |
| 252 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 253 | PointerSize pointer_size = InstructionSetPointerSize(codegen_->GetInstructionSet()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 254 | DexCacheArraysLayout layout(pointer_size, &dex_file); |
| 255 | size_t element_index = layout.TypeOffset(type_index); |
| 256 | load_class->SetLoadKindWithDexCacheReference(load_kind, dex_file, element_index); |
| 257 | break; |
| 258 | } |
| 259 | default: |
| 260 | LOG(FATAL) << "Unexpected load kind: " << load_kind; |
| 261 | UNREACHABLE(); |
| 262 | } |
| 263 | } |
| 264 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 265 | void HSharpening::ProcessLoadString(HLoadString* load_string) { |
| 266 | DCHECK_EQ(load_string->GetLoadKind(), HLoadString::LoadKind::kDexCacheViaMethod); |
| 267 | DCHECK(!load_string->IsInDexCache()); |
| 268 | |
| 269 | const DexFile& dex_file = load_string->GetDexFile(); |
| 270 | uint32_t string_index = load_string->GetStringIndex(); |
| 271 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 272 | HLoadString::LoadKind desired_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 273 | uint64_t address = 0u; // String or dex cache element address. |
| 274 | { |
| 275 | Runtime* runtime = Runtime::Current(); |
| 276 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 277 | ScopedObjectAccess soa(Thread::Current()); |
| 278 | StackHandleScope<1> hs(soa.Self()); |
| 279 | Handle<mirror::DexCache> dex_cache = IsSameDexFile(dex_file, *compilation_unit_.GetDexFile()) |
| 280 | ? compilation_unit_.GetDexCache() |
| 281 | : hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file)); |
| 282 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 283 | if (codegen_->GetCompilerOptions().IsBootImage()) { |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 284 | // Compiling boot image. Resolve the string and allocate it if needed. |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 285 | DCHECK(!runtime->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 286 | mirror::String* string = class_linker->ResolveString(dex_file, string_index, dex_cache); |
| 287 | CHECK(string != nullptr); |
Vladimir Marko | 9502687 | 2016-09-09 09:16:31 +0000 | [diff] [blame] | 288 | if (compiler_driver_->GetSupportBootImageFixup()) { |
| 289 | DCHECK(ContainsElement(compiler_driver_->GetDexFilesForOatFile(), &dex_file)); |
| 290 | desired_load_kind = codegen_->GetCompilerOptions().GetCompilePic() |
| 291 | ? HLoadString::LoadKind::kBootImageLinkTimePcRelative |
| 292 | : HLoadString::LoadKind::kBootImageLinkTimeAddress; |
| 293 | } else { |
| 294 | // MIPS64 or compiler_driver_test. Do not sharpen. |
| 295 | DCHECK_EQ(desired_load_kind, HLoadString::LoadKind::kDexCacheViaMethod); |
| 296 | } |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 297 | } else if (runtime->UseJitCompilation()) { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 298 | // TODO: Make sure we don't set the "compile PIC" flag for JIT as that's bogus. |
Christina Wadsworth | 5a5d0fa | 2016-08-19 14:38:01 -0700 | [diff] [blame] | 299 | // DCHECK(!codegen_->GetCompilerOptions().GetCompilePic()); |
Nicolas Geoffray | 3395fbc | 2016-11-14 12:40:52 +0000 | [diff] [blame] | 300 | mirror::String* string = dex_cache->GetResolvedString(string_index); |
| 301 | if (string != nullptr && runtime->GetHeap()->ObjectIsInBootImageSpace(string)) { |
| 302 | desired_load_kind = HLoadString::LoadKind::kBootImageAddress; |
| 303 | address = reinterpret_cast64<uint64_t>(string); |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 304 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 305 | } else { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 306 | // AOT app compilation. Try to lookup the string without allocating if not found. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 307 | mirror::String* string = class_linker->LookupString(dex_file, string_index, dex_cache); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 308 | if (string != nullptr && |
| 309 | runtime->GetHeap()->ObjectIsInBootImageSpace(string) && |
| 310 | !codegen_->GetCompilerOptions().GetCompilePic()) { |
| 311 | desired_load_kind = HLoadString::LoadKind::kBootImageAddress; |
| 312 | address = reinterpret_cast64<uint64_t>(string); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 313 | } else { |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 314 | desired_load_kind = HLoadString::LoadKind::kBssEntry; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 318 | |
| 319 | HLoadString::LoadKind load_kind = codegen_->GetSupportedLoadStringKind(desired_load_kind); |
| 320 | switch (load_kind) { |
| 321 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 322 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 323 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 324 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 325 | load_string->SetLoadKindWithStringReference(load_kind, dex_file, string_index); |
| 326 | break; |
| 327 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 328 | DCHECK_NE(address, 0u); |
| 329 | load_string->SetLoadKindWithAddress(load_kind, address); |
| 330 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 334 | } // namespace art |