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