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