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 | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 45 | } else if (instruction->IsLoadString()) { |
| 46 | ProcessLoadString(instruction->AsLoadString()); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 47 | } |
| 48 | // TODO: Move the sharpening of invoke-virtual/-interface/-super from HGraphBuilder |
| 49 | // here. Rewrite it to avoid the CompilerDriver's reliance on verifier data |
| 50 | // because we know the type better when inlining. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 55 | static bool IsInBootImage(ArtMethod* method) { |
| 56 | const std::vector<gc::space::ImageSpace*>& image_spaces = |
| 57 | Runtime::Current()->GetHeap()->GetBootImageSpaces(); |
| 58 | for (gc::space::ImageSpace* image_space : image_spaces) { |
| 59 | const auto& method_section = image_space->GetImageHeader().GetMethodsSection(); |
| 60 | if (method_section.Contains(reinterpret_cast<uint8_t*>(method) - image_space->Begin())) { |
| 61 | return true; |
| 62 | } |
| 63 | } |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | static bool AOTCanEmbedMethod(ArtMethod* method, const CompilerOptions& options) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame^] | 68 | return IsInBootImage(method) && !options.GetCompilePic(); |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 71 | void HSharpening::ProcessInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 72 | if (invoke->IsStringInit()) { |
| 73 | // Not using the dex cache arrays. But we could still try to use a better dispatch... |
| 74 | // TODO: Use direct_method and direct_code for the appropriate StringFactory method. |
| 75 | return; |
| 76 | } |
| 77 | |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 78 | ArtMethod* callee = invoke->GetResolvedMethod(); |
| 79 | DCHECK(callee != nullptr); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 80 | |
| 81 | HInvokeStaticOrDirect::MethodLoadKind method_load_kind; |
| 82 | HInvokeStaticOrDirect::CodePtrLocation code_ptr_location; |
| 83 | uint64_t method_load_data = 0u; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 84 | |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 85 | // Note: we never call an ArtMethod through a known code pointer, as |
| 86 | // we do not want to keep on invoking it if it gets deoptimized. This |
| 87 | // applies to both AOT and JIT. |
| 88 | // This also avoids having to find out if the code pointer of an ArtMethod |
| 89 | // is the resolution trampoline (for ensuring the class is initialized), or |
| 90 | // the interpreter entrypoint. Such code pointers we do not want to call |
| 91 | // directly. |
| 92 | // Only in the case of a recursive call can we call directly, as we know the |
| 93 | // class is initialized already or being initialized, and the call will not |
| 94 | // be invoked once the method is deoptimized. |
| 95 | |
Alex Light | 1ebe4fe | 2017-01-30 14:57:11 -0800 | [diff] [blame] | 96 | // We don't optimize for debuggable as it would prevent us from obsoleting the method in some |
| 97 | // situations. |
| 98 | if (callee == codegen_->GetGraph()->GetArtMethod() && !codegen_->GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 99 | // Recursive call. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 100 | method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kRecursive; |
| 101 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallSelf; |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 102 | } else if (Runtime::Current()->UseJitCompilation() || |
| 103 | AOTCanEmbedMethod(callee, codegen_->GetCompilerOptions())) { |
| 104 | // JIT or on-device AOT compilation referencing a boot image method. |
| 105 | // Use the method address directly. |
| 106 | method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress; |
| 107 | method_load_data = reinterpret_cast<uintptr_t>(callee); |
| 108 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 109 | } else { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 110 | // Use PC-relative access to the dex cache arrays. |
| 111 | method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative; |
| 112 | DexCacheArraysLayout layout(GetInstructionSetPointerSize(codegen_->GetInstructionSet()), |
| 113 | &graph_->GetDexFile()); |
| 114 | method_load_data = layout.MethodOffset(invoke->GetDexMethodIndex()); |
| 115 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (graph_->IsDebuggable()) { |
| 119 | // For debuggable apps always use the code pointer from ArtMethod |
| 120 | // so that we don't circumvent instrumentation stubs if installed. |
| 121 | code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; |
| 122 | } |
| 123 | |
| 124 | HInvokeStaticOrDirect::DispatchInfo desired_dispatch_info = { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 125 | method_load_kind, code_ptr_location, method_load_data |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 126 | }; |
| 127 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 128 | codegen_->GetSupportedInvokeStaticOrDirectDispatch(desired_dispatch_info, invoke); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 129 | invoke->SetDispatchInfo(dispatch_info); |
| 130 | } |
| 131 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 132 | HLoadClass::LoadKind HSharpening::SharpenClass(HLoadClass* load_class, |
| 133 | CodeGenerator* codegen, |
| 134 | CompilerDriver* compiler_driver, |
| 135 | const DexCompilationUnit& dex_compilation_unit) { |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 136 | Handle<mirror::Class> klass = load_class->GetClass(); |
Mathieu Chartier | 4a4a601 | 2016-09-16 14:16:42 -0700 | [diff] [blame] | 137 | DCHECK(load_class->GetLoadKind() == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 138 | load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) |
| 139 | << load_class->GetLoadKind(); |
Mathieu Chartier | 4a4a601 | 2016-09-16 14:16:42 -0700 | [diff] [blame] | 140 | DCHECK(!load_class->IsInBootImage()) << "HLoadClass should not be optimized before sharpening."; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 141 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 142 | HLoadClass::LoadKind load_kind = load_class->GetLoadKind(); |
| 143 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 144 | if (load_class->NeedsAccessCheck()) { |
| 145 | // We need to call the runtime anyway, so we simply get the class as that call's return value. |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 146 | } else if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 147 | // Loading from the ArtMethod* is the most efficient retrieval in code size. |
| 148 | // TODO: This may not actually be true for all architectures and |
| 149 | // locations of target classes. The additional register pressure |
| 150 | // for using the ArtMethod* should be considered. |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 151 | } else { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 152 | const DexFile& dex_file = load_class->GetDexFile(); |
| 153 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 154 | |
| 155 | bool is_in_boot_image = false; |
| 156 | HLoadClass::LoadKind desired_load_kind = HLoadClass::LoadKind::kInvalid; |
| 157 | Runtime* runtime = Runtime::Current(); |
| 158 | if (codegen->GetCompilerOptions().IsBootImage()) { |
| 159 | // Compiling boot image. Check if the class is a boot image class. |
| 160 | DCHECK(!runtime->UseJitCompilation()); |
| 161 | if (!compiler_driver->GetSupportBootImageFixup()) { |
| 162 | // compiler_driver_test. Do not sharpen. |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 163 | desired_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 164 | } else if ((klass != nullptr) && compiler_driver->IsImageClass( |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 165 | dex_file.StringDataByIdx(dex_file.GetTypeId(type_index).descriptor_idx_))) { |
| 166 | is_in_boot_image = true; |
| 167 | desired_load_kind = codegen->GetCompilerOptions().GetCompilePic() |
| 168 | ? HLoadClass::LoadKind::kBootImageLinkTimePcRelative |
| 169 | : HLoadClass::LoadKind::kBootImageLinkTimeAddress; |
| 170 | } else { |
| 171 | // Not a boot image class. |
| 172 | DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file)); |
| 173 | desired_load_kind = HLoadClass::LoadKind::kBssEntry; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 174 | } |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 175 | } else { |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 176 | is_in_boot_image = (klass != nullptr) && |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 177 | runtime->GetHeap()->ObjectIsInBootImageSpace(klass.Get()); |
| 178 | if (runtime->UseJitCompilation()) { |
| 179 | // TODO: Make sure we don't set the "compile PIC" flag for JIT as that's bogus. |
| 180 | // DCHECK(!codegen_->GetCompilerOptions().GetCompilePic()); |
| 181 | if (is_in_boot_image) { |
| 182 | // TODO: Use direct pointers for all non-moving spaces, not just boot image. Bug: 29530787 |
| 183 | desired_load_kind = HLoadClass::LoadKind::kBootImageAddress; |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 184 | } else if (klass != nullptr) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 185 | desired_load_kind = HLoadClass::LoadKind::kJitTableAddress; |
| 186 | } else { |
| 187 | // Class not loaded yet. This happens when the dex code requesting |
| 188 | // this `HLoadClass` hasn't been executed in the interpreter. |
| 189 | // Fallback to the dex cache. |
| 190 | // TODO(ngeoffray): Generate HDeoptimize instead. |
| 191 | desired_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod; |
| 192 | } |
| 193 | } else if (is_in_boot_image && !codegen->GetCompilerOptions().GetCompilePic()) { |
| 194 | // AOT app compilation. Check if the class is in the boot image. |
| 195 | desired_load_kind = HLoadClass::LoadKind::kBootImageAddress; |
| 196 | } else { |
| 197 | // Not JIT and either the klass is not in boot image or we are compiling in PIC mode. |
| 198 | desired_load_kind = HLoadClass::LoadKind::kBssEntry; |
| 199 | } |
| 200 | } |
| 201 | DCHECK_NE(desired_load_kind, HLoadClass::LoadKind::kInvalid); |
| 202 | |
| 203 | if (is_in_boot_image) { |
| 204 | load_class->MarkInBootImage(); |
| 205 | } |
| 206 | load_kind = codegen->GetSupportedLoadClassKind(desired_load_kind); |
| 207 | } |
| 208 | |
| 209 | if (!IsSameDexFile(load_class->GetDexFile(), *dex_compilation_unit.GetDexFile())) { |
| 210 | if ((load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) || |
| 211 | (load_kind == HLoadClass::LoadKind::kBssEntry)) { |
| 212 | // We actually cannot reference this class, we're forced to bail. |
| 213 | // We cannot reference this class with Bss, as the entrypoint will lookup the class |
| 214 | // in the caller's dex file, but that dex file does not reference the class. |
| 215 | return HLoadClass::LoadKind::kInvalid; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 216 | } |
| 217 | } |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 218 | return load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 221 | void HSharpening::ProcessLoadString(HLoadString* load_string) { |
| 222 | DCHECK_EQ(load_string->GetLoadKind(), HLoadString::LoadKind::kDexCacheViaMethod); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 223 | |
| 224 | const DexFile& dex_file = load_string->GetDexFile(); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 225 | dex::StringIndex string_index = load_string->GetStringIndex(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 226 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 227 | HLoadString::LoadKind desired_load_kind = static_cast<HLoadString::LoadKind>(-1); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 228 | { |
| 229 | Runtime* runtime = Runtime::Current(); |
| 230 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 231 | ScopedObjectAccess soa(Thread::Current()); |
| 232 | StackHandleScope<1> hs(soa.Self()); |
| 233 | Handle<mirror::DexCache> dex_cache = IsSameDexFile(dex_file, *compilation_unit_.GetDexFile()) |
| 234 | ? compilation_unit_.GetDexCache() |
| 235 | : hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file)); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 236 | mirror::String* string = nullptr; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 237 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 238 | if (codegen_->GetCompilerOptions().IsBootImage()) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 239 | // Compiling boot image. Resolve the string and allocate it if needed, to ensure |
| 240 | // the string will be added to the boot image. |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 241 | DCHECK(!runtime->UseJitCompilation()); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 242 | string = class_linker->ResolveString(dex_file, string_index, dex_cache); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 243 | CHECK(string != nullptr); |
Vladimir Marko | 9502687 | 2016-09-09 09:16:31 +0000 | [diff] [blame] | 244 | if (compiler_driver_->GetSupportBootImageFixup()) { |
| 245 | DCHECK(ContainsElement(compiler_driver_->GetDexFilesForOatFile(), &dex_file)); |
| 246 | desired_load_kind = codegen_->GetCompilerOptions().GetCompilePic() |
| 247 | ? HLoadString::LoadKind::kBootImageLinkTimePcRelative |
| 248 | : HLoadString::LoadKind::kBootImageLinkTimeAddress; |
| 249 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 250 | // compiler_driver_test. Do not sharpen. |
| 251 | desired_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
Vladimir Marko | 9502687 | 2016-09-09 09:16:31 +0000 | [diff] [blame] | 252 | } |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 253 | } else if (runtime->UseJitCompilation()) { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 254 | // 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] | 255 | // DCHECK(!codegen_->GetCompilerOptions().GetCompilePic()); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 256 | string = class_linker->LookupString(dex_file, string_index, dex_cache); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 257 | if (string != nullptr) { |
| 258 | if (runtime->GetHeap()->ObjectIsInBootImageSpace(string)) { |
| 259 | desired_load_kind = HLoadString::LoadKind::kBootImageAddress; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 260 | } else { |
| 261 | desired_load_kind = HLoadString::LoadKind::kJitTableAddress; |
| 262 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 263 | } else { |
| 264 | desired_load_kind = HLoadString::LoadKind::kDexCacheViaMethod; |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 265 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 266 | } else { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 267 | // AOT app compilation. Try to lookup the string without allocating if not found. |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 268 | string = class_linker->LookupString(dex_file, string_index, dex_cache); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 269 | if (string != nullptr && |
| 270 | runtime->GetHeap()->ObjectIsInBootImageSpace(string) && |
| 271 | !codegen_->GetCompilerOptions().GetCompilePic()) { |
| 272 | desired_load_kind = HLoadString::LoadKind::kBootImageAddress; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 273 | } else { |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 274 | desired_load_kind = HLoadString::LoadKind::kBssEntry; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 275 | } |
| 276 | } |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 277 | if (string != nullptr) { |
| 278 | load_string->SetString(handles_->NewHandle(string)); |
| 279 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 280 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 281 | DCHECK_NE(desired_load_kind, static_cast<HLoadString::LoadKind>(-1)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 282 | |
| 283 | HLoadString::LoadKind load_kind = codegen_->GetSupportedLoadStringKind(desired_load_kind); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 284 | load_string->SetLoadKind(load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 287 | } // namespace art |